On Saturday, March 29, 2014 5:24:13 AM UTC-7, Sergey Kirpichev wrote: > > On Saturday, March 29, 2014 8:34:36 AM UTC+4, Richard Fateman wrote: >> >> Your problem is that the notions of + and - in your computer programming >> language >> are apparently inadequate. >> > > In which one? Python, CLisp? >
Common Lisp uses floating-point arithmetic for floats, exact arithmetic for the data type used for rationals. If you stick with integers and ratios of integers, Common Lisp does mathematically valid arithmetic. There is a way of being considerably faster than ratio of integers, while correctly representing WITHOUT ERROR OR ROUNDOFF all results from addition and multiplication of numbers that originate as floats. This is "binary rational" and was used so far as I know in only one system designed by George E. Collins. It works like this: a binary rational is an arbitrary-precision integer X 2^(power). Power is an integer +-, and one could also make it an arbitrary precision number, though 32 or even 16 bits is probably enough for most practical and impractical purposes. Advantage 1: No need for greatest common divisor calculations. If the numerator in binary has k trailing zeros, strike them off and add k to the power. Advantage 2: No overflow or underflow or rounding from add and multiply. Exact results. Advantage 3: strictly a superset of floats. Disadvantage 1. Division is not exact. Disadvantage 2: Strictly a subset of "ratio of integers". > >> It is certainly possible to do this correctly by converting a,b,c >> into ratios of integers >> > > Sure. It's possible to convert a,b,c to rationals, but then it will be > rational > arithmetic, not arithmetic for floats (IEEE 754). > Well, if you want to do crappy arithmetic, maybe you should be forced to do this: crappy_float_plus(a, crappy_float_times(b,c)) etc... instead of hinting/misinforming the programmer as well as the reader of programs that the process indicated is addition or multiplication. > > >> The fact that + gets different answers for adding numbers a,b and >> for adding a', b' where >> a-a' and b=b' can't be a good thing in a system that is supposed to do >> mathematics. >> > > There are still reasons for floats (Christophe point you to major one). > Of course there are. Speed. Storage. > 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. > An example: https://github.com/sympy/sympy/pull/2801 > -- 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/51545f77-a006-492d-804b-2b38957147cc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
