interplane.Get Omega
Read in your language

aien-train

AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.

Brought by drakestapleton

branch main Branches Tags History

aien-train / evidence / COLLECTIVE-P0-ADMIT / lean / AdmitP0Bound.lean

115 lines · 5167 bytes Raw Blame History
1/-
2DRA-15 / aien-train#26 P0 admission (Spark hive card t_8cf72aaf).
3Safety invariant behind the out_of_range guard (-15) of
4native/collective/admit_p0.om: once admission returned 0, no intermediate
5of the response computation leaves signed 64-bit range, so the checked
6arithmetic of the seeded compiler (trap 1) can never fire on an admitted job.
7
8Model (hand-copied from admit_p0.om at this commit; checked by reading):
9 VMAX = 65536 (const VMAX), active budget <= 3 (const KMAX, guard -11);
10 fn bxrow : s := 0; s := s + B[r,c] * x[c] for c = 0,1,2;
11 fn vdot : dot := 0; dot := dot + V[c] * x[c] for c = 0,1,2;
12 fn compute, per planned slot j < k: f := phase * dot; d := f * U[r];
13 acc[r] := acc[r] + d, starting from acc[r] = bxrow r;
14 phase in {1, -1} (guard -3); every entry of x, B and of the planned
15 candidates' U, V in [-VMAX, VMAX] (guard -15).
16Wolfram: 3 * 65536^2 + 9 * 65536^3 = 2533287675297792 < 2^63 - 1.
17-/
18import Mathlib.Tactic
19
20namespace AdmitP0
21
22def M : ℤ := 65536
23def fits64 (v : ℤ) : Prop := -(2:ℤ)^63 ≤ v ∧ v ≤ (2:ℤ)^63 - 1
24/-- ceiling on every intermediate: 3 M^2 + 9 M^3 -/
25def C : ℤ := 3 * M^2 + 9 * M^3
26
27lemma mulb {a b A B : ℤ} (ha : |a| ≤ A) (hb : |b| ≤ B) : |a * b| ≤ A * B := by
28 rw [abs_mul]
29 exact mul_le_mul ha hb (abs_nonneg _) ((abs_nonneg _).trans ha)
30
31lemma addb {a b A B : ℤ} (ha : |a| ≤ A) (hb : |b| ≤ B) : |a + b| ≤ A + B :=
32 (abs_add_le a b).trans (add_le_add ha hb)
33
34lemma fitsC {v : ℤ} (h : |v| ≤ C) : fits64 v := by
35 have hC : C = 2533287675297792 := by norm_num [C, M]
36 rw [hC, abs_le] at h
37 unfold fits64
38 constructor <;> norm_num <;> linarith [h.1, h.2]
39
40/-- bxrow and vdot: every prefix sum of a 3-term dot product fits, and the
41 full sum is at most 3 M^2 in magnitude. -/
42theorem dot3 (a b : Fin 3 → ℤ) (ha : ∀ i, |a i| ≤ M) (hb : ∀ i, |b i| ≤ M) :
43 fits64 (a 0 * b 0) ∧ fits64 (a 0 * b 0 + a 1 * b 1) ∧
44 fits64 (a 0 * b 0 + a 1 * b 1 + a 2 * b 2) ∧
45 |a 0 * b 0 + a 1 * b 1 + a 2 * b 2| ≤ 3 * M^2 := by
46 have t : ∀ i, |a i * b i| ≤ M * M := fun i => mulb (ha i) (hb i)
47 have h1 := t 0
48 have h2 := addb (t 0) (t 1)
49 have h3 := addb h2 (t 2)
50 have hM : M * M = 4294967296 := by norm_num [M]
51 have hC : C = 2533287675297792 := by norm_num [C, M]
52 refine ⟨fitsC ?_, fitsC ?_, fitsC ?_, ?_⟩
53 · rw [hC]; linarith
54 · rw [hC]; linarith
55 · rw [hC]; linarith
56 · have : (3:ℤ) * M^2 = 12884901888 := by norm_num [M]
57 rw [this]; linarith
58
59/-- One planned adapter slot j < 3 of compute preserves the invariant
60 |acc| <= 3 M^2 + j * 3 M^3, and every value it forms fits. -/
61theorem step (acc : ℤ) (j : ℕ) (hj : j < 3)
62 (hacc : |acc| ≤ 3 * M^2 + (j : ℤ) * (3 * M^3))
63 (v x : Fin 3 → ℤ) (u ph : ℤ) (hv : ∀ i, |v i| ≤ M) (hx : ∀ i, |x i| ≤ M)
64 (hu : |u| ≤ M) (hph : ph = 1 ∨ ph = -1) :
65 fits64 (ph * (v 0 * x 0 + v 1 * x 1 + v 2 * x 2)) ∧
66 fits64 (ph * (v 0 * x 0 + v 1 * x 1 + v 2 * x 2) * u) ∧
67 fits64 (acc + ph * (v 0 * x 0 + v 1 * x 1 + v 2 * x 2) * u) ∧
68 |acc + ph * (v 0 * x 0 + v 1 * x 1 + v 2 * x 2) * u| ≤
69 3 * M^2 + ((j : ℤ) + 1) * (3 * M^3) := by
70 obtain ⟨-, -, -, hd⟩ := dot3 v x hv hx
71 have hp : |ph| ≤ 1 := by rcases hph with h | h <;> simp [h]
72 have hf : |ph * (v 0 * x 0 + v 1 * x 1 + v 2 * x 2)| ≤ 1 * (3 * M^2) := mulb hp hd
73 have hdd : |ph * (v 0 * x 0 + v 1 * x 1 + v 2 * x 2) * u| ≤ 1 * (3 * M^2) * M := mulb hf hu
74 have hj' : (j : ℤ) ≤ 2 := by omega
75 have hC : C = 2533287675297792 := by norm_num [C, M]
76 have e2 : (3:ℤ) * M^2 = 12884901888 := by norm_num [M]
77 have e3 : (3:ℤ) * M^3 = 844424930131968 := by norm_num [M]
78 have e1 : (1:ℤ) * (3 * M^2) * M = 844424930131968 := by norm_num [M]
79 rw [e2, e3] at hacc
80 rw [e2] at hf
81 rw [e1] at hdd
82 have hs := addb hacc hdd
83 refine ⟨fitsC ?_, fitsC ?_, fitsC ?_, ?_⟩
84 · rw [hC]; linarith
85 · rw [hC]; linarith
86 · rw [hC]; nlinarith
87 · rw [e2, e3]; nlinarith
88
89/-- Initial state: acc = bxrow r satisfies the invariant with j = 0. -/
90theorem init (b x : Fin 3 → ℤ) (hb : ∀ i, |b i| ≤ M) (hx : ∀ i, |x i| ≤ M) :
91 |b 0 * x 0 + b 1 * x 1 + b 2 * x 2| ≤ 3 * M^2 + ((0:ℕ) : ℤ) * (3 * M^3) := by
92 obtain ⟨-, -, -, h⟩ := dot3 b x hb hx
93 simpa using h
94
95/-- The ceiling itself fits; this is where the budget KMAX = 3 is used. -/
96theorem ceiling_fits : C ≤ (2:ℤ)^63 - 1 := by norm_num [C, M]
97
98/-- Negative control 1: with a range bound of 2^20 instead of 2^16 the same
99 ceiling no longer fits, so the guard's constant is load-bearing. -/
100theorem looser_bound_overflows : ¬ (3 * ((2:ℤ)^20)^2 + 9 * ((2:ℤ)^20)^3 ≤ (2:ℤ)^63 - 1) := by
101 norm_num
102
103/-- Negative control 2: the ceiling is attained (all entries M, phases +1,
104 three adapters), so it is not slack: y = 3 M^2 + 3 * (3 M^2) * M. -/
105theorem ceiling_attained : 3 * M * M + 3 * ((M * M + M * M + M * M) * M) = C := by
106 norm_num [C, M]
107
108end AdmitP0
109
110#print axioms AdmitP0.dot3
111#print axioms AdmitP0.step
112#print axioms AdmitP0.init
113#print axioms AdmitP0.ceiling_fits
114#print axioms AdmitP0.looser_bound_overflows
115#print axioms AdmitP0.ceiling_attained