FAILURE MAP
← Case archive

FA-5411 / Integer arithmetic / Open access

Next power of two inclusive · case 01

Bit length advances exact powers unnecessarily.

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

ROOT CAUSE

Bit length advances exact powers unnecessarily.

VERIFIED REPAIR

Apply the specified mathematical contract directly, preserving all terms and boundary cases: return 1 if n <= 1 else 1 << (n-1).bit_length()

Unsuccessful approach: Rounding downward cannot enclose a nonpower.

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 is nonnegative; return the least positive power of two >=n. Exact operational definition: 1 if n <= 1 else 1 << (n-1).bit_length()

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):
    return 1 << n.bit_length()
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: (0,)', solve(*(0,)), 1)
check('fixture 2: (1,)', solve(*(1,)), 1)
check('fixture 3: (8,)', solve(*(8,)), 8)
check('fixture 4: (9,)', solve(*(9,)), 16)
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
fixture 1: (0,)11Passed
fixture 2: (1,)21Failed
fixture 3: (8,)168Failed
fixture 4: (9,)1616Passed

SHA-256 / 8129e432aa582ddccc36c5566e855b4b1dfb7f03b8740e670f263914b27c5dff

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):
    return 1 << max(0,n.bit_length()-1)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: (0,)', solve(*(0,)), 1)
check('fixture 2: (1,)', solve(*(1,)), 1)
check('fixture 3: (8,)', solve(*(8,)), 8)
check('fixture 4: (9,)', solve(*(9,)), 16)
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
fixture 1: (0,)11Passed
fixture 2: (1,)11Passed
fixture 3: (8,)88Passed
fixture 4: (9,)816Failed

SHA-256 / 383375f620cce9a14e23f972469eab44ccb24d83fd52e4f20388acbabbbb8d0e

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):
    return 1 if n <= 1 else 1 << (n-1).bit_length()
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: (0,)', solve(*(0,)), 1)
check('fixture 2: (1,)', solve(*(1,)), 1)
check('fixture 3: (8,)', solve(*(8,)), 8)
check('fixture 4: (9,)', solve(*(9,)), 16)
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
fixture 1: (0,)11Passed
fixture 2: (1,)11Passed
fixture 3: (8,)88Passed
fixture 4: (9,)1616Passed

SHA-256 / a86c2f8ef42f1966c0fe3a91412a17c667b13a2a7d78f9205f1879e0ec8ed4cb

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

Case digest / 684a79bea92595741feb25d3f6361ca5b656917c0a035f50bc4f582b7e7c8a31