FA-5416 / Integer arithmetic / Open access
Population count width mask · case 01
Counting the Python magnitude ignores finite-word two-complement representation.
ROOT CAUSE
Counting the Python magnitude ignores finite-word two-complement representation.
VERIFIED REPAIR
Apply the specified mathematical contract directly, preserving all terms and boundary cases: return bin(n & ((1<<bits)-1)).count("1")
Unsuccessful approach: Absolute value does not model sign-extension or high-bit masking.
Case contract
Integer arguments; denominators, steps, moduli, and bit widths are positive. Unsigned word inputs fit the specified width except where masking is explicitly the operation. Sequence sizes are nonnegative. n may be any signed integer; count set bits in its low bits-bit word. Exact operational definition: bin(n & ((1<<bits)-1)).count("1")
Why this case matters
Small exact fixtures expose this error without platform timing, external services, or probabilistic observations. Integer mathematics results depend on the stated convention.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
import calendar
import statistics
import itertools
from fractions import Fraction
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN, ROUND_CEILING, ROUND_FLOOR
N = 1
observations = []
def solve(n, bits):
return bin(n).count("1")
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: (-1, 8)', solve(*(-1, 8)), 8)
check('fixture 2: (-2, 8)', solve(*(-2, 8)), 7)
check('fixture 3: (256, 8)', solve(*(256, 8)), 0)
check('fixture 4: (5, 8)', solve(*(5, 8)), 2)
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 |
|---|---|---|---|
| fixture 1: (-1, 8) | 1 | 8 | Failed |
| fixture 2: (-2, 8) | 1 | 7 | Failed |
| fixture 3: (256, 8) | 1 | 0 | Failed |
| fixture 4: (5, 8) | 2 | 2 | Passed |
SHA-256 / 112ef5f02dadae5bbac39f5c98e4ed5ccc426cbc95e25de138dcf475b82002fc
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
import calendar
import statistics
import itertools
from fractions import Fraction
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN, ROUND_CEILING, ROUND_FLOOR
N = 1
observations = []
def solve(n, bits):
return bin(abs(n)).count("1")
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: (-1, 8)', solve(*(-1, 8)), 8)
check('fixture 2: (-2, 8)', solve(*(-2, 8)), 7)
check('fixture 3: (256, 8)', solve(*(256, 8)), 0)
check('fixture 4: (5, 8)', solve(*(5, 8)), 2)
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 |
|---|---|---|---|
| fixture 1: (-1, 8) | 1 | 8 | Failed |
| fixture 2: (-2, 8) | 1 | 7 | Failed |
| fixture 3: (256, 8) | 1 | 0 | Failed |
| fixture 4: (5, 8) | 2 | 2 | Passed |
SHA-256 / e2c6328f9b6278602019bcb35962cdb924ac3255c3781d00d8e055fb39c48a16
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
import calendar
import statistics
import itertools
from fractions import Fraction
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN, ROUND_CEILING, ROUND_FLOOR
N = 1
observations = []
def solve(n, bits):
return bin(n & ((1<<bits)-1)).count("1")
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: (-1, 8)', solve(*(-1, 8)), 8)
check('fixture 2: (-2, 8)', solve(*(-2, 8)), 7)
check('fixture 3: (256, 8)', solve(*(256, 8)), 0)
check('fixture 4: (5, 8)', solve(*(5, 8)), 2)
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 |
|---|---|---|---|
| fixture 1: (-1, 8) | 8 | 8 | Passed |
| fixture 2: (-2, 8) | 7 | 7 | Passed |
| fixture 3: (256, 8) | 0 | 0 | Passed |
| fixture 4: (5, 8) | 2 | 2 | Passed |
SHA-256 / 44407695a58b800b1d3edf53a6c764c56ffecc645ce5ece4b7a5d6ff9f41e1a4
Verification & scope
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:37:49.412408+00:00.
Case digest / 279ff10f48dfb98719a4a55830647df9b69be1d788bcb0e69782a9f81b320530