Datasets:
Formats:
csv
Languages:
English
Size:
< 1K
Tags:
recursive-self-improvement
meta-learning
learned-optimizers
homological-algebra
formal-methods
synthetic-data
Download src/verify_pair.py from PureOne/Nemoriu-Research: direct link, hf CLI and curl.
- Browser
- Download file 5.24 kB
-
https://huggingface.co/datasets/PureOne/Nemoriu-Research/resolve/main/src/verify_pair.py
- Command line
-
hf download hf://datasets/PureOne/Nemoriu-Research/src/verify_pair.py
-
curl -L -o verify_pair.py https://huggingface.co/datasets/PureOne/Nemoriu-Research/resolve/main/src/verify_pair.py
5.24 kB
| """Exact finite counterexample: cheaper repair need not be a better improver. | |
| Python 3.10+, standard library only. Run from the research directory: | |
| python3 src/verify_pair.py --out results/pair_counterexample.json | |
| Enumerates every degree -1 singleton proposal and every matrix-unit input to | |
| the pair's higher-homotopy identity. No sampled trials or floating-point algebra. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| from fractions import Fraction | |
| import json | |
| from pathlib import Path | |
| from core import (Meter, Problem, add, differential, K, mul, nnz, positions, | |
| repaired_candidate, valid) | |
| def example(): | |
| names = ("x", "u", "b", "c", "v", "y", "w") | |
| x, u, b, c, v, y, w = range(7) | |
| d = [0] * 7 | |
| d[b] = 1 << x | |
| d[y] = 1 << c | |
| h0 = [0] * 7 | |
| h0[x] = 1 << b | |
| h0[c] = 1 << y | |
| h1 = [0] * 7 | |
| h1[x] = (1 << b) | (1 << c) | |
| h1[c] = 1 << y | |
| h1[b] = 1 << y | |
| Q = tuple(1 << j if j in (u, v, w) else 0 for j in range(7)) | |
| P = tuple((1 << j) ^ Q[j] for j in range(7)) | |
| problem = Problem(tuple(d), Q, P, tuple(h0), (0, 0, 1, 1, 1, 2, 2)) | |
| return problem, tuple(h0), tuple(h1), names | |
| def verify(): | |
| p, work, generator, names = example() | |
| assert valid(p, work, Meter()) | |
| assert valid(p, generator, Meter()) | |
| # B = w*g; partial B = g-w (minus equals plus over GF(2)). | |
| B = mul(work, generator, Meter()) | |
| assert differential(p, B, Meter()) == add(generator, work, Meter()) | |
| def L(f): | |
| m = Meter() | |
| return add(mul(B, f, m), mul(mul(p.Q, f, m), B, m), m) | |
| verified_units = 0 | |
| for i in range(p.n): | |
| for j in range(p.n): | |
| f = [0] * p.n | |
| f[i] = 1 << j | |
| f = tuple(f) | |
| m = Meter() | |
| lhs = add(K(p, generator, f, m), K(p, work, f, m), m) | |
| rhs = add(differential(p, L(f), m), L(differential(p, f, m)), m) | |
| assert lhs == rhs | |
| verified_units += 1 | |
| available = positions(p, -1, Meter()) | |
| records = [] | |
| for label, gen in (("sparse_h0", work), ("denser_h1", generator)): | |
| trials = [] | |
| for i, j in available: | |
| a = [0] * p.n | |
| a[i] = 1 << j | |
| meter = Meter() | |
| child = repaired_candidate(p, generator, gen, tuple(a), meter) | |
| is_valid = valid(p, child, meter) | |
| score = nnz(child, meter) | |
| success = child == work | |
| assert is_valid | |
| assert success or child == generator | |
| trials.append({"proposal": f"{names[j]}->{names[i]}", | |
| "success": success, "valid": is_valid, | |
| "child_nnz": score, | |
| "candidate_check_score_work": meter.used}) | |
| successes = sum(t["success"] for t in trials) | |
| probability = Fraction(successes, len(trials)) | |
| mean_cost = Fraction(sum(t["candidate_check_score_work"] | |
| for t in trials), len(trials)) | |
| proposal_cost = p.n + 7 | |
| records.append({ | |
| "generator": label, | |
| "generator_nnz": nnz(gen, Meter()), | |
| "successes": successes, | |
| "proposal_count": len(trials), | |
| "success_probability_exact": str(probability), | |
| "mean_candidate_check_score_work_exact": str(mean_cost), | |
| "expected_discovery_work_excluding_setup_and_proposal_exact": | |
| str(mean_cost / probability), | |
| "common_proposal_cost": proposal_cost, | |
| "expected_discovery_work_including_proposal_excluding_setup_exact": | |
| str((mean_cost + proposal_cost) / probability), | |
| "trials": trials, | |
| }) | |
| assert records[0]["successes"] == 1 | |
| assert records[1]["successes"] == 2 | |
| return { | |
| "field": "GF(2)", "dimension": p.n, "names": names, | |
| "grades": p.grades, | |
| "scope": "exact finite counterexample, not a broad benchmark", | |
| "fixed_child": "h1", | |
| "pair_witness_nonzero_entries": ["y->x"], | |
| "pair_witness_orientation": "B = work * generator; partial B = generator - work", | |
| "pair_witness_verified": True, | |
| "higher_homotopy_basis_checks": verified_units, | |
| "cost_warning": "Expected work excludes discovery/selection of the " | |
| "generator and one-time setup. Meter costs are not " | |
| "hardware timings. All parent/pair costs must be " | |
| "charged in a comparative RSI experiment.", | |
| "results": records, | |
| } | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--out", default="results/pair_counterexample.json") | |
| args = parser.parse_args() | |
| result = verify() | |
| out = Path(args.out) | |
| out.parent.mkdir(parents=True, exist_ok=True) | |
| out.write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8") | |
| print(json.dumps({"output": str(out), "pair_witness_verified": True, | |
| "higher_homotopy_basis_checks": | |
| result["higher_homotopy_basis_checks"], | |
| "success_probabilities": | |
| [r["success_probability_exact"] | |
| for r in result["results"]]}, indent=2)) | |