Ticket #2547 (closed enhancement: fixed)

Opened 5 years ago

Last modified 5 years ago

[with patch, positive review] Implement gradient(), hessian() for callable symbolic expressions

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

Description (last modified by was) (diff)

Fix this:

sage: f(x,y) = x+y
sage: f.gradient()
---------------------------------------------------------------------------
<type 'exceptions.AttributeError'>        Traceback (most recent call last)

/Users/was/build/sage-2.10.3.rc3/devel/sage-main/sage/modular/abvar/<ipython console> in <module>()

<type 'exceptions.AttributeError'>: 'CallableSymbolicExpression' object has no attribute 'gradient'


SEE ALSO: This is the extent of my understanding of what #2143 does, perhaps there are other new methods that should be implemented for function rings, or other rings which should have this.

This relates to making vectors over function rings see #2546

Attachments

function_derivatives.patch Download (1.8 KB) - added by jwmerrill 5 years ago.

Change History

comment:1 Changed 5 years ago by gfurnish

  • Owner changed from joyner to gfurnish
  • Status changed from new to assigned

comment:2 Changed 5 years ago by was

  • Status changed from assigned to closed
  • Resolution set to invalid

This is not a clear precise task. This could be discussed on sage-devel.

comment:3 Changed 5 years ago by mabshoff

  • Milestone changed from sage-2.10.4 to sage-duplicate/invalid

comment:4 Changed 5 years ago by was

  • Status changed from closed to reopened
  • Resolution invalid deleted
  • Description modified (diff)
  • Summary changed from Implement gradient(), hessian() for callable function rings to Implement gradient(), hessian() for callable symbolic expressions

comment:5 Changed 5 years ago by was

13:57 < jkantor> The fact that gradient doesn't work with functions defined as f(x,y) is 
                 something I was aware of and was going to fix

comment:6 Changed 5 years ago by was

  • Owner changed from gfurnish to jkantor
  • Status changed from reopened to new

comment:7 Changed 5 years ago by gfurnish

  • Component changed from group_theory to calculus
  • Milestone changed from sage-duplicate/invalid to sage-2.11

comment:8 Changed 5 years ago by jwmerrill

See also #3941 regarding the symbolic jacobian.

comment:9 Changed 5 years ago by jwmerrill

I did a little spelunking on this one, and so far, what it appears to come down to is that is_field is not implemented on CallableSymbolicExpressionRing?_class, but it is implemented (and is True) on SymbolicExpressionRing?_class.

Changed 5 years ago by jwmerrill

comment:10 Changed 5 years ago by jwmerrill

  • Owner changed from jkantor to jwmerrill
  • Summary changed from Implement gradient(), hessian() for callable symbolic expressions to [with patch, needs review] Implement gradient(), hessian() for callable symbolic expressions

This patch implements the gradient and hessian (along with doctests) on callable symbolic expressions. In order to make this work, I added an is_field method on CallablesSymbolicExpressionRing?_class, which just returns true. This is the same behavior as SymbolicExpressionRing?_class, which seems appropriate. I checked that addition and multiplication work okay with callable symbolic expressions, so they seem like an okay ring to me.

This should take care of #3941 as well, I think, though I wonder if Sage should be more careful about making a distinction between the gradient (which really only makes sense in inner product spaces), and the jacobian, which is a more generally sensible object.

comment:11 Changed 5 years ago by mhansen

  • Summary changed from [with patch, needs review] Implement gradient(), hessian() for callable symbolic expressions to [with patch, positive review] Implement gradient(), hessian() for callable symbolic expressions

Looks good to me.

comment:12 Changed 5 years ago by mabshoff

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

Merged in Sage 3.1.2.alpha4

Note: See TracTickets for help on using tickets.