FA-16446 / Floating-point arithmetic / Open access
Positive-real square root subtracts nearly equal radii · case 01
Positive-real square root subtracts nearly equal radii.
ROOT CAUSE
Positive-real square root subtracts nearly equal radii. The faulty expression is imag=math.copysign(math.sqrt((r-x)/2),y).
VERIFIED REPAIR
Apply the contract at this fault site using imag=y/(2*t).
Unsuccessful approach: The attempted local correction imag=math.copysign(math.sqrt(max(0,(r-x)/2)),y) still violates the explicit regression fixtures.
Case contract
Principal complex square root for finite components, using stable branch reconstruction and preserving the imaginary signed-zero side of the negative real branch cut. Fixtures keep hypot finite. Finite results are rendered to eleven significant decimal digits; modeled domain violations and arithmetic errors are explicit strings.
Why this case matters
An offline floating representation model isolates a reproducible arithmetic fault.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
def render(x):
if math.isnan(x): return 'nan'
if math.isinf(x): return '-infinity' if x<0 else '+infinity'
return format(x,'.11g')
N = 1
observations = []
def solve(x,y):
try:
if x==0 and y==0: return ['0',render(y)]
r=math.hypot(x,y)
t=math.sqrt(r/2+abs(x)/2)
if x>=0:
real=t
imag=math.copysign(math.sqrt((r-x)/2),y)
else:
imag=math.copysign(t,y)
real=abs(y)/(2*t)
return [render(real),render(imag)]
except (ValueError, OverflowError, ZeroDivisionError, TypeError):
return "arithmetic-error"
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('positive axis', solve(float(N*N),0.0), [render(float(N)),"0"])
check('negative axis above', solve(-float(N*N),0.0), ["0",render(float(N))])
check('negative axis below', solve(-float(N*N),-0.0), ["0",render(-float(N))])
check('upper quadrant', solve(3.0,4.0), ["2","1"])
check('lower quadrant', solve(3.0,-4.0), ["2","-1"])
check('negative real quadrant', solve(-3.0,4.0), ["1","2"])
check('huge axis', solve(1e308,0.0), ["1e+154","0"])
check('tiny imaginary', solve(4.0,N*1e-200), ["2",render(N*1e-200/4)])
check('origin above', solve(0.0,0.0), ["0","0"])
check('origin below', solve(0.0,-0.0), ["0","-0"])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| positive axis | ['1', '0'] | ['1', '0'] | Passed |
| negative axis above | ['0', '1'] | ['0', '1'] | Passed |
| negative axis below | ['0', '-1'] | ['0', '-1'] | Passed |
| upper quadrant | ['2', '1'] | ['2', '1'] | Passed |
| lower quadrant | ['2', '-1'] | ['2', '-1'] | Passed |
| negative real quadrant | ['1', '2'] | ['1', '2'] | Passed |
| huge axis | ['1e+154', '0'] | ['1e+154', '0'] | Passed |
| tiny imaginary | ['2', '0'] | ['2', '2.5e-201'] | Failed |
| origin above | ['0', '0'] | ['0', '0'] | Passed |
| origin below | ['0', '-0'] | ['0', '-0'] | Passed |
SHA-256 / 7a87c80628adc3e80eeb10c45b8981412d40b342b82e72dc3cff38a1652122a9
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
def render(x):
if math.isnan(x): return 'nan'
if math.isinf(x): return '-infinity' if x<0 else '+infinity'
return format(x,'.11g')
N = 1
observations = []
def solve(x,y):
try:
if x==0 and y==0: return ['0',render(y)]
r=math.hypot(x,y)
t=math.sqrt(r/2+abs(x)/2)
if x>=0:
real=t
imag=math.copysign(math.sqrt(max(0,(r-x)/2)),y)
else:
imag=math.copysign(t,y)
real=abs(y)/(2*t)
return [render(real),render(imag)]
except (ValueError, OverflowError, ZeroDivisionError, TypeError):
return "arithmetic-error"
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('positive axis', solve(float(N*N),0.0), [render(float(N)),"0"])
check('negative axis above', solve(-float(N*N),0.0), ["0",render(float(N))])
check('negative axis below', solve(-float(N*N),-0.0), ["0",render(-float(N))])
check('upper quadrant', solve(3.0,4.0), ["2","1"])
check('lower quadrant', solve(3.0,-4.0), ["2","-1"])
check('negative real quadrant', solve(-3.0,4.0), ["1","2"])
check('huge axis', solve(1e308,0.0), ["1e+154","0"])
check('tiny imaginary', solve(4.0,N*1e-200), ["2",render(N*1e-200/4)])
check('origin above', solve(0.0,0.0), ["0","0"])
check('origin below', solve(0.0,-0.0), ["0","-0"])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| positive axis | ['1', '0'] | ['1', '0'] | Passed |
| negative axis above | ['0', '1'] | ['0', '1'] | Passed |
| negative axis below | ['0', '-1'] | ['0', '-1'] | Passed |
| upper quadrant | ['2', '1'] | ['2', '1'] | Passed |
| lower quadrant | ['2', '-1'] | ['2', '-1'] | Passed |
| negative real quadrant | ['1', '2'] | ['1', '2'] | Passed |
| huge axis | ['1e+154', '0'] | ['1e+154', '0'] | Passed |
| tiny imaginary | ['2', '0'] | ['2', '2.5e-201'] | Failed |
| origin above | ['0', '0'] | ['0', '0'] | Passed |
| origin below | ['0', '-0'] | ['0', '-0'] | Passed |
SHA-256 / d02f5ee265ed7002b1a7f652b5a550c4f99919021ea401356a9f8ccc36948921
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
def render(x):
if math.isnan(x): return 'nan'
if math.isinf(x): return '-infinity' if x<0 else '+infinity'
return format(x,'.11g')
N = 1
observations = []
def solve(x,y):
try:
if x==0 and y==0: return ['0',render(y)]
r=math.hypot(x,y)
t=math.sqrt(r/2+abs(x)/2)
if x>=0:
real=t
imag=y/(2*t)
else:
imag=math.copysign(t,y)
real=abs(y)/(2*t)
return [render(real),render(imag)]
except (ValueError, OverflowError, ZeroDivisionError, TypeError):
return "arithmetic-error"
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('positive axis', solve(float(N*N),0.0), [render(float(N)),"0"])
check('negative axis above', solve(-float(N*N),0.0), ["0",render(float(N))])
check('negative axis below', solve(-float(N*N),-0.0), ["0",render(-float(N))])
check('upper quadrant', solve(3.0,4.0), ["2","1"])
check('lower quadrant', solve(3.0,-4.0), ["2","-1"])
check('negative real quadrant', solve(-3.0,4.0), ["1","2"])
check('huge axis', solve(1e308,0.0), ["1e+154","0"])
check('tiny imaginary', solve(4.0,N*1e-200), ["2",render(N*1e-200/4)])
check('origin above', solve(0.0,0.0), ["0","0"])
check('origin below', solve(0.0,-0.0), ["0","-0"])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| positive axis | ['1', '0'] | ['1', '0'] | Passed |
| negative axis above | ['0', '1'] | ['0', '1'] | Passed |
| negative axis below | ['0', '-1'] | ['0', '-1'] | Passed |
| upper quadrant | ['2', '1'] | ['2', '1'] | Passed |
| lower quadrant | ['2', '-1'] | ['2', '-1'] | Passed |
| negative real quadrant | ['1', '2'] | ['1', '2'] | Passed |
| huge axis | ['1e+154', '0'] | ['1e+154', '0'] | Passed |
| tiny imaginary | ['2', '2.5e-201'] | ['2', '2.5e-201'] | Passed |
| origin above | ['0', '0'] | ['0', '0'] | Passed |
| origin below | ['0', '-0'] | ['0', '-0'] | Passed |
SHA-256 / 9a44494b75975666e33f4c600a76b1f2e736a5bb390106b9c4809fc638a9569d
Verification & scope
Controlled binary64 or explicitly stipulated miniature format; no hardware exception flags or platform floating environment are modeled. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:39:36.377226+00:00.
Case digest / 579489d3631f1b5d8149763798a2083e98751f1b65556b5ca2d0f6aa37858d11