FA-15221 / Numerics / Open access
Multiset permutation unrank: duplicate block normalization · case 01
The exact multiset permutation unrank result violates the stated contract at duplicate block normalization.
ROOT CAUSE
The duplicate block normalization step uses math.factorial(sum(counts.values())) instead of ways(counts).
VERIFIED REPAIR
Use ways(counts) at the duplicate block normalization step.
Unsuccessful approach: The partial repair max(1,ways(counts)//2) still violates the duplicate block normalization invariant.
Case contract
Input [sorted multiset of small integer symbols, rank], valid zero-based lexicographic rank among distinct permutations.
Why this case matters
Exact discrete arithmetic with observable algorithmic state; no floating point approximation is used.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
import itertools
from fractions import Fraction
N = 1
observations = []
def solve(x):
items,r=x
from collections import Counter
counts=Counter(items);out=[]
def ways(c):
v=math.factorial(sum(c.values()))
for n in c.values():v//=math.factorial(n)
return v
for _ in range(len(items)):
for symbol in sorted(counts):
if counts[symbol]==0:continue
counts[symbol]-=1
block=math.factorial(sum(counts.values()))
if r<block:
out.append(symbol)
break
r=r-block
counts[symbol]=counts[symbol]+1
else:return None
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([[0, 1, 1, 2], 3], [1, 0, 1, 2]), ([[0, 0, 1], 1], [0, 1, 0]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 1], 2], [1, 0, 0]), ([[0, 1, 1, 2], 0], [0, 1, 1, 2]), ([[0, 1, 1, 2], 1], [0, 1, 2, 1]), ([[0, 1, 1, 2], 2], [0, 2, 1, 1])], [([[0, 1, 1, 2], 4], [1, 0, 2, 1]), ([[0, 1, 1, 2], 2], [0, 2, 1, 1]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 1, 1], 2], [0, 1, 1, 0]), ([[0, 0, 1, 1], 3], [1, 0, 0, 1]), ([[0, 0, 1, 1], 4], [1, 0, 1, 0]), ([[0, 0, 1, 1], 5], [1, 1, 0, 0])], [([[0, 1, 1, 2], 5], [1, 1, 0, 2]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 0, 1, 2], 13], [1, 0, 0, 2, 0]), ([[0, 0, 0, 1, 2], 14], [1, 0, 2, 0, 0]), ([[0, 0, 0, 1, 2], 15], [1, 2, 0, 0, 0]), ([[0, 0, 0, 1, 2], 16], [2, 0, 0, 0, 1]), ([[0, 0, 0, 1, 2], 17], [2, 0, 0, 1, 0])], [([[0, 1, 1, 2], 6], [1, 1, 2, 0]), ([[0, 1, 1, 2], 8], [1, 2, 1, 0]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 1, 2, 3], 10], [1, 3, 0, 2]), ([[0, 1, 2, 3], 11], [1, 3, 2, 0]), ([[0, 1, 2, 3], 12], [2, 0, 1, 3]), ([[0, 1, 2, 3], 13], [2, 0, 3, 1])], [([[0, 1, 1, 2], 7], [1, 2, 0, 1]), ([[0, 1, 1, 2], 11], [2, 1, 1, 0]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[1, 1, 2, 2, 3], 3], [1, 2, 1, 2, 3]), ([[1, 1, 2, 2, 3], 4], [1, 2, 1, 3, 2]), ([[1, 1, 2, 2, 3], 5], [1, 2, 2, 1, 3]), ([[1, 1, 2, 2, 3], 6], [1, 2, 2, 3, 1])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("explicit oracle %d" % i, solve(args), expected)
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 |
|---|---|---|---|
| explicit oracle 0 | None | [1, 0, 1, 2] | Failed |
| explicit oracle 1 | [0, 1, 0] | [0, 1, 0] | Passed |
| explicit oracle 2 | [0, 0, 1] | [0, 0, 1] | Passed |
| explicit oracle 3 | [2, 1, 3, 2, 1] | [3, 2, 2, 1, 1] | Failed |
| explicit oracle 4 | [1, 0, 0] | [1, 0, 0] | Passed |
| explicit oracle 5 | [0, 1, 1, 2] | [0, 1, 1, 2] | Passed |
| explicit oracle 6 | [0, 1, 2, 1] | [0, 1, 2, 1] | Passed |
| explicit oracle 7 | [0, 2, 1, 1] | [0, 2, 1, 1] | Passed |
SHA-256 / 438f0f4c89d14930d780f2a0eaae51b222366ca52ffceb3c32f683de6cf4b830
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
import itertools
from fractions import Fraction
N = 1
observations = []
def solve(x):
items,r=x
from collections import Counter
counts=Counter(items);out=[]
def ways(c):
v=math.factorial(sum(c.values()))
for n in c.values():v//=math.factorial(n)
return v
for _ in range(len(items)):
for symbol in sorted(counts):
if counts[symbol]==0:continue
counts[symbol]-=1
block=max(1,ways(counts)//2)
if r<block:
out.append(symbol)
break
r=r-block
counts[symbol]=counts[symbol]+1
else:return None
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([[0, 1, 1, 2], 3], [1, 0, 1, 2]), ([[0, 0, 1], 1], [0, 1, 0]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 1], 2], [1, 0, 0]), ([[0, 1, 1, 2], 0], [0, 1, 1, 2]), ([[0, 1, 1, 2], 1], [0, 1, 2, 1]), ([[0, 1, 1, 2], 2], [0, 2, 1, 1])], [([[0, 1, 1, 2], 4], [1, 0, 2, 1]), ([[0, 1, 1, 2], 2], [0, 2, 1, 1]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 1, 1], 2], [0, 1, 1, 0]), ([[0, 0, 1, 1], 3], [1, 0, 0, 1]), ([[0, 0, 1, 1], 4], [1, 0, 1, 0]), ([[0, 0, 1, 1], 5], [1, 1, 0, 0])], [([[0, 1, 1, 2], 5], [1, 1, 0, 2]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 0, 1, 2], 13], [1, 0, 0, 2, 0]), ([[0, 0, 0, 1, 2], 14], [1, 0, 2, 0, 0]), ([[0, 0, 0, 1, 2], 15], [1, 2, 0, 0, 0]), ([[0, 0, 0, 1, 2], 16], [2, 0, 0, 0, 1]), ([[0, 0, 0, 1, 2], 17], [2, 0, 0, 1, 0])], [([[0, 1, 1, 2], 6], [1, 1, 2, 0]), ([[0, 1, 1, 2], 8], [1, 2, 1, 0]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 1, 2, 3], 10], [1, 3, 0, 2]), ([[0, 1, 2, 3], 11], [1, 3, 2, 0]), ([[0, 1, 2, 3], 12], [2, 0, 1, 3]), ([[0, 1, 2, 3], 13], [2, 0, 3, 1])], [([[0, 1, 1, 2], 7], [1, 2, 0, 1]), ([[0, 1, 1, 2], 11], [2, 1, 1, 0]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[1, 1, 2, 2, 3], 3], [1, 2, 1, 2, 3]), ([[1, 1, 2, 2, 3], 4], [1, 2, 1, 3, 2]), ([[1, 1, 2, 2, 3], 5], [1, 2, 2, 1, 3]), ([[1, 1, 2, 2, 3], 6], [1, 2, 2, 3, 1])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("explicit oracle %d" % i, solve(args), expected)
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 |
|---|---|---|---|
| explicit oracle 0 | [1, 2, 0, 1] | [1, 0, 1, 2] | Failed |
| explicit oracle 1 | [1, 0, 0] | [0, 1, 0] | Failed |
| explicit oracle 2 | [0, 0, 1] | [0, 0, 1] | Passed |
| explicit oracle 3 | None | [3, 2, 2, 1, 1] | Failed |
| explicit oracle 4 | None | [1, 0, 0] | Failed |
| explicit oracle 5 | [0, 1, 1, 2] | [0, 1, 1, 2] | Passed |
| explicit oracle 6 | [1, 0, 1, 2] | [0, 1, 2, 1] | Failed |
| explicit oracle 7 | [1, 1, 0, 2] | [0, 2, 1, 1] | Failed |
SHA-256 / cd3c13ccd13781422b2e9531612fecba9a67e193d860df296cf8652f3ffac69a
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
import itertools
from fractions import Fraction
N = 1
observations = []
def solve(x):
items,r=x
from collections import Counter
counts=Counter(items);out=[]
def ways(c):
v=math.factorial(sum(c.values()))
for n in c.values():v//=math.factorial(n)
return v
for _ in range(len(items)):
for symbol in sorted(counts):
if counts[symbol]==0:continue
counts[symbol]-=1
block=ways(counts)
if r<block:
out.append(symbol)
break
r=r-block
counts[symbol]=counts[symbol]+1
else:return None
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([[0, 1, 1, 2], 3], [1, 0, 1, 2]), ([[0, 0, 1], 1], [0, 1, 0]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 1], 2], [1, 0, 0]), ([[0, 1, 1, 2], 0], [0, 1, 1, 2]), ([[0, 1, 1, 2], 1], [0, 1, 2, 1]), ([[0, 1, 1, 2], 2], [0, 2, 1, 1])], [([[0, 1, 1, 2], 4], [1, 0, 2, 1]), ([[0, 1, 1, 2], 2], [0, 2, 1, 1]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 1, 1], 2], [0, 1, 1, 0]), ([[0, 0, 1, 1], 3], [1, 0, 0, 1]), ([[0, 0, 1, 1], 4], [1, 0, 1, 0]), ([[0, 0, 1, 1], 5], [1, 1, 0, 0])], [([[0, 1, 1, 2], 5], [1, 1, 0, 2]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 0, 1, 2], 13], [1, 0, 0, 2, 0]), ([[0, 0, 0, 1, 2], 14], [1, 0, 2, 0, 0]), ([[0, 0, 0, 1, 2], 15], [1, 2, 0, 0, 0]), ([[0, 0, 0, 1, 2], 16], [2, 0, 0, 0, 1]), ([[0, 0, 0, 1, 2], 17], [2, 0, 0, 1, 0])], [([[0, 1, 1, 2], 6], [1, 1, 2, 0]), ([[0, 1, 1, 2], 8], [1, 2, 1, 0]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 1, 2, 3], 10], [1, 3, 0, 2]), ([[0, 1, 2, 3], 11], [1, 3, 2, 0]), ([[0, 1, 2, 3], 12], [2, 0, 1, 3]), ([[0, 1, 2, 3], 13], [2, 0, 3, 1])], [([[0, 1, 1, 2], 7], [1, 2, 0, 1]), ([[0, 1, 1, 2], 11], [2, 1, 1, 0]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[1, 1, 2, 2, 3], 3], [1, 2, 1, 2, 3]), ([[1, 1, 2, 2, 3], 4], [1, 2, 1, 3, 2]), ([[1, 1, 2, 2, 3], 5], [1, 2, 2, 1, 3]), ([[1, 1, 2, 2, 3], 6], [1, 2, 2, 3, 1])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("explicit oracle %d" % i, solve(args), expected)
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 |
|---|---|---|---|
| explicit oracle 0 | [1, 0, 1, 2] | [1, 0, 1, 2] | Passed |
| explicit oracle 1 | [0, 1, 0] | [0, 1, 0] | Passed |
| explicit oracle 2 | [0, 0, 1] | [0, 0, 1] | Passed |
| explicit oracle 3 | [3, 2, 2, 1, 1] | [3, 2, 2, 1, 1] | Passed |
| explicit oracle 4 | [1, 0, 0] | [1, 0, 0] | Passed |
| explicit oracle 5 | [0, 1, 1, 2] | [0, 1, 1, 2] | Passed |
| explicit oracle 6 | [0, 1, 2, 1] | [0, 1, 2, 1] | Passed |
| explicit oracle 7 | [0, 2, 1, 1] | [0, 2, 1, 1] | Passed |
SHA-256 / 4a91e4aa7660771e843040f3b8662844a66e4a1468ddc5e09c032721109a671e
Verification & scope
A deterministic bounded teaching model. Inputs are restricted to the explicit contract; this is not a production algebra library. 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:24.622046+00:00.
Case digest / 20ead7d2e77f870373935d8333b0bec721af6a9186728daaea20a83473aba983