FA-16441 / Floating-point arithmetic / Open access
Complex square root adds signed real part in its stable magnitude · case 01
Complex square root adds signed real part in its stable magnitude.
ROOT CAUSE
Complex square root adds signed real part in its stable magnitude. The faulty expression is t=math.sqrt(r/2+x/2).
VERIFIED REPAIR
Apply the contract at this fault site using t=math.sqrt(r/2+abs(x)/2).
Unsuccessful approach: The attempted local correction t=math.sqrt(abs(r/2+x/2)) 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+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 | arithmetic-error | ['0', '1'] | Failed |
| negative axis below | arithmetic-error | ['0', '-1'] | Failed |
| upper quadrant | ['2', '1'] | ['2', '1'] | Passed |
| lower quadrant | ['2', '-1'] | ['2', '-1'] | Passed |
| negative real quadrant | ['2', '1'] | ['1', '2'] | Failed |
| 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 / fdcf99f9cf506fa9f4e4d790ef41971f0f516ac902215c1f146d385895ce70b6
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(abs(r/2+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 | arithmetic-error | ['0', '1'] | Failed |
| negative axis below | arithmetic-error | ['0', '-1'] | Failed |
| upper quadrant | ['2', '1'] | ['2', '1'] | Passed |
| lower quadrant | ['2', '-1'] | ['2', '-1'] | Passed |
| negative real quadrant | ['2', '1'] | ['1', '2'] | Failed |
| 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 / 2f315c41837765c9778806d3b8da61cf1967c136fce01857e06e21ebfef4d9af
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.331838+00:00.
Case digest / f8383e2bc42e5a7dd5362cd4218dbe9e69d2e73a90ae38b2b84637e436590b6d