FA-81126 / Music interval and transposition theory / Open access
Transposing instrument written and concert pitch: negative MIDI result returned · case 01
Very low written notes for baritone saxophone return negative key numbers instead of None.
ROOT CAUSE
The output range guard checks only the upper MIDI limit.
VERIFIED REPAIR
Restore the result floor step so that it reads `out < 0 or out > 127`.
Unsuccessful approach: A non-strict upper comparison now rejects a legitimate result of 127.
Case contract
Input [instrument, pitch, direction]. Each instrument has a stipulated sounding offset in semitones (concert = written + offset): Bb clarinet -2, A clarinet -3, F horn -7, Eb alto sax -9, Bb tenor sax -14, Eb baritone sax -21, guitar -12, piccolo +12, D trumpet +2, flute 0. direction to_concert adds the offset, to_written subtracts it. pitch and result must be MIDI 0..127; otherwise, or for unknown instrument or direction, return None.
Why this case matters
Score and part generators convert between written and sounding pitch for every transposing instrument.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
table = {'Bb clarinet': -2, 'A clarinet': -3, 'F horn': -7, 'Eb alto sax': -9, 'Bb tenor sax': -14, 'Eb baritone sax': -21, 'guitar': -12, 'piccolo': 12, 'D trumpet': 2, 'flute': 0}
if not isinstance(x, list) or len(x) != 3:
return None
inst, pitch, direction = x
if inst not in table or not isinstance(pitch, int) or not 0 <= pitch <= 127:
return None
if direction == 'to_concert':
out = pitch + table[inst]
elif direction == 'to_written':
out = pitch - table[inst]
else:
return None
if out > 127:
return None
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['Bb clarinet', 62, 'to_concert'], 60), (['Bb clarinet', 60, 'to_written'], 62), (['F horn', 67, 'to_concert'], 60), (['F horn', 60, 'to_written'], 67), (['flute', 127, 'to_concert'], 127), (['piccolo', 115, 'to_concert'], 127), (['Eb baritone sax', 10, 'to_concert'], None), (['guitar', 0, 'to_concert'], None)], [(['F horn', 60, 'to_written'], 67), (['Eb alto sax', 69, 'to_concert'], 60), (['Eb alto sax', 60, 'to_written'], 69), (['Bb tenor sax', 74, 'to_concert'], 60), (['flute', 127, 'to_concert'], 127), (['piccolo', 115, 'to_concert'], 127), (['Bb clarinet', 1, 'to_concert'], None), (['Bb tenor sax', 13, 'to_concert'], None)], [(['Bb tenor sax', 74, 'to_concert'], 60), (['Bb tenor sax', 60, 'to_written'], 74), (['piccolo', 60, 'to_concert'], 72), (['piccolo', 72, 'to_written'], 60), (['flute', 127, 'to_concert'], 127), (['piccolo', 115, 'to_concert'], 127), (['Eb baritone sax', 10, 'to_concert'], None), (['guitar', 0, 'to_concert'], None)], [(['piccolo', 72, 'to_written'], 60), (['D trumpet', 60, 'to_concert'], 62), (['D trumpet', 62, 'to_written'], 60), (['guitar', 64, 'to_concert'], 52), (['flute', 127, 'to_concert'], 127), (['piccolo', 115, 'to_concert'], 127), (['Bb clarinet', 1, 'to_concert'], None), (['Bb tenor sax', 13, 'to_concert'], None)], [(['guitar', 64, 'to_concert'], 52), (['flute', 60, 'to_concert'], 60), (['flute', 60, 'to_written'], 60), (['flute', 127, 'to_concert'], 127), (['piccolo', 115, 'to_concert'], 127), (['Eb baritone sax', 10, 'to_concert'], None), (['piccolo', 120, 'to_concert'], None), (['guitar', 0, 'to_concert'], 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 | 62 | 62 | Passed |
| oracle 2 | 60 | 60 | Passed |
| oracle 3 | 67 | 67 | Passed |
| oracle 4 | 127 | 127 | Passed |
| oracle 5 | 127 | 127 | Passed |
| oracle 6 | -11 | None | Failed |
| oracle 7 | -12 | None | Failed |
SHA-256 / add741b7a8f3286ee2c036664cb07863b8c377b4081474c752f1ae8d183ab2d3
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
table = {'Bb clarinet': -2, 'A clarinet': -3, 'F horn': -7, 'Eb alto sax': -9, 'Bb tenor sax': -14, 'Eb baritone sax': -21, 'guitar': -12, 'piccolo': 12, 'D trumpet': 2, 'flute': 0}
if not isinstance(x, list) or len(x) != 3:
return None
inst, pitch, direction = x
if inst not in table or not isinstance(pitch, int) or not 0 <= pitch <= 127:
return None
if direction == 'to_concert':
out = pitch + table[inst]
elif direction == 'to_written':
out = pitch - table[inst]
else:
return None
if out < 0 or out >= 127:
return None
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['Bb clarinet', 62, 'to_concert'], 60), (['Bb clarinet', 60, 'to_written'], 62), (['F horn', 67, 'to_concert'], 60), (['F horn', 60, 'to_written'], 67), (['flute', 127, 'to_concert'], 127), (['piccolo', 115, 'to_concert'], 127), (['Eb baritone sax', 10, 'to_concert'], None), (['guitar', 0, 'to_concert'], None)], [(['F horn', 60, 'to_written'], 67), (['Eb alto sax', 69, 'to_concert'], 60), (['Eb alto sax', 60, 'to_written'], 69), (['Bb tenor sax', 74, 'to_concert'], 60), (['flute', 127, 'to_concert'], 127), (['piccolo', 115, 'to_concert'], 127), (['Bb clarinet', 1, 'to_concert'], None), (['Bb tenor sax', 13, 'to_concert'], None)], [(['Bb tenor sax', 74, 'to_concert'], 60), (['Bb tenor sax', 60, 'to_written'], 74), (['piccolo', 60, 'to_concert'], 72), (['piccolo', 72, 'to_written'], 60), (['flute', 127, 'to_concert'], 127), (['piccolo', 115, 'to_concert'], 127), (['Eb baritone sax', 10, 'to_concert'], None), (['guitar', 0, 'to_concert'], None)], [(['piccolo', 72, 'to_written'], 60), (['D trumpet', 60, 'to_concert'], 62), (['D trumpet', 62, 'to_written'], 60), (['guitar', 64, 'to_concert'], 52), (['flute', 127, 'to_concert'], 127), (['piccolo', 115, 'to_concert'], 127), (['Bb clarinet', 1, 'to_concert'], None), (['Bb tenor sax', 13, 'to_concert'], None)], [(['guitar', 64, 'to_concert'], 52), (['flute', 60, 'to_concert'], 60), (['flute', 60, 'to_written'], 60), (['flute', 127, 'to_concert'], 127), (['piccolo', 115, 'to_concert'], 127), (['Eb baritone sax', 10, 'to_concert'], None), (['piccolo', 120, 'to_concert'], None), (['guitar', 0, 'to_concert'], 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 | 62 | 62 | Passed |
| oracle 2 | 60 | 60 | Passed |
| oracle 3 | 67 | 67 | Passed |
| oracle 4 | None | 127 | Failed |
| oracle 5 | None | 127 | Failed |
| oracle 6 | None | None | Passed |
| oracle 7 | None | None | Passed |
SHA-256 / ee2b714194f0a2e40a17b24bedafad23a52b83cf852f5199d6a3004006106413
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
table = {'Bb clarinet': -2, 'A clarinet': -3, 'F horn': -7, 'Eb alto sax': -9, 'Bb tenor sax': -14, 'Eb baritone sax': -21, 'guitar': -12, 'piccolo': 12, 'D trumpet': 2, 'flute': 0}
if not isinstance(x, list) or len(x) != 3:
return None
inst, pitch, direction = x
if inst not in table or not isinstance(pitch, int) or not 0 <= pitch <= 127:
return None
if direction == 'to_concert':
out = pitch + table[inst]
elif direction == 'to_written':
out = pitch - table[inst]
else:
return None
if out < 0 or out > 127:
return None
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['Bb clarinet', 62, 'to_concert'], 60), (['Bb clarinet', 60, 'to_written'], 62), (['F horn', 67, 'to_concert'], 60), (['F horn', 60, 'to_written'], 67), (['flute', 127, 'to_concert'], 127), (['piccolo', 115, 'to_concert'], 127), (['Eb baritone sax', 10, 'to_concert'], None), (['guitar', 0, 'to_concert'], None)], [(['F horn', 60, 'to_written'], 67), (['Eb alto sax', 69, 'to_concert'], 60), (['Eb alto sax', 60, 'to_written'], 69), (['Bb tenor sax', 74, 'to_concert'], 60), (['flute', 127, 'to_concert'], 127), (['piccolo', 115, 'to_concert'], 127), (['Bb clarinet', 1, 'to_concert'], None), (['Bb tenor sax', 13, 'to_concert'], None)], [(['Bb tenor sax', 74, 'to_concert'], 60), (['Bb tenor sax', 60, 'to_written'], 74), (['piccolo', 60, 'to_concert'], 72), (['piccolo', 72, 'to_written'], 60), (['flute', 127, 'to_concert'], 127), (['piccolo', 115, 'to_concert'], 127), (['Eb baritone sax', 10, 'to_concert'], None), (['guitar', 0, 'to_concert'], None)], [(['piccolo', 72, 'to_written'], 60), (['D trumpet', 60, 'to_concert'], 62), (['D trumpet', 62, 'to_written'], 60), (['guitar', 64, 'to_concert'], 52), (['flute', 127, 'to_concert'], 127), (['piccolo', 115, 'to_concert'], 127), (['Bb clarinet', 1, 'to_concert'], None), (['Bb tenor sax', 13, 'to_concert'], None)], [(['guitar', 64, 'to_concert'], 52), (['flute', 60, 'to_concert'], 60), (['flute', 60, 'to_written'], 60), (['flute', 127, 'to_concert'], 127), (['piccolo', 115, 'to_concert'], 127), (['Eb baritone sax', 10, 'to_concert'], None), (['piccolo', 120, 'to_concert'], None), (['guitar', 0, 'to_concert'], 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 | 62 | 62 | Passed |
| oracle 2 | 60 | 60 | Passed |
| oracle 3 | 67 | 67 | Passed |
| oracle 4 | 127 | 127 | Passed |
| oracle 5 | 127 | 127 | Passed |
| oracle 6 | None | None | Passed |
| oracle 7 | None | None | Passed |
SHA-256 / 331bef15f4cd537610608b760d6bf6ef76e353ffb9c9109d7d6c4e38c003a2ad
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:59.993434+00:00.
Case digest / 28987716dfcd8a575b41ca585321e670808252a8ec0d23dcaae89f6f813b2b1c