Are you sure this is the source of the problem? Rational(1, 2) and S.Half
should give the exact same object:

>>> Rational(1, 2) is S.Half
True

and furthermore sqrt(x) is just a shortcut function for Pow(x, S.Half).

By the way, ordered() isn't designed to give numerical order, just a
consistent order.

It looks like the problem has to do with exp(-sqrt(2)*sqrt(3/4)), which
is exp(-sqrt(6)/2), vs. exp(-sqrt(3/8)), which is exp(-sqrt(6)/4) (the
other one is correct because you have the 4 outside the sqrt()).

Aaron Meurer


On Mon, Sep 4, 2017 at 1:43 PM, Nicolas Patry <[email protected]> wrote:

> Hello everyone,
>
> I think I identified a bug. It originated in two sets not being equal.
> Here i will write sqrt instead of Pow(..., Rational(1, 2)) for readability.
> {exp(sqrt(3/8)), exp(-sqrt(3/8)} and {exp(sqrt(2)*sqrt(3)/4),
> exp(-sqrt(2)*sqrt(3/4)}
>
> After going deep into this bug, it appears the problem lies with the
> ordering function of FiniteSet.
>
> FiniteSet seems to order improperly the first set, and this cannot do the
> correct comparison.
> the function 'ordered' seems to have trouble with Pow(...., Rational(1,
> 2)) because it works correctly when I use
> Pow(...., S.Half).
>
> Is there is a reason for this behaviour ? It seems the two mechanisms
> should give the same results.
> Also to be noted, the raw comparison ( < ) gives the correct result no
> matter the arguments.
>
>
> Here is the minimal failing test I could come up with exhibiting the
> behaviour
>     from sympy import Pow, Rational
>
>     l = [Pow(3, Rational(1, 2)), -Pow(3, Rational(1, 2))]
>
>     assert list(ordered(tuple(l), warn=True)) == [-Pow(3, Rational(1, 2)),
> Pow(3, Rational(1, 2))]
>
> I am still trying to figure out why there is a difference, but I want to
> make sure there is not some intended purpose for this.
>
>
> Cheers,
> Nicolas Patry
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/sympy/2d73e756-7450-4d69-be95-8e2cdb493bb5%40googlegroups.com
> <https://groups.google.com/d/msgid/sympy/2d73e756-7450-4d69-be95-8e2cdb493bb5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2BDSRZ0qTsnhANx7G%2BKELr_%3Dz%2BQnPe4Pn-ZC-bQFP68qw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to