#7401 closed task (fixed)
Derivative at a point is not translated into Maxima
Reported by:  robert.marik  Owned by:  was 

Priority:  minor  Milestone:  sage6.5 
Component:  interfaces  Keywords:  derivative, at, maxima 
Cc:  eviatarbach  Merged in:  
Authors:  Robert Mařík, Nils Bruin  Reviewers:  KarlDieter Crisman, Nils Bruin, Peter Bruin 
Report Upstream:  N/A  Work issues:  
Branch:  589ff62 (Commits)  Commit:  
Dependencies:  Stopgaps: 
Description
Alex reported http://groups.google.cz/group/sagesupport/browse_thread/thread/81b96a7731600ec2 this bug (see the link for short discussion related to the problem)
Hi all: I found some strange behavior in solve that's related to function composition. Check out this short example.   Sage Version 4.2, Release Date: 20091024   Type notebook() for the GUI, and license() for information.   sage: var('x,t') (x, t) sage: f= function('f',x) sage: e= {x:exp(t)} sage: ft= f.subs(e); ft f(e^t) sage: Ft = t^2 + ft^2; Ft t^2 + f(e^t)^2 sage: a= diff(Ft,t); a 2*e^t*f(e^t)*D[0](f)(e^t) + 2*t sage: solve(a==0,diff(f,x).subs(e)) [D[0](f)(t) == t*e^(t)/f(e^t)] Did you spot the strangeness? Somehow diff(f,x).subs(e) became diff (f,x).subs({x:t}) after solving. Does anybody know how to fix this? Alex
Attachments (2)
Change History (32)
Changed 10 years ago by
comment:1 followup: ↓ 2 Changed 10 years ago by
 Status changed from new to needs_review
Submitted patch solves the problem described above
limitation and disadvantage of this patch are:
 it works for univariable functions only
 introduces new dummy variable into Maxima session
All comments are welcomed and any help appretiated
comment:2 in reply to: ↑ 1 ; followup: ↓ 4 Changed 10 years ago by
 Status changed from needs_review to needs_work
Replying to robert.marik:
Submitted patch solves the problem described above
Yes, this should do so. It would probably be best to add one more doctest, just to show that the original one works (i.e. without showing the Maxima internals).
limitation and disadvantage of this patch are:
 it works for univariable functions only
That's fine  that's still improving the previous situation, correct? Looking at the code, it would be helpful to know what happens if params has more than one element  particularly in
return "at(diff('%s(dummy_var_der), %s),dummy_var_der=%s)"%(f.name(), ", ".join(params), opnds[0])
it seems like one could have more items in the substitution tuple than there are %s to fill up, even if for some reason len(args)==1. What is the relation between args and params  could there be more params than args?
Also, make sure to add a doctest showing that the NotImplementedError? comes into play. Search for 'Traceback' in the file to see how the doctests for errors look.
 introduces new dummy variable into Maxima session
This is unfortunate, but probably unavoidable currently. You should test whether this breaks anything in Maxima, but I don't see why it would.
comment:3 Changed 10 years ago by
Also, there needs to be a blank line after "TESTS::" for documentation formatting.
comment:4 in reply to: ↑ 2 Changed 10 years ago by
Replying to kcrisman:
This is unfortunate, but probably unavoidable currently. You should test whether this breaks anything in Maxima, but I don't see why it would.
Perhaps we can use variable from f.variables() instead of introducing dummy variable.
comment:5 followup: ↓ 6 Changed 10 years ago by
Why not see if that works, then update the patch? One might have to be careful in testing for how many variables/args there are. I am never clear on the difference between those two things, anyway, in Sage.
comment:6 in reply to: ↑ 5 ; followup: ↓ 7 Changed 10 years ago by
Replying to kcrisman:
Why not see if that works, then update the patch? One might have to be careful in testing for how many variables/args there are. I am never clear on the difference between those two things, anyway, in Sage.
My suggestion related to f.variables() does not work, since I cannot acces the variables inside the function derivative.
The original patch does not work for something like diff(f(x,y),x).subs(x=3) so I updated it and tested for various combination how many variables are in the function, how many variables appear at the resulting expression, how many variables are substituted etc.
Perhaps could be improved for multivariable functions, but Maxima expression "at (expr, [eqn_1, ..., eqn_n])" cannot be translated to current Sage and both issues should be fixed together. Perhaps in this ticket? (leaving as needs_work, despite the fact that the original problem has been fixed and doctested)
comment:7 in reply to: ↑ 6 ; followup: ↓ 8 Changed 10 years ago by
Perhaps could be improved for multivariable functions, but Maxima expression "at (expr, [eqn_1, ..., eqn_n])" cannot be translated to current Sage and both issues should be fixed together. Perhaps in this ticket? (leaving as needs_work, despite the fact that the original problem has been fixed and doctested)
Can you give an example of Sage command > Maxima command > Maxima output that would give rise to such a situation? That should make it fairly straightforward to change the at function appropriately.
comment:8 in reply to: ↑ 7 Changed 10 years ago by
 Status changed from needs_work to needs_review
Replying to kcrisman:
Can you give an example of Sage command > Maxima command > Maxima output that would give rise to such a situation? That should make it fairly straightforward to change the at function appropriately.
I thought that this happens for taylor polynomial in more variables. However, it is not the case (btw. taylor polynomial in more variables seem to be not supported in Sage and I submited patch for #7472).
Hence I think that the problem is patched and if someone finds situation where she/he needs to enhace the functionallity, this can be solved in another ticket.
comment:9 Changed 10 years ago by
The patch fixes also #6376.
comment:10 Changed 10 years ago by
 Reviewers set to KarlDieter Crisman
 Status changed from needs_review to positive_review
Okay, positive review, and all relevant tests pass. It is not optimal because of the dummy variable, one variable, etc., but it fixes things and there are open tickets (some with patches!) for making it even better. Great. I will also put a comment on #6376.
comment:11 Changed 10 years ago by
 Merged in set to sage4.3.alpha0
 Resolution set to fixed
 Status changed from positive_review to closed
comment:12 Changed 10 years ago by
This causes a failure in sage/interfaces/maxima.py with this example
maxima(derivative(ceil(x*y*d), d,x,x,y))
since multivariate derivatives are not supported.
comment:13 Changed 10 years ago by
 Merged in sage4.3.alpha0 deleted
 Status changed from closed to needs_work
I've backed this out for now.
comment:14 Changed 6 years ago by
 Cc eviatarbach added
 Report Upstream set to N/A
comment:15 Changed 6 years ago by
 Milestone changed from sage5.11 to sage5.12
comment:16 Changed 6 years ago by
 Milestone changed from sage6.1 to sage6.2
comment:17 Changed 6 years ago by
 Milestone changed from sage6.2 to sage6.3
comment:18 Changed 5 years ago by
 Milestone changed from sage6.3 to sage6.4
comment:19 Changed 5 years ago by
 Milestone changed from sage6.4 to sageduplicate/invalid/wontfix
 Status changed from needs_work to needs_review
On sage 6.5beta1 I get
sage: solve(a==0,diff(f,x).subs(e)) [D[0](f)(e^t) == t*e^(t)/f(e^t)]
so I think this problem has been resolved. Do we close it as (now) invalid?
comment:20 Changed 5 years ago by
 Reviewers changed from KarlDieter Crisman to Nils Bruin, Peter Bruin
 Status changed from needs_review to positive_review
All doctests in the patch now work without the patch, even the ones that were expected to fail.
comment:21 followup: ↓ 23 Changed 5 years ago by
 Status changed from positive_review to needs_work
Awesome! I tested this last night but it must have been too late, because I didn't notice it worked. :P
In which case we should document that it is fixed so we don't get bitten if (say) we switch symbolics or something again.
comment:22 Changed 5 years ago by
As you say, e.g.
sage: x,y,=var('x y') sage: a = function('f', x, y).diff(x).subs(x=4).subs(y=8) sage: b=maxima(a); b ?%at('diff('f(t0,t1),t0,1),[t0=4,t1=8]) sage: b.sage() D[0](f)(4, 8)
Huh. Maybe this is a side effect of making symbolic variables unique in Maxima? Or the library interface? I bet no one has looked at this for a long time.
comment:23 in reply to: ↑ 21 Changed 5 years ago by
 Milestone changed from sageduplicate/invalid/wontfix to sage6.5
 Priority changed from major to minor
 Reviewers changed from Nils Bruin, Peter Bruin to KarlDieter Crisman, Nils Bruin, Peter Bruin
 Type changed from defect to task
 Work issues set to add doctests
Replying to kcrisman:
Awesome! I tested this last night but it must have been too late, because I didn't notice it worked. :P
In which case we should document that it is fixed so we don't get bitten if (say) we switch symbolics or something again.
Good point, I guess we can just add the doctests from the patch.
comment:24 followup: ↓ 25 Changed 5 years ago by
 Branch set to u/kcrisman/pointderivs
 Commit set to 476d8c43f23185ea22c46a9b30fd37c9ead46668
 Status changed from needs_work to needs_review
New commits:
476d8c4  Add doctests for #7401 about derivatives at a point

comment:25 in reply to: ↑ 24 Changed 5 years ago by
Replying to kcrisman:
New commits:
476d8c4 Add doctests for #7401 about derivatives at a point
Two comments:
 use
a = function('f')(x,y).diff(x)
to avoid the confusing (and hopefully to deprecated) function('f',x,y).  perhaps include an example that also tests the behaviour when the auxiliary variables aren't necessary:
sage: a = function('f')(x,y).diff(x) sage: a D[0](f)(x, y) sage: maxima(a) 'diff('f(_SAGE_VAR_x,_SAGE_VAR_y),_SAGE_VAR_x,1)
since that also illustrates a template how to arrive at more userfriendly printing.
comment:26 Changed 5 years ago by
 Commit changed from 476d8c43f23185ea22c46a9b30fd37c9ead46668 to cc7fe0a9f49ded047e5d2ed8c2cbe57b8dbace1c
Branch pushed to git repo; I updated commit sha1. New commits:
cc7fe0a  More doctests for #7401

comment:28 Changed 5 years ago by
 Branch changed from u/kcrisman/pointderivs to u/pbruin/7401pointderivs
 Commit changed from cc7fe0a9f49ded047e5d2ed8c2cbe57b8dbace1c to 589ff620f904ed797b756543c48d83bb72745ad6
 Status changed from needs_review to positive_review
 Work issues add doctests deleted
The reviewer patch (typesetting, logical ordering of doctests, checking a few more intermediate results) adds/changes nothing essential.
comment:29 Changed 5 years ago by
 Branch changed from u/pbruin/7401pointderivs to 589ff620f904ed797b756543c48d83bb72745ad6
 Status changed from positive_review to closed
comment:30 Changed 3 years ago by
 Commit 589ff620f904ed797b756543c48d83bb72745ad6 deleted
apply together with the patch for #385 (if necessary)