data.list.pairwiseMathlib.Data.List.Pairwise

This file has been ported!

Changes since the initial port

The following section lists changes to this file in mathlib3 and mathlib4 that occured after the initial port. Most recent changes are shown first. Hovering over a commit will show all commits associated with the same mathlib3 commit.

Changes in mathlib3

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(last sync)

refactor(*): define list.replicate and migrate to it (#18127)

This definition differs from list.repeat by the order of arguments. The new order is in sync with the Lean 4 version.

Diff
@@ -313,10 +313,10 @@ theorem pairwise_iff_nth_le {R} : ∀ {l : list α},
     exact H _ _ (succ_lt_succ h) (succ_pos _) }
 end
 
-lemma pairwise_repeat {α : Type*} {r : α → α → Prop} {x : α} (hx : r x x) :
-  ∀ (n : ℕ), pairwise r (repeat x n)
+lemma pairwise_replicate {α : Type*} {r : α → α → Prop} {x : α} (hx : r x x) :
+  ∀ (n : ℕ), pairwise r (replicate n x)
 | 0 := by simp
-| (n+1) := by simp [hx, mem_repeat, pairwise_repeat n]
+| (n+1) := by simp [hx, mem_replicate, pairwise_replicate n]
 
 /-! ### Pairwise filtering -/
 

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(first ported)

Changes in mathlib3port

mathlib3
mathlib3port
Diff
@@ -208,7 +208,7 @@ theorem pairwise_append {l₁ l₂ : List α} :
     [simp only [List.Pairwise.nil, forall_prop_of_false (not_mem_nil _), forall_true_iff,
       and_true_iff, true_and_iff, nil_append];
     simp only [cons_append, pairwise_cons, forall_mem_append, IH, forall_mem_cons, forall_and,
-      and_assoc', and_left_comm]]
+      and_assoc, and_left_comm]]
 #align list.pairwise_append List.pairwise_append
 -/
 
@@ -230,7 +230,7 @@ theorem pairwise_middle (s : Symmetric R) {a : α} {l₁ l₂ : List α} :
   show Pairwise R (l₁ ++ ([a] ++ l₂)) ↔ Pairwise R ([a] ++ l₁ ++ l₂) by
     rw [← append_assoc, pairwise_append, @pairwise_append _ _ ([a] ++ l₁),
         pairwise_append_comm s] <;>
-      simp only [mem_append, or_comm']
+      simp only [mem_append, or_comm]
 #align list.pairwise_middle List.pairwise_middle
 -/
 
@@ -337,7 +337,7 @@ theorem pairwise_join {L : List (List α)} :
     ⟨fun h a b c d e => h c d e a b, fun h c d e a b => h a b c d e⟩
   simp only [join, pairwise_append, IH, mem_join, exists_imp, and_imp, this, forall_mem_cons,
     pairwise_cons]
-  simp only [and_assoc', and_comm', and_left_comm]
+  simp only [and_assoc, and_comm, and_left_comm]
 #align list.pairwise_join List.pairwise_join
 -/
 
Diff
@@ -307,7 +307,7 @@ theorem pairwise_pmap {p : β → Prop} {f : ∀ b, p b → α} {l : List β} (h
   by
   induction' l with a l ihl; · simp
   obtain ⟨ha, hl⟩ : p a ∧ ∀ b, b ∈ l → p b := by simpa using h
-  simp only [ihl hl, pairwise_cons, bex_imp, pmap, and_congr_left_iff, mem_pmap]
+  simp only [ihl hl, pairwise_cons, exists₂_imp, pmap, and_congr_left_iff, mem_pmap]
   refine' fun _ => ⟨fun H b hb hpa hpb => H _ _ hb rfl, _⟩
   rintro H _ b hb rfl
   exact H b hb _ _
Diff
@@ -157,7 +157,7 @@ theorem Pairwise.forall_of_forall_of_flip (h₁ : ∀ x ∈ l, R x x) (h₂ : l.
   by
   induction' l with a l ih
   · exact forall_mem_nil _
-  rw [pairwise_cons] at h₂ h₃ 
+  rw [pairwise_cons] at h₂ h₃
   rintro x (rfl | hx) y (rfl | hy)
   · exact h₁ _ (l.mem_cons_self _)
   · exact h₂.1 _ hy
@@ -478,7 +478,7 @@ theorem pwFilter_map (f : β → α) :
       have h' : ¬∀ b : β, b ∈ pwFilter (fun x y : β => R (f x) (f y)) xs → R (f x) (f b) :=
         fun hh =>
         h fun a ha => by
-          rw [pw_filter_map, mem_map] at ha ; rcases ha with ⟨b, hb₀, hb₁⟩
+          rw [pw_filter_map, mem_map] at ha; rcases ha with ⟨b, hb₀, hb₁⟩
           subst a; exact hh _ hb₀
       rw [map, pw_filter_cons_of_neg h, pw_filter_cons_of_neg h', pw_filter_map]
 #align list.pw_filter_map List.pwFilter_map
@@ -542,7 +542,7 @@ theorem forall_mem_pwFilter (neg_trans : ∀ {x y z}, R x z → R x y ∨ R y z)
   ⟨by
     induction' l with x l IH; · exact fun _ _ => False.elim
     simp only [forall_mem_cons]
-    by_cases ∀ y ∈ pw_filter R l, R x y <;> dsimp at h 
+    by_cases ∀ y ∈ pw_filter R l, R x y <;> dsimp at h
     · simp only [pw_filter_cons_of_pos h, forall_mem_cons, and_imp]
       exact fun r H => ⟨r, IH H⟩
     · rw [pw_filter_cons_of_neg h]
Diff
@@ -391,13 +391,18 @@ theorem pairwise_of_reflexive_on_dupl_of_forall_ne [DecidableEq α] {l : List α
 
 #print List.pairwise_of_forall_mem_list /-
 theorem pairwise_of_forall_mem_list {l : List α} {r : α → α → Prop} (h : ∀ a ∈ l, ∀ b ∈ l, r a b) :
-    l.Pairwise r := by classical
+    l.Pairwise r := by
+  classical
+  refine' pairwise_of_reflexive_on_dupl_of_forall_ne (fun a ha' => _) fun a ha b hb _ => h a ha b hb
+  have ha := List.count_pos_iff_mem.1 ha'.le
+  exact h a ha a ha
 #align list.pairwise_of_forall_mem_list List.pairwise_of_forall_mem_list
 -/
 
 #print List.pairwise_of_reflexive_of_forall_ne /-
 theorem pairwise_of_reflexive_of_forall_ne {l : List α} {r : α → α → Prop} (hr : Reflexive r)
-    (h : ∀ a ∈ l, ∀ b ∈ l, a ≠ b → r a b) : l.Pairwise r := by classical
+    (h : ∀ a ∈ l, ∀ b ∈ l, a ≠ b → r a b) : l.Pairwise r := by
+  classical exact pairwise_of_reflexive_on_dupl_of_forall_ne (fun _ _ => hr _) h
 #align list.pairwise_of_reflexive_of_forall_ne List.pairwise_of_reflexive_of_forall_ne
 -/
 
Diff
@@ -391,18 +391,13 @@ theorem pairwise_of_reflexive_on_dupl_of_forall_ne [DecidableEq α] {l : List α
 
 #print List.pairwise_of_forall_mem_list /-
 theorem pairwise_of_forall_mem_list {l : List α} {r : α → α → Prop} (h : ∀ a ∈ l, ∀ b ∈ l, r a b) :
-    l.Pairwise r := by
-  classical
-  refine' pairwise_of_reflexive_on_dupl_of_forall_ne (fun a ha' => _) fun a ha b hb _ => h a ha b hb
-  have ha := List.count_pos_iff_mem.1 ha'.le
-  exact h a ha a ha
+    l.Pairwise r := by classical
 #align list.pairwise_of_forall_mem_list List.pairwise_of_forall_mem_list
 -/
 
 #print List.pairwise_of_reflexive_of_forall_ne /-
 theorem pairwise_of_reflexive_of_forall_ne {l : List α} {r : α → α → Prop} (hr : Reflexive r)
-    (h : ∀ a ∈ l, ∀ b ∈ l, a ≠ b → r a b) : l.Pairwise r := by
-  classical exact pairwise_of_reflexive_on_dupl_of_forall_ne (fun _ _ => hr _) h
+    (h : ∀ a ∈ l, ∀ b ∈ l, a ≠ b → r a b) : l.Pairwise r := by classical
 #align list.pairwise_of_reflexive_of_forall_ne List.pairwise_of_reflexive_of_forall_ne
 -/
 
Diff
@@ -3,10 +3,10 @@ Copyright (c) 2018 Mario Carneiro. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Mario Carneiro
 -/
-import Mathbin.Data.List.Count
-import Mathbin.Data.List.Lex
-import Mathbin.Logic.Pairwise
-import Mathbin.Logic.Relation
+import Data.List.Count
+import Data.List.Lex
+import Logic.Pairwise
+import Logic.Relation
 
 #align_import data.list.pairwise from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e"
 
Diff
@@ -529,11 +529,11 @@ alias ⟨_, pairwise.pw_filter⟩ := pw_filter_eq_self
 
 attribute [protected] pairwise.pw_filter
 
-#print List.pwFilter_idempotent /-
+#print List.pwFilter_idem /-
 @[simp]
-theorem pwFilter_idempotent : pwFilter R (pwFilter R l) = pwFilter R l :=
+theorem pwFilter_idem : pwFilter R (pwFilter R l) = pwFilter R l :=
   (pairwise_pwFilter l).pwFilter
-#align list.pw_filter_idempotent List.pwFilter_idempotent
+#align list.pw_filter_idempotent List.pwFilter_idem
 -/
 
 #print List.forall_mem_pwFilter /-
Diff
@@ -394,7 +394,7 @@ theorem pairwise_of_forall_mem_list {l : List α} {r : α → α → Prop} (h :
     l.Pairwise r := by
   classical
   refine' pairwise_of_reflexive_on_dupl_of_forall_ne (fun a ha' => _) fun a ha b hb _ => h a ha b hb
-  have ha := List.one_le_count_iff_mem.1 ha'.le
+  have ha := List.count_pos_iff_mem.1 ha'.le
   exact h a ha a ha
 #align list.pairwise_of_forall_mem_list List.pairwise_of_forall_mem_list
 -/
@@ -524,7 +524,7 @@ theorem pwFilter_eq_self {l : List α} : pwFilter R l = l ↔ Pairwise R l :=
 #align list.pw_filter_eq_self List.pwFilter_eq_self
 -/
 
-alias pw_filter_eq_self ↔ _ pairwise.pw_filter
+alias ⟨_, pairwise.pw_filter⟩ := pw_filter_eq_self
 #align list.pairwise.pw_filter List.Pairwise.pwFilter
 
 attribute [protected] pairwise.pw_filter
Diff
@@ -2,17 +2,14 @@
 Copyright (c) 2018 Mario Carneiro. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Mario Carneiro
-
-! This file was ported from Lean 3 source module data.list.pairwise
-! leanprover-community/mathlib commit f694c7dead66f5d4c80f446c796a5aad14707f0e
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathbin.Data.List.Count
 import Mathbin.Data.List.Lex
 import Mathbin.Logic.Pairwise
 import Mathbin.Logic.Relation
 
+#align_import data.list.pairwise from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e"
+
 /-!
 # Pairwise relations on a list
 
Diff
@@ -256,11 +256,14 @@ theorem Pairwise.of_map {S : β → β → Prop} (f : α → β) (H : ∀ a b :
 #align list.pairwise.of_map List.Pairwise.of_map
 -/
 
+#print List.Pairwise.map /-
 theorem Pairwise.map {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, R a b → S (f a) (f b))
     (p : Pairwise R l) : Pairwise S (map f l) :=
   (pairwise_map' f).2 <| p.imp H
 #align list.pairwise.map List.Pairwise.map
+-/
 
+#print List.pairwise_filterMap /-
 theorem pairwise_filterMap (f : β → Option α) {l : List β} :
     Pairwise R (filterMap f l) ↔ Pairwise (fun a a' : β => ∀ b ∈ f a, ∀ b' ∈ f a', R b b') l :=
   by
@@ -277,6 +280,7 @@ theorem pairwise_filterMap (f : β → Option α) {l : List β} :
       (∀ a' : β, a' ∈ l → ∀ b' : α, f a' = some b' → R b b') ∧ Pairwise S l
   exact and_congr ⟨fun h b mb a ma => h a b mb ma, fun h a b mb ma => h b mb a ma⟩ Iff.rfl
 #align list.pairwise_filter_map List.pairwise_filterMap
+-/
 
 #print List.Pairwise.filter_map /-
 theorem Pairwise.filter_map {S : β → β → Prop} (f : α → Option β)
@@ -286,12 +290,14 @@ theorem Pairwise.filter_map {S : β → β → Prop} (f : α → Option β)
 #align list.pairwise.filter_map List.Pairwise.filter_map
 -/
 
+#print List.pairwise_filter /-
 theorem pairwise_filter (p : α → Prop) [DecidablePred p] {l : List α} :
     Pairwise R (filter p l) ↔ Pairwise (fun x y => p x → p y → R x y) l :=
   by
   rw [← filter_map_eq_filter, pairwise_filter_map]
   apply pairwise.iff; intros; simp only [Option.mem_def, Option.guard_eq_some, and_imp, forall_eq']
 #align list.pairwise_filter List.pairwise_filter
+-/
 
 theorem Pairwise.filter (p : α → Prop) [DecidablePred p] : Pairwise R l → Pairwise R (filter p l) :=
   Pairwise.sublist (filter_sublist _)
@@ -311,6 +317,7 @@ theorem pairwise_pmap {p : β → Prop} {f : ∀ b, p b → α} {l : List β} (h
 #align list.pairwise_pmap List.pairwise_pmap
 -/
 
+#print List.Pairwise.pmap /-
 theorem Pairwise.pmap {l : List α} (hl : Pairwise R l) {p : α → Prop} {f : ∀ a, p a → β}
     (h : ∀ x ∈ l, p x) {S : β → β → Prop}
     (hS : ∀ ⦃x⦄ (hx : p x) ⦃y⦄ (hy : p y), R x y → S (f x hx) (f y hy)) : Pairwise S (l.pmap f h) :=
@@ -318,6 +325,7 @@ theorem Pairwise.pmap {l : List α} (hl : Pairwise R l) {p : α → Prop} {f : 
   refine' (pairwise_pmap h).2 (pairwise.imp_of_mem _ hl)
   intros; apply hS; assumption
 #align list.pairwise.pmap List.Pairwise.pmap
+-/
 
 #print List.pairwise_join /-
 theorem pairwise_join {L : List (List α)} :
@@ -336,11 +344,13 @@ theorem pairwise_join {L : List (List α)} :
 #align list.pairwise_join List.pairwise_join
 -/
 
+#print List.pairwise_bind /-
 theorem pairwise_bind {R : β → β → Prop} {l : List α} {f : α → List β} :
     List.Pairwise R (l.bind f) ↔
       (∀ a ∈ l, Pairwise R (f a)) ∧ Pairwise (fun a₁ a₂ => ∀ x ∈ f a₁, ∀ y ∈ f a₂, R x y) l :=
   by simp [List.bind, List.pairwise_join, List.mem_map, List.pairwise_map']
 #align list.pairwise_bind List.pairwise_bind
+-/
 
 #print List.pairwise_reverse /-
 @[simp]
Diff
@@ -185,7 +185,7 @@ theorem Pairwise.forall (hR : Symmetric R) (hl : l.Pairwise R) :
 -/
 
 #print List.Pairwise.set_pairwise /-
-theorem Pairwise.set_pairwise (hl : Pairwise R l) (hr : Symmetric R) : { x | x ∈ l }.Pairwise R :=
+theorem Pairwise.set_pairwise (hl : Pairwise R l) (hr : Symmetric R) : {x | x ∈ l}.Pairwise R :=
   hl.forall hr
 #align list.pairwise.set_pairwise List.Pairwise.set_pairwise
 -/
@@ -386,10 +386,9 @@ theorem pairwise_of_reflexive_on_dupl_of_forall_ne [DecidableEq α] {l : List α
 theorem pairwise_of_forall_mem_list {l : List α} {r : α → α → Prop} (h : ∀ a ∈ l, ∀ b ∈ l, r a b) :
     l.Pairwise r := by
   classical
-    refine'
-      pairwise_of_reflexive_on_dupl_of_forall_ne (fun a ha' => _) fun a ha b hb _ => h a ha b hb
-    have ha := List.one_le_count_iff_mem.1 ha'.le
-    exact h a ha a ha
+  refine' pairwise_of_reflexive_on_dupl_of_forall_ne (fun a ha' => _) fun a ha b hb _ => h a ha b hb
+  have ha := List.one_le_count_iff_mem.1 ha'.le
+  exact h a ha a ha
 #align list.pairwise_of_forall_mem_list List.pairwise_of_forall_mem_list
 -/
 
Diff
@@ -125,7 +125,7 @@ theorem Pairwise.iff {S : α → α → Prop} (H : ∀ a b, R a b ↔ S a b) {l
 
 #print List.pairwise_of_forall /-
 theorem pairwise_of_forall {l : List α} (H : ∀ x y, R x y) : Pairwise R l := by
-  induction l <;> [exact pairwise.nil;simp only [*, pairwise_cons, forall₂_true_iff, and_true_iff]]
+  induction l <;> [exact pairwise.nil; simp only [*, pairwise_cons, forall₂_true_iff, and_true_iff]]
 #align list.pairwise_of_forall List.pairwise_of_forall
 -/
 
@@ -160,7 +160,7 @@ theorem Pairwise.forall_of_forall_of_flip (h₁ : ∀ x ∈ l, R x x) (h₂ : l.
   by
   induction' l with a l ih
   · exact forall_mem_nil _
-  rw [pairwise_cons] at h₂ h₃
+  rw [pairwise_cons] at h₂ h₃ 
   rintro x (rfl | hx) y (rfl | hy)
   · exact h₁ _ (l.mem_cons_self _)
   · exact h₂.1 _ hy
@@ -209,9 +209,9 @@ theorem pairwise_append {l₁ l₂ : List α} :
     Pairwise R (l₁ ++ l₂) ↔ Pairwise R l₁ ∧ Pairwise R l₂ ∧ ∀ x ∈ l₁, ∀ y ∈ l₂, R x y := by
   induction' l₁ with x l₁ IH <;>
     [simp only [List.Pairwise.nil, forall_prop_of_false (not_mem_nil _), forall_true_iff,
-      and_true_iff, true_and_iff,
-      nil_append];simp only [cons_append, pairwise_cons, forall_mem_append, IH, forall_mem_cons,
-      forall_and, and_assoc', and_left_comm]]
+      and_true_iff, true_and_iff, nil_append];
+    simp only [cons_append, pairwise_cons, forall_mem_append, IH, forall_mem_cons, forall_and,
+      and_assoc', and_left_comm]]
 #align list.pairwise_append List.pairwise_append
 -/
 
@@ -290,7 +290,7 @@ theorem pairwise_filter (p : α → Prop) [DecidablePred p] {l : List α} :
     Pairwise R (filter p l) ↔ Pairwise (fun x y => p x → p y → R x y) l :=
   by
   rw [← filter_map_eq_filter, pairwise_filter_map]
-  apply pairwise.iff; intros ; simp only [Option.mem_def, Option.guard_eq_some, and_imp, forall_eq']
+  apply pairwise.iff; intros; simp only [Option.mem_def, Option.guard_eq_some, and_imp, forall_eq']
 #align list.pairwise_filter List.pairwise_filter
 
 theorem Pairwise.filter (p : α → Prop) [DecidablePred p] : Pairwise R l → Pairwise R (filter p l) :=
@@ -316,7 +316,7 @@ theorem Pairwise.pmap {l : List α} (hl : Pairwise R l) {p : α → Prop} {f : 
     (hS : ∀ ⦃x⦄ (hx : p x) ⦃y⦄ (hy : p y), R x y → S (f x hx) (f y hy)) : Pairwise S (l.pmap f h) :=
   by
   refine' (pairwise_pmap h).2 (pairwise.imp_of_mem _ hl)
-  intros ; apply hS; assumption
+  intros; apply hS; assumption
 #align list.pairwise.pmap List.Pairwise.pmap
 
 #print List.pairwise_join /-
@@ -349,9 +349,8 @@ theorem pairwise_reverse :
   suffices ∀ {R l}, @Pairwise α R l → Pairwise (fun x y => R y x) (reverse l) from fun R l =>
     ⟨fun p => reverse_reverse l ▸ this p, this⟩
   fun R l p => by
-  induction' p with a l h p IH <;>
-    [apply
-      pairwise.nil;simpa only [reverse_cons, pairwise_append, IH, pairwise_cons,
+  induction' p with a l h p IH <;> [apply pairwise.nil;
+    simpa only [reverse_cons, pairwise_append, IH, pairwise_cons,
       forall_prop_of_false (not_mem_nil _), forall_true_iff, pairwise.nil, mem_reverse,
       mem_singleton, forall_eq, true_and_iff] using h]
 #align list.pairwise_reverse List.pairwise_reverse
@@ -473,7 +472,7 @@ theorem pwFilter_map (f : β → α) :
       have h' : ¬∀ b : β, b ∈ pwFilter (fun x y : β => R (f x) (f y)) xs → R (f x) (f b) :=
         fun hh =>
         h fun a ha => by
-          rw [pw_filter_map, mem_map] at ha; rcases ha with ⟨b, hb₀, hb₁⟩
+          rw [pw_filter_map, mem_map] at ha ; rcases ha with ⟨b, hb₀, hb₁⟩
           subst a; exact hh _ hb₀
       rw [map, pw_filter_cons_of_neg h, pw_filter_cons_of_neg h', pw_filter_map]
 #align list.pw_filter_map List.pwFilter_map
@@ -537,7 +536,7 @@ theorem forall_mem_pwFilter (neg_trans : ∀ {x y z}, R x z → R x y ∨ R y z)
   ⟨by
     induction' l with x l IH; · exact fun _ _ => False.elim
     simp only [forall_mem_cons]
-    by_cases ∀ y ∈ pw_filter R l, R x y <;> dsimp at h
+    by_cases ∀ y ∈ pw_filter R l, R x y <;> dsimp at h 
     · simp only [pw_filter_cons_of_pos h, forall_mem_cons, and_imp]
       exact fun r H => ⟨r, IH H⟩
     · rw [pw_filter_cons_of_neg h]
Diff
@@ -401,6 +401,7 @@ theorem pairwise_of_reflexive_of_forall_ne {l : List α} {r : α → α → Prop
 #align list.pairwise_of_reflexive_of_forall_ne List.pairwise_of_reflexive_of_forall_ne
 -/
 
+#print List.pairwise_iff_nthLe /-
 theorem pairwise_iff_nthLe {R} :
     ∀ {l : List α},
       Pairwise R l ↔
@@ -419,6 +420,7 @@ theorem pairwise_iff_nthLe {R} :
     · rcases nth_le_of_mem m with ⟨n, h, rfl⟩
       exact H _ _ (succ_lt_succ h) (succ_pos _)
 #align list.pairwise_iff_nth_le List.pairwise_iff_nthLe
+-/
 
 #print List.pairwise_replicate /-
 theorem pairwise_replicate {α : Type _} {r : α → α → Prop} {x : α} (hx : r x x) :
Diff
@@ -256,23 +256,11 @@ theorem Pairwise.of_map {S : β → β → Prop} (f : α → β) (H : ∀ a b :
 #align list.pairwise.of_map List.Pairwise.of_map
 -/
 
-/- warning: list.pairwise.map -> List.Pairwise.map is a dubious translation:
-lean 3 declaration is
-  forall {α : Type.{u1}} {β : Type.{u2}} {R : α -> α -> Prop} {l : List.{u1} α} {S : β -> β -> Prop} (f : α -> β), (forall (a : α) (b : α), (R a b) -> (S (f a) (f b))) -> (List.Pairwise.{u1} α R l) -> (List.Pairwise.{u2} β S (List.map.{u1, u2} α β f l))
-but is expected to have type
-  forall {α : Type.{u2}} {β : Type.{u1}} {R : α -> α -> Prop} {l : List.{u2} α} {S : β -> β -> Prop} (f : α -> β), (forall (a : α) (b : α), (R a b) -> (S (f a) (f b))) -> (List.Pairwise.{u2} α R l) -> (List.Pairwise.{u1} β S (List.map.{u2, u1} α β f l))
-Case conversion may be inaccurate. Consider using '#align list.pairwise.map List.Pairwise.mapₓ'. -/
 theorem Pairwise.map {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, R a b → S (f a) (f b))
     (p : Pairwise R l) : Pairwise S (map f l) :=
   (pairwise_map' f).2 <| p.imp H
 #align list.pairwise.map List.Pairwise.map
 
-/- warning: list.pairwise_filter_map -> List.pairwise_filterMap is a dubious translation:
-lean 3 declaration is
-  forall {α : Type.{u1}} {β : Type.{u2}} {R : α -> α -> Prop} (f : β -> (Option.{u1} α)) {l : List.{u2} β}, Iff (List.Pairwise.{u1} α R (List.filterMap.{u2, u1} β α f l)) (List.Pairwise.{u2} β (fun (a : β) (a' : β) => forall (b : α), (Membership.Mem.{u1, u1} α (Option.{u1} α) (Option.hasMem.{u1} α) b (f a)) -> (forall (b' : α), (Membership.Mem.{u1, u1} α (Option.{u1} α) (Option.hasMem.{u1} α) b' (f a')) -> (R b b'))) l)
-but is expected to have type
-  forall {α : Type.{u2}} {β : Type.{u1}} {R : α -> α -> Prop} (f : β -> (Option.{u2} α)) {l : List.{u1} β}, Iff (List.Pairwise.{u2} α R (List.filterMap.{u1, u2} β α f l)) (List.Pairwise.{u1} β (fun (a : β) (a' : β) => forall (b : α), (Membership.mem.{u2, u2} α (Option.{u2} α) (Option.instMembershipOption.{u2} α) b (f a)) -> (forall (b' : α), (Membership.mem.{u2, u2} α (Option.{u2} α) (Option.instMembershipOption.{u2} α) b' (f a')) -> (R b b'))) l)
-Case conversion may be inaccurate. Consider using '#align list.pairwise_filter_map List.pairwise_filterMapₓ'. -/
 theorem pairwise_filterMap (f : β → Option α) {l : List β} :
     Pairwise R (filterMap f l) ↔ Pairwise (fun a a' : β => ∀ b ∈ f a, ∀ b' ∈ f a', R b b') l :=
   by
@@ -298,12 +286,6 @@ theorem Pairwise.filter_map {S : β → β → Prop} (f : α → Option β)
 #align list.pairwise.filter_map List.Pairwise.filter_map
 -/
 
-/- warning: list.pairwise_filter -> List.pairwise_filter is a dubious translation:
-lean 3 declaration is
-  forall {α : Type.{u1}} {R : α -> α -> Prop} (p : α -> Prop) [_inst_1 : DecidablePred.{succ u1} α p] {l : List.{u1} α}, Iff (List.Pairwise.{u1} α R (List.filterₓ.{u1} α p (fun (a : α) => _inst_1 a) l)) (List.Pairwise.{u1} α (fun (x : α) (y : α) => (p x) -> (p y) -> (R x y)) l)
-but is expected to have type
-  forall {α : Type.{u1}} {R : α -> α -> Prop} (p : α -> Prop) [_inst_1 : DecidablePred.{succ u1} α p] {l : List.{u1} α}, Iff (List.Pairwise.{u1} α R (List.filter.{u1} α (fun (a : α) => Decidable.decide (p a) ((fun (a : α) => _inst_1 a) a)) l)) (List.Pairwise.{u1} α (fun (x : α) (y : α) => (p x) -> (p y) -> (R x y)) l)
-Case conversion may be inaccurate. Consider using '#align list.pairwise_filter List.pairwise_filterₓ'. -/
 theorem pairwise_filter (p : α → Prop) [DecidablePred p] {l : List α} :
     Pairwise R (filter p l) ↔ Pairwise (fun x y => p x → p y → R x y) l :=
   by
@@ -329,12 +311,6 @@ theorem pairwise_pmap {p : β → Prop} {f : ∀ b, p b → α} {l : List β} (h
 #align list.pairwise_pmap List.pairwise_pmap
 -/
 
-/- warning: list.pairwise.pmap -> List.Pairwise.pmap is a dubious translation:
-lean 3 declaration is
-  forall {α : Type.{u1}} {β : Type.{u2}} {R : α -> α -> Prop} {l : List.{u1} α}, (List.Pairwise.{u1} α R l) -> (forall {p : α -> Prop} {f : forall (a : α), (p a) -> β} (h : forall (x : α), (Membership.Mem.{u1, u1} α (List.{u1} α) (List.hasMem.{u1} α) x l) -> (p x)) {S : β -> β -> Prop}, (forall {{x : α}} (hx : p x) {{y : α}} (hy : p y), (R x y) -> (S (f x hx) (f y hy))) -> (List.Pairwise.{u2} β S (List.pmap.{u1, u2} α β (fun (a : α) => p a) f l h)))
-but is expected to have type
-  forall {α : Type.{u2}} {β : Type.{u1}} {R : α -> α -> Prop} {l : List.{u2} α}, (List.Pairwise.{u2} α R l) -> (forall {p : α -> Prop} {f : forall (a : α), (p a) -> β} (h : forall (x : α), (Membership.mem.{u2, u2} α (List.{u2} α) (List.instMembershipList.{u2} α) x l) -> (p x)) {S : β -> β -> Prop}, (forall {{x : α}} (hx : p x) {{y : α}} (hy : p y), (R x y) -> (S (f x hx) (f y hy))) -> (List.Pairwise.{u1} β S (List.pmap.{u2, u1} α β (fun (a : α) => p a) f l h)))
-Case conversion may be inaccurate. Consider using '#align list.pairwise.pmap List.Pairwise.pmapₓ'. -/
 theorem Pairwise.pmap {l : List α} (hl : Pairwise R l) {p : α → Prop} {f : ∀ a, p a → β}
     (h : ∀ x ∈ l, p x) {S : β → β → Prop}
     (hS : ∀ ⦃x⦄ (hx : p x) ⦃y⦄ (hy : p y), R x y → S (f x hx) (f y hy)) : Pairwise S (l.pmap f h) :=
@@ -360,12 +336,6 @@ theorem pairwise_join {L : List (List α)} :
 #align list.pairwise_join List.pairwise_join
 -/
 
-/- warning: list.pairwise_bind -> List.pairwise_bind is a dubious translation:
-lean 3 declaration is
-  forall {α : Type.{u1}} {β : Type.{u2}} {R : β -> β -> Prop} {l : List.{u1} α} {f : α -> (List.{u2} β)}, Iff (List.Pairwise.{u2} β R (List.bind.{u1, u2} α β l f)) (And (forall (a : α), (Membership.Mem.{u1, u1} α (List.{u1} α) (List.hasMem.{u1} α) a l) -> (List.Pairwise.{u2} β R (f a))) (List.Pairwise.{u1} α (fun (a₁ : α) (a₂ : α) => forall (x : β), (Membership.Mem.{u2, u2} β (List.{u2} β) (List.hasMem.{u2} β) x (f a₁)) -> (forall (y : β), (Membership.Mem.{u2, u2} β (List.{u2} β) (List.hasMem.{u2} β) y (f a₂)) -> (R x y))) l))
-but is expected to have type
-  forall {α : Type.{u2}} {β : Type.{u1}} {R : β -> β -> Prop} {l : List.{u2} α} {f : α -> (List.{u1} β)}, Iff (List.Pairwise.{u1} β R (List.bind.{u2, u1} α β l f)) (And (forall (a : α), (Membership.mem.{u2, u2} α (List.{u2} α) (List.instMembershipList.{u2} α) a l) -> (List.Pairwise.{u1} β R (f a))) (List.Pairwise.{u2} α (fun (a₁ : α) (a₂ : α) => forall (x : β), (Membership.mem.{u1, u1} β (List.{u1} β) (List.instMembershipList.{u1} β) x (f a₁)) -> (forall (y : β), (Membership.mem.{u1, u1} β (List.{u1} β) (List.instMembershipList.{u1} β) y (f a₂)) -> (R x y))) l))
-Case conversion may be inaccurate. Consider using '#align list.pairwise_bind List.pairwise_bindₓ'. -/
 theorem pairwise_bind {R : β → β → Prop} {l : List α} {f : α → List β} :
     List.Pairwise R (l.bind f) ↔
       (∀ a ∈ l, Pairwise R (f a)) ∧ Pairwise (fun a₁ a₂ => ∀ x ∈ f a₁, ∀ y ∈ f a₂, R x y) l :=
@@ -431,12 +401,6 @@ theorem pairwise_of_reflexive_of_forall_ne {l : List α} {r : α → α → Prop
 #align list.pairwise_of_reflexive_of_forall_ne List.pairwise_of_reflexive_of_forall_ne
 -/
 
-/- warning: list.pairwise_iff_nth_le -> List.pairwise_iff_nthLe is a dubious translation:
-lean 3 declaration is
-  forall {α : Type.{u1}} {R : α -> α -> Prop} {l : List.{u1} α}, Iff (List.Pairwise.{u1} α R l) (forall (i : Nat) (j : Nat) (h₁ : LT.lt.{0} Nat (Preorder.toHasLt.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring)))) j (List.length.{u1} α l)) (h₂ : LT.lt.{0} Nat (Preorder.toHasLt.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring)))) i j), R (List.nthLe.{u1} α l i (lt_trans.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) i j (List.length.{u1} α l) h₂ h₁)) (List.nthLe.{u1} α l j h₁))
-but is expected to have type
-  forall {α : Type.{u1}} {R : α -> α -> Prop} {l : List.{u1} α}, Iff (List.Pairwise.{u1} α R l) (forall (i : Nat) (j : Nat) (h₁ : LT.lt.{0} Nat instLTNat j (List.length.{u1} α l)) (h₂ : LT.lt.{0} Nat instLTNat i j), R (List.nthLe.{u1} α l i (lt_trans.{0} Nat (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)) i j (List.length.{u1} α l) h₂ h₁)) (List.nthLe.{u1} α l j h₁))
-Case conversion may be inaccurate. Consider using '#align list.pairwise_iff_nth_le List.pairwise_iff_nthLeₓ'. -/
 theorem pairwise_iff_nthLe {R} :
     ∀ {l : List α},
       Pairwise R l ↔
Diff
@@ -320,8 +320,7 @@ theorem pairwise_pmap {p : β → Prop} {f : ∀ b, p b → α} {l : List β} (h
     Pairwise R (l.pmap f h) ↔
       Pairwise (fun b₁ b₂ => ∀ (h₁ : p b₁) (h₂ : p b₂), R (f b₁ h₁) (f b₂ h₂)) l :=
   by
-  induction' l with a l ihl
-  · simp
+  induction' l with a l ihl; · simp
   obtain ⟨ha, hl⟩ : p a ∧ ∀ b, b ∈ l → p b := by simpa using h
   simp only [ihl hl, pairwise_cons, bex_imp, pmap, and_congr_left_iff, mem_pmap]
   refine' fun _ => ⟨fun H b hb hpa hpb => H _ _ hb rfl, _⟩
@@ -449,8 +448,7 @@ theorem pairwise_iff_nthLe {R} :
     refine'
       ⟨fun H i j h₁ h₂ => _, fun H =>
         ⟨fun a' m => _, fun i j h₁ h₂ => H _ _ (succ_lt_succ h₁) (succ_lt_succ h₂)⟩⟩
-    · cases' j with j
-      · exact (Nat.not_lt_zero _).elim h₂
+    · cases' j with j; · exact (Nat.not_lt_zero _).elim h₂
       cases' i with i
       · exact H.1 _ (nth_le_mem l _ _)
       · exact H.2 _ _ (lt_of_succ_lt_succ h₁) (lt_of_succ_lt_succ h₂)
@@ -509,10 +507,8 @@ theorem pwFilter_map (f : β → α) :
       have h' : ¬∀ b : β, b ∈ pwFilter (fun x y : β => R (f x) (f y)) xs → R (f x) (f b) :=
         fun hh =>
         h fun a ha => by
-          rw [pw_filter_map, mem_map] at ha
-          rcases ha with ⟨b, hb₀, hb₁⟩
-          subst a
-          exact hh _ hb₀
+          rw [pw_filter_map, mem_map] at ha; rcases ha with ⟨b, hb₀, hb₁⟩
+          subst a; exact hh _ hb₀
       rw [map, pw_filter_cons_of_neg h, pw_filter_cons_of_neg h', pw_filter_map]
 #align list.pw_filter_map List.pwFilter_map
 -/
Diff
@@ -125,7 +125,7 @@ theorem Pairwise.iff {S : α → α → Prop} (H : ∀ a b, R a b ↔ S a b) {l
 
 #print List.pairwise_of_forall /-
 theorem pairwise_of_forall {l : List α} (H : ∀ x y, R x y) : Pairwise R l := by
-  induction l <;> [exact pairwise.nil, simp only [*, pairwise_cons, forall₂_true_iff, and_true_iff]]
+  induction l <;> [exact pairwise.nil;simp only [*, pairwise_cons, forall₂_true_iff, and_true_iff]]
 #align list.pairwise_of_forall List.pairwise_of_forall
 -/
 
@@ -209,9 +209,9 @@ theorem pairwise_append {l₁ l₂ : List α} :
     Pairwise R (l₁ ++ l₂) ↔ Pairwise R l₁ ∧ Pairwise R l₂ ∧ ∀ x ∈ l₁, ∀ y ∈ l₂, R x y := by
   induction' l₁ with x l₁ IH <;>
     [simp only [List.Pairwise.nil, forall_prop_of_false (not_mem_nil _), forall_true_iff,
-      and_true_iff, true_and_iff, nil_append],
-    simp only [cons_append, pairwise_cons, forall_mem_append, IH, forall_mem_cons, forall_and,
-      and_assoc', and_left_comm]]
+      and_true_iff, true_and_iff,
+      nil_append];simp only [cons_append, pairwise_cons, forall_mem_append, IH, forall_mem_cons,
+      forall_and, and_assoc', and_left_comm]]
 #align list.pairwise_append List.pairwise_append
 -/
 
@@ -380,8 +380,9 @@ theorem pairwise_reverse :
   suffices ∀ {R l}, @Pairwise α R l → Pairwise (fun x y => R y x) (reverse l) from fun R l =>
     ⟨fun p => reverse_reverse l ▸ this p, this⟩
   fun R l p => by
-  induction' p with a l h p IH <;> [apply pairwise.nil,
-    simpa only [reverse_cons, pairwise_append, IH, pairwise_cons,
+  induction' p with a l h p IH <;>
+    [apply
+      pairwise.nil;simpa only [reverse_cons, pairwise_append, IH, pairwise_cons,
       forall_prop_of_false (not_mem_nil _), forall_true_iff, pairwise.nil, mem_reverse,
       mem_singleton, forall_eq, true_and_iff] using h]
 #align list.pairwise_reverse List.pairwise_reverse
Diff
@@ -431,7 +431,12 @@ theorem pairwise_of_reflexive_of_forall_ne {l : List α} {r : α → α → Prop
 #align list.pairwise_of_reflexive_of_forall_ne List.pairwise_of_reflexive_of_forall_ne
 -/
 
-#print List.pairwise_iff_nthLe /-
+/- warning: list.pairwise_iff_nth_le -> List.pairwise_iff_nthLe is a dubious translation:
+lean 3 declaration is
+  forall {α : Type.{u1}} {R : α -> α -> Prop} {l : List.{u1} α}, Iff (List.Pairwise.{u1} α R l) (forall (i : Nat) (j : Nat) (h₁ : LT.lt.{0} Nat (Preorder.toHasLt.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring)))) j (List.length.{u1} α l)) (h₂ : LT.lt.{0} Nat (Preorder.toHasLt.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring)))) i j), R (List.nthLe.{u1} α l i (lt_trans.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) i j (List.length.{u1} α l) h₂ h₁)) (List.nthLe.{u1} α l j h₁))
+but is expected to have type
+  forall {α : Type.{u1}} {R : α -> α -> Prop} {l : List.{u1} α}, Iff (List.Pairwise.{u1} α R l) (forall (i : Nat) (j : Nat) (h₁ : LT.lt.{0} Nat instLTNat j (List.length.{u1} α l)) (h₂ : LT.lt.{0} Nat instLTNat i j), R (List.nthLe.{u1} α l i (lt_trans.{0} Nat (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)) i j (List.length.{u1} α l) h₂ h₁)) (List.nthLe.{u1} α l j h₁))
+Case conversion may be inaccurate. Consider using '#align list.pairwise_iff_nth_le List.pairwise_iff_nthLeₓ'. -/
 theorem pairwise_iff_nthLe {R} :
     ∀ {l : List α},
       Pairwise R l ↔
@@ -451,7 +456,6 @@ theorem pairwise_iff_nthLe {R} :
     · rcases nth_le_of_mem m with ⟨n, h, rfl⟩
       exact H _ _ (succ_lt_succ h) (succ_pos _)
 #align list.pairwise_iff_nth_le List.pairwise_iff_nthLe
--/
 
 #print List.pairwise_replicate /-
 theorem pairwise_replicate {α : Type _} {r : α → α → Prop} {x : α} (hx : r x x) :
Diff
@@ -370,7 +370,7 @@ Case conversion may be inaccurate. Consider using '#align list.pairwise_bind Lis
 theorem pairwise_bind {R : β → β → Prop} {l : List α} {f : α → List β} :
     List.Pairwise R (l.bind f) ↔
       (∀ a ∈ l, Pairwise R (f a)) ∧ Pairwise (fun a₁ a₂ => ∀ x ∈ f a₁, ∀ y ∈ f a₂, R x y) l :=
-  by simp [List.bind, List.pairwise_join, List.mem_map', List.pairwise_map']
+  by simp [List.bind, List.pairwise_join, List.mem_map, List.pairwise_map']
 #align list.pairwise_bind List.pairwise_bind
 
 #print List.pairwise_reverse /-

Changes in mathlib4

mathlib3
mathlib4
chore(Data/List): add dates to all deprecated lemmas (#12337)

Most of them go back to the port.

Diff
@@ -101,7 +101,7 @@ theorem Pairwise.set_pairwise (hl : Pairwise R l) (hr : Symmetric R) : { x | x 
 #align list.pairwise_middle List.pairwise_middle
 
 -- Porting note: Duplicate of `pairwise_map` but with `f` explicit.
-@[deprecated] theorem pairwise_map' (f : β → α) :
+@[deprecated] theorem pairwise_map' (f : β → α) : -- 2024-02-25
     ∀ {l : List β}, Pairwise R (map f l) ↔ Pairwise (fun a b : β => R (f a) (f b)) l
   | [] => by simp only [map, Pairwise.nil]
   | b :: l => by
@@ -168,7 +168,7 @@ theorem pairwise_of_reflexive_of_forall_ne {l : List α} {r : α → α → Prop
 #align list.pairwise_of_reflexive_of_forall_ne List.pairwise_of_reflexive_of_forall_ne
 
 set_option linter.deprecated false in
-@[deprecated pairwise_iff_get]
+@[deprecated pairwise_iff_get] -- 2023-01-10
 theorem pairwise_iff_nthLe {R} {l : List α} : Pairwise R l ↔
     ∀ (i j) (h₁ : j < length l) (h₂ : i < j), R (nthLe l i (lt_trans h₂ h₁)) (nthLe l j h₁) :=
   pairwise_iff_get.trans
chore: remove more bex and ball from lemma names (#11615)

Follow-up to #10816.

Remaining places containing such lemmas are

  • Option.bex_ne_none and Option.ball_ne_none: defined in Lean core
  • Nat.decidableBallLT and Nat.decidableBallLE: defined in Lean core
  • bef_def is still used in a number of places and could be renamed
  • BAll.imp_{left,right}, BEx.imp_{left,right}, BEx.intro and BEx.elim

I only audited the first ~150 lemmas mentioning "ball"; too many lemmas named after Metric.ball/openBall/closedBall.

Co-authored-by: Yaël Dillies <yael.dillies@gmail.com>

Diff
@@ -127,7 +127,7 @@ theorem pairwise_pmap {p : β → Prop} {f : ∀ b, p b → α} {l : List β} (h
   induction' l with a l ihl
   · simp
   obtain ⟨_, hl⟩ : p a ∧ ∀ b, b ∈ l → p b := by simpa using h
-  simp only [ihl hl, pairwise_cons, bex_imp, pmap, and_congr_left_iff, mem_pmap]
+  simp only [ihl hl, pairwise_cons, exists₂_imp, pmap, and_congr_left_iff, mem_pmap]
   refine' fun _ => ⟨fun H b hb _ hpb => H _ _ hb rfl, _⟩
   rintro H _ b hb rfl
   exact H b hb _ _
golf: replace some apply foo.mpr by rw [foo] (#11515)

Sometimes, that line can be golfed into the next line. Inspired by a comment of @loefflerd; any decisions are my own.

Diff
@@ -151,14 +151,14 @@ theorem Pairwise.pmap {l : List α} (hl : Pairwise R l) {p : α → Prop} {f : 
 
 theorem pairwise_of_forall_mem_list {l : List α} {r : α → α → Prop} (h : ∀ a ∈ l, ∀ b ∈ l, r a b) :
     l.Pairwise r := by
-  apply pairwise_iff_forall_sublist.mpr
+  rw [pairwise_iff_forall_sublist]
   intro a b hab
   apply h <;> (apply hab.subset; simp)
 #align list.pairwise_of_forall_mem_list List.pairwise_of_forall_mem_list
 
 theorem pairwise_of_reflexive_of_forall_ne {l : List α} {r : α → α → Prop} (hr : Reflexive r)
     (h : ∀ a ∈ l, ∀ b ∈ l, a ≠ b → r a b) : l.Pairwise r := by
-  apply pairwise_iff_forall_sublist.mpr
+  rw [pairwise_iff_forall_sublist]
   intro a b hab
   if heq : a = b then
     cases heq; apply hr
chore: reduce imports (#9830)

This uses the improved shake script from #9772 to reduce imports across mathlib. The corresponding noshake.json file has been added to #9772.

Co-authored-by: Mario Carneiro <di.gama@gmail.com>

Diff
@@ -3,10 +3,9 @@ Copyright (c) 2018 Mario Carneiro. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Mario Carneiro
 -/
-import Mathlib.Data.List.Count
-import Mathlib.Data.List.Lex
 import Mathlib.Logic.Pairwise
 import Mathlib.Logic.Relation
+import Mathlib.Data.List.Basic
 
 #align_import data.list.pairwise from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e"
 
chore: update to std4#100 (#6743)

Std bump patch for https://github.com/leanprover/std4/pull/100

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -42,94 +42,36 @@ mk_iff_of_inductive_prop List.Pairwise List.pairwise_iff
 #align list.pairwise.nil List.Pairwise.nil
 #align list.pairwise.cons List.Pairwise.cons
 
-theorem rel_of_pairwise_cons (p : (a :: l).Pairwise R) : ∀ {a'}, a' ∈ l → R a a' :=
-  (pairwise_cons.1 p).1 _
 #align list.rel_of_pairwise_cons List.rel_of_pairwise_cons
 
-theorem Pairwise.of_cons (p : (a :: l).Pairwise R) : Pairwise R l :=
-  (pairwise_cons.1 p).2
 #align list.pairwise.of_cons List.Pairwise.of_cons
 
-theorem Pairwise.tail : ∀ {l : List α} (_p : Pairwise R l), Pairwise R l.tail
-  | [], h => h
-  | _ :: _, h => h.of_cons
 #align list.pairwise.tail List.Pairwise.tail
 
-theorem Pairwise.drop : ∀ {l : List α} {n : ℕ}, List.Pairwise R l → List.Pairwise R (l.drop n)
-  | _, 0, h => h
-  | [], _ + 1, _ => List.Pairwise.nil
-  | a :: l, n + 1, h => by rw [List.drop]; exact Pairwise.drop (pairwise_cons.mp h).right
 #align list.pairwise.drop List.Pairwise.drop
 
-theorem Pairwise.imp_of_mem {S : α → α → Prop} {l : List α}
-    (H : ∀ {a b}, a ∈ l → b ∈ l → R a b → S a b) (p : Pairwise R l) : Pairwise S l := by
-  induction p with
-  | nil => constructor
-  | @cons a l r _ ih =>
-    constructor
-    · exact BAll.imp_right (fun x h ↦ H (mem_cons_self _ _) (mem_cons_of_mem _ h)) r
-    · exact ih fun {a b} m m' ↦ H (mem_cons_of_mem _ m) (mem_cons_of_mem _ m')
 #align list.pairwise.imp_of_mem List.Pairwise.imp_of_mem
 
 #align list.pairwise.imp List.Pairwise.impₓ -- Implicits Order
 
-theorem pairwise_and_iff : (l.Pairwise fun a b => R a b ∧ S a b) ↔ l.Pairwise R ∧ l.Pairwise S :=
-  ⟨fun h => ⟨h.imp @fun a b h => h.1, h.imp @fun a b h => h.2⟩, fun ⟨hR, hS⟩ =>
-    by induction' hR with a l R1 R2 IH <;> simp only [Pairwise.nil, pairwise_cons] at *
-       exact ⟨fun b bl => ⟨R1 b bl, hS.1 b bl⟩, IH ⟨R2, hS.2⟩ hS.2⟩⟩
 #align list.pairwise_and_iff List.pairwise_and_iff
 
-theorem Pairwise.and (hR : l.Pairwise R) (hS : l.Pairwise S) :
-    l.Pairwise fun a b => R a b ∧ S a b :=
-  pairwise_and_iff.2 ⟨hR, hS⟩
 #align list.pairwise.and List.Pairwise.and
 
-theorem Pairwise.imp₂ (H : ∀ a b, R a b → S a b → T a b) (hR : l.Pairwise R) (hS : l.Pairwise S) :
-    l.Pairwise T :=
-  (hR.and hS).imp fun h => (H _ _ h.1 h.2)
 #align list.pairwise.imp₂ List.Pairwise.imp₂
 
-theorem Pairwise.iff_of_mem {S : α → α → Prop} {l : List α}
-    (H : ∀ {a b}, a ∈ l → b ∈ l → (R a b ↔ S a b)) : Pairwise R l ↔ Pairwise S l :=
-  ⟨Pairwise.imp_of_mem fun {_ _} m m' ↦ (H m m').1,
-   Pairwise.imp_of_mem fun {_ _} m m' ↦ (H m m').2⟩
 #align list.pairwise.iff_of_mem List.Pairwise.iff_of_mem
 
-theorem Pairwise.iff {S : α → α → Prop} (H : ∀ a b, R a b ↔ S a b) {l : List α} :
-    Pairwise R l ↔ Pairwise S l :=
-  Pairwise.iff_of_mem fun _ _ => H _ _
 #align list.pairwise.iff List.Pairwise.iff
 
-theorem pairwise_of_forall {l : List α} (H : ∀ x y, R x y) : Pairwise R l := by
-  induction l <;> [exact Pairwise.nil; simp only [*, pairwise_cons, forall₂_true_iff, and_true_iff]]
 #align list.pairwise_of_forall List.pairwise_of_forall
 
-theorem Pairwise.and_mem {l : List α} :
-    Pairwise R l ↔ Pairwise (fun x y => x ∈ l ∧ y ∈ l ∧ R x y) l :=
-  Pairwise.iff_of_mem
-    (by simp (config := { contextual := true }) only [true_and_iff, iff_self_iff, forall₂_true_iff])
 #align list.pairwise.and_mem List.Pairwise.and_mem
 
-theorem Pairwise.imp_mem {l : List α} :
-    Pairwise R l ↔ Pairwise (fun x y => x ∈ l → y ∈ l → R x y) l :=
-  Pairwise.iff_of_mem
-    (by simp (config := { contextual := true }) only [forall_prop_of_true, iff_self_iff,
-        forall₂_true_iff])
 #align list.pairwise.imp_mem List.Pairwise.imp_mem
 
 #align list.pairwise.sublist List.Pairwise.sublistₓ -- Implicits order
 
-theorem Pairwise.forall_of_forall_of_flip (h₁ : ∀ x ∈ l, R x x) (h₂ : l.Pairwise R)
-    (h₃ : l.Pairwise (flip R)) : ∀ ⦃x⦄, x ∈ l → ∀ ⦃y⦄, y ∈ l → R x y := by
-  induction' l with a l ih
-  · exact forall_mem_nil _
-  rw [pairwise_cons] at h₂ h₃
-  simp only [mem_cons]
-  rintro x (rfl | hx) y (rfl | hy)
-  · exact h₁ _ (l.mem_cons_self _)
-  · exact h₂.1 _ hy
-  · exact h₃.1 _ hx
-  · exact ih (fun x hx => h₁ _ <| mem_cons_of_mem _ hx) h₂.2 h₃.2 hx hy
 #align list.pairwise.forall_of_forall_of_flip List.Pairwise.forall_of_forall_of_flip
 
 theorem Pairwise.forall_of_forall (H : Symmetric R) (H₁ : ∀ x ∈ l, R x x) (H₂ : l.Pairwise R) :
@@ -149,29 +91,14 @@ theorem Pairwise.set_pairwise (hl : Pairwise R l) (hr : Symmetric R) : { x | x 
   hl.forall hr
 #align list.pairwise.set_pairwise List.Pairwise.set_pairwise
 
-theorem pairwise_singleton (R) (a : α) : Pairwise R [a] := by
-  simp [Pairwise.nil]
 #align list.pairwise_singleton List.pairwise_singleton
 
-theorem pairwise_pair {a b : α} : Pairwise R [a, b] ↔ R a b := by
-  simp only [pairwise_cons, mem_singleton, forall_eq, forall_prop_of_false (not_mem_nil _),
-    forall_true_iff, Pairwise.nil, and_true_iff]
 #align list.pairwise_pair List.pairwise_pair
 
 #align list.pairwise_append List.pairwise_append
 
-theorem pairwise_append_comm (s : Symmetric R) {l₁ l₂ : List α} :
-    Pairwise R (l₁ ++ l₂) ↔ Pairwise R (l₂ ++ l₁) := by
-  have : ∀ l₁ l₂ : List α, (∀ x : α, x ∈ l₁ → ∀ y : α, y ∈ l₂ → R x y) →
-    ∀ x : α, x ∈ l₂ → ∀ y : α, y ∈ l₁ → R x y := fun l₁ l₂ a x xm y ym ↦ s (a y ym x xm)
-  simp only [pairwise_append, and_left_comm]; rw [Iff.intro (this l₁ l₂) (this l₂ l₁)]
 #align list.pairwise_append_comm List.pairwise_append_comm
 
-theorem pairwise_middle (s : Symmetric R) {a : α} {l₁ l₂ : List α} :
-    Pairwise R (l₁ ++ a :: l₂) ↔ Pairwise R (a :: (l₁ ++ l₂)) :=
-  show Pairwise R (l₁ ++ ([a] ++ l₂)) ↔ Pairwise R ([a] ++ l₁ ++ l₂) by
-    rw [← append_assoc, pairwise_append, @pairwise_append _ _ ([a] ++ l₁), pairwise_append_comm s]
-    simp only [mem_append, or_comm]
 #align list.pairwise_middle List.pairwise_middle
 
 -- Porting note: Duplicate of `pairwise_map` but with `f` explicit.
@@ -183,48 +110,16 @@ theorem pairwise_middle (s : Symmetric R) {a : α} {l₁ l₂ : List α} :
       forall_apply_eq_imp_iff₂, pairwise_map]
 #align list.pairwise_map List.pairwise_map'
 
-theorem Pairwise.of_map {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, S (f a) (f b) → R a b)
-    (p : Pairwise S (map f l)) : Pairwise R l :=
-  (pairwise_map.1 p).imp (H _ _)
 #align list.pairwise.of_map List.Pairwise.of_map
 
-theorem Pairwise.map {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, R a b → S (f a) (f b))
-    (p : Pairwise R l) : Pairwise S (map f l) :=
-  pairwise_map.2 <| p.imp (H _ _)
 #align list.pairwise.map List.Pairwise.map
 
-theorem pairwise_filterMap (f : β → Option α) {l : List β} :
-    Pairwise R (filterMap f l) ↔ Pairwise (fun a a' : β => ∀ b ∈ f a, ∀ b' ∈ f a', R b b') l := by
-  let _S (a a' : β) := ∀ b ∈ f a, ∀ b' ∈ f a', R b b'
-  simp only [Option.mem_def]; induction' l with a l IH
-  · simp only [filterMap, Pairwise.nil]
-  cases' e : f a with b
-  · --Porting note: Why do I need `propext IH` here?
-    rw [filterMap_cons_none _ _ e, propext IH, pairwise_cons]
-    simp only [e, forall_prop_of_false not_false, forall₃_true_iff, true_and_iff]
-  rw [filterMap_cons_some _ _ _ e]
-  simp only [pairwise_cons, mem_filterMap, forall_exists_index, and_imp, IH, e, Option.some.injEq,
-    forall_eq', and_congr_left_iff]
-  intro _
-  exact ⟨fun h a ha b hab => h _ _ ha hab, fun h a b ha hab => h _ ha _ hab⟩
 #align list.pairwise_filter_map List.pairwise_filterMap
 
-theorem Pairwise.filter_map {S : β → β → Prop} (f : α → Option β)
-    (H : ∀ a a' : α, R a a' → ∀ b ∈ f a, ∀ b' ∈ f a', S b b') {l : List α} (p : Pairwise R l) :
-    Pairwise S (filterMap f l) :=
-  (pairwise_filterMap _).2 <| p.imp (H _ _)
 #align list.pairwise.filter_map List.Pairwise.filter_map
 
-theorem pairwise_filter (p : α → Prop) [DecidablePred p] {l : List α} :
-    Pairwise R (filter p l) ↔ Pairwise (fun x y => p x → p y → R x y) l := by
-  rw [← filterMap_eq_filter, pairwise_filterMap]
-  apply Pairwise.iff; intros
-  simp only [decide_eq_true_eq, Option.mem_def, Option.guard_eq_some, and_imp, forall_eq']
 #align list.pairwise_filter List.pairwise_filter
 
---Porting note: changed Prop to Bool
-theorem Pairwise.filter (p : α → Bool) : Pairwise R l → Pairwise R (filter p l) :=
-  Pairwise.sublist (filter_sublist _)
 #align list.pairwise.filter List.Pairwise.filterₓ
 
 theorem pairwise_pmap {p : β → Prop} {f : ∀ b, p b → α} {l : List β} (h : ∀ x ∈ l, p x) :
@@ -247,87 +142,32 @@ theorem Pairwise.pmap {l : List α} (hl : Pairwise R l) {p : α → Prop} {f : 
   intros; apply hS; assumption
 #align list.pairwise.pmap List.Pairwise.pmap
 
-theorem pairwise_join {L : List (List α)} :
-    Pairwise R (join L) ↔
-      (∀ l ∈ L, Pairwise R l) ∧ Pairwise (fun l₁ l₂ => ∀ x ∈ l₁, ∀ y ∈ l₂, R x y) L := by
-  induction' L with l L IH
-  · simp only [join, Pairwise.nil, forall_prop_of_false (not_mem_nil _), forall_const, and_self_iff]
-  have :
-    (∀ x : α, x ∈ l → ∀ (y : α) (x_1 : List α), x_1 ∈ L → y ∈ x_1 → R x y) ↔
-      ∀ a' : List α, a' ∈ L → ∀ x : α, x ∈ l → ∀ y : α, y ∈ a' → R x y :=
-    ⟨fun h a b c d e => h c d e a b, fun h c d e a b => h a b c d e⟩
-  simp only [join, pairwise_append, IH, mem_join, exists_imp, and_imp, this, forall_mem_cons,
-    pairwise_cons]
-  simp only [and_assoc, and_comm, and_left_comm]
 #align list.pairwise_join List.pairwise_join
 
-theorem pairwise_bind {R : β → β → Prop} {l : List α} {f : α → List β} :
-    List.Pairwise R (l.bind f) ↔
-      (∀ a ∈ l, Pairwise R (f a)) ∧ Pairwise (fun a₁ a₂ => ∀ x ∈ f a₁, ∀ y ∈ f a₂, R x y) l :=
-  by simp [List.bind, List.pairwise_join, List.mem_map, List.pairwise_map]
 #align list.pairwise_bind List.pairwise_bind
 
 #align list.pairwise_reverse List.pairwise_reverse
 
-theorem pairwise_of_reflexive_on_dupl_of_forall_ne [DecidableEq α] {l : List α} {r : α → α → Prop}
-    (hr : ∀ a, 1 < count a l → r a a) (h : ∀ a ∈ l, ∀ b ∈ l, a ≠ b → r a b) : l.Pairwise r := by
-  induction' l with hd tl IH
-  · simp
-  · rw [List.pairwise_cons]
-    constructor
-    · intro x hx
-      by_cases H : hd = x
-      · rw [H]
-        refine' hr _ _
-        simpa [count_cons, H, Nat.succ_lt_succ_iff, count_pos_iff_mem] using hx
-      · exact h hd (mem_cons_self _ _) x (mem_cons_of_mem _ hx) H
-    · refine' IH _ _
-      · intro x hx
-        refine' hr _ _
-        rw [count_cons]
-        split_ifs
-        · exact hx.trans (Nat.lt_succ_self _)
-        · exact hx
-      · intro x hx y hy
-        exact h x (mem_cons_of_mem _ hx) y (mem_cons_of_mem _ hy)
 #align list.pairwise_of_reflexive_on_dupl_of_forall_ne List.pairwise_of_reflexive_on_dupl_of_forall_ne
 
 theorem pairwise_of_forall_mem_list {l : List α} {r : α → α → Prop} (h : ∀ a ∈ l, ∀ b ∈ l, r a b) :
     l.Pairwise r := by
-  classical
-    refine'
-      pairwise_of_reflexive_on_dupl_of_forall_ne (fun a ha' => _) fun a ha b hb _ => h a ha b hb
-    have ha := List.count_pos_iff_mem.1 ha'.le
-    exact h a ha a ha
+  apply pairwise_iff_forall_sublist.mpr
+  intro a b hab
+  apply h <;> (apply hab.subset; simp)
 #align list.pairwise_of_forall_mem_list List.pairwise_of_forall_mem_list
 
 theorem pairwise_of_reflexive_of_forall_ne {l : List α} {r : α → α → Prop} (hr : Reflexive r)
     (h : ∀ a ∈ l, ∀ b ∈ l, a ≠ b → r a b) : l.Pairwise r := by
-  classical exact pairwise_of_reflexive_on_dupl_of_forall_ne (fun _ _ => hr _) h
+  apply pairwise_iff_forall_sublist.mpr
+  intro a b hab
+  if heq : a = b then
+    cases heq; apply hr
+  else
+    apply h <;> try (apply hab.subset; simp)
+    exact heq
 #align list.pairwise_of_reflexive_of_forall_ne List.pairwise_of_reflexive_of_forall_ne
 
-theorem pairwise_iff_get : ∀ {l : List α}, Pairwise R l ↔
-    ∀ (i j) (_hij : i < j), R (get l i) (get l j)
-  | [] => by
-    simp only [Pairwise.nil, true_iff_iff]; exact fun i j _h => (Nat.not_lt_zero j).elim j.2
-  | a :: l => by
-    rw [pairwise_cons, pairwise_iff_get]
-    refine'
-      ⟨fun H i j hij => _, fun H =>
-        ⟨fun a' m => _, fun i j hij => _⟩⟩
-    · cases' j with j hj
-      cases' j with j
-      · exact (Nat.not_lt_zero _).elim hij
-      cases' i with i hi
-      cases' i with i
-      · exact H.1 _ (get_mem l _ _)
-      · exact H.2 _ _ (Nat.lt_of_succ_lt_succ hij)
-    · rcases get_of_mem m with ⟨n, h, rfl⟩
-      have := H ⟨0, show 0 < (a::l).length from Nat.succ_pos _⟩ ⟨n.succ, Nat.succ_lt_succ n.2⟩
-        (Nat.succ_pos n)
-      simpa
-    · simpa using H i.succ j.succ (show i.1.succ < j.1.succ from Nat.succ_lt_succ hij)
-
 set_option linter.deprecated false in
 @[deprecated pairwise_iff_get]
 theorem pairwise_iff_nthLe {R} {l : List α} : Pairwise R l ↔
@@ -337,11 +177,6 @@ theorem pairwise_iff_nthLe {R} {l : List α} : Pairwise R l ↔
      fun h i j hij => h i j _ hij⟩
 #align list.pairwise_iff_nth_le List.pairwise_iff_nthLe
 
-theorem pairwise_replicate {α : Type*} {r : α → α → Prop} {x : α} (hx : r x x) :
-    ∀ n : ℕ, Pairwise r (List.replicate n x)
-  | 0 => by simp
-  | n + 1 => by simp only [replicate, add_eq, add_zero, pairwise_cons, mem_replicate, ne_eq,
-    and_imp, forall_eq_apply_imp_iff', hx, implies_true, pairwise_replicate hx n, and_self]
 #align list.pairwise_replicate List.pairwise_replicate
 
 /-! ### Pairwise filtering -/
@@ -349,71 +184,20 @@ theorem pairwise_replicate {α : Type*} {r : α → α → Prop} {x : α} (hx :
 
 variable [DecidableRel R]
 
-@[simp]
-theorem pwFilter_nil : pwFilter R [] = [] :=
-  rfl
 #align list.pw_filter_nil List.pwFilter_nil
 
-@[simp]
-theorem pwFilter_cons_of_pos {a : α} {l : List α} (h : ∀ b ∈ pwFilter R l, R a b) :
-    pwFilter R (a :: l) = a :: pwFilter R l :=
-  if_pos h
 #align list.pw_filter_cons_of_pos List.pwFilter_cons_of_pos
 
-@[simp]
-theorem pwFilter_cons_of_neg {a : α} {l : List α} (h : ¬∀ b ∈ pwFilter R l, R a b) :
-    pwFilter R (a :: l) = pwFilter R l :=
-  if_neg h
 #align list.pw_filter_cons_of_neg List.pwFilter_cons_of_neg
 
-theorem pwFilter_map (f : β → α) :
-    ∀ l : List β, pwFilter R (map f l) = map f (pwFilter (fun x y => R (f x) (f y)) l)
-  | [] => rfl
-  | x :: xs =>
-    if h : ∀ b ∈ pwFilter R (map f xs), R (f x) b then by
-      have h' : ∀ b : β, b ∈ pwFilter (fun x y : β => R (f x) (f y)) xs → R (f x) (f b) :=
-        fun b hb => h _ (by rw [pwFilter_map f xs]; apply mem_map_of_mem _ hb)
-      rw [map, pwFilter_cons_of_pos h, pwFilter_cons_of_pos h', pwFilter_map f xs, map]
-    else by
-      have h' : ¬∀ b : β, b ∈ pwFilter (fun x y : β => R (f x) (f y)) xs → R (f x) (f b) :=
-        fun hh =>
-        h fun a ha => by
-          rw [pwFilter_map f xs, mem_map] at ha
-          rcases ha with ⟨b, hb₀, hb₁⟩
-          subst a
-          exact hh _ hb₀
-      rw [map, pwFilter_cons_of_neg h, pwFilter_cons_of_neg h', pwFilter_map f xs]
 #align list.pw_filter_map List.pwFilter_map
 
-theorem pwFilter_sublist : ∀ l : List α, pwFilter R l <+ l
-  | [] => nil_sublist _
-  | x :: l => by
-    by_cases h : ∀ y ∈ pwFilter R l, R x y
-    · rw [pwFilter_cons_of_pos h]
-      exact (pwFilter_sublist l).cons_cons _
-    · rw [pwFilter_cons_of_neg h]
-      exact sublist_cons_of_sublist _ (pwFilter_sublist l)
 #align list.pw_filter_sublist List.pwFilter_sublist
 
-theorem pwFilter_subset (l : List α) : pwFilter R l ⊆ l :=
-  (pwFilter_sublist _).subset
 #align list.pw_filter_subset List.pwFilter_subset
 
-theorem pairwise_pwFilter : ∀ l : List α, Pairwise R (pwFilter R l)
-  | [] => Pairwise.nil
-  | x :: l => by
-    by_cases h : ∀ y ∈ pwFilter R l, R x y
-    · rw [pwFilter_cons_of_pos h]
-      exact pairwise_cons.2 ⟨h, pairwise_pwFilter l⟩
-    · rw [pwFilter_cons_of_neg h]
-      exact pairwise_pwFilter l
 #align list.pairwise_pw_filter List.pairwise_pwFilter
 
-theorem pwFilter_eq_self {l : List α} : pwFilter R l = l ↔ Pairwise R l :=
-  ⟨fun e => e ▸ pairwise_pwFilter l, fun p => by
-    induction' l with x l IH; · rfl
-    cases' pairwise_cons.1 p with al p
-    rw [pwFilter_cons_of_pos (BAll.imp_left (pwFilter_subset l) al), IH p]⟩
 #align list.pw_filter_eq_self List.pwFilter_eq_self
 
 alias ⟨_, Pairwise.pwFilter⟩ := pwFilter_eq_self
@@ -422,27 +206,8 @@ alias ⟨_, Pairwise.pwFilter⟩ := pwFilter_eq_self
 -- Porting note: commented out
 -- attribute [protected] List.Pairwise.pwFilter
 
-@[simp]
-theorem pwFilter_idempotent : pwFilter R (pwFilter R l) = pwFilter R l :=
-  (pairwise_pwFilter l).pwFilter
-#align list.pw_filter_idempotent List.pwFilter_idempotent
-
-theorem forall_mem_pwFilter (neg_trans : ∀ {x y z}, R x z → R x y ∨ R y z) (a : α) (l : List α) :
-    (∀ b ∈ pwFilter R l, R a b) ↔ ∀ b ∈ l, R a b :=
-  ⟨by
-    induction' l with x l IH; · exact fun _ _ h => (not_mem_nil _ h).elim
-    simp only [forall_mem_cons]
-    by_cases h : ∀ y ∈ pwFilter R l, R x y
-    · simp only [pwFilter_cons_of_pos h, forall_mem_cons, and_imp]
-      exact fun r H => ⟨r, IH H⟩
-    · rw [pwFilter_cons_of_neg h]
-      refine' fun H => ⟨_, IH H⟩
-      cases' e : find? (fun y => ¬R x y) (pwFilter R l) with k
-      · refine' h.elim (BAll.imp_right _ (find?_eq_none.1 e))
-        exact fun y _ => by simp
-      · have := find?_some e
-        exact (neg_trans (H k (find?_mem e))).resolve_right (by simpa),
-          BAll.imp_left (pwFilter_subset l)⟩
+#align list.pw_filter_idempotent List.pwFilter_idem
+
 #align list.forall_mem_pw_filter List.forall_mem_pwFilter
 
 end List
feat: patch for new alias command (#6172)
Diff
@@ -416,7 +416,7 @@ theorem pwFilter_eq_self {l : List α} : pwFilter R l = l ↔ Pairwise R l :=
     rw [pwFilter_cons_of_pos (BAll.imp_left (pwFilter_subset l) al), IH p]⟩
 #align list.pw_filter_eq_self List.pwFilter_eq_self
 
-alias pwFilter_eq_self ↔ _ Pairwise.pwFilter
+alias ⟨_, Pairwise.pwFilter⟩ := pwFilter_eq_self
 #align list.pairwise.pw_filter List.Pairwise.pwFilter
 
 -- Porting note: commented out
chore: bump Std (#6721)

This incorporates changes from https://github.com/leanprover-community/mathlib4/pull/6575

I have also renamed Multiset.countp to Multiset.countP for consistency.

Co-authored-by: James Gallichio <jamesgallicchio@gmail.com>

Co-authored-by: James <jamesgallicchio@gmail.com> Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -279,7 +279,7 @@ theorem pairwise_of_reflexive_on_dupl_of_forall_ne [DecidableEq α] {l : List α
       by_cases H : hd = x
       · rw [H]
         refine' hr _ _
-        simpa [count_cons, H, Nat.succ_lt_succ_iff, count_pos] using hx
+        simpa [count_cons, H, Nat.succ_lt_succ_iff, count_pos_iff_mem] using hx
       · exact h hd (mem_cons_self _ _) x (mem_cons_of_mem _ hx) H
     · refine' IH _ _
       · intro x hx
@@ -297,7 +297,7 @@ theorem pairwise_of_forall_mem_list {l : List α} {r : α → α → Prop} (h :
   classical
     refine'
       pairwise_of_reflexive_on_dupl_of_forall_ne (fun a ha' => _) fun a ha b hb _ => h a ha b hb
-    have ha := List.one_le_count_iff_mem.1 ha'.le
+    have ha := List.count_pos_iff_mem.1 ha'.le
     exact h a ha a ha
 #align list.pairwise_of_forall_mem_list List.pairwise_of_forall_mem_list
 
chore: remove unused simps (#6632)

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>

Diff
@@ -432,7 +432,7 @@ theorem forall_mem_pwFilter (neg_trans : ∀ {x y z}, R x z → R x y ∨ R y z)
   ⟨by
     induction' l with x l IH; · exact fun _ _ h => (not_mem_nil _ h).elim
     simp only [forall_mem_cons]
-    by_cases h : ∀ y ∈ pwFilter R l, R x y <;> dsimp at h
+    by_cases h : ∀ y ∈ pwFilter R l, R x y
     · simp only [pwFilter_cons_of_pos h, forall_mem_cons, and_imp]
       exact fun r H => ⟨r, IH H⟩
     · rw [pwFilter_cons_of_neg h]
chore: banish Type _ and Sort _ (#6499)

We remove all possible occurences of Type _ and Sort _ in favor of Type* and Sort*.

This has nice performance benefits.

Diff
@@ -32,7 +32,7 @@ open Nat Function
 
 namespace List
 
-variable {α β : Type _} {R S T : α → α → Prop} {a : α} {l : List α}
+variable {α β : Type*} {R S T : α → α → Prop} {a : α} {l : List α}
 
 mk_iff_of_inductive_prop List.Pairwise List.pairwise_iff
 #align list.pairwise_iff List.pairwise_iff
@@ -337,7 +337,7 @@ theorem pairwise_iff_nthLe {R} {l : List α} : Pairwise R l ↔
      fun h i j hij => h i j _ hij⟩
 #align list.pairwise_iff_nth_le List.pairwise_iff_nthLe
 
-theorem pairwise_replicate {α : Type _} {r : α → α → Prop} {x : α} (hx : r x x) :
+theorem pairwise_replicate {α : Type*} {r : α → α → Prop} {x : α} (hx : r x x) :
     ∀ n : ℕ, Pairwise r (List.replicate n x)
   | 0 => by simp
   | n + 1 => by simp only [replicate, add_eq, add_zero, pairwise_cons, mem_replicate, ne_eq,
chore: script to replace headers with #align_import statements (#5979)

Open in Gitpod

Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -2,17 +2,14 @@
 Copyright (c) 2018 Mario Carneiro. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Mario Carneiro
-
-! This file was ported from Lean 3 source module data.list.pairwise
-! leanprover-community/mathlib commit f694c7dead66f5d4c80f446c796a5aad14707f0e
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathlib.Data.List.Count
 import Mathlib.Data.List.Lex
 import Mathlib.Logic.Pairwise
 import Mathlib.Logic.Relation
 
+#align_import data.list.pairwise from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e"
+
 /-!
 # Pairwise relations on a list
 
chore: remove occurrences of semicolon after space (#5713)

This is the second half of the changes originally in #5699, removing all occurrences of ; after a space and implementing a linter rule to enforce it.

In most cases this 2-character substring has a space after it, so the following command was run first:

find . -type f -name "*.lean" -exec sed -i -E 's/ ; /; /g' {} \;

The remaining cases were few enough in number that they were done manually.

Diff
@@ -247,7 +247,7 @@ theorem Pairwise.pmap {l : List α} (hl : Pairwise R l) {p : α → Prop} {f : 
     (hS : ∀ ⦃x⦄ (hx : p x) ⦃y⦄ (hy : p y), R x y → S (f x hx) (f y hy)) :
     Pairwise S (l.pmap f h) := by
   refine' (pairwise_pmap h).2 (Pairwise.imp_of_mem _ hl)
-  intros ; apply hS; assumption
+  intros; apply hS; assumption
 #align list.pairwise.pmap List.Pairwise.pmap
 
 theorem pairwise_join {L : List (List α)} :
chore: fix focusing dots (#5708)

This PR is the result of running

find . -type f -name "*.lean" -exec sed -i -E 's/^( +)\. /\1· /' {} \;
find . -type f -name "*.lean" -exec sed -i -E 'N;s/^( +·)\n +(.*)$/\1 \2/;P;D' {} \;

which firstly replaces . focusing dots with · and secondly removes isolated instances of such dots, unifying them with the following line. A new rule is placed in the style linter to verify this.

Diff
@@ -143,9 +143,9 @@ theorem Pairwise.forall_of_forall (H : Symmetric R) (H₁ : ∀ x ∈ l, R x x)
 theorem Pairwise.forall (hR : Symmetric R) (hl : l.Pairwise R) :
     ∀ ⦃a⦄, a ∈ l → ∀ ⦃b⦄, b ∈ l → a ≠ b → R a b := by
   apply Pairwise.forall_of_forall
-  . exact fun a b h hne => hR (h hne.symm)
-  . exact fun _ _ hx => (hx rfl).elim
-  . exact hl.imp (@fun a b h _ => by exact h)
+  · exact fun a b h hne => hR (h hne.symm)
+  · exact fun _ _ hx => (hx rfl).elim
+  · exact hl.imp (@fun a b h _ => by exact h)
 #align list.pairwise.forall List.Pairwise.forall
 
 theorem Pairwise.set_pairwise (hl : Pairwise R l) (hr : Symmetric R) : { x | x ∈ l }.Pairwise R :=
@@ -329,7 +329,7 @@ theorem pairwise_iff_get : ∀ {l : List α}, Pairwise R l ↔
       have := H ⟨0, show 0 < (a::l).length from Nat.succ_pos _⟩ ⟨n.succ, Nat.succ_lt_succ n.2⟩
         (Nat.succ_pos n)
       simpa
-    . simpa using H i.succ j.succ (show i.1.succ < j.1.succ from Nat.succ_lt_succ hij)
+    · simpa using H i.succ j.succ (show i.1.succ < j.1.succ from Nat.succ_lt_succ hij)
 
 set_option linter.deprecated false in
 @[deprecated pairwise_iff_get]
chore: update std 05-22 (#4248)

The main breaking change is that tac <;> [t1, t2] is now written tac <;> [t1; t2], to avoid clashing with tactics like cases and use that take comma-separated lists.

Diff
@@ -104,7 +104,7 @@ theorem Pairwise.iff {S : α → α → Prop} (H : ∀ a b, R a b ↔ S a b) {l
 #align list.pairwise.iff List.Pairwise.iff
 
 theorem pairwise_of_forall {l : List α} (H : ∀ x y, R x y) : Pairwise R l := by
-  induction l <;> [exact Pairwise.nil, simp only [*, pairwise_cons, forall₂_true_iff, and_true_iff]]
+  induction l <;> [exact Pairwise.nil; simp only [*, pairwise_cons, forall₂_true_iff, and_true_iff]]
 #align list.pairwise_of_forall List.pairwise_of_forall
 
 theorem Pairwise.and_mem {l : List α} :
chore: bye-bye, solo bys! (#3825)

This PR puts, with one exception, every single remaining by that lies all by itself on its own line to the previous line, thus matching the current behaviour of start-port.sh. The exception is when the by begins the second or later argument to a tuple or anonymous constructor; see https://github.com/leanprover-community/mathlib4/pull/3825#discussion_r1186702599.

Essentially this is s/\n *by$/ by/g, but with manual editing to satisfy the linter's max-100-char-line requirement. The Python style linter is also modified to catch these "isolated bys".

Diff
@@ -373,13 +373,11 @@ theorem pwFilter_map (f : β → α) :
     ∀ l : List β, pwFilter R (map f l) = map f (pwFilter (fun x y => R (f x) (f y)) l)
   | [] => rfl
   | x :: xs =>
-    if h : ∀ b ∈ pwFilter R (map f xs), R (f x) b then
-      by
+    if h : ∀ b ∈ pwFilter R (map f xs), R (f x) b then by
       have h' : ∀ b : β, b ∈ pwFilter (fun x y : β => R (f x) (f y)) xs → R (f x) (f b) :=
         fun b hb => h _ (by rw [pwFilter_map f xs]; apply mem_map_of_mem _ hb)
       rw [map, pwFilter_cons_of_pos h, pwFilter_cons_of_pos h', pwFilter_map f xs, map]
-    else
-      by
+    else by
       have h' : ¬∀ b : β, b ∈ pwFilter (fun x y : β => R (f x) (f y)) xs → R (f x) (f b) :=
         fun hh =>
         h fun a ha => by
@@ -415,8 +413,7 @@ theorem pairwise_pwFilter : ∀ l : List α, Pairwise R (pwFilter R l)
 #align list.pairwise_pw_filter List.pairwise_pwFilter
 
 theorem pwFilter_eq_self {l : List α} : pwFilter R l = l ↔ Pairwise R l :=
-  ⟨fun e => e ▸ pairwise_pwFilter l, fun p =>
-    by
+  ⟨fun e => e ▸ pairwise_pwFilter l, fun p => by
     induction' l with x l IH; · rfl
     cases' pairwise_cons.1 p with al p
     rw [pwFilter_cons_of_pos (BAll.imp_left (pwFilter_subset l) al), IH p]⟩
chore: bump Std (#3113)

Notably incorporates https://github.com/leanprover/std4/pull/98 and https://github.com/leanprover/std4/pull/109.

https://github.com/leanprover/std4/pull/98 moves a number of lemmas from Mathlib to Std, so the bump requires deleting them in Mathlib. I did check on each lemma whether its attributes were kept in the move (and gave attribute markings in Mathlib if they were not present in Std), but a reviewer may wish to re-check.

List.mem_map changed statement from b ∈ l.map f ↔ ∃ a, a ∈ l ∧ b = f a to b ∈ l.map f ↔ ∃ a, a ∈ l ∧ f a = b. Similarly for List.exists_of_mem_map. This was a deliberate change, so I have simply adjusted proofs (many become simpler, which supports the change). I also deleted List.mem_map', List.exists_of_mem_map', which were temporary versions in Mathlib while waiting for this change (replacing their uses with the unprimed versions).

Also, the lemma sublist_nil_iff_eq_nil seems to have been renamed to sublist_nil during the move, so I added an alias for the old name.

(another issue fixed during review by @digama0) List.Sublist.filter had an argument change from explicit to implicit. This appears to have been an oversight (cc @JamesGallicchio). I have temporarily introduced List.Sublist.filter' with the argument explicit, and replaced Mathlib uses of Sublist.filter with Sublist.filter'. Later we can fix the argument in Std, and then delete List.Sublist.filter'.

Diff
@@ -182,7 +182,7 @@ theorem pairwise_middle (s : Symmetric R) {a : α} {l₁ l₂ : List α} :
     ∀ {l : List β}, Pairwise R (map f l) ↔ Pairwise (fun a b : β => R (f a) (f b)) l
   | [] => by simp only [map, Pairwise.nil]
   | b :: l => by
-    simp only [map, pairwise_cons, mem_map', forall_exists_index, and_imp,
+    simp only [map, pairwise_cons, mem_map, forall_exists_index, and_imp,
       forall_apply_eq_imp_iff₂, pairwise_map]
 #align list.pairwise_map List.pairwise_map'
 
@@ -267,7 +267,7 @@ theorem pairwise_join {L : List (List α)} :
 theorem pairwise_bind {R : β → β → Prop} {l : List α} {f : α → List β} :
     List.Pairwise R (l.bind f) ↔
       (∀ a ∈ l, Pairwise R (f a)) ∧ Pairwise (fun a₁ a₂ => ∀ x ∈ f a₁, ∀ y ∈ f a₂, R x y) l :=
-  by simp [List.bind, List.pairwise_join, List.mem_map', List.pairwise_map]
+  by simp [List.bind, List.pairwise_join, List.mem_map, List.pairwise_map]
 #align list.pairwise_bind List.pairwise_bind
 
 #align list.pairwise_reverse List.pairwise_reverse
chore: add missing hypothesis names to by_cases (#2679)
Diff
@@ -393,7 +393,7 @@ theorem pwFilter_map (f : β → α) :
 theorem pwFilter_sublist : ∀ l : List α, pwFilter R l <+ l
   | [] => nil_sublist _
   | x :: l => by
-    by_cases ∀ y ∈ pwFilter R l, R x y
+    by_cases h : ∀ y ∈ pwFilter R l, R x y
     · rw [pwFilter_cons_of_pos h]
       exact (pwFilter_sublist l).cons_cons _
     · rw [pwFilter_cons_of_neg h]
@@ -407,7 +407,7 @@ theorem pwFilter_subset (l : List α) : pwFilter R l ⊆ l :=
 theorem pairwise_pwFilter : ∀ l : List α, Pairwise R (pwFilter R l)
   | [] => Pairwise.nil
   | x :: l => by
-    by_cases ∀ y ∈ pwFilter R l, R x y
+    by_cases h : ∀ y ∈ pwFilter R l, R x y
     · rw [pwFilter_cons_of_pos h]
       exact pairwise_cons.2 ⟨h, pairwise_pwFilter l⟩
     · rw [pwFilter_cons_of_neg h]
@@ -438,7 +438,7 @@ theorem forall_mem_pwFilter (neg_trans : ∀ {x y z}, R x z → R x y ∨ R y z)
   ⟨by
     induction' l with x l IH; · exact fun _ _ h => (not_mem_nil _ h).elim
     simp only [forall_mem_cons]
-    by_cases ∀ y ∈ pwFilter R l, R x y <;> dsimp at h
+    by_cases h : ∀ y ∈ pwFilter R l, R x y <;> dsimp at h
     · simp only [pwFilter_cons_of_pos h, forall_mem_cons, and_imp]
       exact fun r H => ⟨r, IH H⟩
     · rw [pwFilter_cons_of_neg h]
Diff
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Mario Carneiro
 
 ! This file was ported from Lean 3 source module data.list.pairwise
-! leanprover-community/mathlib commit dd71334db81d0bd444af1ee339a29298bef40734
+! leanprover-community/mathlib commit f694c7dead66f5d4c80f446c796a5aad14707f0e
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
chore: add missing #align statements (#1902)

This PR is the result of a slight variant on the following "algorithm"

  • take all mathlib 3 names, remove _ and make all uppercase letters into lowercase
  • take all mathlib 4 names, remove _ and make all uppercase letters into lowercase
  • look for matches, and create pairs (original_lean3_name, OriginalLean4Name)
  • for pairs that do not have an align statement:
    • use Lean 4 to lookup the file + position of the Lean 4 name
    • add an #align statement just before the next empty line
  • manually fix some tiny mistakes (e.g., empty lines in proofs might cause the #align statement to have been inserted too early)
Diff
@@ -38,6 +38,7 @@ namespace List
 variable {α β : Type _} {R S T : α → α → Prop} {a : α} {l : List α}
 
 mk_iff_of_inductive_prop List.Pairwise List.pairwise_iff
+#align list.pairwise_iff List.pairwise_iff
 
 /-! ### Pairwise -/
 
@@ -422,6 +423,7 @@ theorem pwFilter_eq_self {l : List α} : pwFilter R l = l ↔ Pairwise R l :=
 #align list.pw_filter_eq_self List.pwFilter_eq_self
 
 alias pwFilter_eq_self ↔ _ Pairwise.pwFilter
+#align list.pairwise.pw_filter List.Pairwise.pwFilter
 
 -- Porting note: commented out
 -- attribute [protected] List.Pairwise.pwFilter
chore: format by line breaks (#1523)

During porting, I usually fix the desired format we seem to want for the line breaks around by with

awk '{do {{if (match($0, "^  by$") && length(p) < 98) {p=p " by";} else {if (NR!=1) {print p}; p=$0}}} while (getline == 1) if (getline==0) print p}' Mathlib/File/Im/Working/On.lean

I noticed there are some more files that slipped through.

This pull request is the result of running this command:

grep -lr "^  by\$" Mathlib | xargs -n 1 awk -i inplace '{do {{if (match($0, "^  by$") && length(p) < 98 && not (match(p, "^[ \t]*--"))) {p=p " by";} else {if (NR!=1) {print p}; p=$0}}} while (getline == 1) if (getline==0) print p}'

Co-authored-by: Moritz Firsching <firsching@google.com>

Diff
@@ -122,8 +122,7 @@ theorem Pairwise.imp_mem {l : List α} :
 #align list.pairwise.sublist List.Pairwise.sublistₓ -- Implicits order
 
 theorem Pairwise.forall_of_forall_of_flip (h₁ : ∀ x ∈ l, R x x) (h₂ : l.Pairwise R)
-    (h₃ : l.Pairwise (flip R)) : ∀ ⦃x⦄, x ∈ l → ∀ ⦃y⦄, y ∈ l → R x y :=
-  by
+    (h₃ : l.Pairwise (flip R)) : ∀ ⦃x⦄, x ∈ l → ∀ ⦃y⦄, y ∈ l → R x y := by
   induction' l with a l ih
   · exact forall_mem_nil _
   rw [pairwise_cons] at h₂ h₃
@@ -197,8 +196,7 @@ theorem Pairwise.map {S : β → β → Prop} (f : α → β) (H : ∀ a b : α,
 #align list.pairwise.map List.Pairwise.map
 
 theorem pairwise_filterMap (f : β → Option α) {l : List β} :
-    Pairwise R (filterMap f l) ↔ Pairwise (fun a a' : β => ∀ b ∈ f a, ∀ b' ∈ f a', R b b') l :=
-  by
+    Pairwise R (filterMap f l) ↔ Pairwise (fun a a' : β => ∀ b ∈ f a, ∀ b' ∈ f a', R b b') l := by
   let _S (a a' : β) := ∀ b ∈ f a, ∀ b' ∈ f a', R b b'
   simp only [Option.mem_def]; induction' l with a l IH
   · simp only [filterMap, Pairwise.nil]
@@ -233,8 +231,7 @@ theorem Pairwise.filter (p : α → Bool) : Pairwise R l → Pairwise R (filter
 
 theorem pairwise_pmap {p : β → Prop} {f : ∀ b, p b → α} {l : List β} (h : ∀ x ∈ l, p x) :
     Pairwise R (l.pmap f h) ↔
-      Pairwise (fun b₁ b₂ => ∀ (h₁ : p b₁) (h₂ : p b₂), R (f b₁ h₁) (f b₂ h₂)) l :=
-  by
+      Pairwise (fun b₁ b₂ => ∀ (h₁ : p b₁) (h₂ : p b₂), R (f b₁ h₁) (f b₂ h₂)) l := by
   induction' l with a l ihl
   · simp
   obtain ⟨_, hl⟩ : p a ∧ ∀ b, b ∈ l → p b := by simpa using h
@@ -254,8 +251,7 @@ theorem Pairwise.pmap {l : List α} (hl : Pairwise R l) {p : α → Prop} {f : 
 
 theorem pairwise_join {L : List (List α)} :
     Pairwise R (join L) ↔
-      (∀ l ∈ L, Pairwise R l) ∧ Pairwise (fun l₁ l₂ => ∀ x ∈ l₁, ∀ y ∈ l₂, R x y) L :=
-  by
+      (∀ l ∈ L, Pairwise R l) ∧ Pairwise (fun l₁ l₂ => ∀ x ∈ l₁, ∀ y ∈ l₂, R x y) L := by
   induction' L with l L IH
   · simp only [join, Pairwise.nil, forall_prop_of_false (not_mem_nil _), forall_const, and_self_iff]
   have :
@@ -276,8 +272,7 @@ theorem pairwise_bind {R : β → β → Prop} {l : List α} {f : α → List β
 #align list.pairwise_reverse List.pairwise_reverse
 
 theorem pairwise_of_reflexive_on_dupl_of_forall_ne [DecidableEq α] {l : List α} {r : α → α → Prop}
-    (hr : ∀ a, 1 < count a l → r a a) (h : ∀ a ∈ l, ∀ b ∈ l, a ≠ b → r a b) : l.Pairwise r :=
-  by
+    (hr : ∀ a, 1 < count a l → r a a) (h : ∀ a ∈ l, ∀ b ∈ l, a ≠ b → r a b) : l.Pairwise r := by
   induction' l with hd tl IH
   · simp
   · rw [List.pairwise_cons]
chore: the style linter shouldn't complain about long #align lines (#1643)
Diff
@@ -297,8 +297,7 @@ theorem pairwise_of_reflexive_on_dupl_of_forall_ne [DecidableEq α] {l : List α
         · exact hx
       · intro x hx y hy
         exact h x (mem_cons_of_mem _ hx) y (mem_cons_of_mem _ hy)
-#align
-  list.pairwise_of_reflexive_on_dupl_of_forall_ne List.pairwise_of_reflexive_on_dupl_of_forall_ne
+#align list.pairwise_of_reflexive_on_dupl_of_forall_ne List.pairwise_of_reflexive_on_dupl_of_forall_ne
 
 theorem pairwise_of_forall_mem_list {l : List α} {r : α → α → Prop} (h : ∀ a ∈ l, ∀ b ∈ l, r a b) :
     l.Pairwise r := by
Refactor: drop List.repeat (#1579)

Mathlib 3 migrated to list.replicate in leanprover-community/mathlib#18127 (merged) and leanprover-community/mathlib#18181 (awaiting review).

Diff
@@ -350,13 +350,7 @@ theorem pairwise_replicate {α : Type _} {r : α → α → Prop} {x : α} (hx :
   | 0 => by simp
   | n + 1 => by simp only [replicate, add_eq, add_zero, pairwise_cons, mem_replicate, ne_eq,
     and_imp, forall_eq_apply_imp_iff', hx, implies_true, pairwise_replicate hx n, and_self]
-
-set_option linter.deprecated false in
-@[deprecated pairwise_replicate]
-theorem pairwise_repeat {α : Type _} {r : α → α → Prop} {x : α} (hx : r x x) :
-    ∀ n : ℕ, Pairwise r (List.repeat x n) :=
-  List.pairwise_replicate hx
-#align list.pairwise_repeat List.pairwise_repeat
+#align list.pairwise_replicate List.pairwise_replicate
 
 /-! ### Pairwise filtering -/
 
feat: port Mathlib.Data.List.Nodup (#1456)

Co-authored-by: ChrisHughes24 <chrishughes24@gmail.com>

Diff
@@ -226,9 +226,10 @@ theorem pairwise_filter (p : α → Prop) [DecidablePred p] {l : List α} :
   simp only [decide_eq_true_eq, Option.mem_def, Option.guard_eq_some, and_imp, forall_eq']
 #align list.pairwise_filter List.pairwise_filter
 
-theorem Pairwise.filter (p : α → Prop) [DecidablePred p] : Pairwise R l → Pairwise R (filter p l) :=
+--Porting note: changed Prop to Bool
+theorem Pairwise.filter (p : α → Bool) : Pairwise R l → Pairwise R (filter p l) :=
   Pairwise.sublist (filter_sublist _)
-#align list.pairwise.filter List.Pairwise.filter
+#align list.pairwise.filter List.Pairwise.filterₓ
 
 theorem pairwise_pmap {p : β → Prop} {f : ∀ b, p b → α} {l : List β} (h : ∀ x ∈ l, p x) :
     Pairwise R (l.pmap f h) ↔
feat port: Data.List.Pairwise (#1450)
Diff
@@ -2,34 +2,66 @@
 Copyright (c) 2018 Mario Carneiro. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Mario Carneiro
+
+! This file was ported from Lean 3 source module data.list.pairwise
+! leanprover-community/mathlib commit dd71334db81d0bd444af1ee339a29298bef40734
+! Please do not edit these lines, except to modify the commit id
+! if you have ported upstream changes.
 -/
-import Mathlib.Data.List.Basic
+import Mathlib.Data.List.Count
+import Mathlib.Data.List.Lex
+import Mathlib.Logic.Pairwise
+import Mathlib.Logic.Relation
 
 /-!
 # Pairwise relations on a list
+
+This file provides basic results about `List.Pairwise` and `List.pwFilter` (definitions are in
+`Data.List.Defs`).
+`Pairwise r [a 0, ..., a (n - 1)]` means `∀ i j, i < j → r (a i) (a j)`. For example,
+`Pairwise (≠) l` means that all elements of `l` are distinct, and `Pairwise (<) l` means that `l`
+is strictly increasing.
+`pwFilter r l` is the list obtained by iteratively adding each element of `l` that doesn't break
+the pairwiseness of the list we have so far. It thus yields `l'` a maximal sublist of `l` such that
+`Pairwise r l'`.
+
+## Tags
+
+sorted, nodup
 -/
 
+
+open Nat Function
+
 namespace List
 
 variable {α β : Type _} {R S T : α → α → Prop} {a : α} {l : List α}
 
-theorem pairwise_append_comm (s : Symmetric R) {l₁ l₂ : List α} :
-    Pairwise R (l₁ ++ l₂) ↔ Pairwise R (l₂ ++ l₁) := by
-  have : ∀ l₁ l₂ : List α, (∀ x : α, x ∈ l₁ → ∀ y : α, y ∈ l₂ → R x y) →
-    ∀ x : α, x ∈ l₂ → ∀ y : α, y ∈ l₁ → R x y := fun l₁ l₂ a x xm y ym ↦ s (a y ym x xm)
-  simp only [pairwise_append, and_left_comm]; rw [Iff.intro (this l₁ l₂) (this l₂ l₁)]
+mk_iff_of_inductive_prop List.Pairwise List.pairwise_iff
 
-theorem pairwise_middle (s : Symmetric R) {a : α} {l₁ l₂ : List α} :
-    Pairwise R (l₁ ++ a :: l₂) ↔ Pairwise R (a :: (l₁ ++ l₂)) :=
-  show Pairwise R (l₁ ++ ([a] ++ l₂)) ↔ Pairwise R ([a] ++ l₁ ++ l₂) by
-    rw [← append_assoc, pairwise_append, @pairwise_append _ _ ([a] ++ l₁), pairwise_append_comm s]
-    simp only [mem_append, or_comm]
+/-! ### Pairwise -/
 
-theorem pairwise_singleton (R) (a : α) : Pairwise R [a] := by
-  simp [Pairwise.nil]
+#align list.pairwise.nil List.Pairwise.nil
+#align list.pairwise.cons List.Pairwise.cons
 
 theorem rel_of_pairwise_cons (p : (a :: l).Pairwise R) : ∀ {a'}, a' ∈ l → R a a' :=
   (pairwise_cons.1 p).1 _
+#align list.rel_of_pairwise_cons List.rel_of_pairwise_cons
+
+theorem Pairwise.of_cons (p : (a :: l).Pairwise R) : Pairwise R l :=
+  (pairwise_cons.1 p).2
+#align list.pairwise.of_cons List.Pairwise.of_cons
+
+theorem Pairwise.tail : ∀ {l : List α} (_p : Pairwise R l), Pairwise R l.tail
+  | [], h => h
+  | _ :: _, h => h.of_cons
+#align list.pairwise.tail List.Pairwise.tail
+
+theorem Pairwise.drop : ∀ {l : List α} {n : ℕ}, List.Pairwise R l → List.Pairwise R (l.drop n)
+  | _, 0, h => h
+  | [], _ + 1, _ => List.Pairwise.nil
+  | a :: l, n + 1, h => by rw [List.drop]; exact Pairwise.drop (pairwise_cons.mp h).right
+#align list.pairwise.drop List.Pairwise.drop
 
 theorem Pairwise.imp_of_mem {S : α → α → Prop} {l : List α}
     (H : ∀ {a b}, a ∈ l → b ∈ l → R a b → S a b) (p : Pairwise R l) : Pairwise S l := by
@@ -39,20 +71,393 @@ theorem Pairwise.imp_of_mem {S : α → α → Prop} {l : List α}
     constructor
     · exact BAll.imp_right (fun x h ↦ H (mem_cons_self _ _) (mem_cons_of_mem _ h)) r
     · exact ih fun {a b} m m' ↦ H (mem_cons_of_mem _ m) (mem_cons_of_mem _ m')
+#align list.pairwise.imp_of_mem List.Pairwise.imp_of_mem
+
+#align list.pairwise.imp List.Pairwise.impₓ -- Implicits Order
+
+theorem pairwise_and_iff : (l.Pairwise fun a b => R a b ∧ S a b) ↔ l.Pairwise R ∧ l.Pairwise S :=
+  ⟨fun h => ⟨h.imp @fun a b h => h.1, h.imp @fun a b h => h.2⟩, fun ⟨hR, hS⟩ =>
+    by induction' hR with a l R1 R2 IH <;> simp only [Pairwise.nil, pairwise_cons] at *
+       exact ⟨fun b bl => ⟨R1 b bl, hS.1 b bl⟩, IH ⟨R2, hS.2⟩ hS.2⟩⟩
+#align list.pairwise_and_iff List.pairwise_and_iff
+
+theorem Pairwise.and (hR : l.Pairwise R) (hS : l.Pairwise S) :
+    l.Pairwise fun a b => R a b ∧ S a b :=
+  pairwise_and_iff.2 ⟨hR, hS⟩
+#align list.pairwise.and List.Pairwise.and
+
+theorem Pairwise.imp₂ (H : ∀ a b, R a b → S a b → T a b) (hR : l.Pairwise R) (hS : l.Pairwise S) :
+    l.Pairwise T :=
+  (hR.and hS).imp fun h => (H _ _ h.1 h.2)
+#align list.pairwise.imp₂ List.Pairwise.imp₂
+
+theorem Pairwise.iff_of_mem {S : α → α → Prop} {l : List α}
+    (H : ∀ {a b}, a ∈ l → b ∈ l → (R a b ↔ S a b)) : Pairwise R l ↔ Pairwise S l :=
+  ⟨Pairwise.imp_of_mem fun {_ _} m m' ↦ (H m m').1,
+   Pairwise.imp_of_mem fun {_ _} m m' ↦ (H m m').2⟩
+#align list.pairwise.iff_of_mem List.Pairwise.iff_of_mem
+
+theorem Pairwise.iff {S : α → α → Prop} (H : ∀ a b, R a b ↔ S a b) {l : List α} :
+    Pairwise R l ↔ Pairwise S l :=
+  Pairwise.iff_of_mem fun _ _ => H _ _
+#align list.pairwise.iff List.Pairwise.iff
+
+theorem pairwise_of_forall {l : List α} (H : ∀ x y, R x y) : Pairwise R l := by
+  induction l <;> [exact Pairwise.nil, simp only [*, pairwise_cons, forall₂_true_iff, and_true_iff]]
+#align list.pairwise_of_forall List.pairwise_of_forall
+
+theorem Pairwise.and_mem {l : List α} :
+    Pairwise R l ↔ Pairwise (fun x y => x ∈ l ∧ y ∈ l ∧ R x y) l :=
+  Pairwise.iff_of_mem
+    (by simp (config := { contextual := true }) only [true_and_iff, iff_self_iff, forall₂_true_iff])
+#align list.pairwise.and_mem List.Pairwise.and_mem
+
+theorem Pairwise.imp_mem {l : List α} :
+    Pairwise R l ↔ Pairwise (fun x y => x ∈ l → y ∈ l → R x y) l :=
+  Pairwise.iff_of_mem
+    (by simp (config := { contextual := true }) only [forall_prop_of_true, iff_self_iff,
+        forall₂_true_iff])
+#align list.pairwise.imp_mem List.Pairwise.imp_mem
+
+#align list.pairwise.sublist List.Pairwise.sublistₓ -- Implicits order
+
+theorem Pairwise.forall_of_forall_of_flip (h₁ : ∀ x ∈ l, R x x) (h₂ : l.Pairwise R)
+    (h₃ : l.Pairwise (flip R)) : ∀ ⦃x⦄, x ∈ l → ∀ ⦃y⦄, y ∈ l → R x y :=
+  by
+  induction' l with a l ih
+  · exact forall_mem_nil _
+  rw [pairwise_cons] at h₂ h₃
+  simp only [mem_cons]
+  rintro x (rfl | hx) y (rfl | hy)
+  · exact h₁ _ (l.mem_cons_self _)
+  · exact h₂.1 _ hy
+  · exact h₃.1 _ hx
+  · exact ih (fun x hx => h₁ _ <| mem_cons_of_mem _ hx) h₂.2 h₃.2 hx hy
+#align list.pairwise.forall_of_forall_of_flip List.Pairwise.forall_of_forall_of_flip
+
+theorem Pairwise.forall_of_forall (H : Symmetric R) (H₁ : ∀ x ∈ l, R x x) (H₂ : l.Pairwise R) :
+    ∀ ⦃x⦄, x ∈ l → ∀ ⦃y⦄, y ∈ l → R x y :=
+  H₂.forall_of_forall_of_flip H₁ <| by rwa [H.flip_eq]
+#align list.pairwise.forall_of_forall List.Pairwise.forall_of_forall
+
+theorem Pairwise.forall (hR : Symmetric R) (hl : l.Pairwise R) :
+    ∀ ⦃a⦄, a ∈ l → ∀ ⦃b⦄, b ∈ l → a ≠ b → R a b := by
+  apply Pairwise.forall_of_forall
+  . exact fun a b h hne => hR (h hne.symm)
+  . exact fun _ _ hx => (hx rfl).elim
+  . exact hl.imp (@fun a b h _ => by exact h)
+#align list.pairwise.forall List.Pairwise.forall
+
+theorem Pairwise.set_pairwise (hl : Pairwise R l) (hr : Symmetric R) : { x | x ∈ l }.Pairwise R :=
+  hl.forall hr
+#align list.pairwise.set_pairwise List.Pairwise.set_pairwise
+
+theorem pairwise_singleton (R) (a : α) : Pairwise R [a] := by
+  simp [Pairwise.nil]
+#align list.pairwise_singleton List.pairwise_singleton
+
+theorem pairwise_pair {a b : α} : Pairwise R [a, b] ↔ R a b := by
+  simp only [pairwise_cons, mem_singleton, forall_eq, forall_prop_of_false (not_mem_nil _),
+    forall_true_iff, Pairwise.nil, and_true_iff]
+#align list.pairwise_pair List.pairwise_pair
+
+#align list.pairwise_append List.pairwise_append
+
+theorem pairwise_append_comm (s : Symmetric R) {l₁ l₂ : List α} :
+    Pairwise R (l₁ ++ l₂) ↔ Pairwise R (l₂ ++ l₁) := by
+  have : ∀ l₁ l₂ : List α, (∀ x : α, x ∈ l₁ → ∀ y : α, y ∈ l₂ → R x y) →
+    ∀ x : α, x ∈ l₂ → ∀ y : α, y ∈ l₁ → R x y := fun l₁ l₂ a x xm y ym ↦ s (a y ym x xm)
+  simp only [pairwise_append, and_left_comm]; rw [Iff.intro (this l₁ l₂) (this l₂ l₁)]
+#align list.pairwise_append_comm List.pairwise_append_comm
+
+theorem pairwise_middle (s : Symmetric R) {a : α} {l₁ l₂ : List α} :
+    Pairwise R (l₁ ++ a :: l₂) ↔ Pairwise R (a :: (l₁ ++ l₂)) :=
+  show Pairwise R (l₁ ++ ([a] ++ l₂)) ↔ Pairwise R ([a] ++ l₁ ++ l₂) by
+    rw [← append_assoc, pairwise_append, @pairwise_append _ _ ([a] ++ l₁), pairwise_append_comm s]
+    simp only [mem_append, or_comm]
+#align list.pairwise_middle List.pairwise_middle
+
+-- Porting note: Duplicate of `pairwise_map` but with `f` explicit.
+@[deprecated] theorem pairwise_map' (f : β → α) :
+    ∀ {l : List β}, Pairwise R (map f l) ↔ Pairwise (fun a b : β => R (f a) (f b)) l
+  | [] => by simp only [map, Pairwise.nil]
+  | b :: l => by
+    simp only [map, pairwise_cons, mem_map', forall_exists_index, and_imp,
+      forall_apply_eq_imp_iff₂, pairwise_map]
+#align list.pairwise_map List.pairwise_map'
 
 theorem Pairwise.of_map {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, S (f a) (f b) → R a b)
     (p : Pairwise S (map f l)) : Pairwise R l :=
   (pairwise_map.1 p).imp (H _ _)
+#align list.pairwise.of_map List.Pairwise.of_map
 
 theorem Pairwise.map {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, R a b → S (f a) (f b))
     (p : Pairwise R l) : Pairwise S (map f l) :=
   pairwise_map.2 <| p.imp (H _ _)
+#align list.pairwise.map List.Pairwise.map
 
-theorem Pairwise.iff_of_mem {S : α → α → Prop} {l : List α}
-    (H : ∀ {a b}, a ∈ l → b ∈ l → (R a b ↔ S a b)) : Pairwise R l ↔ Pairwise S l :=
-  ⟨Pairwise.imp_of_mem fun {_ _} m m' ↦ (H m m').1,
-   Pairwise.imp_of_mem fun {_ _} m m' ↦ (H m m').2⟩
+theorem pairwise_filterMap (f : β → Option α) {l : List β} :
+    Pairwise R (filterMap f l) ↔ Pairwise (fun a a' : β => ∀ b ∈ f a, ∀ b' ∈ f a', R b b') l :=
+  by
+  let _S (a a' : β) := ∀ b ∈ f a, ∀ b' ∈ f a', R b b'
+  simp only [Option.mem_def]; induction' l with a l IH
+  · simp only [filterMap, Pairwise.nil]
+  cases' e : f a with b
+  · --Porting note: Why do I need `propext IH` here?
+    rw [filterMap_cons_none _ _ e, propext IH, pairwise_cons]
+    simp only [e, forall_prop_of_false not_false, forall₃_true_iff, true_and_iff]
+  rw [filterMap_cons_some _ _ _ e]
+  simp only [pairwise_cons, mem_filterMap, forall_exists_index, and_imp, IH, e, Option.some.injEq,
+    forall_eq', and_congr_left_iff]
+  intro _
+  exact ⟨fun h a ha b hab => h _ _ ha hab, fun h a b ha hab => h _ ha _ hab⟩
+#align list.pairwise_filter_map List.pairwise_filterMap
 
-theorem Pairwise.and_mem {l : List α} :
-    Pairwise R l ↔ Pairwise (fun x y ↦ x ∈ l ∧ y ∈ l ∧ R x y) l :=
-  Pairwise.iff_of_mem (by simp (config := { contextual := true }))
+theorem Pairwise.filter_map {S : β → β → Prop} (f : α → Option β)
+    (H : ∀ a a' : α, R a a' → ∀ b ∈ f a, ∀ b' ∈ f a', S b b') {l : List α} (p : Pairwise R l) :
+    Pairwise S (filterMap f l) :=
+  (pairwise_filterMap _).2 <| p.imp (H _ _)
+#align list.pairwise.filter_map List.Pairwise.filter_map
+
+theorem pairwise_filter (p : α → Prop) [DecidablePred p] {l : List α} :
+    Pairwise R (filter p l) ↔ Pairwise (fun x y => p x → p y → R x y) l := by
+  rw [← filterMap_eq_filter, pairwise_filterMap]
+  apply Pairwise.iff; intros
+  simp only [decide_eq_true_eq, Option.mem_def, Option.guard_eq_some, and_imp, forall_eq']
+#align list.pairwise_filter List.pairwise_filter
+
+theorem Pairwise.filter (p : α → Prop) [DecidablePred p] : Pairwise R l → Pairwise R (filter p l) :=
+  Pairwise.sublist (filter_sublist _)
+#align list.pairwise.filter List.Pairwise.filter
+
+theorem pairwise_pmap {p : β → Prop} {f : ∀ b, p b → α} {l : List β} (h : ∀ x ∈ l, p x) :
+    Pairwise R (l.pmap f h) ↔
+      Pairwise (fun b₁ b₂ => ∀ (h₁ : p b₁) (h₂ : p b₂), R (f b₁ h₁) (f b₂ h₂)) l :=
+  by
+  induction' l with a l ihl
+  · simp
+  obtain ⟨_, hl⟩ : p a ∧ ∀ b, b ∈ l → p b := by simpa using h
+  simp only [ihl hl, pairwise_cons, bex_imp, pmap, and_congr_left_iff, mem_pmap]
+  refine' fun _ => ⟨fun H b hb _ hpb => H _ _ hb rfl, _⟩
+  rintro H _ b hb rfl
+  exact H b hb _ _
+#align list.pairwise_pmap List.pairwise_pmap
+
+theorem Pairwise.pmap {l : List α} (hl : Pairwise R l) {p : α → Prop} {f : ∀ a, p a → β}
+    (h : ∀ x ∈ l, p x) {S : β → β → Prop}
+    (hS : ∀ ⦃x⦄ (hx : p x) ⦃y⦄ (hy : p y), R x y → S (f x hx) (f y hy)) :
+    Pairwise S (l.pmap f h) := by
+  refine' (pairwise_pmap h).2 (Pairwise.imp_of_mem _ hl)
+  intros ; apply hS; assumption
+#align list.pairwise.pmap List.Pairwise.pmap
+
+theorem pairwise_join {L : List (List α)} :
+    Pairwise R (join L) ↔
+      (∀ l ∈ L, Pairwise R l) ∧ Pairwise (fun l₁ l₂ => ∀ x ∈ l₁, ∀ y ∈ l₂, R x y) L :=
+  by
+  induction' L with l L IH
+  · simp only [join, Pairwise.nil, forall_prop_of_false (not_mem_nil _), forall_const, and_self_iff]
+  have :
+    (∀ x : α, x ∈ l → ∀ (y : α) (x_1 : List α), x_1 ∈ L → y ∈ x_1 → R x y) ↔
+      ∀ a' : List α, a' ∈ L → ∀ x : α, x ∈ l → ∀ y : α, y ∈ a' → R x y :=
+    ⟨fun h a b c d e => h c d e a b, fun h c d e a b => h a b c d e⟩
+  simp only [join, pairwise_append, IH, mem_join, exists_imp, and_imp, this, forall_mem_cons,
+    pairwise_cons]
+  simp only [and_assoc, and_comm, and_left_comm]
+#align list.pairwise_join List.pairwise_join
+
+theorem pairwise_bind {R : β → β → Prop} {l : List α} {f : α → List β} :
+    List.Pairwise R (l.bind f) ↔
+      (∀ a ∈ l, Pairwise R (f a)) ∧ Pairwise (fun a₁ a₂ => ∀ x ∈ f a₁, ∀ y ∈ f a₂, R x y) l :=
+  by simp [List.bind, List.pairwise_join, List.mem_map', List.pairwise_map]
+#align list.pairwise_bind List.pairwise_bind
+
+#align list.pairwise_reverse List.pairwise_reverse
+
+theorem pairwise_of_reflexive_on_dupl_of_forall_ne [DecidableEq α] {l : List α} {r : α → α → Prop}
+    (hr : ∀ a, 1 < count a l → r a a) (h : ∀ a ∈ l, ∀ b ∈ l, a ≠ b → r a b) : l.Pairwise r :=
+  by
+  induction' l with hd tl IH
+  · simp
+  · rw [List.pairwise_cons]
+    constructor
+    · intro x hx
+      by_cases H : hd = x
+      · rw [H]
+        refine' hr _ _
+        simpa [count_cons, H, Nat.succ_lt_succ_iff, count_pos] using hx
+      · exact h hd (mem_cons_self _ _) x (mem_cons_of_mem _ hx) H
+    · refine' IH _ _
+      · intro x hx
+        refine' hr _ _
+        rw [count_cons]
+        split_ifs
+        · exact hx.trans (Nat.lt_succ_self _)
+        · exact hx
+      · intro x hx y hy
+        exact h x (mem_cons_of_mem _ hx) y (mem_cons_of_mem _ hy)
+#align
+  list.pairwise_of_reflexive_on_dupl_of_forall_ne List.pairwise_of_reflexive_on_dupl_of_forall_ne
+
+theorem pairwise_of_forall_mem_list {l : List α} {r : α → α → Prop} (h : ∀ a ∈ l, ∀ b ∈ l, r a b) :
+    l.Pairwise r := by
+  classical
+    refine'
+      pairwise_of_reflexive_on_dupl_of_forall_ne (fun a ha' => _) fun a ha b hb _ => h a ha b hb
+    have ha := List.one_le_count_iff_mem.1 ha'.le
+    exact h a ha a ha
+#align list.pairwise_of_forall_mem_list List.pairwise_of_forall_mem_list
+
+theorem pairwise_of_reflexive_of_forall_ne {l : List α} {r : α → α → Prop} (hr : Reflexive r)
+    (h : ∀ a ∈ l, ∀ b ∈ l, a ≠ b → r a b) : l.Pairwise r := by
+  classical exact pairwise_of_reflexive_on_dupl_of_forall_ne (fun _ _ => hr _) h
+#align list.pairwise_of_reflexive_of_forall_ne List.pairwise_of_reflexive_of_forall_ne
+
+theorem pairwise_iff_get : ∀ {l : List α}, Pairwise R l ↔
+    ∀ (i j) (_hij : i < j), R (get l i) (get l j)
+  | [] => by
+    simp only [Pairwise.nil, true_iff_iff]; exact fun i j _h => (Nat.not_lt_zero j).elim j.2
+  | a :: l => by
+    rw [pairwise_cons, pairwise_iff_get]
+    refine'
+      ⟨fun H i j hij => _, fun H =>
+        ⟨fun a' m => _, fun i j hij => _⟩⟩
+    · cases' j with j hj
+      cases' j with j
+      · exact (Nat.not_lt_zero _).elim hij
+      cases' i with i hi
+      cases' i with i
+      · exact H.1 _ (get_mem l _ _)
+      · exact H.2 _ _ (Nat.lt_of_succ_lt_succ hij)
+    · rcases get_of_mem m with ⟨n, h, rfl⟩
+      have := H ⟨0, show 0 < (a::l).length from Nat.succ_pos _⟩ ⟨n.succ, Nat.succ_lt_succ n.2⟩
+        (Nat.succ_pos n)
+      simpa
+    . simpa using H i.succ j.succ (show i.1.succ < j.1.succ from Nat.succ_lt_succ hij)
+
+set_option linter.deprecated false in
+@[deprecated pairwise_iff_get]
+theorem pairwise_iff_nthLe {R} {l : List α} : Pairwise R l ↔
+    ∀ (i j) (h₁ : j < length l) (h₂ : i < j), R (nthLe l i (lt_trans h₂ h₁)) (nthLe l j h₁) :=
+  pairwise_iff_get.trans
+    ⟨fun h i j _ h₂ => h ⟨i, _⟩ ⟨j, _⟩ h₂,
+     fun h i j hij => h i j _ hij⟩
+#align list.pairwise_iff_nth_le List.pairwise_iff_nthLe
+
+theorem pairwise_replicate {α : Type _} {r : α → α → Prop} {x : α} (hx : r x x) :
+    ∀ n : ℕ, Pairwise r (List.replicate n x)
+  | 0 => by simp
+  | n + 1 => by simp only [replicate, add_eq, add_zero, pairwise_cons, mem_replicate, ne_eq,
+    and_imp, forall_eq_apply_imp_iff', hx, implies_true, pairwise_replicate hx n, and_self]
+
+set_option linter.deprecated false in
+@[deprecated pairwise_replicate]
+theorem pairwise_repeat {α : Type _} {r : α → α → Prop} {x : α} (hx : r x x) :
+    ∀ n : ℕ, Pairwise r (List.repeat x n) :=
+  List.pairwise_replicate hx
+#align list.pairwise_repeat List.pairwise_repeat
+
+/-! ### Pairwise filtering -/
+
+
+variable [DecidableRel R]
+
+@[simp]
+theorem pwFilter_nil : pwFilter R [] = [] :=
+  rfl
+#align list.pw_filter_nil List.pwFilter_nil
+
+@[simp]
+theorem pwFilter_cons_of_pos {a : α} {l : List α} (h : ∀ b ∈ pwFilter R l, R a b) :
+    pwFilter R (a :: l) = a :: pwFilter R l :=
+  if_pos h
+#align list.pw_filter_cons_of_pos List.pwFilter_cons_of_pos
+
+@[simp]
+theorem pwFilter_cons_of_neg {a : α} {l : List α} (h : ¬∀ b ∈ pwFilter R l, R a b) :
+    pwFilter R (a :: l) = pwFilter R l :=
+  if_neg h
+#align list.pw_filter_cons_of_neg List.pwFilter_cons_of_neg
+
+theorem pwFilter_map (f : β → α) :
+    ∀ l : List β, pwFilter R (map f l) = map f (pwFilter (fun x y => R (f x) (f y)) l)
+  | [] => rfl
+  | x :: xs =>
+    if h : ∀ b ∈ pwFilter R (map f xs), R (f x) b then
+      by
+      have h' : ∀ b : β, b ∈ pwFilter (fun x y : β => R (f x) (f y)) xs → R (f x) (f b) :=
+        fun b hb => h _ (by rw [pwFilter_map f xs]; apply mem_map_of_mem _ hb)
+      rw [map, pwFilter_cons_of_pos h, pwFilter_cons_of_pos h', pwFilter_map f xs, map]
+    else
+      by
+      have h' : ¬∀ b : β, b ∈ pwFilter (fun x y : β => R (f x) (f y)) xs → R (f x) (f b) :=
+        fun hh =>
+        h fun a ha => by
+          rw [pwFilter_map f xs, mem_map] at ha
+          rcases ha with ⟨b, hb₀, hb₁⟩
+          subst a
+          exact hh _ hb₀
+      rw [map, pwFilter_cons_of_neg h, pwFilter_cons_of_neg h', pwFilter_map f xs]
+#align list.pw_filter_map List.pwFilter_map
+
+theorem pwFilter_sublist : ∀ l : List α, pwFilter R l <+ l
+  | [] => nil_sublist _
+  | x :: l => by
+    by_cases ∀ y ∈ pwFilter R l, R x y
+    · rw [pwFilter_cons_of_pos h]
+      exact (pwFilter_sublist l).cons_cons _
+    · rw [pwFilter_cons_of_neg h]
+      exact sublist_cons_of_sublist _ (pwFilter_sublist l)
+#align list.pw_filter_sublist List.pwFilter_sublist
+
+theorem pwFilter_subset (l : List α) : pwFilter R l ⊆ l :=
+  (pwFilter_sublist _).subset
+#align list.pw_filter_subset List.pwFilter_subset
+
+theorem pairwise_pwFilter : ∀ l : List α, Pairwise R (pwFilter R l)
+  | [] => Pairwise.nil
+  | x :: l => by
+    by_cases ∀ y ∈ pwFilter R l, R x y
+    · rw [pwFilter_cons_of_pos h]
+      exact pairwise_cons.2 ⟨h, pairwise_pwFilter l⟩
+    · rw [pwFilter_cons_of_neg h]
+      exact pairwise_pwFilter l
+#align list.pairwise_pw_filter List.pairwise_pwFilter
+
+theorem pwFilter_eq_self {l : List α} : pwFilter R l = l ↔ Pairwise R l :=
+  ⟨fun e => e ▸ pairwise_pwFilter l, fun p =>
+    by
+    induction' l with x l IH; · rfl
+    cases' pairwise_cons.1 p with al p
+    rw [pwFilter_cons_of_pos (BAll.imp_left (pwFilter_subset l) al), IH p]⟩
+#align list.pw_filter_eq_self List.pwFilter_eq_self
+
+alias pwFilter_eq_self ↔ _ Pairwise.pwFilter
+
+-- Porting note: commented out
+-- attribute [protected] List.Pairwise.pwFilter
+
+@[simp]
+theorem pwFilter_idempotent : pwFilter R (pwFilter R l) = pwFilter R l :=
+  (pairwise_pwFilter l).pwFilter
+#align list.pw_filter_idempotent List.pwFilter_idempotent
+
+theorem forall_mem_pwFilter (neg_trans : ∀ {x y z}, R x z → R x y ∨ R y z) (a : α) (l : List α) :
+    (∀ b ∈ pwFilter R l, R a b) ↔ ∀ b ∈ l, R a b :=
+  ⟨by
+    induction' l with x l IH; · exact fun _ _ h => (not_mem_nil _ h).elim
+    simp only [forall_mem_cons]
+    by_cases ∀ y ∈ pwFilter R l, R x y <;> dsimp at h
+    · simp only [pwFilter_cons_of_pos h, forall_mem_cons, and_imp]
+      exact fun r H => ⟨r, IH H⟩
+    · rw [pwFilter_cons_of_neg h]
+      refine' fun H => ⟨_, IH H⟩
+      cases' e : find? (fun y => ¬R x y) (pwFilter R l) with k
+      · refine' h.elim (BAll.imp_right _ (find?_eq_none.1 e))
+        exact fun y _ => by simp
+      · have := find?_some e
+        exact (neg_trans (H k (find?_mem e))).resolve_right (by simpa),
+          BAll.imp_left (pwFilter_subset l)⟩
+#align list.forall_mem_pw_filter List.forall_mem_pwFilter
+
+end List

Dependencies 2 + 90

91 files ported (97.8%)
42439 lines ported (99.7%)
Show graph

The unported dependencies are