Evidence

CALCULATION.py

Download source fileOpen in research workspace
"""C480: finite source grammar of the frozen C470 1150 inventory.

Standard library only. No source, pivot, phase, or operator is admitted here.
"""
from collections import Counter, defaultdict
from fractions import Fraction
from itertools import product

KEYS = ("gear", "Cainan", "Terah60", "full430")
WEIGHTS = (2, 130, 60, 215)
CONTEXTS = list(product(range(1, 4), range(2), range(2), range(2)))


def context(record):
    return tuple(record[k] for k in KEYS)


def role(record):
    return (record["tradition"], record["role"], record.get("rail"))


def shift(q):
    g, c, t, f = q
    return 2 * (g - 1) + 130 * c + 60 * t + 215 * f


def classify(a, b, delta):
    """Predicates use identities and context, never numerical cutoffs."""
    same = delta == (0, 0, 0, 0)
    if (role(a) == ("MT", "Shem death", None)
            and role(b) in [("SP", "Flood start", None), ("LXX", "Flood start", None)]
            and same):
        return "A"
    if (role(a) == ("MT", "Shem birth", None)
            and role(b) in [("SP", "Noah birth", "primary"), ("LXX", "Noah birth", None)]
            and same):
        return "B"
    if (role(a) == ("MT", "Noah death", None)
            and role(b) in [("SP", "Flood close", None), ("LXX", "Flood close", None)]
            and delta == (-2, 0, -1, 1)):
        return "C"
    if (role(a) == ("MT", "Flood start", None)
            and role(b) == ("SP", "Shem birth", "companion")
            and delta == (-2, 1, 1, 1)):
        return "D"
    return None


def run(load, read, check):
    records = load("C286_DATA.json")["target_register"]
    old = load("C470_DATA.json")
    pivots = load("C450_DATA.json")["pivots"]
    output_grammar = load("C472_DATA.json")
    ix = defaultdict(list)
    role_context_index = {}
    bases = defaultdict(set)
    role_contexts = defaultdict(set)
    for i, rec in enumerate(records):
        ix[rec["center"]].append(i)
        rq = role(rec), context(rec)
        assert rq not in role_context_index
        role_context_index[rq] = i
        bases[role(rec)].add(rec["center"] - shift(context(rec)))
        role_contexts[role(rec)].add(context(rec))
    ix = dict(ix)  # Missing outputs must never create source-index entries.
    check("frozen_domain_528_labels_373_coordinates", len(records) == 528 and len(ix) == 373)
    check("22_complete_role_grids", len(bases) == 22 and all(v == set(CONTEXTS) for v in role_contexts.values()))
    check("each_role_has_one_affine_base", all(len(v) == 1 for v in bases.values()))
    base = {k: next(iter(v)) for k, v in bases.items()}
    check("fixed_eight_pivots", pivots == [2756, 2758, 2816, 2818, 3620, 3622, 3680, 3682])
    check("all_pivots_sourced", all(h in ix for h in pivots))

    # Main route: preserve every label index in the already frozen inventory.
    labels = []
    coordinate_rows = []
    for p in old["all_1150_pairs"]:
        x, y = p["coordinates"]
        check(f"frozen_indices_{x}", p["source_indices"] == [ix[x], ix[y]] and y - x == 1150)
        rows = []
        for i, j in product(*p["source_indices"]):
            a, b = records[i], records[j]
            delta = tuple(b[k] - a[k] for k in KEYS)
            family = classify(a, b, delta)
            check(f"typed_label_{i}_{j}", family is not None)
            row = {
                "lower_record": i, "upper_record": j, "coordinates": [x, y],
                "family": family, "lower_context": list(context(a)),
                "upper_context": list(context(b)), "delta_context": list(delta),
                "lower_role": list(role(a)), "upper_role": list(role(b)),
            }
            rows.append(row)
            labels.append(row)
        families = {z["family"] for z in rows}
        check(f"one_family_at_coordinate_{x}", len(families) == 1)
        coordinate_rows.append({"coordinates": [x, y], "source_indices": p["source_indices"],
                                "family": rows[0]["family"], "label_pairs": len(rows)})
    check("51_coordinates_101_labels", len(coordinate_rows) == 51 and len(labels) == 101)
    check("no_duplicate_label_pairs", len({(z["lower_record"], z["upper_record"]) for z in labels}) == 101)

    # Alternative completeness route: solve the role/context equation before
    # instantiating records. There are 22^2 * 5 * 3^3 possible signatures.
    signatures = []
    reconstructed = set()
    tested_signatures = 0
    for ra, ba in sorted(base.items(), key=lambda x: str(x[0])):
        for rb, bb in sorted(base.items(), key=lambda x: str(x[0])):
            for delta in product(range(-2, 3), range(-1, 2), range(-1, 2), range(-1, 2)):
                tested_signatures += 1
                if bb - ba + sum(w * v for w, v in zip(WEIGHTS, delta)) != 1150:
                    continue
                generated = []
                for q in CONTEXTS:
                    other = tuple(a + d for a, d in zip(q, delta))
                    if other not in CONTEXTS:
                        continue
                    i, j = role_context_index[ra, q], role_context_index[rb, other]
                    reconstructed.add((i, j))
                    generated.append([i, j])
                signatures.append({"lower_role": list(ra), "upper_role": list(rb),
                                   "baseline_gap": bb - ba, "delta_context": list(delta),
                                   "label_pairs": generated, "label_count": len(generated)})
    expected_pairs = {(z["lower_record"], z["upper_record"]) for z in labels}
    direct_pairs = {(i, j) for i, a in enumerate(records) for j, b in enumerate(records)
                    if b["center"] - a["center"] == 1150}
    check("65340_signature_equations_seven_solutions", tested_signatures == 65340 and len(signatures) == 7)
    check("algebraic_instantiation_exactly_matches_frozen_labels", reconstructed == expected_pairs)
    check("direct_record_comparison_exactly_matches_templates", direct_pairs == expected_pairs)

    # These formulas generate precisely the four coordinate templates.
    formula_pairs = {
        "A": {(1741 + shift(q), 2891 + shift(q)) for q in CONTEXTS},
        "B": {(2341 + shift(q), 3491 + shift(q)) for q in CONTEXTS},
        "C": {(1955 + 130 * c, 3105 + 130 * c) for c in range(2)},
        "D": {(2245, 3395)},
    }
    equations = {"A": [500, 650], "B": [500, 650],
                 "C": [350, 650, 215, -60, -4, -1],
                 "D": [750, 130, 60, 215, -4, -1]}
    summary = []
    for f in "ABCD":
        coords = {tuple(z["coordinates"]) for z in coordinate_rows if z["family"] == f}
        check(f"formula_generation_{f}", coords == formula_pairs[f])
        check(f"source_equation_{f}", sum(equations[f]) == 1150)
        summary.append({"family": f, "coordinate_pairs": len(coords),
                        "label_pairs": sum(z["family"] == f for z in labels),
                        "source_equation_terms": equations[f]})
    check("four_disjoint_coordinate_templates", sum(len(v) for v in formula_pairs.values()) == len(set.union(*formula_pairs.values())) == 51)
    check("matched_families_correspond_by_600", {(x + 600, y + 600) for x, y in formula_pairs["A"]} == formula_pairs["B"])
    check("template_counts", [(z["coordinate_pairs"], z["label_pairs"]) for z in summary] == [(24, 48), (24, 48), (2, 4), (1, 1)])
    alias_groups = []
    for p in coordinate_rows:
        ls = [z for z in labels if z["coordinates"] == p["coordinates"]]
        if len(ls) == 2:
            check(f"SP_LXX_only_alias_{p['coordinates'][0]}",
                  len({z["lower_record"] for z in ls}) == 1
                  and {z["upper_role"][0] for z in ls} == {"SP", "LXX"}
                  and len({(tuple(z["upper_context"]), z["upper_role"][1]) for z in ls}) == 1)
            alias_groups.append({"coordinates": p["coordinates"], "family": p["family"],
                                 "record_pairs": [[z["lower_record"], z["upper_record"]] for z in ls],
                                 "Cainan": ls[0]["upper_context"][1],
                                 "LXX_state": "native ON" if ls[0]["upper_context"][1] else "theoretical OFF"})
    check("50_tradition_alias_groups_no_extra_role_aliases", len(alias_groups) == 50 and sum(z["label_pairs"] == 1 for z in coordinate_rows) == 1)

    # Evaluate only the inherited 408 trials. Integrality is x == h (mod 23).
    trials, integral, admitted = [], [], []
    statuses = ("fractional", "neither", "lower_only", "upper_only", "both")
    counts = {f: Counter() for f in "ABCD"}
    old_rows = []
    output_by_pair = defaultdict(list)
    for z in output_grammar["label_pairs"]:
        output_by_pair[tuple(z["coordinates"])].append(z)
    for p in coordinate_rows:
        x, y = p["coordinates"]
        for h in pivots:
            values = [Fraction(25 * z - 2 * h, 23) for z in (x, y)]
            integer = all(z.denominator == 1 for z in values)
            check(f"congruence_and_span_{x}_{h}", integer == ((x - h) % 23 == 0) and values[1] - values[0] == 1250)
            available = [int(z) in ix for z in values] if integer else [None, None]
            status = "fractional" if not integer else (
                "both" if all(available) else "lower_only" if available[0]
                else "upper_only" if available[1] else "neither")
            row = {"family": p["family"], "input_pair": [x, y], "pivot": h,
                   "outputs": list(map(str, values)), "integer_outputs": integer,
                   "output_source_membership": available, "status": status}
            trials.append(row)
            counts[p["family"]][status] += 1
            old_rows.append({"input_pair": [x, y], "pivot": h, "outputs": list(map(str, values)),
                             "integer_outputs": integer, "both_outputs_sourced": status == "both"})
            if integer:
                integral.append({**row, "output_indices": [ix.get(int(z), []) for z in values]})
            if status == "both":
                out = list(map(int, values))
                predecessors = []
                for first in pivots:
                    pre = [Fraction(23 * z + 2 * first, 25) for z in (x, y)]
                    integral_pre = all(z.denominator == 1 for z in pre)
                    check(f"inverse_congruence_{x}_{first}", integral_pre == ((first - x) % 25 == 0) and pre[1] - pre[0] == 1058)
                    sourced = integral_pre and all(int(z) in ix for z in pre)
                    predecessors.append({"first_pivot": first, "predecessor_pair": list(map(str, pre)),
                                         "complete": sourced})
                admitted.append({"family": p["family"], "input_pair": [x, y], "output_pair": out,
                                 "second_pivot": h, "input_indices": [ix[x], ix[y]],
                                 "output_indices": [ix[z] for z in out], "pivot_indices": ix[h],
                                 "endpoint_changes": [out[0] - x, out[1] - y],
                                 "output_label_classifications": output_by_pair[tuple(out)],
                                 "predecessor_trials": predecessors,
                                 "complete_predecessors": [z for z in predecessors if z["complete"]]})
    check("all_408_trials_equal_C470", old_rows == old["all_trials"])
    for row, inherited in zip(admitted, old["admitted_expansions"]):
        check(f"admitted_source_ancestry_matches_{row['input_pair'][0]}", all(row[k] == v for k, v in inherited.items()))
    check("exactly_three_admitted_expansions", len(admitted) == len(old["admitted_expansions"]) == 3)
    check("all_outputs_in_C472_matched_Shem_family", all(z["family"] == "A_matched_Shem" for a in admitted for z in a["output_label_classifications"]))
    check("exactly_one_complete_2K_predecessor", sum(bool(z["complete_predecessors"]) for z in admitted) == 1)
    failure_summary = [{"family": f, "trials": sum(counts[f].values()),
                        **{s: counts[f][s] for s in statuses}} for f in "ABCD"]
    check("family_failure_partition", [[counts[f][s] for s in statuses] for f in "ABCD"] ==
          [[185, 4, 0, 1, 2], [184, 4, 4, 0, 0], [15, 0, 0, 0, 1], [8, 0, 0, 0, 0]])

    # Reverse selection from sourced output intervals uses integer arithmetic
    # and no Fraction evaluation. It verifies the positive list independently.
    reverse_hits = set()
    for p in coordinate_rows:
        x, y = p["coordinates"]
        for q in output_grammar["coordinate_pairs"]:
            u, v = q["lower"], q["upper"]
            twice_h = 25 * x - 23 * u
            if twice_h % 2 == 0 and twice_h // 2 in pivots and 25 * y - 23 * v == twice_h:
                reverse_hits.add((x, y, twice_h // 2, u, v))
    expected_hits = {(*z["input_pair"], z["second_pivot"], *z["output_pair"]) for z in admitted}
    check("reverse_output_to_pivot_selection_agrees", reverse_hits == expected_hits)
    check("no_sources_or_pivots_added", len(ix) == 373 and len(pivots) == 8)
    return {
        "step": "C480", "normalization": {
            "context_keys": list(KEYS), "formula": "beta_role + 2*(gear-1) + 130*Cainan + 60*Terah60 + 215*full430",
            "roles": [{"role": list(k), "beta_role": v} for k, v in sorted(base.items(), key=lambda x: str(x[0]))],
            "contexts": [list(q) for q in CONTEXTS],
            "LXX_qualification": "Cainan=1 native ON; Cainan=0 theoretical OFF; SP and MT Cainan=1 are declared insertions.",
        },
        "template_summary": summary, "coordinate_pairs": coordinate_rows, "label_pairs": labels,
        "signature_solutions": signatures, "alias_groups": alias_groups,
        "fixed_pivots": [{"coordinate": h, "residue_mod23": h % 23, "source_indices": ix[h]} for h in pivots],
        "all_trials": trials, "integral_trials": integral, "failure_summary": failure_summary,
        "admitted_expansions": admitted,
        "counts": {"coordinate_pairs": 51, "label_pairs": 101, "source_role_context_signatures": 7,
                   "templates": 4, "tradition_alias_groups": 50, "tested_signature_equations": tested_signatures,
                   "trials": len(trials), "fractional_trials": sum(t["status"] == "fractional" for t in trials),
                   "integral_trials": len(integral), "admitted_expansions": len(admitted),
                   "complete_2K_predecessors": sum(bool(z["complete_predecessors"]) for z in admitted)},
        "limits": "Finite source/context grammar only; no new date, pivot, phase, operator, canonical or graph edit. Same-agent alternative computations; no independent-agent review or historical-intention inference.",
    }
Edition and provenance

CALCULATION.py

SHA-256 aa87bce17a91902e5563a16807321273713f03bebbb30afba64e0f870057ec2b

C480–C1634/Research_Cycles/C0480_Bridge/evidence/CALCULATION.py