FAILURE MAP
← Case archive

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

Key signature and measure accidental resolution: flat signature built in sharp order · case 01

In F major the note F4 is flattened instead of B4; every flat key signature alters the wrong letters.

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

ROOT CAUSE

Flat signatures take letters from the sharp order instead of the reversed order B E A D G C F.

VERIFIED REPAIR

Restore the flat signature order step so that it reads `'BEADGCF'[:-fifths]`.

Unsuccessful approach: Using the right order but one fewer letter drops the last flat, so Eb major leaves A natural.

Case contract

Input [fifths, tokens]. fifths -7..7 gives signature sharps on F C G D A E B or flats on B E A D G C F. Tokens are "|" (barline) or letter + optional sign (# b x bb n) + single-digit octave. An explicit sign sets the alteration for that letter in that octave until the next barline (n = 0 cancels the signature); otherwise the signature applies. Return the MIDI numbers (C4 = 60) or None if any token or the signature is invalid.

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
    fifths, tokens = x
    if not isinstance(fifths, int) or fifths < -7 or fifths > 7:
        return None
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    keysig = {}
    if fifths > 0:
        for letter in 'FCGDAEB'[:fifths]:
            keysig[letter] = 1
    else:
        for letter in 'FCGDAEB'[:-fifths]:
            keysig[letter] = -1
    marks = {}
    out = []
    for tok in tokens:
        if tok == '|':
            marks = {}
            continue
        letter, sign, octave = tok[0], tok[1:-1], tok[-1]
        if letter not in base or not octave.isdigit() or sign not in ('', '#', 'b', 'n', 'x', 'bb'):
            return None
        slot = letter + octave
        if sign:
            marks[slot] = {'#': 1, 'b': -1, 'n': 0, 'x': 2, 'bb': -2}[sign]
        alter = marks[slot] if slot in marks else keysig.get(letter, 0)
        out.append(12 * (int(octave) + 1) + base[letter] + alter)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([1, ['F4', 'Fn4', 'F4', '|', 'F4']], [66, 65, 65, 66]), ([0, ['C#4', 'C4', '|', 'C4']], [61, 61, 60]), ([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([-3, ['E4', 'A4', 'B4', 'D4']], [63, 68, 70, 62]), ([2, ['F4', 'C5', 'G4']], [66, 73, 67]), ([-2, ['Eb4', 'E4', 'En4', 'E4']], [63, 63, 64, 64]), ([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68]), ([-1, ['Bbb4', 'B4', '|', 'B4']], [69, 69, 70])], [([0, ['C#4', 'C5', 'C4']], [61, 72, 61]), ([-3, ['E4', 'A4', 'B4', 'D4']], [63, 68, 70, 62]), ([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68]), ([7, ['B3', 'E4', 'C4']], [60, 65, 61]), ([8, ['C4']], None), ([0, ['H4']], None), ([-2, ['B4', 'E4', 'Bn4', 'B4', 'E4']], [70, 63, 71, 71, 63])], [([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([-7, ['F4', 'C4', 'B3']], [64, 59, 58]), ([0, ['H4']], None), ([0, ['C#44']], None), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([1, ['Fn4', 'Fn5', 'F5', 'F4']], [65, 77, 77, 65]), ([-1, ['Bbb4', 'B4', '|', 'B4']], [69, 69, 70])], [([-3, ['E4', 'A4', 'B4', 'D4']], [63, 68, 70, 62]), ([-4, ['D4', 'Db4', 'D4', '|', 'D4']], [61, 61, 61, 61]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([1, ['Fn4', 'Fn5', 'F5', 'F4']], [65, 77, 77, 65]), ([6, ['E4', 'B4', 'A4']], [65, 71, 70]), ([0, ['Ab4', '|', 'Ab4', 'A4']], [68, 68, 68]), ([2, ['C#4', 'Cn4', 'C4', '|', 'C4']], [61, 60, 60, 61]), ([-2, ['B4', 'E4', 'Bn4', 'B4', 'E4']], [70, 63, 71, 71, 63])], [([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59]), ([0, ['Ab4', '|', 'Ab4', 'A4']], [68, 68, 68]), ([2, ['C#4', 'Cn4', 'C4', '|', 'C4']], [61, 60, 60, 61]), ([0, ['F#3', 'F#4', 'F3', 'F4']], [54, 66, 54, 66]), ([-1, ['Bbb4', 'B4', '|', 'B4']], [69, 69, 70]), ([0, ['Cq4']], 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 fixtureActualExpectedOutcome
oracle 0[66, 65, 65, 66][66, 65, 65, 66]Passed
oracle 1[61, 61, 60][61, 61, 60]Passed
oracle 2[71, 71, 71, 71][70, 71, 71, 70]Failed
oracle 3[64, 69, 71, 62][63, 68, 70, 62]Failed
oracle 4[66, 73, 67][66, 73, 67]Passed
oracle 5[63, 63, 64, 64][63, 63, 64, 64]Passed
oracle 6[67, 67, 66, 68][67, 67, 66, 68]Passed
oracle 7[69, 69, 71][69, 69, 70]Failed

SHA-256 / 2e262f4d1a66bfa7b4cdbca94b599168d8fbdcaf5addb5c2f7c8b96211a365fd

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
    fifths, tokens = x
    if not isinstance(fifths, int) or fifths < -7 or fifths > 7:
        return None
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    keysig = {}
    if fifths > 0:
        for letter in 'FCGDAEB'[:fifths]:
            keysig[letter] = 1
    else:
        for letter in 'BEADGCF'[:abs(fifths) - 1]:
            keysig[letter] = -1
    marks = {}
    out = []
    for tok in tokens:
        if tok == '|':
            marks = {}
            continue
        letter, sign, octave = tok[0], tok[1:-1], tok[-1]
        if letter not in base or not octave.isdigit() or sign not in ('', '#', 'b', 'n', 'x', 'bb'):
            return None
        slot = letter + octave
        if sign:
            marks[slot] = {'#': 1, 'b': -1, 'n': 0, 'x': 2, 'bb': -2}[sign]
        alter = marks[slot] if slot in marks else keysig.get(letter, 0)
        out.append(12 * (int(octave) + 1) + base[letter] + alter)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([1, ['F4', 'Fn4', 'F4', '|', 'F4']], [66, 65, 65, 66]), ([0, ['C#4', 'C4', '|', 'C4']], [61, 61, 60]), ([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([-3, ['E4', 'A4', 'B4', 'D4']], [63, 68, 70, 62]), ([2, ['F4', 'C5', 'G4']], [66, 73, 67]), ([-2, ['Eb4', 'E4', 'En4', 'E4']], [63, 63, 64, 64]), ([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68]), ([-1, ['Bbb4', 'B4', '|', 'B4']], [69, 69, 70])], [([0, ['C#4', 'C5', 'C4']], [61, 72, 61]), ([-3, ['E4', 'A4', 'B4', 'D4']], [63, 68, 70, 62]), ([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68]), ([7, ['B3', 'E4', 'C4']], [60, 65, 61]), ([8, ['C4']], None), ([0, ['H4']], None), ([-2, ['B4', 'E4', 'Bn4', 'B4', 'E4']], [70, 63, 71, 71, 63])], [([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([-7, ['F4', 'C4', 'B3']], [64, 59, 58]), ([0, ['H4']], None), ([0, ['C#44']], None), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([1, ['Fn4', 'Fn5', 'F5', 'F4']], [65, 77, 77, 65]), ([-1, ['Bbb4', 'B4', '|', 'B4']], [69, 69, 70])], [([-3, ['E4', 'A4', 'B4', 'D4']], [63, 68, 70, 62]), ([-4, ['D4', 'Db4', 'D4', '|', 'D4']], [61, 61, 61, 61]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([1, ['Fn4', 'Fn5', 'F5', 'F4']], [65, 77, 77, 65]), ([6, ['E4', 'B4', 'A4']], [65, 71, 70]), ([0, ['Ab4', '|', 'Ab4', 'A4']], [68, 68, 68]), ([2, ['C#4', 'Cn4', 'C4', '|', 'C4']], [61, 60, 60, 61]), ([-2, ['B4', 'E4', 'Bn4', 'B4', 'E4']], [70, 63, 71, 71, 63])], [([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59]), ([0, ['Ab4', '|', 'Ab4', 'A4']], [68, 68, 68]), ([2, ['C#4', 'Cn4', 'C4', '|', 'C4']], [61, 60, 60, 61]), ([0, ['F#3', 'F#4', 'F3', 'F4']], [54, 66, 54, 66]), ([-1, ['Bbb4', 'B4', '|', 'B4']], [69, 69, 70]), ([0, ['Cq4']], 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 fixtureActualExpectedOutcome
oracle 0[66, 65, 65, 66][66, 65, 65, 66]Passed
oracle 1[61, 61, 59][61, 61, 60]Failed
oracle 2[71, 71, 71, 71][70, 71, 71, 70]Failed
oracle 3[63, 69, 70, 62][63, 68, 70, 62]Failed
oracle 4[66, 73, 67][66, 73, 67]Passed
oracle 5[63, 63, 64, 64][63, 63, 64, 64]Passed
oracle 6[67, 67, 66, 68][67, 67, 66, 68]Passed
oracle 7[69, 69, 71][69, 69, 70]Failed

SHA-256 / 429be2eaac91a26e4aa7aa40b3561fcd62b107ee3f04687ebae0af42ade4594f

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
    fifths, tokens = x
    if not isinstance(fifths, int) or fifths < -7 or fifths > 7:
        return None
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    keysig = {}
    if fifths > 0:
        for letter in 'FCGDAEB'[:fifths]:
            keysig[letter] = 1
    else:
        for letter in 'BEADGCF'[:-fifths]:
            keysig[letter] = -1
    marks = {}
    out = []
    for tok in tokens:
        if tok == '|':
            marks = {}
            continue
        letter, sign, octave = tok[0], tok[1:-1], tok[-1]
        if letter not in base or not octave.isdigit() or sign not in ('', '#', 'b', 'n', 'x', 'bb'):
            return None
        slot = letter + octave
        if sign:
            marks[slot] = {'#': 1, 'b': -1, 'n': 0, 'x': 2, 'bb': -2}[sign]
        alter = marks[slot] if slot in marks else keysig.get(letter, 0)
        out.append(12 * (int(octave) + 1) + base[letter] + alter)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([1, ['F4', 'Fn4', 'F4', '|', 'F4']], [66, 65, 65, 66]), ([0, ['C#4', 'C4', '|', 'C4']], [61, 61, 60]), ([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([-3, ['E4', 'A4', 'B4', 'D4']], [63, 68, 70, 62]), ([2, ['F4', 'C5', 'G4']], [66, 73, 67]), ([-2, ['Eb4', 'E4', 'En4', 'E4']], [63, 63, 64, 64]), ([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68]), ([-1, ['Bbb4', 'B4', '|', 'B4']], [69, 69, 70])], [([0, ['C#4', 'C5', 'C4']], [61, 72, 61]), ([-3, ['E4', 'A4', 'B4', 'D4']], [63, 68, 70, 62]), ([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68]), ([7, ['B3', 'E4', 'C4']], [60, 65, 61]), ([8, ['C4']], None), ([0, ['H4']], None), ([-2, ['B4', 'E4', 'Bn4', 'B4', 'E4']], [70, 63, 71, 71, 63])], [([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([-7, ['F4', 'C4', 'B3']], [64, 59, 58]), ([0, ['H4']], None), ([0, ['C#44']], None), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([1, ['Fn4', 'Fn5', 'F5', 'F4']], [65, 77, 77, 65]), ([-1, ['Bbb4', 'B4', '|', 'B4']], [69, 69, 70])], [([-3, ['E4', 'A4', 'B4', 'D4']], [63, 68, 70, 62]), ([-4, ['D4', 'Db4', 'D4', '|', 'D4']], [61, 61, 61, 61]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([1, ['Fn4', 'Fn5', 'F5', 'F4']], [65, 77, 77, 65]), ([6, ['E4', 'B4', 'A4']], [65, 71, 70]), ([0, ['Ab4', '|', 'Ab4', 'A4']], [68, 68, 68]), ([2, ['C#4', 'Cn4', 'C4', '|', 'C4']], [61, 60, 60, 61]), ([-2, ['B4', 'E4', 'Bn4', 'B4', 'E4']], [70, 63, 71, 71, 63])], [([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59]), ([0, ['Ab4', '|', 'Ab4', 'A4']], [68, 68, 68]), ([2, ['C#4', 'Cn4', 'C4', '|', 'C4']], [61, 60, 60, 61]), ([0, ['F#3', 'F#4', 'F3', 'F4']], [54, 66, 54, 66]), ([-1, ['Bbb4', 'B4', '|', 'B4']], [69, 69, 70]), ([0, ['Cq4']], 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 fixtureActualExpectedOutcome
oracle 0[66, 65, 65, 66][66, 65, 65, 66]Passed
oracle 1[61, 61, 60][61, 61, 60]Passed
oracle 2[70, 71, 71, 70][70, 71, 71, 70]Passed
oracle 3[63, 68, 70, 62][63, 68, 70, 62]Passed
oracle 4[66, 73, 67][66, 73, 67]Passed
oracle 5[63, 63, 64, 64][63, 63, 64, 64]Passed
oracle 6[67, 67, 66, 68][67, 67, 66, 68]Passed
oracle 7[69, 69, 70][69, 69, 70]Passed

SHA-256 / cefd651496be378a880d39211761732916771b21b2f3e016c692b74935b808ea

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

Case digest / 5699798cde42fa7f24c2608e7718e51e053c66d0be2d485d04d6f94d6d922662