On Wed, May 20, 2009 at 13:55, Ondrej Certik <ond...@certik.cz> wrote: > > Hi Pablo! > > On Wed, May 20, 2009 at 4:40 AM, Pablo W. <pablo.win...@gmail.com> wrote: >> >> Hello, >> >> I have been using sympy a lot recently (economical modelling) and >> (while it's a great software) I found a strange behavior when doing >> substitution : it is not respecting operators priority. I think it's >> because it works sequentially with all its arguments, but it leads to >> somewhat surprising results. >> >> In the following session, I was expecting to get the square root of 4, >> i.e. 2, but instead the program is taking to fractional exponents of a >> negative number which has a non unique definition. >> >> In [1]: from sympy import * >> >> In [2]: var('a b') >> Out[2]: (a, b) >> >> In [3]: eq = (a/b)**0.5 >> >> In [4]: eq.subs({a:-2,b:-0.5}) >> Out[4]: -2.00000000000000 >> >> As a workaround, I found myself lambdifying expressions, but I know >> it's a bad workaround working only when substituion is made with >> respect to all arguments. What do you suggest ? > > Indeed, that's a bug that has to be fixed: > > http://code.google.com/p/sympy/issues/detail?id=1427 > > thanks for discovering it and reporting it. > > The sqrt() (or rational power) simplifications has to be fixed in > sympy, as pointed out by Sebastian and Aaron. I didn't realize there > is such a big problem in there. One way to fix it is check if "a" and > "b" is positive, only then split sqrt(a/b) to sqrt(a)/sqrt(b).
Hmm, I thought I fixed that already: http://code.google.com/p/sympy/issues/detail?id=1263 -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---