@@ -16,9 +16,9 @@ public section
1616/-!
1717# Basic properties of `mergeSort`.
1818
19- * `sorted_mergeSort `: `mergeSort` produces a sorted list.
19+ * `pairwise_mergeSort `: `mergeSort` produces a sorted list.
2020* `mergeSort_perm`: `mergeSort` is a permutation of the input list.
21- * `mergeSort_of_sorted `: `mergeSort` does not change a sorted list.
21+ * `mergeSort_of_pairwise `: `mergeSort` does not change a sorted list.
2222* `mergeSort_cons`: proves `mergeSort le (x :: xs) = l₁ ++ x :: l₂` for some `l₁, l₂`
2323 so that `mergeSort le xs = l₁ ++ l₂`, and no `a ∈ l₁` satisfies `le a x`.
2424* `sublist_mergeSort`: if `c` is a sorted sublist of `l`, then `c` is still a sublist of `mergeSort le l`.
@@ -77,14 +77,20 @@ theorem splitInTwo_cons_cons_zipIdx_snd (i : Nat) (l : List α) :
7777 congr
7878 ext <;> simp; omega
7979
80- theorem splitInTwo_fst_sorted (l : { l : List α // l.length = n }) (h : Pairwise le l.1 ) : Pairwise le (splitInTwo l).1 .1 := by
80+ theorem splitInTwo_fst_pairwise (l : { l : List α // l.length = n }) (h : Pairwise le l.1 ) : Pairwise le (splitInTwo l).1 .1 := by
8181 rw [splitInTwo_fst]
8282 exact h.take
8383
84- theorem splitInTwo_snd_sorted (l : { l : List α // l.length = n }) (h : Pairwise le l.1 ) : Pairwise le (splitInTwo l).2 .1 := by
84+ @[deprecated splitInTwo_fst_pairwise (since := " 2025-10-23" )]
85+ abbrev splitInTwo_fst_sorted := @splitInTwo_fst_pairwise
86+
87+ theorem splitInTwo_snd_pairwise (l : { l : List α // l.length = n }) (h : Pairwise le l.1 ) : Pairwise le (splitInTwo l).2 .1 := by
8588 rw [splitInTwo_snd]
8689 exact h.drop
8790
91+ @[deprecated splitInTwo_snd_pairwise (since := " 2025-10-23" )]
92+ abbrev splitInTwo_snd_sorted := @splitInTwo_fst_pairwise
93+
8894theorem splitInTwo_fst_le_splitInTwo_snd {l : { l : List α // l.length = n }} (h : Pairwise le l.1 ) :
8995 ∀ a b, a ∈ (splitInTwo l).1 .1 → b ∈ (splitInTwo l).2 .1 → le a b := by
9096 rw [splitInTwo_fst, splitInTwo_snd]
@@ -208,7 +214,7 @@ attribute [local instance] boolRelToRel
208214If the ordering relation `le` is transitive and total (i.e. `le a b || le b a` for all `a, b`)
209215then the `merge` of two sorted lists is sorted.
210216-/
211- theorem sorted_merge
217+ theorem pairwise_merge
212218 (trans : ∀ (a b c : α), le a b → le b c → le a c)
213219 (total : ∀ (a b : α), le a b || le b a)
214220 (l₁ l₂ : List α) (h₁ : l₁.Pairwise le) (h₂ : l₂.Pairwise le) : (merge l₁ l₂ le).Pairwise le := by
@@ -238,6 +244,9 @@ theorem sorted_merge
238244 · exact rel_of_pairwise_cons h₂ m
239245 · exact ih₂ h₂.tail
240246
247+ @[deprecated pairwise_merge (since := " 2025-10-23" )]
248+ abbrev sorted_merge := @pairwise_merge
249+
241250theorem merge_of_le : ∀ {xs ys : List α} (_ : ∀ a b, a ∈ xs → b ∈ ys → le a b),
242251 merge xs ys le = xs ++ ys
243252 | [], ys, _
@@ -295,35 +304,41 @@ and total in the sense that `le a b || le b a`.
295304
296305The comparison function need not be irreflexive, i.e. `le a b` and `le b a` is allowed even when `a ≠ b`.
297306-/
298- theorem sorted_mergeSort
307+ theorem pairwise_mergeSort
299308 (trans : ∀ (a b c : α), le a b → le b c → le a c)
300309 (total : ∀ (a b : α), le a b || le b a) :
301310 (l : List α) → (mergeSort l le).Pairwise le
302311 | [] => by simp
303312 | [a] => by simp
304313 | a :: b :: xs => by
305314 rw [mergeSort]
306- apply sorted_merge @trans @total
307- apply sorted_mergeSort trans total
308- apply sorted_mergeSort trans total
315+ apply pairwise_merge @trans @total
316+ apply pairwise_mergeSort trans total
317+ apply pairwise_mergeSort trans total
309318termination_by l => l.length
310319
320+ @[deprecated pairwise_mergeSort (since := " 2025-10-23" )]
321+ abbrev sorted_mergeSort := @pairwise_mergeSort
322+
311323/--
312324If the input list is already sorted, then `mergeSort` does not change the list.
313325-/
314- theorem mergeSort_of_sorted : ∀ {l : List α} (_ : Pairwise le l), mergeSort l le = l
326+ theorem mergeSort_of_pairwise : ∀ {l : List α} (_ : Pairwise le l), mergeSort l le = l
315327 | [], _ => by simp
316328 | [a], _ => by simp
317329 | a :: b :: xs, h => by
318330 have : (splitInTwo ⟨a :: b :: xs, rfl⟩).1 .1 .length < xs.length + 1 + 1 := by simp [splitInTwo_fst]; omega
319331 have : (splitInTwo ⟨a :: b :: xs, rfl⟩).2 .1 .length < xs.length + 1 + 1 := by simp [splitInTwo_snd]; omega
320332 rw [mergeSort]
321- rw [mergeSort_of_sorted (splitInTwo_fst_sorted ⟨a :: b :: xs, rfl⟩ h)]
322- rw [mergeSort_of_sorted (splitInTwo_snd_sorted ⟨a :: b :: xs, rfl⟩ h)]
333+ rw [mergeSort_of_pairwise (splitInTwo_fst_pairwise ⟨a :: b :: xs, rfl⟩ h)]
334+ rw [mergeSort_of_pairwise (splitInTwo_snd_pairwise ⟨a :: b :: xs, rfl⟩ h)]
323335 rw [merge_of_le (splitInTwo_fst_le_splitInTwo_snd h)]
324336 rw [splitInTwo_fst_append_splitInTwo_snd]
325337termination_by l => l.length
326338
339+ @[deprecated mergeSort_of_pairwise (since := " 2025-10-23" )]
340+ abbrev mergeSort_of_sorted := @mergeSort_of_pairwise
341+
327342/--
328343This merge sort algorithm is stable,
329344in the sense that breaking ties in the ordering function using the position in the list
@@ -359,8 +374,6 @@ where go : ∀ (i : Nat) (l : List α),
359374 omega
360375termination_by _ l => l.length
361376
362-
363-
364377theorem mergeSort_cons {le : α → α → Bool}
365378 (trans : ∀ (a b c : α), le a b → le b c → le a c)
366379 (total : ∀ (a b : α), le a b || le b a)
@@ -373,7 +386,7 @@ theorem mergeSort_cons {le : α → α → Bool}
373386 have m₁ : (a, 0 ) ∈ mergeSort ((a :: l).zipIdx) (zipIdxLE le) :=
374387 mem_mergeSort.mpr mem_cons_self
375388 obtain ⟨l₁, l₂, h⟩ := append_of_mem m₁
376- have s := sorted_mergeSort (zipIdxLE_trans trans) (zipIdxLE_total total) ((a :: l).zipIdx)
389+ have s := pairwise_mergeSort (zipIdxLE_trans trans) (zipIdxLE_total total) ((a :: l).zipIdx)
377390 rw [h] at s
378391 have p := mergeSort_perm ((a :: l).zipIdx) (zipIdxLE le)
379392 rw [h] at p
@@ -384,8 +397,8 @@ theorem mergeSort_cons {le : α → α → Bool}
384397 have q : mergeSort (l.zipIdx 1 ) (zipIdxLE le) ~ l₁ ++ l₂ :=
385398 (mergeSort_perm (l.zipIdx 1 ) (zipIdxLE le)).trans
386399 (p.symm.trans perm_middle).cons_inv
387- apply Perm.eq_of_sorted (le := zipIdxLE le)
388- · rintro ⟨a, i⟩ ⟨b, j⟩ ha hb
400+ apply Perm.eq_of_pairwise (le := zipIdxLE le)
401+ · rintro ⟨a, i⟩ ⟨b, j⟩ ha hb
389402 simp only [mem_mergeSort] at ha
390403 simp only [← q.mem_iff, mem_mergeSort] at hb
391404 simp only [zipIdxLE]
@@ -400,7 +413,7 @@ theorem mergeSort_cons {le : α → α → Bool}
400413 have := mem_zipIdx hb
401414 simp_all
402415 · rfl
403- · exact sorted_mergeSort (zipIdxLE_trans trans) (zipIdxLE_total total) ..
416+ · exact pairwise_mergeSort (zipIdxLE_trans trans) (zipIdxLE_total total) ..
404417 · exact s.sublist ((sublist_cons_self (a, 0 ) l₂).append_left l₁)
405418 · exact q
406419 · intro b m
0 commit comments