Some numerical instability suggested by the Gemini AI

Georgi Guninski <[email protected]>
Newsgroups gmane.comp.mathematics.pari.devel
Message-ID <CAGUWgD-csQsJDH8aN2CFLnN30Np5EioxzA=fAURJLLUHXno9Ug@mail.gmail.com>
I don't claim this is a bug, just FYI.
Suggested by Gemini, prompts by me, based on floating point instability.

Follows session:
? pre = 38;
? default(realprecision, pre);
?
? 0.1 + 0.2 == 0.3
%4 = 0
? b = default(realbitprecision);
? x = 2.0^b;
? x==x+1
%7 = 1
? x==x+2
%8 = 0

Attach is more serious floating point numbers in python.
gemini_floats.py (text/x-python, 1.1 KB)
#gemini python code about floats
import math

# 1. Non-Associativity: (a + b) + c != a + (b + c)
a, b, c = 1e16, -1e16, 1.0
(a + b) + c  # 1.0
a + (b + c)  # 0.0
(a + b) + c == a + (b + c)  # False

# 2. Binary Decimal Inexactness
0.1 + 0.2  # 0.30000000000000004
0.1 + 0.2 == 0.3  # False

# 3. The Absorption Wall (53-bit mantissa limit in float64)
x = 2.0**53  # 9007199254740992.0
x + 1.0  # 9007199254740992.0
x + 1.0 == x  # True
x + 2.0 == x  # False

# 4. NaN Breaks Reflexivity and Trichotomy
nan = float("nan")
nan == nan  # False
nan != nan  # True
nan < 1.0  # False
nan >= 1.0  # False

# 5. Signed Zero Equivalence vs. Behavior
pos_zero, neg_zero = 0.0, -0.0
pos_zero == neg_zero  # True
math.copysign(1.0, pos_zero)  # 1.0
math.copysign(1.0, neg_zero)  # -1.0

# 6. Indeterminate Forms
inf = float("inf")
inf - inf  # nan
inf * 0.0  # nan

# 7. The Container 'in' Operator Trap (identity 'is' vs equality '==')
nan_a = float("nan")
nan_b = float("nan")
nan_a in [nan_a]  # True  (checks identity 'is' first)
nan_a in [nan_b]  # False (falls back to '==', which evaluates to False!)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.