FA-80846 / Music interval and transposition theory / Open access
Spelled pitch to MIDI key number: letters treated as evenly spaced whole tones · case 01
F, G, A and B read one semitone sharp (F4 reports 66) while C, D and E stay correct.
ROOT CAUSE
The natural-letter offset is derived as twice the letter index, ignoring the E-F and B-C half steps of the diatonic scale.
VERIFIED REPAIR
Restore the natural letter table step so that it reads `names[x[0]] + acc`.
Unsuccessful approach: The half-step correction compares letters alphabetically, so A and B (which sort before E) keep the extra semitone.
Case contract
Input a spelled pitch string: uppercase letter A-G, any run of accidentals (# = +1, b = -1, x = +2), then a signed integer octave where C4 = 60 and C-1 = 0. Return the MIDI key number, or None for malformed text or results outside 0..127.
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):
names = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
if not isinstance(x, str) or len(x) < 2 or x[0] not in names:
return None
i = 1
acc = 0
while i < len(x) and x[i] in '#bx':
acc += {'#': 1, 'b': -1, 'x': 2}[x[i]]
i += 1
tail = x[i:]
neg = tail.startswith('-')
digits = tail[1:] if neg else tail
if not digits.isdigit():
return None
octave = -int(digits) if neg else int(digits)
midi = (octave + 1) * 12 + 'CDEFGAB'.index(x[0]) * 2 + acc
if midi < 0 or midi > 127:
return None
return midi
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('C4', 60), ('A4', 69), ('C-1', 0), ('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('B4', 71)], [('G9', 127), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Bb3', 58)], [('B#3', 60), ('Dbbb4', 59), ('Cb-1', None), ('B-1', 11), ('E4', 64), ('C0', 12), ('D#0', 15), ('A0', 21)], [('Fx4', 67), ('F4', 65), ('B4', 71), ('C0', 12), ('D#0', 15), ('Cx-1', 2), ('H4', None), ('Bx-1', 13)], [('B-1', 11), ('B4', 71), ('Bb3', 58), ('H4', None), ('C', None), ('c4', None), ('C#', None), ('Ab-1', 8)]]
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 | 60 | 60 | Passed |
| oracle 1 | 70 | 69 | Failed |
| oracle 2 | 0 | 0 | Passed |
| oracle 3 | None | None | Passed |
| oracle 4 | None | None | Passed |
| oracle 5 | 61 | 60 | Failed |
| oracle 6 | 59 | 59 | Passed |
| oracle 7 | 72 | 71 | Failed |
SHA-256 / 592b8df12820ec30de01676d81b1596d6a2bc9fad0811efcbc15c14376c2ea05
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
names = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
if not isinstance(x, str) or len(x) < 2 or x[0] not in names:
return None
i = 1
acc = 0
while i < len(x) and x[i] in '#bx':
acc += {'#': 1, 'b': -1, 'x': 2}[x[i]]
i += 1
tail = x[i:]
neg = tail.startswith('-')
digits = tail[1:] if neg else tail
if not digits.isdigit():
return None
octave = -int(digits) if neg else int(digits)
midi = (octave + 1) * 12 + 'CDEFGAB'.index(x[0]) * 2 - (1 if x[0] > 'E' else 0) + acc
if midi < 0 or midi > 127:
return None
return midi
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('C4', 60), ('A4', 69), ('C-1', 0), ('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('B4', 71)], [('G9', 127), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Bb3', 58)], [('B#3', 60), ('Dbbb4', 59), ('Cb-1', None), ('B-1', 11), ('E4', 64), ('C0', 12), ('D#0', 15), ('A0', 21)], [('Fx4', 67), ('F4', 65), ('B4', 71), ('C0', 12), ('D#0', 15), ('Cx-1', 2), ('H4', None), ('Bx-1', 13)], [('B-1', 11), ('B4', 71), ('Bb3', 58), ('H4', None), ('C', None), ('c4', None), ('C#', None), ('Ab-1', 8)]]
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 | 60 | 60 | Passed |
| oracle 1 | 70 | 69 | Failed |
| oracle 2 | 0 | 0 | Passed |
| oracle 3 | None | None | Passed |
| oracle 4 | None | None | Passed |
| oracle 5 | 61 | 60 | Failed |
| oracle 6 | 59 | 59 | Passed |
| oracle 7 | 72 | 71 | Failed |
SHA-256 / 029ab794bdf82b929714ad98e8c4fee82653147d4cf9322f409dccca3ad7ba8e
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
names = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
if not isinstance(x, str) or len(x) < 2 or x[0] not in names:
return None
i = 1
acc = 0
while i < len(x) and x[i] in '#bx':
acc += {'#': 1, 'b': -1, 'x': 2}[x[i]]
i += 1
tail = x[i:]
neg = tail.startswith('-')
digits = tail[1:] if neg else tail
if not digits.isdigit():
return None
octave = -int(digits) if neg else int(digits)
midi = (octave + 1) * 12 + names[x[0]] + acc
if midi < 0 or midi > 127:
return None
return midi
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('C4', 60), ('A4', 69), ('C-1', 0), ('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('B4', 71)], [('G9', 127), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Bb3', 58)], [('B#3', 60), ('Dbbb4', 59), ('Cb-1', None), ('B-1', 11), ('E4', 64), ('C0', 12), ('D#0', 15), ('A0', 21)], [('Fx4', 67), ('F4', 65), ('B4', 71), ('C0', 12), ('D#0', 15), ('Cx-1', 2), ('H4', None), ('Bx-1', 13)], [('B-1', 11), ('B4', 71), ('Bb3', 58), ('H4', None), ('C', None), ('c4', None), ('C#', None), ('Ab-1', 8)]]
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 | 60 | 60 | Passed |
| oracle 1 | 69 | 69 | Passed |
| oracle 2 | 0 | 0 | Passed |
| oracle 3 | None | None | Passed |
| oracle 4 | None | None | Passed |
| oracle 5 | 60 | 60 | Passed |
| oracle 6 | 59 | 59 | Passed |
| oracle 7 | 71 | 71 | Passed |
SHA-256 / 2c492173f06455be85b9803aec74ba9d1441e9e732b46b1d2f41ec863ec8a7a7
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:57.442866+00:00.
Case digest / c366e083338b430ea1a39b62f04811deef928a98e0366d557b773edb23ba0789