FAILURE MAP
← Case archive

FA-15066 / Numerics / Open access

Baby step giant step logarithm: baby exponent coverage · case 01

The exact baby step giant step logarithm result violates the stated contract at baby exponent coverage.

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

ROOT CAUSE

The baby exponent coverage step uses range(1,m) instead of range(m).

VERIFIED REPAIR

Use range(m) at the baby exponent coverage step.

Unsuccessful approach: The partial repair range(m-1) still violates the baby exponent coverage invariant.

Case contract

Input [g,h,p], p prime and nonzero g,h; return least e>=0 with g^e=h mod p or None.

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):
    g,h,p=x;m=math.isqrt(p-1)+1
    baby={};v=1
    for j in range(1,m):
     if v not in baby:baby[v]=j
     v=v*g%p
    factor=pow(pow(g,m,p),-1,p)
    v=h
    answers=[]
    for i in range(m+1):
     if v in baby:
      e=i*m+baby[v]
      if pow(g,e,p)==h:answers.append(e)
     v=v*factor%p
    return min(answers) if answers else None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([1, 1, 3], 0), ([2, 2, 3], 1), ([22, 22, 23], 1), ([1, 2, 3], None), ([2, 1, 3], 0), ([1, 1, 5], 0), ([1, 2, 5], None), ([1, 3, 5], None)], [([2, 1, 3], 0), ([2, 4, 7], 2), ([1, 1, 3], 0), ([22, 22, 23], 1), ([4, 2, 5], None), ([4, 3, 5], None), ([4, 4, 5], 1), ([1, 1, 7], 0)], [([2, 2, 3], 1), ([4, 2, 7], 2), ([1, 1, 3], 0), ([22, 22, 23], 1), ([3, 3, 7], 1), ([3, 4, 7], 4), ([3, 5, 7], 5), ([3, 6, 7], 3)], [([1, 1, 5], 0), ([2, 7, 11], 7), ([1, 1, 3], 0), ([22, 22, 23], 1), ([6, 2, 7], None), ([6, 3, 7], None), ([6, 4, 7], None), ([6, 5, 7], None)], [([2, 1, 5], 0), ([4, 9, 11], 3), ([1, 1, 3], 0), ([22, 22, 23], 1), ([2, 3, 11], 8), ([2, 4, 11], 2), ([2, 5, 11], 4), ([2, 6, 11], 9)]]
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 1None1Failed
explicit oracle 2None1Failed
explicit oracle 3NoneNonePassed
explicit oracle 4None0Failed
explicit oracle 510Failed
explicit oracle 6NoneNonePassed
explicit oracle 7NoneNonePassed

SHA-256 / 2075b871497f3251f598d512ae19a975d1bf18e9fc577c800edf0c5436b283a6

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):
    g,h,p=x;m=math.isqrt(p-1)+1
    baby={};v=1
    for j in range(m-1):
     if v not in baby:baby[v]=j
     v=v*g%p
    factor=pow(pow(g,m,p),-1,p)
    v=h
    answers=[]
    for i in range(m+1):
     if v in baby:
      e=i*m+baby[v]
      if pow(g,e,p)==h:answers.append(e)
     v=v*factor%p
    return min(answers) if answers else None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([1, 1, 3], 0), ([2, 2, 3], 1), ([22, 22, 23], 1), ([1, 2, 3], None), ([2, 1, 3], 0), ([1, 1, 5], 0), ([1, 2, 5], None), ([1, 3, 5], None)], [([2, 1, 3], 0), ([2, 4, 7], 2), ([1, 1, 3], 0), ([22, 22, 23], 1), ([4, 2, 5], None), ([4, 3, 5], None), ([4, 4, 5], 1), ([1, 1, 7], 0)], [([2, 2, 3], 1), ([4, 2, 7], 2), ([1, 1, 3], 0), ([22, 22, 23], 1), ([3, 3, 7], 1), ([3, 4, 7], 4), ([3, 5, 7], 5), ([3, 6, 7], 3)], [([1, 1, 5], 0), ([2, 7, 11], 7), ([1, 1, 3], 0), ([22, 22, 23], 1), ([6, 2, 7], None), ([6, 3, 7], None), ([6, 4, 7], None), ([6, 5, 7], None)], [([2, 1, 5], 0), ([4, 9, 11], 3), ([1, 1, 3], 0), ([22, 22, 23], 1), ([2, 3, 11], 8), ([2, 4, 11], 2), ([2, 5, 11], 4), ([2, 6, 11], 9)]]
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 1None1Failed
explicit oracle 211Passed
explicit oracle 3NoneNonePassed
explicit oracle 400Passed
explicit oracle 500Passed
explicit oracle 6NoneNonePassed
explicit oracle 7NoneNonePassed

SHA-256 / 68c829c0bd8fe5202c539036f656e554d03ac232f0a6410ad4569903555d1e43

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):
    g,h,p=x;m=math.isqrt(p-1)+1
    baby={};v=1
    for j in range(m):
     if v not in baby:baby[v]=j
     v=v*g%p
    factor=pow(pow(g,m,p),-1,p)
    v=h
    answers=[]
    for i in range(m+1):
     if v in baby:
      e=i*m+baby[v]
      if pow(g,e,p)==h:answers.append(e)
     v=v*factor%p
    return min(answers) if answers else None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([1, 1, 3], 0), ([2, 2, 3], 1), ([22, 22, 23], 1), ([1, 2, 3], None), ([2, 1, 3], 0), ([1, 1, 5], 0), ([1, 2, 5], None), ([1, 3, 5], None)], [([2, 1, 3], 0), ([2, 4, 7], 2), ([1, 1, 3], 0), ([22, 22, 23], 1), ([4, 2, 5], None), ([4, 3, 5], None), ([4, 4, 5], 1), ([1, 1, 7], 0)], [([2, 2, 3], 1), ([4, 2, 7], 2), ([1, 1, 3], 0), ([22, 22, 23], 1), ([3, 3, 7], 1), ([3, 4, 7], 4), ([3, 5, 7], 5), ([3, 6, 7], 3)], [([1, 1, 5], 0), ([2, 7, 11], 7), ([1, 1, 3], 0), ([22, 22, 23], 1), ([6, 2, 7], None), ([6, 3, 7], None), ([6, 4, 7], None), ([6, 5, 7], None)], [([2, 1, 5], 0), ([4, 9, 11], 3), ([1, 1, 3], 0), ([22, 22, 23], 1), ([2, 3, 11], 8), ([2, 4, 11], 2), ([2, 5, 11], 4), ([2, 6, 11], 9)]]
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 111Passed
explicit oracle 211Passed
explicit oracle 3NoneNonePassed
explicit oracle 400Passed
explicit oracle 500Passed
explicit oracle 6NoneNonePassed
explicit oracle 7NoneNonePassed

SHA-256 / 0c7f3713ace9acd0e1d60f394d041f0078ce50e2dbbce39e374df3e75b415ba1

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

Case digest / 6eb6574c4551f4148f06ff628537f4a578100507fbc096c803de3c574033ce6a