FA-16716 / Floating-point arithmetic / Open access
Quadratic roots compute the small root by subtraction · case 01
Quadratic roots compute the small root by subtraction.
ROOT CAUSE
Quadratic roots compute the small root by subtraction. The faulty expression is r2=(-b+math.sqrt(d))/(2*a).
VERIFIED REPAIR
Apply the contract at this fault site using r2=c/q.
Unsuccessful approach: The attempted local correction r2=(-b-math.sqrt(d))/(2*a) still violates the explicit regression fixtures.
Case contract
Real roots of a*x*x+b*x+c=0 for finite coefficients with bounded discriminant products. Use sign-aware q to avoid subtractive cancellation and c/q for the complementary root. Return sorted rendered roots, repeated root once, or explicit degenerate/no-real markers. 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(a,b,c):
try:
if a==0:
return [render(-c/b)] if b!=0 else ('all' if c==0 else 'none')
d=b*b-4*a*c
if d<0: return 'no-real'
if d==0: return [render(-b/(2*a))]
s=math.sqrt(d)
q=-0.5*(b+math.copysign(s,b))
r1=q/a
r2=(-b+math.sqrt(d))/(2*a)
return [render(v) for v in sorted([r1,r2])]
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('large positive b', solve(1.0,1e16*N,1.0), [render(-1e16*N),render(-1/(1e16*N))])
check('large negative b', solve(1.0,-1e16*N,1.0), [render(1/(1e16*N)),render(1e16*N)])
check('normal roots', solve(1.0,-3.0,2.0), ["1","2"])
check('repeated', solve(1.0,-2.0*N,float(N*N)), [render(float(N))])
check('linear', solve(0.0,2.0,-2.0*N), [render(float(N))])
check('no real', solve(1.0,0.0,float(N)), "no-real")
check('all', solve(0.0,0.0,0.0), "all")
check('inconsistent', solve(0.0,0.0,float(N)), "none")
check('zero constant', solve(1.0,-float(N),0.0), ["0",render(float(N))])
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 |
|---|---|---|---|
| large positive b | ['-1e+16', '0'] | ['-1e+16', '-1e-16'] | Failed |
| large negative b | ['1e+16', '1e+16'] | ['1e-16', '1e+16'] | Failed |
| normal roots | ['2', '2'] | ['1', '2'] | Failed |
| repeated | ['1'] | ['1'] | Passed |
| linear | ['1'] | ['1'] | Passed |
| no real | no-real | no-real | Passed |
| all | all | all | Passed |
| inconsistent | none | none | Passed |
| zero constant | ['1', '1'] | ['0', '1'] | Failed |
SHA-256 / 23f633c6f01d903683a206fee7447ba13a3ac05bcf7ba8c9803df3957e431adf
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(a,b,c):
try:
if a==0:
return [render(-c/b)] if b!=0 else ('all' if c==0 else 'none')
d=b*b-4*a*c
if d<0: return 'no-real'
if d==0: return [render(-b/(2*a))]
s=math.sqrt(d)
q=-0.5*(b+math.copysign(s,b))
r1=q/a
r2=(-b-math.sqrt(d))/(2*a)
return [render(v) for v in sorted([r1,r2])]
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('large positive b', solve(1.0,1e16*N,1.0), [render(-1e16*N),render(-1/(1e16*N))])
check('large negative b', solve(1.0,-1e16*N,1.0), [render(1/(1e16*N)),render(1e16*N)])
check('normal roots', solve(1.0,-3.0,2.0), ["1","2"])
check('repeated', solve(1.0,-2.0*N,float(N*N)), [render(float(N))])
check('linear', solve(0.0,2.0,-2.0*N), [render(float(N))])
check('no real', solve(1.0,0.0,float(N)), "no-real")
check('all', solve(0.0,0.0,0.0), "all")
check('inconsistent', solve(0.0,0.0,float(N)), "none")
check('zero constant', solve(1.0,-float(N),0.0), ["0",render(float(N))])
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 |
|---|---|---|---|
| large positive b | ['-1e+16', '-1e+16'] | ['-1e+16', '-1e-16'] | Failed |
| large negative b | ['0', '1e+16'] | ['1e-16', '1e+16'] | Failed |
| normal roots | ['1', '2'] | ['1', '2'] | Passed |
| repeated | ['1'] | ['1'] | Passed |
| linear | ['1'] | ['1'] | Passed |
| no real | no-real | no-real | Passed |
| all | all | all | Passed |
| inconsistent | none | none | Passed |
| zero constant | ['0', '1'] | ['0', '1'] | Passed |
SHA-256 / d712f33628472a045c3c9c8875d66d888d0c1c4fee909df371a04123268a09b7
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(a,b,c):
try:
if a==0:
return [render(-c/b)] if b!=0 else ('all' if c==0 else 'none')
d=b*b-4*a*c
if d<0: return 'no-real'
if d==0: return [render(-b/(2*a))]
s=math.sqrt(d)
q=-0.5*(b+math.copysign(s,b))
r1=q/a
r2=c/q
return [render(v) for v in sorted([r1,r2])]
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('large positive b', solve(1.0,1e16*N,1.0), [render(-1e16*N),render(-1/(1e16*N))])
check('large negative b', solve(1.0,-1e16*N,1.0), [render(1/(1e16*N)),render(1e16*N)])
check('normal roots', solve(1.0,-3.0,2.0), ["1","2"])
check('repeated', solve(1.0,-2.0*N,float(N*N)), [render(float(N))])
check('linear', solve(0.0,2.0,-2.0*N), [render(float(N))])
check('no real', solve(1.0,0.0,float(N)), "no-real")
check('all', solve(0.0,0.0,0.0), "all")
check('inconsistent', solve(0.0,0.0,float(N)), "none")
check('zero constant', solve(1.0,-float(N),0.0), ["0",render(float(N))])
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 |
|---|---|---|---|
| large positive b | ['-1e+16', '-1e-16'] | ['-1e+16', '-1e-16'] | Passed |
| large negative b | ['1e-16', '1e+16'] | ['1e-16', '1e+16'] | Passed |
| normal roots | ['1', '2'] | ['1', '2'] | Passed |
| repeated | ['1'] | ['1'] | Passed |
| linear | ['1'] | ['1'] | Passed |
| no real | no-real | no-real | Passed |
| all | all | all | Passed |
| inconsistent | none | none | Passed |
| zero constant | ['0', '1'] | ['0', '1'] | Passed |
SHA-256 / c821538eaac37cd1b9ec3c4973814f85efffa66e5c2360a75d333aa28d2ff975
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:39.016765+00:00.
Case digest / a4609df7f2777b29bff7362307e5e3196684ba577b949fc8c541622366f35859