-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Fallen Seraph wrote: | The IRC channel suggested I post my related bug report here. | | Basically, using the "diff" function is giving me different, and | equally wrong, answers depending on the sytax I use. | | The function I was interested in was: | | g(p,q) = 2*q(exp((q+p)^4)+1)+p(2*exp((q+p)^4)-1) | | To find the derivative wrt q I tried: | | diff(g,q) | which returned: | | | (p, q) |--> 16*(q + p)^3*e^(q + p)^4 | | Which looked very wrong, so I rephrased the function as: | | h(p,q) = (2*q*exp((q+p)^4)+2*q)+p(2*exp((q+p)^4)-1) | | and | | diff(h,q) | | returned | | (p, q) |--> 8*q*(q + p)^3*e^(q + p)^4 + 8*(q + p)^3*e^(q + p)^4 + | 2*e^(q | + p)^4 + 2 | | Which is less wrong, but still too wrong. At this point I headed over | to the IRC channel and was ended up here. | | I assume it is of relevence that I'm using version 2.10.1 32 bit on | ubuntu from the appropriate package. | | I hope this is helpful. |
As David Harvey pointed out, the problem is with the definition of the function itself rather than with the derivatives code. Look what happens: Your original function definition: sage: g(p,q) = 2*q(exp((q+p)^4)+1)+p(2*exp((q+p)^4)-1) sage: g (p, q) |--> 2*(e^(q + p)^4 + 1) + 2*e^(q + p)^4 - 1 So you and Sage do not agree on what the function g is. Your second function definition: sage: h(p,q) = (2*q*exp((q+p)^4)+2*q)+p(2*exp((q+p)^4)-1) sage: h (p, q) |--> 2*q*e^(q + p)^4 + 2*e^(q + p)^4 + 2*q - 1 I believe this is also not what you want. Alright, how about now? sage: f(p,q) = 2*q*(exp((q+p)^4)+1)+p*(2*exp((q+p)^4)-1) sage: f (p, q) |--> p*(2*e^(q + p)^4 - 1) + 2*q*(e^(q + p)^4 + 1) That looks good to me. Let's take the derivative: sage: diff(f,q) (p, q) |--> 2*(e^(q + p)^4 + 1) + 8*q*(q + p)^3*e^(q + p)^4 + 8*p*(q + p)^3*e^(q + p)^4 Assuming that f(p,q) was actually the function you intended, this is indeed the correct derivative. I'm not sure I know what the moral of the story is. The problem is clearly in inputting the function, and it probably should count as a bug that we're just dropping q's and p's when they don't make sense (which is what seems to be happening in the first two examples). If so, an error message would be preferable to quietly doing the wrong thing. Maybe someone who knows about how these things are parsed can chime in here. But the derivative code is definitely returning the correct answer once it is run on the correct function. Best, Alex - -- Alexandru Ghitza Assistant Professor Department of Mathematics Colby College Waterville, ME 04901 http://bayes.colby.edu/~ghitza/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.7 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHwcV7dZTaNFFPILgRAmFJAJ0TJOqas96+ptggHOZj/BjRWftnPgCeK+8J +dKh+UKi9pBlB5voRz1PHI8= =Ktn2 -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---