On Sat, Mar 29, 2014 at 01:28:54PM -0700, Richard Fateman wrote:
> Common Lisp uses floating-point arithmetic for floats, exact arithmetic
> for the data type used for rationals.
Good news. Python does same.
> If you stick with integers and ratios of integers, Common
> Lisp does mathematically valid arithmetic.
Excelent! Python too.
The problem is: float arithmetic is not a "valid arithmetic" by
design. And the question is: should we use float "numbers" in SymPy
at all.
> But I admit, we shouldn't allow
> using of Float's (or builtin float type) in symbolic mathematics.
>
> I disagree, from experience. People want to introduce floats. For
> example, some people
> write squareroot(x) as x^0.5
> Saves typing, and they believe it is the same thing.
But that's not necessary floats! It's just a different
notation for rational 1/2 (as "they believe").
In [1]: Rational('0.123')
Out[1]:
123
────
1000
In [2]: Float('0.123')
Out[2]: 0.123000000000000
In [3]: type(_)
Out[3]: sympy.core.numbers.Float
In [4]: sympify('0.123')
Out[4]: 0.123000000000000
In [5]: type(_)
Out[5]: sympy.core.numbers.Float
The little problem here is that float(0.3) != 3/10 internally, for
example (despite people think so). See this:
https://docs.python.org/2/tutorial/floatingpoint.html
In [16]: Decimal(0.3)
Out[16]:
Decimal('0.299999999999999988897769753748434595763683319091796875')
In [17]: Rational(0.3)
Out[17]:
5404319552844595
─────────────────
18014398509481984
In [18]: Rational(str(0.3))
Out[18]: 3/10
End of story. It seems, people want to introduce not floats but a fancy
notation for rationals. If this is only the reason why we keep Float
object - we should drop Float's and fix sympify to map python's floats
to Rational's instead (for example: sympify(0.2) -> Rational(str(0.2))).
Is there a real need for floats in symbolic mathematics package?
--
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/20140331162823.GB30706%40darkstar.order.hcn-strela.ru.
For more options, visit https://groups.google.com/d/optout.