The Principia Machina/TPC-PY/gen yardstick corpus.py: Difference between revisions
Appearance
TPC-PY source gen_yardstick_corpus.py (-), SHA-256 b51f0ec9a83216d6; conformed TPS 0.3.0; PROPOSED, not declared (CO-8) |
m 1 revision imported |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 9: | Line 9: | ||
regenerates the archived corpus byte for byte. Changed in the tree: the | regenerates the archived corpus byte for byte. Changed in the tree: the | ||
writer only (ensure_ascii=False, so a hidden character is written as | writer only (ensure_ascii=False, so a hidden character is written as | ||
itself, as the published corpus carries it; RD-C8-2). No case changed.""" | itself, as the published corpus carries it; RD-C8-2). No case changed. | ||
0.1.1 (C-MS-5, increment 11): six decode/ cases added at the end. | |||
0.2.0 (increment 12; tpm_record_functions 0.1.0 section 10, D195 (f) at | |||
Option 1, RD-RS-35): FIELD:U_C read from the field table the caller builds | |||
with tpc_record field_values ({rid: {"U_C": canonical decimal}}; L records | |||
"0"); any other FIELD refused as not in the field table; the C-16 message | |||
retired, its case re-expected; the fields/ cases added.""" | |||
import copy, json, os, sys | import copy, json, os, sys | ||
HERE = os.path.dirname(os.path.abspath(__file__)) | HERE = os.path.dirname(os.path.abspath(__file__)) | ||
| Line 86: | Line 92: | ||
"[REFUSED,no yardstick named x<U+202E>y]") | "[REFUSED,no yardstick named x<U+202E>y]") | ||
case("refused/field-awaits-c16", "yardstick_harness", {"tms": T, "name": "field", "suite": SUITE}, | case("refused/field-awaits-c16", "yardstick_harness", {"tms": T, "name": "field", "suite": SUITE}, | ||
"[REFUSED,FIELD | "[REFUSED,FIELD VALUE is not in the field table]", | ||
note="0.2.0: the field table holds U_C alone; the C-16 message is retired (RD-RS-35); the id is kept") | |||
case("refused/weight-not-finite", "yardstick_harness", {"tms": T, "name": "big", "suite": SUITE}, | case("refused/weight-not-finite", "yardstick_harness", {"tms": T, "name": "big", "suite": SUITE}, | ||
"[REFUSED,weight w_big is not a finite double]") | "[REFUSED,weight w_big is not a finite double]") | ||
case("refused/value-not-finite", "yardstick_harness", {"tms": T, "name": "huge", "suite": SUITE}, | case("refused/value-not-finite", "yardstick_harness", {"tms": T, "name": "huge", "suite": SUITE}, | ||
"[REFUSED,a yardstick value is not finite]", note="1e308*a + 1e308*s overflows to infinity") | "[REFUSED,a yardstick value is not finite]", note="1e308*a + 1e308*s overflows to infinity") | ||
# ---- 0.1.1 (C-MS-5; increment 11): a JSON {} and a JSON [] are told apart ------------- | |||
# Expectations by hand: a TMS the zone check refuses is "not well-formed" before any key is | |||
# built. Each case is one an assoc-array reading answered otherwise. | |||
case("decode/key-tms-list", "yardstick_key", {"tms": [], "name": "skel", "rid": "R1", "records": R}, | |||
"[REFUSED,TMS is not well-formed]") | |||
case("decode/key-yardsticks-object", "yardstick_key", | |||
{"tms": dict(tms(), YARDSTICKS={}), "name": "skel", "rid": "R1", "records": R}, | |||
"[REFUSED,TMS is not well-formed]", note="YARDSTICKS {} is not a list (it read as none: no yardstick named skel)") | |||
case("decode/key-yardsticks-zero-keyed", "yardstick_key", | |||
{"tms": dict(tms(), YARDSTICKS={"0": {"NAME": "skel", "KEY": ["SR1", "A", "S"], "LIMITING": []}}), | |||
"name": "skel", "rid": "R1", "records": R}, | |||
"[REFUSED,TMS is not well-formed]", note="it read as the list [skel] and keyed R1 [0,1,3]") | |||
case("decode/harness-limiting-object", "yardstick_harness", | |||
{"tms": tms(("skel", ["SR1", "A", "S"], {})), "name": "skel", "suite": SUITE}, | |||
"[REFUSED,TMS is not well-formed]") | |||
case("decode/checks-constants-zero-keyed", "yardstick_checks", | |||
{"tms": dict(tms(("skel", ["SR1", "A", "S"], [])), CONSTANTS={"0": {"NAME": "w_a", "VALUE": "1"}}), | |||
"name": "skel", "suite": SUITE}, | |||
"[REFUSED,TMS is not well-formed]") | |||
case("decode/harness-parameters-list", "yardstick_harness", | |||
{"tms": dict(tms(("skel", ["SR1", "A", "S"], [])), PARAMETERS=[]), "name": "skel", "suite": SUITE}, | |||
"[REFUSED,TMS is not well-formed]") | |||
# ---- 0.2.0 (increment 12): FIELD:U_C from the field table (tpm_record_functions 0.1.0 section 10) ----- | |||
# The table as tpc_record field_values builds it: an L record "0"; R3 an M record whose U_C is 50 ms | |||
# (5e-2 in s), R6 one whose U_C is 1 mm (1e-3 in m): the prefixes are normalized upstream. | |||
FT = {"R1": {"U_C": "0"}, "R2": {"U_C": "0"}, "R3": {"U_C": "5e-2"}, "R4": {"U_C": "0"}, | |||
"R5": {"U_C": "0"}, "R6": {"U_C": "1e-3"}, "R7": {"U_C": "0"}} | |||
SUITE_F = dict(copy.deepcopy(SUITE), fields=FT) | |||
FT_NO_R6 = dict((k, v) for k, v in FT.items() if k != "R6") | |||
# the 0.1.x TMS T is kept byte for byte; the FIELD:U_C yardsticks live in TF | |||
TF = copy.deepcopy(T) | |||
TF["YARDSTICKS"] += [{"NAME": n, "KEY": k, "LIMITING": l} for n, k, l in ( | |||
("uc", ["SR1", "FIELD:U_C", "A"], []), | |||
("uc_wsum", ["SR1", "WSUM:w_s*FIELD:U_C;w_a*A"], []), | |||
("uc_neg", ["SR1", "NEG:FIELD:U_C"], []), | |||
("field_wsum", ["SR1", "WSUM:w_a*FIELD:VALUE"], []))] | |||
def kf(name, rid, fields, expect, **extra): | |||
inp = {"tms": TF, "name": name, "rid": rid, "records": R} | |||
if fields is not None: | |||
inp["fields"] = fields | |||
case("fields/key-%s-%s" % (name, rid) + extra.pop("suffix", ""), "yardstick_key", inp, expect, **extra) | |||
kf("uc", "R1", FT, "[OK,[0,0,1]]", note="an L record's U_C is 0") | |||
kf("uc", "R5", FT, "[OK,[0,0,1]]", note="an L record at 0 in a limiting-free key") | |||
kf("uc", "R3", FT, "[OK,[0,0.05,0]]", note="an M record: U_C 5e-2 read as the double 0.05") | |||
kf("uc", "R6", FT, "[OK,[0,0.001,1]]", note="another prefix upstream: 1e-3") | |||
kf("uc_wsum", "R6", FT, "[OK,[0,1.0005]]", note="WSUM in canonical atom order: 1 * a + 0.5 * U_C") | |||
kf("uc_neg", "R3", FT, "[OK,[0,-0.05]]") | |||
kf("uc_neg", "R1", FT, "[OK,[0,0]]", note="NEG of 0 is written 0, never -0") | |||
kf("uc", "R3", FT_NO_R6, "[OK,[0,0.05,0]]", suffix="-other-missing", note="only the keyed record's value is read") | |||
kf("uc", "R6", FT_NO_R6, "[REFUSED,FIELD U_C has no value for R6]", suffix="-missing") | |||
kf("uc", "R1", None, "[REFUSED,FIELD U_C has no value for R1]", suffix="-no-table") | |||
kf("uc", "R3", dict(FT, R3={"U_C": "0.050"}), "[REFUSED,FIELD U_C has no value for R3]", suffix="-not-canonical", | |||
note="the table holds canonical decimals (field_values); 0.050 is not one (RD-TQ reading)") | |||
kf("uc", "R3", dict(FT, R3={}), "[REFUSED,FIELD U_C has no value for R3]", suffix="-empty-row") | |||
kf("uc", "R3", [], "[REFUSED,FIELD U_C has no value for R3]", suffix="-table-list", | |||
note="a JSON [] is not the table (C-MS-5)") | |||
kf("field", "R1", FT, "[REFUSED,FIELD VALUE is not in the field table]") | |||
kf("field_wsum", "R1", FT, "[REFUSED,FIELD VALUE is not in the field table]", note="inside a WSUM too") | |||
case("fields/harness-uc", "yardstick_harness", {"tms": TF, "name": "uc", "suite": SUITE_F}, "[OK,true,true,true,0]", | |||
note="FIELD is independent of the assumption count: r+ carries r's U_C, so C2 holds") | |||
case("fields/harness-uc_wsum", "yardstick_harness", {"tms": TF, "name": "uc_wsum", "suite": SUITE_F}, | |||
"[OK,true,true,true,0]") | |||
case("fields/harness-uc_neg", "yardstick_harness", {"tms": TF, "name": "uc_neg", "suite": SUITE_F}, | |||
"[OK,true,true,true,0]") | |||
case("fields/checks-uc", "yardstick_checks", {"tms": TF, "name": "uc", "suite": SUITE_F}, | |||
"[OK,[true,[]],[true,[],[]],[true,[]]]") | |||
case("fields/harness-uc-missing", "yardstick_harness", | |||
{"tms": TF, "name": "uc", "suite": dict(copy.deepcopy(SUITE), fields=FT_NO_R6)}, | |||
"[REFUSED,FIELD U_C has no value for R6]") | |||
case("fields/harness-uc-no-table", "yardstick_harness", {"tms": TF, "name": "uc", "suite": SUITE}, | |||
"[REFUSED,FIELD U_C has no value for R4]", note="C1 keys the SR1-failing records first (tpc_sr9 sr9_c1)") | |||
case("fields/harness-skel-table-ignored", "yardstick_harness", {"tms": TF, "name": "skel", "suite": SUITE_F}, | |||
"[OK,true,true,true,0]", note="a FIELD-free yardstick reads no table") | |||
def dispatch(fn, i): | def dispatch(fn, i): | ||
if fn == "yardstick_key": | if fn == "yardstick_key": | ||
return Y.yardstick_key(i["tms"], i["name"], i["rid"], i["records"], i.get("tfk_assumptions", [])) | return Y.yardstick_key(i["tms"], i["name"], i["rid"], i["records"], i.get("tfk_assumptions", []), | ||
i.get("fields")) | |||
if fn == "yardstick_checks": | if fn == "yardstick_checks": | ||
return Y.yardstick_checks(i["tms"], i["name"], i["suite"]) | return Y.yardstick_checks(i["tms"], i["name"], i["suite"]) | ||
| Line 114: | Line 202: | ||
corpus = { | corpus = { | ||
"meta": { | "meta": { | ||
"name": "tpc_yardstick_corpus", "version": "0. | "name": "tpc_yardstick_corpus", "version": "0.2.0", | ||
"status": "VERIFIED (both residences)", | "status": "VERIFIED (both residences)", | ||
"conforms_tps": "0.1.0 revision 4 (TPS 4.5: SR9 C1, C2, C4 on a declared, executable TMS entry; D100.1)", | "conforms_tps": "0.1.0 revision 4 (TPS 4.5: SR9 C1, C2, C4 on a declared, executable TMS entry; D100.1)", | ||
"module": "tpc_yardstick 0. | "module": "tpc_yardstick 0.2.0 (tpc_zone 0.2.0, tpc_sr9 0.1.0)", | ||
"suite": "sr9_synthetic_suite 0.1.0, verbatim", | "suite": "sr9_synthetic_suite 0.1.0, verbatim", | ||
"note": ("Expectations hand-derived: a() R1=1 R2=2 R3=0 R4=0 R5=1 R6=1 R7=0; steps 3 1 1 1 2 2 2; " | "note": ("Expectations hand-derived: a() R1=1 R2=2 R3=0 R4=0 R5=1 R6=1 R7=0; steps 3 1 1 1 2 2 2; " | ||
"only R4 fails SR1; R5 in LIM, R6 in OTHER. Both residences MUST reproduce every expect.") | "only R4 fails SR1; R5 in LIM, R6 in OTHER. Both residences MUST reproduce every expect. " | ||
"0.1.1 (C-MS-5, increment 11, 2026-09-28): six decode/ cases, a JSON {} and [] and an object keyed 0 " | |||
"read as written in both residences; no earlier answer moves. " | |||
"0.2.0 (increment 12): FIELD:U_C from the field table; the C-16 refusal retired.") | |||
}, | }, | ||
"cases": cases | "cases": cases | ||
Latest revision as of 02:11, 30 September 2026
# -*- coding: utf-8 -*-
"""Generator for tpc/vectors/yardstick_corpus.json (TPC step 2, increment 5).
Expectations are HAND-DERIVED from the synthetic suite and written literally
below; the generator refuses to write the corpus if the module disagrees.
Run: cd tpc && python3 gen_yardstick_corpus.py (Windows: py ...).
Recovered 2026-09-27 (BASE-GEN; record 0.18.0 section 7) from the TIDY 3
archive, tidy3_2026-09-25/gen_yardstick_corpus.py, SHA-256
74edc22c5818f5c8f93f5004b76128e52dd857bbc95ea11289729e891f49eae1, where it
regenerates the archived corpus byte for byte. Changed in the tree: the
writer only (ensure_ascii=False, so a hidden character is written as
itself, as the published corpus carries it; RD-C8-2). No case changed.
0.1.1 (C-MS-5, increment 11): six decode/ cases added at the end.
0.2.0 (increment 12; tpm_record_functions 0.1.0 section 10, D195 (f) at
Option 1, RD-RS-35): FIELD:U_C read from the field table the caller builds
with tpc_record field_values ({rid: {"U_C": canonical decimal}}; L records
"0"); any other FIELD refused as not in the field table; the C-16 message
retired, its case re-expected; the fields/ cases added."""
import copy, json, os, sys
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
import tpc_strike as S
import tpc_yardstick as Y
# The synthetic record suite of increment 3, verbatim (sr9_corpus.json).
SUITE = json.load(open(os.path.join(HERE, "vectors", "sr9_corpus.json"), encoding="utf-8"))["cases"][0]["input"]["suite"]
# Hand facts about the suite: a(): R1=1 R2=2 R3=0 R4=0 R5=1 R6=1 R7=0.
# steps: R1=3 R2=1 R3=1 R4=1 R5=2 R6=2 R7=2. Only R4 fails SR1.
# DOMAIN: R5=LIM, R6=OTHER, the rest MAIN. L-M pairs: R1|R3, R2|R3, R7|R3.
assert [SUITE["records"][r]["steps"] for r in ["R1", "R2", "R3", "R4", "R5", "R6", "R7"]] == [3, 1, 1, 1, 2, 2, 2]
PARAMS = {"STEP_CONVENTION": "one inference rule is one step", "K": "2", "N_X": 2, "S_MAX": 10}
CONSTS = [{"NAME": "w_a", "VALUE": "1"}, {"NAME": "w_s", "VALUE": "0.5"},
{"NAME": "w_big", "VALUE": "1e400"}, {"NAME": "w_huge", "VALUE": "1e308"}]
def tms(*yardsticks):
return {"PARAMETERS": dict(PARAMS), "CONSTANTS": copy.deepcopy(CONSTS),
"YARDSTICKS": [{"NAME": n, "KEY": k, "LIMITING": l} for n, k, l in yardsticks]}
T = tms(
("skel", ["SR1", "A", "S"], []),
("comb", ["SR1", "WSUM:w_a*A;w_s*S", "S"], []),
("lim", ["SR1", "A", "S"], [{"DOMAIN": "LIM", "KEY": ["SR1", "NEG:A", "S"]}]),
("lim_main", ["SR1", "A"], [{"DOMAIN": "MAIN", "KEY": ["SR1", "NEG:A"]}]),
("field", ["SR1", "FIELD:VALUE"], []),
("big", ["SR1", "WSUM:w_big*S"], []),
("huge", ["SR1", "WSUM:w_huge*A;w_huge*S"], []),
)
R = SUITE["records"]
cases = []
def case(cid, fn, inp, expect, **extra):
c = {"id": cid, "fn": fn, "input": inp}
c.update(extra)
c["expect"] = expect
cases.append(c)
# ---- keys ------------------------------------------------------------------
case("key/skel-R1", "yardstick_key", {"tms": T, "name": "skel", "rid": "R1", "records": R}, "[OK,[0,1,3]]")
case("key/skel-R4-fails-SR1", "yardstick_key", {"tms": T, "name": "skel", "rid": "R4", "records": R}, "[OK,[1,0,1]]")
case("key/comb-R1", "yardstick_key", {"tms": T, "name": "comb", "rid": "R1", "records": R}, "[OK,[0,2.5,3]]",
note="a + 0.5 s = 1 + 1.5")
case("key/comb-R2", "yardstick_key", {"tms": T, "name": "comb", "rid": "R2", "records": R}, "[OK,[0,2.5,1]]",
note="2 + 0.5; ties R1 on the WSUM, S breaks the tie")
case("key/lim-R5-uses-limiting-key", "yardstick_key", {"tms": T, "name": "lim", "rid": "R5", "records": R}, "[OK,[0,-1,2]]")
case("key/lim-R1-uses-main-key", "yardstick_key", {"tms": T, "name": "lim", "rid": "R1", "records": R}, "[OK,[0,1,3]]")
case("key/lim_main-R3-no-negative-zero", "yardstick_key", {"tms": T, "name": "lim_main", "rid": "R3", "records": R},
"[OK,[0,0]]", note="NEG of a(R3) = 0 is written 0, never -0")
# ---- the harness on declared yardsticks --------------------------------------
case("harness/skel", "yardstick_harness", {"tms": T, "name": "skel", "suite": SUITE}, "[OK,true,true,true,0]",
note="the strike skeleton declared in the grammar reproduces increment 3's skeleton fixture")
case("harness/comb", "yardstick_harness", {"tms": T, "name": "comb", "suite": SUITE}, "[OK,true,true,true,0]")
case("checks/lim", "yardstick_checks", {"tms": T, "name": "lim", "suite": SUITE},
"[OK,[true,[]],[true,[],[R5]],[true,[]]]",
note="R5 (LIM) is keyed by -a: one more assumption lowers its key, exempt inside the declared DOMAIN")
case("checks/lim_main", "yardstick_checks", {"tms": T, "name": "lim_main", "suite": SUITE},
"[OK,[true,[]],[true,[],[R1,R2,R3,R4,R7]],[true,[]]]",
note="every MAIN record inverted and exempt; R5 (LIM) and R6 (OTHER) keep the main KEY and pass")
# ---- refusals ----------------------------------------------------------------
case("refused/naive-key-is-not-well-formed", "yardstick_harness",
{"tms": tms(("naive", ["A", "S"], [])), "name": "naive", "suite": SUITE},
"[REFUSED,TMS is not well-formed]", note="C1 fails by construction: KEY must begin with SR1")
case("refused/more-is-better-is-not-well-formed", "yardstick_harness",
{"tms": tms(("more", ["SR1", "NEG:A", "S"], [])), "name": "more", "suite": SUITE},
"[REFUSED,TMS is not well-formed]", note="static C2 refuses it at entry")
case("refused/no-such-yardstick", "yardstick_harness", {"tms": T, "name": "nope", "suite": SUITE},
"[REFUSED,no yardstick named nope]")
case("refused/name-escaped", "yardstick_harness", {"tms": T, "name": "x\u202ey", "suite": SUITE},
"[REFUSED,no yardstick named x<U+202E>y]")
case("refused/field-awaits-c16", "yardstick_harness", {"tms": T, "name": "field", "suite": SUITE},
"[REFUSED,FIELD VALUE is not in the field table]",
note="0.2.0: the field table holds U_C alone; the C-16 message is retired (RD-RS-35); the id is kept")
case("refused/weight-not-finite", "yardstick_harness", {"tms": T, "name": "big", "suite": SUITE},
"[REFUSED,weight w_big is not a finite double]")
case("refused/value-not-finite", "yardstick_harness", {"tms": T, "name": "huge", "suite": SUITE},
"[REFUSED,a yardstick value is not finite]", note="1e308*a + 1e308*s overflows to infinity")
# ---- 0.1.1 (C-MS-5; increment 11): a JSON {} and a JSON [] are told apart -------------
# Expectations by hand: a TMS the zone check refuses is "not well-formed" before any key is
# built. Each case is one an assoc-array reading answered otherwise.
case("decode/key-tms-list", "yardstick_key", {"tms": [], "name": "skel", "rid": "R1", "records": R},
"[REFUSED,TMS is not well-formed]")
case("decode/key-yardsticks-object", "yardstick_key",
{"tms": dict(tms(), YARDSTICKS={}), "name": "skel", "rid": "R1", "records": R},
"[REFUSED,TMS is not well-formed]", note="YARDSTICKS {} is not a list (it read as none: no yardstick named skel)")
case("decode/key-yardsticks-zero-keyed", "yardstick_key",
{"tms": dict(tms(), YARDSTICKS={"0": {"NAME": "skel", "KEY": ["SR1", "A", "S"], "LIMITING": []}}),
"name": "skel", "rid": "R1", "records": R},
"[REFUSED,TMS is not well-formed]", note="it read as the list [skel] and keyed R1 [0,1,3]")
case("decode/harness-limiting-object", "yardstick_harness",
{"tms": tms(("skel", ["SR1", "A", "S"], {})), "name": "skel", "suite": SUITE},
"[REFUSED,TMS is not well-formed]")
case("decode/checks-constants-zero-keyed", "yardstick_checks",
{"tms": dict(tms(("skel", ["SR1", "A", "S"], [])), CONSTANTS={"0": {"NAME": "w_a", "VALUE": "1"}}),
"name": "skel", "suite": SUITE},
"[REFUSED,TMS is not well-formed]")
case("decode/harness-parameters-list", "yardstick_harness",
{"tms": dict(tms(("skel", ["SR1", "A", "S"], [])), PARAMETERS=[]), "name": "skel", "suite": SUITE},
"[REFUSED,TMS is not well-formed]")
# ---- 0.2.0 (increment 12): FIELD:U_C from the field table (tpm_record_functions 0.1.0 section 10) -----
# The table as tpc_record field_values builds it: an L record "0"; R3 an M record whose U_C is 50 ms
# (5e-2 in s), R6 one whose U_C is 1 mm (1e-3 in m): the prefixes are normalized upstream.
FT = {"R1": {"U_C": "0"}, "R2": {"U_C": "0"}, "R3": {"U_C": "5e-2"}, "R4": {"U_C": "0"},
"R5": {"U_C": "0"}, "R6": {"U_C": "1e-3"}, "R7": {"U_C": "0"}}
SUITE_F = dict(copy.deepcopy(SUITE), fields=FT)
FT_NO_R6 = dict((k, v) for k, v in FT.items() if k != "R6")
# the 0.1.x TMS T is kept byte for byte; the FIELD:U_C yardsticks live in TF
TF = copy.deepcopy(T)
TF["YARDSTICKS"] += [{"NAME": n, "KEY": k, "LIMITING": l} for n, k, l in (
("uc", ["SR1", "FIELD:U_C", "A"], []),
("uc_wsum", ["SR1", "WSUM:w_s*FIELD:U_C;w_a*A"], []),
("uc_neg", ["SR1", "NEG:FIELD:U_C"], []),
("field_wsum", ["SR1", "WSUM:w_a*FIELD:VALUE"], []))]
def kf(name, rid, fields, expect, **extra):
inp = {"tms": TF, "name": name, "rid": rid, "records": R}
if fields is not None:
inp["fields"] = fields
case("fields/key-%s-%s" % (name, rid) + extra.pop("suffix", ""), "yardstick_key", inp, expect, **extra)
kf("uc", "R1", FT, "[OK,[0,0,1]]", note="an L record's U_C is 0")
kf("uc", "R5", FT, "[OK,[0,0,1]]", note="an L record at 0 in a limiting-free key")
kf("uc", "R3", FT, "[OK,[0,0.05,0]]", note="an M record: U_C 5e-2 read as the double 0.05")
kf("uc", "R6", FT, "[OK,[0,0.001,1]]", note="another prefix upstream: 1e-3")
kf("uc_wsum", "R6", FT, "[OK,[0,1.0005]]", note="WSUM in canonical atom order: 1 * a + 0.5 * U_C")
kf("uc_neg", "R3", FT, "[OK,[0,-0.05]]")
kf("uc_neg", "R1", FT, "[OK,[0,0]]", note="NEG of 0 is written 0, never -0")
kf("uc", "R3", FT_NO_R6, "[OK,[0,0.05,0]]", suffix="-other-missing", note="only the keyed record's value is read")
kf("uc", "R6", FT_NO_R6, "[REFUSED,FIELD U_C has no value for R6]", suffix="-missing")
kf("uc", "R1", None, "[REFUSED,FIELD U_C has no value for R1]", suffix="-no-table")
kf("uc", "R3", dict(FT, R3={"U_C": "0.050"}), "[REFUSED,FIELD U_C has no value for R3]", suffix="-not-canonical",
note="the table holds canonical decimals (field_values); 0.050 is not one (RD-TQ reading)")
kf("uc", "R3", dict(FT, R3={}), "[REFUSED,FIELD U_C has no value for R3]", suffix="-empty-row")
kf("uc", "R3", [], "[REFUSED,FIELD U_C has no value for R3]", suffix="-table-list",
note="a JSON [] is not the table (C-MS-5)")
kf("field", "R1", FT, "[REFUSED,FIELD VALUE is not in the field table]")
kf("field_wsum", "R1", FT, "[REFUSED,FIELD VALUE is not in the field table]", note="inside a WSUM too")
case("fields/harness-uc", "yardstick_harness", {"tms": TF, "name": "uc", "suite": SUITE_F}, "[OK,true,true,true,0]",
note="FIELD is independent of the assumption count: r+ carries r's U_C, so C2 holds")
case("fields/harness-uc_wsum", "yardstick_harness", {"tms": TF, "name": "uc_wsum", "suite": SUITE_F},
"[OK,true,true,true,0]")
case("fields/harness-uc_neg", "yardstick_harness", {"tms": TF, "name": "uc_neg", "suite": SUITE_F},
"[OK,true,true,true,0]")
case("fields/checks-uc", "yardstick_checks", {"tms": TF, "name": "uc", "suite": SUITE_F},
"[OK,[true,[]],[true,[],[]],[true,[]]]")
case("fields/harness-uc-missing", "yardstick_harness",
{"tms": TF, "name": "uc", "suite": dict(copy.deepcopy(SUITE), fields=FT_NO_R6)},
"[REFUSED,FIELD U_C has no value for R6]")
case("fields/harness-uc-no-table", "yardstick_harness", {"tms": TF, "name": "uc", "suite": SUITE},
"[REFUSED,FIELD U_C has no value for R4]", note="C1 keys the SR1-failing records first (tpc_sr9 sr9_c1)")
case("fields/harness-skel-table-ignored", "yardstick_harness", {"tms": TF, "name": "skel", "suite": SUITE_F},
"[OK,true,true,true,0]", note="a FIELD-free yardstick reads no table")
def dispatch(fn, i):
if fn == "yardstick_key":
return Y.yardstick_key(i["tms"], i["name"], i["rid"], i["records"], i.get("tfk_assumptions", []),
i.get("fields"))
if fn == "yardstick_checks":
return Y.yardstick_checks(i["tms"], i["name"], i["suite"])
if fn == "yardstick_harness":
return Y.yardstick_harness(i["tms"], i["name"], i["suite"])
raise KeyError(fn)
bad = 0
for c in cases:
got = S.canon(dispatch(c["fn"], c["input"]))
if got != c["expect"]:
bad += 1
print("MISMATCH", c["id"], "\n expect", c["expect"], "\n got ", got)
if bad:
sys.exit("refusing to write: %d mismatches" % bad)
corpus = {
"meta": {
"name": "tpc_yardstick_corpus", "version": "0.2.0",
"status": "VERIFIED (both residences)",
"conforms_tps": "0.1.0 revision 4 (TPS 4.5: SR9 C1, C2, C4 on a declared, executable TMS entry; D100.1)",
"module": "tpc_yardstick 0.2.0 (tpc_zone 0.2.0, tpc_sr9 0.1.0)",
"suite": "sr9_synthetic_suite 0.1.0, verbatim",
"note": ("Expectations hand-derived: a() R1=1 R2=2 R3=0 R4=0 R5=1 R6=1 R7=0; steps 3 1 1 1 2 2 2; "
"only R4 fails SR1; R5 in LIM, R6 in OTHER. Both residences MUST reproduce every expect. "
"0.1.1 (C-MS-5, increment 11, 2026-09-28): six decode/ cases, a JSON {} and [] and an object keyed 0 "
"read as written in both residences; no earlier answer moves. "
"0.2.0 (increment 12): FIELD:U_C from the field table; the C-16 refusal retired.")
},
"cases": cases
}
with open(os.path.join(HERE, "vectors", "yardstick_corpus.json"), "w", encoding="utf-8",
newline="\n") as f:
f.write(json.dumps(corpus, indent=1, ensure_ascii=False) + "\n")
print("wrote", len(cases), "yardstick cases; all match hand-derived expectations")