forked from leanprover-community/mathlib4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush_neg.lean
More file actions
237 lines (191 loc) · 6.17 KB
/
push_neg.lean
File metadata and controls
237 lines (191 loc) · 6.17 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
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
/-
Copyright (c) 2022 Alice Laroche. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alice Laroche, Frédéric Dupuis, Jireh Loreaux
-/
module
import Mathlib.Order.Defs.LinearOrder
import Mathlib.Data.Set.Basic
import Mathlib.Tactic.Push
private axiom test_sorry : ∀ {α}, α
set_option autoImplicit true
variable {α β : Type} [LinearOrder β] {p q : Prop} {p' q' : α → Prop}
example : ¬ False := by
push Not
example (h : ¬ True) : False := by
push Not at h
exact h
example : (¬p ∧ ¬q) → ¬(p ∨ q) := by
intro h
push Not
guard_target = ¬p ∧ ¬q
exact h
example : ¬(p ∧ q) → (p → ¬q) := by
intro h
push Not at h
guard_hyp h : p → ¬q
exact h
example : (∀ (x : α), ¬ p' x) → ¬ ∃ (x : α), p' x := by
intro h
push Not
guard_target = ∀ (x : α), ¬p' x
exact h
example : (¬ ∀ (x : α), p' x) → (∃ (x : α), ¬ p' x) := by
intro h
push Not at h
guard_hyp h : ∃ (x : α), ¬p' x
exact h
example (p : Bool) : decide (¬ ¬ p) = p := by
push Not
guard_target = decide p = p
cases p <;> rfl
example : ((fun x => x+x) 1) = 2 := by
push Not
guard_target = 1 + 1 = 2
simp
example : ¬ ¬ p = p := by
push Not
guard_target = p = p
rfl
example (x y : β) (h : y < x) : ¬(x ≤ y) := by
push Not
guard_target = y < x
exact h
example (a b : β) (h : a ≤ b) : ¬ a > b := by
push Not
guard_target = a ≤ b
exact h
example (x y : α) (h : x = y) : ¬ (x ≠ y) := by
push Not
guard_target = x = y
exact h
example : ¬∃ (y : Unit), (y ≠ ()) := by
push Not
guard_target = ∀ (y : Unit), y = ()
simp
example (h : ∃ y : Nat, ¬(y=1)): ¬∀ (y : Nat), (y = 1) := by
push Not
guard_target = ∃ (y : Nat), y ≠ 1
exact h
example (x y : β) (h : y < x) : ¬¬¬ (x ≤ y) := by
push Not
guard_target = y < x
exact h
set_option linter.unusedVariables false in
example (x y : β) (h₁ : ¬¬¬(x < y)) (h₂ : ¬∃ (x y : Nat), x = y) : ¬ ∀ (x y : Nat), x = y := by
push Not at *
guard_target = ∃ (x y : Nat), x ≠ y
guard_hyp h₁ : y ≤ x
guard_hyp h₂ : ∀ (x y : Nat), x ≠ y
exact ⟨0, 1, by simp⟩
set_option linter.unusedVariables false in
example (x y : β) (h₁ : ¬¬¬(x < y)) (h₂ : ¬∃ (x y : Nat), x = y) : ¬ ∀ (x y : Nat), x = y := by
push Not at h₁ h₂ ⊢
guard_target = ∃ (x y : Nat), x ≠ y
guard_hyp h₁ : y ≤ x
guard_hyp h₂ : ∀ (x y : Nat), x ≠ y
exact ⟨0, 1, by simp⟩
example (h : p → ¬ q) : ¬ (p ∧ q) := by
push Not
guard_target = p → ¬q
exact h
example (a : β) : ¬ ∀ x : β, x < a → ∃ y : β, (y < a) ∧ ∀ z : β, x = z := by
push Not
guard_target = ∃ x, x < a ∧ ∀ (y : β), y < a → ∃ z, x ≠ z
exact test_sorry
set_option linter.unusedVariables false in
example {α} [Preorder α] (m n : α) (h : ¬(∃ k : α, m ≤ k)) (h₂ : m ≤ n) : m ≤ n := by
push Not at h
guard_hyp h : ∀ k, ¬(m ≤ k)
exact h₂
set_option linter.unusedVariables false in
example {α} [Preorder α] (m n : α) (h : ¬(∃ k : α, m < k)) (h₂ : m ≤ n) : m ≤ n := by
push Not at h
guard_hyp h : ∀ k, ¬(m < k)
exact h₂
example (r : LinearOrder α) (s : Preorder α) (a b : α) : ¬(s.lt a b → r.lt a b) := by
push Not
guard_target = s.lt a b ∧ r.le b a
exact test_sorry
example (r : LinearOrder α) (s : Preorder α) (a b : α) : ¬(r.lt a b → s.lt a b) := by
push Not
guard_target = r.lt a b ∧ ¬ s.lt a b
exact test_sorry
-- check that `push Not` does not expand `let` definitions
example (h : p ∧ q) : ¬¬(p ∧ q) := by
let r := p ∧ q
change ¬¬r
push Not
guard_target =ₛ r
exact h
-- new error message as of https://github.com/leanprover-community/mathlib4/issues/27562
/-- error: `push` made no progress anywhere -/
#guard_msgs in
example {P : Prop} (h : P) : P := by push Not at *
-- new behaviour as of https://github.com/leanprover-community/mathlib4/issues/27562
-- (Previously, because of a metavariable instantiation issue, the tactic succeeded as a no-op.)
/-- error: `push` made no progress at `h` -/
#guard_msgs in
example {x y : ℕ} : True := by
have h : x ≤ y := test_sorry
push Not at h
-- new behaviour as of https://github.com/leanprover-community/mathlib4/issues/27562 (previously the tactic succeeded as a no-op)
/-- error: Cannot run `push` at `inductive_proof`, it is an implementation detail -/
#guard_msgs in
def inductive_proof : True := by
push Not at inductive_proof
trivial
section use_distrib
example (h : ¬ p ∨ ¬ q) : ¬ (p ∧ q) := by
push +distrib Not
guard_target = ¬p ∨ ¬q
exact h
set_option push_neg.use_distrib true
example (h : ¬ p ∨ ¬ q) : ¬ (p ∧ q) := by
push Not
guard_target = ¬p ∨ ¬q
exact h
example : p → ¬ ¬ ¬ ¬ ¬ ¬ p := by
push Not
guard_target = p → p
exact id
example (h : x = 0 ∧ y ≠ 0) : ¬(x = 0 → y = 0) := by
push Not
guard_target = x = 0 ∧ y ≠ 0
exact h
end use_distrib
example (a : α) (o : Option α) (h : ¬∀ hs, o.get hs ≠ a) : ∃ hs, o.get hs = a := by
push Not at h
exact h
example (s : Set α) (h : ¬s.Nonempty) : s = ∅ := by
push Not at h
exact h
example (s : Set α) (h : ¬ s = ∅) : s.Nonempty := by
push Not at h
exact h
example (s : Set α) (h : s ≠ ∅) : s.Nonempty := by
push Not at h
exact h
example (s : Set α) (h : ∅ ≠ s) : s.Nonempty := by
push Not at h
exact h
namespace no_proj
structure G (V : Type) where
Adj : V → V → Prop
def g : G Nat where
Adj a b := (a ≠ b) ∧ ((a ∣ b) ∨ (b ∣ a))
example {p q : Nat} : ¬ g.Adj p q := by
rw [g]
guard_target =ₛ ¬ G.Adj { Adj := fun a b => (a ≠ b) ∧ ((a ∣ b) ∨ (b ∣ a)) } p q
fail_if_success push Not
guard_target =ₛ ¬ G.Adj { Adj := fun a b => (a ≠ b) ∧ ((a ∣ b) ∨ (b ∣ a)) } p q
dsimp only
guard_target =ₛ ¬ ((p ≠ q) ∧ ((p ∣ q) ∨ (q ∣ p)))
push Not
guard_target =ₛ p ≠ q → ¬p ∣ q ∧ ¬q ∣ p
exact test_sorry
end no_proj
-- test that binder names are preserved by `push Not`
/-- info: ∀ (a b : ℕ), ∃ c d, a + b ≠ c + d -/
#guard_msgs in
#push Not => ¬ ∃ a b : Nat, ∀ c d : Nat, a + b = c + d