Opened 7 years ago
Last modified 3 years ago
#10982 new defect
symbolic derivatives should be able to have non-variable arguments
Reported by: | casamayou | Owned by: | burcin |
---|---|---|---|
Priority: | minor | Milestone: | sage-6.4 |
Component: | calculus | Keywords: | simplify, maxima, symbolic derivative |
Cc: | kcrisman, zimmerma | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
Here is an example from the french sagebook to compute the laplacian in polar, that no longer works with version 4.6 of Sage
sage: x, y, r, t = var('x, y, r, t'); f = function('f', x, y) sage: F = f(x = r*cos(t), y = r*sin(t)) sage: d = (diff(F,r,2) + diff(F,t,2)/r**2 + diff(F,r)/r) sage: d.simplify_full() --------------------------------------------------------------- NotImplementedError Traceback (most recent call last) NotImplementedError: arguments must be distinct variables
With older versions, you got it :
sage: d.simplify_full() D[0, 0](f)(r, t) + D[1, 1](f)(r, t)
Change History (13)
comment:1 Changed 7 years ago by
- Cc kcrisman added
- Keywords simplify maxima symbolic derivative added; simplify_full removed
- Summary changed from regression to symbolic derivatives should be able to have non-variable arguments
comment:2 follow-up: ↓ 3 Changed 7 years ago by
AFAIK, #7377 improves the conversion of derivatives to maxima. It might fix this as well.
comment:3 in reply to: ↑ 2 ; follow-up: ↓ 4 Changed 7 years ago by
comment:4 in reply to: ↑ 3 Changed 7 years ago by
Replying to kcrisman:
Replying to burcin:
AFAIK, #7377 improves the conversion of derivatives to maxima. It might fix this as well.
Nice idea! Unfortunately, it seems to have the same problem.
but see http://trac.sagemath.org/sage_trac/ticket/7377#comment:54 for some ideas on how to improve this. The concerns about "at" in maxima are ungrounded: It's the documentation that is wrong and this will be fixed in the new version. It would be quite straightforward to extend the support to general derivatives, including conversion to/from maxima (we'll have to see how much trouble the "at" expressions give further down the line, of course). Furthermore, the conversion is easier to do with #7377 but it's not required. You could already do this in the old setup.
comment:5 Changed 7 years ago by
Thanks for that comment reference. I think you are right that this could work out. You are also right that "Sage support for functional derivatives is only rudimentary." This largely changed when the D[0]
notation was introduced.
comment:6 Changed 7 years ago by
- Cc zimmerma added
comment:7 Changed 6 years ago by
This seems to work for me in 5.0:
sage: x, y, r, t = var('x, y, r, t') sage: f = function('f', x, y) sage: F = f(x = r*cos(t), y = r*sin(t)) sage: d = (diff(F,r,2) + diff(F,t,2)/r**2 + diff(F,r)/r) sage: d.simplify() (sin(t)*D[1, 1](f)(r*cos(t), r*sin(t)) + cos(t)*D[0, 1](f)(r*cos(t), r*sin(t)))*sin(t) + (sin(t)*D[0, 1](f)(r*cos(t), r*sin(t)) + cos(t)*D[0, 0](f)(r*cos(t), r*sin(t)))*cos(t) + (sin(t)*D[1](f)(r*cos(t), r*sin(t)) + cos(t)*D[0](f)(r*cos(t), r*sin(t)))/r - ((r*sin(t)*D[0, 1](f)(r*cos(t), r*sin(t)) - r*cos(t)*D[1, 1](f)(r*cos(t), r*sin(t)))*r*cos(t) - (r*sin(t)*D[0, 0](f)(r*cos(t), r*sin(t)) - r*cos(t)*D[0, 1](f)(r*cos(t), r*sin(t)))*r*sin(t) + r*sin(t)*D[1](f)(r*cos(t), r*sin(t)) + r*cos(t)*D[0](f)(r*cos(t), r*sin(t)))/r^2 sage: d.simplify_full() D[0, 0](f)(r*cos(t), r*sin(t)) + D[1, 1](f)(r*cos(t), r*sin(t)) sage: diff(F,r).simplify() sin(t)*D[1](f)(r*cos(t), r*sin(t)) + cos(t)*D[0](f)(r*cos(t), r*sin(t)) sage: diff(F,r).simplify_full() sin(t)*D[1](f)(r*cos(t), r*sin(t)) + cos(t)*D[0](f)(r*cos(t), r*sin(t))
Although I'm too lazy to bisect to find out when it started working again, it'd probably be a good idea to add a doctest to make sure that it stays that way. Not quite sure where to put it, though.
comment:8 follow-up: ↓ 9 Changed 6 years ago by
Hmm. On second thought, I may have spoken too quickly:
D[0, 0](f)(r*cos(t), r*sin(t)) + D[1, 1](f)(r*cos(t), r*sin(t))
and
D[0, 0](f)(r, t) + D[1, 1](f)(r, t)
are a little different. Not incompatible, because the functions are abstract, but still not the same. Do we want to recover the original representation?
comment:9 in reply to: ↑ 8 Changed 6 years ago by
Replying to dsm:
D[0, 0](f)(r, t) + D[1, 1](f)(r, t)
Wow, Sage before 4.6 was just plain wrong. We'll excuse casamayou, since superficially it looks like what one would sloppily write in a calculus book (the coordinate transformation implicitly assumed).
The formula for d is the expression for the laplacian in polar coordinates, so it should be equal to
(diff(f,x,x)+diff(f,y,y)).subs(x=r*cos(t),y=r*sin(t))
which is what 5.0 verifies.
I'm pretty sure #12796 fixed this, since this kind of computation was the point of that ticket. I think this ticket can be closed. Add a doctest if you think the current tests are insufficient.
comment:10 Changed 4 years ago by
- Milestone changed from sage-5.11 to sage-5.12
comment:11 Changed 4 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:12 Changed 4 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:13 Changed 3 years ago by
- Milestone changed from sage-6.3 to sage-6.4
I don't know that this is necessarily a regression so much as having made some choices about what is 'allowed' to be a symbolic derivative. We don't allow (for reasons that are unclear to me, because I still don't understand why we changed how we represent symbolic derivatives) arguments that are not just variables, unlike here where they are expressions.
It's the conversion to Maxima that is failing, by the way.
This even happens with trying to simplify (send to Maxima)
This is at least tangentially related to #6840 and #6756, though probably not directly.