FAILURE MAP
← Case archive

FA-15101 / Numerics / Open access

Lehmer permutation rank: factoradic place weighting · case 01

The exact lehmer permutation rank result violates the stated contract at factoradic place weighting.

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

ROOT CAUSE

The factoradic place weighting step uses rank+digit*math.factorial(n-i) instead of rank+digit*math.factorial(n-i-1).

VERIFIED REPAIR

Use rank+digit*math.factorial(n-i-1) at the factoradic place weighting step.

Unsuccessful approach: The partial repair rank+digit still violates the factoradic place weighting invariant.

Case contract

Input permutation of 0..n-1 with n<=7; return zero-based lexicographic rank.

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):
    p=x;n=len(p)
    remaining=list(range(n));rank=0
    for i,v in enumerate(p):
     if v not in remaining:return None
     digit=remaining.index(v)
     rank=rank+digit*math.factorial(n-i)
     remaining.pop(remaining.index(v))
    return rank
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([1, 0], 1), ([1, 0, 2], 2), ([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([0, 1], 0), ([0, 1, 2], 0), ([0, 2, 1], 1), ([1, 2, 0], 3)], [([0, 2, 1], 1), ([2, 1, 0], 5), ([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([1, 2, 0, 3], 8), ([1, 2, 3, 0], 9), ([1, 3, 0, 2], 10), ([1, 3, 2, 0], 11)], [([1, 0, 2], 2), ([0, 3, 1, 2], 4), ([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([0, 1, 2, 4, 3], 1), ([0, 1, 3, 2, 4], 2), ([0, 1, 3, 4, 2], 3), ([0, 1, 4, 2, 3], 4)], [([1, 2, 0], 3), ([1, 0, 3, 2], 7), ([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([0, 4, 1, 2, 3], 18), ([0, 4, 1, 3, 2], 19), ([0, 4, 2, 1, 3], 20), ([0, 4, 2, 3, 1], 21)], [([2, 0, 1], 4), ([1, 3, 0, 2], 10), ([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([1, 2, 4, 3, 0], 35), ([1, 3, 0, 2, 4], 36), ([1, 3, 0, 4, 2], 37), ([1, 3, 2, 0, 4], 38)]]
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 021Failed
explicit oracle 162Failed
explicit oracle 200Passed
explicit oracle 34166719Failed
explicit oracle 400Passed
explicit oracle 500Passed
explicit oracle 621Failed
explicit oracle 783Failed

SHA-256 / b6aa12bef4bf0dc45d740587979c4e3db0f0b24f11469fa065df6bc2c39580af

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):
    p=x;n=len(p)
    remaining=list(range(n));rank=0
    for i,v in enumerate(p):
     if v not in remaining:return None
     digit=remaining.index(v)
     rank=rank+digit
     remaining.pop(remaining.index(v))
    return rank
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([1, 0], 1), ([1, 0, 2], 2), ([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([0, 1], 0), ([0, 1, 2], 0), ([0, 2, 1], 1), ([1, 2, 0], 3)], [([0, 2, 1], 1), ([2, 1, 0], 5), ([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([1, 2, 0, 3], 8), ([1, 2, 3, 0], 9), ([1, 3, 0, 2], 10), ([1, 3, 2, 0], 11)], [([1, 0, 2], 2), ([0, 3, 1, 2], 4), ([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([0, 1, 2, 4, 3], 1), ([0, 1, 3, 2, 4], 2), ([0, 1, 3, 4, 2], 3), ([0, 1, 4, 2, 3], 4)], [([1, 2, 0], 3), ([1, 0, 3, 2], 7), ([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([0, 4, 1, 2, 3], 18), ([0, 4, 1, 3, 2], 19), ([0, 4, 2, 1, 3], 20), ([0, 4, 2, 3, 1], 21)], [([2, 0, 1], 4), ([1, 3, 0, 2], 10), ([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([1, 2, 4, 3, 0], 35), ([1, 3, 0, 2, 4], 36), ([1, 3, 0, 4, 2], 37), ([1, 3, 2, 0, 4], 38)]]
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 011Passed
explicit oracle 112Failed
explicit oracle 200Passed
explicit oracle 315719Failed
explicit oracle 400Passed
explicit oracle 500Passed
explicit oracle 611Passed
explicit oracle 723Failed

SHA-256 / 696246c9a4930d4dc6fcf8bd2136af64bceaddece1f1a39dc9caa040d04284ff

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):
    p=x;n=len(p)
    remaining=list(range(n));rank=0
    for i,v in enumerate(p):
     if v not in remaining:return None
     digit=remaining.index(v)
     rank=rank+digit*math.factorial(n-i-1)
     remaining.pop(remaining.index(v))
    return rank
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([1, 0], 1), ([1, 0, 2], 2), ([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([0, 1], 0), ([0, 1, 2], 0), ([0, 2, 1], 1), ([1, 2, 0], 3)], [([0, 2, 1], 1), ([2, 1, 0], 5), ([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([1, 2, 0, 3], 8), ([1, 2, 3, 0], 9), ([1, 3, 0, 2], 10), ([1, 3, 2, 0], 11)], [([1, 0, 2], 2), ([0, 3, 1, 2], 4), ([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([0, 1, 2, 4, 3], 1), ([0, 1, 3, 2, 4], 2), ([0, 1, 3, 4, 2], 3), ([0, 1, 4, 2, 3], 4)], [([1, 2, 0], 3), ([1, 0, 3, 2], 7), ([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([0, 4, 1, 2, 3], 18), ([0, 4, 1, 3, 2], 19), ([0, 4, 2, 1, 3], 20), ([0, 4, 2, 3, 1], 21)], [([2, 0, 1], 4), ([1, 3, 0, 2], 10), ([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([1, 2, 4, 3, 0], 35), ([1, 3, 0, 2, 4], 36), ([1, 3, 0, 4, 2], 37), ([1, 3, 2, 0, 4], 38)]]
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 011Passed
explicit oracle 122Passed
explicit oracle 200Passed
explicit oracle 3719719Passed
explicit oracle 400Passed
explicit oracle 500Passed
explicit oracle 611Passed
explicit oracle 733Passed

SHA-256 / 928a46e2c6e913bc74fe3d6c7c581304dfef33be6c37c15d289b1f01aba57764

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

Case digest / c522922910c48043c0d6179eaf9a1450bb40fd579e69d53e8a3578bd14d03a1c