FAILURE MAP
← Case archive

FA-15111 / Numerics / Open access

Lehmer permutation rank: rank origin · case 01

The exact lehmer permutation rank result violates the stated contract at rank origin.

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

ROOT CAUSE

The rank origin step uses rank+1 instead of rank.

VERIFIED REPAIR

Use rank at the rank origin step.

Unsuccessful approach: The partial repair rank if rank else 1 still violates the rank origin 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-1)
     remaining.pop(remaining.index(v))
    return rank+1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([0, 1], 0), ([1, 0], 1), ([0, 1, 2], 0), ([0, 2, 1], 1), ([1, 0, 2], 2), ([1, 2, 0], 3)], [([0, 1], 0), ([0, 1, 2, 3], 0), ([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], 1), ([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), ([0, 1, 4, 3, 2], 5)], [([0, 1, 2], 0), ([0, 1, 2, 3], 0), ([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)], [([0, 2, 1], 1), ([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), ([1, 3, 2, 4, 0], 39)]]
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 010Failed
explicit oracle 1720719Failed
explicit oracle 210Failed
explicit oracle 321Failed
explicit oracle 410Failed
explicit oracle 521Failed
explicit oracle 632Failed
explicit oracle 743Failed

SHA-256 / 18f124668d5c5bc662cb3b1792a1c8febce7217d7e9febcefd51c3fdefc293c0

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*math.factorial(n-i-1)
     remaining.pop(remaining.index(v))
    return rank if rank else 1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([0, 1], 0), ([1, 0], 1), ([0, 1, 2], 0), ([0, 2, 1], 1), ([1, 0, 2], 2), ([1, 2, 0], 3)], [([0, 1], 0), ([0, 1, 2, 3], 0), ([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], 1), ([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), ([0, 1, 4, 3, 2], 5)], [([0, 1, 2], 0), ([0, 1, 2, 3], 0), ([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)], [([0, 2, 1], 1), ([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), ([1, 3, 2, 4, 0], 39)]]
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 010Failed
explicit oracle 1719719Passed
explicit oracle 210Failed
explicit oracle 311Passed
explicit oracle 410Failed
explicit oracle 511Passed
explicit oracle 622Passed
explicit oracle 733Passed

SHA-256 / 982ba796ed66372783f9bf9a64bcbeb4e3b5527e240aec1ac079a78ff9875020

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 = [[([0], 0), ([5, 4, 3, 2, 1, 0], 719), ([0, 1], 0), ([1, 0], 1), ([0, 1, 2], 0), ([0, 2, 1], 1), ([1, 0, 2], 2), ([1, 2, 0], 3)], [([0, 1], 0), ([0, 1, 2, 3], 0), ([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], 1), ([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), ([0, 1, 4, 3, 2], 5)], [([0, 1, 2], 0), ([0, 1, 2, 3], 0), ([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)], [([0, 2, 1], 1), ([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), ([1, 3, 2, 4, 0], 39)]]
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 000Passed
explicit oracle 1719719Passed
explicit oracle 200Passed
explicit oracle 311Passed
explicit oracle 400Passed
explicit oracle 511Passed
explicit oracle 622Passed
explicit oracle 733Passed

SHA-256 / 249d6f4ad94f524d5146aeb91def8bec6b88969421aaf2c7b1f4137c8fd4a664

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

Case digest / 469c454fd1e7685a9b9f2afc4dcaf191d0e6a2cb689480204413183a0ba8feef