forked from leanprover-community/mathlib4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasic.lean
More file actions
163 lines (127 loc) · 4.95 KB
/
Copy pathBasic.lean
File metadata and controls
163 lines (127 loc) · 4.95 KB
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
module
import Mathlib.Tactic.Convert
import Mathlib.Algebra.Group.Basic
import Mathlib.Data.Set.Image
import Mathlib.Algebra.Notation.Pi.Defs
private axiom test_sorry : ∀ {α}, α
set_option autoImplicit true
namespace Tests
example (P : Prop) (h : P) : P := by convert h
example (α β : Type) (h : α = β) (b : β) : α := by
convert b
example (α β : Type) (h : ∀ α β : Type, α = β) (b : β) : α := by
convert b
apply h
example (m n : Nat) (h : m = n) (b : Fin n) : Nat × Nat × Nat × Fin m := by
convert (37, 57, 2, b)
example (α β : Type) (h : α = β) (b : β) : Nat × α := by
-- type eq ok since arguments to `Prod` are explicit
convert (37, b)
example (α β : Type) (h : β = α) (b : β) : Nat × α := by
convert ← (37, b)
example (α β : Type) (h : α = β) (b : β) : Nat × Nat × Nat × α := by
convert (37, 57, 2, b)
example (α β : Type) (h : α = β) (b : β) : Nat × Nat × Nat × α := by
convert (37, 57, 2, b) using 2
guard_target = (Nat × α) = (Nat × β)
congr!
example {f : β → α} {x y : α} (h : x ≠ y) : f ⁻¹' {x} ∩ f ⁻¹' {y} = ∅ := by
have : {x} ∩ {y} = (∅ : Set α) := by simpa [ne_comm] using h
convert Set.preimage_empty
rw [← Set.preimage_inter, this]
section convert_to
example {α} [AddCommMonoid α] {a b c d : α} (H : a = c) (H' : b = d) : a + b = d + c := by
convert_to c + d = _ using 2
rw [add_comm]
example {α} [AddCommMonoid α] {a b c d : α} (H : a = c) (H' : b = d) : a + b = d + c := by
convert_to c + d = _ -- defaults to `using 1`
congr 2
rw [add_comm]
-- Check that `using 1` gives the same behavior as the default.
example {α} [AddCommMonoid α] {a b c d : α} (H : a = c) (H' : b = d) : a + b = d + c := by
convert_to c + d = _ using 1
congr 2
rw [add_comm]
end convert_to
example (prime : Nat → Prop) (n : Nat) (h : prime (2 * n + 1)) :
prime (n + n + 1) := by
convert! h
· guard_target = (HAdd.hAdd : Nat → Nat → Nat) = HMul.hMul
exact test_sorry
· guard_target = n = 2
exact test_sorry
example (prime : Nat → Prop) (n : Nat) (h : prime (2 * n + 1)) :
prime (n + n + 1) := by
convert h
guard_target = n + n = 2 * n
exact test_sorry
example (p q : Nat → Prop) (h : ∀ ε > 0, p ε) :
∀ ε > 0, q ε := by
convert h using 2 with ε hε
guard_hyp hε : ε > 0
guard_target = q ε ↔ p ε
exact test_sorry
class Fintype (α : Type _) where
card : Nat
axiom Fintype.foo (α : Type _) [Fintype α] : Fintype.card α = 2
axiom Fintype.foo' (α : Type _) [Fintype α] [Fintype (Option α)] : Fintype.card α = 2
axiom instFintypeBool : Fintype Bool
/- Would be "failed to synthesize instance Fintype ?m" without allowing TC failure. -/
example : @Fintype.card Bool instFintypeBool = 2 := by
convert Fintype.foo _
example : @Fintype.card Bool instFintypeBool = 2 := by
convert Fintype.foo' _ using 1
guard_target = Fintype (Option Bool)
exact test_sorry
example : True := by
convert_to ?x + ?y = ?z
case x => exact 1
case y => exact 2
case z => exact 3
all_goals try infer_instance
· simp
· simp
-- This test does not work unless we specify that `α` and `β` lie in the same universe.
-- Prior to https://github.com/leanprover/lean4/pull/4493 it did,
-- because previously bodies of `example`s were (confusingly!) allowed to
-- affect the elaboration of the signature!
set_option linter.unusedTactic false in
example {α β : Type u} [Fintype α] [Fintype β] : Fintype.card α = Fintype.card β := by
congr!
guard_target = Fintype.card α = Fintype.card β
congr! +typeEqs
· guard_target = α = β
exact test_sorry
· rename_i inst1 inst2 h
guard_target = inst1 ≍ inst2
have : Subsingleton (Fintype α) := test_sorry
congr!
example (x y z : Nat) (h : x + y = z) : y + x = z := by
convert_to y + x = _ at h
· rw [Nat.add_comm]
exact h
/-! Check that we don't unfold at semireducible transparency: although `congr!` (which
`convert` relies on) applies lemmas at reducible transparency, it used to call
`assumption`/`rfl` at default transparency and solve too much.
`convert!` uses default transparency throughout, and solves the goals all at once.
-/
/-- An identity function at default transparency, to test that we don't unfold too much. -/
def semireducibleId {α : Type*} (a : α) := a
example (P : ℕ → Prop) {a : ℕ} (h : P a) : P (semireducibleId a) := by
convert h
guard_target =ₛ semireducibleId a = a
rfl
example (P : ℕ → Prop) {a : ℕ} (h : P a) : P (semireducibleId a) := by
convert! h
example (P : ℕ → Prop) {a b : ℕ} (hab : b = a) (h : P a) : P (semireducibleId b) := by
convert h
guard_target =ₛ semireducibleId b = a
exact hab
example (P : ℕ → Prop) {a b : ℕ} (hab : b = a) (h : P (semireducibleId a)) : P b := by
convert! h
-- Test that overapplications are supported
example (f g h k : Nat → Nat) (H : (f + g) 1 = 0) : (h + k) 1 = 0 := by
convert H
guard_target =ₛ h = f
all_goals exact test_sorry
end Tests