FAILURE MAP
← Case archive

FA-6341 / Statistics / Open access

Frequency distribution entropy bits · case 01

Natural logarithms return nats under a bits contract.

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

ROOT CAUSE

Natural logarithms return nats under a bits contract.

VERIFIED REPAIR

Apply the specified mathematical contract directly, preserving all terms and boundary cases: return round(-sum((c/sum(counts))*math.log2(c/sum(counts)) for c in counts if c),10) if sum(counts) else None

Unsuccessful approach: Maximum entropy assumes all listed categories have equal mass.

Case contract

Integer finite observations and equal lengths for paired samples. Counts and weights are nonnegative. Rational results use reduced Fraction strings. Empty or undefined statistics return None where shown. Nonnegative frequency counts; ignore zero-probability terms and return None for zero total. Round base-two Shannon entropy to ten decimal places. Exact operational definition: round(-sum((c/sum(counts))*math.log2(c/sum(counts)) for c in counts if c),10) if sum(counts) else None

Why this case matters

Small exact fixtures expose this error without platform timing, external services, or probabilistic observations. Statistical estimators 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(counts):
    return round(-sum((c/sum(counts))*math.log(c/sum(counts)) for c in counts if c),10) if sum(counts) else None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: ([1, 1],)', solve(*([1, 1],)), 1.0)
check('fixture 2: ([1, 1, 1, 1],)', solve(*([1, 1, 1, 1],)), 2.0)
check('fixture 3: ([5, 0],)', solve(*([5, 0],)), 0.0)
check('fixture 4: ([0, 0],)', solve(*([0, 0],)), None)
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: ([1, 1],)0.69314718061.0Failed
fixture 2: ([1, 1, 1, 1],)1.38629436112.0Failed
fixture 3: ([5, 0],)-0.00.0Passed
fixture 4: ([0, 0],)NoneNonePassed

SHA-256 / a527930749516a8b3abee4c281285591dbf062d3f3daed9c4b96895de235fc59

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(counts):
    return round(math.log2(len(counts)),10) if counts else None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: ([1, 1],)', solve(*([1, 1],)), 1.0)
check('fixture 2: ([1, 1, 1, 1],)', solve(*([1, 1, 1, 1],)), 2.0)
check('fixture 3: ([5, 0],)', solve(*([5, 0],)), 0.0)
check('fixture 4: ([0, 0],)', solve(*([0, 0],)), None)
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: ([1, 1],)1.01.0Passed
fixture 2: ([1, 1, 1, 1],)2.02.0Passed
fixture 3: ([5, 0],)1.00.0Failed
fixture 4: ([0, 0],)1.0NoneFailed

SHA-256 / 8ba5338ab0d11b19a8c3ca1cc833ca7d0e00780acfa925e618cec330d7e9e33b

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(counts):
    return round(-sum((c/sum(counts))*math.log2(c/sum(counts)) for c in counts if c),10) if sum(counts) else None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: ([1, 1],)', solve(*([1, 1],)), 1.0)
check('fixture 2: ([1, 1, 1, 1],)', solve(*([1, 1, 1, 1],)), 2.0)
check('fixture 3: ([5, 0],)', solve(*([5, 0],)), 0.0)
check('fixture 4: ([0, 0],)', solve(*([0, 0],)), None)
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: ([1, 1],)1.01.0Passed
fixture 2: ([1, 1, 1, 1],)2.02.0Passed
fixture 3: ([5, 0],)-0.00.0Passed
fixture 4: ([0, 0],)NoneNonePassed

SHA-256 / dae6ae204dbd73339d2e73c9c25285eb7e50fd3d02298204fefbc04ba10bd6b7

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

Case digest / 2d204d5aa125f5dfb9fa7c0a74a8aba25ecc0f4c91c5a616f5b8b17f6e4b8627