FAILURE MAP
← Case archive

FA-15116 / Numerics / Open access

Factoradic permutation unrank: factoradic digit count · case 01

The exact factoradic permutation unrank result violates the stated contract at factoradic digit count.

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

ROOT CAUSE

The factoradic digit count step uses range(n-1,0,-1) instead of range(n-1,-1,-1).

VERIFIED REPAIR

Use range(n-1,-1,-1) at the factoradic digit count step.

Unsuccessful approach: The partial repair range(n) still violates the factoradic digit count 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,0,-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 = [[([1, 0], [0]), ([3, 1], [0, 2, 1]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([2, 0], [0, 1]), ([2, 1], [1, 0]), ([3, 0], [0, 1, 2]), ([3, 2], [1, 0, 2]), ([3, 3], [1, 2, 0])], [([2, 0], [0, 1]), ([3, 4], [2, 0, 1]), ([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])], [([2, 1], [1, 0]), ([4, 2], [0, 2, 1, 3]), ([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, 0], [0, 1, 2]), ([4, 5], [0, 3, 2, 1]), ([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, 1], [0, 2, 1]), ([4, 8], [1, 2, 0, 3]), ([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 fixtureActualExpectedOutcome
explicit oracle 0[][0]Failed
explicit oracle 1[0, 2][0, 2, 1]Failed
explicit oracle 2[5, 4, 3, 2, 1][5, 4, 3, 2, 1, 0]Failed
explicit oracle 3[0][0, 1]Failed
explicit oracle 4[1][1, 0]Failed
explicit oracle 5[0, 1][0, 1, 2]Failed
explicit oracle 6[1, 0][1, 0, 2]Failed
explicit oracle 7[1, 2][1, 2, 0]Failed

SHA-256 / a9cfcfd5d0a72e48324a5d7b5c82724c91c4df140b59ffbc105060f6f3a779d0

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):
     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 = [[([1, 0], [0]), ([3, 1], [0, 2, 1]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([2, 0], [0, 1]), ([2, 1], [1, 0]), ([3, 0], [0, 1, 2]), ([3, 2], [1, 0, 2]), ([3, 3], [1, 2, 0])], [([2, 0], [0, 1]), ([3, 4], [2, 0, 1]), ([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])], [([2, 1], [1, 0]), ([4, 2], [0, 2, 1, 3]), ([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, 0], [0, 1, 2]), ([4, 5], [0, 3, 2, 1]), ([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, 1], [0, 2, 1]), ([4, 8], [1, 2, 0, 3]), ([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 fixtureActualExpectedOutcome
explicit oracle 0[0][0]Passed
explicit oracle 1[1, 0, 2][0, 2, 1]Failed
explicit oracle 2None[5, 4, 3, 2, 1, 0]Failed
explicit oracle 3[0, 1][0, 1]Passed
explicit oracle 4[1, 0][1, 0]Passed
explicit oracle 5[0, 1, 2][0, 1, 2]Passed
explicit oracle 6[2, 0, 1][1, 0, 2]Failed
explicit oracle 7None[1, 2, 0]Failed

SHA-256 / bac6cea526bc94bc740951ef92b848885497c7ee9191a81d0ff64b2726617703

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 = [[([1, 0], [0]), ([3, 1], [0, 2, 1]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([2, 0], [0, 1]), ([2, 1], [1, 0]), ([3, 0], [0, 1, 2]), ([3, 2], [1, 0, 2]), ([3, 3], [1, 2, 0])], [([2, 0], [0, 1]), ([3, 4], [2, 0, 1]), ([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])], [([2, 1], [1, 0]), ([4, 2], [0, 2, 1, 3]), ([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, 0], [0, 1, 2]), ([4, 5], [0, 3, 2, 1]), ([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, 1], [0, 2, 1]), ([4, 8], [1, 2, 0, 3]), ([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 fixtureActualExpectedOutcome
explicit oracle 0[0][0]Passed
explicit oracle 1[0, 2, 1][0, 2, 1]Passed
explicit oracle 2[5, 4, 3, 2, 1, 0][5, 4, 3, 2, 1, 0]Passed
explicit oracle 3[0, 1][0, 1]Passed
explicit oracle 4[1, 0][1, 0]Passed
explicit oracle 5[0, 1, 2][0, 1, 2]Passed
explicit oracle 6[1, 0, 2][1, 0, 2]Passed
explicit oracle 7[1, 2, 0][1, 2, 0]Passed

SHA-256 / adc49fb72454ba8bdc569b433a3d3b9b604aecc62c9d6c9af99ed5f35d1ce85b

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

Case digest / cffc5ad7c388c96a66ccd4732a4501ee837ecf0dd17d8d75e768be765774910e