FA-80946 / Music interval and transposition theory / Open access
Enharmonic respelling on a requested letter: double accidentals excluded from respelling · case 01
G4 cannot be respelled as Abb4 and G4 on F returns None instead of Fx4.
ROOT CAUSE
The accidental budget stops at one, although the contract allows two.
VERIFIED REPAIR
Restore the accidental budget step so that it reads `abs(shift) <= 2`.
Unsuccessful approach: Allowing +2 but not -2 still rejects double-flat respellings such as Abb4.
Case contract
Input [note, letter]. note: letter, accidentals (# +1, b -1, x +2), nonnegative octave. Return the same sounding pitch spelled on the requested letter in whichever octave needs the fewest accidentals, rendering +2 x, +1 #, -1 b, -2 bb; octave numbers follow the letter (B#3 = C4). If more than two accidentals would be needed return None.
Why this case matters
Pitch spelling and interval arithmetic decide the notes that notation, transposition and analysis tools display or play.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
if not isinstance(x, list) or len(x) != 2:
return None
note, letter = x
if letter not in base or not isinstance(note, str) or len(note) < 2 or note[0] not in base:
return None
i = 1
acc = 0
while i < len(note) and note[i] in '#bx':
acc += {'#': 1, 'b': -1, 'x': 2}[note[i]]
i += 1
if not note[i:].isdigit():
return None
m = 12 * (int(note[i:]) + 1) + base[note[0]] + acc
best = None
for o in range(m // 12 - 2, m // 12 + 1):
shift = m - (12 * (o + 1) + base[letter])
if abs(shift) < 2 and (best is None or abs(shift) < abs(best[1])):
best = (o, shift)
if best is None:
return None
o, shift = best
sign = {2: 'x', 1: '#', 0: '', -1: 'b', -2: 'bb'}[shift]
return letter + sign + str(o)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['C4', 'B'], 'B#3'), (['B3', 'C'], 'Cb4'), (['E4', 'F'], 'Fb4'), (['F4', 'E'], 'E#4'), (['G4', 'A'], 'Abb4'), (['C4', 'D'], 'Dbb4'), (['C4', 'E'], None), (['A4', 'B'], 'Bbb4')], [(['F4', 'E'], 'E#4'), (['G4', 'A'], 'Abb4'), (['A4', 'G'], 'Gx4'), (['C4', 'D'], 'Dbb4'), (['C4', 'E'], None), (['C#4', 'D'], 'Db4'), (['Db4', 'C'], 'C#4'), (['G4', 'F'], 'Fx4')], [(['C4', 'D'], 'Dbb4'), (['Db4', 'C'], 'C#4'), (['B#3', 'C'], 'C4'), (['Cb4', 'B'], 'B3'), (['Fx4', 'G'], 'G4'), (['D4', 'C'], 'Cx4'), (['C0', 'B'], 'B#-1'), (['F4', 'G'], 'Gbb4')], [(['Fx4', 'G'], 'G4'), (['G4', 'F'], 'Fx4'), (['C0', 'B'], 'B#-1'), (['B0', 'C'], 'Cb1'), (['E4', 'D'], 'Dx4'), (['F4', 'G'], 'Gbb4'), (['C4', 'C'], 'C4'), (['A4', 'B'], 'Bbb4')], [(['G4', 'A'], 'Abb4'), (['D4', 'C'], 'Cx4'), (['F4', 'G'], 'Gbb4'), (['C4', 'C'], 'C4'), (['Bb3', 'A'], 'A#3'), (['A#3', 'B'], 'Bb3'), (['C4', 'H'], None), (['A4', 'B'], 'Bbb4')]]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| oracle 0 | B#3 | B#3 | Passed |
| oracle 1 | Cb4 | Cb4 | Passed |
| oracle 2 | Fb4 | Fb4 | Passed |
| oracle 3 | E#4 | E#4 | Passed |
| oracle 4 | None | Abb4 | Failed |
| oracle 5 | None | Dbb4 | Failed |
| oracle 6 | None | None | Passed |
| oracle 7 | None | Bbb4 | Failed |
SHA-256 / 3a662e1dc110e69c11e23b78a03e2b35632b0e582593ea569a50bf38af54c77a
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
if not isinstance(x, list) or len(x) != 2:
return None
note, letter = x
if letter not in base or not isinstance(note, str) or len(note) < 2 or note[0] not in base:
return None
i = 1
acc = 0
while i < len(note) and note[i] in '#bx':
acc += {'#': 1, 'b': -1, 'x': 2}[note[i]]
i += 1
if not note[i:].isdigit():
return None
m = 12 * (int(note[i:]) + 1) + base[note[0]] + acc
best = None
for o in range(m // 12 - 2, m // 12 + 1):
shift = m - (12 * (o + 1) + base[letter])
if abs(shift) <= 1 or shift == 2 and (best is None or abs(shift) < abs(best[1])):
best = (o, shift)
if best is None:
return None
o, shift = best
sign = {2: 'x', 1: '#', 0: '', -1: 'b', -2: 'bb'}[shift]
return letter + sign + str(o)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['C4', 'B'], 'B#3'), (['B3', 'C'], 'Cb4'), (['E4', 'F'], 'Fb4'), (['F4', 'E'], 'E#4'), (['G4', 'A'], 'Abb4'), (['C4', 'D'], 'Dbb4'), (['C4', 'E'], None), (['A4', 'B'], 'Bbb4')], [(['F4', 'E'], 'E#4'), (['G4', 'A'], 'Abb4'), (['A4', 'G'], 'Gx4'), (['C4', 'D'], 'Dbb4'), (['C4', 'E'], None), (['C#4', 'D'], 'Db4'), (['Db4', 'C'], 'C#4'), (['G4', 'F'], 'Fx4')], [(['C4', 'D'], 'Dbb4'), (['Db4', 'C'], 'C#4'), (['B#3', 'C'], 'C4'), (['Cb4', 'B'], 'B3'), (['Fx4', 'G'], 'G4'), (['D4', 'C'], 'Cx4'), (['C0', 'B'], 'B#-1'), (['F4', 'G'], 'Gbb4')], [(['Fx4', 'G'], 'G4'), (['G4', 'F'], 'Fx4'), (['C0', 'B'], 'B#-1'), (['B0', 'C'], 'Cb1'), (['E4', 'D'], 'Dx4'), (['F4', 'G'], 'Gbb4'), (['C4', 'C'], 'C4'), (['A4', 'B'], 'Bbb4')], [(['G4', 'A'], 'Abb4'), (['D4', 'C'], 'Cx4'), (['F4', 'G'], 'Gbb4'), (['C4', 'C'], 'C4'), (['Bb3', 'A'], 'A#3'), (['A#3', 'B'], 'Bb3'), (['C4', 'H'], None), (['A4', 'B'], 'Bbb4')]]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| oracle 0 | B#3 | B#3 | Passed |
| oracle 1 | Cb4 | Cb4 | Passed |
| oracle 2 | Fb4 | Fb4 | Passed |
| oracle 3 | E#4 | E#4 | Passed |
| oracle 4 | None | Abb4 | Failed |
| oracle 5 | None | Dbb4 | Failed |
| oracle 6 | None | None | Passed |
| oracle 7 | None | Bbb4 | Failed |
SHA-256 / 8a24e51711346e6e84b9ab54d3d1ca5d61bf502f8b281b25ba622c794543377b
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
if not isinstance(x, list) or len(x) != 2:
return None
note, letter = x
if letter not in base or not isinstance(note, str) or len(note) < 2 or note[0] not in base:
return None
i = 1
acc = 0
while i < len(note) and note[i] in '#bx':
acc += {'#': 1, 'b': -1, 'x': 2}[note[i]]
i += 1
if not note[i:].isdigit():
return None
m = 12 * (int(note[i:]) + 1) + base[note[0]] + acc
best = None
for o in range(m // 12 - 2, m // 12 + 1):
shift = m - (12 * (o + 1) + base[letter])
if abs(shift) <= 2 and (best is None or abs(shift) < abs(best[1])):
best = (o, shift)
if best is None:
return None
o, shift = best
sign = {2: 'x', 1: '#', 0: '', -1: 'b', -2: 'bb'}[shift]
return letter + sign + str(o)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['C4', 'B'], 'B#3'), (['B3', 'C'], 'Cb4'), (['E4', 'F'], 'Fb4'), (['F4', 'E'], 'E#4'), (['G4', 'A'], 'Abb4'), (['C4', 'D'], 'Dbb4'), (['C4', 'E'], None), (['A4', 'B'], 'Bbb4')], [(['F4', 'E'], 'E#4'), (['G4', 'A'], 'Abb4'), (['A4', 'G'], 'Gx4'), (['C4', 'D'], 'Dbb4'), (['C4', 'E'], None), (['C#4', 'D'], 'Db4'), (['Db4', 'C'], 'C#4'), (['G4', 'F'], 'Fx4')], [(['C4', 'D'], 'Dbb4'), (['Db4', 'C'], 'C#4'), (['B#3', 'C'], 'C4'), (['Cb4', 'B'], 'B3'), (['Fx4', 'G'], 'G4'), (['D4', 'C'], 'Cx4'), (['C0', 'B'], 'B#-1'), (['F4', 'G'], 'Gbb4')], [(['Fx4', 'G'], 'G4'), (['G4', 'F'], 'Fx4'), (['C0', 'B'], 'B#-1'), (['B0', 'C'], 'Cb1'), (['E4', 'D'], 'Dx4'), (['F4', 'G'], 'Gbb4'), (['C4', 'C'], 'C4'), (['A4', 'B'], 'Bbb4')], [(['G4', 'A'], 'Abb4'), (['D4', 'C'], 'Cx4'), (['F4', 'G'], 'Gbb4'), (['C4', 'C'], 'C4'), (['Bb3', 'A'], 'A#3'), (['A#3', 'B'], 'Bb3'), (['C4', 'H'], None), (['A4', 'B'], 'Bbb4')]]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| oracle 0 | B#3 | B#3 | Passed |
| oracle 1 | Cb4 | Cb4 | Passed |
| oracle 2 | Fb4 | Fb4 | Passed |
| oracle 3 | E#4 | E#4 | Passed |
| oracle 4 | Abb4 | Abb4 | Passed |
| oracle 5 | Dbb4 | Dbb4 | Passed |
| oracle 6 | None | None | Passed |
| oracle 7 | Bbb4 | Bbb4 | Passed |
SHA-256 / 40fa63e5a69f3eadf1659bcde09ba28dbb2067a1614b284cd6efd1271d51f4f3
Verification & scope
A deterministic bounded teaching model with a stipulated toy contract; it is not a complete music notation or theory engine. 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:49:58.613187+00:00.
Case digest / 9a65b1d8959f244d44f71edcb7affbe60eec5afeeef42707c4925567a48afbcd