FA-80991 / Music interval and transposition theory / Open access
Key signature and measure accidental resolution: natural sign falls back to the key signature · case 01
In G major, F4 after an explicit natural plays F#4 again because the natural mark (zero) is treated as absent.
ROOT CAUSE
The lookup uses a truthiness fallback, so a stored alteration of zero reverts to the signature.
VERIFIED REPAIR
Restore the natural cancellation step so that it reads `alter = marks[slot] if slot in marks else keysig.get(letter, 0)`.
Unsuccessful approach: Adding the measure mark to the signature double-counts: an explicit F#4 in G major becomes F##4.
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 '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.get(slot) or 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]), ([0, ['C#4', 'C5', 'C4']], [61, 72, 61]), ([-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]), ([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68])], [([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([2, ['F4', 'C5', 'G4']], [66, 73, 67]), ([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([-7, ['F4', 'C4', 'B3']], [64, 59, 58]), ([7, ['B3', 'E4', 'C4']], [60, 65, 61]), ([8, ['C4']], None), ([0, ['H4']], None), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62])], [([-2, ['Eb4', 'E4', 'En4', 'E4']], [63, 63, 64, 64]), ([7, ['B3', 'E4', 'C4']], [60, 65, 61]), ([8, ['C4']], None), ([0, ['H4']], None), ([0, ['C#44']], None), ([-4, ['D4', 'Db4', 'D4', '|', 'D4']], [61, 61, 61, 61]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59])], [([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68]), ([0, ['C#44']], None), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59]), ([-5, ['G4', 'Gn4', 'G4', 'G5']], [66, 67, 67, 78]), ([6, ['E4', 'B4', 'A4']], [65, 71, 70]), ([0, ['Ab4', '|', 'Ab4', 'A4']], [68, 68, 68])], [([1, ['F4', 'Fn4', 'F4', '|', 'F4']], [66, 65, 65, 66]), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([-5, ['G4', 'Gn4', 'G4', 'G5']], [66, 67, 67, 78]), ([1, ['Fn4', 'Fn5', 'F5', 'F4']], [65, 77, 77, 65]), ([0, ['Ab4', '|', 'Ab4', 'A4']], [68, 68, 68]), ([0, ['F#3', 'F#4', 'F3', 'F4']], [54, 66, 54, 66]), ([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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| oracle 0 | [66, 66, 66, 66] | [66, 65, 65, 66] | Failed |
| oracle 1 | [61, 61, 60] | [61, 61, 60] | Passed |
| oracle 2 | [61, 72, 61] | [61, 72, 61] | 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, 63, 63] | [63, 63, 64, 64] | Failed |
| oracle 6 | [65, 65, 67] | [65, 65, 67] | Passed |
| oracle 7 | [67, 67, 66, 68] | [67, 67, 66, 68] | Passed |
SHA-256 / c23cab576790fd906c2e1b44b01a5f0c1a2bf42213f8defdb6e7b9ed37576dfa
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'[:-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 = keysig.get(letter, 0) + marks.get(slot, 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]), ([0, ['C#4', 'C5', 'C4']], [61, 72, 61]), ([-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]), ([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68])], [([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([2, ['F4', 'C5', 'G4']], [66, 73, 67]), ([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([-7, ['F4', 'C4', 'B3']], [64, 59, 58]), ([7, ['B3', 'E4', 'C4']], [60, 65, 61]), ([8, ['C4']], None), ([0, ['H4']], None), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62])], [([-2, ['Eb4', 'E4', 'En4', 'E4']], [63, 63, 64, 64]), ([7, ['B3', 'E4', 'C4']], [60, 65, 61]), ([8, ['C4']], None), ([0, ['H4']], None), ([0, ['C#44']], None), ([-4, ['D4', 'Db4', 'D4', '|', 'D4']], [61, 61, 61, 61]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59])], [([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68]), ([0, ['C#44']], None), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59]), ([-5, ['G4', 'Gn4', 'G4', 'G5']], [66, 67, 67, 78]), ([6, ['E4', 'B4', 'A4']], [65, 71, 70]), ([0, ['Ab4', '|', 'Ab4', 'A4']], [68, 68, 68])], [([1, ['F4', 'Fn4', 'F4', '|', 'F4']], [66, 65, 65, 66]), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([-5, ['G4', 'Gn4', 'G4', 'G5']], [66, 67, 67, 78]), ([1, ['Fn4', 'Fn5', 'F5', 'F4']], [65, 77, 77, 65]), ([0, ['Ab4', '|', 'Ab4', 'A4']], [68, 68, 68]), ([0, ['F#3', 'F#4', 'F3', 'F4']], [54, 66, 54, 66]), ([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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| oracle 0 | [66, 66, 66, 66] | [66, 65, 65, 66] | Failed |
| oracle 1 | [61, 61, 60] | [61, 61, 60] | Passed |
| oracle 2 | [61, 72, 61] | [61, 72, 61] | Passed |
| oracle 3 | [63, 68, 70, 62] | [63, 68, 70, 62] | Passed |
| oracle 4 | [66, 73, 67] | [66, 73, 67] | Passed |
| oracle 5 | [62, 62, 63, 63] | [63, 63, 64, 64] | Failed |
| oracle 6 | [65, 65, 67] | [65, 65, 67] | Passed |
| oracle 7 | [68, 68, 66, 68] | [67, 67, 66, 68] | Failed |
SHA-256 / 9a3b8950a7160e58628bd0840609eb10c465f8820a86eddf2a8cac300decf1e2
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]), ([0, ['C#4', 'C5', 'C4']], [61, 72, 61]), ([-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]), ([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68])], [([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([2, ['F4', 'C5', 'G4']], [66, 73, 67]), ([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([-7, ['F4', 'C4', 'B3']], [64, 59, 58]), ([7, ['B3', 'E4', 'C4']], [60, 65, 61]), ([8, ['C4']], None), ([0, ['H4']], None), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62])], [([-2, ['Eb4', 'E4', 'En4', 'E4']], [63, 63, 64, 64]), ([7, ['B3', 'E4', 'C4']], [60, 65, 61]), ([8, ['C4']], None), ([0, ['H4']], None), ([0, ['C#44']], None), ([-4, ['D4', 'Db4', 'D4', '|', 'D4']], [61, 61, 61, 61]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59])], [([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68]), ([0, ['C#44']], None), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59]), ([-5, ['G4', 'Gn4', 'G4', 'G5']], [66, 67, 67, 78]), ([6, ['E4', 'B4', 'A4']], [65, 71, 70]), ([0, ['Ab4', '|', 'Ab4', 'A4']], [68, 68, 68])], [([1, ['F4', 'Fn4', 'F4', '|', 'F4']], [66, 65, 65, 66]), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([-5, ['G4', 'Gn4', 'G4', 'G5']], [66, 67, 67, 78]), ([1, ['Fn4', 'Fn5', 'F5', 'F4']], [65, 77, 77, 65]), ([0, ['Ab4', '|', 'Ab4', 'A4']], [68, 68, 68]), ([0, ['F#3', 'F#4', 'F3', 'F4']], [54, 66, 54, 66]), ([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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| oracle 0 | [66, 65, 65, 66] | [66, 65, 65, 66] | Passed |
| oracle 1 | [61, 61, 60] | [61, 61, 60] | Passed |
| oracle 2 | [61, 72, 61] | [61, 72, 61] | 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 | [65, 65, 67] | [65, 65, 67] | Passed |
| oracle 7 | [67, 67, 66, 68] | [67, 67, 66, 68] | Passed |
SHA-256 / d0328f3f6d9a3326dcccaeea3f406ce07d38bd5723ae460b3afa92447cadc5b3
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.862822+00:00.
Case digest / e1b5af369fc1fb50a731c43814b2f716ec1709d8ef6c774ac6802cccf1e03d38