Documentation

CslibFrontier.Foundations.Data.List.Forall2

Composing and splitting aligned lists #

Two lists aligned by List.Forall₂ R can be cut at matching positions: a cut of one side, as an append or around a middle element, gives a cut of the other side with the same lengths, and the parts stay aligned. Proofs that keep several lists aligned with one another, such as the chains, hole triples and runs of a search, split them all around the element that changes.

Main results #

theorem List.Forall₂.trans {α : Type u_1} {β : Type u_2} {R : α → β → Prop} {γ : Type u_3} {S : β → γ → Prop} {T : α → γ → Prop} [Trans R S T] {a : List α} {b : List β} {c : List γ} (hab : Forall₂ R a b) (hbc : Forall₂ S b c) :
Forall₂ T a c

Composing alignments pointwise composes their element relations.

theorem List.Forall₂.split_right {α : Type u_1} {β : Type u_2} {R : α → β → Prop} {l : List α} {pre post : List β} (h : Forall₂ R l (pre ++ post)) :
∃ (a : List α) (b : List α), l = a ++ b ∧ a.length = pre.length ∧ Forall₂ R a pre ∧ Forall₂ R b post

An alignment with an append on the right is an append of alignments.

theorem List.Forall₂.split_right_cons {α : Type u_1} {β : Type u_2} {R : α → β → Prop} {l : List α} {pre post : List β} {x : β} (h : Forall₂ R l (pre ++ x :: post)) :
∃ (a : List α) (y : α) (b : List α), l = a ++ y :: b ∧ a.length = pre.length ∧ Forall₂ R a pre ∧ R y x ∧ Forall₂ R b post

An alignment with a middle element on the right has an aligned middle element on the left.

theorem List.Forall₂.split_left_cons {α : Type u_1} {β : Type u_2} {R : α → β → Prop} {pre post : List α} {x : α} {l : List β} (h : Forall₂ R (pre ++ x :: post) l) :
∃ (a : List β) (y : β) (b : List β), l = a ++ y :: b ∧ a.length = pre.length ∧ Forall₂ R pre a ∧ R x y ∧ Forall₂ R post b

An alignment with a middle element on the left has an aligned middle element on the right.

theorem List.Forall₂.exists_mem_of_mem {α : Type u_1} {β : Type u_2} {R : α → β → Prop} {a : List α} {b : List β} (h : Forall₂ R a b) {x : α} (hx : x ∈ a) :
∃ y ∈ b, R x y

Every element of the left list has an aligned element in the right list.

theorem List.Forall₂.split_of_length_eq {α : Type u_1} {β : Type u_2} {R : α → β → Prop} {a a' : List α} {b b' : List β} (hlen : a.length = b.length) (h : Forall₂ R (a ++ a') (b ++ b')) :
Forall₂ R a b ∧ Forall₂ R a' b'

Two aligned appends whose first parts have equal lengths are aligned part by part.