Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .github/workflows/bpd-pinned-kernel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: BPD-LG-01 pinned Lean kernel validation
on:
push:
paths:
- 'fixtures/bpd_lean_curriculum_pinned/**'
- '.github/workflows/bpd-pinned-kernel.yml'
pull_request:
paths:
- 'fixtures/bpd_lean_curriculum_pinned/**'
- '.github/workflows/bpd-pinned-kernel.yml'
workflow_dispatch:
permissions:
contents: read
jobs:
kernel:
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Regenerate pinned BPD-LG-01 corpus and verify hashes
run: |
python - <<'PY'
import hashlib, json, subprocess
from pathlib import Path
path = Path("fixtures/bpd_lean_curriculum_pinned/generate.py")
assert hashlib.sha256(path.read_bytes()).hexdigest() == "3b474850e3aac9c6958be8c7d33ae16b2448fbf8ef6fac965d7d795fb2f830fe"
out = Path("/tmp/bpd-lg01")
subprocess.run(["python", str(path), "--out", str(out)], check=True)
m = json.loads((out/"manifest.json").read_text())
assert m["cases"] == 384
assert m["positive_templates"] == m["negative_finite_countermodels"] == 192
assert m["split_counts"] == {"train": 256, "dev": 64, "test": 64}
assert {k:m["sha256"][k] for k in ("train_positives.lean","dev_positives.lean","test_positives.lean")} == {
"train_positives.lean": "c688fc711817e33633c9065569e11cafcabfca665c29013c6b5704cec43fbdab",
"dev_positives.lean": "bb2329e9745c966e529cbf8f591276228df707c04b0f6471e291602d8ed2607f",
"test_positives.lean": "e2376bb1cef30eb78ab93dc13853b682a740bc6f3daa12560fd010fd23a8048f"
}
PY
- name: Install pinned Lean 4.19.0
run: |
curl --fail --location --retry 3 https://github.com/leanprover/lean4/releases/download/v4.19.0/lean-4.19.0-linux.tar.zst -o /tmp/lean.tar.zst
tar --zstd -xf /tmp/lean.tar.zst -C /tmp
echo '/tmp/lean-4.19.0-linux/bin' >> "$GITHUB_PATH"
- name: Kernel typecheck all positives and reject axiom dependencies
run: |
python - <<'PY'
import hashlib, json, re, subprocess
from pathlib import Path
root = Path("/tmp/bpd-lg01")
version = subprocess.check_output(["lean","--version"], text=True).strip()
assert "version 4.19.0" in version, version
receipt = {"source_repo":"MoralityLabAI/LoopedTransformers",
"source_commit":"ebdd76e3acacb5d68d4d736d6dc49417f26f166f",
"generator_sha256":"3b474850e3aac9c6958be8c7d33ae16b2448fbf8ef6fac965d7d795fb2f830fe",
"lean_version":version, "by_split":{}, "kernel_checked":0, "axiom_free":False}
try:
seen=set()
for split,count in (("train",128),("dev",32),("test",32)):
original=root/f"{split}_positives.lean"
content=original.read_text()
names=re.findall(r"^theorem (thm_bpd_[A-Za-z0-9_]+)\b",content,re.M)
assert len(names)==len(set(names))==count
assert not seen.intersection(names)
seen.update(names)
assert not re.search(r"\b(?:axiom|sorry|admit|native_decide|unsafe)\b",content)
audited=root/f"{split}_axiom_audit.lean"
audited.write_text(content+"\n"+"\n".join("#print axioms "+n for n in names)+"\n")
p=subprocess.run(["lean",str(audited)],capture_output=True,text=True,timeout=180)
(root/f"{split}_stdout.log").write_text(p.stdout)
(root/f"{split}_stderr.log").write_text(p.stderr)
if p.returncode:
raise RuntimeError(f"{split}: Lean exit {p.returncode}\n"+p.stdout[-6000:]+p.stderr[-6000:])
if p.stdout.count("does not depend on any axioms")!=count:
raise RuntimeError(f"{split}: axiom audit count mismatch\n"+p.stdout[-6000:])
receipt["by_split"][split]={"theorems":count,"axiom_free":count,
"source_sha256":hashlib.sha256(original.read_bytes()).hexdigest()}
receipt["kernel_checked"]+=count
assert receipt["kernel_checked"]==192
receipt["axiom_free"]=True
finally:
(root/"kernel_audit_receipt.json").write_text(json.dumps(receipt,sort_keys=True,indent=2)+"\n")
print("BPD-LG-01 KERNEL:",json.dumps(receipt,sort_keys=True))
PY
- name: Archive generated sources and independent kernel receipt
if: always()
uses: actions/upload-artifact@v4
with:
name: bpd-lg01-kernel-pinned-${{ github.run_id }}
path: /tmp/bpd-lg01/
retention-days: 30
if-no-files-found: warn
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ and `PYTHONPATH=src python scripts/verify_cryptomania_audit.py`.

Reviewers: see [`REVIEW.md`](REVIEW.md).

**New (BPD-01, 2026-11-15):** [interventional separation and looped Lean curriculum](paper/bpd_interventional_separation.md) formalizes routed mechanism-pair coverage, optimal fixed/adaptive probes, clock-versus-state observability floors and a recurrence-repair counterexample. Exact 512-matrix and 96 seeded audits are source-hashed in `output/evaluation_bpd/bpd_01.json`. Reproduce via `python scripts/check_receipts.py --only bpd`. It supplies design mathematics, not a neural decomposition result.

## Self-designed evaluation and FRC

The [HRC-FRC-01 extension](paper/frc_harmonic_self_evaluation.md) studies
Expand Down
156 changes: 156 additions & 0 deletions fixtures/bpd_lean_curriculum_pinned/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
"""BPD-LG-01: reproducible source-owned Lean witness/countermodel task family.

Generated source is a conjectured Lean syntax fixture until a pinned `lean`
compiler actually checks the positive theorem scripts. Negative cases are
independently witnessed by finite countermodels, never emitted as sorry.
"""
from __future__ import annotations

import argparse
import hashlib
import json
from pathlib import Path

SCHEMA = "BPD-LG-01-v1"
FAMILIES = ("exact", "rw", "rcases", "induction")
DEPTHS = (1, 2, 3, 4)
ROOTS = tuple(range(6))


def split_of(root: int) -> str:
if root in (0, 1, 2, 3):
return "train"
return "dev" if root == 4 else "test"


def mk_case(family: str, depth: int, root: int, critical: bool, nuisance: bool) -> dict:
if family not in FAMILIES or depth not in DEPTHS or root not in ROOTS:
raise ValueError("unsupported family/depth/root")
stem = f"bpd_{family}_d{depth}_r{root}_{int(critical)}_{int(nuisance)}"
name = "thm_" + stem
extra = " (noise : Nat)" if nuisance else ""
proof = None
countermodel = None
if family == "exact":
props = " ".join(f"P{i}" for i in range(depth + 1))
hyps = "" if not critical else " (h0 : P0)"
hyps += "".join(f" (h{i} : P{i-1} → P{i})" for i in range(1, depth + 1))
statement = f"theorem {name} ({props} : Prop){hyps}{extra} : P{depth} := by"
if critical:
term = "h0"
for i in range(1, depth + 1):
term = f"h{i} ({term})"
proof = " exact " + term
else:
countermodel = {"P_values": [False] * (depth + 1), "goal": False}
elif family == "rw":
a, b = "a", "b"
for _ in range(depth):
a, b = f"Nat.succ ({a})", f"Nat.succ ({b})"
hyp = " (hEq : a = b)" if critical else ""
statement = f"theorem {name} (a b : Nat){hyp}{extra} : {a} = {b} := by"
if critical:
proof = " rw [hEq]"
else:
countermodel = {"a": 0, "b": 1, "goal": False}
elif family == "rcases":
props = " ".join(f"P{i}" for i in range(depth + 1))
nested = f"P{depth}"
for j in reversed(range(depth)):
nested = f"(P{j} ∧ {nested})"
hyp = f" (h : {nested})" if critical else ""
statement = f"theorem {name} ({props} : Prop){hyp}{extra} : P{depth} := by"
if critical:
lines = []
previous = "h"
for i in range(depth):
nxt = f"tail{i}"
lines.append(f" rcases {previous} with ⟨_, {nxt}⟩")
previous = nxt
proof = "\n".join(lines + [f" exact {previous}"])
else:
countermodel = {"P_values": [False] * (depth + 1), "goal": False}
else:
fn = "fn_" + stem
initial = "0" if critical else "1"
definition = (f"private def {fn} : Nat → Nat\n"
f" | 0 => {initial}\n"
f" | n + 1 => Nat.succ ({fn} n)\n")
expr = "n"
for _ in range(depth):
expr = f"{fn} ({expr})"
statement = f"theorem {name}{extra} : ∀ n : Nat, {expr} = n := by"
if critical:
proof = (f" intro n\n induction n with\n"
f" | zero => rfl\n"
f" | succ n ih =>\n"
f" simpa only [{fn}] using congrArg Nat.succ ih")
else:
countermodel = {"n": 0, "actual_at_zero": depth, "goal": False}
statement = definition + "\n" + statement
return {
"schema": SCHEMA, "case_id": stem,
"root_id": f"{family}-d{depth}-r{root}", "split": split_of(root),
"family": family, "structural_depth": depth,
"critical": critical, "nuisance": nuisance,
"public_goal_source": statement.removesuffix(" := by"),
"lean_theorem": statement + "\n" + (proof or " -- Negative: no theorem is sent for Lean proof checking"),
"gold_proof": proof, "countermodel": countermodel,
"host_label": "positive_proof_template" if critical else "negative_countermodel",
"kernel_verified": False,
}


def roster() -> list[dict]:
return [mk_case(f, d, r, critical, nuisance)
for f in FAMILIES for d in DEPTHS for r in ROOTS
for critical in (True, False) for nuisance in (False, True)]


def check_countermodel(row: dict) -> bool:
if row["critical"]:
return row["countermodel"] is None and row["gold_proof"] is not None
w = row["countermodel"]
d = row["structural_depth"]
if row["family"] in ("exact", "rcases"):
return all(v is False for v in w["P_values"]) and w["goal"] is False
if row["family"] == "rw":
return w == {"a": 0, "b": 1, "goal": False} and (w["a"] + d != w["b"] + d)
return w == {"n": 0, "actual_at_zero": d, "goal": False} and d > 0


def export(out: Path) -> dict:
cases = roster()
out.mkdir(parents=True, exist_ok=True)
by_split = {s: [c for c in cases if c["split"] == s] for s in ("train", "dev", "test")}
for split, rows in by_split.items():
(out / f"{split}.jsonl").write_text(
"".join(json.dumps(row, sort_keys=True, ensure_ascii=False) + "\n" for row in rows))
proofs = [c["lean_theorem"] for c in rows if c["critical"]]
(out / f"{split}_positives.lean").write_text(
"/- BPD-LG-01 generated positive proof candidates; compile with Lean 4.19.0 -/\n\n"
+ "\n\n".join(proofs) + "\n")
assert all(check_countermodel(row) for row in cases)
roots = {s: {r["root_id"] for r in rows} for s, rows in by_split.items()}
assert not roots["train"] & roots["dev"] and not roots["train"] & roots["test"]
assert not roots["dev"] & roots["test"]
report = {
"schema": SCHEMA, "cases": len(cases),
"split_counts": {k: len(v) for k, v in by_split.items()},
"positive_templates": sum(c["critical"] for c in cases),
"negative_finite_countermodels": sum(not c["critical"] for c in cases),
"families": list(FAMILIES), "depths": list(DEPTHS),
"all_countermodels_verified": True,
"kernel_status": "not_run_by_export; require CI pinned Lean compiler",
"sha256": {p.name: hashlib.sha256(p.read_bytes()).hexdigest()
for p in sorted(out.glob("*.lean")) + sorted(out.glob("*.jsonl"))},
}
(out / "manifest.json").write_text(json.dumps(report, indent=2, sort_keys=True) + "\n")
return report


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--out", type=Path, required=True)
args = parser.parse_args()
print(json.dumps(export(args.out), sort_keys=True))
72 changes: 72 additions & 0 deletions output/evaluation_bpd/bpd_01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"binary_matrices": 512,
"branched_witness": {
"adaptive_cost": 2,
"batch_cost": 3
},
"checks": {
"adaptive_strict_example": true,
"all_binary_matrices_independent": true,
"clock_fibre_gap": true,
"early_repair_obscures_final": true,
"routing_collision": true,
"visible_fibre_collision": true,
"weighted_multiway_independent": true
},
"clock_witness": {
"state_clock": 0,
"state_only": 1,
"visible_only": 1
},
"evidence": "finite exact deterministic oracle; mathematical proof in paper; no neural or Lean model measurements",
"refill_witness": {
"baseline": [
1,
1,
1,
1
],
"persistent_cut_final": 0,
"single_cut_final": [
1,
1,
1,
0
],
"single_cut_trajectories": [
[
0,
1,
1,
1
],
[
1,
0,
1,
1
],
[
1,
1,
0,
1
],
[
1,
1,
1,
0
]
],
"terminal_blind_early_cuts": 3
},
"schema": "BPD-01-v1",
"source_sha256": {
"paper/bpd_interventional_separation.md": "a1738c49c47bf1efa1aa2ce177305711ce93852b8d4fef47b57d3bf2f18fd7ac",
"scripts/verify_evaluation_bpd.py": "a43cbbb642fe3b8d1283f1f4b8b91fbcebef3e50f6079f30b46f98bba54bc835",
"src/spiral_ln/evaluation_bpd.py": "9c0e1d386dd2335ab43b970e604e073c72afc3e2e4512a1f75a0cb0a1c6a8062",
"tests/test_evaluation_bpd.py": "76ba84ca0930e89ae5534a72d6688c5c80f3dc9462c1bdc924bf899a4b045412"
},
"weighted_categorical_cases": 96
}
Loading
Loading