Documentation

Mathlib.Data.Fin.Tuple.Basic

Operation on tuples #

We interpret maps ∀ i : Fin n, α i as n-tuples of elements of possibly varying type α i, (α 0, …, α (n-1)). A particular case is Fin n → α of elements with all the same type. In this case when α i is a constant map, then tuples are isomorphic (but not definitionally equal) to Vectors.

Main declarations #

There are three (main) ways to consider Fin n as a subtype of Fin (n + 1), hence three (main) ways to move between tuples of length n and of length n + 1 by adding/removing an entry.

Adding at the start #

Adding at the end #

Adding in the middle #

For a pivot p : Fin (n + 1),

p = 0 means we add at the start. p = last n means we add at the end.

Miscellaneous #

theorem Fin.tuple0_le {α : Fin 0Type u_1} [(i : Fin 0) → Preorder (α i)] (f g : (i : Fin 0) → α i) :
f g
def Fin.tail {n : } {α : Fin (n + 1)Sort u} (q : (i : Fin (n + 1)) → α i) (i : Fin n) :
α i.succ

The tail of an n+1 tuple, i.e., its last n entries.

Equations
theorem Fin.tail_def {n : } {α : Fin (n + 1)Sort u_1} {q : (i : Fin (n + 1)) → α i} :
(tail fun (k : Fin (n + 1)) => q k) = fun (k : Fin n) => q k.succ
def Fin.cons {n : } {α : Fin (n + 1)Sort u} (x : α 0) (p : (i : Fin n) → α i.succ) (i : Fin (n + 1)) :
α i

Adding an element at the beginning of an n-tuple, to get an n+1-tuple.

Equations
@[simp]
theorem Fin.tail_cons {n : } {α : Fin (n + 1)Sort u} (x : α 0) (p : (i : Fin n) → α i.succ) :
tail (cons x p) = p
@[simp]
theorem Fin.cons_succ {n : } {α : Fin (n + 1)Sort u} (x : α 0) (p : (i : Fin n) → α i.succ) (i : Fin n) :
cons x p i.succ = p i
@[simp]
theorem Fin.cons_zero {n : } {α : Fin (n + 1)Sort u} (x : α 0) (p : (i : Fin n) → α i.succ) :
cons x p 0 = x
@[simp]
theorem Fin.cons_one {n : } {α : Fin (n + 2)Sort u_1} (x : α 0) (p : (i : Fin n.succ) → α i.succ) :
cons x p 1 = p 0
@[simp]
theorem Fin.cons_update {n : } {α : Fin (n + 1)Sort u} (x : α 0) (p : (i : Fin n) → α i.succ) (i : Fin n) (y : α i.succ) :

Updating a tuple and adding an element at the beginning commute.

theorem Fin.cons_injective2 {n : } {α : Fin (n + 1)Sort u} :

As a binary function, Fin.cons is injective.

@[simp]
theorem Fin.cons_inj {n : } {α : Fin (n + 1)Sort u} {x₀ y₀ : α 0} {x y : (i : Fin n) → α i.succ} :
cons x₀ x = cons y₀ y x₀ = y₀ x = y
theorem Fin.cons_left_injective {n : } {α : Fin (n + 1)Sort u} (x : (i : Fin n) → α i.succ) :
Function.Injective fun (x₀ : α 0) => cons x₀ x
theorem Fin.cons_right_injective {n : } {α : Fin (n + 1)Sort u} (x₀ : α 0) :
theorem Fin.update_cons_zero {n : } {α : Fin (n + 1)Sort u} (x : α 0) (p : (i : Fin n) → α i.succ) (z : α 0) :
Function.update (cons x p) 0 z = cons z p

Adding an element at the beginning of a tuple and then updating it amounts to adding it directly.

@[simp]
theorem Fin.cons_self_tail {n : } {α : Fin (n + 1)Sort u} (q : (i : Fin (n + 1)) → α i) :
cons (q 0) (tail q) = q

Concatenating the first element of a tuple with its tail gives back the original tuple

def Fin.consEquiv {n : } (α : Fin (n + 1)Type u_1) :
α 0 × ((i : Fin n) → α i.succ) ((i : Fin (n + 1)) → α i)

Equivalence between tuples of length n + 1 and pairs of an element and a tuple of length n given by separating out the first element of the tuple.

This is Fin.cons as an Equiv.

Equations
@[simp]
theorem Fin.consEquiv_symm_apply {n : } (α : Fin (n + 1)Type u_1) (f : (i : Fin (n + 1)) → α i) :
(consEquiv α).symm f = (f 0, tail f)
@[simp]
theorem Fin.consEquiv_apply {n : } (α : Fin (n + 1)Type u_1) (f : α 0 × ((i : Fin n) → α i.succ)) (i : Fin (n + 1)) :
(consEquiv α) f i = cons f.1 f.2 i
def Fin.consCases {n : } {α : Fin (n + 1)Sort u} {P : ((i : Fin n.succ) → α i)Sort v} (h : (x₀ : α 0) → (x : (i : Fin n) → α i.succ) → P (cons x₀ x)) (x : (i : Fin n.succ) → α i) :
P x

Recurse on an n+1-tuple by splitting it into a single element and an n-tuple.

Equations
@[simp]
theorem Fin.consCases_cons {n : } {α : Fin (n + 1)Sort u} {P : ((i : Fin n.succ) → α i)Sort v} (h : (x₀ : α 0) → (x : (i : Fin n) → α i.succ) → P (cons x₀ x)) (x₀ : α 0) (x : (i : Fin n) → α i.succ) :
consCases h (cons x₀ x) = h x₀ x
def Fin.consInduction {α : Sort u_1} {P : {n : } → (Fin nα)Sort v} (h0 : P elim0) (h : {n : } → (x₀ : α) → (x : Fin nα) → P xP (cons x₀ x)) {n : } (x : Fin nα) :
P x

Recurse on a tuple by splitting into Fin.elim0 and Fin.cons.

Equations
theorem Fin.cons_injective_of_injective {n : } {α : Type u_1} {x₀ : α} {x : Fin nα} (hx₀ : x₀Set.range x) (hx : Function.Injective x) :
theorem Fin.cons_injective_iff {n : } {α : Type u_1} {x₀ : α} {x : Fin nα} :
@[simp]
theorem Fin.forall_fin_zero_pi {α : Fin 0Sort u_1} {P : ((i : Fin 0) → α i)Prop} :
(∀ (x : (i : Fin 0) → α i), P x) P finZeroElim
@[simp]
theorem Fin.exists_fin_zero_pi {α : Fin 0Sort u_1} {P : ((i : Fin 0) → α i)Prop} :
(∃ (x : (i : Fin 0) → α i), P x) P finZeroElim
theorem Fin.forall_fin_succ_pi {n : } {α : Fin (n + 1)Sort u} {P : ((i : Fin (n + 1)) → α i)Prop} :
(∀ (x : (i : Fin (n + 1)) → α i), P x) ∀ (a : α 0) (v : (i : Fin n) → α i.succ), P (cons a v)
theorem Fin.exists_fin_succ_pi {n : } {α : Fin (n + 1)Sort u} {P : ((i : Fin (n + 1)) → α i)Prop} :
(∃ (x : (i : Fin (n + 1)) → α i), P x) ∃ (a : α 0) (v : (i : Fin n) → α i.succ), P (cons a v)
@[simp]
theorem Fin.tail_update_zero {n : } {α : Fin (n + 1)Sort u} (q : (i : Fin (n + 1)) → α i) (z : α 0) :

Updating the first element of a tuple does not change the tail.

@[simp]
theorem Fin.tail_update_succ {n : } {α : Fin (n + 1)Sort u} (q : (i : Fin (n + 1)) → α i) (i : Fin n) (y : α i.succ) :

Updating a nonzero element and taking the tail commute.

theorem Fin.comp_cons {n : } {α : Sort u_1} {β : Sort u_2} (g : αβ) (y : α) (q : Fin nα) :
g cons y q = cons (g y) (g q)
theorem Fin.comp_tail {n : } {α : Sort u_1} {β : Sort u_2} (g : αβ) (q : Fin n.succα) :
g tail q = tail (g q)
theorem Fin.le_cons {n : } {α : Fin (n + 1)Type u_1} [(i : Fin (n + 1)) → Preorder (α i)] {x : α 0} {q : (i : Fin (n + 1)) → α i} {p : (i : Fin n) → α i.succ} :
q cons x p q 0 x tail q p
theorem Fin.cons_le {n : } {α : Fin (n + 1)Type u_1} [(i : Fin (n + 1)) → Preorder (α i)] {x : α 0} {q : (i : Fin (n + 1)) → α i} {p : (i : Fin n) → α i.succ} :
cons x p q x q 0 p tail q
theorem Fin.cons_le_cons {n : } {α : Fin (n + 1)Type u_1} [(i : Fin (n + 1)) → Preorder (α i)] {x₀ y₀ : α 0} {x y : (i : Fin n) → α i.succ} :
cons x₀ x cons y₀ y x₀ y₀ x y
theorem Fin.range_fin_succ {n : } {α : Type u_1} (f : Fin (n + 1)α) :
@[simp]
theorem Fin.range_cons {α : Type u_1} {n : } (x : α) (b : Fin nα) :
def Fin.append {m n : } {α : Sort u_1} (a : Fin mα) (b : Fin nα) :
Fin (m + n)α

Append a tuple of length m to a tuple of length n to get a tuple of length m + n. This is a non-dependent version of Fin.add_cases.

Equations
@[simp]
theorem Fin.append_left {m n : } {α : Sort u_1} (u : Fin mα) (v : Fin nα) (i : Fin m) :
append u v (castAdd n i) = u i
@[simp]
theorem Fin.append_right {m n : } {α : Sort u_1} (u : Fin mα) (v : Fin nα) (i : Fin n) :
append u v (natAdd m i) = v i
theorem Fin.append_right_nil {m n : } {α : Sort u_1} (u : Fin mα) (v : Fin nα) (hv : n = 0) :
append u v = u Fin.cast
@[simp]
theorem Fin.append_elim0 {m : } {α : Sort u_1} (u : Fin mα) :
theorem Fin.append_left_nil {m n : } {α : Sort u_1} (u : Fin mα) (v : Fin nα) (hu : m = 0) :
append u v = v Fin.cast
@[simp]
theorem Fin.elim0_append {n : } {α : Sort u_1} (v : Fin nα) :
theorem Fin.append_assoc {m n : } {α : Sort u_1} {p : } (a : Fin mα) (b : Fin nα) (c : Fin pα) :
append (append a b) c = append a (append b c) Fin.cast
theorem Fin.append_left_eq_cons {α : Sort u_1} {n : } (x₀ : Fin 1α) (x : Fin nα) :
append x₀ x = cons (x₀ 0) x Fin.cast

Appending a one-tuple to the left is the same as Fin.cons.

theorem Fin.cons_eq_append {n : } {α : Sort u_1} (x : α) (xs : Fin nα) :
cons x xs = append (cons x elim0) xs Fin.cast

Fin.cons is the same as appending a one-tuple to the left.

@[simp]
theorem Fin.append_cast_left {α : Sort u_1} {n m : } (xs : Fin nα) (ys : Fin mα) (n' : ) (h : n' = n) :
append (xs Fin.cast h) ys = append xs ys Fin.cast
@[simp]
theorem Fin.append_cast_right {α : Sort u_1} {n m : } (xs : Fin nα) (ys : Fin mα) (m' : ) (h : m' = m) :
append xs (ys Fin.cast h) = append xs ys Fin.cast
theorem Fin.append_rev {α : Sort u_1} {m n : } (xs : Fin mα) (ys : Fin nα) (i : Fin (m + n)) :
append xs ys i.rev = append (ys rev) (xs rev) (Fin.cast i)
theorem Fin.append_comp_rev {α : Sort u_1} {m n : } (xs : Fin mα) (ys : Fin nα) :
append xs ys rev = append (ys rev) (xs rev) Fin.cast
theorem Fin.append_castAdd_natAdd {m n : } {α : Sort u_1} {f : Fin (m + n)α} :
(append (fun (i : Fin m) => f (castAdd n i)) fun (i : Fin n) => f (natAdd m i)) = f
def Fin.repeat {n : } {α : Sort u_1} (m : ) (a : Fin nα) :
Fin (m * n)α

Repeat a m times. For example Fin.repeat 2 ![0, 3, 7] = ![0, 3, 7, 0, 3, 7].

Equations
@[simp]
theorem Fin.repeat_apply {m n : } {α : Sort u_1} (a : Fin nα) (i : Fin (m * n)) :
«repeat» m a i = a i.modNat
@[simp]
theorem Fin.repeat_zero {n : } {α : Sort u_1} (a : Fin nα) :
@[simp]
theorem Fin.repeat_one {n : } {α : Sort u_1} (a : Fin nα) :
theorem Fin.repeat_succ {n : } {α : Sort u_1} (a : Fin nα) (m : ) :
@[simp]
theorem Fin.repeat_add {n : } {α : Sort u_1} (a : Fin nα) (m₁ m₂ : ) :
«repeat» (m₁ + m₂) a = append («repeat» m₁ a) («repeat» m₂ a) Fin.cast
theorem Fin.repeat_rev {m n : } {α : Sort u_1} (a : Fin nα) (k : Fin (m * n)) :
theorem Fin.repeat_comp_rev {m n : } {α : Sort u_1} (a : Fin nα) :

In the previous section, we have discussed inserting or removing elements on the left of a tuple. In this section, we do the same on the right. A difference is that Fin (n+1) is constructed inductively from Fin n starting from the left, not from the right. This implies that Lean needs more help to realize that elements belong to the right types, i.e., we need to insert casts at several places.

def Fin.init {n : } {α : Fin (n + 1)Sort u_1} (q : (i : Fin (n + 1)) → α i) (i : Fin n) :

The beginning of an n+1 tuple, i.e., its first n entries

Equations
theorem Fin.init_def {n : } {α : Fin (n + 1)Sort u_1} {q : (i : Fin (n + 1)) → α i} :
(init fun (k : Fin (n + 1)) => q k) = fun (k : Fin n) => q k.castSucc
def Fin.snoc {n : } {α : Fin (n + 1)Sort u_1} (p : (i : Fin n) → α i.castSucc) (x : α (last n)) (i : Fin (n + 1)) :
α i

Adding an element at the end of an n-tuple, to get an n+1-tuple. The name snoc comes from cons (i.e., adding an element to the left of a tuple) read in reverse order.

Equations
@[simp]
theorem Fin.init_snoc {n : } {α : Fin (n + 1)Sort u_1} (x : α (last n)) (p : (i : Fin n) → α i.castSucc) :
init (snoc p x) = p
@[simp]
theorem Fin.snoc_castSucc {n : } {α : Fin (n + 1)Sort u_1} (x : α (last n)) (p : (i : Fin n) → α i.castSucc) (i : Fin n) :
snoc p x i.castSucc = p i
@[simp]
theorem Fin.snoc_comp_castSucc {n : } {α : Sort u_2} {a : α} {f : Fin nα} :
@[simp]
theorem Fin.snoc_last {n : } {α : Fin (n + 1)Sort u_1} (x : α (last n)) (p : (i : Fin n) → α i.castSucc) :
snoc p x (last n) = x
theorem Fin.snoc_zero {α : Sort u_2} (p : Fin 0α) (x : α) :
snoc p x = fun (x_1 : Fin (0 + 1)) => x
@[simp]
theorem Fin.snoc_comp_nat_add {n m : } {α : Sort u_2} (f : Fin (m + n)α) (a : α) :
snoc f a natAdd m = snoc (f natAdd m) a
@[simp]
theorem Fin.snoc_cast_add {m n : } {α : Fin (n + m + 1)Sort u_2} (f : (i : Fin (n + m)) → α i.castSucc) (a : α (last (n + m))) (i : Fin n) :
snoc f a (castAdd (m + 1) i) = f (castAdd m i)
@[simp]
theorem Fin.snoc_comp_cast_add {n m : } {α : Sort u_2} (f : Fin (n + m)α) (a : α) :
snoc f a castAdd (m + 1) = f castAdd m
@[simp]
theorem Fin.snoc_update {n : } {α : Fin (n + 1)Sort u_1} (x : α (last n)) (p : (i : Fin n) → α i.castSucc) (i : Fin n) (y : α i.castSucc) :

Updating a tuple and adding an element at the end commute.

theorem Fin.update_snoc_last {n : } {α : Fin (n + 1)Sort u_1} (x : α (last n)) (p : (i : Fin n) → α i.castSucc) (z : α (last n)) :
Function.update (snoc p x) (last n) z = snoc p z

Adding an element at the beginning of a tuple and then updating it amounts to adding it directly.

theorem Fin.snoc_injective2 {n : } {α : Fin (n + 1)Sort u_1} :

As a binary function, Fin.snoc is injective.

@[simp]
theorem Fin.snoc_inj {n : } {α : Fin (n + 1)Sort u_1} {x y : (i : Fin n) → α i.castSucc} {xₙ yₙ : α (last n)} :
snoc x xₙ = snoc y yₙ x = y xₙ = yₙ
theorem Fin.snoc_right_injective {n : } {α : Fin (n + 1)Sort u_1} (x : (i : Fin n) → α i.castSucc) :
theorem Fin.snoc_left_injective {n : } {α : Fin (n + 1)Sort u_1} (xₙ : α (last n)) :
Function.Injective fun (x : (i : Fin n) → α i.castSucc) => snoc x xₙ
@[simp]
theorem Fin.snoc_init_self {n : } {α : Fin (n + 1)Sort u_1} (q : (i : Fin (n + 1)) → α i) :
snoc (init q) (q (last n)) = q

Concatenating the first element of a tuple with its tail gives back the original tuple

@[simp]
theorem Fin.init_update_last {n : } {α : Fin (n + 1)Sort u_1} (q : (i : Fin (n + 1)) → α i) (z : α (last n)) :

Updating the last element of a tuple does not change the beginning.

@[simp]
theorem Fin.init_update_castSucc {n : } {α : Fin (n + 1)Sort u_1} (q : (i : Fin (n + 1)) → α i) (i : Fin n) (y : α i.castSucc) :

Updating an element and taking the beginning commute.

theorem Fin.tail_init_eq_init_tail {n : } {β : Sort u_2} (q : Fin (n + 2)β) :
tail (init q) = init (tail q)

tail and init commute. We state this lemma in a non-dependent setting, as otherwise it would involve a cast to convince Lean that the two types are equal, making it harder to use.

theorem Fin.cons_snoc_eq_snoc_cons {n : } {β : Sort u_2} (a : β) (q : Fin nβ) (b : β) :
cons a (snoc q b) = snoc (cons a q) b

cons and snoc commute. We state this lemma in a non-dependent setting, as otherwise it would involve a cast to convince Lean that the two types are equal, making it harder to use.

theorem Fin.comp_snoc {n : } {α : Sort u_2} {β : Sort u_3} (g : αβ) (q : Fin nα) (y : α) :
g snoc q y = snoc (g q) (g y)
theorem Fin.append_right_eq_snoc {α : Sort u_2} {n : } (x : Fin nα) (x₀ : Fin 1α) :
append x x₀ = snoc x (x₀ 0)

Appending a one-tuple to the right is the same as Fin.snoc.

theorem Fin.snoc_eq_append {n : } {α : Sort u_2} (xs : Fin nα) (x : α) :
snoc xs x = append xs (cons x elim0)

Fin.snoc is the same as appending a one-tuple

theorem Fin.append_left_snoc {n m : } {α : Sort u_2} (xs : Fin nα) (x : α) (ys : Fin mα) :
append (snoc xs x) ys = append xs (cons x ys) Fin.cast
theorem Fin.append_right_cons {n m : } {α : Sort u_2} (xs : Fin nα) (y : α) (ys : Fin mα) :
append xs (cons y ys) = append (snoc xs y) ys Fin.cast
theorem Fin.append_cons {m n : } {α : Sort u_2} (a : α) (as : Fin nα) (bs : Fin mα) :
append (cons a as) bs = cons a (append as bs) Fin.cast
theorem Fin.append_snoc {m n : } {α : Sort u_2} (as : Fin nα) (bs : Fin mα) (b : α) :
append as (snoc bs b) = snoc (append as bs) b
theorem Fin.comp_init {n : } {α : Sort u_2} {β : Sort u_3} (g : αβ) (q : Fin n.succα) :
g init q = init (g q)
def Fin.snocEquiv {n : } (α : Fin (n + 1)Type u_2) :
α (last n) × ((i : Fin n) → α i.castSucc) ((i : Fin (n + 1)) → α i)

Equivalence between tuples of length n + 1 and pairs of an element and a tuple of length n given by separating out the last element of the tuple.

This is Fin.snoc as an Equiv.

Equations
  • One or more equations did not get rendered due to their size.
@[simp]
theorem Fin.snocEquiv_apply {n : } (α : Fin (n + 1)Type u_2) (f : α (last n) × ((i : Fin n) → α i.castSucc)) (x✝ : Fin (n + 1)) :
(snocEquiv α) f x✝ = snoc f.2 f.1 x✝
@[simp]
theorem Fin.snocEquiv_symm_apply {n : } (α : Fin (n + 1)Type u_2) (f : (i : Fin (n + 1)) → α i) :
(snocEquiv α).symm f = (f (last n), init f)
@[inline]
def Fin.snocCases {n : } {α : Fin (n + 1)Sort u_1} {P : ((i : Fin n.succ) → α i)Sort u_2} (h : (xs : (i : Fin n) → α i.castSucc) → (x : α (last n)) → P (snoc xs x)) (x : (i : Fin n.succ) → α i) :
P x

Recurse on an n+1-tuple by splitting it its initial n-tuple and its last element.

Equations
@[simp]
theorem Fin.snocCases_snoc {n : } {α : Fin (n + 1)Sort u_1} {P : ((i : Fin (n + 1)) → α i)Sort u_2} (h : (x : (i : Fin n) → α i.castSucc) → (x₀ : α (last n)) → P (snoc x x₀)) (x : (i : Fin n) → init α i) (x₀ : α (last n)) :
snocCases h (snoc x x₀) = h x x₀
def Fin.snocInduction {α : Sort u_2} {P : {n : } → (Fin nα)Sort u_3} (h0 : P elim0) (h : {n : } → (x : Fin nα) → (x₀ : α) → P xP (snoc x x₀)) {n : } (x : Fin nα) :
P x

Recurse on a tuple by splitting into Fin.elim0 and Fin.snoc.

Equations
def Fin.succAboveCases {n : } {α : Fin (n + 1)Sort u} (i : Fin (n + 1)) (x : α i) (p : (j : Fin n) → α (i.succAbove j)) (j : Fin (n + 1)) :
α j

Define a function on Fin (n + 1) from a value on i : Fin (n + 1) and values on each Fin.succAbove i j, j : Fin n. This version is elaborated as eliminator and works for propositions, see also Fin.insertNth for a version without an @[elab_as_elim] attribute.

Equations
theorem Fin.forall_iff_succ {n : } {P : Fin (n + 1)Prop} :
(∀ (i : Fin (n + 1)), P i) P 0 ∀ (i : Fin n), P i.succ

Alias of Fin.forall_fin_succ.

theorem Fin.exists_iff_succ {n : } {P : Fin (n + 1)Prop} :
(∃ (i : Fin (n + 1)), P i) P 0 ∃ (i : Fin n), P i.succ

Alias of Fin.exists_fin_succ.

theorem Fin.forall_iff_castSucc {n : } {P : Fin (n + 1)Prop} :
(∀ (i : Fin (n + 1)), P i) P (last n) ∀ (i : Fin n), P i.castSucc
theorem Fin.exists_iff_castSucc {n : } {P : Fin (n + 1)Prop} :
(∃ (i : Fin (n + 1)), P i) P (last n) ∃ (i : Fin n), P i.castSucc
theorem Fin.forall_iff_succAbove {n : } {P : Fin (n + 1)Prop} (p : Fin (n + 1)) :
(∀ (i : Fin (n + 1)), P i) P p ∀ (i : Fin n), P (p.succAbove i)
theorem Fin.exists_iff_succAbove {n : } {P : Fin (n + 1)Prop} (p : Fin (n + 1)) :
(∃ (i : Fin (n + 1)), P i) P p ∃ (i : Fin n), P (p.succAbove i)
theorem Fin.eq_self_or_eq_succAbove {n : } (p i : Fin (n + 1)) :
i = p ∃ (j : Fin n), i = p.succAbove j

Analogue of Fin.eq_zero_or_eq_succ for succAbove.

def Fin.removeNth {n : } {α : Fin (n + 1)Sort u_1} (p : Fin (n + 1)) (f : (i : Fin (n + 1)) → α i) (i : Fin n) :
α (p.succAbove i)

Remove the p-th entry of a tuple.

Equations
def Fin.insertNth {n : } {α : Fin (n + 1)Sort u_1} (i : Fin (n + 1)) (x : α i) (p : (j : Fin n) → α (i.succAbove j)) (j : Fin (n + 1)) :
α j

Insert an element into a tuple at a given position. For i = 0 see Fin.cons, for i = Fin.last n see Fin.snoc. See also Fin.succAboveCases for a version elaborated as an eliminator.

Equations
@[simp]
theorem Fin.insertNth_apply_same {n : } {α : Fin (n + 1)Sort u_1} (i : Fin (n + 1)) (x : α i) (p : (j : Fin n) → α (i.succAbove j)) :
i.insertNth x p i = x
@[simp]
theorem Fin.insertNth_apply_succAbove {n : } {α : Fin (n + 1)Sort u_1} (i : Fin (n + 1)) (x : α i) (p : (j : Fin n) → α (i.succAbove j)) (j : Fin n) :
i.insertNth x p (i.succAbove j) = p j
@[simp]
theorem Fin.removeNth_insertNth {n : } {α : Fin (n + 1)Sort u_1} (p : Fin (n + 1)) (a : α p) (f : (i : Fin n) → α (p.succAbove i)) :
p.removeNth (p.insertNth a f) = f
@[simp]
theorem Fin.removeNth_zero {n : } {α : Fin (n + 1)Sort u_1} (f : (i : Fin (n + 1)) → α i) :
@[simp]
theorem Fin.removeNth_last {n : } {α : Type u_3} (f : Fin (n + 1)α) :
@[simp]
theorem Fin.insertNth_comp_succAbove {n : } {β : Sort u_2} (i : Fin (n + 1)) (x : β) (p : Fin nβ) :
theorem Fin.insertNth_eq_iff {n : } {α : Fin (n + 1)Sort u_1} {p : Fin (n + 1)} {a : α p} {f : (i : Fin n) → α (p.succAbove i)} {g : (j : Fin (n + 1)) → α j} :
p.insertNth a f = g a = g p f = p.removeNth g
theorem Fin.eq_insertNth_iff {n : } {α : Fin (n + 1)Sort u_1} {p : Fin (n + 1)} {a : α p} {f : (i : Fin n) → α (p.succAbove i)} {g : (j : Fin (n + 1)) → α j} :
g = p.insertNth a f g p = a p.removeNth g = f
theorem Fin.insertNth_injective2 {n : } {α : Fin (n + 1)Sort u_1} {p : Fin (n + 1)} :

As a binary function, Fin.insertNth is injective.

@[simp]
theorem Fin.insertNth_inj {n : } {α : Fin (n + 1)Sort u_1} {p : Fin (n + 1)} {x y : (i : Fin n) → α (p.succAbove i)} {xₚ yₚ : α p} :
p.insertNth xₚ x = p.insertNth yₚ y xₚ = yₚ x = y
theorem Fin.insertNth_left_injective {n : } {α : Fin (n + 1)Sort u_1} {p : Fin (n + 1)} (x : (i : Fin n) → α (p.succAbove i)) :
Function.Injective fun (x_1 : α p) => p.insertNth x_1 x
theorem Fin.insertNth_right_injective {n : } {α : Fin (n + 1)Sort u_1} {p : Fin (n + 1)} (x : α p) :
theorem Fin.insertNth_apply_below {n : } {α : Fin (n + 1)Sort u_1} {i j : Fin (n + 1)} (h : j < i) (x : α i) (p : (k : Fin n) → α (i.succAbove k)) :
i.insertNth x p j = Eq.recOn (p (j.castPred ))
theorem Fin.insertNth_apply_above {n : } {α : Fin (n + 1)Sort u_1} {i j : Fin (n + 1)} (h : i < j) (x : α i) (p : (k : Fin n) → α (i.succAbove k)) :
i.insertNth x p j = Eq.recOn (p (j.pred ))
theorem Fin.insertNth_zero {n : } {α : Fin (n + 1)Sort u_1} (x : α 0) (p : (j : Fin n) → α (succAbove 0 j)) :
insertNth 0 x p = cons x fun (j : Fin n) => cast (p j)
@[simp]
theorem Fin.insertNth_zero' {n : } {β : Sort u_2} (x : β) (p : Fin nβ) :
insertNth 0 x p = cons x p
theorem Fin.insertNth_last {n : } {α : Fin (n + 1)Sort u_1} (x : α (last n)) (p : (j : Fin n) → α ((last n).succAbove j)) :
(last n).insertNth x p = snoc (fun (j : Fin n) => cast (p j)) x
@[simp]
theorem Fin.insertNth_last' {n : } {β : Sort u_2} (x : β) (p : Fin nβ) :
(last n).insertNth x p = snoc p x
theorem Fin.insertNth_rev {n : } {α : Sort u_3} (i : Fin (n + 1)) (a : α) (f : Fin nα) (j : Fin (n + 1)) :
i.insertNth a f j.rev = i.rev.insertNth a (f rev) j
theorem Fin.insertNth_comp_rev {n : } {α : Sort u_3} (i : Fin (n + 1)) (x : α) (p : Fin nα) :
theorem Fin.cons_rev {α : Sort u_3} {n : } (a : α) (f : Fin nα) (i : Fin (n + 1)) :
cons a f i.rev = snoc (f rev) a i
theorem Fin.cons_comp_rev {α : Sort u_3} {n : } (a : α) (f : Fin nα) :
cons a f rev = snoc (f rev) a
theorem Fin.snoc_rev {α : Sort u_3} {n : } (a : α) (f : Fin nα) (i : Fin (n + 1)) :
snoc f a i.rev = cons a (f rev) i
theorem Fin.snoc_comp_rev {α : Sort u_3} {n : } (a : α) (f : Fin nα) :
snoc f a rev = cons a (f rev)
theorem Fin.insertNth_binop {n : } {α : Fin (n + 1)Sort u_1} (op : (j : Fin (n + 1)) → α jα jα j) (i : Fin (n + 1)) (x y : α i) (p q : (j : Fin n) → α (i.succAbove j)) :
(i.insertNth (op i x y) fun (j : Fin n) => op (i.succAbove j) (p j) (q j)) = fun (j : Fin (n + 1)) => op j (i.insertNth x p j) (i.insertNth y q j)
theorem Fin.insertNth_le_iff {n : } {α : Fin (n + 1)Type u_3} [(i : Fin (n + 1)) → Preorder (α i)] {i : Fin (n + 1)} {x : α i} {p : (j : Fin n) → α (i.succAbove j)} {q : (j : Fin (n + 1)) → α j} :
i.insertNth x p q x q i p fun (j : Fin n) => q (i.succAbove j)
theorem Fin.le_insertNth_iff {n : } {α : Fin (n + 1)Type u_3} [(i : Fin (n + 1)) → Preorder (α i)] {i : Fin (n + 1)} {x : α i} {p : (j : Fin n) → α (i.succAbove j)} {q : (j : Fin (n + 1)) → α j} :
q i.insertNth x p q i x (fun (j : Fin n) => q (i.succAbove j)) p
@[simp]
theorem Fin.removeNth_update {n : } {α : Fin (n + 1)Sort u_1} (p : Fin (n + 1)) (x : α p) (f : (j : Fin (n + 1)) → α j) :
@[simp]
theorem Fin.insertNth_removeNth {n : } {α : Fin (n + 1)Sort u_1} (p : Fin (n + 1)) (x : α p) (f : (j : Fin (n + 1)) → α j) :
theorem Fin.insertNth_self_removeNth {n : } {α : Fin (n + 1)Sort u_1} (p : Fin (n + 1)) (f : (j : Fin (n + 1)) → α j) :
p.insertNth (f p) (p.removeNth f) = f
@[simp]
theorem Fin.update_insertNth {n : } {α : Fin (n + 1)Sort u_1} (p : Fin (n + 1)) (x y : α p) (f : (i : Fin n) → α (p.succAbove i)) :
def Fin.insertNthEquiv {n : } (α : Fin (n + 1)Type u) (p : Fin (n + 1)) :
α p × ((i : Fin n) → α (p.succAbove i)) ((i : Fin (n + 1)) → α i)

Equivalence between tuples of length n + 1 and pairs of an element and a tuple of length n given by separating out the p-th element of the tuple.

This is Fin.insertNth as an Equiv.

Equations
  • One or more equations did not get rendered due to their size.
@[simp]
theorem Fin.insertNthEquiv_apply {n : } (α : Fin (n + 1)Type u) (p : Fin (n + 1)) (f : α p × ((i : Fin n) → α (p.succAbove i))) (j : Fin (n + 1)) :
(insertNthEquiv α p) f j = p.insertNth f.1 f.2 j
@[simp]
theorem Fin.insertNthEquiv_symm_apply {n : } (α : Fin (n + 1)Type u) (p : Fin (n + 1)) (f : (i : Fin (n + 1)) → α i) :
@[simp]
theorem Fin.insertNthEquiv_zero {n : } (α : Fin (n + 1)Type u_3) :
@[simp]
theorem Fin.insertNthEquiv_last (n : ) (α : Type u_3) :
insertNthEquiv (fun (x : Fin (n + 1)) => α) (last n) = snocEquiv fun (x : Fin (n + 1)) => α

Note this lemma can only be written about non-dependent tuples as insertNth (last n) = snoc is not a definitional equality.

def Fin.find {n : } (p : Fin nProp) [DecidablePred p] :

find p returns the first index n where p n is satisfied, and none if it is never satisfied.

Equations
theorem Fin.find_spec {n : } (p : Fin nProp) [DecidablePred p] {i : Fin n} :
i find pp i

If find p = some i, then p i holds

theorem Fin.isSome_find_iff {n : } {p : Fin nProp} [DecidablePred p] :
(find p).isSome = true ∃ (i : Fin n), p i

find p does not return none if and only if p i holds at some index i.

theorem Fin.find_eq_none_iff {n : } {p : Fin nProp} [DecidablePred p] :
find p = none ∀ (i : Fin n), ¬p i

find p returns none if and only if p i never holds.

theorem Fin.find_min {n : } {p : Fin nProp} [DecidablePred p] {i : Fin n} :
i find p∀ {j : Fin n}, j < i¬p j

If find p returns some i, then p j does not hold for j < i, i.e., i is minimal among the indices where p holds.

theorem Fin.find_min' {n : } {p : Fin nProp} [DecidablePred p] {i : Fin n} (h : i find p) {j : Fin n} (hj : p j) :
i j
theorem Fin.nat_find_mem_find {n : } {p : Fin nProp} [DecidablePred p] (h : ∃ (i : ) (hin : i < n), p i, hin) :
Nat.find h, find p
theorem Fin.mem_find_iff {n : } {p : Fin nProp} [DecidablePred p] {i : Fin n} :
i find p p i ∀ (j : Fin n), p ji j
theorem Fin.find_eq_some_iff {n : } {p : Fin nProp} [DecidablePred p] {i : Fin n} :
find p = some i p i ∀ (j : Fin n), p ji j
theorem Fin.mem_find_of_unique {n : } {p : Fin nProp} [DecidablePred p] (h : ∀ (i j : Fin n), p ip ji = j) {i : Fin n} (hi : p i) :
i find p
def Fin.contractNth {n : } {α : Sort u_1} (j : Fin (n + 1)) (op : ααα) (g : Fin (n + 1)α) (k : Fin n) :
α

Sends (g₀, ..., gₙ) to (g₀, ..., op gⱼ gⱼ₊₁, ..., gₙ).

Equations
theorem Fin.contractNth_apply_of_lt {n : } {α : Sort u_1} (j : Fin (n + 1)) (op : ααα) (g : Fin (n + 1)α) (k : Fin n) (h : k < j) :
j.contractNth op g k = g k.castSucc
theorem Fin.contractNth_apply_of_eq {n : } {α : Sort u_1} (j : Fin (n + 1)) (op : ααα) (g : Fin (n + 1)α) (k : Fin n) (h : k = j) :
j.contractNth op g k = op (g k.castSucc) (g k.succ)
theorem Fin.contractNth_apply_of_gt {n : } {α : Sort u_1} (j : Fin (n + 1)) (op : ααα) (g : Fin (n + 1)α) (k : Fin n) (h : j < k) :
j.contractNth op g k = g k.succ
theorem Fin.contractNth_apply_of_ne {n : } {α : Sort u_1} (j : Fin (n + 1)) (op : ααα) (g : Fin (n + 1)α) (k : Fin n) (hjk : j k) :
j.contractNth op g k = g (j.succAbove k)
theorem Fin.comp_contractNth {n : } {α : Sort u_1} {β : Sort u_2} (opα : ααα) (opβ : βββ) {f : αβ} (hf : ∀ (x y : α), f (opα x y) = opβ (f x) (f y)) (j : Fin (n + 1)) (g : Fin (n + 1)α) :
f j.contractNth opα g = j.contractNth opβ (f g)
theorem Fin.sigma_eq_of_eq_comp_cast {α : Type u_1} {a b : (ii : ) × (Fin iiα)} (h : a.fst = b.fst) :
a.snd = b.snd Fin.cast ha = b

To show two sigma pairs of tuples agree, it to show the second elements are related via Fin.cast.

theorem Fin.sigma_eq_iff_eq_comp_cast {α : Type u_1} {a b : (ii : ) × (Fin iiα)} :
a = b ∃ (h : a.fst = b.fst), a.snd = b.snd Fin.cast h

Fin.sigma_eq_of_eq_comp_cast as an iff.

def piFinTwoEquiv (α : Fin 2Type u) :
((i : Fin 2) → α i) α 0 × α 1

Π i : Fin 2, α i is equivalent to α 0 × α 1. See also finTwoArrowEquiv for a non-dependent version and prodEquivPiFinTwo for a version with inputs α β : Type u.

Equations
@[simp]
theorem piFinTwoEquiv_apply (α : Fin 2Type u) :
(piFinTwoEquiv α) = fun (f : (i : Fin 2) → α i) => (f 0, f 1)
@[simp]
theorem piFinTwoEquiv_symm_apply (α : Fin 2Type u) :
(piFinTwoEquiv α).symm = fun (p : α 0 × α 1) => Fin.cons p.1 (Fin.cons p.2 finZeroElim)