On Sun, Feb 24, 2008 at 11:28 AM, Alex Ghitza <[EMAIL PROTECTED]> wrote:
>
>  -----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

What's happening is the original poster thinks sage does implicit multiplication
but it doesn't.  Instead it creates constant functions p and q and
p( ... ) an q (...) means evaluate and p and q.  For example:

sage: f(q,p) = q(2) + p(3)
sage: f
(q, p) |--> 5

This is related to

     http://trac.sagemath.org/sage_trac/ticket/1554

which got closed by fixing something related to this without fixing this.

The problem basically goes back to this.  If you want the following
to work:

sage: f = sin(x)
sage: f(2)
sin(2)

Then you *have* to also allow the following to work like this:

sage: f(q,p) = q(2) + p(3)
sage: f
(q, p) |--> 5

This is really exactly the same thing.  You've made a symbolic
expression q above and
by default those are callable.  By calling it at 2 you get back "2".

Another example:

sage: f = sin(x)(3)
sage: f
sin(3)

It is very convenient that this works.  But it causes great confusion
to people who
try to use implicit multiplication notation.

Comments?

Changing this behavior would (1) require changing a huge number of doctests all
over Sage, and (2) be a annoying to people who know what's going on and don't
think Sage does implicit multiplication.  However, it would avoid a
lot of confusion
for certain new users.

 -- William

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to