Skip to content

Commit 92a17c0

Browse files
committed
more progress on unfinished proofs
1 parent 224ad9c commit 92a17c0

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

RecMath/SortingNetwork.lean

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,26 @@ theorem Equiv.Perm.strictmono_of_monotone {α} [PartialOrder α] {p : Equiv.Perm
297297
have : p i ≠ p j := Function.Injective.ne (Equiv.injective _) (by order)
298298
order
299299

300-
theorem monotone_perm_eq_one {n : Nat} {p : Equiv.Perm (Fin (n + 1))} (h : Monotone p) : p = 1 := by
301-
unfold Monotone at h
302-
contrapose! h
300+
def extend_fin.equiv {n : Nat} : Fin n ≃ {x : Fin (n + 1) // x < n } where
301+
toFun x := Subtype.mk (Fin.mk x.val (by omega)) (by bound)
302+
invFun x := Fin.mk x.val.val x.prop
303+
left_inv _ := rfl
304+
right_inv _ := rfl
303305

304-
sorry
306+
theorem monotone_perm_eq_one {n : Nat} {p : Equiv.Perm (Fin n)} (h : Monotone p) : p = 1 := by
307+
unfold Monotone at h
308+
-- Induct and try to transfer proofs using MonotoneOn then expand the set
309+
induction n with
310+
| zero => exact Subsingleton.allEq p 1
311+
| succ n h =>
312+
change p = Equiv.refl _
313+
rw [<- Equiv.Perm.extendDomain_refl extend_fin.equiv]
314+
sorry
305315

306316
-- The basic idea that if a comparison network can sort all permuataions, then it can sort anything
307317
-- I see it as a weaker form of the zero-one principle
308318
theorem ComparisonNetwork.permutation_test (net : ComparisonNetwork n) :
309-
(∀ (p : Equiv.Perm (Fin n)), Monotone (net.apply ⇑p)) -> net.Sorts := by
319+
(∀ (p : Equiv.Perm (Fin n)), Monotone (net.apply ⇑p)) -> net.Sorts := by
310320
intro h α inst a i j i_le_j
311321

312322
-- i dont know if this approach will actually work
@@ -339,8 +349,25 @@ theorem ComparisonNetwork.zero_one_principle (net : ComparisonNetwork n) :
339349
let f : α -> Bool := (a i < ·)
340350
have fmono : Monotone f := by
341351
grind only [= Monotone, = Bool.le_iff_imp, = decide_eq_true, -> lt_of_lt_of_le]
342-
have : (f ∘ net.apply a) = net.apply (f ∘ a) := by
343-
rw [monotone_comp fmono]
352+
have fswap := monotone_iff_forall_lt.mp fmono bad_swap
353+
have : f ∘ net.apply a = net.apply (f ∘ a) := by
354+
simp [monotone_comp fmono]
355+
356+
use f ∘ a
357+
dsimp [Monotone]
358+
push_neg
359+
use i, j
360+
constructor
361+
· order
362+
simp [<- this]
363+
364+
have : f (net.apply a j) ≠ f (net.apply a i) := by
365+
unfold f
366+
simp
367+
push_neg
368+
simp [f, Bool.le_iff_imp] at fswap
369+
370+
order
344371

345372
-- have : f (a j) = true := by
346373
-- unfold f
@@ -355,21 +382,6 @@ theorem ComparisonNetwork.zero_one_principle (net : ComparisonNetwork n) :
355382

356383
-- sorry
357384

358-
use f ∘ a
359-
rw [monotone_comp fmono]
360-
361-
unfold Monotone
362-
push_neg
363-
use i, j
364-
constructor
365-
· exact i_le_j
366-
simp only [Function.comp_apply]
367-
368-
have := monotone_iff_forall_lt.mp fmono bad_swap
369-
-- have : f (net.apply a j) ≠ f (net.apply a i) := by sorry
370-
371-
-- order
372-
373385
sorry
374386

375387
-- Using the zero-one principle i could implement Decidable ComparisonNetwork.Sorts

0 commit comments

Comments
 (0)