FA-16781 / Floating-point arithmetic / Open access
Cosine-pi evaluates the negative branch directly near a half integer · case 01
Cosine-pi evaluates the negative branch directly near a half integer.
ROOT CAUSE
Cosine-pi evaluates the negative branch directly near a half integer. The faulty expression is result=math.cos(math.pi*r).
THE FAILURE
Cosine-pi evaluates the negative branch directly near a half integer. The faulty expression is result=math.cos(math.pi*r).
Unsuccessful approach: The attempted local correction result=min(0.0,math.cos(math.pi*r)) still violates the explicit regression fixtures.
Case contract
Evaluate cos(pi*x) for finite x after modulo-two reduction. Half integers return positive zero; integers are exact; near half integers use a sine of the distance to the half integer. 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):
try:
r=abs(math.remainder(x,2.0))
if r==0: return '1'
if r==1: return '-1'
if r==0.5: return '0'
if r<0.5:
result=math.sin(math.pi*(0.5-r))
else:
result=math.cos(math.pi*r)
return render(result)
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('even integer', solve(2.0*N), "1")
check('odd integer', solve(2.0*N+1), "-1")
check('negative integer', solve(-2.0*N-1), "-1")
check('half integer', solve(2.0*N+0.5), "0")
check('quarter', solve(0.25), render(math.sqrt(0.5)))
check('three quarters', solve(0.75), render(-math.sqrt(0.5)))
check('near half below', solve(0.5-N*2.0**-50), render(math.sin(math.pi*N*2.0**-50)))
check('near half above', solve(0.5+N*2.0**-50), render(-math.sin(math.pi*N*2.0**-50)))
check('negative half', solve(-0.5), "0")
check('negative quarter', solve(-0.25), render(math.sqrt(0.5)))
check('large integer', solve(2.0**52+2*N), "1")
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 |
|---|---|---|---|
| even integer | 1 | 1 | Passed |
| odd integer | -1 | -1 | Passed |
| negative integer | -1 | -1 | Passed |
| half integer | 0 | 0 | Passed |
| quarter | 0.70710678119 | 0.70710678119 | Passed |
| three quarters | -0.70710678119 | -0.70710678119 | Passed |
| near half below | 2.7902947984e-15 | 2.7902947984e-15 | Passed |
| near half above | -2.8253475241e-15 | -2.7902947984e-15 | Failed |
| negative half | 0 | 0 | Passed |
| negative quarter | 0.70710678119 | 0.70710678119 | Passed |
| large integer | 1 | 1 | Passed |
SHA-256 / 8dd0290dc8be4ee390e40a151e542a854a765a074333e15058358b43501d7cf5
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):
try:
r=abs(math.remainder(x,2.0))
if r==0: return '1'
if r==1: return '-1'
if r==0.5: return '0'
if r<0.5:
result=math.sin(math.pi*(0.5-r))
else:
result=min(0.0,math.cos(math.pi*r))
return render(result)
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('even integer', solve(2.0*N), "1")
check('odd integer', solve(2.0*N+1), "-1")
check('negative integer', solve(-2.0*N-1), "-1")
check('half integer', solve(2.0*N+0.5), "0")
check('quarter', solve(0.25), render(math.sqrt(0.5)))
check('three quarters', solve(0.75), render(-math.sqrt(0.5)))
check('near half below', solve(0.5-N*2.0**-50), render(math.sin(math.pi*N*2.0**-50)))
check('near half above', solve(0.5+N*2.0**-50), render(-math.sin(math.pi*N*2.0**-50)))
check('negative half', solve(-0.5), "0")
check('negative quarter', solve(-0.25), render(math.sqrt(0.5)))
check('large integer', solve(2.0**52+2*N), "1")
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 |
|---|---|---|---|
| even integer | 1 | 1 | Passed |
| odd integer | -1 | -1 | Passed |
| negative integer | -1 | -1 | Passed |
| half integer | 0 | 0 | Passed |
| quarter | 0.70710678119 | 0.70710678119 | Passed |
| three quarters | -0.70710678119 | -0.70710678119 | Passed |
| near half below | 2.7902947984e-15 | 2.7902947984e-15 | Passed |
| near half above | -2.8253475241e-15 | -2.7902947984e-15 | Failed |
| negative half | 0 | 0 | Passed |
| negative quarter | 0.70710678119 | 0.70710678119 | Passed |
| large integer | 1 | 1 | Passed |
SHA-256 / a1956576f47754e7e2b82255788f989b9a47fdb19c27fe8395e8c1ab476579c9
HELD IN THE MEMBER ARCHIVE
The verified repair and its recorded checks are member-only.
This mechanism has 11 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.
Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.
Member access is invitation-based. Sign in with your invited account to inspect the repair.
Sign in to the archive ↗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:40.135289+00:00.
Case digest / 17d59c3fcc05531bbcf5b3bb21837e23403763ade9ded5301cb0b6a4c69d8188