I forgot to mention: this is a transfert from a sage-support message by Emmanuel: https://groups.google.com/d/msg/sage-support/5M50BRbHy2k/5jRYMnf7AQAJ
Le samedi 1 août 2020 12:19:45 UTC+2, Eric Gourgoulhon a écrit : > > > > Le samedi 1 août 2020 10:06:47 UTC+2, Emmanuel Charpentier a écrit : >> >> Consider : >> >> sage: f=function("f") >> sage: m=var("m", domain="integer") >> sage: assume(m>0) >> >> Sage follows the Maxima convention for multiple derivation d^n/dx^n f(x) >> is diff(f(x),x,n) : >> >> sage: diff(sin(x),x,3) >> -cos(x) # Okay.... >> sage: diff(sin(x),x,m) >> 0 *## Huh ???* >> sage: diff(f(x),x,3) >> diff(f(x), x, x, x) # Okay, sort of >> sage: diff(f(x),x,m) >> 0 *## Huh ???* >> >> Note that Sage will silently return a mathematically false result when >> the degree of derivation is symbolic. >> >> The problem doesn't seem to reside i Maxima, which returns results >> consistent to its convention : >> >> sage: %maxima diff(sin(x),x,3) >> -cos(x) >> sage: %maxima diff(sin(x),x,m) >> 'diff(sin(x),x,m) >> sage: %maxima diff(f(x),x,3) >> 'diff(f(x),x,3) >> sage: %maxima diff(f(x),x,m) >> 'diff(f(x),x,m) >> >> The problem is similar to the one seen in sympy *when incorrectly called >> :* >> >> sage: import sympy >> sage: sympy.diff(*[sympy.sympify(u) for u in [sin(x),x,3]]) >> -cos(x) >> sage: sympy.diff(*[sympy.sympify(u) for u in [sin(x),x,m]]) >> 0 # Huh again... >> sage: sympy.diff(*[sympy.sympify(u) for u in [sin(x),[x,m]]]) >> Derivative(sin(x), (x, m)) # Unfulfilling but correct... >> sage: sympy.diff(*[sympy.sympify(u) for u in [f(x),[x,m]]]) >> Derivative(f(x), (x, m)) # Unfulfilling but correct... >> >> Note that sympy's alternative convention for multiple derivation gives >> consistent results : >> >> sage: sympy.diff(*[sympy.sympify(u) for u in [sin(x),[x,m]]]).subs([(m, >> 3)]) >> Derivative(sin(x), (x, 3)) >> sage: sympy.diff(*[sympy.sympify(u) for u in [sin(x),[x,m]]]).subs([(m, >> 3)]).doit >> ....: () >> -cos(x) >> sage: sympy.diff(*[sympy.sympify(u) for u in [f(x),[x,m]]]).subs([(m, 3)]) >> Derivative(f(x), (x, 3)) >> sage: sympy.diff(*[sympy.sympify(u) for u in [f(x),[x,m]]]).subs([(m, >> 3)]).doit() >> ....: >> Derivative(f(x), (x, 3)) >> >> Sage doesn't accept Sympy's convention for multiple derivation : >> >> sage: diff(f(x), (x,3)) >> >> --------------------------------------------------------------------------- >> [ Snip ... ] >> >> TypeError: no canonical coercion from <class 'tuple'> to Symbolic Ring >> >> Therefore, Sage seems to interpret diff(<expression>, <variable>, >> <numerical value>) as d/d<variable> <expression> and diff(<expression>, >> <variable1>, <variable2>) as d/d<variable1> d/d<variable2> <expression>, >> with no way to express d^<variable2>/d<variable1)^<variable2> <expression>. >> >> This is, IMNSHO, a serious mess. Which, as demonstrated above, *can silently >> return >> mathematically false results*. >> >> The problem is that I cannot see a way to fix this that doesn't break >> backwards compatibility somehow. >> >> Help about the way to efficiently file a (probably critical) ticket >> against this horror most welcome... >> >> PS : One can note that Mathematica expresses its result in the symbolic >> case in a peculiar way : >> >> sage: mathematica.D(f(x),[x,m]) >> Derivative[m][F][x] >> >> One can also note that it may handle some special cases in a smarter way >> than Sage/Maxima/Sympy : >> >> sage: mathematica.D(sin(x),[x,m]) >> Sin[(m*Pi)/2 + x] >> >> but this is another story... >> >> -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/09e879d7-62b2-47cd-8a9b-288709903ff8o%40googlegroups.com.