FAILURE MAP
← Case archive

FA-16356 / Floating-point arithmetic / Open access

Cosine decrement subtracts one after rounding · case 01

Cosine decrement subtracts one after rounding.

Verified by executionVariant 1 · 7 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Cosine decrement subtracts one after rounding. The faulty expression is result=math.cos(x)-1.

VERIFIED REPAIR

Apply the contract at this fault site using result=-2*s*s.

Unsuccessful approach: The attempted local correction result=min(0.0,math.cos(x)-1) still violates the explicit regression fixtures.

Case contract

Evaluate cos(x)-1 for finite x without cancellation using the half-angle identity. 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:
        if x==0: return '-0'
        s=math.sin(x/2)
        result=math.cos(x)-1
        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('tiny', solve(N*2.0**-30), render(-0.5*(N*2.0**-30)**2))
check('negative tiny', solve(-N*2.0**-30), render(-0.5*(N*2.0**-30)**2))
check('normal', solve(float(N)), render(-2*math.sin(N/2)**2))
check('negative normal', solve(-float(N)), render(-2*math.sin(N/2)**2))
check('zero', solve(0.0), "-0")
check('pi', solve(math.pi), "-2")
check('half pi', solve(math.pi/2), "-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 fixtureActualExpectedOutcome
tiny0-4.3368086899e-19Failed
negative tiny0-4.3368086899e-19Failed
normal-0.45969769413-0.45969769413Passed
negative normal-0.45969769413-0.45969769413Passed
zero-0-0Passed
pi-2-2Passed
half pi-1-1Passed

SHA-256 / 62ee63816fdfdf0ba30736c8c469bbed37454b9784e083324e6ecf68d1249c4e

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:
        if x==0: return '-0'
        s=math.sin(x/2)
        result=min(0.0,math.cos(x)-1)
        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('tiny', solve(N*2.0**-30), render(-0.5*(N*2.0**-30)**2))
check('negative tiny', solve(-N*2.0**-30), render(-0.5*(N*2.0**-30)**2))
check('normal', solve(float(N)), render(-2*math.sin(N/2)**2))
check('negative normal', solve(-float(N)), render(-2*math.sin(N/2)**2))
check('zero', solve(0.0), "-0")
check('pi', solve(math.pi), "-2")
check('half pi', solve(math.pi/2), "-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 fixtureActualExpectedOutcome
tiny0-4.3368086899e-19Failed
negative tiny0-4.3368086899e-19Failed
normal-0.45969769413-0.45969769413Passed
negative normal-0.45969769413-0.45969769413Passed
zero-0-0Passed
pi-2-2Passed
half pi-1-1Passed

SHA-256 / 4bcbbb0f8e0e56c1d1eb9c004036309efc7de77541cb4e9f25bee9a6c57734e7

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):
    try:
        if x==0: return '-0'
        s=math.sin(x/2)
        result=-2*s*s
        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('tiny', solve(N*2.0**-30), render(-0.5*(N*2.0**-30)**2))
check('negative tiny', solve(-N*2.0**-30), render(-0.5*(N*2.0**-30)**2))
check('normal', solve(float(N)), render(-2*math.sin(N/2)**2))
check('negative normal', solve(-float(N)), render(-2*math.sin(N/2)**2))
check('zero', solve(0.0), "-0")
check('pi', solve(math.pi), "-2")
check('half pi', solve(math.pi/2), "-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 fixtureActualExpectedOutcome
tiny-4.3368086899e-19-4.3368086899e-19Passed
negative tiny-4.3368086899e-19-4.3368086899e-19Passed
normal-0.45969769413-0.45969769413Passed
negative normal-0.45969769413-0.45969769413Passed
zero-0-0Passed
pi-2-2Passed
half pi-1-1Passed

SHA-256 / 574c04d51a1b28a816c764b6b202eef5b0e3c80f7a3240d643a5f67654f8271c

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:35.405501+00:00.

Case digest / 20460f7035b818a7a53181896d32a42cfe1eb031b9103c20cf95409d43ae497e