broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    coeffs, f, B, mode = x
    scale = 2 ** f
    hi, lo = 2 ** (B - 1) - 1, -2 ** (B - 1)
    codes = []
    sat = 0
    err = Fraction(0)
    for s in coeffs:
        c = Fraction(s)
        v = c * scale
        if mode == 'nearest':
            q = math.floor(abs(v) + Fraction(1, 2)) * (1 if v >= 0 else -1)
        else:
            q = math.floor(v)
        raw = q
        if q > hi or q < lo:
            sat += 1
            q = max(lo, min(hi, q))
        codes.append(q)
        err = max(err, abs(Fraction(raw, scale) - c))
    return {'codes': codes, 'saturated': sat, 'max_error': str(err)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: positive overflow', [['1', '0.99'], 7, 8, 'nearest'], {'codes': [127, 127], 'saturated': 1, 'max_error': '1/128'}], ['regression: negative overflow', [['-1.5'], 7, 8, 'truncate'], {'codes': [-128], 'saturated': 1, 'max_error': '1/2'}], ['repair check: tie cases nearest', [['0.125', '0.375', '-0.125'], 2, 8, 'nearest'], {'codes': [1, 2, -1], 'saturated': 0, 'max_error': '1/8'}], ['control: negative full scale', [['-1'], 7, 8, 'nearest'], {'codes': [-128], 'saturated': 0, 'max_error': '0'}], ['control: exact grid', [['0.5', '-0.25'], 2, 4, 'nearest'], {'codes': [2, -1], 'saturated': 0, 'max_error': '0'}], ['control: exact grid truncate', [['0.5', '-0.25', '0.75'], 2, 4, 'truncate'], {'codes': [2, -1, 3], 'saturated': 0, 'max_error': '0'}], ['control: integer multiple truncate', [['-0.5', '1.25'], 3, 6, 'truncate'], {'codes': [-4, 10], 'saturated': 0, 'max_error': '0'}]], [['regression: random quantize 8', [['0.08', '-2.194', '-0.29'], 4, 6, 'nearest'], {'codes': [1, -32, -5], 'saturated': 1, 'max_error': '97/500'}], ['regression: random quantize 9', [['-0.92', '1.79'], 4, 5, 'truncate'], {'codes': [-15, 15], 'saturated': 1, 'max_error': '341/400'}], ['regression: positive overflow', [['1', '0.99'], 7, 8, 'nearest'], {'codes': [127, 127], 'saturated': 1, 'max_error': '1/128'}], ['control: negative full scale', [['-1'], 7, 8, 'nearest'], {'codes': [-128], 'saturated': 0, 'max_error': '0'}], ['control: exact grid', [['0.5', '-0.25'], 2, 4, 'nearest'], {'codes': [2, -1], 'saturated': 0, 'max_error': '0'}], ['control: exact grid truncate', [['0.5', '-0.25', '0.75'], 2, 4, 'truncate'], {'codes': [2, -1, 3], 'saturated': 0, 'max_error': '0'}], ['control: integer multiple truncate', [['-0.5', '1.25'], 3, 6, 'truncate'], {'codes': [-4, 10], 'saturated': 0, 'max_error': '0'}]], [['regression: random quantize 21', [['1.81'], 6, 7, 'truncate'], {'codes': [63], 'saturated': 1, 'max_error': '1321/1600'}], ['regression: random quantize 26', [['-1.848', '0.82', '-1.59'], 2, 3, 'truncate'], {'codes': [-4, 3, -4], 'saturated': 2, 'max_error': '106/125'}], ['repair check: random quantize 0', [['-1.79', '1.59'], 3, 5, 'truncate'], {'codes': [-15, 12], 'saturated': 0, 'max_error': '9/100'}], ['control: negative full scale', [['-1'], 7, 8, 'nearest'], {'codes': [-128], 'saturated': 0, 'max_error': '0'}], ['control: exact grid', [['0.5', '-0.25'], 2, 4, 'nearest'], {'codes': [2, -1], 'saturated': 0, 'max_error': '0'}], ['control: exact grid truncate', [['0.5', '-0.25', '0.75'], 2, 4, 'truncate'], {'codes': [2, -1, 3], 'saturated': 0, 'max_error': '0'}], ['control: integer multiple truncate', [['-0.5', '1.25'], 3, 6, 'truncate'], {'codes': [-4, 10], 'saturated': 0, 'max_error': '0'}]], [['regression: random quantize 32', [['-1.79', '-1.633', '-0.38'], 3, 4, 'nearest'], {'codes': [-8, -8, -3], 'saturated': 2, 'max_error': '79/100'}], ['regression: random quantize 36', [['-1.29', '-1.846'], 3, 4, 'truncate'], {'codes': [-8, -8], 'saturated': 2, 'max_error': '423/500'}], ['repair check: random quantize 2', [['-0.09', '-0.09', '0.397'], 4, 7, 'nearest'], {'codes': [-1, -1, 6], 'saturated': 0, 'max_error': '11/400'}], ['control: negative full scale', [['-1'], 7, 8, 'nearest'], {'codes': [-128], 'saturated': 0, 'max_error': '0'}], ['control: exact grid', [['0.5', '-0.25'], 2, 4, 'nearest'], {'codes': [2, -1], 'saturated': 0, 'max_error': '0'}], ['control: exact grid truncate', [['0.5', '-0.25', '0.75'], 2, 4, 'truncate'], {'codes': [2, -1, 3], 'saturated': 0, 'max_error': '0'}], ['control: integer multiple truncate', [['-0.5', '1.25'], 3, 6, 'truncate'], {'codes': [-4, 10], 'saturated': 0, 'max_error': '0'}]], [['regression: random quantize 38', [['2.146', '-1.527', '-1.91'], 5, 6, 'nearest'], {'codes': [31, -32, -32], 'saturated': 3, 'max_error': '4709/4000'}], ['regression: random quantize 39', [['1.85', '-1.902'], 3, 4, 'truncate'], {'codes': [7, -8], 'saturated': 2, 'max_error': '39/40'}], ['regression: random quantize 4', [['-1.49', '-1.91'], 2, 3, 'nearest'], {'codes': [-4, -4], 'saturated': 2, 'max_error': '91/100'}], ['control: negative full scale', [['-1'], 7, 8, 'nearest'], {'codes': [-128], 'saturated': 0, 'max_error': '0'}], ['control: exact grid', [['0.5', '-0.25'], 2, 4, 'nearest'], {'codes': [2, -1], 'saturated': 0, 'max_error': '0'}], ['control: exact grid truncate', [['0.5', '-0.25', '0.75'], 2, 4, 'truncate'], {'codes': [2, -1, 3], 'saturated': 0, 'max_error': '0'}], ['control: integer multiple truncate', [['-0.5', '1.25'], 3, 6, 'truncate'], {'codes': [-4, 10], 'saturated': 0, 'max_error': '0'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    coeffs, f, B, mode = x
    scale = 2 ** f
    hi, lo = 2 ** (B - 1) - 1, -2 ** (B - 1)
    codes = []
    sat = 0
    err = Fraction(0)
    for s in coeffs:
        c = Fraction(s)
        v = c * scale
        if mode == 'nearest':
            q = math.floor(abs(v) + Fraction(1, 2)) * (1 if v >= 0 else -1)
        else:
            q = math.floor(v)
        if q > hi or q < lo:
            sat += 1
            q = max(lo, min(hi, q))
        codes.append(q)
        err = max(err, abs(q - v))
    return {'codes': codes, 'saturated': sat, 'max_error': str(err)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: positive overflow', [['1', '0.99'], 7, 8, 'nearest'], {'codes': [127, 127], 'saturated': 1, 'max_error': '1/128'}], ['regression: negative overflow', [['-1.5'], 7, 8, 'truncate'], {'codes': [-128], 'saturated': 1, 'max_error': '1/2'}], ['repair check: tie cases nearest', [['0.125', '0.375', '-0.125'], 2, 8, 'nearest'], {'codes': [1, 2, -1], 'saturated': 0, 'max_error': '1/8'}], ['control: negative full scale', [['-1'], 7, 8, 'nearest'], {'codes': [-128], 'saturated': 0, 'max_error': '0'}], ['control: exact grid', [['0.5', '-0.25'], 2, 4, 'nearest'], {'codes': [2, -1], 'saturated': 0, 'max_error': '0'}], ['control: exact grid truncate', [['0.5', '-0.25', '0.75'], 2, 4, 'truncate'], {'codes': [2, -1, 3], 'saturated': 0, 'max_error': '0'}], ['control: integer multiple truncate', [['-0.5', '1.25'], 3, 6, 'truncate'], {'codes': [-4, 10], 'saturated': 0, 'max_error': '0'}]], [['regression: random quantize 8', [['0.08', '-2.194', '-0.29'], 4, 6, 'nearest'], {'codes': [1, -32, -5], 'saturated': 1, 'max_error': '97/500'}], ['regression: random quantize 9', [['-0.92', '1.79'], 4, 5, 'truncate'], {'codes': [-15, 15], 'saturated': 1, 'max_error': '341/400'}], ['regression: positive overflow', [['1', '0.99'], 7, 8, 'nearest'], {'codes': [127, 127], 'saturated': 1, 'max_error': '1/128'}], ['control: negative full scale', [['-1'], 7, 8, 'nearest'], {'codes': [-128], 'saturated': 0, 'max_error': '0'}], ['control: exact grid', [['0.5', '-0.25'], 2, 4, 'nearest'], {'codes': [2, -1], 'saturated': 0, 'max_error': '0'}], ['control: exact grid truncate', [['0.5', '-0.25', '0.75'], 2, 4, 'truncate'], {'codes': [2, -1, 3], 'saturated': 0, 'max_error': '0'}], ['control: integer multiple truncate', [['-0.5', '1.25'], 3, 6, 'truncate'], {'codes': [-4, 10], 'saturated': 0, 'max_error': '0'}]], [['regression: random quantize 21', [['1.81'], 6, 7, 'truncate'], {'codes': [63], 'saturated': 1, 'max_error': '1321/1600'}], ['regression: random quantize 26', [['-1.848', '0.82', '-1.59'], 2, 3, 'truncate'], {'codes': [-4, 3, -4], 'saturated': 2, 'max_error': '106/125'}], ['repair check: random quantize 0', [['-1.79', '1.59'], 3, 5, 'truncate'], {'codes': [-15, 12], 'saturated': 0, 'max_error': '9/100'}], ['control: negative full scale', [['-1'], 7, 8, 'nearest'], {'codes': [-128], 'saturated': 0, 'max_error': '0'}], ['control: exact grid', [['0.5', '-0.25'], 2, 4, 'nearest'], {'codes': [2, -1], 'saturated': 0, 'max_error': '0'}], ['control: exact grid truncate', [['0.5', '-0.25', '0.75'], 2, 4, 'truncate'], {'codes': [2, -1, 3], 'saturated': 0, 'max_error': '0'}], ['control: integer multiple truncate', [['-0.5', '1.25'], 3, 6, 'truncate'], {'codes': [-4, 10], 'saturated': 0, 'max_error': '0'}]], [['regression: random quantize 32', [['-1.79', '-1.633', '-0.38'], 3, 4, 'nearest'], {'codes': [-8, -8, -3], 'saturated': 2, 'max_error': '79/100'}], ['regression: random quantize 36', [['-1.29', '-1.846'], 3, 4, 'truncate'], {'codes': [-8, -8], 'saturated': 2, 'max_error': '423/500'}], ['repair check: random quantize 2', [['-0.09', '-0.09', '0.397'], 4, 7, 'nearest'], {'codes': [-1, -1, 6], 'saturated': 0, 'max_error': '11/400'}], ['control: negative full scale', [['-1'], 7, 8, 'nearest'], {'codes': [-128], 'saturated': 0, 'max_error': '0'}], ['control: exact grid', [['0.5', '-0.25'], 2, 4, 'nearest'], {'codes': [2, -1], 'saturated': 0, 'max_error': '0'}], ['control: exact grid truncate', [['0.5', '-0.25', '0.75'], 2, 4, 'truncate'], {'codes': [2, -1, 3], 'saturated': 0, 'max_error': '0'}], ['control: integer multiple truncate', [['-0.5', '1.25'], 3, 6, 'truncate'], {'codes': [-4, 10], 'saturated': 0, 'max_error': '0'}]], [['regression: random quantize 38', [['2.146', '-1.527', '-1.91'], 5, 6, 'nearest'], {'codes': [31, -32, -32], 'saturated': 3, 'max_error': '4709/4000'}], ['regression: random quantize 39', [['1.85', '-1.902'], 3, 4, 'truncate'], {'codes': [7, -8], 'saturated': 2, 'max_error': '39/40'}], ['regression: random quantize 4', [['-1.49', '-1.91'], 2, 3, 'nearest'], {'codes': [-4, -4], 'saturated': 2, 'max_error': '91/100'}], ['control: negative full scale', [['-1'], 7, 8, 'nearest'], {'codes': [-128], 'saturated': 0, 'max_error': '0'}], ['control: exact grid', [['0.5', '-0.25'], 2, 4, 'nearest'], {'codes': [2, -1], 'saturated': 0, 'max_error': '0'}], ['control: exact grid truncate', [['0.5', '-0.25', '0.75'], 2, 4, 'truncate'], {'codes': [2, -1, 3], 'saturated': 0, 'max_error': '0'}], ['control: integer multiple truncate', [['-0.5', '1.25'], 3, 6, 'truncate'], {'codes': [-4, 10], 'saturated': 0, 'max_error': '0'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

prompt:
max_error understates the real error for saturated coefficients.

Input [coeffs, f, B, mode]: quantize each decimal coefficient to a B-bit two's-complement code with f fractional bits; "nearest" rounds half away from zero, "truncate" floors. Codes saturate to [-2^(B-1), 2^(B-1)-1]. Return {"codes", "saturated": count of clipped codes, "max_error": max |code/2^f - c| after saturation as a fraction string}.

split: open-access


meaning: Fixture-count band, not measured model difficulty

deps: stdlib

prompt:
With two or more sections, each section reads the delay values written by the previous one.

Input [gain, sections, limit, samples]; each section [b0, b1, b2, a1, a2] is a direct-form-I biquad (a0 = 1) with its own state. The input is scaled by gain, each section output is clamped to [-limit, limit] and the clamped value is both stored as that section's output state and fed to the next section. Return exact fraction strings.

split: open-access


prompt:
With saturating stages the output differs from gain-at-input: loud inputs are no longer clipped in the first stage.

Input [gain, sections, limit, samples]; each section [b0, b1, b2, a1, a2] is a direct-form-I biquad (a0 = 1) with its own state. The input is scaled by gain, each section output is clamped to [-limit, limit] and the clamped value is both stored as that section's output state and fed to the next section. Return exact fraction strings.

split: open-access


prompt:
Intermediate stages exceed the limit, so later stages see values the hardware could never produce.

Input [gain, sections, limit, samples]; each section [b0, b1, b2, a1, a2] is a direct-form-I biquad (a0 = 1) with its own state. The input is scaled by gain, each section output is clamped to [-limit, limit] and the clamped value is both stored as that section's output state and fed to the next section. Return exact fraction strings.

split: open-access


prompt:
After a clip the recursive part continues from a value beyond the limit.

Input [gain, sections, limit, samples]; each section [b0, b1, b2, a1, a2] is a direct-form-I biquad (a0 = 1) with its own state. The input is scaled by gain, each section output is clamped to [-limit, limit] and the clamped value is both stored as that section's output state and fed to the next section. Return exact fraction strings.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
    h = list(x)
    lead = 0
    while lead < len(h) and h[lead] == 0:
        lead += 1
    if lead == len(h):
        return 'degenerate'
    end = len(h)
    while h[end - 1] == 0:
        end -= 1
    g = h[lead:end]
    N = len(g)
    sym = all(g[i] == g[N - 1 - i] for i in range(N))
    anti = all(g[i] == -g[N - 1 - i] for i in range(N // 2))
    if sym:
        typ = 1 if N % 2 else 2
    elif anti:
        typ = 3 if N % 2 else 4
    else:
        return {'type': None, 'group_delay': None}
    return {'type': typ, 'group_delay': str(lead + Fraction(N - 1, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['regression: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}], ['repair check: type IV', [1, -1], {'type': 4, 'group_delay': '1/2'}], ['control: type III zero centre', [1, 0, -1], {'type': 3, 'group_delay': '1'}], ['control: type I', [1, 2, 1], {'type': 1, 'group_delay': '1'}], ['control: type II', [1, 1], {'type': 2, 'group_delay': '1/2'}], ['control: leading zeros symmetric', [0, 0, 1, 2, 1], {'type': 1, 'group_delay': '3'}]], [['regression: random linear phase 6', [0, 3, 2, -3], {'type': None, 'group_delay': None}], ['regression: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['repair check: random linear phase 1', [0, 2, -2, 0, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['control: trailing zeros', [1, 2, 1, 0], {'type': 1, 'group_delay': '1'}], ['control: interior zero symmetric', [1, 0, 1], {'type': 1, 'group_delay': '1'}], ['control: all zero', [0, 0, 0], 'degenerate'], ['control: not linear phase', [1, 2, 3], {'type': None, 'group_delay': None}]], [['regression: random linear phase 4', [0, 1, -1, -1, 0], {'type': None, 'group_delay': None}], ['regression: random linear phase 6', [0, 3, 2, -3], {'type': None, 'group_delay': None}], ['repair check: random linear phase 10', [0, 0, 0, -1, 1, 0], {'type': 4, 'group_delay': '7/2'}], ['control: padded type II', [0, 3, 3, 0, 0], {'type': 2, 'group_delay': '3/2'}], ['control: single tap', [5], {'type': 1, 'group_delay': '0'}], ['control: padded interior zeros', [0, 2, 0, 0, 2], {'type': 2, 'group_delay': '5/2'}], ['control: random linear phase 0', [-1, -2, -1, 0, 1, 2, 1, 0], {'type': 3, 'group_delay': '3'}]], [['regression: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}], ['regression: random linear phase 4', [0, 1, -1, -1, 0], {'type': None, 'group_delay': None}], ['repair check: random linear phase 12', [-1, 1, -1, 1, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['control: random linear phase 3', [1, 0, 1, 0], {'type': 1, 'group_delay': '1'}], ['control: random linear phase 5', [0, 0, -3, -3, -2, -3, -3, 0], {'type': 1, 'group_delay': '4'}], ['control: random linear phase 7', [0, 0, 0, 0, 0], 'degenerate'], ['control: random linear phase 9', [0, 0, -1, -3, 3, -1, 3, -3, -1, 0, 0], {'type': 1, 'group_delay': '5'}]], [['regression: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['regression: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}], ['repair check: random linear phase 16', [0, -3, -1, 1, 3, 0, 0], {'type': 4, 'group_delay': '5/2'}], ['control: random linear phase 13', [-3, -3, 0, 0], {'type': 2, 'group_delay': '1/2'}], ['control: random linear phase 15', [0, 0, 1, -1, -1, 1, 0, 0], {'type': 2, 'group_delay': '7/2'}], ['control: random linear phase 17', [0, -3, 1, 3, -1, 3, 1, -3], {'type': 1, 'group_delay': '4'}], ['control: random linear phase 18', [0, 0, 3, 3, 0, 0], {'type': 2, 'group_delay': '5/2'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
    h = list(x)
    lead = 0
    while lead < len(h) and h[lead] == 0:
        lead += 1
    if lead == len(h):
        return 'degenerate'
    end = len(h)
    while h[end - 1] == 0:
        end -= 1
    g = h[lead:end]
    N = len(g)
    sym = all(g[i] == g[N - 1 - i] for i in range(N))
    anti = all(g[i] == -g[N - 1 - i] for i in range(N // 2)) and g[N // 2] == 0
    if sym:
        typ = 1 if N % 2 else 2
    elif anti:
        typ = 3 if N % 2 else 4
    else:
        return {'type': None, 'group_delay': None}
    return {'type': typ, 'group_delay': str(lead + Fraction(N - 1, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['regression: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}], ['repair check: type IV', [1, -1], {'type': 4, 'group_delay': '1/2'}], ['control: type III zero centre', [1, 0, -1], {'type': 3, 'group_delay': '1'}], ['control: type I', [1, 2, 1], {'type': 1, 'group_delay': '1'}], ['control: type II', [1, 1], {'type': 2, 'group_delay': '1/2'}], ['control: leading zeros symmetric', [0, 0, 1, 2, 1], {'type': 1, 'group_delay': '3'}]], [['regression: random linear phase 6', [0, 3, 2, -3], {'type': None, 'group_delay': None}], ['regression: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['repair check: random linear phase 1', [0, 2, -2, 0, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['control: trailing zeros', [1, 2, 1, 0], {'type': 1, 'group_delay': '1'}], ['control: interior zero symmetric', [1, 0, 1], {'type': 1, 'group_delay': '1'}], ['control: all zero', [0, 0, 0], 'degenerate'], ['control: not linear phase', [1, 2, 3], {'type': None, 'group_delay': None}]], [['regression: random linear phase 4', [0, 1, -1, -1, 0], {'type': None, 'group_delay': None}], ['regression: random linear phase 6', [0, 3, 2, -3], {'type': None, 'group_delay': None}], ['repair check: random linear phase 10', [0, 0, 0, -1, 1, 0], {'type': 4, 'group_delay': '7/2'}], ['control: padded type II', [0, 3, 3, 0, 0], {'type': 2, 'group_delay': '3/2'}], ['control: single tap', [5], {'type': 1, 'group_delay': '0'}], ['control: padded interior zeros', [0, 2, 0, 0, 2], {'type': 2, 'group_delay': '5/2'}], ['control: random linear phase 0', [-1, -2, -1, 0, 1, 2, 1, 0], {'type': 3, 'group_delay': '3'}]], [['regression: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}], ['regression: random linear phase 4', [0, 1, -1, -1, 0], {'type': None, 'group_delay': None}], ['repair check: random linear phase 12', [-1, 1, -1, 1, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['control: random linear phase 3', [1, 0, 1, 0], {'type': 1, 'group_delay': '1'}], ['control: random linear phase 5', [0, 0, -3, -3, -2, -3, -3, 0], {'type': 1, 'group_delay': '4'}], ['control: random linear phase 7', [0, 0, 0, 0, 0], 'degenerate'], ['control: random linear phase 9', [0, 0, -1, -3, 3, -1, 3, -3, -1, 0, 0], {'type': 1, 'group_delay': '5'}]], [['regression: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['regression: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}], ['repair check: random linear phase 16', [0, -3, -1, 1, 3, 0, 0], {'type': 4, 'group_delay': '5/2'}], ['control: random linear phase 13', [-3, -3, 0, 0], {'type': 2, 'group_delay': '1/2'}], ['control: random linear phase 15', [0, 0, 1, -1, -1, 1, 0, 0], {'type': 2, 'group_delay': '7/2'}], ['control: random linear phase 17', [0, -3, 1, 3, -1, 3, 1, -3], {'type': 1, 'group_delay': '4'}], ['control: random linear phase 18', [0, 0, 3, 3, 0, 0], {'type': 2, 'group_delay': '5/2'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

prompt:
[1, 2, -1] is classified as type 3 although a nonzero centre breaks antisymmetry.

Input integer taps. Strip leading and trailing zeros ("degenerate" if all zero). The trimmed support of length N is type 1/2 if symmetric (odd/even N), type 3/4 if antisymmetric (odd/even N), otherwise not linear phase. Return {"type", "group_delay": leading zeros + (N-1)/2 as a fraction string} or both None.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
    h = list(x)
    lead = 0
    while lead < len(h) and h[lead] == 0:
        lead += 1
    if lead == len(h):
        return 'degenerate'
    end = len(h)
    while h[end - 1] == 0:
        end -= 1
    g = h[lead:end]
    N = len(g)
    sym = all(g[i] == g[N - 1 - i] for i in range(N))
    anti = all(g[i] == -g[N - 1 - i] for i in range(N))
    if sym:
        typ = 1 if N % 2 else 2
    elif anti:
        typ = 3 if N % 2 else 4
    else:
        return {'type': None, 'group_delay': None}
    return {'type': typ, 'group_delay': str(Fraction(N - 1, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: leading zeros symmetric', [0, 0, 1, 2, 1], {'type': 1, 'group_delay': '3'}], ['regression: padded type II', [0, 3, 3, 0, 0], {'type': 2, 'group_delay': '3/2'}], ['repair check: trailing zeros', [1, 2, 1, 0], {'type': 1, 'group_delay': '1'}], ['control: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['control: type III zero centre', [1, 0, -1], {'type': 3, 'group_delay': '1'}], ['control: type I', [1, 2, 1], {'type': 1, 'group_delay': '1'}], ['control: type II', [1, 1], {'type': 2, 'group_delay': '1/2'}]], [['regression: random linear phase 1', [0, 2, -2, 0, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['regression: random linear phase 5', [0, 0, -3, -3, -2, -3, -3, 0], {'type': 1, 'group_delay': '4'}], ['regression: padded type II', [0, 3, 3, 0, 0], {'type': 2, 'group_delay': '3/2'}], ['control: type IV', [1, -1], {'type': 4, 'group_delay': '1/2'}], ['control: interior zero symmetric', [1, 0, 1], {'type': 1, 'group_delay': '1'}], ['control: all zero', [0, 0, 0], 'degenerate'], ['control: not linear phase', [1, 2, 3], {'type': None, 'group_delay': None}]], [['regression: random linear phase 10', [0, 0, 0, -1, 1, 0], {'type': 4, 'group_delay': '7/2'}], ['regression: random linear phase 11', [0, 0, 2, -2, 0], {'type': 4, 'group_delay': '5/2'}], ['repair check: random linear phase 0', [-1, -2, -1, 0, 1, 2, 1, 0], {'type': 3, 'group_delay': '3'}], ['control: type IV longer', [2, 1, -1, -2], {'type': 4, 'group_delay': '3/2'}], ['control: single tap', [5], {'type': 1, 'group_delay': '0'}], ['control: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}], ['control: random linear phase 4', [0, 1, -1, -1, 0], {'type': None, 'group_delay': None}]], [['regression: random linear phase 15', [0, 0, 1, -1, -1, 1, 0, 0], {'type': 2, 'group_delay': '7/2'}], ['regression: random linear phase 16', [0, -3, -1, 1, 3, 0, 0], {'type': 4, 'group_delay': '5/2'}], ['repair check: random linear phase 3', [1, 0, 1, 0], {'type': 1, 'group_delay': '1'}], ['control: random linear phase 6', [0, 3, 2, -3], {'type': None, 'group_delay': None}], ['control: random linear phase 7', [0, 0, 0, 0, 0], 'degenerate'], ['control: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['control: type III zero centre', [1, 0, -1], {'type': 3, 'group_delay': '1'}]], [['regression: random linear phase 18', [0, 0, 3, 3, 0, 0], {'type': 2, 'group_delay': '5/2'}], ['regression: random linear phase 20', [0, 2, -2, 2, 0, 0], {'type': 1, 'group_delay': '2'}], ['repair check: random linear phase 8', [2, -2, -2, 2, 2, -2, 0, 0], {'type': 4, 'group_delay': '5/2'}], ['control: type I', [1, 2, 1], {'type': 1, 'group_delay': '1'}], ['control: type II', [1, 1], {'type': 2, 'group_delay': '1/2'}], ['control: type IV', [1, -1], {'type': 4, 'group_delay': '1/2'}], ['control: interior zero symmetric', [1, 0, 1], {'type': 1, 'group_delay': '1'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
    h = list(x)
    lead = 0
    while lead < len(h) and h[lead] == 0:
        lead += 1
    if lead == len(h):
        return 'degenerate'
    end = len(h)
    while h[end - 1] == 0:
        end -= 1
    g = h[lead:end]
    N = len(g)
    sym = all(g[i] == g[N - 1 - i] for i in range(N))
    anti = all(g[i] == -g[N - 1 - i] for i in range(N))
    if sym:
        typ = 1 if N % 2 else 2
    elif anti:
        typ = 3 if N % 2 else 4
    else:
        return {'type': None, 'group_delay': None}
    return {'type': typ, 'group_delay': str(len(h) - end + Fraction(N - 1, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: leading zeros symmetric', [0, 0, 1, 2, 1], {'type': 1, 'group_delay': '3'}], ['regression: padded type II', [0, 3, 3, 0, 0], {'type': 2, 'group_delay': '3/2'}], ['repair check: trailing zeros', [1, 2, 1, 0], {'type': 1, 'group_delay': '1'}], ['control: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['control: type III zero centre', [1, 0, -1], {'type': 3, 'group_delay': '1'}], ['control: type I', [1, 2, 1], {'type': 1, 'group_delay': '1'}], ['control: type II', [1, 1], {'type': 2, 'group_delay': '1/2'}]], [['regression: random linear phase 1', [0, 2, -2, 0, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['regression: random linear phase 5', [0, 0, -3, -3, -2, -3, -3, 0], {'type': 1, 'group_delay': '4'}], ['regression: padded type II', [0, 3, 3, 0, 0], {'type': 2, 'group_delay': '3/2'}], ['control: type IV', [1, -1], {'type': 4, 'group_delay': '1/2'}], ['control: interior zero symmetric', [1, 0, 1], {'type': 1, 'group_delay': '1'}], ['control: all zero', [0, 0, 0], 'degenerate'], ['control: not linear phase', [1, 2, 3], {'type': None, 'group_delay': None}]], [['regression: random linear phase 10', [0, 0, 0, -1, 1, 0], {'type': 4, 'group_delay': '7/2'}], ['regression: random linear phase 11', [0, 0, 2, -2, 0], {'type': 4, 'group_delay': '5/2'}], ['repair check: random linear phase 0', [-1, -2, -1, 0, 1, 2, 1, 0], {'type': 3, 'group_delay': '3'}], ['control: type IV longer', [2, 1, -1, -2], {'type': 4, 'group_delay': '3/2'}], ['control: single tap', [5], {'type': 1, 'group_delay': '0'}], ['control: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}], ['control: random linear phase 4', [0, 1, -1, -1, 0], {'type': None, 'group_delay': None}]], [['regression: random linear phase 15', [0, 0, 1, -1, -1, 1, 0, 0], {'type': 2, 'group_delay': '7/2'}], ['regression: random linear phase 16', [0, -3, -1, 1, 3, 0, 0], {'type': 4, 'group_delay': '5/2'}], ['repair check: random linear phase 3', [1, 0, 1, 0], {'type': 1, 'group_delay': '1'}], ['control: random linear phase 6', [0, 3, 2, -3], {'type': None, 'group_delay': None}], ['control: random linear phase 7', [0, 0, 0, 0, 0], 'degenerate'], ['control: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['control: type III zero centre', [1, 0, -1], {'type': 3, 'group_delay': '1'}]], [['regression: random linear phase 18', [0, 0, 3, 3, 0, 0], {'type': 2, 'group_delay': '5/2'}], ['regression: random linear phase 20', [0, 2, -2, 2, 0, 0], {'type': 1, 'group_delay': '2'}], ['repair check: random linear phase 8', [2, -2, -2, 2, 2, -2, 0, 0], {'type': 4, 'group_delay': '5/2'}], ['control: type I', [1, 2, 1], {'type': 1, 'group_delay': '1'}], ['control: type II', [1, 1], {'type': 2, 'group_delay': '1/2'}], ['control: type IV', [1, -1], {'type': 4, 'group_delay': '1/2'}], ['control: interior zero symmetric', [1, 0, 1], {'type': 1, 'group_delay': '1'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

prompt:
[0, 0, 1, 2, 1] reports a delay of 1 sample instead of 3.

Input integer taps. Strip leading and trailing zeros ("degenerate" if all zero). The trimmed support of length N is type 1/2 if symmetric (odd/even N), type 3/4 if antisymmetric (odd/even N), otherwise not linear phase. Return {"type", "group_delay": leading zeros + (N-1)/2 as a fraction string} or both None.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
    h = list(x)
    lead = 0
    while lead < len(h) and h[lead] == 0:
        lead += 1
    if lead == len(h):
        return 'degenerate'
    end = len(h)
    while h[end - 1] == 0:
        end -= 1
    g = h[lead:end]
    N = len(g)
    sym = all(g[i] == g[N - 1 - i] for i in range(N))
    anti = all(g[i] == -g[N - 1 - i] for i in range(N))
    if sym:
        typ = 2 if N % 2 else 1
    elif anti:
        typ = 3 if N % 2 else 4
    else:
        return {'type': None, 'group_delay': None}
    return {'type': typ, 'group_delay': str(lead + Fraction(N - 1, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: type I', [1, 2, 1], {'type': 1, 'group_delay': '1'}], ['regression: type II', [1, 1], {'type': 2, 'group_delay': '1/2'}], ['repair check: type III zero centre', [1, 0, -1], {'type': 3, 'group_delay': '1'}], ['control: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['control: all zero', [0, 0, 0], 'degenerate'], ['control: not linear phase', [1, 2, 3], {'type': None, 'group_delay': None}], ['control: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}]], [['regression: trailing zeros', [1, 2, 1, 0], {'type': 1, 'group_delay': '1'}], ['regression: interior zero symmetric', [1, 0, 1], {'type': 1, 'group_delay': '1'}], ['repair check: type IV longer', [2, 1, -1, -2], {'type': 4, 'group_delay': '3/2'}], ['control: random linear phase 4', [0, 1, -1, -1, 0], {'type': None, 'group_delay': None}], ['control: random linear phase 6', [0, 3, 2, -3], {'type': None, 'group_delay': None}], ['control: random linear phase 7', [0, 0, 0, 0, 0], 'degenerate'], ['control: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}]], [['regression: single tap', [5], {'type': 1, 'group_delay': '0'}], ['regression: padded interior zeros', [0, 2, 0, 0, 2], {'type': 2, 'group_delay': '5/2'}], ['repair check: random linear phase 1', [0, 2, -2, 0, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['control: all zero', [0, 0, 0], 'degenerate'], ['control: not linear phase', [1, 2, 3], {'type': None, 'group_delay': None}], ['control: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}], ['control: random linear phase 4', [0, 1, -1, -1, 0], {'type': None, 'group_delay': None}]], [['regression: random linear phase 5', [0, 0, -3, -3, -2, -3, -3, 0], {'type': 1, 'group_delay': '4'}], ['regression: random linear phase 9', [0, 0, -1, -3, 3, -1, 3, -3, -1, 0, 0], {'type': 1, 'group_delay': '5'}], ['repair check: random linear phase 10', [0, 0, 0, -1, 1, 0], {'type': 4, 'group_delay': '7/2'}], ['control: random linear phase 6', [0, 3, 2, -3], {'type': None, 'group_delay': None}], ['control: random linear phase 7', [0, 0, 0, 0, 0], 'degenerate'], ['control: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['control: all zero', [0, 0, 0], 'degenerate']], [['regression: random linear phase 15', [0, 0, 1, -1, -1, 1, 0, 0], {'type': 2, 'group_delay': '7/2'}], ['regression: random linear phase 17', [0, -3, 1, 3, -1, 3, 1, -3], {'type': 1, 'group_delay': '4'}], ['repair check: random linear phase 12', [-1, 1, -1, 1, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['control: not linear phase', [1, 2, 3], {'type': None, 'group_delay': None}], ['control: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}], ['control: random linear phase 4', [0, 1, -1, -1, 0], {'type': None, 'group_delay': None}], ['control: random linear phase 6', [0, 3, 2, -3], {'type': None, 'group_delay': None}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
    h = list(x)
    lead = 0
    while lead < len(h) and h[lead] == 0:
        lead += 1
    if lead == len(h):
        return 'degenerate'
    end = len(h)
    while h[end - 1] == 0:
        end -= 1
    g = h[lead:end]
    N = len(g)
    sym = all(g[i] == g[N - 1 - i] for i in range(N))
    anti = all(g[i] == -g[N - 1 - i] for i in range(N))
    if sym:
        typ = 1 if N % 2 else 2
    elif anti:
        typ = 4 if N % 2 else 3
    else:
        return {'type': None, 'group_delay': None}
    return {'type': typ, 'group_delay': str(lead + Fraction(N - 1, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: type I', [1, 2, 1], {'type': 1, 'group_delay': '1'}], ['regression: type II', [1, 1], {'type': 2, 'group_delay': '1/2'}], ['repair check: type III zero centre', [1, 0, -1], {'type': 3, 'group_delay': '1'}], ['control: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['control: all zero', [0, 0, 0], 'degenerate'], ['control: not linear phase', [1, 2, 3], {'type': None, 'group_delay': None}], ['control: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}]], [['regression: trailing zeros', [1, 2, 1, 0], {'type': 1, 'group_delay': '1'}], ['regression: interior zero symmetric', [1, 0, 1], {'type': 1, 'group_delay': '1'}], ['repair check: type IV longer', [2, 1, -1, -2], {'type': 4, 'group_delay': '3/2'}], ['control: random linear phase 4', [0, 1, -1, -1, 0], {'type': None, 'group_delay': None}], ['control: random linear phase 6', [0, 3, 2, -3], {'type': None, 'group_delay': None}], ['control: random linear phase 7', [0, 0, 0, 0, 0], 'degenerate'], ['control: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}]], [['regression: single tap', [5], {'type': 1, 'group_delay': '0'}], ['regression: padded interior zeros', [0, 2, 0, 0, 2], {'type': 2, 'group_delay': '5/2'}], ['repair check: random linear phase 1', [0, 2, -2, 0, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['control: all zero', [0, 0, 0], 'degenerate'], ['control: not linear phase', [1, 2, 3], {'type': None, 'group_delay': None}], ['control: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}], ['control: random linear phase 4', [0, 1, -1, -1, 0], {'type': None, 'group_delay': None}]], [['regression: random linear phase 5', [0, 0, -3, -3, -2, -3, -3, 0], {'type': 1, 'group_delay': '4'}], ['regression: random linear phase 9', [0, 0, -1, -3, 3, -1, 3, -3, -1, 0, 0], {'type': 1, 'group_delay': '5'}], ['repair check: random linear phase 10', [0, 0, 0, -1, 1, 0], {'type': 4, 'group_delay': '7/2'}], ['control: random linear phase 6', [0, 3, 2, -3], {'type': None, 'group_delay': None}], ['control: random linear phase 7', [0, 0, 0, 0, 0], 'degenerate'], ['control: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['control: all zero', [0, 0, 0], 'degenerate']], [['regression: random linear phase 15', [0, 0, 1, -1, -1, 1, 0, 0], {'type': 2, 'group_delay': '7/2'}], ['regression: random linear phase 17', [0, -3, 1, 3, -1, 3, 1, -3], {'type': 1, 'group_delay': '4'}], ['repair check: random linear phase 12', [-1, 1, -1, 1, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['control: not linear phase', [1, 2, 3], {'type': None, 'group_delay': None}], ['control: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}], ['control: random linear phase 4', [0, 1, -1, -1, 0], {'type': None, 'group_delay': None}], ['control: random linear phase 6', [0, 3, 2, -3], {'type': None, 'group_delay': None}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

prompt:
An odd-length symmetric filter is labelled type 2.

Input integer taps. Strip leading and trailing zeros ("degenerate" if all zero). The trimmed support of length N is type 1/2 if symmetric (odd/even N), type 3/4 if antisymmetric (odd/even N), otherwise not linear phase. Return {"type", "group_delay": leading zeros + (N-1)/2 as a fraction string} or both None.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
    h = list(x)
    lead = 0
    if all(v == 0 for v in h):
        return 'degenerate'
    end = len(h)
    while h[end - 1] == 0:
        end -= 1
    g = h[lead:end]
    N = len(g)
    sym = all(g[i] == g[N - 1 - i] for i in range(N))
    anti = all(g[i] == -g[N - 1 - i] for i in range(N))
    if sym:
        typ = 1 if N % 2 else 2
    elif anti:
        typ = 3 if N % 2 else 4
    else:
        return {'type': None, 'group_delay': None}
    return {'type': typ, 'group_delay': str(lead + Fraction(N - 1, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: leading zeros symmetric', [0, 0, 1, 2, 1], {'type': 1, 'group_delay': '3'}], ['regression: padded type II', [0, 3, 3, 0, 0], {'type': 2, 'group_delay': '3/2'}], ['repair check: type III zero centre', [1, 0, -1], {'type': 3, 'group_delay': '1'}], ['control: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['control: type I', [1, 2, 1], {'type': 1, 'group_delay': '1'}], ['control: type II', [1, 1], {'type': 2, 'group_delay': '1/2'}], ['control: type IV', [1, -1], {'type': 4, 'group_delay': '1/2'}]], [['regression: random linear phase 1', [0, 2, -2, 0, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['regression: random linear phase 5', [0, 0, -3, -3, -2, -3, -3, 0], {'type': 1, 'group_delay': '4'}], ['repair check: interior zero symmetric', [1, 0, 1], {'type': 1, 'group_delay': '1'}], ['control: trailing zeros', [1, 2, 1, 0], {'type': 1, 'group_delay': '1'}], ['control: all zero', [0, 0, 0], 'degenerate'], ['control: not linear phase', [1, 2, 3], {'type': None, 'group_delay': None}], ['control: type IV longer', [2, 1, -1, -2], {'type': 4, 'group_delay': '3/2'}]], [['regression: random linear phase 10', [0, 0, 0, -1, 1, 0], {'type': 4, 'group_delay': '7/2'}], ['regression: random linear phase 11', [0, 0, 2, -2, 0], {'type': 4, 'group_delay': '5/2'}], ['regression: padded interior zeros', [0, 2, 0, 0, 2], {'type': 2, 'group_delay': '5/2'}], ['control: single tap', [5], {'type': 1, 'group_delay': '0'}], ['control: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}], ['control: random linear phase 4', [0, 1, -1, -1, 0], {'type': None, 'group_delay': None}], ['control: random linear phase 6', [0, 3, 2, -3], {'type': None, 'group_delay': None}]], [['regression: random linear phase 15', [0, 0, 1, -1, -1, 1, 0, 0], {'type': 2, 'group_delay': '7/2'}], ['regression: random linear phase 16', [0, -3, -1, 1, 3, 0, 0], {'type': 4, 'group_delay': '5/2'}], ['regression: random linear phase 1', [0, 2, -2, 0, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['control: random linear phase 7', [0, 0, 0, 0, 0], 'degenerate'], ['control: random linear phase 8', [2, -2, -2, 2, 2, -2, 0, 0], {'type': 4, 'group_delay': '5/2'}], ['control: random linear phase 12', [-1, 1, -1, 1, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['control: random linear phase 13', [-3, -3, 0, 0], {'type': 2, 'group_delay': '1/2'}]], [['regression: random linear phase 18', [0, 0, 3, 3, 0, 0], {'type': 2, 'group_delay': '5/2'}], ['regression: random linear phase 20', [0, 2, -2, 2, 0, 0], {'type': 1, 'group_delay': '2'}], ['regression: random linear phase 5', [0, 0, -3, -3, -2, -3, -3, 0], {'type': 1, 'group_delay': '4'}], ['control: random linear phase 19', [3, -1, 3, -3, 1, -3, 0, 0], {'type': 4, 'group_delay': '5/2'}], ['control: random linear phase 21', [1, -2, 1, 1, -2, 1, 0], {'type': 2, 'group_delay': '5/2'}], ['control: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['control: type I', [1, 2, 1], {'type': 1, 'group_delay': '1'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
    h = list(x)
    lead = 0
    if all(v == 0 for v in h):
        return 'degenerate'
    g = [v for v in h if v != 0]
    N = len(g)
    sym = all(g[i] == g[N - 1 - i] for i in range(N))
    anti = all(g[i] == -g[N - 1 - i] for i in range(N))
    if sym:
        typ = 1 if N % 2 else 2
    elif anti:
        typ = 3 if N % 2 else 4
    else:
        return {'type': None, 'group_delay': None}
    return {'type': typ, 'group_delay': str(lead + Fraction(N - 1, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: leading zeros symmetric', [0, 0, 1, 2, 1], {'type': 1, 'group_delay': '3'}], ['regression: padded type II', [0, 3, 3, 0, 0], {'type': 2, 'group_delay': '3/2'}], ['repair check: type III zero centre', [1, 0, -1], {'type': 3, 'group_delay': '1'}], ['control: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['control: type I', [1, 2, 1], {'type': 1, 'group_delay': '1'}], ['control: type II', [1, 1], {'type': 2, 'group_delay': '1/2'}], ['control: type IV', [1, -1], {'type': 4, 'group_delay': '1/2'}]], [['regression: random linear phase 1', [0, 2, -2, 0, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['regression: random linear phase 5', [0, 0, -3, -3, -2, -3, -3, 0], {'type': 1, 'group_delay': '4'}], ['repair check: interior zero symmetric', [1, 0, 1], {'type': 1, 'group_delay': '1'}], ['control: trailing zeros', [1, 2, 1, 0], {'type': 1, 'group_delay': '1'}], ['control: all zero', [0, 0, 0], 'degenerate'], ['control: not linear phase', [1, 2, 3], {'type': None, 'group_delay': None}], ['control: type IV longer', [2, 1, -1, -2], {'type': 4, 'group_delay': '3/2'}]], [['regression: random linear phase 10', [0, 0, 0, -1, 1, 0], {'type': 4, 'group_delay': '7/2'}], ['regression: random linear phase 11', [0, 0, 2, -2, 0], {'type': 4, 'group_delay': '5/2'}], ['regression: padded interior zeros', [0, 2, 0, 0, 2], {'type': 2, 'group_delay': '5/2'}], ['control: single tap', [5], {'type': 1, 'group_delay': '0'}], ['control: random linear phase 2', [0, 0, 2, 0, 2, 0, -2, 0, 0], {'type': None, 'group_delay': None}], ['control: random linear phase 4', [0, 1, -1, -1, 0], {'type': None, 'group_delay': None}], ['control: random linear phase 6', [0, 3, 2, -3], {'type': None, 'group_delay': None}]], [['regression: random linear phase 15', [0, 0, 1, -1, -1, 1, 0, 0], {'type': 2, 'group_delay': '7/2'}], ['regression: random linear phase 16', [0, -3, -1, 1, 3, 0, 0], {'type': 4, 'group_delay': '5/2'}], ['regression: random linear phase 1', [0, 2, -2, 0, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['control: random linear phase 7', [0, 0, 0, 0, 0], 'degenerate'], ['control: random linear phase 8', [2, -2, -2, 2, 2, -2, 0, 0], {'type': 4, 'group_delay': '5/2'}], ['control: random linear phase 12', [-1, 1, -1, 1, 0, 0], {'type': 4, 'group_delay': '3/2'}], ['control: random linear phase 13', [-3, -3, 0, 0], {'type': 2, 'group_delay': '1/2'}]], [['regression: random linear phase 18', [0, 0, 3, 3, 0, 0], {'type': 2, 'group_delay': '5/2'}], ['regression: random linear phase 20', [0, 2, -2, 2, 0, 0], {'type': 1, 'group_delay': '2'}], ['regression: random linear phase 5', [0, 0, -3, -3, -2, -3, -3, 0], {'type': 1, 'group_delay': '4'}], ['control: random linear phase 19', [3, -1, 3, -3, 1, -3, 0, 0], {'type': 4, 'group_delay': '5/2'}], ['control: random linear phase 21', [1, -2, 1, 1, -2, 1, 0], {'type': 2, 'group_delay': '5/2'}], ['control: type III nonzero centre', [1, 2, -1], {'type': None, 'group_delay': None}], ['control: type I', [1, 2, 1], {'type': 1, 'group_delay': '1'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

prompt:
[0, 3, 3, 0, 0] is reported as not linear phase.

Input integer taps. Strip leading and trailing zeros ("degenerate" if all zero). The trimmed support of length N is type 1/2 if symmetric (odd/even N), type 3/4 if antisymmetric (odd/even N), otherwise not linear phase. Return {"type", "group_delay": leading zeros + (N-1)/2 as a fraction string} or both None.

split: open-access


prompt:
A ramp input gets a kink at the edges and the filtered ends droop.

Input [taps, samples] (integers). Zero-phase filtering: pad = min(3 (len(taps) - 1), len - 1); extend with odd reflection about each end (2 x[0] - x[i] for i = pad..1 before, 2 x[-1] - x[n-1-i] for i = 1..pad after); filter forward with zero initial state, reverse, filter again, reverse, and return the middle len samples.

split: open-access


prompt:
The result has twice the group delay instead of zero phase.

Input [taps, samples] (integers). Zero-phase filtering: pad = min(3 (len(taps) - 1), len - 1); extend with odd reflection about each end (2 x[0] - x[i] for i = pad..1 before, 2 x[-1] - x[n-1-i] for i = 1..pad after); filter forward with zero initial state, reverse, filter again, reverse, and return the middle len samples.

split: open-access


prompt:
The output starts with padded samples and is shifted by pad samples.

Input [taps, samples] (integers). Zero-phase filtering: pad = min(3 (len(taps) - 1), len - 1); extend with odd reflection about each end (2 x[0] - x[i] for i = pad..1 before, 2 x[-1] - x[n-1-i] for i = 1..pad after); filter forward with zero initial state, reverse, filter again, reverse, and return the middle len samples.

split: open-access


prompt:
The padded extension repeats the edge value, creating a flat spot that biases the ends.

Input [taps, samples] (integers). Zero-phase filtering: pad = min(3 (len(taps) - 1), len - 1); extend with odd reflection about each end (2 x[0] - x[i] for i = pad..1 before, 2 x[-1] - x[n-1-i] for i = 1..pad after); filter forward with zero initial state, reverse, filter again, reverse, and return the middle len samples.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    fin, fout, roll = x[0], x[1], Fraction(x[2])
    if fin <= 0 or fout <= 0 or not 0 < roll <= 1:
        return 'bad-spec'
    g = math.gcd(fin, fout)
    L, M = fin // g, fout // g
    inter = fin * L
    cutoff = Fraction(min(fin, fout), 2) * roll
    return {'up': L, 'down': M, 'intermediate_rate': inter, 'cutoff_hz': str(cutoff), 'cutoff_norm': str(cutoff / Fraction(inter, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}]], [['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}]], [['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['repair check: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}]], [['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}]], [['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['repair check: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    fin, fout, roll = x[0], x[1], Fraction(x[2])
    if fin <= 0 or fout <= 0 or not 0 < roll <= 1:
        return 'bad-spec'
    g = math.gcd(fin, fout)
    L, M = fout // g, fin
    inter = fin * L
    cutoff = Fraction(min(fin, fout), 2) * roll
    return {'up': L, 'down': M, 'intermediate_rate': inter, 'cutoff_hz': str(cutoff), 'cutoff_norm': str(cutoff / Fraction(inter, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}]], [['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}]], [['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['repair check: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}]], [['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}]], [['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['repair check: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

prompt:
48 kHz to 44.1 kHz is planned as up 160, down 147 instead of up 147, down 160.

Input [fin, fout, rolloff] (positive integer rates, rolloff in (0, 1]). Reduce fout/fin to up/down = L/M by gcd, intermediate rate = fin L, anti-alias cutoff = min(fin, fout)/2 * rolloff in Hz and normalized to the intermediate Nyquist. Return {"up", "down", "intermediate_rate", "cutoff_hz", "cutoff_norm"} or "bad-spec".

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    fin, fout, roll = x[0], x[1], Fraction(x[2])
    if fin <= 0 or fout <= 0 or not 0 < roll <= 1:
        return 'bad-spec'
    g = math.gcd(fin, fout)
    L, M = fout // g, fin // g
    inter = fin * L
    cutoff = Fraction(max(fin, fout), 2) * roll
    return {'up': L, 'down': M, 'intermediate_rate': inter, 'cutoff_hz': str(cutoff), 'cutoff_norm': str(cutoff / Fraction(inter, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}]], [['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}]], [['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}]], [['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}]], [['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    fin, fout, roll = x[0], x[1], Fraction(x[2])
    if fin <= 0 or fout <= 0 or not 0 < roll <= 1:
        return 'bad-spec'
    g = math.gcd(fin, fout)
    L, M = fout // g, fin // g
    inter = fin * L
    cutoff = Fraction(fout, 2) * roll
    return {'up': L, 'down': M, 'intermediate_rate': inter, 'cutoff_hz': str(cutoff), 'cutoff_norm': str(cutoff / Fraction(inter, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}]], [['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}]], [['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}]], [['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}]], [['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

prompt:
Downsampling 48 kHz to 16 kHz keeps content up to 24 kHz, which aliases.

Input [fin, fout, rolloff] (positive integer rates, rolloff in (0, 1]). Reduce fout/fin to up/down = L/M by gcd, intermediate rate = fin L, anti-alias cutoff = min(fin, fout)/2 * rolloff in Hz and normalized to the intermediate Nyquist. Return {"up", "down", "intermediate_rate", "cutoff_hz", "cutoff_norm"} or "bad-spec".

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    fin, fout, roll = x[0], x[1], Fraction(x[2])
    if fin <= 0 or fout <= 0 or not 0 < roll <= 1:
        return 'bad-spec'
    g = math.gcd(fin, fout)
    L, M = fout // g, fin // g
    inter = fin * L
    cutoff = Fraction(min(fin, fout), 2) * roll
    return {'up': L, 'down': M, 'intermediate_rate': inter, 'cutoff_hz': str(cutoff), 'cutoff_norm': str(cutoff / Fraction(fin, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['repair check: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}]], [['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['repair check: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}]], [['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['repair check: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}]], [['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['repair check: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['repair check: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}]], [['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['repair check: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['repair check: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    fin, fout, roll = x[0], x[1], Fraction(x[2])
    if fin <= 0 or fout <= 0 or not 0 < roll <= 1:
        return 'bad-spec'
    g = math.gcd(fin, fout)
    L, M = fout // g, fin // g
    inter = fin * L
    cutoff = Fraction(min(fin, fout), 2) * roll
    return {'up': L, 'down': M, 'intermediate_rate': inter, 'cutoff_hz': str(cutoff), 'cutoff_norm': str(cutoff / inter)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['repair check: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}]], [['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['repair check: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}]], [['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['repair check: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}]], [['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['repair check: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['repair check: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}]], [['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['repair check: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['repair check: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

prompt:
The normalized cutoff handed to the filter designer is L times too large.

Input [fin, fout, rolloff] (positive integer rates, rolloff in (0, 1]). Reduce fout/fin to up/down = L/M by gcd, intermediate rate = fin L, anti-alias cutoff = min(fin, fout)/2 * rolloff in Hz and normalized to the intermediate Nyquist. Return {"up", "down", "intermediate_rate", "cutoff_hz", "cutoff_norm"} or "bad-spec".

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    fin, fout, roll = x[0], x[1], Fraction(x[2])
    if fin <= 0 or fout <= 0 or not 0 < roll <= 1:
        return 'bad-spec'
    g = math.gcd(fin, fout)
    L, M = fout // g, fin // g
    inter = fin * M
    cutoff = Fraction(min(fin, fout), 2) * roll
    return {'up': L, 'down': M, 'intermediate_rate': inter, 'cutoff_hz': str(cutoff), 'cutoff_norm': str(cutoff / Fraction(inter, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}]], [['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}]], [['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}]], [['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}]], [['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    fin, fout, roll = x[0], x[1], Fraction(x[2])
    if fin <= 0 or fout <= 0 or not 0 < roll <= 1:
        return 'bad-spec'
    g = math.gcd(fin, fout)
    L, M = fout // g, fin // g
    inter = max(fin, fout) * L
    cutoff = Fraction(min(fin, fout), 2) * roll
    return {'up': L, 'down': M, 'intermediate_rate': inter, 'cutoff_hz': str(cutoff), 'cutoff_norm': str(cutoff / Fraction(inter, 2))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}]], [['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: downsample by 3', [48000, 16000, '1'], {'up': 1, 'down': 3, 'intermediate_rate': 48000, 'cutoff_hz': '8000', 'cutoff_norm': '1/3'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}]], [['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}]], [['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}]], [['regression: 48k to 44.1k', [48000, 44100, '9/10'], {'up': 147, 'down': 160, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: 44.1k to 48k', [44100, 48000, '9/10'], {'up': 160, 'down': 147, 'intermediate_rate': 7056000, 'cutoff_hz': '19845', 'cutoff_norm': '9/1600'}], ['regression: odd ratio', [22050, 32000, '19/20'], {'up': 640, 'down': 441, 'intermediate_rate': 14112000, 'cutoff_hz': '41895/4', 'cutoff_norm': '19/12800'}], ['control: identity', [16000, 16000, '1'], {'up': 1, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '8000', 'cutoff_norm': '1'}], ['control: bad rolloff', [8000, 16000, '0'], 'bad-spec'], ['regression: coprime rates', [7, 5, '1/2'], {'up': 5, 'down': 7, 'intermediate_rate': 35, 'cutoff_hz': '5/4', 'cutoff_norm': '1/14'}], ['regression: upsample by 2', [8000, 16000, '4/5'], {'up': 2, 'down': 1, 'intermediate_rate': 16000, 'cutoff_hz': '3200', 'cutoff_norm': '2/5'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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)

prompt:
48 kHz to 44.1 kHz reports an intermediate rate of 7.68 MHz instead of 7.056 MHz.

Input [fin, fout, rolloff] (positive integer rates, rolloff in (0, 1]). Reduce fout/fin to up/down = L/M by gcd, intermediate rate = fin L, anti-alias cutoff = min(fin, fout)/2 * rolloff in Hz and normalized to the intermediate Nyquist. Return {"up", "down", "intermediate_rate", "cutoff_hz", "cutoff_norm"} or "bad-spec".

split: open-access


prompt:
The digital cutoff lands at about half the intended frequency.

Input [kind, wc, fs] with rational analog cutoff wc (rad/s) and sample rate fs. Map H(s) = wc/(s+wc) (lowpass) or s/(s+wc) (highpass) with s = K (1 - z^-1)/(1 + z^-1), K = 2 fs, no prewarping. Return {"b": [b0, b1], "a": [1, a1]} as fraction strings normalized so a0 = 1, or "bad-spec".

split: open-access


prompt:
The pole is mirrored to the other side of the z-plane, turning a lowpass into a resonance near Nyquist.

Input [kind, wc, fs] with rational analog cutoff wc (rad/s) and sample rate fs. Map H(s) = wc/(s+wc) (lowpass) or s/(s+wc) (highpass) with s = K (1 - z^-1)/(1 + z^-1), K = 2 fs, no prewarping. Return {"b": [b0, b1], "a": [1, a1]} as fraction strings normalized so a0 = 1, or "bad-spec".

split: open-access


prompt:
The "highpass" blocks high frequencies and passes DC.

Input [kind, wc, fs] with rational analog cutoff wc (rad/s) and sample rate fs. Map H(s) = wc/(s+wc) (lowpass) or s/(s+wc) (highpass) with s = K (1 - z^-1)/(1 + z^-1), K = 2 fs, no prewarping. Return {"b": [b0, b1], "a": [1, a1]} as fraction strings normalized so a0 = 1, or "bad-spec".

split: open-access


prompt:
The DC gain is (K + wc)/K instead of 1.

Input [kind, wc, fs] with rational analog cutoff wc (rad/s) and sample rate fs. Map H(s) = wc/(s+wc) (lowpass) or s/(s+wc) (highpass) with s = K (1 - z^-1)/(1 + z^-1), K = 2 fs, no prewarping. Return {"b": [b0, b1], "a": [1, a1]} as fraction strings normalized so a0 = 1, or "bad-spec".

split: open-access