FAILURE MAP
← Case archive

FA-80851 / Music interval and transposition theory / Open access

Spelled pitch to MIDI key number: octave minus one rejected as malformed · case 01

Every pitch in octave -1 (C-1 through B-1) is rejected even though keys 0..11 are valid.

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

ROOT CAUSE

The octave parser never recognises a leading minus sign, so the digit check fails on "-1".

VERIFIED REPAIR

Restore the negative octave sign step so that it reads `neg = tail.startswith('-')`.

Unsuccessful approach: Requiring more than one digit after the minus sign still rejects the single-digit octave -1.

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 = False
    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), ('Ab9', None), ('Cx-1', 2), ('Bx-1', 13)], [('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('B-1', 11), ('Bx-1', 13), ('G-1', 7)], [('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None), ('Cx-1', 2), ('G-1', 7), ('Ab-1', 8)], [('C-1', 0), ('Dbbb4', 59), ('Cb-1', None), ('E4', 64), ('F4', 65), ('B4', 71), ('Bx-1', 13), ('Ab-1', 8)], [('C-1', 0), ('B-1', 11), ('F4', 65), ('B4', 71), ('Bb3', 58), ('C0', 12), ('D#0', 15), ('G-1', 7)]]
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 fixtureActualExpectedOutcome
oracle 06060Passed
oracle 16969Passed
oracle 2None0Failed
oracle 3127127Passed
oracle 4NoneNonePassed
oracle 5NoneNonePassed
oracle 6None2Failed
oracle 7None13Failed

SHA-256 / d2d62220551803e8a309fe4ee682821a642469de0a3ba91e898802f28dd43c61

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('-') and len(tail) > 2
    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), ('Ab9', None), ('Cx-1', 2), ('Bx-1', 13)], [('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('B-1', 11), ('Bx-1', 13), ('G-1', 7)], [('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None), ('Cx-1', 2), ('G-1', 7), ('Ab-1', 8)], [('C-1', 0), ('Dbbb4', 59), ('Cb-1', None), ('E4', 64), ('F4', 65), ('B4', 71), ('Bx-1', 13), ('Ab-1', 8)], [('C-1', 0), ('B-1', 11), ('F4', 65), ('B4', 71), ('Bb3', 58), ('C0', 12), ('D#0', 15), ('G-1', 7)]]
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 fixtureActualExpectedOutcome
oracle 06060Passed
oracle 16969Passed
oracle 2None0Failed
oracle 3127127Passed
oracle 4NoneNonePassed
oracle 5NoneNonePassed
oracle 6None2Failed
oracle 7None13Failed

SHA-256 / f59f75253790af9e6d9a295bb03df695da2f5be8edf3a5dc4d664937da1ef7bb

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), ('Ab9', None), ('Cx-1', 2), ('Bx-1', 13)], [('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('B-1', 11), ('Bx-1', 13), ('G-1', 7)], [('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None), ('Cx-1', 2), ('G-1', 7), ('Ab-1', 8)], [('C-1', 0), ('Dbbb4', 59), ('Cb-1', None), ('E4', 64), ('F4', 65), ('B4', 71), ('Bx-1', 13), ('Ab-1', 8)], [('C-1', 0), ('B-1', 11), ('F4', 65), ('B4', 71), ('Bb3', 58), ('C0', 12), ('D#0', 15), ('G-1', 7)]]
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 fixtureActualExpectedOutcome
oracle 06060Passed
oracle 16969Passed
oracle 200Passed
oracle 3127127Passed
oracle 4NoneNonePassed
oracle 5NoneNonePassed
oracle 622Passed
oracle 71313Passed

SHA-256 / c2a0249a59573f5e093bc303a749c12d6fee0dfd49b0a5dbd74009eb82d2b44a

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

Case digest / 93234b63c18421275cd9526787449b659063a7cae5cdc4ebed21a57696a80c1d