FAILURE MAP
← Case archive

FA-15216 / Numerics / Open access

Multiset permutation unrank: multiset alphabet order · case 01

The exact multiset permutation unrank result violates the stated contract at multiset alphabet order.

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

ROOT CAUSE

The multiset alphabet order step uses sorted(counts,reverse=True) instead of sorted(counts).

VERIFIED REPAIR

Use sorted(counts) at the multiset alphabet order step.

Unsuccessful approach: The partial repair list(reversed(list(counts))) still violates the multiset alphabet order invariant.

Case contract

Input [sorted multiset of small integer symbols, rank], valid zero-based lexicographic rank among distinct permutations.

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):
    items,r=x
    from collections import Counter
    counts=Counter(items);out=[]
    def ways(c):
     v=math.factorial(sum(c.values()))
     for n in c.values():v//=math.factorial(n)
     return v
    for _ in range(len(items)):
     for symbol in sorted(counts,reverse=True):
      if counts[symbol]==0:continue
      counts[symbol]-=1
      block=ways(counts)
      if r<block:
       out.append(symbol)
       break
      r=r-block
      counts[symbol]=counts[symbol]+1
     else:return None
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 1], 1], [0, 1, 0]), ([[0, 0, 1], 2], [1, 0, 0]), ([[0, 1, 1, 2], 0], [0, 1, 1, 2]), ([[0, 1, 1, 2], 1], [0, 1, 2, 1]), ([[0, 1, 1, 2], 2], [0, 2, 1, 1]), ([[0, 1, 1, 2], 3], [1, 0, 1, 2])], [([[0, 0, 1], 2], [1, 0, 0]), ([[0, 1, 1, 2], 1], [0, 1, 2, 1]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 1, 1], 2], [0, 1, 1, 0]), ([[0, 0, 1, 1], 3], [1, 0, 0, 1]), ([[0, 0, 1, 1], 4], [1, 0, 1, 0]), ([[0, 0, 1, 1], 5], [1, 1, 0, 0])], [([[0, 1, 1, 2], 0], [0, 1, 1, 2]), ([[0, 1, 1, 2], 4], [1, 0, 2, 1]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 0, 1, 2], 13], [1, 0, 0, 2, 0]), ([[0, 0, 0, 1, 2], 14], [1, 0, 2, 0, 0]), ([[0, 0, 0, 1, 2], 15], [1, 2, 0, 0, 0]), ([[0, 0, 0, 1, 2], 16], [2, 0, 0, 0, 1])], [([[0, 1, 1, 2], 1], [0, 1, 2, 1]), ([[0, 1, 1, 2], 7], [1, 2, 0, 1]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 1, 2, 3], 10], [1, 3, 0, 2]), ([[0, 1, 2, 3], 11], [1, 3, 2, 0]), ([[0, 1, 2, 3], 12], [2, 0, 1, 3]), ([[0, 1, 2, 3], 13], [2, 0, 3, 1])], [([[0, 1, 1, 2], 2], [0, 2, 1, 1]), ([[0, 1, 1, 2], 10], [2, 1, 0, 1]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[1, 1, 2, 2, 3], 3], [1, 2, 1, 2, 3]), ([[1, 1, 2, 2, 3], 4], [1, 2, 1, 3, 2]), ([[1, 1, 2, 2, 3], 5], [1, 2, 2, 1, 3]), ([[1, 1, 2, 2, 3], 6], [1, 2, 2, 3, 1])]]
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, 0][0, 0, 1]Failed
explicit oracle 1[1, 1, 2, 2, 3][3, 2, 2, 1, 1]Failed
explicit oracle 2[0, 1, 0][0, 1, 0]Passed
explicit oracle 3[0, 0, 1][1, 0, 0]Failed
explicit oracle 4[2, 1, 1, 0][0, 1, 1, 2]Failed
explicit oracle 5[2, 1, 0, 1][0, 1, 2, 1]Failed
explicit oracle 6[2, 0, 1, 1][0, 2, 1, 1]Failed
explicit oracle 7[1, 2, 1, 0][1, 0, 1, 2]Failed

SHA-256 / d5e84813d7295d7521abaf7e5fa82447c5aeaac3d74f3e6a7519ffe76be0945a

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):
    items,r=x
    from collections import Counter
    counts=Counter(items);out=[]
    def ways(c):
     v=math.factorial(sum(c.values()))
     for n in c.values():v//=math.factorial(n)
     return v
    for _ in range(len(items)):
     for symbol in list(reversed(list(counts))):
      if counts[symbol]==0:continue
      counts[symbol]-=1
      block=ways(counts)
      if r<block:
       out.append(symbol)
       break
      r=r-block
      counts[symbol]=counts[symbol]+1
     else:return None
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 1], 1], [0, 1, 0]), ([[0, 0, 1], 2], [1, 0, 0]), ([[0, 1, 1, 2], 0], [0, 1, 1, 2]), ([[0, 1, 1, 2], 1], [0, 1, 2, 1]), ([[0, 1, 1, 2], 2], [0, 2, 1, 1]), ([[0, 1, 1, 2], 3], [1, 0, 1, 2])], [([[0, 0, 1], 2], [1, 0, 0]), ([[0, 1, 1, 2], 1], [0, 1, 2, 1]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 1, 1], 2], [0, 1, 1, 0]), ([[0, 0, 1, 1], 3], [1, 0, 0, 1]), ([[0, 0, 1, 1], 4], [1, 0, 1, 0]), ([[0, 0, 1, 1], 5], [1, 1, 0, 0])], [([[0, 1, 1, 2], 0], [0, 1, 1, 2]), ([[0, 1, 1, 2], 4], [1, 0, 2, 1]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 0, 1, 2], 13], [1, 0, 0, 2, 0]), ([[0, 0, 0, 1, 2], 14], [1, 0, 2, 0, 0]), ([[0, 0, 0, 1, 2], 15], [1, 2, 0, 0, 0]), ([[0, 0, 0, 1, 2], 16], [2, 0, 0, 0, 1])], [([[0, 1, 1, 2], 1], [0, 1, 2, 1]), ([[0, 1, 1, 2], 7], [1, 2, 0, 1]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 1, 2, 3], 10], [1, 3, 0, 2]), ([[0, 1, 2, 3], 11], [1, 3, 2, 0]), ([[0, 1, 2, 3], 12], [2, 0, 1, 3]), ([[0, 1, 2, 3], 13], [2, 0, 3, 1])], [([[0, 1, 1, 2], 2], [0, 2, 1, 1]), ([[0, 1, 1, 2], 10], [2, 1, 0, 1]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[1, 1, 2, 2, 3], 3], [1, 2, 1, 2, 3]), ([[1, 1, 2, 2, 3], 4], [1, 2, 1, 3, 2]), ([[1, 1, 2, 2, 3], 5], [1, 2, 2, 1, 3]), ([[1, 1, 2, 2, 3], 6], [1, 2, 2, 3, 1])]]
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, 0][0, 0, 1]Failed
explicit oracle 1[1, 1, 2, 2, 3][3, 2, 2, 1, 1]Failed
explicit oracle 2[0, 1, 0][0, 1, 0]Passed
explicit oracle 3[0, 0, 1][1, 0, 0]Failed
explicit oracle 4[2, 1, 1, 0][0, 1, 1, 2]Failed
explicit oracle 5[2, 1, 0, 1][0, 1, 2, 1]Failed
explicit oracle 6[2, 0, 1, 1][0, 2, 1, 1]Failed
explicit oracle 7[1, 2, 1, 0][1, 0, 1, 2]Failed

SHA-256 / e64deac9028479f94a1c347e79f30042505089fc9d6c04e37578797081bbec01

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):
    items,r=x
    from collections import Counter
    counts=Counter(items);out=[]
    def ways(c):
     v=math.factorial(sum(c.values()))
     for n in c.values():v//=math.factorial(n)
     return v
    for _ in range(len(items)):
     for symbol in sorted(counts):
      if counts[symbol]==0:continue
      counts[symbol]-=1
      block=ways(counts)
      if r<block:
       out.append(symbol)
       break
      r=r-block
      counts[symbol]=counts[symbol]+1
     else:return None
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 1], 1], [0, 1, 0]), ([[0, 0, 1], 2], [1, 0, 0]), ([[0, 1, 1, 2], 0], [0, 1, 1, 2]), ([[0, 1, 1, 2], 1], [0, 1, 2, 1]), ([[0, 1, 1, 2], 2], [0, 2, 1, 1]), ([[0, 1, 1, 2], 3], [1, 0, 1, 2])], [([[0, 0, 1], 2], [1, 0, 0]), ([[0, 1, 1, 2], 1], [0, 1, 2, 1]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 1, 1], 2], [0, 1, 1, 0]), ([[0, 0, 1, 1], 3], [1, 0, 0, 1]), ([[0, 0, 1, 1], 4], [1, 0, 1, 0]), ([[0, 0, 1, 1], 5], [1, 1, 0, 0])], [([[0, 1, 1, 2], 0], [0, 1, 1, 2]), ([[0, 1, 1, 2], 4], [1, 0, 2, 1]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 0, 0, 1, 2], 13], [1, 0, 0, 2, 0]), ([[0, 0, 0, 1, 2], 14], [1, 0, 2, 0, 0]), ([[0, 0, 0, 1, 2], 15], [1, 2, 0, 0, 0]), ([[0, 0, 0, 1, 2], 16], [2, 0, 0, 0, 1])], [([[0, 1, 1, 2], 1], [0, 1, 2, 1]), ([[0, 1, 1, 2], 7], [1, 2, 0, 1]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[0, 1, 2, 3], 10], [1, 3, 0, 2]), ([[0, 1, 2, 3], 11], [1, 3, 2, 0]), ([[0, 1, 2, 3], 12], [2, 0, 1, 3]), ([[0, 1, 2, 3], 13], [2, 0, 3, 1])], [([[0, 1, 1, 2], 2], [0, 2, 1, 1]), ([[0, 1, 1, 2], 10], [2, 1, 0, 1]), ([[0, 0, 1], 0], [0, 0, 1]), ([[1, 1, 2, 2, 3], 29], [3, 2, 2, 1, 1]), ([[1, 1, 2, 2, 3], 3], [1, 2, 1, 2, 3]), ([[1, 1, 2, 2, 3], 4], [1, 2, 1, 3, 2]), ([[1, 1, 2, 2, 3], 5], [1, 2, 2, 1, 3]), ([[1, 1, 2, 2, 3], 6], [1, 2, 2, 3, 1])]]
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, 1][0, 0, 1]Passed
explicit oracle 1[3, 2, 2, 1, 1][3, 2, 2, 1, 1]Passed
explicit oracle 2[0, 1, 0][0, 1, 0]Passed
explicit oracle 3[1, 0, 0][1, 0, 0]Passed
explicit oracle 4[0, 1, 1, 2][0, 1, 1, 2]Passed
explicit oracle 5[0, 1, 2, 1][0, 1, 2, 1]Passed
explicit oracle 6[0, 2, 1, 1][0, 2, 1, 1]Passed
explicit oracle 7[1, 0, 1, 2][1, 0, 1, 2]Passed

SHA-256 / e542a36e1149cf1696b5fe7d7ee023f4a2d027a8f6fdcc54c78a26eaf3dda774

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

Case digest / ad019ff92134f8473bc893868e6422881bc7f113d63b80af1637794cc971d996