Skip to content

Commit 275f907

Browse files
fix: Rename theorems that use sorted instead of pairwise (#10743)
This PR renames theorems that use `sorted` in their name to instead use `pairwise`. Closes #10742. --------- Co-authored-by: Markus Himmel <[email protected]>
1 parent 8b28467 commit 275f907

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

src/Init/Data/List/Perm.lean

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ theorem Perm.pairwise {R : α → α → Prop} {l l' : List α} (hl : l ~ l') (h
491491
If two lists are sorted by an antisymmetric relation, and permutations of each other,
492492
they must be equal.
493493
-/
494-
theorem Perm.eq_of_sorted : ∀ {l₁ l₂ : List α}
494+
theorem Perm.eq_of_pairwise : ∀ {l₁ l₂ : List α}
495495
(_ : ∀ a b, a ∈ l₁ → b ∈ l₂ → le a b → le b a → a = b)
496496
(_ : l₁.Pairwise le) (_ : l₂.Pairwise le) (_ : l₁ ~ l₂), l₁ = l₂
497497
| [], [], _, _, _, _ => rfl
@@ -511,11 +511,14 @@ theorem Perm.eq_of_sorted : ∀ {l₁ l₂ : List α}
511511
(rel_of_pairwise_cons h₁ bm) (rel_of_pairwise_cons h₂ am)
512512
subst ab
513513
simp only [perm_cons] at h
514-
have := Perm.eq_of_sorted
514+
have := Perm.eq_of_pairwise
515515
(fun x y hx hy => w x y (mem_cons_of_mem a hx) (mem_cons_of_mem a hy))
516516
h₁.tail h₂.tail h
517517
simp_all
518518

519+
@[deprecated Perm.eq_of_pairwise (since := "2025-10-23")]
520+
abbrev Perm.eq_of_sorted := @Perm.eq_of_pairwise
521+
519522
theorem Nodup.perm {l l' : List α} (hR : l.Nodup) (hl : l ~ l') : l'.Nodup :=
520523
Pairwise.perm hR hl (by intro x y h h'; simp_all)
521524

src/Init/Data/List/Sort/Lemmas.lean

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
8894
theorem 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
208214
If the ordering relation `le` is transitive and total (i.e. `le a b || le b a` for all `a, b`)
209215
then 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+
241250
theorem 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
296305
The 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
309318
termination_by l => l.length
310319

320+
@[deprecated pairwise_mergeSort (since := "2025-10-23")]
321+
abbrev sorted_mergeSort := @pairwise_mergeSort
322+
311323
/--
312324
If 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]
325337
termination_by l => l.length
326338

339+
@[deprecated mergeSort_of_pairwise (since := "2025-10-23")]
340+
abbrev mergeSort_of_sorted := @mergeSort_of_pairwise
341+
327342
/--
328343
This merge sort algorithm is stable,
329344
in 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
360375
termination_by _ l => l.length
361376

362-
363-
364377
theorem 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

src/Std/Data/DTreeMap/Internal/WF/Lemmas.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ theorem equiv_iff_toListModel_perm {t t' : Impl α β} :
546546
theorem Equiv.toListModel_eq [Ord α] [OrientedOrd α]
547547
{t t' : Impl α β} (h : t.Equiv t') (htb : t.Ordered) (htb' : t'.Ordered) :
548548
t.toListModel = t'.toListModel := by
549-
refine List.Perm.eq_of_sorted ?_ htb htb' h.1
549+
refine List.Perm.eq_of_pairwise ?_ htb htb' h.1
550550
intro a b ha hb hlt hgt
551551
rw [OrientedOrd.eq_swap, hlt] at hgt
552552
contradiction

0 commit comments

Comments
 (0)