GasStationManager commited on
Commit
f9d28cf
·
verified ·
1 Parent(s): feef162

Upload 2 files

Browse files
Files changed (2) hide show
  1. EasyBenchmark.lean +1045 -0
  2. easy.jsonl +24 -0
EasyBenchmark.lean ADDED
@@ -0,0 +1,1045 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+
3
+
4
+ def solveAdd (a b:Int): Int
5
+ := b-a
6
+
7
+ theorem solveAdd_correct (a b: Int): a + (solveAdd a b) =b
8
+ := by simp[solveAdd]
9
+
10
+ def solveAdd0(a:Int): Int
11
+ := -a
12
+
13
+ theorem solveAdd0_correct(a: Int): a +(solveAdd0 a)=0
14
+ := by simp[solveAdd0]
15
+
16
+ def solveSub(a b:Int): Int
17
+ := a-b
18
+
19
+ theorem solveSub_correct(a b:Int): a - (solveSub a b)=b
20
+ := by simp[solveSub]
21
+
22
+ def solve1x1(a b: Rat): Option Rat :=
23
+ if a = 0 then
24
+ if b=0 then
25
+ some 0
26
+ else
27
+ none
28
+ else
29
+ some (b/a)
30
+
31
+ theorem solve1x1_correct(a b:Rat): (∃ x, a*x=b) -> a * (solve1x1 a b).get! =b
32
+ := by
33
+ intro hsol
34
+ simp[solve1x1]
35
+ split_ifs
36
+ next hb=>simp[hb]
37
+ next ha hb=> simp[ha] at hsol; rw[hsol] at hb; contradiction
38
+ next ha=>
39
+ simp
40
+ simp[Rat.div_def]
41
+ simp[Rat.mul_comm b]
42
+ simp[← Rat.mul_assoc]
43
+ have: a*a.inv=1 :=by{
44
+ have hainv: a⁻¹ = a.inv :=by {
45
+ exact rfl
46
+ }
47
+ rw[← hainv]
48
+ rw[Rat.mul_inv_cancel]
49
+ assumption
50
+ }
51
+ simp[this]
52
+
53
+ theorem solve1x1_none(a b:Rat): (Not (∃ x, a*x=b)) -> solve1x1 a b=none
54
+ := by
55
+ intro h
56
+ simp[solve1x1]
57
+ split_ifs
58
+ next ha hb=> simp[ha] at h;rw[hb] at h; contradiction
59
+ next=>rfl
60
+ next ha=>
61
+ contrapose! h
62
+ use b/a
63
+ exact mul_div_cancel₀ b ha
64
+
65
+ def solveMul(a: Rat): Rat
66
+ := if a=0 then 0 else 1/a
67
+
68
+ theorem solveMul_correct(a:Rat): (∃ x, a*x=1)->a * (solveMul a)=1
69
+ := by
70
+ intro h
71
+ simp[solveMul]
72
+ split
73
+ next ha=>
74
+ simp[ha] at h
75
+ next ha=>
76
+ exact Rat.mul_inv_cancel a ha
77
+
78
+ theorem solveMul_nosol (a:Rat): (Not (∃ x, a*x=1)) ->solveMul a =0
79
+ := by
80
+ intro h
81
+ simp[solveMul]
82
+ contrapose! h
83
+ use 1/a
84
+ exact mul_one_div_cancel h
85
+
86
+ def solveDiv(a b:Rat) (ha: a≠ 0)(hb: b≠ 0): Rat
87
+ := a/b
88
+
89
+ theorem solveDiv_correct(a b:Rat)(ha:a≠ 0)(hb: b≠ 0):
90
+ a / (solveDiv a b ha hb)= b
91
+ := by
92
+ simp[solveDiv]
93
+ rw[← div_mul]
94
+ rw[div_self (by simp[ha])]
95
+ simp
96
+
97
+ def isPrime(a: Nat): Bool
98
+ :=
99
+ if a<=1 then false
100
+ else
101
+ let rec helper (cur: Nat):Bool:=
102
+ if cur>=a then true
103
+ else if a%cur=0 then false
104
+ else helper (cur+1)
105
+ termination_by a-cur
106
+ decreasing_by{
107
+ simp_wf
108
+ have hacur: a>cur:=by omega
109
+ exact Nat.sub_succ_lt_self a cur hacur
110
+ }
111
+ helper 2
112
+
113
+
114
+ theorem isPrime_correct(a: Nat):
115
+ (isPrime a) <-> Nat.Prime a := by{
116
+ constructor
117
+ · {
118
+ unfold isPrime
119
+ split
120
+ simp
121
+ have: ∀ cur:Nat, cur>=2->(∀x:Nat, (x>=2 ∧ x< cur)-> a%x !=0) ->isPrime.helper a cur ->a.Prime:=by {
122
+ intro cur
123
+ intro hcur2
124
+ induction cur using isPrime.helper.induct
125
+ exact a
126
+ next ha1 c hcga =>
127
+ have hhelp: isPrime.helper a c =true:=by {
128
+ unfold isPrime.helper
129
+ simp[hcga]
130
+ }
131
+ simp[hhelp]
132
+ contrapose!
133
+ intro hnp
134
+
135
+ apply Nat.exists_dvd_of_not_prime2 at hnp
136
+ rcases hnp with ⟨ k, hnp'⟩
137
+ use k
138
+ simp[hnp']
139
+ omega
140
+ omega
141
+
142
+
143
+ next ha c hca hmod =>
144
+ have hhelp: isPrime.helper a c=false:=by{
145
+ unfold isPrime.helper
146
+ simp[hmod,hca]
147
+ }
148
+ simp[hhelp]
149
+
150
+ next ha c hca hmod ih =>
151
+ unfold isPrime.helper
152
+ split
153
+ simp
154
+ have: c>=a :=by assumption
155
+ contradiction
156
+ have: c+1>=2 :=by omega
157
+ simp[ this] at ih
158
+ simp
159
+ intro hx
160
+ apply ih
161
+ intro x
162
+ intro hx2
163
+ intro hxlt
164
+ cases hc1x: c-x
165
+
166
+ have: c=x :=by {
167
+ omega
168
+
169
+ }
170
+ rw[← this]
171
+ assumption
172
+ have: x<c :=by{
173
+ omega
174
+ }
175
+ apply hx
176
+ assumption
177
+ assumption
178
+ }
179
+
180
+
181
+ apply this
182
+ omega
183
+ intro x
184
+ omega
185
+
186
+ }
187
+ next=>
188
+ contrapose!
189
+ unfold isPrime
190
+ split
191
+ simp
192
+ have: a<=1 :=by assumption
193
+ have ha2: a ≠ 2 :=by omega
194
+ have ha3: a≠ 3 :=by omega
195
+ intro hp
196
+ have h5p: 5<=a :=by {
197
+ exact Nat.Prime.five_le_of_ne_two_of_ne_three hp ha2 ha3 --Prime.five_le_of_ne_two_of_ne_three a hp ha2 ha3
198
+ }
199
+ omega
200
+ have: ∀cur: Nat, cur>=2 ->isPrime.helper a cur ≠ true ->¬ a.Prime :=by{
201
+ intro cur
202
+ intro hcur2
203
+ induction cur using isPrime.helper.induct
204
+ exact a
205
+ next ha1 x hxa=>
206
+ unfold isPrime.helper
207
+ simp[hxa]
208
+
209
+
210
+ next ha1 x hxa hmod =>
211
+ unfold isPrime.helper
212
+ simp[hxa,hmod]
213
+ have :x ∣ a :=by omega
214
+ have hxneqa: x≠ a :=by omega
215
+ have hxneq1: x≠ 1 :=by omega
216
+ exact Nat.not_prime_of_dvd_of_ne this hxneq1 hxneqa
217
+
218
+ next ha1 x hxa hmod ih=>
219
+ unfold isPrime.helper
220
+ simp[hxa,hmod]
221
+ simp at ih
222
+ apply ih
223
+ omega
224
+
225
+ }
226
+ apply this
227
+ omega
228
+
229
+ }
230
+
231
+ def modInv(a: Nat) (p:Nat)(hp:p.Prime): Option Nat
232
+ :=
233
+ if a%p=0 then
234
+ none
235
+ else
236
+ let expn:Nat := p-2
237
+ some ( (a^expn) %p)
238
+
239
+ theorem modInv_correct(a:Nat) (p:Nat)(hp:p.Prime):
240
+ (∃ x:Nat, (a*x)%p=1)->(a*(modInv a p hp).get!)%p=1 :=by{
241
+ intro hexist
242
+ have han0: a%p ≠ 0:=by{
243
+ contrapose! hexist
244
+ intro x
245
+ have: (a*x)%p =(a%p *x)%p:=by{
246
+ simp[Nat.mod_mul_mod]
247
+ --exact Eq.symm (Nat.mod_mul_mod a x ↑p)
248
+ }
249
+ rw[hexist] at this
250
+ simp[this]
251
+ }
252
+ unfold modInv
253
+ simp[han0]
254
+ --simp[Option.get!]
255
+ have hp2:p>=2 :=by{
256
+ exact Nat.Prime.two_le hp
257
+ }
258
+ have hm:a*a^(p-2)=a^(p-1) :=by{
259
+ calc
260
+ a*a^(p-2)= a^1 *a^(p-2):=by {simp}
261
+ _=a^(1+(p-2)) :=by{exact Eq.symm (Nat.pow_add a 1 (p - 2))}
262
+ _=a^(p-1) :=by{
263
+ have: 1+(p-2)=p-1:=by omega
264
+ exact congrArg (HPow.hPow a) this
265
+ }
266
+ }
267
+ simp[hm]
268
+
269
+ --Fermat's little theorem
270
+ --from Mathlib.FieldTheory.Finite
271
+ have hcop: IsCoprime (a:Int) p :=by{
272
+ refine Nat.isCoprime_iff_coprime.mpr ?_
273
+ have: ¬ p ∣ a :=by{omega}
274
+ refine Nat.coprime_iff_isRelPrime.mpr ?_
275
+ have hrp:= (Irreducible.isRelPrime_iff_not_dvd hp).mpr this
276
+ exact
277
+ IsRelPrime.symm hrp
278
+ }
279
+ have:= Int.ModEq.pow_card_sub_one_eq_one hp hcop
280
+ have pz:((a:Int)^(p-1))%(p:Int)=1%(p:Int):=by{
281
+ exact this
282
+ }
283
+ --contrapose this
284
+ --intro hzmod
285
+ have h1mp: 1%(p:Int)=1 :=by{
286
+ refine Int.emod_eq_of_lt ?H1 ?H2
287
+ omega
288
+ omega
289
+ }
290
+ rw[h1mp] at pz
291
+
292
+ norm_cast at pz
293
+
294
+ }
295
+
296
+ theorem modInv_none(a:Nat) (p:Nat)(hp:p.Prime): (Not (∃ x, (a*x)%p=1))-> modInv a p hp=none
297
+ :=by
298
+ intro h
299
+ simp[modInv]
300
+ contrapose! h
301
+ refine Nat.exists_mul_emod_eq_one_of_coprime ?hkn ?hk
302
+ refine Nat.coprime_iff_isRelPrime.mpr ?_
303
+ have: ¬ p ∣ a :=by{omega}
304
+ have hrp:= (Irreducible.isRelPrime_iff_not_dvd hp).mpr this
305
+ exact IsRelPrime.symm hrp
306
+ exact Nat.Prime.one_lt hp
307
+
308
+ def minFacT(a:Nat) (h: a>1)
309
+ : {x:Nat//x>1∧ x ∣ a∧ Not (∃ y>1, y∣a ∧ y<x)}
310
+ :=
311
+ let lst:= List.range (a+1)
312
+ let res:=lst.find? (fun x=> x>1 ∧ x∣ a)
313
+ have : res.isSome :=by{
314
+ refine (@List.find?_isSome _ lst fun x => decide (x > 1 ∧ x ∣ a)).mpr ?_
315
+ use a
316
+ constructor
317
+ exact List.self_mem_range_succ a
318
+ simp[h]
319
+ }
320
+ let r:=res.get this
321
+ ⟨r, by{
322
+ have hf:lst.find? (fun x=> x>1 ∧ x∣ a)=some r:=by{
323
+ exact Eq.symm (Option.some_get this)
324
+ }
325
+ have lem := @List.find?_range_eq_some (a+1) _ _|>.mp hf
326
+ simp at lem
327
+ constructor
328
+ simp[lem.left]
329
+ constructor
330
+ simp[lem.left]
331
+ have lr:=lem.right
332
+ rcases lr with ⟨ _,lr'⟩
333
+ intro hy
334
+ rcases hy with ⟨ y , hy'⟩
335
+ have:= lr' y hy'.2.2
336
+ rcases this <;> omega
337
+ }⟩
338
+
339
+ def minFac(a:Nat) (h: a>1):Nat
340
+ := minFacT a h
341
+
342
+ theorem minFac_isfac(a:Nat)(h: a>1): ( (minFac a h) ∣ a) ∧ (minFac a h>1)
343
+ :=by
344
+ simp[minFac]
345
+ let r:=minFacT a h
346
+ simp[r.2]
347
+
348
+ theorem minFac_ismin(a:Nat)(h:a>1): Not (∃ y>1,( y ∣ a) ∧ y<minFac a h)
349
+ :=by
350
+ simp[minFac]
351
+ let r:=minFacT a h
352
+ have:=r.2.2.2
353
+ intro x h1 hdvd
354
+ simp at this
355
+ have:=this x h1 hdvd
356
+ simp[r,this]
357
+
358
+
359
+ def midPoint (x1 y1 x2 y2: Rat):Rat × Rat
360
+ :=((x1+x2)/2, (y1+y2)/2)
361
+
362
+ def distSq( x1 y1 x2 y2: Rat):Rat:=
363
+ (x1-x2)^2 + (y1-y2)^2
364
+
365
+ theorem midPoint_correct (x1 y1 x2 y2: Rat)
366
+ : let (xmid,ymid) :=midPoint x1 y1 x2 y2
367
+ distSq xmid ymid x1 y1=distSq xmid ymid x2 y2
368
+ ∧ 4*(distSq xmid ymid x1 y1)=distSq x1 y1 x2 y2
369
+ :=by
370
+ simp[midPoint,distSq]
371
+ constructor <;> ring_nf
372
+
373
+
374
+ def GCD (x y: Nat): Nat :=
375
+
376
+ if y = 0 then
377
+ x
378
+ else
379
+ GCD y (x % y)
380
+ termination_by y
381
+ decreasing_by {
382
+ simp_wf
383
+ apply Nat.mod_lt _
384
+ refine Nat.zero_lt_of_ne_zero ?_
385
+ assumption
386
+ }
387
+
388
+ theorem gcd_is_div (x y: Nat):
389
+ (p: x > 0)→ ((GCD x y) ∣ x) ∧ ((GCD x y) ∣ y) := match y with
390
+ | 0 => by {
391
+ simp[GCD]
392
+ }
393
+ | Nat.succ z =>by {
394
+ have hyp: z.succ>0 := by {
395
+ exact Nat.zero_lt_succ z
396
+ }
397
+ have ih := gcd_is_div z.succ (x % z.succ)
398
+ have ihh := ih hyp
399
+ have heq: GCD x z.succ = GCD z.succ (x%z.succ) :=by{
400
+ rw[GCD.eq_def]
401
+ tauto
402
+ }
403
+ intro hx
404
+ simp[heq, ihh]
405
+ rcases ihh.right with ⟨k, ihh' ⟩
406
+
407
+ have hq: x = (GCD z.succ (x%z.succ))*k +z.succ*(x/z.succ) :=by{
408
+ rw[← ihh']
409
+ exact Eq.symm (Nat.mod_add_div x z.succ)
410
+ }
411
+ rcases ihh.left with ⟨ m, ihhl'⟩
412
+ use (x/z.succ) * m + k
413
+ rw[Nat.mul_add]
414
+ rw[Nat.mul_comm, Nat.mul_assoc]
415
+ rw[Nat.mul_comm m]
416
+ rw[← ihhl']
417
+ rw[Nat.mul_comm]
418
+ rw[Nat.add_comm]
419
+ have hz: z+1 = z.succ :=by omega
420
+ rw[hz]
421
+ omega
422
+ }
423
+ termination_by y
424
+ decreasing_by {
425
+ simp_wf
426
+ apply Nat.mod_lt _
427
+ refine Nat.zero_lt_of_ne_zero ?_
428
+ tauto
429
+ }
430
+
431
+ theorem gcd_is_greatest (x y: Nat):
432
+ (x>0) → Not (∃ z: Nat, z∣ x ∧ z∣ y ∧ z> GCD x y ) := match y with
433
+ | 0 => by {
434
+ have hgcd0: GCD x 0 = x :=by {
435
+ simp[GCD]
436
+ }
437
+ intro hx
438
+ intro hh
439
+ rcases hh with ⟨z0, hh' ⟩
440
+ have hzx: z0 ≤ x :=by{
441
+ have hzdx: z0∣ x:=by {tauto}
442
+ rcases hzdx with ⟨k, hzdx'⟩
443
+ have hk: k>0 :=by{
444
+ contrapose hx
445
+ have hk0: k=0 := by omega
446
+ have hx0: x=0:= by simp[hzdx', hk0]
447
+ omega
448
+ }
449
+ have hkg1: k>=1:=by{omega}
450
+ rw[hzdx']
451
+ have hz0: z0=z0*1:=by {omega}
452
+ nth_rewrite 1 [hz0]
453
+ exact Nat.mul_le_mul_left z0 hk
454
+ }
455
+ have: z0>GCD x 0:=by{tauto}
456
+ rw[hgcd0] at this
457
+ omega
458
+ }
459
+ | Nat.succ yy => by{
460
+ intro hx
461
+ intro hh
462
+ rcases hh with ⟨z0, hh' ⟩
463
+ have ih:=gcd_is_greatest yy.succ (x%yy.succ)
464
+ have hyg0: yy.succ>0 :=by{omega}
465
+ have ihh:= ih hyg0
466
+ have hgcd: GCD x yy.succ = GCD yy.succ (x%yy.succ) := by {
467
+ rw[GCD.eq_def]
468
+ tauto
469
+ }
470
+ contrapose! ihh
471
+ use z0
472
+ have hzg: z0> GCD yy.succ (x%yy.succ):= by {
473
+ omega
474
+ }
475
+ simp[hzg, hh']
476
+ have hzx: z0∣ x:=by tauto
477
+ rcases hzx with ⟨ k, hzx'⟩
478
+ have hzy: z0 ∣ yy.succ :=by tauto
479
+ rcases hzy with ⟨ m, hzy' ⟩
480
+ have hmod: x%yy.succ + yy.succ * (x/yy.succ) =x :=by{
481
+ exact Nat.mod_add_div x yy.succ
482
+ }
483
+ refine (Nat.dvd_mod_iff ?h.intro.intro.h).mpr ?h.intro.intro.a
484
+ tauto
485
+ tauto
486
+ }
487
+ termination_by y
488
+ decreasing_by {
489
+ simp_wf
490
+ apply Nat.mod_lt _
491
+ refine Nat.zero_lt_of_ne_zero ?_
492
+ tauto
493
+ }
494
+
495
+
496
+ def solveProg(t:Nat):Nat
497
+ :=
498
+ let rec loop (i:{i':Nat//¬ ∃ i'' < i',i''*(i''+1)>=t*2}) (acc:{a:Nat//a*2=i.val*(i.val+1)})
499
+ :{x:Nat//x*(x+1)>=t*2∧ ¬ ∃ y<x, y*(y+1)>=t*2}:=
500
+ have ih:=acc.2
501
+ have iih:=i.2
502
+ if h:acc>=t then
503
+ ⟨i, by constructor;omega;exact iih⟩
504
+ else
505
+ have hi: Not (i.val*(i.val+1)>=t*2):=by{
506
+ rw[← ih]
507
+ simp[h]
508
+ }
509
+ have: ¬∃ i'' < i.val + 1, i'' * (i'' + 1) ≥ t * 2:=by{
510
+ simp
511
+ intro x hx
512
+ by_cases x < i.val
513
+ next hlt=> simp at iih; exact iih x hlt
514
+ next hlt=>
515
+ have : x=i:=by omega
516
+ rw[this]
517
+ simpa using hi
518
+ }
519
+ loop ⟨i.val+1,this⟩ ⟨acc.val+i.val+1, by ring_nf;rw[ih];ring⟩
520
+ termination_by t-acc
521
+ decreasing_by{
522
+ simp_wf
523
+ refine Nat.sub_lt_sub_left (by omega) (by omega)
524
+ }
525
+ loop ⟨ 0, by omega⟩ ⟨ 0, by simp⟩
526
+
527
+ theorem solveProg_isgeq(t:Nat): (solveProg t)*((solveProg t)+1) >= t*2
528
+ :=by
529
+ simp[solveProg]
530
+ have ih:=(solveProg.loop t ⟨ 0,by omega⟩ ⟨0, solveProg.proof_2⟩).2
531
+ omega
532
+
533
+ theorem solveProg_ismin(t:Nat): Not (∃ y< (solveProg t), y*(y+1)>=t*2)
534
+ :=by
535
+ simp[solveProg]
536
+ have ih:=(solveProg.loop t ⟨ 0,by omega⟩ ⟨0, solveProg.proof_2⟩).2
537
+ simp at ih
538
+ exact ih.right
539
+
540
+
541
+ def solveGeom(a t:Nat)(h:a>1):Nat
542
+ :=
543
+ let rec loop (h:a>1)(i:{i':Nat//¬ ∃i'' < i',a^(i''+1)-1>=t*(a-1)})(acc:{acc':Nat//a^(i.val+1)-1=acc'*(a-1)})
544
+ :{x:Nat//a^(x+1)-1>=t*(a-1)∧ ¬∃ y<x,a^(y+1)-1>=t*(a-1)}:=
545
+ have ih:=acc.2
546
+ have iih:=i.2
547
+ if hge:acc>=t then
548
+ ⟨i, by rw [ih];constructor;exact Nat.mul_le_mul_right (a - 1) hge; exact iih⟩
549
+ else
550
+ let newacc:=acc+a^(i.val+1)
551
+ have : a^(i.val+2)-1=newacc *(a-1):=by{
552
+ ring_nf
553
+ rw[← ih]
554
+ ring_nf
555
+ have : 0< a * a ^ i.val :=by refine Nat.mul_pos (by omega) (by refine Nat.pow_pos (by omega))
556
+ rw[← Nat.add_sub_assoc (by omega) (a * a ^ i.val * (a - 1))]
557
+ ring_nf
558
+ have: a * a ^ i.val+a * a ^ i.val * (a - 1) =a * a ^ i.val*a:=by{
559
+ have lem:=Nat.mul_one (a * a ^ i.val)
560
+ nth_rewrite 1 [← lem]
561
+ rw[← Nat.mul_add (a*a^i.val) 1]
562
+ have: 1+(a-1)=a:=by omega
563
+ rw[this]
564
+ }
565
+ rw[this]
566
+ ring_nf
567
+ }
568
+ have hopt:¬∃ i'' < i.val + 1, a ^ (i'' + 1) - 1 ≥ t * (a - 1):=by{
569
+ simp
570
+ intro x xh
571
+ by_cases x < i.val
572
+ next hlt=> simp at iih; exact iih x hlt
573
+ next hlt=>
574
+ have hxi: x=i :=by omega
575
+ simp at hge
576
+ rw[hxi,ih]
577
+ refine Nat.mul_lt_mul_of_pos_right hge (by simp[h])
578
+ }
579
+ loop h ⟨i.val+1, hopt⟩ ⟨newacc,this ⟩
580
+ termination_by t-acc
581
+ decreasing_by{
582
+ simp_wf
583
+ refine Nat.sub_lt_sub_left (by omega) ?_
584
+ have: a^(i.val+1)>0 :=by{
585
+ refine Nat.pow_pos (by omega)
586
+ }
587
+ omega
588
+ }
589
+ loop h ⟨0, by simp⟩ ⟨1, by ring_nf⟩
590
+
591
+ theorem solveGeom_isgeq(a t:Nat)(h:a>1): a^((solveGeom a t h)+1)-1 >=t*(a-1)
592
+ :=by
593
+ simp[solveGeom]
594
+ have:=(solveGeom.loop a t h h ⟨0, by simp⟩ ⟨1, by ring_nf⟩).2
595
+ simp[this]
596
+
597
+ theorem solveGeom_ismin(a t:Nat)(h:a>1): Not (∃ y<solveGeom a t h, a^(y+1)-1>= t*(a-1))
598
+ :=by
599
+ simp[solveGeom]
600
+ have:=(solveGeom.loop a t h h ⟨0, by simp⟩ ⟨1, by ring_nf⟩).2.2
601
+ simp at this
602
+ exact this
603
+
604
+
605
+ def solveSquare(t:Nat): Nat
606
+ :=
607
+ let rec loop (i:{i':Nat//¬ ∃ i'' < i', i''*i''>=t})
608
+ :{x:Nat//x*x>=t∧ ¬ ∃ y<x, y*y>=t} :=
609
+ have iih:=i.2
610
+ if hcomp: i*i>=t then
611
+ ⟨ i, by simp[hcomp];simp at iih;exact iih⟩
612
+ else
613
+ loop ⟨i+1,
614
+ by{
615
+ simp
616
+ intro x hx
617
+ by_cases x < i.val
618
+ next hlt=> simp at iih; exact iih x hlt
619
+ next hlt=>
620
+ have hxi: x=i.val :=by omega
621
+ rw[hxi]
622
+ omega
623
+ }⟩
624
+ termination_by t-i*i
625
+ decreasing_by{
626
+ simp_wf
627
+ refine Nat.sub_lt_sub_left (by omega) (by ring_nf;omega)
628
+ }
629
+ loop ⟨0, by simp⟩
630
+
631
+ theorem solveSquare_isgeq(t:Nat): (solveSquare t)*(solveSquare t)>=t
632
+ :=by
633
+ simp[solveSquare]
634
+ have:=(solveSquare.loop t ⟨0, by simp⟩).2
635
+ simp[this]
636
+
637
+ theorem solveSquare_ismin(t:Nat): Not (∃ y< (solveSquare t), y*y>=t)
638
+ :=by
639
+ simp[solveSquare]
640
+ have:=(solveSquare.loop t ⟨0, by simp⟩).2.2
641
+ simp at this
642
+ exact this
643
+
644
+ def f[Monad m] (op: Nat->Nat->(m Nat)) (n: Nat): (m Nat)
645
+ :=
646
+ match n with
647
+ | 0 => pure 1
648
+ | 1 => pure 1
649
+ | n + 2 =>
650
+ do
651
+ let x ← f op (n + 1)
652
+ let y ← f op n
653
+ op x y
654
+
655
+
656
+ theorem f_base (op : Nat → Nat → Id Nat) :
657
+ (f op 0 = pure 1) ∧ (f op 1 = pure 1)
658
+ := by constructor <;> rfl
659
+
660
+
661
+ theorem f_recursive (op : Nat → Nat → Id Nat) (n : Nat) : f op (n+2) =do {op (← f op (n+1)) (← f op n) }
662
+ := by rfl
663
+
664
+ def rev(xs: List Int): List Int
665
+ := match xs with
666
+ |[] => []
667
+ |h::t => (rev t) ++ [h]
668
+
669
+ theorem reverse_correct(xs:List Int):
670
+ xs.length=(rev xs).length ∧
671
+ ∀ i<xs.length, xs[i]! =(rev xs)[xs.length-1-i]!
672
+ :=by{
673
+ induction xs
674
+ next=>simp[rev]
675
+ next h t ih=>
676
+ constructor
677
+ · {
678
+ simp[rev,ih]
679
+ }
680
+ · {
681
+ simp[rev]
682
+ intro i
683
+ have hlen: (rev t).length=t.length:=by{
684
+ simp [ih.left]
685
+ }
686
+ cases i with
687
+ |zero=>
688
+ simp
689
+ have :t.length<(rev t ++[h]).length :=by{
690
+ exact List.get_of_append_proof rfl hlen
691
+ }
692
+ have hind:(rev t ++ [h])[t.length]! =(rev t ++ [h])[t.length] :=by{
693
+ exact getElem!_pos (rev t ++ [h]) t.length this
694
+ }
695
+ simp[hind]
696
+ exact Eq.symm (List.getElem_concat_length (rev t) h t.length (id (Eq.symm hlen)) this)
697
+ |succ i'=>
698
+ simp
699
+ have:= ih.right i'
700
+ intro hi'
701
+ simp[hi'] at this
702
+
703
+ have hlind:t.length-1-i'=t.length - (i' + 1) :=by{
704
+ omega
705
+ }
706
+ have hh: (rev t)[t.length - 1 - i']! =(rev t ++ [h])[t.length - (i' + 1)]! :=by{
707
+ simp[hlind]
708
+ have hlt:t.length - (i' + 1)<(rev t).length :=by{
709
+ simp[hlen]
710
+ omega
711
+ }
712
+ have hl':(rev t)[t.length - (i' + 1)]! =(rev t)[t.length - (i' + 1)] :=by{
713
+ exact getElem!_pos (rev t) (t.length - (i' + 1)) hlt
714
+ }
715
+ have hrlen: (rev t ++ [h]).length>(rev t).length:=by {
716
+ exact
717
+ List.get_of_append_proof rfl rfl
718
+ }
719
+ have hrlt: t.length - (i' + 1)<(rev t ++ [h]).length :=by{
720
+ omega
721
+ }
722
+ have hr': (rev t ++ [h])[t.length - (i' + 1)]! =(rev t ++ [h])[t.length - (i' + 1)] :=by{
723
+ refine getElem!_pos (rev t ++[h]) (t.length - (i' + 1)) ?_
724
+
725
+ }
726
+ simp[hr',hl']
727
+ refine Eq.symm (List.getElem_append_left (as:= rev t) (bs:=[h]) ?_)
728
+ omega
729
+ }
730
+ omega
731
+
732
+
733
+ }
734
+
735
+ }
736
+
737
+
738
+ def maxProp(xs:List Int)(x:Int):=
739
+ x∈ xs ∧∀ y∈ xs, x≥ y
740
+
741
+ def findMaxA (xs: List Int): Option <| Subtype <| maxProp xs :=
742
+ match hm: xs.attach with
743
+ |[]=>none
744
+ |h::t=>
745
+
746
+ let rec helper (curr: {y//y∈ xs})(rest:List {y//y∈ xs})
747
+ :{y//y∈ xs ∧ ∀ y'∈ curr::rest, y'<=y}:=
748
+ match rest with
749
+ |[]=> ⟨curr, by simp[maxProp,curr.2]⟩
750
+ |rh::rt=>
751
+ let newmax:= if rh.val>curr.val then rh else curr
752
+ let r:=helper newmax rt
753
+ have ih:=r.2
754
+ have ihr:=ih.right
755
+ ⟨ r, by {
756
+ simp[ih]
757
+
758
+ have:=ihr newmax (by simp)
759
+ have hgeq: newmax.val>=curr.val∧ newmax.val >=rh.val:=by{
760
+ simp[newmax]
761
+ split <;> constructor<;> try simp
762
+ next hsplit=> exact le_of_lt hsplit
763
+ next hsplit=>simp at hsplit; exact hsplit
764
+ }
765
+ constructor
766
+ omega
767
+ constructor
768
+ omega
769
+ intro a b hab
770
+ have:=ihr ⟨ a,b⟩ (by simp[hab])
771
+ simp[this]
772
+ }⟩
773
+
774
+ let res:=helper h t
775
+ have ih:=res.2
776
+ have ihr:=ih.right
777
+ some ⟨ res, by {
778
+ simp[maxProp,ih]
779
+ intro y yh
780
+ let yy:{x//x∈xs}:=⟨ y,yh⟩
781
+ have hin:yy∈ h::t :=by{
782
+ rw[← hm]
783
+ exact List.mem_attach xs yy
784
+ }
785
+ have:= ihr yy hin
786
+ simp[this]
787
+ }⟩
788
+
789
+ def findMax (xs : List Int) : Option Int
790
+ := match xs with
791
+ |[]=>none
792
+ |h::t=> findMaxA (h::t)
793
+
794
+
795
+ theorem findMax_correct(x: Int) (xs : List Int):
796
+ ∃ max∈ (x::xs),
797
+ And (findMax (x::xs) = some max) (∀ y ∈ (x::xs) , y ≤ max)
798
+ :=by
799
+ simp only[findMax,pure]
800
+ have hsome: findMaxA (x::xs)|>.isSome :=by exact rfl
801
+ match hm: findMaxA (x::xs) with
802
+ |none=>contradiction
803
+ |some y=>
804
+ use y
805
+ simp
806
+ have:=y.2
807
+ simp[maxProp] at this
808
+ exact this
809
+
810
+
811
+
812
+ theorem findMax_base : findMax [] = none
813
+ :=by
814
+ unfold findMax
815
+ simp only [findMaxA]
816
+
817
+ abbrev minSol(xs:List Int):=
818
+ {x:Int//x∈xs ∧ ∀ y∈ xs, y>=x}
819
+
820
+ def findMinTyped (xs : List Int)
821
+ : {r:Option (minSol xs) // r=none ↔ xs=[]}
822
+ :=match hm:xs with
823
+ |[]=> ⟨ none, by simp⟩
824
+ |h::t=>
825
+ let rest:=findMinTyped t
826
+ match hr: rest with
827
+ |⟨ none, hn⟩ =>
828
+ let sol:minSol (h::t) :=⟨ h, by simp[hm]; simp at hn; simp[hn] ⟩
829
+ ⟨ some sol, by simp ⟩
830
+ |⟨some r,_⟩ =>
831
+ let newmin:{y:Int//y∈ h::t∧ y≤ h ∧ y≤ r}:=if hcomp:h<r then ⟨h,by simp;omega⟩ else ⟨r,by simp[r.2];omega⟩
832
+ have ih:=r.2
833
+ let sol:minSol (h::t):=
834
+ ⟨ newmin,
835
+ by constructor;exact newmin.2.left;simp[newmin.2];intro a ha;have:=ih.right a ha; omega
836
+
837
+ ⟨ some sol, by simp⟩
838
+
839
+ def findMin (xs:List Int):Option Int
840
+ :=match xs with
841
+ |[]=>none
842
+ |h::t=>findMinTyped (h::t) |>.val
843
+
844
+ theorem findMin_correct(x: Int) (xs : List Int):
845
+ ∃ min∈ (x::xs),
846
+ And (findMin (x::xs) = some min) (∀ y ∈ (x::xs) , y >= min)
847
+ :=by
848
+ simp only [findMin,pure]
849
+ --have hsome: findMinTyped (x::xs)|>.val.isSome :=by sorry
850
+ match hm: findMinTyped (x::xs) with
851
+ |⟨ none, hn⟩ =>simp at hn
852
+ |⟨ some y,_⟩ =>
853
+ use y
854
+ simp
855
+ have :=y.2
856
+ constructor;simpa using this.left;simpa using this.right
857
+
858
+ theorem findMin_base : findMin [] = none
859
+ :=by exact rfl
860
+
861
+ def isIn (x:Int) (xs: List Int):Bool
862
+ := match xs with
863
+ |[] => false
864
+ |h::t => x==h || isIn x t
865
+
866
+ def isIn_correct (x:Int)(xs:List Int):
867
+ isIn x xs = true ↔ x∈ xs := by{
868
+ induction xs with
869
+ |nil=> simp[isIn]
870
+ |cons h t ih=> simp[isIn,ih]
871
+ }
872
+
873
+
874
+ def countEq (x:Int)(xs:List Int):Nat
875
+ := match xs with
876
+ |[]=>0
877
+ |h::t =>
878
+ let c:= if h=x then 1 else 0
879
+ (countEq x t) + c
880
+
881
+ def countEq_correct (x:Int)(xs:List Int):
882
+ List.count x xs = countEq x xs
883
+ :=by{
884
+ induction xs with
885
+ |nil =>rfl
886
+ |cons h t ih=>
887
+ simp[countEq]
888
+ have lem:=List.count_cons x h t
889
+ rw[← ih]
890
+ rw[lem]
891
+ simp
892
+ }
893
+
894
+ def findIfT(xs:List Int)(p:Int->Bool)
895
+ :{oi:Option Int//
896
+ if (∃ x∈ xs, p x) then ∃ y∈ xs, oi=some y ∧ p y
897
+ else oi=none}
898
+ :=match xs with
899
+ |[]=>⟨ none, by exact rfl⟩
900
+ |h::t=>
901
+ if hp: (p h=true) then
902
+ ⟨ some h, by simp[hp]⟩
903
+ else
904
+ let rest:=findIfT t p
905
+ ⟨ rest, by simp[hp,rest.2]⟩
906
+
907
+ def findIf(xs:List Int)(p:Int->Bool):Option Int
908
+ :=findIfT xs p
909
+
910
+ theorem findIf_some(xs:List Int)(p:Int->Bool):
911
+ (∃ x∈ xs, p x) -> ∃ y∈ xs, findIf xs p=some y ∧ p y
912
+ :=by
913
+ simp only [findIf]
914
+ have:=(findIfT xs p).2
915
+ intro h
916
+ simp[h] at this
917
+ exact this
918
+
919
+
920
+ theorem findIf_none(xs:List Int)(p:Int->Bool):
921
+ (¬ ∃ y∈ xs, p y =true)-> findIf xs p=none
922
+ :=by
923
+ simp only [findIf]
924
+ have:=(findIfT xs p).2
925
+ intro h
926
+ simp[h] at this
927
+ exact this
928
+
929
+ def filterIf(xs:List Int)(p:Int->Bool):List Int
930
+ :=
931
+ match xs with
932
+ |[] => []
933
+ |h::t =>
934
+ if p h then
935
+ h::(filterIf t p)
936
+ else
937
+ filterIf t p
938
+
939
+
940
+ theorem filterIf_correct(xs:List Int)(p:Int->Bool):
941
+ filterIf xs p = List.filter p xs
942
+ :=by
943
+ induction xs with
944
+ |nil=> simp[filterIf]
945
+ |cons h t ih=>
946
+ simp[List.filter_cons]
947
+ simp[filterIf]
948
+ rw[ih]
949
+
950
+ def mapInt(xs:List Int)(f:Int->Int):List Int
951
+ :=match xs with
952
+ |[]=>[]
953
+ |h::t=> (f h) :: (mapInt t f)
954
+
955
+ theorem mapInt_correct(xs:List Int)(f:Int->Int)
956
+ : (mapInt xs f).length=xs.length
957
+ ∧ ∀ i:Fin xs.length, (mapInt xs f)[i]! = f xs[i]
958
+ :=by
959
+ induction xs with
960
+ |nil=>simp[mapInt]
961
+ |cons h t ih=>
962
+ have hsize:(mapInt (h :: t) f).length = (h :: t).length :=by{
963
+ simp[mapInt,ih]
964
+ }
965
+ constructor
966
+ · exact hsize
967
+ · {
968
+ intro i
969
+ have hil:i<(mapInt (h :: t) f).length :=by{
970
+ simp[hsize]
971
+ }
972
+ have: (mapInt (h :: t) f)[i]! =(mapInt (h :: t) f)[i] :=by{
973
+ exact getElem!_pos (mapInt (h :: t) f) i hil
974
+ }
975
+ rw[this]
976
+ rcases i with ⟨i',hi⟩
977
+ cases i'
978
+ next=>
979
+ simp[mapInt]
980
+
981
+ next n=>
982
+ simp[mapInt]
983
+ have:=ih.right ⟨ n,by simp at hi;exact hi⟩
984
+ simp at this
985
+ rw[← this]
986
+ symm
987
+ exact getElem!_pos (mapInt t f) n (by simp at hi; omega)
988
+
989
+ }
990
+
991
+ def isPrefix (p xs:List α):=
992
+ List.take p.length xs = p
993
+
994
+ /- longest common prefix for a pair of lists-/
995
+ def lcpPair(xs ys:List Int )
996
+ :{zs:List Int//isPrefix zs xs∧ isPrefix zs ys
997
+ ∧ (∀zz, isPrefix zz xs∧ isPrefix zz ys->zz.length<=zs.length)}
998
+ :=match xs,ys with
999
+ |[],_=>⟨ [],by simp[isPrefix]⟩
1000
+ |_,[]=>⟨ [],by simp[isPrefix]⟩
1001
+ |xh::xt, yh::yt=>
1002
+ if heq: xh=yh then
1003
+ let rest:=lcpPair xt yt
1004
+ ⟨ xh:: rest,
1005
+ by{
1006
+ have:=rest.2
1007
+ constructor
1008
+ · simpa[isPrefix,rest,heq] using this.1
1009
+ · {
1010
+ constructor
1011
+ · simpa[isPrefix,rest,heq] using this.2.1
1012
+ ·{
1013
+ intros zz hxy
1014
+ cases zz
1015
+ next=>
1016
+ have: ([]:List Int).length=0:=by exact rfl
1017
+ rw[this]
1018
+ omega
1019
+ next h t=>
1020
+ simp[isPrefix] at hxy
1021
+ have ih:=this.2.2
1022
+ have ht:isPrefix t xt∧ isPrefix t yt:=by {
1023
+ simp[isPrefix,hxy]
1024
+ }
1025
+ have ihh:=ih _ ht
1026
+ simp[ihh]
1027
+ }
1028
+ }
1029
+
1030
+ }
1031
+
1032
+ else
1033
+ ⟨ [],
1034
+ by {
1035
+ simp[isPrefix]
1036
+ intros zz hx hy
1037
+ cases zz
1038
+ next=>rfl
1039
+ next h t=>
1040
+ simp at hx
1041
+ simp at hy
1042
+ have : xh=yh :=by simp[hx,hy]
1043
+ contradiction
1044
+ }
1045
+
easy.jsonl ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"description": "write a function that, given integers a and b, returns an integer x such that a + x = b", "function_signature": "def solveAdd (a b:Int): Int", "test_cases": null, "theorem_signature": "theorem solveAdd_correct (a b: Int): a + (solveAdd a b) =b ", "theorem2_signature": null}
2
+ {"description": "write a function that, given integer a, returns an integer x such that a + x = 0", "function_signature": "def solveAdd0(a:Int): Int", "test_cases": null, "theorem_signature": "theorem solveAdd0_correct(a: Int): a +(solveAdd0 a)=0", "theorem2_signature": null}
3
+ {"description": "write a function that, given integers a and b, returns an integer x such that a - x = b", "function_signature": "def solveSub(a b:Int): Int", "test_cases": null, "theorem_signature": "theorem solveSub_correct(a b:Int): a - (solveSub a b)=b", "theorem2_signature": null}
4
+ {"description": "write a function that, given rationals a and b, return some x such that a*x=b. if no solution exists, return none", "function_signature": "def solve1x1(a b: Rat): Option Rat", "test_cases": null, "theorem_signature": "theorem solve1x1_correct(a b:Rat): (∃ x, a*x=b) -> a * (solve1x1 a b).get! =b", "theorem2_signature": "theorem solve1x1_none(a b:Rat): (Not (∃ x, a*x=b)) -> solve1x1 a b=none"}
5
+ {"description": "write a function that, given rational a, returns a rational x such that a*x=1. If no solution exists, return 0.", "function_signature": "def solveMul(a: Rat): Rat", "test_cases": null, "theorem_signature": "theorem solveMul_correct(a:Rat): (∃ x, a*x=1)->a * (solveMul a)=1", "theorem2_signature": "theorem solveMul_nosol (a:Rat): (Not (∃ x, a*x=1)) ->solveMul a =0"}
6
+ {"description": "write a function that, given rationals a and b, both not equal to zero, return x such that a/x=b.", "function_signature": "def solveDiv(a b:Rat) (ha: a≠ 0)(hb: b≠ 0): Rat", "test_cases": null, "theorem_signature": "theorem solveDiv_correct(a b:Rat)(ha:a≠ 0)(hb: b≠ 0):\na / (solveDiv a b ha hb)= b", "theorem2_signature": null}
7
+ {"description": "write a function isPrime that given a natural number a, returns true if and only if a is prime.", "function_signature": "def isPrime(a: Nat): Bool", "test_cases": null, "theorem_signature": "theorem isPrime_correct(a: Nat): (isPrime a)=True <-> Nat.Prime a", "theorem2_signature": null}
8
+ {"description": "write a function that given a natrual number a and a prime number p, returns a natural number x such that (a*x)%p=1. if no solution exists, return none.", "function_signature": "def modInv(a: Nat) (p:Nat)(hp:p.Prime): Option Nat", "test_cases": null, "theorem_signature": "\ntheorem modInv_correct(a:Nat) (p:Nat)(hp:p.Prime):\n (∃ x:Nat, (a*x)%p=1)->(a*(modInv a p hp).get!)%p=1", "theorem2_signature": "theorem modInv_none(a:Nat) (p:Nat)(hp:p.Prime): (Not (∃ x, (a*x)%p=1))-> modInv a p hp=none"}
9
+ {"description": "write a function that given a natural number a, a>1, find the minimum factor of a that is not 1. ", "function_signature": "def minFac(a:Nat) (h: a>1): Nat ", "test_cases": null, "theorem_signature": "theorem minFac_isfac(a:Nat)(h: a>1): ( (minFac a h) ∣a) ∧(minFac a h>1)", "theorem2_signature": "theorem minFac_ismin(a:Nat)(h:a>1): Not (∃ y>1,( y ∣ a) ∧y<minFac a h)"}
10
+ {"description": "write a function that, given rational number coordinates of two points x1, y1 and x2, y2, return the rational number coordinates of a point (xmid, ymid) such that: the distance betwee (xmid,ymid) and (x1, y1) is equal to the distance between (xmid,ymid) and (x2,y2), which is equal to half of the distance between (x1, y1) and (x2, y2).", "function_signature": "def midPoint (x1 y1 x2 y2: Rat):Rat × Rat", "test_cases": null, "theorem_signature": "def distSq( x1 y1 x2 y2: Rat):Rat:=\n (x1-x2)^2 + (y1-y2)^2\n\ntheorem midPoint_correct (x1 y1 x2 y2: Rat)\n: let (xmid,ymid) :=midPoint x1 y1 x2 y2\ndistSq xmid ymid x1 y1=distSq xmid ymid x2 y2\n∧ 4*(distSq xmid ymid x1 y1)=distSq x1 y1 x2 y2", "theorem2_signature": null}
11
+ {"description": "write a function that, given natural numbers a and b, computes their greatest common denominator.", "function_signature": "def GCD(a b:Nat):Nat", "test_cases": null, "theorem_signature": "\ntheorem gcd_is_div (x y: Nat):\n (p: x > 0)→ ((GCD x y) ∣ x) ∧ ((GCD x y) ∣ y)", "theorem2_signature": "\ntheorem gcd_is_greatest (x y: Nat):\n (x>0) → Not (∃ z: Nat, z∣ x ∧ z∣ y ∧ z> GCD x y )"}
12
+ {"description": "write a function that, given natural number t, find the minimum n such that 1+2+…+n>=t.", "function_signature": "def solveProg(t:Nat):Nat", "test_cases": null, "theorem_signature": "theorem solveProg_isgeq(t:Nat): (solveProg t)*((solveProg t)+1) >= t*2", "theorem2_signature": "theorem solveProg_ismin(t:Nat): Not (∃ y< (solveProg t), y*(y+1)>=t*2)"}
13
+ {"description": "write a function that, given natural numbers a and t, with a>1, find the minimum n such that a^0+a^1+..a^n >=t.", "function_signature": "def solveGeom(a t:Nat)(h:a>1):Nat", "test_cases": null, "theorem_signature": "theorem solveGeom_isgeq(a t:Nat)(h:a>1): a^((solveGeom a t h)+1)-1 >=t*(a-1)", "theorem2_signature": "theorem solveGeom_ismin(a t:Nat)(h:a>1): Not (∃ y<solveGeom a t h, a^(y+1)-1>= t*(a-1))"}
14
+ {"description": "write a function that, given natural number t, find the minimum n such that n*n>=t.", "function_signature": "def solveSquare(t:Nat): Nat", "test_cases": null, "theorem_signature": "theorem solveSquare_isgeq(t:Nat): (solveSquare t)*(solveSquare t)>=t", "theorem2_signature": "theorem solveSquare_ismin(t:Nat): Not (∃ y< (solveSquare t), y*y>=t)"}
15
+ {"description": "Implement the following in lean 4. Given a binary operator op, we define the function f : Nat->Nat to be: f 0 =1; f 1=1; f n = op (f (n-1)) (f (n-2)). Write a lean 4 function that, given the op and the natural number n as arguments, computes f n. Additionally, op returns a value wrapped in a monad. Your function should have the signature def f [Monad m] (op: Nat->Nat->(m Nat)) (n: Nat): (m Nat) :=", "function_signature": "def f[Monad m] (op: Nat->Nat->(m Nat)) (n: Nat): (m Nat)", "test_cases": null, "theorem_signature": "theorem f_base (op : Nat → Nat → Id Nat) :\n (f op 0 = pure 1) ∧ (f op 1 = pure 1)", "theorem2_signature": "theorem f_recursive (op : Nat → Nat → Id Nat) (n : Nat) : f op (n+2) =do {op (← f op (n+1)) (← f op n) }"}
16
+ {"description": "write a function that, given a List of integers, return the list in reverse order.", "function_signature": "def rev(xs: List Int): List Int", "test_cases": null, "theorem_signature": "theorem reverse_correct(xs:List Int):\n xs.length=(rev xs).length ∧\n ∀ i<xs.length, xs[i]! =(rev xs)[xs.length-1-i]!", "theorem2_signature": null}
17
+ {"description": "write a function that, given a List of integers, finds its maximum", "function_signature": "def findMax (xs : List Int) : Option Int ", "test_cases": null, "theorem_signature": "\ntheorem findMax_correct(x: Int) (xs : List Int):\n ∃ max∈ (x::xs),\n And (findMax (x::xs) = some max) (∀ y ∈ (x::xs) , y ≤ max) ", "theorem2_signature": "theorem findMax_base : findMax [] = none"}
18
+ {"description": "write a function that, given a List of integers, finds the minimum", "function_signature": "def findMin (xs : List Int) : Option Int ", "test_cases": null, "theorem_signature": "\ntheorem findMin_correct(x: Int) (xs : List Int):\n ∃ min∈ (x::xs),\n And (findMin (x::xs) = some min) (∀ y ∈ (x::xs) , y >= min) ", "theorem2_signature": "theorem findMin_base : findMin [] = none"}
19
+ {"description": "write a function that, given an integer x and a List of integers, returns true if and only if x is in the List", "function_signature": "def isIn (x:Int) (xs: List Int):Bool", "test_cases": null, "theorem_signature": "def isIn_correct (x:Int)(xs:List Int):\n isIn x xs = true ↔ x∈ xs", "theorem2_signature": null}
20
+ {"description": "write a function that, given an integer x and a List of integers, returns the number of times that x appears in the list.", "function_signature": "\ndef countEq (x:Int)(xs:List Int):Nat", "test_cases": null, "theorem_signature": "def countEq_correct (x:Int)(xs:List Int):\n List.count x xs = countEq x xs", "theorem2_signature": null}
21
+ {"description": "write a function that, given a List of integers and a predicate function p that takes an integer and returns a boolean, returns an element of the list x if p x = true. If such x does not exist, return none", "function_signature": "def findIf(xs:List Int)(p:Int->Bool):Option Int", "test_cases": null, "theorem_signature": "\ntheorem findIf_some(xs:List Int)(p:Int->Bool):\n (∃ x∈ xs, p x) -> ∃ y∈ xs, findIf xs p=some y ∧ p y", "theorem2_signature": "\ntheorem findIf_none(xs:List Int)(p:Int->Bool):\n (¬ ∃ y∈ xs, p y =true)-> findIf xs p=none "}
22
+ {"description": "write a function that, given a List of integers and a predicate function p that takes an integer and returns a boolean, returns another list consisting of elements x of the original list such that p x = true.", "function_signature": "def filterIf(xs:List Int)(p:Int->Bool):List Int", "test_cases": null, "theorem_signature": "\ntheorem filterIf_correct(xs:List Int)(p:Int->Bool):\n filterIf xs p = List.filter p xs", "theorem2_signature": null}
23
+ {"description": "write a function that, given a List of integers xs and a function f:Int->Int, returns a List of integers whose i-th element is f xs[i]", "function_signature": "def mapInt(xs:List Int)(f:Int->Int):List Int", "test_cases": null, "theorem_signature": "theorem mapInt_correct(xs:List Int)(f:Int->Int)\n: (mapInt xs f).length=xs.length\n∧ ∀ i:Fin xs.length, (mapInt xs f)[i]! = f xs[i]", "theorem2_signature": null}
24
+ {"description": "Write a function that, given two lists of integers, find their longest common prefix.", "function_signature": "def isPrefix (p xs:List α):=\n List.take p.length xs = p\n\n/- longest common prefix for a pair of lists-/\ndef lcpPair:(xs ys:List Int )\n->{zs:List Int//isPrefix zs xs∧ isPrefix zs ys\n ∧ (∀zz, isPrefix zz xs∧ isPrefix zz ys->zz.length<=zs.length)}", "test_cases": null, "theorem_signature": null, "theorem2_signature": null}