Documentation

Mathlib.Data.List.Pairwise

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

theorem List.pairwise_iff {α : Type u} (R : ααProp) (a✝ : List α) :
Pairwise R a✝ a✝ = [] (a : α), (l : List α), (∀ (a' : α), a' lR a a') Pairwise R l a✝ = a :: l

Pairwise #

theorem List.Pairwise.forall_of_forall {α : Type u_1} {R : ααProp} {l : List α} (H : Symmetric R) (H₁ : ∀ (x : α), x lR x x) (H₂ : Pairwise R l) x : α :
x l∀ ⦃y : α⦄, y lR x y
theorem List.Pairwise.forall {α : Type u_1} {R : ααProp} {l : List α} (hR : Symmetric R) (hl : Pairwise R l) a : α :
a l∀ ⦃b : α⦄, b la bR a b
theorem List.Pairwise.set_pairwise {α : Type u_1} {R : ααProp} {l : List α} (hl : Pairwise R l) (hr : Symmetric R) :
{x : α | x l}.Pairwise R
theorem List.pairwise_of_reflexive_of_forall_ne {α : Type u_1} {R : ααProp} {l : List α} (hr : Reflexive R) (h : ∀ (a : α), a l∀ (b : α), b la bR a b) :
theorem List.Pairwise.rel_head_tail {α : Type u_1} {R : ααProp} {l : List α} {a : α} (h₁ : Pairwise R l) (ha : a l.tail) :
R (l.head ) a
theorem List.Pairwise.rel_head_of_rel_head_head {α : Type u_1} {R : ααProp} {l : List α} {a : α} (h₁ : Pairwise R l) (ha : a l) (hhead : R (l.head ) (l.head )) :
R (l.head ) a
theorem List.Pairwise.rel_head {α : Type u_1} {R : ααProp} {l : List α} {a : α} [IsRefl α R] (h₁ : Pairwise R l) (ha : a l) :
R (l.head ) a
theorem List.Pairwise.rel_dropLast_getLast {α : Type u_1} {R : ααProp} {l : List α} {a : α} (h : Pairwise R l) (ha : a l.dropLast) :
R a (l.getLast )
theorem List.Pairwise.rel_getLast_of_rel_getLast_getLast {α : Type u_1} {R : ααProp} {l : List α} {a : α} (h₁ : Pairwise R l) (ha : a l) (hlast : R (l.getLast ) (l.getLast )) :
R a (l.getLast )
theorem List.Pairwise.rel_getLast {α : Type u_1} {R : ααProp} {l : List α} {a : α} [IsRefl α R] (h₁ : Pairwise R l) (ha : a l) :
R a (l.getLast )
theorem List.Pairwise.of_reverse {α : Type u_1} {R : ααProp} {l : List α} :
Pairwise R l.reversePairwise (fun (a b : α) => R b a) l

Alias of the forward direction of List.pairwise_reverse.

theorem List.Pairwise.reverse {α : Type u_1} {R : ααProp} {l : List α} :
Pairwise (fun (a b : α) => R b a) lPairwise R l.reverse

Alias of the reverse direction of List.pairwise_reverse.

theorem List.Pairwise.head!_le {α : Type u_1} {R : ααProp} {l : List α} {a : α} [Inhabited α] [IsRefl α R] (h : Pairwise R l) (ha : a l) :
R l.head! a
@[deprecated List.Pairwise.head!_le (since := "2025-10-11")]
theorem List.Sorted.head!_le {α : Type u_1} {R : ααProp} {l : List α} {a : α} [Inhabited α] [IsRefl α R] (h : Pairwise R l) (ha : a l) :
R l.head! a

Alias of List.Pairwise.head!_le.

@[deprecated List.Pairwise.head!_le (since := "2025-10-11")]
theorem List.Sorted.le_head! {α : Type u_1} {R : ααProp} {l : List α} {a : α} [Inhabited α] [IsRefl α R] (h : Pairwise R l) (ha : a l) :
R l.head! a

Alias of List.Pairwise.head!_le.

theorem List.pairwise_replicate_of_refl {α : Type u_1} {R : ααProp} {a : α} {n : } [IsRefl α R] :
@[deprecated List.pairwise_replicate_of_refl (since := "2025-10-11")]
theorem List.sorted_replicate {α : Type u_1} {R : ααProp} {a : α} {n : } [IsRefl α R] :

Alias of List.pairwise_replicate_of_refl.

Pairwise filtering #

theorem List.Pairwise.pwFilter {α : Type u_1} {R : ααProp} [DecidableRel R] {l : List α} :
Pairwise R lpwFilter R l = l

Alias of the reverse direction of List.pwFilter_eq_self.

theorem List.pairwise_cons_cons_iff_of_trans {α : Type u_1} {R : ααProp} [IsTrans α R] {l : List α} {a b : α} :
Pairwise R (a :: b :: l) R a b Pairwise R (b :: l)
@[deprecated List.pairwise_cons_cons_iff_of_trans (since := "2025-10-11")]
theorem List.sorted_cons_cons {α : Type u_1} {R : ααProp} [IsTrans α R] {l : List α} {a b : α} :
Pairwise R (a :: b :: l) R a b Pairwise R (b :: l)

Alias of List.pairwise_cons_cons_iff_of_trans.

theorem List.Pairwise.cons_cons_of_trans {α : Type u_1} {R : ααProp} [IsTrans α R] {l : List α} {a b : α} :
R a bPairwise R (b :: l)Pairwise R (a :: b :: l)
@[deprecated List.Pairwise.cons_cons_of_trans (since := "2025-10-11")]
theorem List.Sorted.cons {α : Type u_1} {R : ααProp} [IsTrans α R] {l : List α} {a b : α} :
R a bPairwise R (b :: l)Pairwise R (a :: b :: l)

Alias of List.Pairwise.cons_cons_of_trans.

theorem List.Pairwise.rel_get_of_lt {α : Type u_1} {R : ααProp} {l : List α} (h : Pairwise R l) {a b : Fin l.length} (hab : a < b) :
R (l.get a) (l.get b)
@[deprecated List.Pairwise.rel_get_of_lt (since := "2025-10-11")]
theorem List.Sorted.rel_get_of_lt {α : Type u_1} {R : ααProp} {l : List α} (h : Pairwise R l) {a b : Fin l.length} (hab : a < b) :
R (l.get a) (l.get b)

Alias of List.Pairwise.rel_get_of_lt.

theorem List.Pairwise.rel_get_of_le {α : Type u_1} {R : ααProp} [IsRefl α R] {l : List α} (h : Pairwise R l) {a b : Fin l.length} (hab : a b) :
R (l.get a) (l.get b)
@[deprecated List.Pairwise.rel_get_of_le (since := "2025-10-11")]
theorem List.Sorted.rel_get_of_le {α : Type u_1} {R : ααProp} [IsRefl α R] {l : List α} (h : Pairwise R l) {a b : Fin l.length} (hab : a b) :
R (l.get a) (l.get b)

Alias of List.Pairwise.rel_get_of_le.

theorem List.Pairwise.decide {α : Type u_1} {R : ααProp} [DecidableRel R] (l : List α) (h : Pairwise R l) :
Pairwise (fun (a b : α) => Decidable.decide (R a b) = true) l
@[deprecated List.Pairwise.decide (since := "2025-10-11")]
theorem List.Sorted.decide {α : Type u_1} {R : ααProp} [DecidableRel R] (l : List α) (h : Pairwise R l) :
Pairwise (fun (a b : α) => Decidable.decide (R a b) = true) l

Alias of List.Pairwise.decide.