FA-80856 / Music interval and transposition theory / Open access
Spelled pitch to MIDI key number: range check admits key 128 · case 01
G#9 and Ab9 are returned as key 128 instead of being rejected as out of range.
ROOT CAUSE
The upper range check compares against 128, one past the last valid seven-bit key number.
VERIFIED REPAIR
Restore the upper MIDI bound step so that it reads `midi > 127`.
Unsuccessful approach: Flipping to a non-strict comparison now rejects G9, the valid top key 127.
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 + names[x[0]] + acc
if midi < 0 or midi > 128:
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), ('G9', 127), ('G#9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67)], [('G9', 127), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None)], [('G9', 127), ('G#9', None), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None), ('B-1', 11), ('E4', 64), ('F4', 65)], [('G9', 127), ('Ab9', None), ('B-1', 11), ('E4', 64), ('F4', 65), ('B4', 71), ('Bb3', 58), ('C0', 12)], [('G9', 127), ('G#9', None), ('B4', 71), ('Bb3', 58), ('C0', 12), ('D#0', 15), ('Cx-1', 2), ('H4', None)]]
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 | 127 | 127 | Passed |
| oracle 4 | 128 | None | Failed |
| oracle 5 | 60 | 60 | Passed |
| oracle 6 | 59 | 59 | Passed |
| oracle 7 | 67 | 67 | Passed |
SHA-256 / a734493f3d512b799eb453acd0c83fd5e524607d951d0d465a82eb009d71df53
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 + 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), ('G9', 127), ('G#9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67)], [('G9', 127), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None)], [('G9', 127), ('G#9', None), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None), ('B-1', 11), ('E4', 64), ('F4', 65)], [('G9', 127), ('Ab9', None), ('B-1', 11), ('E4', 64), ('F4', 65), ('B4', 71), ('Bb3', 58), ('C0', 12)], [('G9', 127), ('G#9', None), ('B4', 71), ('Bb3', 58), ('C0', 12), ('D#0', 15), ('Cx-1', 2), ('H4', None)]]
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 | 127 | Failed |
| oracle 4 | None | None | Passed |
| oracle 5 | 60 | 60 | Passed |
| oracle 6 | 59 | 59 | Passed |
| oracle 7 | 67 | 67 | Passed |
SHA-256 / b7944429578c35b6d207540941b1dcf620b20b34bc34602b49129c51d91db6b9
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), ('G9', 127), ('G#9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67)], [('G9', 127), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None)], [('G9', 127), ('G#9', None), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None), ('B-1', 11), ('E4', 64), ('F4', 65)], [('G9', 127), ('Ab9', None), ('B-1', 11), ('E4', 64), ('F4', 65), ('B4', 71), ('Bb3', 58), ('C0', 12)], [('G9', 127), ('G#9', None), ('B4', 71), ('Bb3', 58), ('C0', 12), ('D#0', 15), ('Cx-1', 2), ('H4', None)]]
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 | 127 | 127 | Passed |
| oracle 4 | None | None | Passed |
| oracle 5 | 60 | 60 | Passed |
| oracle 6 | 59 | 59 | Passed |
| oracle 7 | 67 | 67 | Passed |
SHA-256 / fcddd08d58191439a871a7f80c610f8a9e2d4e59feb82aa29f3f0f02d449bb47
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.652195+00:00.
Case digest / 35b6d7158a8384bffec920364ddb6b5d233671e3cd01a48a9a0cdbe26925c773