Skip to content

Commit 224ad9c

Browse files
committed
Cleaned up proofs
1 parent 59eb127 commit 224ad9c

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

RecMath/SortingNetwork.lean

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ theorem IndexPair.apply_j_eq_max {p : IndexPair n} {t : Tuple α n} :
6161
rewrite [apply, toPerm]
6262
grind only [= Equiv.Perm.one_apply, = Equiv.swap_apply_right, = max_def]
6363

64-
@[grind <-]
64+
@[grind ]
6565
theorem IndexPair.apply_i_le_apply_j {p : IndexPair n} {t : Tuple α n} :
6666
p.apply t p.i ≤ p.apply t p.j := by
6767
simp! only [apply_i_eq_min, apply_j_eq_max, le_sup_iff, inf_le_left, inf_le_right, or_self]
@@ -71,13 +71,20 @@ theorem IndexPair.apply.monotoneOn_ij {p : IndexPair n} {t : Tuple α n} :
7171
intro a ha b hb a_le_b
7272
by_cases a_eq_b : a = b
7373
{ subst a_eq_b; rfl }
74+
-- grind only [= apply_i_eq_min, = Set.mem_singleton_iff, = apply_j_eq_max, = Set.subset_def,
75+
-- = Set.singleton_subset_iff, ← apply_i_le_apply_j, Set.subset_insert, = Set.mem_insert_iff,
76+
-- cases IndexPair, cases Or]
7477
have ⟨i_eq_a, j_eq_b⟩: p.i = a ∧ p.j = b := by
7578
grind only [= Set.mem_singleton_iff, = Set.mem_insert_iff, IndexPair]
7679
subst i_eq_a j_eq_b
7780
exact apply_i_le_apply_j
78-
-- simp only [apply, toPerm, Function.comp]
79-
-- grind only [= Equiv.Perm.one_apply, = Equiv.swap_apply_left,
80-
-- = Equiv.swap_apply_right, le_of_not_ge]
81+
82+
@[simp, grind =]
83+
theorem IndexPair.apply_of_ne_of_ne {p : IndexPair n} {t : Tuple α n} {x : Fin n} :
84+
x ≠ p.i -> x ≠ p.j -> p.apply t x = t x := by
85+
intro x_ne_i x_ne_j
86+
dsimp [apply, toPerm]
87+
grind only [= Equiv.swap_apply_def, = Equiv.Perm.one_apply]
8188

8289
def ComparisonNetwork (n : Nat) := List (IndexPair n)
8390

@@ -93,7 +100,6 @@ def ComparisonNetwork.toPerm (t : Tuple α n) (net : ComparisonNetwork n) : Equi
93100
def ComparisonNetwork.apply (net : ComparisonNetwork n) (t : Tuple α n) : Tuple α n :=
94101
t ∘ net.toPerm t
95102

96-
97103
-- This proof ensures that the ComparisonNetwork.toPerm implementation is correct
98104
@[grind _=_]
99105
theorem ComparisonNetwork.apply_eq_foldr_apply (net : ComparisonNetwork n) (t : Tuple α n) :
@@ -241,18 +247,11 @@ attribute [grind] Equiv.injective Equiv.surjective Equiv.bijective
241247
attribute [grind =] Equiv.Perm.one_apply Equiv.swap_apply_left Equiv.swap_apply_right
242248
attribute [grind ←] Equiv.swap_apply_of_ne_of_ne
243249
-- attribute [grind →] ne_of_lt
250+
attribute [grind] Monotone.map_max Monotone.map_min
244251

245252
section ZeroOnePrinciple
246253

247-
-- TODO: bad name
248-
@[grind <-]
249-
theorem IndexPair.apply_eq_self {p : IndexPair n} {t : Tuple α n} {x : Fin n} :
250-
x ≠ p.i ∧ x ≠ p.j -> p.apply t x = t x := by
251-
rintro ⟨x_ne_i, x_ne_j⟩
252-
rw [apply, toPerm]
253-
grind only [Equiv.swap_apply_def, = Equiv.Perm.one_apply]
254-
255-
-- Should these grind annotations be replaced by a different grind option?
254+
-- These two lemmas are from the wikipedia proof. I can probably get rid of them
256255
@[grind]
257256
theorem IndexPair.apply_i_eq_min_mono {p : IndexPair n} {t : Tuple α n} {f : α -> β}
258257
(hf : Monotone f) : f (p.apply t p.i) = min (f (t p.i)) (f (t p.j)) := by
@@ -268,8 +267,8 @@ theorem IndexPair.monotone_comp {p : IndexPair n} {a : Tuple α n} {f : α -> β
268267
p.apply (f ∘ a) = f ∘ (p.apply a) := by
269268
funext k
270269
by_cases k = p.i ∨ k = p.j <;>
271-
grind only [apply_i_eq_min_mono, = apply_i_eq_min, apply_j_eq_max_mono, = apply_j_eq_max,
272-
cases Or, ← apply_eq_self]
270+
grind only [Monotone.map_min, Monotone.map_max, = apply_i_eq_min, = apply_j_eq_max,
271+
cases Or, = apply_of_ne_of_ne]
273272

274273
-- Lemme 28.1 in Introduction to algorithms 1e
275274
-- Should probably rename this theorem too

0 commit comments

Comments
 (0)