FA-16741 / Floating-point arithmetic / Open access
Quadratic solver reflects a negative discriminant · case 01
Quadratic solver reflects a negative discriminant.
ROOT CAUSE
Quadratic solver reflects a negative discriminant. The faulty expression is if d<0: d=abs(d).
VERIFIED REPAIR
Apply the contract at this fault site using if d<0: return 'no-real'.
Unsuccessful approach: The attempted local correction if d<0: d=0.0 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: d=abs(d)
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 | ['-1', '-1'] | no-real | Failed |
| all | all | all | Passed |
| inconsistent | none | none | Passed |
| zero constant | ['0', '1'] | ['0', '1'] | Passed |
SHA-256 / e7260663f57aed9a78359d31f901f30e1653df6746a290b352374bbbceebee83
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: d=0.0
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 | ['-0'] | no-real | Failed |
| all | all | all | Passed |
| inconsistent | none | none | Passed |
| zero constant | ['0', '1'] | ['0', '1'] | Passed |
SHA-256 / 80be9e1e7ab45c1a156a6d39b5f8ba97faea4c34aea673a15b1eafbf805fc004
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.466454+00:00.
Case digest / 5969e2c939bbb7f1ddbdf74dae0b9e68320027fe0b234d5c474e3c9b80c37374