Timings for Theory.v
Require Import Basics.Overture Basics.Tactics Basics.PathGroupoids Basics.Trunc.
Require Import Types.Paths Types.Unit Types.Prod.
Require Export Spaces.List.Core.
(** * Theory of Lists and List Operations *)
(** In this file we collect lemmas about lists and their operations. We don't include those in [List.Core] so that file can stay lightweight on dependencies. *)
(** We generally try to keep the order the same as the concepts appeared in [List.Core]. *)
Local Open Scope list_scope.
(** ** Concatenation *)
(** Associativity of list concatenation. *)
Definition app_assoc {A} (x y z : list A)
: app x (app y z) = app (app x y) z.
induction x as [|a x IHx] in |- *.
(** The type of lists has a monoidal structure given by concatenation. *)
Definition list_pentagon {A} (w x y z : list A)
: app_assoc w x (y ++ z) @ app_assoc (w ++ x) y z
= ap (fun l => w ++ l) (app_assoc x y z)
@ app_assoc w (x ++ y) z
@ ap (fun l => l ++ z) (app_assoc w x y).
induction w as [|? w IHw] in x, y, z |- *.
rhs_V nrapply (ap (ap (cons a)) (IHw x y z)).
lhs_V nrapply ap_compose.
nrapply (ap_compose (fun l => l ++ z)).
Lemma fold_left_app {A B} (f : A -> B -> A) (l l' : list B) (i : A)
: fold_left f (l ++ l') i = fold_left f l' (fold_left f l i).
Lemma fold_right_app {A B} (f : B -> A -> A) (i : A) (l l' : list B)
: fold_right f i (l ++ l') = fold_right f (fold_right f i l') l.
exact (ap (f a) (IHl _)).
Lemma map_id {A} (f : A -> A) (Hf : forall x, f x = x) (l : list A)
: map f l = l.
induction l as [|x l IHl].
Lemma map2_cons {A B C} (f : A -> B -> C) defl defr x l1 y l2
: map2 f defl defr (x :: l1) (y :: l2)
= (f x y) :: map2 f defl defr l1 l2.
Lemma for_all_trivial {A} (P : A -> Type) : (forall x, P x) ->
forall l, for_all P l.
intros HP l; induction l as [|x l IHl]; split; auto.
Lemma for_all_map {A B} P Q (f : A -> B) (Hf : forall x, P x -> Q (f x))
: forall l, for_all P l -> for_all Q (map f l).
intros l;induction l as [|x l IHl];simpl.
Lemma for_all_map2 {A B C}
(P : A -> Type) (Q : B -> Type) (R : C -> Type)
(f : A -> B -> C) (Hf : forall x y, P x -> Q y -> R (f x y))
def_l (Hdefl : forall l1, for_all P l1 -> for_all R (def_l l1))
def_r (Hdefr : forall l2, for_all Q l2 -> for_all R (def_r l2))
(l1 : list A) (l2 : list B)
: for_all P l1 -> for_all Q l2
-> for_all R (map2 f def_l def_r l1 l2).
induction l1 as [|x l1 IHl1] in l2 |- *.
destruct l2 as [|y l2]; cbn; auto.
destruct l2 as [|y l2]; intros [Hx Hl1];
[intros _ | intros [Hy Hl2] ]; simpl; auto.
Lemma fold_preserves {A B} P Q (f : A -> B -> A)
(Hf : forall x y, P x -> Q y -> P (f x y))
(acc : A) (Ha : P acc) (l : list B) (Hl : for_all Q l)
: P (fold_left f l acc).
induction l as [|x l IHl] in acc, Ha, Hl |- *.
Global Instance for_all_trunc {A} {n} (P : A -> Type) (l : list A)
: for_all (fun x => IsTrunc n (P x)) l -> IsTrunc n (for_all P l).
induction l as [|x l IHl]; simpl.