Documentation

Mathlib.Data.List.Scan

List.scanl and List.scanr #

theorem List.length_scanl {α : Type u_1} {β : Type u_2} {f : βαβ} (a : β) (l : List α) :
(scanl f a l).length = l.length + 1
@[simp]
theorem List.scanl_nil {α : Type u_1} {β : Type u_2} {f : βαβ} (b : β) :
scanl f b [] = [b]
@[simp]
theorem List.scanl_cons {α : Type u_1} {β : Type u_2} {f : βαβ} {b : β} {a : α} {l : List α} :
scanl f b (a :: l) = [b] ++ scanl f (f b a) l
@[simp]
theorem List.getElem?_scanl_zero {α : Type u_1} {β : Type u_2} {f : βαβ} {b : β} {l : List α} :
(scanl f b l)[0]? = some b
@[simp]
theorem List.getElem_scanl_zero {α : Type u_1} {β : Type u_2} {f : βαβ} {b : β} {l : List α} {h : 0 < (scanl f b l).length} :
(scanl f b l)[0] = b
theorem List.getElem?_succ_scanl {α : Type u_1} {β : Type u_2} {f : βαβ} {b : β} {l : List α} {i : } :
(scanl f b l)[i + 1]? = (scanl f b l)[i]?.bind fun (x : β) => Option.map (fun (y : α) => f x y) l[i]?
@[deprecated List.getElem?_succ_scanl (since := "2025-02-21")]
theorem List.get?_succ_scanl {α : Type u_1} {β : Type u_2} {f : βαβ} {b : β} {l : List α} {i : } :
(scanl f b l)[i + 1]? = (scanl f b l)[i]?.bind fun (x : β) => Option.map (fun (y : α) => f x y) l[i]?

Alias of List.getElem?_succ_scanl.

theorem List.getElem_succ_scanl {α : Type u_1} {β : Type u_2} {f : βαβ} {b : β} {l : List α} {i : } (h : i + 1 < (scanl f b l).length) :
(scanl f b l)[i + 1] = f (scanl f b l)[i] l[i]
@[simp]
theorem List.scanr_nil {α : Type u_1} {β : Type u_2} (f : αββ) (b : β) :
scanr f b [] = [b]
@[simp]
theorem List.scanr_cons {α : Type u_1} {β : Type u_2} (f : αββ) (b : β) (a : α) (l : List α) :
scanr f b (a :: l) = foldr f b (a :: l) :: scanr f b l