FAILURE MAP
← Case archive

FA-15136 / Numerics / Open access

Factoradic permutation unrank: within block rank · case 01

The exact factoradic permutation unrank result violates the stated contract at within block rank.

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

ROOT CAUSE

The within block rank step uses r//block instead of r%block.

VERIFIED REPAIR

Use r%block at the within block rank step.

Unsuccessful approach: The partial repair r-block still violates the within block rank 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)
     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]), ([2, 0], [0, 1]), ([1, 0], [0]), ([6, 719], [5, 4, 3, 2, 1, 0]), ([3, 0], [0, 1, 2]), ([3, 1], [0, 2, 1]), ([3, 2], [1, 0, 2]), ([3, 3], [1, 2, 0])], [([3, 1], [0, 2, 1]), ([3, 2], [1, 0, 2]), ([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, 0], [0, 1, 2, 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, 3], [1, 2, 0]), ([4, 3], [0, 2, 3, 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, 4], [2, 0, 1]), ([4, 6], [1, 0, 2, 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 0None[1, 0]Failed
explicit oracle 1[0, 1][0, 1]Passed
explicit oracle 2[0][0]Passed
explicit oracle 3[5, 0, 1, 2, 3, 4][5, 4, 3, 2, 1, 0]Failed
explicit oracle 4[0, 1, 2][0, 1, 2]Passed
explicit oracle 5[0, 1, 2][0, 2, 1]Failed
explicit oracle 6None[1, 0, 2]Failed
explicit oracle 7None[1, 2, 0]Failed

SHA-256 / 4c7ee2af99ad07d581656958c72245ccaf44185d7a2b2b38eb8222e724654cc1

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

SHA-256 / 00e2a5d6b079adcf1aaebeeb61ba957f310dd205199b15bfb1be1a336f857a56

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

SHA-256 / f5607134e54ca0782b7c274266e2940b2c00299c3df923e887d999f8625abf67

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

Case digest / 4fb0b05eb7bbe2797cf0d1b990c86197b7cb07fdff09381f453bd9ad3dd88d89