Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hashes for derivatives of symbolic functions w.r.t. different variables are the same #6243

Closed
burcin opened this issue Jun 7, 2009 · 9 comments

Comments

@burcin
Copy link

burcin commented Jun 7, 2009

From Alex Raichev on sage-support:

Hi all:

Upon upgrading to Sage 4.0, i can no longer make a dictionary with
derivatives as keys (see below).  Can someone please fix this?

Alex

----------------------------------------------------------------------
| Sage Version 4.0, Release Date: 2009-05-29                         |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: X= var('x,y')
sage: f= function('f',*X); f
f(x, y)
sage: for x in X:
....:     diff(f,x)
....:
D[0](f)(x, y)
D[1](f)(x, y)
sage: d= {}
sage: for x in X:
....:     d[diff(f,x)] = 1
....:
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call
last)

/Users/raichev/<ipython console> in <module>()

/Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
expression.so in sage.symbolic.expression.Expression.__nonzero__ (sage/
symbolic/expression.cpp:7814)()

/Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
expression.so in sage.symbolic.expression.Expression.test_relation
(sage/symbolic/expression.cpp:9187)()

/Applications/sage/local/lib/python2.5/site-packages/sage/rings/
complex_interval_field.pyc in __call__(self, x, im)
    286
    287             try:
--> 288                 return x._complex_mpfi_( self )  
    289             except AttributeError:
    290                 pass

/Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
expression.so in sage.symbolic.expression.Expression._complex_mpfi_
(sage/symbolic/expression.cpp:5484)()

/Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
expression_conversions.pyc in __call__(self, ex)
    212                 div = self.get_fake_div(ex)
    213                 return self.arithmetic(div, div.operator())
--> 214             return self.arithmetic(ex, operator)  
    215         elif operator in relation_operators:
    216             return self.relation(ex, operator)

/Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
expression_conversions.pyc in arithmetic(self, ex, operator)
   1424             return base ** expt
   1425         else:
-> 1426             return reduce(operator, map(self, operands))  
   1427
   1428     def composition(self, ex, operator):

/Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
expression_conversions.pyc in __call__(self, ex)
    216             return self.relation(ex, operator)
    217         elif isinstance(operator, FDerivativeOperator):
--> 218             return self.derivative(ex, operator)  
    219         else:
    220             return self.composition(ex, operator)

/Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
expression_conversions.pyc in derivative(self, ex, operator)
    344             NotImplementedError: derivative
    345         """
--> 346         raise NotImplementedError, "derivative"  
    347
    348     def arithmetic(self, ex, operator):

NotImplementedError: derivative

I suppose an immediate fix is to implement the derivative method in sage.symbolic.expression_conversions.Converter. I believe the right fix is to change pynac to pass on the parent for numerical approximation instead of just the precision. I'll work on making the necessary changes in pynac.

CC: @mwhansen

Component: symbolics

Author: Burcin Erocal

Reviewer: Golam Mortuza Hossain

Merged: Sage 4.1.1.rc1

Issue created by migration from https://trac.sagemath.org/ticket/6243

@burcin burcin added this to the sage-4.1.1 milestone Jun 7, 2009
@burcin
Copy link
Author

burcin commented Jul 31, 2009

doctests for the fix

@burcin
Copy link
Author

burcin commented Jul 31, 2009

Author: Burcin Erocal

@burcin
Copy link
Author

burcin commented Jul 31, 2009

comment:1

Attachment: trac_6243-fderivative_hash.patch.gz

I have a fix for this in my local pynac tree. I took a shortcut and changed the fderivative hashes to include the parameters.

I'll make a new pynac package with fixes for some other bugs available soon.

@burcin burcin changed the title add support for arbitrary parents in pynac's evalf hashes for derivatives of symbolic functions w.r.t. different variables are the same Jul 31, 2009
@burcin
Copy link
Author

burcin commented Aug 1, 2009

comment:2

This now depends on the package linked from #6404.

Please follow the instructions on that ticket to apply & test.

@burcin burcin self-assigned this Aug 1, 2009
@golam-m-hossain
Copy link

comment:3

I tested this out. Pynac changes seem fine to me. I encountered one issue though:

sage: d = {}
sage: d[x] = 1
sage: d
{x: 1}
sage: f(x) = function('f',x)
sage: d[diff(f(x),x)] = 2
sage: d.keys()
[D[0](f)(x), x]
sage: d.values()
[2, 1]
sage: d
!boom!

The origin of this !boom! lies in expression_conversions.py for fderivative
which is clearly NOT in purview of this patch. So I am going to give it a positive review
shortly.

@golam-m-hossain
Copy link

comment:4

Note: I am giving partial positive review because I tested this patch against my stable
sage-4.1. So if it applies cleanly on Sage-4.1.1.rc1 then that would be full positive from me.

@golam-m-hossain golam-m-hossain changed the title hashes for derivatives of symbolic functions w.r.t. different variables are the same [positive review partial] hashes for derivatives of symbolic functions w.r.t. different variables are the same Aug 2, 2009
@golam-m-hossain
Copy link

Reviewer: Golam Mortuza Hossain

@sagetrac-mvngu
Copy link
Mannequin

sagetrac-mvngu mannequin commented Aug 3, 2009

comment:6

I applied patches in the following order:

  1. the spkg pynac-0.1.8.p2.spkg at Typeseting for conjugate() of symbolic function is inadequate #6404
  2. trac_6404-conjugate_typesetting.patch
  3. trac_6401-real_imag_typesetting.patch
  4. trac_6377-exp_infinity.patch
  5. trac_6243-fderivative_hash.patch
    All doctests pass in my merge tree. So I'm changing Typeseting for conjugate() of symbolic function is inadequate #6404, Typesettings of real() and imag() are broken #6401, exp(x) is broken at x=Infinity and x=-Infinity #6377 and hashes for derivatives of symbolic functions w.r.t. different variables are the same #6243 to positive review as per Golam's request.

@sagetrac-mvngu
Copy link
Mannequin

sagetrac-mvngu mannequin commented Aug 3, 2009

Merged: Sage 4.1.1.rc1

@sagetrac-mvngu sagetrac-mvngu mannequin changed the title [positive review partial] hashes for derivatives of symbolic functions w.r.t. different variables are the same hashes for derivatives of symbolic functions w.r.t. different variables are the same Aug 3, 2009
@sagetrac-mvngu sagetrac-mvngu mannequin closed this as completed Aug 3, 2009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants