-
Notifications
You must be signed in to change notification settings - Fork 298
/
tactics.lean
747 lines (637 loc) · 18.3 KB
/
tactics.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Scott Morrison
-/
import tactic data.set.lattice data.prod data.vector
tactic.rewrite data.stream.basic
tactic.tfae tactic.converter.interactive
tactic.ring tactic.ring2
section tauto₀
variables p q r : Prop
variables h : p ∧ q ∨ p ∧ r
include h
example : p ∧ p :=
by tauto
end tauto₀
section tauto₁
variables α : Type
variables p q r : α → Prop
variables h : (∃ x, p x ∧ q x) ∨ (∃ x, p x ∧ r x)
include h
example : ∃ x, p x :=
by tauto
end tauto₁
section tauto₂
variables α : Type
variables x : α
variables p q r : α → Prop
variables h₀ : (∀ x, p x → q x → r x) ∨ r x
variables h₁ : p x
variables h₂ : q x
include h₀ h₁ h₂
example : ∃ x, r x :=
by tauto
end tauto₂
section tauto₃
example (p : Prop) : p ∧ true ↔ p := by tauto
example (p : Prop) : p ∨ false ↔ p := by tauto
example (p q r : Prop) [decidable p] [decidable r] : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (r ∨ p ∨ r) := by tauto
example (p q r : Prop) [decidable q] [decidable r] : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (r ∨ p ∨ r) := by tauto
example (p q : Prop) [decidable q] [decidable p] (h : ¬ (p ↔ q)) (h' : ¬ p) : q := by tauto
example (p q : Prop) [decidable q] [decidable p] (h : ¬ (p ↔ q)) (h' : p) : ¬ q := by tauto
example (p q : Prop) [decidable q] [decidable p] (h : ¬ (p ↔ q)) (h' : q) : ¬ p := by tauto
example (p q : Prop) [decidable q] [decidable p] (h : ¬ (p ↔ q)) (h' : ¬ q) : p := by tauto
example (p q : Prop) [decidable q] [decidable p] (h : ¬ (p ↔ q)) (h' : ¬ q) (h'' : ¬ p) : false := by tauto
example (p q r : Prop) [decidable q] [decidable p] (h : p ↔ q) (h' : r ↔ q) (h'' : ¬ r) : ¬ p := by tauto
example (p q r : Prop) (h : p ↔ q) (h' : r ↔ q) : p ↔ r :=
by tauto!
example (p q r : Prop) (h : ¬ p = q) (h' : r = q) : p ↔ ¬ r := by tauto!
section modulo_symmetry
variables {p q r : Prop} {α : Type} {x y : α}
variables (h : x = y)
variables (h'' : (p ∧ q ↔ q ∨ r) ↔ (r ∧ p ↔ r ∨ q))
include h
include h''
example (h' : ¬ y = x) : p ∧ q := by tauto
example (h' : p ∧ ¬ y = x) : p ∧ q := by tauto
example : y = x := by tauto
example (h' : ¬ x = y) : p ∧ q := by tauto
example : x = y := by tauto
end modulo_symmetry
end tauto₃
section wlog
example {x y : ℕ} (a : x = 1) : true :=
begin
suffices : false, trivial,
wlog h : x = y,
{ guard_target x = y ∨ y = x,
admit },
{ guard_hyp h := x = y,
guard_hyp a := x = 1,
admit }
end
example {x y : ℕ} : true :=
begin
suffices : false, trivial,
wlog h : x ≤ y,
{ guard_hyp h := x ≤ y,
guard_target false,
admit }
end
example {x y z : ℕ} : true :=
begin
suffices : false, trivial,
wlog : x ≤ y + z using x y,
{ guard_target x ≤ y + z ∨ y ≤ x + z,
admit },
{ guard_hyp case := x ≤ y + z,
guard_target false,
admit },
end
example {x : ℕ} (S₀ S₁ : set ℕ) (P : ℕ → Prop)
(h : x ∈ S₀ ∪ S₁) : true :=
begin
suffices : false, trivial,
wlog h' : x ∈ S₀ using S₀ S₁,
{ guard_target x ∈ S₀ ∨ x ∈ S₁,
admit },
{ guard_hyp h := x ∈ S₀ ∪ S₁,
guard_hyp h' := x ∈ S₀,
admit }
end
example {n m i : ℕ} {p : ℕ → ℕ → ℕ → Prop} : true :=
begin
suffices : false, trivial,
wlog : p n m i using [n m i, n i m, i n m],
{ guard_target p n m i ∨ p n i m ∨ p i n m,
admit },
{ guard_hyp case := p n m i,
admit }
end
example {n m i : ℕ} {p : ℕ → Prop} : true :=
begin
suffices : false, trivial,
wlog : p n using [n m i, m n i, i n m],
{ guard_target p n ∨ p m ∨ p i,
admit },
{ guard_hyp case := p n,
admit }
end
example {n m i : ℕ} {p : ℕ → ℕ → Prop} {q : ℕ → ℕ → ℕ → Prop} : true :=
begin
suffices : q n m i, trivial,
have h : p n i ∨ p i m ∨ p m i, from sorry,
wlog : p n i := h using n m i,
{ guard_hyp h := p n i,
guard_target q n m i,
admit },
{ guard_hyp h := p i m,
guard_hyp this := q i m n,
guard_target q n m i,
admit },
{ guard_hyp h := p m i,
guard_hyp this := q m i n,
guard_target q n m i,
admit },
end
example (X : Type) (A B C : set X) : A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) :=
begin
ext x,
split,
{ intro hyp,
cases hyp,
wlog x_in : x ∈ B using B C,
{ assumption },
{ exact or.inl ⟨hyp_left, x_in⟩ } },
{ intro hyp,
wlog x_in : x ∈ A ∩ B using B C,
{ assumption },
{ exact ⟨x_in.left, or.inl x_in.right⟩ } }
end
example (X : Type) (A B C : set X) : A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) :=
begin
ext x,
split,
{ intro hyp,
wlog x_in : x ∈ B := hyp.2 using B C,
{ exact or.inl ⟨hyp.1, x_in⟩ } },
{ intro hyp,
wlog x_in : x ∈ A ∩ B := hyp using B C,
{ exact ⟨x_in.left, or.inl x_in.right⟩ } }
end
example (X : Type) (A B C : set X) : A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) :=
begin
ext x,
split,
{ intro hyp,
cases hyp,
wlog x_in : x ∈ B := hyp_right using B C,
{ exact or.inl ⟨hyp_left, x_in⟩ }, },
{ intro hyp,
wlog x_in : x ∈ A ∩ B := hyp using B C,
{ exact ⟨x_in.left, or.inl x_in.right⟩ } }
end
end wlog
example (m n p q : nat) (h : m + n = p) : true :=
begin
have : m + n = q,
{ generalize_hyp h' : m + n = x at h,
guard_hyp h' := m + n = x,
guard_hyp h := x = p,
guard_target m + n = q,
admit },
have : m + n = q,
{ generalize_hyp h' : m + n = x at h ⊢,
guard_hyp h' := m + n = x,
guard_hyp h := x = p,
guard_target x = q,
admit },
trivial
end
example (α : Sort*) (L₁ L₂ L₃ : list α)
(H : L₁ ++ L₂ = L₃) : true :=
begin
have : L₁ ++ L₂ = L₂,
{ generalize_hyp h : L₁ ++ L₂ = L at H,
induction L with hd tl ih,
case list.nil
{ tactic.cleanup,
change list.nil = L₃ at H,
admit },
case list.cons
{ change list.cons hd tl = L₃ at H,
admit } },
trivial
end
section convert
open set
variables {α β : Type}
local attribute [simp]
private lemma singleton_inter_singleton_eq_empty {x y : α} :
({x} ∩ {y} = (∅ : set α)) ↔ x ≠ y :=
by simp [singleton_inter_eq_empty]
example {f : β → α} {x y : α} (h : x ≠ y) : f ⁻¹' {x} ∩ f ⁻¹' {y} = ∅ :=
begin
have : {x} ∩ {y} = (∅ : set α) := by simpa using h,
convert preimage_empty,
rw [←preimage_inter,this],
end
end convert
section rcases
universe u
variables {α β γ : Type u}
example (x : α × β × γ) : true :=
begin
rcases x with ⟨a, b, c⟩,
{ guard_hyp a := α,
guard_hyp b := β,
guard_hyp c := γ,
trivial }
end
example (x : α × β × γ) : true :=
begin
rcases x with ⟨a, ⟨b, c⟩⟩,
{ guard_hyp a := α,
guard_hyp b := β,
guard_hyp c := γ,
trivial }
end
example (x : (α × β) × γ) : true :=
begin
rcases x with ⟨⟨a, b⟩, c⟩,
{ guard_hyp a := α,
guard_hyp b := β,
guard_hyp c := γ,
trivial }
end
example (x : inhabited α × option β ⊕ γ) : true :=
begin
rcases x with ⟨⟨a⟩, _ | b⟩ | c,
{ guard_hyp a := α, trivial },
{ guard_hyp a := α, guard_hyp b := β, trivial },
{ guard_hyp c := γ, trivial }
end
example (x y : ℕ) (h : x = y) : true :=
begin
rcases x with _|⟨⟩|z,
{ guard_hyp h := nat.zero = y, trivial },
{ guard_hyp h := nat.succ nat.zero = y, trivial },
{ guard_hyp z := ℕ,
guard_hyp h := z.succ.succ = y, trivial },
end
-- from equiv.sum_empty
example (s : α ⊕ empty) : true :=
begin
rcases s with _ | ⟨⟨⟩⟩,
{ guard_hyp s := α, trivial }
end
end rcases
section ext
@[extensionality] lemma unit.ext (x y : unit) : x = y :=
begin
cases x, cases y, refl
end
example : subsingleton unit :=
begin
split, intros, ext
end
example (x y : ℕ) : true :=
begin
have : x = y,
{ ext <|> admit },
have : x = y,
{ ext i <|> admit },
have : x = y,
{ ext : 1 <|> admit },
trivial
end
example (X Y : ℕ × ℕ) (h : X.1 = Y.1) (h : X.2 = Y.2) : X = Y :=
begin
ext; assumption
end
example (X Y : (ℕ → ℕ) × ℕ) (h : ∀ i, X.1 i = Y.1 i) (h : X.2 = Y.2) : X = Y :=
begin
ext x; solve_by_elim,
end
example (X Y : ℕ → ℕ × ℕ) (h : ∀ i, X i = Y i) : true :=
begin
have : X = Y,
{ ext i : 1,
guard_target X i = Y i,
admit },
have : X = Y,
{ ext i,
guard_target (X i).fst = (Y i).fst, admit,
guard_target (X i).snd = (Y i).snd, admit, },
have : X = Y,
{ ext : 1,
guard_target X x = Y x,
admit },
trivial,
end
example (s₀ s₁ : set ℕ) (h : s₁ = s₀) : s₀ = s₁ :=
by { ext1, guard_target x ∈ s₀ ↔ x ∈ s₁, simp * }
example (s₀ s₁ : stream ℕ) (h : s₁ = s₀) : s₀ = s₁ :=
by { ext1, guard_target s₀.nth n = s₁.nth n, simp * }
example (s₀ s₁ : ℤ → set (ℕ × ℕ))
(h : ∀ i a b, (a,b) ∈ s₀ i ↔ (a,b) ∈ s₁ i) : s₀ = s₁ :=
begin
ext i ⟨a,b⟩,
apply h
end
def my_foo {α} (x : semigroup α) (y : group α) : true := trivial
example {α : Type} : true :=
begin
have : true,
{ refine_struct (@my_foo α { .. } { .. } ),
-- 9 goals
guard_tags _field mul semigroup, admit,
-- case semigroup, mul
-- α : Type
-- ⊢ α → α → α
guard_tags _field mul_assoc semigroup, admit,
-- case semigroup, mul_assoc
-- α : Type
-- ⊢ ∀ (a b c : α), a * b * c = a * (b * c)
guard_tags _field mul group, admit,
-- case group, mul
-- α : Type
-- ⊢ α → α → α
guard_tags _field mul_assoc group, admit,
-- case group, mul_assoc
-- α : Type
-- ⊢ ∀ (a b c : α), a * b * c = a * (b * c)
guard_tags _field one group, admit,
-- case group, one
-- α : Type
-- ⊢ α
guard_tags _field one_mul group, admit,
-- case group, one_mul
-- α : Type
-- ⊢ ∀ (a : α), 1 * a = a
guard_tags _field mul_one group, admit,
-- case group, mul_one
-- α : Type
-- ⊢ ∀ (a : α), a * 1 = a
guard_tags _field inv group, admit,
-- case group, inv
-- α : Type
-- ⊢ α → α
guard_tags _field mul_left_inv group, admit,
-- case group, mul_left_inv
-- α : Type
-- ⊢ ∀ (a : α), a⁻¹ * a = 1
},
trivial
end
def my_bar {α} (x : semigroup α) (y : group α) (i j : α) : α := i
example {α : Type} : true :=
begin
have : monoid α,
{ refine_struct { mul := my_bar { .. } { .. } },
guard_tags _field mul semigroup, admit,
guard_tags _field mul_assoc semigroup, admit,
guard_tags _field mul group, admit,
guard_tags _field mul_assoc group, admit,
guard_tags _field one group, admit,
guard_tags _field one_mul group, admit,
guard_tags _field mul_one group, admit,
guard_tags _field inv group, admit,
guard_tags _field mul_left_inv group, admit,
guard_tags _field mul_assoc monoid, admit,
guard_tags _field one monoid, admit,
guard_tags _field one_mul monoid, admit,
guard_tags _field mul_one monoid, admit, },
trivial
end
structure dependent_fields :=
(a : bool)
(v : if a then ℕ else ℤ)
@[extensionality] lemma df.ext (s t : dependent_fields) (h : s.a = t.a)
(w : (@eq.rec _ s.a (λ b, if b then ℕ else ℤ) s.v t.a h) = t.v): s = t :=
begin
cases s, cases t,
dsimp at *,
congr,
exact h,
subst h,
simp,
simp at w,
exact w,
end
example (s : dependent_fields) : s = s :=
begin
tactic.ext1 [] {tactic.apply_cfg . new_goals := tactic.new_goals.all},
guard_target s.a = s.a,
refl,
refl,
end
end ext
section apply_rules
example {a b c d e : nat} (h1 : a ≤ b) (h2 : c ≤ d) (h3 : 0 ≤ e) :
a + c * e + a + c + 0 ≤ b + d * e + b + d + e :=
add_le_add (add_le_add (add_le_add (add_le_add h1 (mul_le_mul_of_nonneg_right h2 h3)) h1 ) h2) h3
example {a b c d e : nat} (h1 : a ≤ b) (h2 : c ≤ d) (h3 : 0 ≤ e) :
a + c * e + a + c + 0 ≤ b + d * e + b + d + e :=
by apply_rules [add_le_add, mul_le_mul_of_nonneg_right]
@[user_attribute]
meta def mono_rules : user_attribute :=
{ name := `mono_rules,
descr := "lemmas usable to prove monotonicity" }
attribute [mono_rules] add_le_add mul_le_mul_of_nonneg_right
example {a b c d e : nat} (h1 : a ≤ b) (h2 : c ≤ d) (h3 : 0 ≤ e) :
a + c * e + a + c + 0 ≤ b + d * e + b + d + e :=
by apply_rules [mono_rules]
example {a b c d e : nat} (h1 : a ≤ b) (h2 : c ≤ d) (h3 : 0 ≤ e) :
a + c * e + a + c + 0 ≤ b + d * e + b + d + e :=
by apply_rules mono_rules
end apply_rules
section h_generalize
variables {α β γ φ ψ : Type} (f : α → α → α → φ → γ)
(x y : α) (a b : β) (z : φ)
(h₀ : β = α) (h₁ : β = α) (h₂ : φ = β)
(hx : x == a) (hy : y == b) (hz : z == a)
include f x y z a b hx hy hz
example : f x y x z = f (eq.rec_on h₀ a) (cast h₀ b) (eq.mpr h₁.symm a) (eq.mpr h₂ a) :=
begin
guard_hyp_nums 16,
h_generalize hp : a == p with hh,
guard_hyp_nums 19,
guard_hyp' hh := β = α,
guard_target f x y x z = f p (cast h₀ b) p (eq.mpr h₂ a),
h_generalize hq : _ == q,
guard_hyp_nums 21,
guard_target f x y x z = f p q p (eq.mpr h₂ a),
h_generalize _ : _ == r,
guard_hyp_nums 23,
guard_target f x y x z = f p q p r,
casesm* [_ == _, _ = _], refl
end
end h_generalize
section h_generalize
variables {α β γ φ ψ : Type} (f : list α → list α → γ)
(x : list α) (a : list β) (z : φ)
(h₀ : β = α) (h₁ : list β = list α)
(hx : x == a)
include f x z a hx h₀ h₁
example : true :=
begin
have : f x x = f (eq.rec_on h₀ a) (cast h₁ a),
{ guard_hyp_nums 11,
h_generalize : a == p with _,
guard_hyp_nums 13,
guard_hyp' h := β = α,
guard_target f x x = f p (cast h₁ a),
h_generalize! : a == q ,
guard_hyp_nums 13,
guard_target ∀ q, f x x = f p q,
casesm* [_ == _, _ = _],
success_if_fail { refl },
admit },
trivial
end
end h_generalize
section assoc_rw
open tactic
example : ∀ x y z a b c : ℕ, true :=
begin
intros,
have : x + (y + z) = 3 + y, admit,
have : a + (b + x) + y + (z + b + c) ≤ 0,
(do this ← get_local `this,
tgt ← to_expr ```(a + (b + x) + y + (z + b + c)),
assoc ← mk_mapp ``add_monoid.add_assoc [`(ℕ),none],
(l,p) ← assoc_rewrite_intl assoc this tgt,
note `h none p ),
erw h,
guard_target a + b + 3 + y + b + c ≤ 0,
admit,
trivial
end
example : ∀ x y z a b c : ℕ, true :=
begin
intros,
have : ∀ y, x + (y + z) = 3 + y, admit,
have : a + (b + x) + y + (z + b + c) ≤ 0,
(do this ← get_local `this,
tgt ← to_expr ```(a + (b + x) + y + (z + b + c)),
assoc_rewrite_target this ),
guard_target a + b + 3 + y + b + c ≤ 0,
admit,
trivial
end
variables x y z a b c : ℕ
variables h₀ : ∀ (y : ℕ), x + (y + z) = 3 + y
variables h₁ : a + (b + x) + y + (z + b + a) ≤ 0
variables h₂ : y + b + c = y + b + a
include h₀ h₁ h₂
example : a + (b + x) + y + (z + b + c) ≤ 0 :=
by { assoc_rw [h₀,h₂] at *,
guard_hyp _inst := is_associative ℕ has_add.add,
-- keep a local instance of is_associative to cache
-- type class queries
exact h₁ }
end assoc_rw
-- section tfae
-- example (p q r s : Prop)
-- (h₀ : p ↔ q)
-- (h₁ : q ↔ r)
-- (h₂ : r ↔ s) :
-- p ↔ s :=
-- begin
-- scc,
-- end
-- example (p' p q r r' s s' : Prop)
-- (h₀ : p' → p)
-- (h₀ : p → q)
-- (h₁ : q → r)
-- (h₁ : r' → r)
-- (h₂ : r ↔ s)
-- (h₂ : s → p)
-- (h₂ : s → s') :
-- p ↔ s :=
-- begin
-- scc,
-- end
-- example (p' p q r r' s s' : Prop)
-- (h₀ : p' → p)
-- (h₀ : p → q)
-- (h₁ : q → r)
-- (h₁ : r' → r)
-- (h₂ : r ↔ s)
-- (h₂ : s → p)
-- (h₂ : s → s') :
-- p ↔ s :=
-- begin
-- scc',
-- assumption
-- end
-- example : tfae [true, ∀ n : ℕ, 0 ≤ n * n, true, true] := begin
-- tfae_have : 3 → 1, { intro h, constructor },
-- tfae_have : 2 → 3, { intro h, constructor },
-- tfae_have : 2 ← 1, { intros h n, apply nat.zero_le },
-- tfae_have : 4 ↔ 2, { tauto },
-- tfae_finish,
-- end
-- example : tfae [] := begin
-- tfae_finish,
-- end
-- end tfae
section conv
example : 0 + 0 = 0 :=
begin
conv_lhs {erw [add_zero]}
end
example : 0 + 0 = 0 :=
begin
conv_lhs {simp}
end
example : 0 = 0 + 0 :=
begin
conv_rhs {simp}
end
-- Example with ring discharging the goal
example : 22 + 7 * 4 + 3 * 8 = 0 + 7 * 4 + 46 :=
begin
conv { ring, },
end
-- Example with ring failing to discharge, to normalizing the goal
example : (22 + 7 * 4 + 3 * 8 = 0 + 7 * 4 + 47) = (74 = 75) :=
begin
conv { ring, },
end
-- Example with ring discharging the goal
example (x : ℕ) : 22 + 7 * x + 3 * 8 = 0 + 7 * x + 46 :=
begin
conv { ring, },
end
-- Example with ring failing to discharge, to normalizing the goal
example (x : ℕ) : (22 + 7 * x + 3 * 8 = 0 + 7 * x + 46 + 1)
= (7 * x + 46 = 7 * x + 47) :=
begin
conv { ring, },
end
-- norm_num examples:
example : 22 + 7 * 4 + 3 * 8 = 74 :=
begin
conv { norm_num, },
end
example (x : ℕ) : 22 + 7 * x + 3 * 8 = 7 * x + 46 :=
begin
conv { norm_num, },
end
end conv
section clear_aux_decl
example (n m : ℕ) (h₁ : n = m) (h₂ : ∃ a : ℕ, a = n ∧ a = m) : 2 * m = 2 * n :=
let ⟨a, ha⟩ := h₂ in
begin
clear_aux_decl, -- subst will fail without this line
subst h₁
end
example (x y : ℕ) (h₁ : ∃ n : ℕ, n * 1 = 2) (h₂ : 1 + 1 = 2 → x * 1 = y) : x = y :=
let ⟨n, hn⟩ := h₁ in
begin
clear_aux_decl, -- finish produces an error without this line
finish
end
end clear_aux_decl
private meta def get_exception_message (t : lean.parser unit) : lean.parser string
| s := match t s with
| result.success a s' := result.success "No exception" s
| result.exception none pos s' := result.success "Exception no msg" s
| result.exception (some msg) pos s' := result.success (msg ()).to_string s
end
@[user_command] meta def test_parser1_fail_cmd
(_ : interactive.parse (lean.parser.tk "test_parser1")) : lean.parser unit :=
do
let msg := "oh, no!",
let t : lean.parser unit := tactic.fail msg,
s ← get_exception_message t,
if s = msg then tactic.skip
else interaction_monad.fail "Message was corrupted while being passed through `lean.parser.of_tactic`"
.
-- Due to `lean.parser.of_tactic'` priority, the following *should not* fail with
-- a VM check error, and instead catch the error gracefully and just
-- run and succeed silently.
test_parser1