Download verification/verification_math.py from PureOne/Lyotherin_Tia: direct link, hf CLI and curl.
- Browser
- Download file 19.9 kB
-
https://huggingface.co/datasets/PureOne/Lyotherin_Tia/resolve/main/verification/verification_math.py
- Command line
-
hf download hf://datasets/PureOne/Lyotherin_Tia/verification/verification_math.py
-
curl -L -o verification_math.py https://huggingface.co/datasets/PureOne/Lyotherin_Tia/resolve/main/verification/verification_math.py
19.9 kB
| #!/usr/bin/env python3 | |
| """Exact, finite mathematical checks for Lyotherin_Tia. | |
| This file checks declared algebra and tiny finite coding problems. It is not a | |
| game adapter, timing benchmark, floating-point equivalence proof, or test of | |
| NVIDIA software. Only Python's standard library is used. All algebra uses | |
| fractions.Fraction; the seed and counts are deliberately modest and explicit. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import itertools | |
| import json | |
| import random | |
| from dataclasses import dataclass | |
| from fractions import Fraction as F | |
| from pathlib import Path | |
| SEED = 20261030 | |
| def fq(rng: random.Random, lo: int = -6, hi: int = 6) -> F: | |
| return F(rng.randint(lo, hi), rng.randint(1, 5)) | |
| def clip(x: F, lo: F, hi: F) -> F: | |
| assert lo <= hi | |
| return min(hi, max(lo, x)) | |
| class ClampAffine: | |
| a: F | |
| b: F | |
| lo: F | |
| hi: F | |
| def __post_init__(self) -> None: | |
| assert self.a >= 0 and self.lo <= self.hi | |
| def __call__(self, x: F) -> F: | |
| return clip(self.a * x + self.b, self.lo, self.hi) | |
| def compose(outer: ClampAffine, inner: ClampAffine) -> ClampAffine: | |
| """Return outer o inner in the same four-parameter family.""" | |
| return ClampAffine( | |
| outer.a * inner.a, | |
| outer.a * inner.b + outer.b, | |
| outer(inner.lo), | |
| outer(inner.hi), | |
| ) | |
| def random_clamp(rng: random.Random) -> ClampAffine: | |
| bounds = sorted((fq(rng), fq(rng))) | |
| return ClampAffine(F(rng.randint(0, 8), rng.randint(1, 5)), fq(rng), *bounds) | |
| def check_clamps(rng: random.Random) -> dict: | |
| examples = [ | |
| (ClampAffine(F(0), F(2), F(-1), F(1)), | |
| ClampAffine(F(3), F(-1), F(-2), F(2))), | |
| (ClampAffine(F(2), F(-1), F(0), F(0)), | |
| ClampAffine(F(0), F(7), F(0), F(3))), | |
| (ClampAffine(F(1), F(0), F(-10), F(10)), | |
| ClampAffine(F(2), F(1), F(-1), F(1))), | |
| ] | |
| examples.extend((random_clamp(rng), random_clamp(rng)) for _ in range(60)) | |
| query_points = [F(i, 5) for i in range(-10, 11)] | |
| for outer, inner in examples: | |
| merged = compose(outer, inner) | |
| for x in query_points: | |
| assert merged(x) == outer(inner(x)) | |
| word_lengths = [] | |
| word_queries = [F(i, 3) for i in range(-6, 7)] | |
| for _ in range(24): | |
| word = [random_clamp(rng) for _ in range(rng.randint(1, 12))] | |
| word_lengths.append(len(word)) | |
| merged = word[0] | |
| for fn in word[1:]: | |
| merged = compose(fn, merged) | |
| for x in word_queries: | |
| actual = x | |
| for fn in word: | |
| actual = fn(actual) | |
| assert merged(x) == actual | |
| # Aggregating only input deltas loses irreversible saturation information. | |
| x, u, v = F(9, 10), F(1, 5), F(-1, 5) | |
| sequential = clip(clip(x + u, F(0), F(1)) + v, F(0), F(1)) | |
| total_only = clip(x + u + v, F(0), F(1)) | |
| assert sequential == F(4, 5) and total_only == F(9, 10) | |
| return { | |
| "status": "passed", | |
| "composition_pairs": len(examples), | |
| "query_points_per_pair": len(query_points), | |
| "random_words": len(word_lengths), | |
| "word_lengths": word_lengths, | |
| "query_points_per_word": len(word_queries), | |
| "saturation_counterexample": { | |
| "initial": str(x), "deltas": [str(u), str(v)], | |
| "sequential": str(sequential), "sum_only": str(total_only), | |
| }, | |
| "assumptions": [ | |
| "Each slope is nonnegative; bounds are finite and ordered.", | |
| "These are exact rational identities, not bit-exact float claims.", | |
| "Constant parameter count does not bound integer bit complexity.", | |
| ], | |
| } | |
| def check_transport(rng: random.Random) -> dict: | |
| for _ in range(100): | |
| x, k, d, u = (fq(rng) for _ in range(4)) | |
| assert k * (x + u) + d == (k * x + d) + k * u | |
| lengths = [] | |
| for _ in range(48): | |
| x = fq(rng) | |
| full = x | |
| K, D, delta = F(1), F(0), F(0) | |
| length = rng.randint(5, 30) | |
| lengths.append(length) | |
| for _ in range(length): | |
| if rng.randrange(2): | |
| k, d = fq(rng), fq(rng) | |
| full = k * full + d | |
| K, D, delta = k * K, k * D + d, k * delta | |
| else: | |
| u = fq(rng) | |
| full += u | |
| delta += u | |
| assert full == K * x + D + delta | |
| return { | |
| "status": "passed", "one_step_identities": 100, | |
| "interleaved_words": len(lengths), "word_lengths": lengths, | |
| "prefix_equalities": sum(lengths), | |
| "identity": "B o A_u = A_(k*u) o B, B(x)=k*x+d", | |
| "recurrence": "On B: (K,D,delta)<-(k*K,k*D+d,k*delta); on A_u: delta<-delta+u", | |
| "assumptions": [ | |
| "Only the declared affine/translation dynamics are represented.", | |
| "Every input is consumed exactly once in its declared order.", | |
| "No hidden collision, branch, rounding or unobserved world update is inferred.", | |
| ], | |
| } | |
| def matvec(matrix: list[list[F]], vector: list[F]) -> list[F]: | |
| return [sum((x * y for x, y in zip(row, vector)), F(0)) for row in matrix] | |
| def rank(matrix: list[list[F]]) -> int: | |
| if not matrix: | |
| return 0 | |
| a = [row[:] for row in matrix] | |
| m, n = len(a), len(a[0]) | |
| pivot_row = 0 | |
| for col in range(n): | |
| pivot = next((r for r in range(pivot_row, m) if a[r][col]), None) | |
| if pivot is None: | |
| continue | |
| a[pivot_row], a[pivot] = a[pivot], a[pivot_row] | |
| scale = a[pivot_row][col] | |
| a[pivot_row] = [v / scale for v in a[pivot_row]] | |
| for row in range(m): | |
| if row != pivot_row and a[row][col]: | |
| scale = a[row][col] | |
| a[row] = [v - scale * w for v, w in zip(a[row], a[pivot_row])] | |
| pivot_row += 1 | |
| if pivot_row == m: | |
| break | |
| return pivot_row | |
| def temporal_rows(weights: list[F], shift: int) -> list[list[F]]: | |
| n = len(weights) | |
| rows = [] | |
| for p, weight in enumerate(weights): | |
| row = [F(0)] * (2 * n) | |
| row[(p + shift) % n] = weight | |
| row[n + p] = 1 - weight | |
| rows.append(row) | |
| return rows | |
| def check_history(rng: random.Random) -> dict: | |
| # Arbitrary global RGB grade, fixed target history and premultiplied HUD. | |
| # Bilinear two-source mixing is just an explicit source sample here. | |
| for _ in range(80): | |
| source = [[fq(rng) for _ in range(3)] for _ in range(2)] | |
| grade = [[fq(rng) for _ in range(3)] for _ in range(3)] | |
| bias = [fq(rng) for _ in range(3)] | |
| for p in range(2): | |
| blend, hud_alpha, interp = (F(rng.randint(0, 8), 8) for _ in range(3)) | |
| history, hud = [fq(rng) for _ in range(3)], [fq(rng) for _ in range(3)] | |
| z = [(1 - interp) * source[p][j] + interp * source[1-p][j] | |
| for j in range(3)] | |
| next_history = [blend * z[j] + (1-blend) * history[j] for j in range(3)] | |
| transformed = matvec(grade, next_history) | |
| direct = [hud[j] + (1-hud_alpha) * (transformed[j] + bias[j]) | |
| for j in range(3)] | |
| k = (1-hud_alpha) * blend | |
| retained_history = [(1-blend) * v for v in history] | |
| early = matvec(grade, retained_history) | |
| b = [hud[j] + (1-hud_alpha) * (early[j] + bias[j]) for j in range(3)] | |
| mz = matvec(grade, z) | |
| compact = [k * mz[j] + b[j] for j in range(3)] | |
| assert direct == compact | |
| # The visible-only formula alone does not reconstruct next history. | |
| assert next_history == [blend * z[j] + retained_history[j] for j in range(3)] | |
| weights_grid = [F(0), F(1, 4), F(1, 2), F(3, 4), F(1)] | |
| two_pixel_rank_results = [] | |
| for a0, a1 in itertools.product(weights_grid, repeat=2): | |
| weights = [a0, a1] | |
| C, R = temporal_rows(weights, 0), temporal_rows(weights, 1) | |
| extra = rank(C + R) - rank(C) | |
| assert extra in (0, 1) | |
| if F(0) < a0 < F(1) and F(0) < a1 < F(1): | |
| assert extra == 1 | |
| c0, c1, h0, h1 = (fq(rng) for _ in range(4)) | |
| u = [c0, c1, h0, h1] | |
| cached, required = matvec(C, u), matvec(R, u) | |
| delta = c1 - c0 | |
| decoded = [cached[0] + a0 * delta, cached[1] - a1 * delta] | |
| assert decoded == required | |
| two_pixel_rank_results.append({"a0": str(a0), "a1": str(a1), "extra_rank": extra}) | |
| cyclic_results = [] | |
| for n in range(2, 7): | |
| for a in (F(1, 4), F(1, 2), F(3, 4)): | |
| C = temporal_rows([a] * n, 0) | |
| all_rows = [row for shift in range(n) for row in temporal_rows([a] * n, shift)] | |
| extra = rank(C + all_rows) - rank(C) | |
| assert extra == n - 1 | |
| cyclic_results.append({"n": n, "weight": str(a), "cache_rank": rank(C), | |
| "joint_rank": rank(C + all_rows), "extra_rank": extra}) | |
| return { | |
| "status": "passed", "rgb_configurations": 80, "pixels_per_configuration": 2, | |
| "two_pixel_rank_cases": two_pixel_rank_results, | |
| "cyclic_rank_cases": cyclic_results, | |
| "two_pixel_decoder": "delta=c1-c0; shifted=(cached0+a0*delta,cached1-a1*delta)", | |
| "assumptions": [ | |
| "Linear RGB and the stated blend/grade/HUD order; no nonlinear tone mapping.", | |
| "HUD, target history, blend weights and grade are independent of admitted late input.", | |
| "The source samples are supplied; geometry/occlusion validity is not inferred.", | |
| "A candidate history is a value only; no canonical history is committed here.", | |
| "The cyclic-rank example is scalar; independent RGB gives three copies.", | |
| ], | |
| } | |
| def partitions(n: int): | |
| """Enumerate canonical set partitions as restricted-growth label tuples.""" | |
| if n == 0: | |
| yield () | |
| return | |
| def visit(labels, largest): | |
| if len(labels) == n: | |
| yield tuple(labels) | |
| return | |
| for color in range(largest + 2): | |
| labels.append(color) | |
| yield from visit(labels, max(largest, color)) | |
| labels.pop() | |
| yield from visit([0], 0) | |
| def conflict_graph(cache, image, transition_record, eps): | |
| """Record equality includes successor, outcome, status and side effects. | |
| A hashable integer may be a shorthand label for a full exact transition | |
| record. Equal successor classes alone do not imply equal records. | |
| """ | |
| n, queries = len(cache), len(image[0]) | |
| adjacency = [set() for _ in range(n)] | |
| for i in range(n): | |
| for j in range(i + 1, n): | |
| if cache[i] != cache[j]: | |
| continue | |
| conflict = any( | |
| transition_record[i][q] != transition_record[j][q] | |
| or any(abs(a-b) > 2*eps for a, b in zip(image[i][q], image[j][q])) | |
| for q in range(queries) | |
| ) | |
| if conflict: | |
| adjacency[i].add(j) | |
| adjacency[j].add(i) | |
| return adjacency | |
| def direct_decoder(labels, cache, image, transition_record, eps): | |
| """Test image boxes and full exact-record agreement without a graph.""" | |
| result = {} | |
| for known_cache, label in set(zip(cache, labels)): | |
| members = [i for i in range(len(cache)) if (cache[i], labels[i]) == (known_cache, label)] | |
| for q in range(len(image[0])): | |
| targets = {transition_record[i][q] for i in members} | |
| if len(targets) != 1: | |
| return None | |
| decoded = [] | |
| for coordinate in range(len(image[0][q])): | |
| values = [image[i][q][coordinate] for i in members] | |
| # Independently intersect every admissible interval. | |
| lower = max(v - eps for v in values) | |
| upper = min(v + eps for v in values) | |
| if lower > upper: | |
| return None | |
| decoded.append((min(values) + max(values)) / 2) | |
| result[(known_cache, label, q)] = (decoded, next(iter(targets))) | |
| return result | |
| def chromatic_number(adjacency): | |
| n = len(adjacency) | |
| order = sorted(range(n), key=lambda v: (-len(adjacency[v]), v)) | |
| for limit in range(1, n + 1): | |
| colors = [-1] * n | |
| def solve(at): | |
| if at == n: | |
| return True | |
| vertex = order[at] | |
| forbidden = {colors[w] for w in adjacency[vertex] if colors[w] >= 0} | |
| for color in range(limit): | |
| if color not in forbidden: | |
| colors[vertex] = color | |
| if solve(at + 1): | |
| return True | |
| colors[vertex] = -1 | |
| return False | |
| if solve(0): | |
| return limit, tuple(colors) | |
| raise AssertionError("Finite graph must admit singleton coloring") | |
| def check_code_instance(name, cache, image, transition_record, eps): | |
| adjacency = conflict_graph(cache, image, transition_record, eps) | |
| graph_min, graph_labels = chromatic_number(adjacency) | |
| direct_min, tested, valid = len(cache) + 1, 0, 0 | |
| for labels in partitions(len(cache)): | |
| tested += 1 | |
| decoder = direct_decoder(labels, cache, image, transition_record, eps) | |
| proper = all(labels[i] != labels[j] for i in range(len(cache)) for j in adjacency[i]) | |
| assert proper == (decoder is not None) | |
| if decoder is not None: | |
| valid += 1 | |
| direct_min = min(direct_min, max(labels) + 1) | |
| assert direct_min == graph_min | |
| decoder = direct_decoder(graph_labels, cache, image, transition_record, eps) | |
| assert decoder is not None | |
| for i in range(len(cache)): | |
| for q in range(len(image[0])): | |
| output, exact_record = decoder[(cache[i], graph_labels[i], q)] | |
| assert exact_record == transition_record[i][q] | |
| assert all(abs(a-b) <= eps for a, b in zip(output, image[i][q])) | |
| return { | |
| "name": name, "states": len(cache), "queries": len(image[0]), | |
| "image_coordinates": len(image[0][0]), "epsilon": str(eps), | |
| "partitions_examined": tested, "valid_partitions": valid, | |
| "minimum_code_alphabet": direct_min, "chromatic_number": graph_min, | |
| "edges": [[i,j] for i in range(len(cache)) for j in sorted(adjacency[i]) if i < j], | |
| } | |
| def check_mixed_coding(rng: random.Random) -> dict: | |
| cases = [] | |
| for n in range(1, 7): | |
| for trial in range(5): | |
| query_count = 1 + trial % 3 | |
| cache = [rng.randrange(1 + trial % 2) for _ in range(n)] | |
| eps = (F(0), F(1, 4), F(1, 2), F(1), F(3, 2))[trial] | |
| image = [[[F(rng.randint(-3, 3), 2) for _ in range(2)] | |
| for _ in range(query_count)] for _ in range(n)] | |
| # Integers abbreviate full exact transition records. Include | |
| # both identical records and per-query differing records. | |
| transition_record = [[0 if trial % 2 == 0 else rng.randrange(2) | |
| for _ in range(query_count)] for _ in range(n)] | |
| cases.append(check_code_instance(f"random_n{n}_case{trial}", cache, image, transition_record, eps)) | |
| # An induced C5: each edge gets a coordinate with its endpoints +1 and -1. | |
| # Adjacent vertices differ by 2, nonadjacent ones by at most 1. | |
| edges = [(i, (i + 1) % 5) for i in range(5)] | |
| image = [[[F(1) if i == a else F(-1) if i == b else F(0) | |
| for a, b in edges]] for i in range(5)] | |
| c5 = check_code_instance("five_cycle", [0]*5, image, [[0]]*5, F(1,2)) | |
| assert c5["chromatic_number"] == 3 | |
| cases.append(c5) | |
| exact_continuation = check_code_instance( | |
| "same_image_distinct_successor", [0,0], [[[F(0)]],[[F(0)]]], [[0],[1]], F(1)) | |
| assert exact_continuation["chromatic_number"] == 2 | |
| cases.append(exact_continuation) | |
| # A shared future state does not erase required immediate nonvisual output. | |
| # Tuple order: (successor class, authoritative outcome, status, effects). | |
| record0 = (0, "pulse_committed", "accepted", ("emit_pulse",)) | |
| record1 = (0, "pulse_blocked", "rejected", ()) | |
| assert record0[0] == record1[0] and record0 != record1 | |
| distinct_effects = check_code_instance( | |
| "same_image_same_successor_distinct_immediate_effect_status", [0,0], | |
| [[[F(0)]],[[F(0)]]], [[record0],[record1]], F(1)) | |
| assert distinct_effects["chromatic_number"] == 2 | |
| distinct_effects["same_successor_class"] = True | |
| distinct_effects["exact_transition_records"] = [record0, record1] | |
| cases.append(distinct_effects) | |
| cache_reuse = check_code_instance( | |
| "reuse_labels_across_cache_fibers", [0,0,1,1], | |
| [[[F(0)]],[[F(3)]],[[F(0)]],[[F(3)]]], [[0],[0],[0],[0]], F(1)) | |
| assert cache_reuse["chromatic_number"] == 2 | |
| cases.append(cache_reuse) | |
| # Pairwise distance <= 2 epsilon is not enough for arbitrary norms. | |
| # In L2, unit balls at (0,0),(2,0) meet only at (1,0), which is 3/2 | |
| # from the third center (1,3/2). Every pair of centers is <= 2 apart. | |
| triangle = [(F(0),F(0)),(F(2),F(0)),(F(1),F(3,2))] | |
| distances_squared = [sum((x-y)**2 for x,y in zip(a,b)) | |
| for a,b in itertools.combinations(triangle,2)] | |
| assert max(distances_squared) <= 4 | |
| assert (F(3,2))**2 > 1 | |
| return { | |
| "status": "passed", "instances": cases, | |
| "total_instances": len(cases), | |
| "total_partitions_examined": sum(c["partitions_examined"] for c in cases), | |
| "l2_counterexample_squared_pair_distances": [str(x) for x in distances_squared], | |
| "assumptions": [ | |
| "Finite state/cache/query sets with every listed query admissible for every listed state.", | |
| "The encoder sees state; decoder sees exact cache value, query and code label.", | |
| "Approximate image error uses an L-infinity ball, coordinate by coordinate.", | |
| "Exact transition records include successor continuation class, immediate authoritative outcomes, accept/reject status and required side-effect records.", | |
| "Generic integer labels abbreviate full exact transition records; successor classes require independent semantic certification and realization.", | |
| "Tests check the specified one-step decoder; they do not prove online approximate stability.", | |
| "Palette reuse across different cache fibers is permitted because the cache is decoder side information.", | |
| "No practical encoding or decoding time bound follows from chromatic minimality.", | |
| ], | |
| } | |
| def main() -> None: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--output", type=Path, default=Path(__file__).with_name("verification_math_results.json")) | |
| args = parser.parse_args() | |
| rng = random.Random(SEED) | |
| result = { | |
| "project": "Lyotherin_Tia", "seed": SEED, | |
| "arithmetic": "Python standard-library fractions.Fraction", | |
| "evidence_type": "finite exact algebra and combinatorial sanity checks; not hardware measurement or formal proof assistant output", | |
| "clamped_affine": check_clamps(rng), | |
| "transported_translation": check_transport(rng), | |
| "history_compaction": check_history(rng), | |
| "mixed_image_exact_continuation": check_mixed_coding(rng), | |
| "overall_status": "passed", | |
| } | |
| args.output.write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8") | |
| print(json.dumps({"overall_status": result["overall_status"], "output": str(args.output), | |
| "clamp_pairs": result["clamped_affine"]["composition_pairs"], | |
| "interleaved_words": result["transported_translation"]["interleaved_words"], | |
| "rgb_configurations": result["history_compaction"]["rgb_configurations"], | |
| "finite_coding_instances": result["mixed_image_exact_continuation"]["total_instances"], | |
| "finite_partitions": result["mixed_image_exact_continuation"]["total_partitions_examined"]})) | |
| if __name__ == "__main__": | |
| main() | |