And what about the following code ?
The user of Sympy must know that types are different and so that the
variable are not the same things. A float is not a rational.
Just try the following code using a classical sequence showing a weakness
of the floats.
=== PYTHON ===
from sympy import *
a = 1/3
b = S(1)/3
print(a == b)
print(type(a))
print(type(b))
for i in range(31):
print(a, ";", b)
a = 4*a - 1
b = 4*b - 1
== OUTPUT ===
True
<class 'float'>
<class 'sympy.core.numbers.Rational'>
0.3333333333333333 ; 1/3
0.33333333333333326 ; 1/3
0.33333333333333304 ; 1/3
0.33333333333333215 ; 1/3
0.3333333333333286 ; 1/3
0.3333333333333144 ; 1/3
0.33333333333325754 ; 1/3
0.33333333333303017 ; 1/3
0.3333333333321207 ; 1/3
0.3333333333284827 ; 1/3
0.3333333333139308 ; 1/3
0.3333333332557231 ; 1/3
0.3333333330228925 ; 1/3
0.3333333320915699 ; 1/3
0.3333333283662796 ; 1/3
0.3333333134651184 ; 1/3
0.33333325386047363 ; 1/3
0.33333301544189453 ; 1/3
0.3333320617675781 ; 1/3
0.3333282470703125 ; 1/3
0.33331298828125 ; 1/3
0.333251953125 ; 1/3
0.3330078125 ; 1/3
0.33203125 ; 1/3
0.328125 ; 1/3
0.3125 ; 1/3
0.25 ; 1/3
0.0 ; 1/3
-1.0 ; 1/3
-5.0 ; 1/3
-21.0 ; 1/3
2014-10-02 18:58 GMT+02:00 Richard Fateman <[email protected]>:
> Lisp has a variety of equality testing predicates.
> EQ for " same memory location"
> = for "numeric equality"
> There's also EQL, EQUAL, CHAR=, STRING=. ...
> One of the benefits of NOT having infix syntax for relations like "=" is
> that
> it puts these others on a more equal footing, language-wise.
>
> I suppose you might argue that "types" solve this problem, but you
> would be wrong. It is perfectly possible to want to know if two strings
> that are string= are also eq -- that is, in the same memory location.
>
>
>
> RJF
>
>
> On Thursday, October 2, 2014 6:02:10 AM UTC-7, Christophe Bal wrote:
>>
>> Hello.
>>
>> For me the fact that 1/3 == S(1)/3 has value True sounds like a bug
>> because 1/3 is a float, and S(1)/3 a rational.
>>
>> Christophe BAL
>>
>> === PYTHON ===
>>
>> from sympy import *
>>
>> a = 1/3
>> b = S(1)/3
>>
>> print(a)
>> print(b)
>>
>> print(a == b)
>> print(type(a))
>> print(type(b))
>>
>> --- OUTPUT ---
>>
>> 0.3333333333333333
>> 1/3
>> True
>> <class 'float'>
>> <class 'sympy.core.numbers.Rational'>
>>
> --
> 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 http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/0dac566d-9a53-4388-8c16-937269370c1c%40googlegroups.com
> <https://groups.google.com/d/msgid/sympy/0dac566d-9a53-4388-8c16-937269370c1c%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 http://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/CAAb4jGkOfULyJ2_prpmMEgyXyxzQvQ9PU_CEEVJJX4rxNyBFPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.