on floating-point numbers
Joe Pfeiffer
pfeiffer at cs.nmsu.edu
Tue Sep 7 15:54:08 EDT 2021
Hope Rouselle <hrouselle at jevedi.com> writes:
> Christian Gollwitzer <auriocus at gmx.de> writes:
>>
>> I believe it is not commutativity, but associativity, that is
>> violated.
>
> Shall we take this seriously? (I will disagree, but that doesn't mean I
> am not grateful for your post. Quite the contary.) It in general
> violates associativity too, but the example above couldn't be referring
> to associativity because the second sum above could not be obtained from
> associativity alone. Commutativity is required, applied to five pairs
> of numbers. How can I go from
>
> 7.23 + 8.41 + 6.15 + 2.31 + 7.73 + 7.77
>
> to
>
> 8.41 + 6.15 + 2.31 + 7.73 + 7.77 + 7.23?
>
> Perhaps only through various application of commutativity, namely the
> ones below. (I omit the parentheses for less typing. I suppose that
> does not create much trouble. There is no use of associativity below,
> except for the intented omission of parentheses.)
>
> 7.23 + 8.41 + 6.15 + 2.31 + 7.73 + 7.77
> = 8.41 + 7.23 + 6.15 + 2.31 + 7.73 + 7.77
> = 8.41 + 6.15 + 7.23 + 2.31 + 7.73 + 7.77
> = 8.41 + 6.15 + 2.31 + 7.23 + 7.73 + 7.77
> = 8.41 + 6.15 + 2.31 + 7.73 + 7.23 + 7.77
> = 8.41 + 6.15 + 2.31 + 7.73 + 7.77 + 7.23.
But these transformations depend on both commutativity and
associativity, precisely due to those omitted parentheses. When you
transform
7.23 + 8.41 + 6.15 + 2.31 + 7.73 + 7.77
into
8.41 + 6.15 + 2.31 + 7.73 + 7.77 + 7.23.
it isn't just assuming commutativity, it's also assuming associativity
since it is changing from
(7.23 + 8.41 + 6.15 + 2.31 + 7.73) + 7.77
to
(8.41 + 6.15 + 2.31 + 7.73 + 7.77) + 7.23.
If I use parentheses to modify the order of operations of the first line
to match that of the last, I get
7.23 + (8.41 + 6.15 + 2.31 + 7.73 + 7.77)
Now, I get 39.60000000000001 evaluating either of them.
More information about the Python-list
mailing list