Opened 14 years ago

Closed 14 years ago

#4030 closed enhancement (fixed)

[with patch, positive review] Vectors of callable things should be callable

Reported by: jwmerrill Owned by: jwmerrill
Priority: major Milestone: sage-3.1.2
Component: calculus Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

The motivation here is being able to evaluate the gradient of a function at a point.

The desired behavior is
    sage: x, y = var('x, y')
    sage: f = x^2 + y^2
    sage: g = f.gradient()
    sage: g(x=3,y=2)
    (6,4)

Currently, however
    sage: g(x=3,y=2)
    Traceback (most recent call last):
    ...
    TypeError:
    'sage.modules.free_module_element.FreeModuleElement_generic_dense'
    object is not callable

Calls should also work for a vector of callable symbolic expressions.
Note that the gradient part will only work once #2547 is applied.
    sage: f(x,y) = x^2 + y^2
    sage: g = f.gradient()
    sage: g(3,2)
    (6,4)
    sage: g(y=2,x=3)
    (6,4)
}}

Attachments (1)

callable_vectors.patch (1.7 KB) - added by jwmerrill 14 years ago.

Download all attachments as: .zip

Change History (7)

Changed 14 years ago by jwmerrill

comment:1 Changed 14 years ago by jwmerrill

  • Component changed from algebra to calculus
  • Owner changed from tbd to jwmerrill
  • Summary changed from Vectors of callable things should be callable to [with patch, needs work] Vectors of callable things should be callable

The attached patch solves all the cases above except the last, which returns

sage: g(y=2,x=3)
Traceback (most recent call last):
...
TypeError: __call__() got an unexpected keyword argument 'y'

Not sure what the deal is with that.

This patch should only be applied after #2547.

comment:2 Changed 14 years ago by jwmerrill

  • Summary changed from [with patch, needs work] Vectors of callable things should be callable to [with patch, needs review] Vectors of callable things should be callable
  • Type changed from defect to enhancement

After applying #4031, the patch here gives the desired behavior.

comment:3 Changed 14 years ago by mabshoff

  • Milestone set to sage-3.1.2

Jason,

please assign a milestone to new tickets. The next release is usually the right choice.

Cheers,

Michael

comment:4 Changed 14 years ago by mhansen

  • Summary changed from [with patch, needs review] Vectors of callable things should be callable to [with patch, positive review] Vectors of callable things should be callable

Looks good to me. Apply only after #4031.

comment:5 in reply to: ↑ description Changed 14 years ago by jwmerrill

Just to be clear, both #2547 and #4031 should be applied before this patch. The functionality doesn't depend on #2547, but the doctests do.

comment:6 Changed 14 years ago by mabshoff

  • Resolution set to fixed
  • Status changed from new to closed

Merged in Sage 3.1.2.alpha4

Note: See TracTickets for help on using tickets.