FAILURE MAP
← Case archive

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

Key-aware MIDI note spelling: E sharp spelling limited to seven sharps · case 01

In F# major, key 65 is spelled F4 instead of the stipulated E#4.

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

ROOT CAUSE

The E# respelling is guarded by the seven-sharp condition used for B#, not by six or more sharps.

VERIFIED REPAIR

Restore the E sharp threshold step so that it reads `f >= 6 and pc == 5`.

Unsuccessful approach: Lowering the threshold to five sharps also respells F natural as E# in B major.

Case contract

Input [midi, fifths] with midi 0..127 and fifths -7..7. Use flat names when fifths < 0, sharp names otherwise; in keys with at least six sharps pitch class 5 is E#, with seven sharps pitch class 0 is B# of the previous octave, and with at least six flats pitch class 11 is Cb of the next octave. Octave -1 starts at key 0. Invalid input returns 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):
    if not isinstance(x, list) or len(x) != 2:
        return None
    m, f = x
    if not isinstance(m, int) or m < 0 or m > 127:
        return None
    if not isinstance(f, int) or f < -7 or f > 7:
        return None
    sharps = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
    flats = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B']
    table = flats if f < 0 else sharps
    pc = m % 12
    octave = m // 12 - 1
    name = table[pc]
    if f == 7 and pc == 5:
        name = 'E#'
    if f == 7 and pc == 0:
        name = 'B#'
        octave -= 1
    if f <= -6 and pc == 11:
        name = 'Cb'
        octave += 1
    return name + str(octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([60, 0], 'C4'), ([61, 0], 'C#4'), ([61, -1], 'Db4'), ([61, 1], 'C#4'), ([70, -2], 'Bb4'), ([70, 2], 'A#4'), ([65, 6], 'E#4'), ([65, 5], 'F4')], [([61, 1], 'C#4'), ([70, -2], 'Bb4'), ([70, 2], 'A#4'), ([65, 5], 'F4'), ([65, 7], 'E#4'), ([65, -6], 'F4'), ([60, 7], 'B#3'), ([5, 6], 'E#-1')], [([65, 6], 'E#4'), ([65, 5], 'F4'), ([65, 7], 'E#4'), ([65, -6], 'F4'), ([60, 7], 'B#3'), ([48, 7], 'B#2'), ([71, -6], 'Cb5'), ([71, -7], 'Cb5')], [([65, 5], 'F4'), ([48, 7], 'B#2'), ([71, -6], 'Cb5'), ([71, -7], 'Cb5'), ([59, -6], 'Cb4'), ([0, 0], 'C-1'), ([1, -3], 'Db-1'), ([5, 6], 'E#-1')], [([65, 6], 'E#4'), ([65, 5], 'F4'), ([59, -6], 'Cb4'), ([0, 0], 'C-1'), ([1, -3], 'Db-1'), ([11, 0], 'B-1'), ([127, 0], 'G9'), ([127, 7], 'G9')]]
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 0C4C4Passed
oracle 1C#4C#4Passed
oracle 2Db4Db4Passed
oracle 3C#4C#4Passed
oracle 4Bb4Bb4Passed
oracle 5A#4A#4Passed
oracle 6F4E#4Failed
oracle 7F4F4Passed

SHA-256 / 4864938c5e59e594b0e24b45920e1900e7c4ed82acf3d1b5fa8af89f985197c4

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    if not isinstance(x, list) or len(x) != 2:
        return None
    m, f = x
    if not isinstance(m, int) or m < 0 or m > 127:
        return None
    if not isinstance(f, int) or f < -7 or f > 7:
        return None
    sharps = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
    flats = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B']
    table = flats if f < 0 else sharps
    pc = m % 12
    octave = m // 12 - 1
    name = table[pc]
    if f >= 5 and pc == 5:
        name = 'E#'
    if f == 7 and pc == 0:
        name = 'B#'
        octave -= 1
    if f <= -6 and pc == 11:
        name = 'Cb'
        octave += 1
    return name + str(octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([60, 0], 'C4'), ([61, 0], 'C#4'), ([61, -1], 'Db4'), ([61, 1], 'C#4'), ([70, -2], 'Bb4'), ([70, 2], 'A#4'), ([65, 6], 'E#4'), ([65, 5], 'F4')], [([61, 1], 'C#4'), ([70, -2], 'Bb4'), ([70, 2], 'A#4'), ([65, 5], 'F4'), ([65, 7], 'E#4'), ([65, -6], 'F4'), ([60, 7], 'B#3'), ([5, 6], 'E#-1')], [([65, 6], 'E#4'), ([65, 5], 'F4'), ([65, 7], 'E#4'), ([65, -6], 'F4'), ([60, 7], 'B#3'), ([48, 7], 'B#2'), ([71, -6], 'Cb5'), ([71, -7], 'Cb5')], [([65, 5], 'F4'), ([48, 7], 'B#2'), ([71, -6], 'Cb5'), ([71, -7], 'Cb5'), ([59, -6], 'Cb4'), ([0, 0], 'C-1'), ([1, -3], 'Db-1'), ([5, 6], 'E#-1')], [([65, 6], 'E#4'), ([65, 5], 'F4'), ([59, -6], 'Cb4'), ([0, 0], 'C-1'), ([1, -3], 'Db-1'), ([11, 0], 'B-1'), ([127, 0], 'G9'), ([127, 7], 'G9')]]
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 0C4C4Passed
oracle 1C#4C#4Passed
oracle 2Db4Db4Passed
oracle 3C#4C#4Passed
oracle 4Bb4Bb4Passed
oracle 5A#4A#4Passed
oracle 6E#4E#4Passed
oracle 7E#4F4Failed

SHA-256 / 6f1957a4733def9cabc37ef16e6e22827a7d5ef96cafbef39d2b5c6d8e9d075b

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    if not isinstance(x, list) or len(x) != 2:
        return None
    m, f = x
    if not isinstance(m, int) or m < 0 or m > 127:
        return None
    if not isinstance(f, int) or f < -7 or f > 7:
        return None
    sharps = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
    flats = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B']
    table = flats if f < 0 else sharps
    pc = m % 12
    octave = m // 12 - 1
    name = table[pc]
    if f >= 6 and pc == 5:
        name = 'E#'
    if f == 7 and pc == 0:
        name = 'B#'
        octave -= 1
    if f <= -6 and pc == 11:
        name = 'Cb'
        octave += 1
    return name + str(octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([60, 0], 'C4'), ([61, 0], 'C#4'), ([61, -1], 'Db4'), ([61, 1], 'C#4'), ([70, -2], 'Bb4'), ([70, 2], 'A#4'), ([65, 6], 'E#4'), ([65, 5], 'F4')], [([61, 1], 'C#4'), ([70, -2], 'Bb4'), ([70, 2], 'A#4'), ([65, 5], 'F4'), ([65, 7], 'E#4'), ([65, -6], 'F4'), ([60, 7], 'B#3'), ([5, 6], 'E#-1')], [([65, 6], 'E#4'), ([65, 5], 'F4'), ([65, 7], 'E#4'), ([65, -6], 'F4'), ([60, 7], 'B#3'), ([48, 7], 'B#2'), ([71, -6], 'Cb5'), ([71, -7], 'Cb5')], [([65, 5], 'F4'), ([48, 7], 'B#2'), ([71, -6], 'Cb5'), ([71, -7], 'Cb5'), ([59, -6], 'Cb4'), ([0, 0], 'C-1'), ([1, -3], 'Db-1'), ([5, 6], 'E#-1')], [([65, 6], 'E#4'), ([65, 5], 'F4'), ([59, -6], 'Cb4'), ([0, 0], 'C-1'), ([1, -3], 'Db-1'), ([11, 0], 'B-1'), ([127, 0], 'G9'), ([127, 7], 'G9')]]
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 0C4C4Passed
oracle 1C#4C#4Passed
oracle 2Db4Db4Passed
oracle 3C#4C#4Passed
oracle 4Bb4Bb4Passed
oracle 5A#4A#4Passed
oracle 6E#4E#4Passed
oracle 7F4F4Passed

SHA-256 / 6b7f5e76a12887bbf0dd352d9cec27b1b8e078a3a1f0893a612007f902b251de

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

Case digest / 97a03a2f05393634c0e89ad913425d8a86039be4cfb3d2a45ff45bc7ba1271e2