From: Kris K. <kat...@gm...> - 2015-05-18 20:24:17
|
[moved to maxima-discuss from the old maxima list] On 05/18/2015 01:16 AM, Raymond Toy wrote: > > > On Sat, May 16, 2015 at 9:10 PM, Kris Katterjohn > <kj...@us... <mailto:kj...@us...>> wrote: > > This is an automated email from the git hooks/post-receive script. > It was > generated because a ref change was pushed to the repository containing > the project "Maxima CAS". > > The branch, master has been updated > via 2b1366c1ffb07f117f3a4256aff2efe718141122 (commit) > via 4746f47c5491593dd7c7e2ef757fdd8a7c43d675 (commit) > via 59ec160bfe9883b3e0a76b6529adca90f61ee99d (commit) > via 2f63280ffda2eb51ebb5ff44d7c93cfc30a3672e (commit) > via bfafbab18bfe8a5fc76d8c415218d3b372e318dc (commit) > from f238ef41c0cbfa828b0a2e8cef3d16f70cf659b7 (commit) > > Those revisions listed above that are new to this repository have > not appeared on any other notification email; so we list those > revisions in full, below. > > - Log ----------------------------------------------------------------- > commit 2b1366c1ffb07f117f3a4256aff2efe718141122 > Author: Kris Katterjohn <kat...@gm... > <mailto:kat...@gm...>> > Date: Sat May 16 22:53:02 2015 -0500 > > Fix issues with gamma_incomplete's GRAD and psi's INTEGRAL > properties > > Part of the GRAD property for gamma_incomplete and the INTEGRAL > property for psi are implemented with Lisp lambda expressions. The > parameters in the lambda lists should have been used to > construct the > return values, but this was not done correctly (symbols matching the > parameters' names were used in quoted lists instead of using the > parameters' values). > > The parameter names in the lambda lists match the dummy variable > names > in the CARs of the GRAD and INTEGRAL properties, so the intended > functionality still happened to work. If the dummy variables were > consistently renamed then this would cease to work. > > > Is there a test case for this? I think that would be a useful addition. > I think that maybe I wasn't explicit enough in describing my use of the phrase "dummy variables" in the commit message, so I'll give a more in-depth description here (so hopefully the commit message will make more sense). I'm assuming that this caused confusion. The dummy variables I mentioned in the commit message are not the "dummy variables" we use in calling diff, integrate, etc. So prior to this commit using different variable names would work as expected: (%i1) assume(a>0, b>0)$ (%i2) diff(gamma_incomplete(a,z), a); (%o2) (-(gamma(a)-gamma_incomplete(a,z))*log(z)) +gamma(a)^2*hypergeometric_regularized([a,a],[a+1,a+1],-z)*z^a +(psi[0])(a)*gamma(a) (%i3) diff(gamma_incomplete(b,x), b); (%o3) (-(gamma(b)-gamma_incomplete(b,x))*log(x)) +gamma(b)^2*hypergeometric_regularized([b,b],[b+1,b+1],-x)*x^b +(psi[0])(b)*gamma(b) In this example, the dummy variables I mentioned are the ones stored in the symbol plist for gamma_incomplete: (%i1) :lisp (get '%gamma_incomplete 'grad) ((A Z) #<Anonymous Function #x300001F1B84F> ((MTIMES) -1 ((MEXPT) $%E ((MTIMES) -1 Z)) ((MEXPT) Z ((MPLUS) -1 A)))) (%i1) diff(gamma_incomplete(f,s),s); (%o1) -s^(f-1)*%e^-s So these A and Z are the dummy variables (as seen being used in the expression for the derivative wrt the second argument). Consistently renaming the (visible) dummy variables from A, Z to Q, R still gives a working derivative wrt the second arg: (%i2) :lisp (get '%gamma_incomplete 'grad) ((Q R) #<Anonymous Function #x30200077556F> ((MTIMES) -1 ((MEXPT) $%E ((MTIMES) -1 R)) ((MEXPT) R ((MPLUS) -1 Q)))) (%i2) diff(gamma_incomplete(f,s),s); (%o2) -s^(f-1)*%e^-s However, prior to this commit, the derivative wrt the first arg would then give the wrong variables in the result (the bare Lisp symbols ?a and ?z instead of f and s): (%i3) lispdisp:true$ (%i4) assume(f>0)$ (%i5) diff(gamma_incomplete(f,s),f); (%o5) (-gamma_incomplete_generalized(?a,0,?z)*log(?z)) +gamma(?a)^2*hypergeometric_regularized([?a,?a],[?a+1,?a+1],-?z)*?z^?a +(psi[0])(?a)*gamma(?a) After this commit it works correctly. So the problem would occur only when changing the dummy variables in the plist (which should be a valid thing to do, since they're supposed to be dummy variables...). It doesn't make sense to me for the lambda expression (anonymous function) to depend on its parameters and also the dummy variables in the plist if its parameters are all that it needs. So I'm not sure of a good test for this. Or perhaps I misunderstood your suggestion? Either way, I hope this helps explain what's going on in the commit. Cheers, Kris Katterjohn |
From: Raymond T. <toy...@gm...> - 2015-05-19 01:32:26
|
>>>>> "Kris" == Kris Katterjohn <kat...@gm...> writes: Kris> On 05/18/2015 05:15 PM, Raymond Toy wrote: >>>>>>> "Kris" == Kris Katterjohn <kat...@gm...> writes: >> Kris> [moved to maxima-discuss from the old maxima list] Kris> On 05/18/2015 01:16 AM, Raymond Toy wrote: >> >> [snip] >> >> Thanks for the clarification. Isn't your example in %i5 a good >> test case? The original version would have ?a and ?z in the >> answer but your fix would replace them with f and s >> appropriately. >> Kris> Yes, but I had to change %GAMMA_INCOMPLETE's plist in order Kris> to get that behavior. Is (temporarily) manipulating symbol Kris> plists via :lisp in the test suite acceptable? (Can :lisp Kris> even be used in the regular test suite? Comments in Kris> tests/rtest_rules.mac suggest not.) Oh, I misunderstood. Changing the plist just to show the error is probably not a good idea. After all, it's not how users would use it, so I don't see why we really need to test it. Sorry for the noise! Ray |
From: Jaime V. <vi...@fe...> - 2015-05-18 21:57:25
|
On 18-05-2015 21:23, Kris Katterjohn wrote: > (%i3) diff(gamma_incomplete(b,x), b); > (%o3) (-(gamma(b)-gamma_incomplete(b,x))*log(x)) While we are talking about the derivative of gamma_incomplete, I'd like to bring your attention to (%i2) diff (gamma_incomplete (1/3, -x^3), x); (%o2) 3*%e^x^3 Which gives rise to a wrong anti-derivative for %e^x^3 (see bug #2941, https://sourceforge.net/p/maxima/bugs/2941/) The correct result for diff (gamma_incomplete (1/3, -x^3), x) should be 3*x^2*%e^x^3/(-x^3)^(2/3) but Maxima simplifies x^2/(-x^3)^(2/3) as equal to 1 Regards, Jaime |
From: Raymond T. <toy...@gm...> - 2015-05-18 22:16:15
|
>>>>> "Kris" == Kris Katterjohn <kat...@gm...> writes: Kris> [moved to maxima-discuss from the old maxima list] Kris> On 05/18/2015 01:16 AM, Raymond Toy wrote: >> >> >> On Sat, May 16, 2015 at 9:10 PM, Kris Katterjohn >> <kj...@us... <mailto:kj...@us...>> wrote: >> >> This is an automated email from the git hooks/post-receive >> script. It was generated because a ref change was pushed to >> the repository containing the project "Maxima CAS". >> >> The branch, master has been updated via >> 2b1366c1ffb07f117f3a4256aff2efe718141122 (commit) via >> 4746f47c5491593dd7c7e2ef757fdd8a7c43d675 (commit) via >> 59ec160bfe9883b3e0a76b6529adca90f61ee99d (commit) via >> 2f63280ffda2eb51ebb5ff44d7c93cfc30a3672e (commit) via >> bfafbab18bfe8a5fc76d8c415218d3b372e318dc (commit) from >> f238ef41c0cbfa828b0a2e8cef3d16f70cf659b7 (commit) >> >> Those revisions listed above that are new to this repository >> have not appeared on any other notification email; so we list >> those revisions in full, below. >> >> - Log >> ----------------------------------------------------------------- >> commit 2b1366c1ffb07f117f3a4256aff2efe718141122 Author: Kris >> Katterjohn <kat...@gm... <mailto:kat...@gm...>> >> Date: Sat May 16 22:53:02 2015 -0500 >> >> Fix issues with gamma_incomplete's GRAD and psi's INTEGRAL >> properties >> >> Part of the GRAD property for gamma_incomplete and the INTEGRAL >> property for psi are implemented with Lisp lambda expressions. >> The parameters in the lambda lists should have been used to >> construct the return values, but this was not done correctly >> (symbols matching the parameters' names were used in quoted >> lists instead of using the parameters' values). >> >> The parameter names in the lambda lists match the dummy >> variable names in the CARs of the GRAD and INTEGRAL properties, >> so the intended functionality still happened to work. If the >> dummy variables were consistently renamed then this would cease >> to work. >> >> >> Is there a test case for this? I think that would be a useful >> addition. >> Kris> I think that maybe I wasn't explicit enough in describing my Kris> use of the phrase "dummy variables" in the commit message, Kris> so I'll give a more in-depth description here (so hopefully Kris> the commit message will make more sense). I'm assuming that Kris> this caused confusion. Kris> The dummy variables I mentioned in the commit message are Kris> not the "dummy variables" we use in calling diff, integrate, Kris> etc. So prior to this commit using different variable names Kris> would work as expected: Kris> (%i1) assume(a>0, b>0)$ Kris> (%i2) diff(gamma_incomplete(a,z), a); (%o2) Kris> (-(gamma(a)-gamma_incomplete(a,z))*log(z)) Kris> +gamma(a)^2*hypergeometric_regularized([a,a],[a+1,a+1],-z)*z^a Kris> +(psi[0])(a)*gamma(a) Kris> (%i3) diff(gamma_incomplete(b,x), b); (%o3) Kris> (-(gamma(b)-gamma_incomplete(b,x))*log(x)) Kris> +gamma(b)^2*hypergeometric_regularized([b,b],[b+1,b+1],-x)*x^b Kris> +(psi[0])(b)*gamma(b) Kris> In this example, the dummy variables I mentioned are the Kris> ones stored in the symbol plist for gamma_incomplete: Kris> (%i1) :lisp (get '%gamma_incomplete 'grad) ((A Z) Kris> #<Anonymous Function #x300001F1B84F> Kris> ((MTIMES) -1 ((MEXPT) $%E ((MTIMES) -1 Z)) ((MEXPT) Z Kris> ((MPLUS) -1 A)))) Kris> (%i1) diff(gamma_incomplete(f,s),s); (%o1) -s^(f-1)*%e^-s Kris> So these A and Z are the dummy variables (as seen being used Kris> in the expression for the derivative wrt the second Kris> argument). Kris> Consistently renaming the (visible) dummy variables from A, Kris> Z to Q, R still gives a working derivative wrt the second Kris> arg: Kris> (%i2) :lisp (get '%gamma_incomplete 'grad) ((Q R) Kris> #<Anonymous Function #x30200077556F> Kris> ((MTIMES) -1 ((MEXPT) $%E ((MTIMES) -1 R)) ((MEXPT) R Kris> ((MPLUS) -1 Q)))) Kris> (%i2) diff(gamma_incomplete(f,s),s); (%o2) -s^(f-1)*%e^-s Kris> However, prior to this commit, the derivative wrt the first Kris> arg would then give the wrong variables in the result (the Kris> bare Lisp symbols ?a and ?z instead of f and s): Kris> (%i3) lispdisp:true$ (%i4) assume(f>0)$ Kris> (%i5) diff(gamma_incomplete(f,s),f); (%o5) Kris> (-gamma_incomplete_generalized(?a,0,?z)*log(?z)) Kris> +gamma(?a)^2*hypergeometric_regularized([?a,?a],[?a+1,?a+1],-?z)*?z^?a Kris> +(psi[0])(?a)*gamma(?a) Kris> After this commit it works correctly. Kris> So the problem would occur only when changing the dummy Kris> variables in the plist (which should be a valid thing to do, Kris> since they're supposed to be dummy variables...). It Kris> doesn't make sense to me for the lambda expression Kris> (anonymous function) to depend on its parameters and also Kris> the dummy variables in the plist if its parameters are all Kris> that it needs. Kris> So I'm not sure of a good test for this. Or perhaps I Kris> misunderstood your suggestion? Thanks for the clarification. Isn't your example in %i5 a good test case? The original version would have ?a and ?z in the answer but your fix would replace them with f and s appropriately. -- Ray |
From: Kris K. <kat...@gm...> - 2015-05-19 00:01:10
|
On 05/18/2015 05:15 PM, Raymond Toy wrote: >>>>>> "Kris" == Kris Katterjohn <kat...@gm...> writes: > > Kris> [moved to maxima-discuss from the old maxima list] > Kris> On 05/18/2015 01:16 AM, Raymond Toy wrote: > >> > >> > >> On Sat, May 16, 2015 at 9:10 PM, Kris Katterjohn > >> <kj...@us... <mailto:kj...@us...>> wrote: > >> > >> This is an automated email from the git hooks/post-receive > >> script. It was generated because a ref change was pushed to > >> the repository containing the project "Maxima CAS". > >> > >> The branch, master has been updated via > >> 2b1366c1ffb07f117f3a4256aff2efe718141122 (commit) via > >> 4746f47c5491593dd7c7e2ef757fdd8a7c43d675 (commit) via > >> 59ec160bfe9883b3e0a76b6529adca90f61ee99d (commit) via > >> 2f63280ffda2eb51ebb5ff44d7c93cfc30a3672e (commit) via > >> bfafbab18bfe8a5fc76d8c415218d3b372e318dc (commit) from > >> f238ef41c0cbfa828b0a2e8cef3d16f70cf659b7 (commit) > >> > >> Those revisions listed above that are new to this repository > >> have not appeared on any other notification email; so we list > >> those revisions in full, below. > >> > >> - Log > >> ----------------------------------------------------------------- > >> commit 2b1366c1ffb07f117f3a4256aff2efe718141122 Author: Kris > >> Katterjohn <kat...@gm... <mailto:kat...@gm...>> > >> Date: Sat May 16 22:53:02 2015 -0500 > >> > >> Fix issues with gamma_incomplete's GRAD and psi's INTEGRAL > >> properties > >> > >> Part of the GRAD property for gamma_incomplete and the INTEGRAL > >> property for psi are implemented with Lisp lambda expressions. > >> The parameters in the lambda lists should have been used to > >> construct the return values, but this was not done correctly > >> (symbols matching the parameters' names were used in quoted > >> lists instead of using the parameters' values). > >> > >> The parameter names in the lambda lists match the dummy > >> variable names in the CARs of the GRAD and INTEGRAL properties, > >> so the intended functionality still happened to work. If the > >> dummy variables were consistently renamed then this would cease > >> to work. > >> > >> > >> Is there a test case for this? I think that would be a useful > >> addition. > >> > > Kris> I think that maybe I wasn't explicit enough in describing my > Kris> use of the phrase "dummy variables" in the commit message, > Kris> so I'll give a more in-depth description here (so hopefully > Kris> the commit message will make more sense). I'm assuming that > Kris> this caused confusion. > > Kris> The dummy variables I mentioned in the commit message are > Kris> not the "dummy variables" we use in calling diff, integrate, > Kris> etc. So prior to this commit using different variable names > Kris> would work as expected: > > > Kris> (%i1) assume(a>0, b>0)$ > > Kris> (%i2) diff(gamma_incomplete(a,z), a); (%o2) > Kris> (-(gamma(a)-gamma_incomplete(a,z))*log(z)) > Kris> +gamma(a)^2*hypergeometric_regularized([a,a],[a+1,a+1],-z)*z^a > Kris> +(psi[0])(a)*gamma(a) > > Kris> (%i3) diff(gamma_incomplete(b,x), b); (%o3) > Kris> (-(gamma(b)-gamma_incomplete(b,x))*log(x)) > Kris> +gamma(b)^2*hypergeometric_regularized([b,b],[b+1,b+1],-x)*x^b > Kris> +(psi[0])(b)*gamma(b) > > Kris> In this example, the dummy variables I mentioned are the > Kris> ones stored in the symbol plist for gamma_incomplete: > > Kris> (%i1) :lisp (get '%gamma_incomplete 'grad) ((A Z) > Kris> #<Anonymous Function #x300001F1B84F> > Kris> ((MTIMES) -1 ((MEXPT) $%E ((MTIMES) -1 Z)) ((MEXPT) Z > Kris> ((MPLUS) -1 A)))) > > Kris> (%i1) diff(gamma_incomplete(f,s),s); (%o1) -s^(f-1)*%e^-s > > Kris> So these A and Z are the dummy variables (as seen being used > Kris> in the expression for the derivative wrt the second > Kris> argument). > > Kris> Consistently renaming the (visible) dummy variables from A, > Kris> Z to Q, R still gives a working derivative wrt the second > Kris> arg: > > Kris> (%i2) :lisp (get '%gamma_incomplete 'grad) ((Q R) > Kris> #<Anonymous Function #x30200077556F> > Kris> ((MTIMES) -1 ((MEXPT) $%E ((MTIMES) -1 R)) ((MEXPT) R > Kris> ((MPLUS) -1 Q)))) > > Kris> (%i2) diff(gamma_incomplete(f,s),s); (%o2) -s^(f-1)*%e^-s > > Kris> However, prior to this commit, the derivative wrt the first > Kris> arg would then give the wrong variables in the result (the > Kris> bare Lisp symbols ?a and ?z instead of f and s): > > Kris> (%i3) lispdisp:true$ (%i4) assume(f>0)$ > > Kris> (%i5) diff(gamma_incomplete(f,s),f); (%o5) > Kris> (-gamma_incomplete_generalized(?a,0,?z)*log(?z)) > Kris> +gamma(?a)^2*hypergeometric_regularized([?a,?a],[?a+1,?a+1],-?z)*?z^?a > Kris> +(psi[0])(?a)*gamma(?a) > > Kris> After this commit it works correctly. > > Kris> So the problem would occur only when changing the dummy > Kris> variables in the plist (which should be a valid thing to do, > Kris> since they're supposed to be dummy variables...). It > Kris> doesn't make sense to me for the lambda expression > Kris> (anonymous function) to depend on its parameters and also > Kris> the dummy variables in the plist if its parameters are all > Kris> that it needs. > > Kris> So I'm not sure of a good test for this. Or perhaps I > Kris> misunderstood your suggestion? > > Thanks for the clarification. Isn't your example in %i5 a good test > case? The original version would have ?a and ?z in the answer but > your fix would replace them with f and s appropriately. > Yes, but I had to change %GAMMA_INCOMPLETE's plist in order to get that behavior. Is (temporarily) manipulating symbol plists via :lisp in the test suite acceptable? (Can :lisp even be used in the regular test suite? Comments in tests/rtest_rules.mac suggest not.) I can add something to the test suite if it is actually desired (and if it will work). I just want to make sure the details are clear before adding it. Thanks for your comments. Here is a more self-contained example with less commentary... (%i1) assume(f>0)$ lispdisp:true$ Use older code: (%i3) :lisp (load "src/gamma.lisp") This still works: (%i3) diff(gamma_incomplete(f,s),f); (%o3) (-(gamma(f)-gamma_incomplete(f,s))*log(s)) +gamma(f)^2*hypergeometric_regularized([f,f],[f+1,f+1],-s)*s^f +(psi[0])(f)*gamma(f) Alter plist: (%i4) :lisp (setf (get '%gamma_incomplete 'grad) (sublis '((a . q) (z . r)) (get '%gamma_incomplete 'grad))) ((Q R) #<Anonymous Function #x30200077559F> ((MTIMES) -1 ((MEXPT) $%E ((MTIMES) -1 R)) ((MEXPT) R ((MPLUS) -1 Q)))) Now we get the bad behavior: (%i4) diff(gamma_incomplete(f,s),f); (%o4) (-gamma_incomplete_generalized(?a,0,?z)*log(?z)) +gamma(?a)^2*hypergeometric_regularized([?a,?a],[?a+1,?a+1],-?z)*?z^?a +(psi[0])(?a)*gamma(?a) Cheers, Kris Katterjohn |