gdp-wired 0.50.6 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/core/accel-refute.d.ts +53 -0
- package/dist/core/accel-refute.js +997 -0
- package/dist/core/cli.d.ts +2 -0
- package/dist/core/cli.js +8 -1
- package/dist/core/cycles.d.ts +2 -0
- package/dist/core/cycles.js +12 -9
- package/dist/core/dsl.d.ts +11 -2
- package/dist/core/dsl.js +194 -29
- package/dist/core/fixed-division.d.ts +9 -0
- package/dist/core/fixed-division.js +87 -0
- package/dist/core/fixed-integers.d.ts +33 -0
- package/dist/core/fixed-integers.js +279 -0
- package/dist/core/live-support.d.ts +5 -0
- package/dist/core/live-support.js +148 -0
- package/dist/core/live.js +194 -37
- package/dist/core/lockstep.d.ts +5 -0
- package/dist/core/lockstep.js +23 -0
- package/dist/core/machine.d.ts +1 -0
- package/dist/core/machine.js +33 -3
- package/dist/core/ordered-pair-seeds.d.ts +2 -0
- package/dist/core/ordered-pair-seeds.js +109 -0
- package/dist/core/proof-output.d.ts +38 -1
- package/dist/core/proof-output.js +38 -0
- package/dist/core/search-termination.d.ts +4 -0
- package/dist/core/search-termination.js +1 -1
- package/dist/core/source-check.d.ts +4 -1
- package/dist/core/source-check.js +5 -2
- package/dist/core/sparse-kind-proof.d.ts +7 -0
- package/dist/core/sparse-kind-proof.js +49 -0
- package/dist/core/step-seeds.d.ts +46 -0
- package/dist/core/step-seeds.js +316 -0
- package/dist/kernel/integer-primitives.d.ts +38 -0
- package/dist/kernel/integer-primitives.js +179 -0
- package/dist/kernel/kernel.d.ts +1 -0
- package/dist/kernel/kernel.js +44 -5
- package/dist/kernel/prove.js +13 -0
- package/dist/kernel/word-division-cuts.d.ts +6 -0
- package/dist/kernel/word-division-cuts.js +69 -0
- package/dist/kernel/word-division.d.ts +12 -0
- package/dist/kernel/word-division.js +167 -0
- package/dist/lean-kernel/Cert.lean +222 -0
- package/dist/lean-kernel/Count.lean +1568 -0
- package/dist/lean-kernel/Ghost.lean +373 -0
- package/dist/lean-kernel/GhostMap.lean +426 -0
- package/dist/lean-kernel/Kernel.lean +2881 -0
- package/dist/lean-kernel/Live.lean +1168 -0
- package/dist/lean-kernel/Progress.lean +543 -0
- package/dist/lean-kernel/Sets.lean +1975 -0
- package/dist/lean-kernel/StepLaw.lean +128 -0
- package/dist/lean-kernel/Steps.lean +477 -0
- package/dist/lean-kernel/Sums.lean +916 -0
- package/dist/lean-kernel/emit.d.ts +8 -1
- package/dist/lean-kernel/emit.js +59 -15
- package/dist/lean-kernel/integer-primitives.d.ts +17 -0
- package/dist/lean-kernel/integer-primitives.js +81 -0
- package/dist/lean-kernel/lean-aggregate/FiniteFold.lean +44 -0
- package/dist/lean-kernel/lean-aggregate/GroupedTransport.lean +308 -0
- package/dist/lean-kernel/lean-aggregate/aggregate.d.ts +13 -0
- package/dist/lean-kernel/lean-aggregate/aggregate.js +68 -0
- package/dist/lean-kernel/lean-aggregate/assets.d.ts +5 -0
- package/dist/lean-kernel/lean-aggregate/assets.js +7 -0
- package/dist/lean-kernel/lean-aggregate/audit.d.ts +3 -0
- package/dist/lean-kernel/lean-aggregate/audit.js +13 -0
- package/dist/lean-kernel/lean-aggregate/exact.d.ts +15 -0
- package/dist/lean-kernel/lean-aggregate/exact.js +51 -0
- package/dist/lean-kernel/lean-aggregate/index.d.ts +19 -0
- package/dist/lean-kernel/lean-aggregate/index.js +52 -0
- package/dist/lean-kernel/lean-aggregate/point-fold.d.ts +27 -0
- package/dist/lean-kernel/lean-aggregate/point-fold.js +79 -0
- package/dist/lean-kernel/lean-aggregate/replay-fold.d.ts +2 -0
- package/dist/lean-kernel/lean-aggregate/replay-fold.js +163 -0
- package/dist/lean-kernel/lean-aggregate/source.d.ts +2 -0
- package/dist/lean-kernel/lean-aggregate/source.js +141 -0
- package/dist/lean-kernel/lean-aggregate/weighted-flags.d.ts +2 -0
- package/dist/lean-kernel/lean-aggregate/weighted-flags.js +26 -0
- package/dist/lean-kernel/lean-aggregate/weighted-replay.d.ts +7 -0
- package/dist/lean-kernel/lean-aggregate/weighted-replay.js +53 -0
- package/dist/lean-kernel/lean-aggregate/weighted-seeded.d.ts +30 -0
- package/dist/lean-kernel/lean-aggregate/weighted-seeded.js +64 -0
- package/dist/lean-kernel/lean-aggregate/weighted.d.ts +18 -0
- package/dist/lean-kernel/lean-aggregate/weighted.js +115 -0
- package/dist/lean-kernel/lean-aggregate/worker.d.ts +10 -0
- package/dist/lean-kernel/lean-aggregate/worker.js +46 -0
- package/dist/lean-kernel/library.js +13 -0
- package/dist/lean-kernel/word-division-export.d.ts +26 -0
- package/dist/lean-kernel/word-division-export.js +172 -0
- package/dist/lean-kernel/word-division-lower.d.ts +10 -0
- package/dist/lean-kernel/word-division-lower.js +103 -0
- package/docs/lean-aggregate.md +29 -0
- package/package.json +6 -1
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/-
|
|
2
|
+
Cert: the trusted core of gdp-wired, with its proofs. Lean 4.34.0, core only.
|
|
3
|
+
|
|
4
|
+
A row `Σ cᵢ·xᵢ + c ≤ 0` over the integers. A certificate is a list of steps that replays into rows: an input row, a
|
|
5
|
+
positive combination of two earlier rows, or a cut (an earlier row whose coefficients are all g times q, replaced by q
|
|
6
|
+
with a constant c such that g·c ≤ constant + g − 1). `check` accepts when the last row has only zero coefficients and a
|
|
7
|
+
positive constant. `sound`: if `check` accepts, no integer point satisfies every input row.
|
|
8
|
+
|
|
9
|
+
A row holds its nonzero coefficients alone (column, coefficient), in column order, so a step costs a row's nonzeros
|
|
10
|
+
rather than the table's width. Any list reads as a sum (`dot`); sorted lists stay sorted and cancel to [] under `addL`.
|
|
11
|
+
|
|
12
|
+
`run_preserves` is the induction rule a step machine's laws rest on: a property true at the start and preserved by
|
|
13
|
+
every step holds after every sequence of steps.
|
|
14
|
+
-/
|
|
15
|
+
|
|
16
|
+
namespace Cert
|
|
17
|
+
|
|
18
|
+
structure Row where
|
|
19
|
+
coefs : List (Nat × Int)
|
|
20
|
+
const : Int
|
|
21
|
+
deriving Repr
|
|
22
|
+
|
|
23
|
+
def dot : List (Nat × Int) → List Int → Int
|
|
24
|
+
| [], _ => 0
|
|
25
|
+
| p :: rest, x => p.2 * x.getD p.1 0 + dot rest x
|
|
26
|
+
|
|
27
|
+
def eval (r : Row) (x : List Int) : Int := dot r.coefs x + r.const
|
|
28
|
+
|
|
29
|
+
-- Two sorted lists merged, coefficients of one column added (a column that cancels dropped). The fuel only bounds the
|
|
30
|
+
-- recursion: out of it, the lists are put side by side, which reads the same.
|
|
31
|
+
def addF : Nat → List (Nat × Int) → List (Nat × Int) → List (Nat × Int)
|
|
32
|
+
| 0, a, b => a ++ b
|
|
33
|
+
| _ + 1, [], b => b
|
|
34
|
+
| _ + 1, a, [] => a
|
|
35
|
+
| n + 1, p :: as, q :: bs =>
|
|
36
|
+
if p.1 < q.1 then p :: addF n as (q :: bs)
|
|
37
|
+
else if q.1 < p.1 then q :: addF n (p :: as) bs
|
|
38
|
+
else if p.2 + q.2 = 0 then addF n as bs else (p.1, p.2 + q.2) :: addF n as bs
|
|
39
|
+
|
|
40
|
+
def addL (a b : List (Nat × Int)) : List (Nat × Int) := addF (a.length + b.length) a b
|
|
41
|
+
|
|
42
|
+
def scaleL (m : Int) (a : List (Nat × Int)) : List (Nat × Int) := if m = 0 then [] else a.map (fun p => (p.1, m * p.2))
|
|
43
|
+
|
|
44
|
+
def allZero : List (Nat × Int) → Bool
|
|
45
|
+
| [] => true
|
|
46
|
+
| p :: a => p.2 == 0 && allZero a
|
|
47
|
+
|
|
48
|
+
theorem dot_app (x : List Int) : ∀ (a b : List (Nat × Int)), dot (a ++ b) x = dot a x + dot b x
|
|
49
|
+
| [], b => by simp [dot]
|
|
50
|
+
| p :: a, b => by simp only [List.cons_append, dot, dot_app x a b]; omega
|
|
51
|
+
|
|
52
|
+
theorem dot_addF (x : List Int) : ∀ (n : Nat) (a b : List (Nat × Int)), dot (addF n a b) x = dot a x + dot b x
|
|
53
|
+
| 0, a, b => by simp only [addF, dot_app]
|
|
54
|
+
| _ + 1, [], b => by simp [addF, dot]
|
|
55
|
+
| _ + 1, _ :: _, [] => by simp [addF, dot]
|
|
56
|
+
| n + 1, p :: as, q :: bs => by
|
|
57
|
+
simp only [addF]
|
|
58
|
+
split
|
|
59
|
+
· simp only [dot, dot_addF x n as (q :: bs)]; omega
|
|
60
|
+
· split
|
|
61
|
+
· simp only [dot, dot_addF x n (p :: as) bs]; omega
|
|
62
|
+
· have hpq : p.1 = q.1 := by omega
|
|
63
|
+
split
|
|
64
|
+
· rename_i hz
|
|
65
|
+
simp only [dot, dot_addF x n as bs, hpq]
|
|
66
|
+
have : p.2 * x.getD q.1 0 + q.2 * x.getD q.1 0 = 0 := by rw [← Int.add_mul, hz, Int.zero_mul]
|
|
67
|
+
omega
|
|
68
|
+
· simp only [dot, dot_addF x n as bs, hpq, Int.add_mul]; omega
|
|
69
|
+
|
|
70
|
+
theorem dot_addL (a b : List (Nat × Int)) (x : List Int) : dot (addL a b) x = dot a x + dot b x := dot_addF x _ a b
|
|
71
|
+
|
|
72
|
+
theorem dot_map (m : Int) (x : List Int) : ∀ (a : List (Nat × Int)), dot (a.map (fun p => (p.1, m * p.2))) x = m * dot a x
|
|
73
|
+
| [] => by simp [dot]
|
|
74
|
+
| p :: a => by simp only [List.map_cons, dot, dot_map m x a, Int.mul_add, Int.mul_assoc]
|
|
75
|
+
|
|
76
|
+
theorem dot_scaleL (m : Int) (a : List (Nat × Int)) (x : List Int) : dot (scaleL m a) x = m * dot a x := by
|
|
77
|
+
unfold scaleL
|
|
78
|
+
split
|
|
79
|
+
· rename_i h; subst h; simp [dot]
|
|
80
|
+
· exact dot_map m x a
|
|
81
|
+
|
|
82
|
+
theorem dot_allZero : ∀ (a : List (Nat × Int)) (x : List Int), allZero a = true → dot a x = 0
|
|
83
|
+
| [], _, _ => rfl
|
|
84
|
+
| p :: a, x, h => by
|
|
85
|
+
simp only [allZero, Bool.and_eq_true, beq_iff_eq] at h
|
|
86
|
+
simp [dot, h.1, dot_allZero a x h.2]
|
|
87
|
+
|
|
88
|
+
inductive Step where
|
|
89
|
+
| input (i : Nat)
|
|
90
|
+
| combine (a b : Nat) (ma mb : Int)
|
|
91
|
+
| cut (of : Nat) (g : Int) (q : List (Nat × Int)) (c : Int)
|
|
92
|
+
deriving Repr
|
|
93
|
+
|
|
94
|
+
def combineRow (ma mb : Int) (A B : Row) : Row :=
|
|
95
|
+
⟨addL (scaleL ma A.coefs) (scaleL mb B.coefs), ma * A.const + mb * B.const⟩
|
|
96
|
+
|
|
97
|
+
def cutOk (A : Row) (g : Int) (q : List (Nat × Int)) (c : Int) : Bool :=
|
|
98
|
+
decide (1 ≤ g) && decide (A.coefs = scaleL g q) && decide (g * c ≤ A.const + g - 1)
|
|
99
|
+
|
|
100
|
+
-- The rows so far kept newest first, with their number (step i's row is at n − 1 − i): a row is put on the front and
|
|
101
|
+
-- read where it is, never past a chain of appends.
|
|
102
|
+
def replay (inputs : List Row) : List Step → Nat → List Row → Option (List Row)
|
|
103
|
+
| [], _, rows => some rows
|
|
104
|
+
| .input i :: ss, n, rows =>
|
|
105
|
+
match inputs[i]? with
|
|
106
|
+
| some r => replay inputs ss (n + 1) (r :: rows)
|
|
107
|
+
| none => none
|
|
108
|
+
| .combine a b ma mb :: ss, n, rows =>
|
|
109
|
+
match rows[n - 1 - a]?, rows[n - 1 - b]? with
|
|
110
|
+
| some A, some B => if a < n ∧ b < n ∧ 0 < ma ∧ 0 < mb then replay inputs ss (n + 1) (combineRow ma mb A B :: rows) else none
|
|
111
|
+
| _, _ => none
|
|
112
|
+
| .cut o g q c :: ss, n, rows =>
|
|
113
|
+
match rows[n - 1 - o]? with
|
|
114
|
+
| some A => if o < n ∧ cutOk A g q c then replay inputs ss (n + 1) (⟨q, c⟩ :: rows) else none
|
|
115
|
+
| none => none
|
|
116
|
+
|
|
117
|
+
def check (inputs : List Row) (steps : List Step) : Bool :=
|
|
118
|
+
match replay inputs steps 0 [] with
|
|
119
|
+
| some rows =>
|
|
120
|
+
match rows.head? with
|
|
121
|
+
| some r => allZero r.coefs && decide (0 < r.const)
|
|
122
|
+
| none => false
|
|
123
|
+
| none => false
|
|
124
|
+
|
|
125
|
+
theorem cut_sound (g d c c' : Int) (hg : 1 ≤ g) (h : g * d + c ≤ 0) (hc : g * c' ≤ c + g - 1) : d + c' ≤ 0 := by
|
|
126
|
+
have hd : g * (d + c') = g * d + g * c' := Int.mul_add g d c'
|
|
127
|
+
refine Int.not_lt.mp (fun h1 => ?_)
|
|
128
|
+
have h2 : g * 1 ≤ g * (d + c') := Int.mul_le_mul_of_nonneg_left (by omega) (by omega)
|
|
129
|
+
omega
|
|
130
|
+
|
|
131
|
+
-- Every row a replay produces holds wherever the inputs and the rows so far hold.
|
|
132
|
+
theorem replay_holds (inputs : List Row) (x : List Int) (hx : ∀ r ∈ inputs, eval r x ≤ 0) :
|
|
133
|
+
∀ (ss : List Step) (n : Nat) (rows out : List Row), (∀ r ∈ rows, eval r x ≤ 0) →
|
|
134
|
+
replay inputs ss n rows = some out → ∀ r ∈ out, eval r x ≤ 0 := by
|
|
135
|
+
intro ss
|
|
136
|
+
induction ss with
|
|
137
|
+
| nil =>
|
|
138
|
+
intro n rows out hrows h
|
|
139
|
+
simp only [replay, Option.some.injEq] at h
|
|
140
|
+
exact h ▸ hrows
|
|
141
|
+
| cons s ss ih =>
|
|
142
|
+
intro n rows out hrows h
|
|
143
|
+
cases s with
|
|
144
|
+
| input i =>
|
|
145
|
+
simp only [replay] at h
|
|
146
|
+
split at h
|
|
147
|
+
· rename_i r hr
|
|
148
|
+
refine ih _ _ out ?_ h
|
|
149
|
+
intro r' hr'
|
|
150
|
+
rcases List.mem_cons.mp hr' with hr' | hr'
|
|
151
|
+
· exact hr' ▸ hx r (List.mem_of_getElem? hr)
|
|
152
|
+
· exact hrows r' hr'
|
|
153
|
+
· exact absurd h (by simp)
|
|
154
|
+
| combine a b ma mb =>
|
|
155
|
+
simp only [replay] at h
|
|
156
|
+
split at h
|
|
157
|
+
· rename_i A B hA hB
|
|
158
|
+
split at h
|
|
159
|
+
· rename_i hm
|
|
160
|
+
refine ih _ _ out ?_ h
|
|
161
|
+
intro r' hr'
|
|
162
|
+
rcases List.mem_cons.mp hr' with hr' | hr'
|
|
163
|
+
· subst hr'
|
|
164
|
+
have eA := hrows A (List.mem_of_getElem? hA)
|
|
165
|
+
have eB := hrows B (List.mem_of_getElem? hB)
|
|
166
|
+
simp only [eval, combineRow, dot_addL, dot_scaleL] at eA eB ⊢
|
|
167
|
+
have h1 : ma * (dot A.coefs x + A.const) ≤ ma * 0 := Int.mul_le_mul_of_nonneg_left eA (by omega)
|
|
168
|
+
have h2 : mb * (dot B.coefs x + B.const) ≤ mb * 0 := Int.mul_le_mul_of_nonneg_left eB (by omega)
|
|
169
|
+
simp only [Int.mul_add, Int.mul_zero] at h1 h2
|
|
170
|
+
omega
|
|
171
|
+
· exact hrows r' hr'
|
|
172
|
+
· exact absurd h (by simp)
|
|
173
|
+
· exact absurd h (by simp)
|
|
174
|
+
| cut o g q c =>
|
|
175
|
+
simp only [replay] at h
|
|
176
|
+
split at h
|
|
177
|
+
· rename_i A hA
|
|
178
|
+
split at h
|
|
179
|
+
· rename_i hok
|
|
180
|
+
refine ih _ _ out ?_ h
|
|
181
|
+
intro r' hr'
|
|
182
|
+
rcases List.mem_cons.mp hr' with hr' | hr'
|
|
183
|
+
· subst hr'
|
|
184
|
+
simp only [cutOk, Bool.and_eq_true, decide_eq_true_eq] at hok
|
|
185
|
+
obtain ⟨_, ⟨hg, hq⟩, hc⟩ := hok
|
|
186
|
+
have eA := hrows A (List.mem_of_getElem? hA)
|
|
187
|
+
have hdot : dot A.coefs x = g * dot q x := by rw [hq, dot_scaleL]
|
|
188
|
+
simp only [eval, hdot] at eA
|
|
189
|
+
exact cut_sound g (dot q x) A.const c hg eA hc
|
|
190
|
+
· exact hrows r' hr'
|
|
191
|
+
· exact absurd h (by simp)
|
|
192
|
+
· exact absurd h (by simp)
|
|
193
|
+
|
|
194
|
+
/-- A certificate the checker accepts refutes its inputs: no integer point satisfies them all. -/
|
|
195
|
+
theorem sound (inputs : List Row) (steps : List Step) (h : check inputs steps = true) (x : List Int)
|
|
196
|
+
(hx : ∀ r ∈ inputs, eval r x ≤ 0) : False := by
|
|
197
|
+
simp only [check] at h
|
|
198
|
+
split at h
|
|
199
|
+
· rename_i rows hrows
|
|
200
|
+
split at h
|
|
201
|
+
· rename_i r hr
|
|
202
|
+
simp only [Bool.and_eq_true, decide_eq_true_eq] at h
|
|
203
|
+
have hall := replay_holds inputs x hx steps 0 [] rows (by simp) hrows
|
|
204
|
+
have hm : r ∈ rows := by
|
|
205
|
+
cases rows with
|
|
206
|
+
| nil => simp at hr
|
|
207
|
+
| cons a as => simp only [List.head?, Option.some.injEq] at hr; subst hr; exact List.mem_cons_self
|
|
208
|
+
have := hall r hm
|
|
209
|
+
simp only [eval, dot_allZero r.coefs x h.1] at this
|
|
210
|
+
omega
|
|
211
|
+
· exact absurd h (by simp)
|
|
212
|
+
· exact absurd h (by simp)
|
|
213
|
+
|
|
214
|
+
/-- The induction rule: what holds at the start and survives every step holds after any sequence of steps. -/
|
|
215
|
+
theorem run_preserves {S I : Type} (step : S → I → S) (P : S → Prop) (start : S)
|
|
216
|
+
(h0 : P start) (hs : ∀ s i, P s → P (step s i)) : ∀ (is : List I), P (is.foldl step start) := by
|
|
217
|
+
intro is
|
|
218
|
+
induction is generalizing start with
|
|
219
|
+
| nil => exact h0
|
|
220
|
+
| cons i is ih => exact ih (step start i) (hs start i h0)
|
|
221
|
+
|
|
222
|
+
end Cert
|