FA-15121 / Numerics / Open access
Factoradic permutation unrank: permutation block size · case 01
The exact factoradic permutation unrank result violates the stated contract at permutation block size.
ROOT CAUSE
The permutation block size step uses math.factorial(i+1) instead of math.factorial(i).
VERIFIED REPAIR
Use math.factorial(i) at the permutation block size step.
Unsuccessful approach: The partial repair max(1,i) still violates the permutation block size invariant.
Case contract
Input [n,r], n<=7 and 0<=r<n!; return lexicographic permutation of 0..n-1 at rank r.
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):
n,r=x;pool=list(range(n));out=[]
for i in range(n-1,-1,-1):
block=math.factorial(i+1)
digit=r//block
if digit<0 or digit>=len(pool):return None
out.append(pool.pop(digit))
r=r%block
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([2, 1], [1, 0]), ([4, 3], [0, 2, 3, 1]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([2, 0], [0, 1]), ([3, 0], [0, 1, 2]), ([3, 1], [0, 2, 1]), ([3, 2], [1, 0, 2])], [([3, 1], [0, 2, 1]), ([4, 6], [1, 0, 2, 3]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([4, 8], [1, 2, 0, 3]), ([4, 9], [1, 2, 3, 0]), ([4, 10], [1, 3, 0, 2]), ([4, 11], [1, 3, 2, 0])], [([3, 2], [1, 0, 2]), ([4, 9], [1, 2, 3, 0]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([5, 1], [0, 1, 2, 4, 3]), ([5, 2], [0, 1, 3, 2, 4]), ([5, 3], [0, 1, 3, 4, 2]), ([5, 4], [0, 1, 4, 2, 3])], [([3, 3], [1, 2, 0]), ([4, 12], [2, 0, 1, 3]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([5, 18], [0, 4, 1, 2, 3]), ([5, 19], [0, 4, 1, 3, 2]), ([5, 20], [0, 4, 2, 1, 3]), ([5, 21], [0, 4, 2, 3, 1])], [([3, 4], [2, 0, 1]), ([4, 15], [2, 1, 3, 0]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([5, 35], [1, 2, 4, 3, 0]), ([5, 36], [1, 3, 0, 2, 4]), ([5, 37], [1, 3, 0, 4, 2]), ([5, 38], [1, 3, 2, 0, 4])]]
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] | Failed |
| explicit oracle 1 | None | [0, 2, 3, 1] | Failed |
| explicit oracle 2 | [0] | [0] | Passed |
| explicit oracle 3 | None | [5, 4, 3, 2, 1, 0] | Failed |
| explicit oracle 4 | [0, 1] | [0, 1] | Passed |
| explicit oracle 5 | [0, 1, 2] | [0, 1, 2] | Passed |
| explicit oracle 6 | None | [0, 2, 1] | Failed |
| explicit oracle 7 | [0, 2, 1] | [1, 0, 2] | Failed |
SHA-256 / 7dc9a329fb9aa09191c18eeb833c8087bbe87aae3a255ff1b82b6dde7c40600e
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):
n,r=x;pool=list(range(n));out=[]
for i in range(n-1,-1,-1):
block=max(1,i)
digit=r//block
if digit<0 or digit>=len(pool):return None
out.append(pool.pop(digit))
r=r%block
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([2, 1], [1, 0]), ([4, 3], [0, 2, 3, 1]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([2, 0], [0, 1]), ([3, 0], [0, 1, 2]), ([3, 1], [0, 2, 1]), ([3, 2], [1, 0, 2])], [([3, 1], [0, 2, 1]), ([4, 6], [1, 0, 2, 3]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([4, 8], [1, 2, 0, 3]), ([4, 9], [1, 2, 3, 0]), ([4, 10], [1, 3, 0, 2]), ([4, 11], [1, 3, 2, 0])], [([3, 2], [1, 0, 2]), ([4, 9], [1, 2, 3, 0]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([5, 1], [0, 1, 2, 4, 3]), ([5, 2], [0, 1, 3, 2, 4]), ([5, 3], [0, 1, 3, 4, 2]), ([5, 4], [0, 1, 4, 2, 3])], [([3, 3], [1, 2, 0]), ([4, 12], [2, 0, 1, 3]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([5, 18], [0, 4, 1, 2, 3]), ([5, 19], [0, 4, 1, 3, 2]), ([5, 20], [0, 4, 2, 1, 3]), ([5, 21], [0, 4, 2, 3, 1])], [([3, 4], [2, 0, 1]), ([4, 15], [2, 1, 3, 0]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([5, 35], [1, 2, 4, 3, 0]), ([5, 36], [1, 3, 0, 2, 4]), ([5, 37], [1, 3, 0, 4, 2]), ([5, 38], [1, 3, 2, 0, 4])]]
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, 0] | Passed |
| explicit oracle 1 | [1, 0, 2, 3] | [0, 2, 3, 1] | Failed |
| explicit oracle 2 | [0] | [0] | Passed |
| explicit oracle 3 | None | [5, 4, 3, 2, 1, 0] | Failed |
| explicit oracle 4 | [0, 1] | [0, 1] | Passed |
| explicit oracle 5 | [0, 1, 2] | [0, 1, 2] | Passed |
| explicit oracle 6 | [0, 2, 1] | [0, 2, 1] | Passed |
| explicit oracle 7 | [1, 0, 2] | [1, 0, 2] | Passed |
SHA-256 / 8420e10055d993423ff24134dda9c677c908ba4468bfec409310ff04e85ab7e0
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):
n,r=x;pool=list(range(n));out=[]
for i in range(n-1,-1,-1):
block=math.factorial(i)
digit=r//block
if digit<0 or digit>=len(pool):return None
out.append(pool.pop(digit))
r=r%block
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([2, 1], [1, 0]), ([4, 3], [0, 2, 3, 1]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([2, 0], [0, 1]), ([3, 0], [0, 1, 2]), ([3, 1], [0, 2, 1]), ([3, 2], [1, 0, 2])], [([3, 1], [0, 2, 1]), ([4, 6], [1, 0, 2, 3]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([4, 8], [1, 2, 0, 3]), ([4, 9], [1, 2, 3, 0]), ([4, 10], [1, 3, 0, 2]), ([4, 11], [1, 3, 2, 0])], [([3, 2], [1, 0, 2]), ([4, 9], [1, 2, 3, 0]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([5, 1], [0, 1, 2, 4, 3]), ([5, 2], [0, 1, 3, 2, 4]), ([5, 3], [0, 1, 3, 4, 2]), ([5, 4], [0, 1, 4, 2, 3])], [([3, 3], [1, 2, 0]), ([4, 12], [2, 0, 1, 3]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([5, 18], [0, 4, 1, 2, 3]), ([5, 19], [0, 4, 1, 3, 2]), ([5, 20], [0, 4, 2, 1, 3]), ([5, 21], [0, 4, 2, 3, 1])], [([3, 4], [2, 0, 1]), ([4, 15], [2, 1, 3, 0]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([5, 35], [1, 2, 4, 3, 0]), ([5, 36], [1, 3, 0, 2, 4]), ([5, 37], [1, 3, 0, 4, 2]), ([5, 38], [1, 3, 2, 0, 4])]]
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, 0] | Passed |
| explicit oracle 1 | [0, 2, 3, 1] | [0, 2, 3, 1] | Passed |
| explicit oracle 2 | [0] | [0] | Passed |
| explicit oracle 3 | [5, 4, 3, 2, 1, 0] | [5, 4, 3, 2, 1, 0] | Passed |
| explicit oracle 4 | [0, 1] | [0, 1] | Passed |
| explicit oracle 5 | [0, 1, 2] | [0, 1, 2] | Passed |
| explicit oracle 6 | [0, 2, 1] | [0, 2, 1] | Passed |
| explicit oracle 7 | [1, 0, 2] | [1, 0, 2] | Passed |
SHA-256 / d62c4d019ace38b470adc9c36870c69e79a9a6653e4c4cf07b1ba57290a2150d
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:23.593414+00:00.
Case digest / bb438727a3fd79fc1ec5c7cecbc74b6038373ae81b4be11e2c68f930ec602fb2