Thank you for the overview. It seems as though this community will also look to IEEE-754 (the IEEE Standard for Floating-Point Arithmetic) for Reals and also Infinity.Should Python raise exceptions for Integers or [Complex] Fractions involving Infinity,or should Python assume that IEEE-754 is the canonical source of truth about infinity?IEEE-754 (2019), a closed standard, costs $100 for the PDF. I'll Ctrl-F for 'infinity' in the Wikipedia article:Exception handling
The standard defines five exceptions, each of which returns a default value and has a corresponding status flag that is raised when the exception occurs.[e] No other exception handling is required, but additional non-default alternatives are recommended (see § Alternate exception handling).
The five possible exceptions are:
- Invalid operation: mathematically undefined, e.g., the square root of a negative number. By default, returns qNaN.
- Division by zero: an operation on finite operands gives an exact infinite result, e.g., 1/0 or log(0). By default, returns ±infinity.
- Overflow: a result is too large to be represented correctly (i.e., its exponent with an unbounded exponent range would be larger than emax). By default, returns ±infinity for the round-to-nearest modes (and follows the rounding rules for the directed rounding modes).
- Underflow: a result is very small (outside the normal range) and is inexact. By default, returns a subnormal or zero (following the rounding rules).
Inexact: the exact (i.e., unrounded) result is not representable exactly. By default, returns the correctly rounded result.It appears that IEEE-754 implemented as per the binary spec could not represent more complex assessments of inifnity:As with IEEE 754-1985, the biased-exponent field is filled with all 1 bits to indicate either infinity (trailing significand field = 0) or a NaN (trailing significand field ≠ 0). For NaNs, quiet NaNs and signaling NaNs are distinguished by using the most significant bit of the trailing significand field exclusively,[d] and the payload is carried in the remaining bits.json5 extends the JSON to support IEEE-754 +-inf (and +-0, which can also be used to indicate 1D directionality sans magnitude).Presumably, in the IEEE-754 view of the world,from math import inf, nanassert type(inf) == floatassert isinstance(inf, float)assert float("inf") == infassert inf / inf == nanassert inf / 0 == inf # currently: ZeroDivisionErrorassert (x/0) < ((x+1e-10)/0) # where x>0 (x in Z+) # Not possible; Python is not a CAShttps://en.wikipedia.org/wiki/List_of_computer_algebra_systems doesn't have a column for a "Surreal Numbers" or "non-Float handling of infinity".https://en.wikipedia.org/wiki/Quantum_field_theory#Infinities_and_renormalization deals with Infinities; which have curently been removed.inf**infOn Sun, Oct 11, 2020 at 9:07 PM Steven D'Aprano <email@example.com> wrote:
On Sun, Oct 11, 2020 at 05:47:44PM -0400, Wes Turner wrote:
> No, 2 times something is greater than something. Something over something
> is 1.
Define "something". Define "times" (multiplication). Define "greater
than". Define "over" (division).
And while you are at it, don't forget to define what you mean by
"infinity". Do you mean potential infinity, actual infinity, Absolute
infinity, aleph and beth numbers, omegas, or something else?
I am not being facetious. Getting your definitions right is vital if you
wish to avoid error, and to avoid miscommunication. Change the
definitions, and you change the meaning of everything said.
(1) In the so-called "real numbers", there is no such thing as infinity.
Since there is no such thing as infinity, infinity is not "something"
that can be multiplied or divided, or added or subtracted. In the Real
number system, there is no coherent way of doing arithmetic on
"infinity". "Two times infinity" is meaningless.
In the real numbers, there's no sensible way of doing arithmetic with
"infinity" without leading to contradiction.
Informally, infinity in the Real number system is a process that never
completes, so doing twice as much doesn't take any longer.
(2) Mathematicians have created at least two extensions to the Real
number line which do include at least one infinity. It is possible to
construct a coherent system that is not self-contradictory by including
either a pair of plus and minus infinity, or just a single unsigned
But in doing so, we have to give up certain "common sense" properties of
finite numbers. For example, with only a single infinity, infinity is
both greater than everything, and less than (more negative) than
everything. We lose a coherent definition of "greater than".
Even in the extended number lines, two times infinity is just infinity,
and infinity divided by infinity is not coherent and cannot be defined
in any sensible way.
The IEEE-754 standard, and consequently Python floats, closely models
the extended real number line.
(3) In the *cardinal numbers*, there is something called infinity. Or
rather, there are an *infinite number* of infinities, starting with the
smallest, aleph-0, which represents the cardinality of the integers,
i.e. what people usually mean when they think of infinity.
Even in the cardinal numbers, two times infinity (aleph-0) is just
aleph-0; however you might be pleased to know that two to the power of
aleph-0 is aleph-1.
Arithmetic with infinite cardinal numbers is strange.
(4) In other extensions of the real numbers, such as hyperreal and
surreal numbers, we can work with various different kinds of
infinities (and infinitesimals).
For example, in the surreal numbers, we can do arithmetic on infinities,
and you will be gratified, I am sure, that twice infinity is different
from plain old infinity. In the language of the surreals:
2ω = ω + ω ≠ ω
(That's an omega symbol, not ∞.)
Unfortunately, the surreals are very different from the commonsense
world of the real numbers we know and love. For starters, they form a
tree, not a line. You cannot reach ω by starting at 0 and adding 1
repeatedly. (ω is not the successor of any ordinal number.) Consequently
there are other infinite numbers like ω-1 that are less than infinity
but cannot be reached by counting upwards from zero but only by counting
down from infinity.
And of course, in the surreal numbers, there are an infinity of
ever-growing infinities: not just ω+1 and 2ω but ω^2 and ω^ω and so on,
all of which are "bigger than infinity".
All very fascinating I am sure, but I don't think that we should be
trying to emulate the surreal numbers as part of float.
Python-ideas mailing list -- firstname.lastname@example.org
To unsubscribe send an email to email@example.com
Message archived at https://firstname.lastname@example.org/message/MI4HG64LQGJ5TZYIOVNYNZKYVTEUHND4/
Code of Conduct: http://python.org/psf/codeofconduct/