Unexpected behaviour of math.floor, round and int functions (rounding)

Avi Gross avigross at verizon.net
Sat Nov 20 20:54:53 EST 2021


Not at all, Robb. I am not intending to demean Mathematicians as one of my degrees is in that subject and I liked it. I mean that some things in mathematics are not as intuitive to people when they first encounter them, let alone those who never see them and then marvel at results and have expectations.

The example I gave, is NOW, indeed on quite firm footing but for quite a while was not.

What we have in this forum recently is people taking pot shots at aspects of Python where in a similar way, they know not what is actually happening and insist it be some other way. Some people also assume that an email message work any way they want and post things to a text-only group that other cannot see or become badly formatted or complain why a very large attachment makes a message be rejected. They also expect SPAM checkers to be perfect and never reject valid messages and so on.

Things are what they are, not what we wish them to be. And many kinds of pure mathematics live in a Platonic world and must be used with care. Calculus is NOT on a firm footing when any of the ideas in it are violated. A quantum Mechanical universe at a deep level does not have continuity so continuous functions may not really exist and there can be no such thing as an infinitesimal smaller than any epsilon and so on. Much of what we see at that level includes things like a probabilistic view of an electron cloud forming the probability that an electron (which is not a mathematical point) is at any moment at a particular location around an atom. But some like the p-orbital have a sort of 3-D figure eight shape (sort of a pair of teardrops) where there is a plane between the two halves with a mathematically zero probability of the electron ever being there. Yet, quantum tunneling effects let it dross through that plane without actually ever being in the plane because various kinds of quantum jumps in a very wiggly space-time fabric can and will happen in a way normal mathematics may not predict or allow. 

Which brings me back to the python analogy of algorithms implemented that gradually zoom in on an answer you might view as a local maximum or minimum. It may be that with infinite precision calculations, you might zoom in ever closer to the optimal answer where the tangent to such a curve has slope zero. Your program would never halt though if the condition was that it be exactly at that point to an infinite number of decimal places. This is a place I do not agree that the concept of being near the answer (or in this case being near zero) is not a good enough heuristic solution. There are many iterative problems (and recursive ones) where  a close-enough condition is adequate. Some libraries incorporated into languages like Python use an infinite series to calculate something like sin(x) and many other such things, including potentially e and pi and various roots. Many of them can safely stop after N significant digits are locked into place, and especially when all available significant digits are locked. Running them further gains nothing much. So code like:

(previous_estimate - current_estimate) == 0

may be a bad idea compared to something like:

abs(previous_estimate - current_estimate) < epsilon

No disrespect to mathematics intended. My understanding is that mathematics can only be used validly if all underlying axioms are assumed to be true. When (as in the real world or computer programs) some axioms are violated, watch out. Matrix multiplication does not have a symmetry so A*B in general is not the same as B*A and even worse, may be a matrix of a different dimension. A 4x2 matrix and a 2x4 matrix can result in either a 2x2 or 4x4 for example. The violation of that rule may bother some people but is not really an issue as any mathematics that has an axiom for say an abelian group, simply is not expected to apply for a non-abelian case.




-----Original Message-----
From: Python-list <python-list-bounces+avigross=verizon.net at python.org> On Behalf Of Rob Cliffe via Python-list
Sent: Saturday, November 20, 2021 6:19 PM
To: 
Subject: Re: Unexpected behaviour of math.floor, round and int functions (rounding)



On 20/11/2021 22:59, Avi Gross via Python-list wrote:
> there are grey lines along the way where some mathematical proofs do 
> weird things like IGNORE parts of a calculation by suggesting they are 
> going to zero much faster than other parts and then wave a 
> mathematical wand about what happens when they approach a limit like 
> zero and voila, we just "proved" that the derivative of X**2 is 2*X or 
> the more general derivative of A*(X**N) is N*A*(X**(N-1)) and then 
> extend that to N being negative or fractional or a transcendental number and beyond.
>
>
     You seem to be maligning mathematicians.
     What you say was true in the time of Newton, Leibniz and Bishop Berkeley, but analysis was made completely rigorous by the efforts of Weierstrass and others.  There are no "grey lines".  Proofs do not "suggest", they PROVE (else they are not proofs, they are plain wrong). It is not the fault of mathematicians (or mathematics) if some people produce sloppy hand-wavy "proofs" as justification for their conclusions.
     I am absolutely sure you know all this, but your post does not read as if you do.  And it could give a mistaken impression to a non-mathematician.  I think we have had enough denigration of experts.
Best
Rob Cliffe



--
https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list