FA-16796 / Floating-point arithmetic / Open access
Cosine-pi derives half-integer zero by a rounded cosine · case 01
Cosine-pi derives half-integer zero by a rounded cosine.
ROOT CAUSE
Cosine-pi derives half-integer zero by a rounded cosine. The faulty expression is if r==0.5: return render(math.cos(math.pi*r)).
THE FAILURE
Cosine-pi derives half-integer zero by a rounded cosine. The faulty expression is if r==0.5: return render(math.cos(math.pi*r)).
Unsuccessful approach: The attempted local correction if r==0.5: return '-0' 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 render(math.cos(math.pi*r))
if r<0.5:
result=math.sin(math.pi*(0.5-r))
else:
result=-math.sin(math.pi*(r-0.5))
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 | 6.1232339957e-17 | 0 | Failed |
| 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.7902947984e-15 | -2.7902947984e-15 | Passed |
| negative half | 6.1232339957e-17 | 0 | Failed |
| negative quarter | 0.70710678119 | 0.70710678119 | Passed |
| large integer | 1 | 1 | Passed |
SHA-256 / bba9aea5e7f39c16f2f18157cf8ea10aab84003ac8e4fdb15194f2b46e49b3e2
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=-math.sin(math.pi*(r-0.5))
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 | Failed |
| 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.7902947984e-15 | -2.7902947984e-15 | Passed |
| negative half | -0 | 0 | Failed |
| negative quarter | 0.70710678119 | 0.70710678119 | Passed |
| large integer | 1 | 1 | Passed |
SHA-256 / 3fa8c57d190bc42025fe4ae3f3ed46ae2e9a19418db59de7058e5d1b14fdfc00
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 / bfc1db2aeea2139bfab06b9a5d94fc092ca71200d7aed4bd23324de2a30bba34