Commit ec592463 authored by Robbert Krebbers's avatar Robbert Krebbers
Browse files

Merge branch 'ralf/list-find-fmap' into 'master'

some list lemmas

See merge request iris/stdpp!82
parents 2e0bf441 7748d9c5
......@@ -907,8 +907,41 @@ Section find.
induction 1 as [|x y l ? IH]; intros; simplify_option_eq; eauto.
by destruct IH as [[i x'] ->]; [|exists (S i, x')].
Lemma list_find_fmap {B : Type} (f : B → A) (l : list B) :
list_find P (f <$> l) = prod_map id f <$> list_find (P ∘ f) l.
induction l as [|x l IH]; [done|]. csimpl. (* csimpl re-folds fmap *)
case_decide; [done|].
rewrite IH. by destruct (list_find (P ∘ f) l).
Lemma list_find_ext (Q : A → Prop) `{∀ x, Decision (Q x)} l :
(∀ x, P x ↔ Q x) →
list_find P l = list_find Q l.
intros HPQ. induction l as [|x l IH]; [done|]. simpl.
erewrite decide_iff by done. by rewrite IH.
End find.
(** ** Properties of the [omap] function *)
Lemma list_fmap_omap {B C : Type} (f : A → option B) (g : B → C) (l : list A) :
g <$> omap f l = omap (λ x, g <$> (f x)) l.
induction l as [|x y IH]; [done|]. csimpl.
destruct (f x); [|done]. csimpl. by f_equal.
Lemma list_omap_ext {B C : Type} (f : A → option C) (g : B → option C)
(l1 : list A) (l2 : list B) :
Forall2 (λ a b, f a = g b) l1 l2 →
omap f l1 = omap g l2.
induction 1 as [|x y l l' Hfg ? IH]; [done|].
csimpl. rewrite Hfg. destruct (g y); [|done].
by f_equal.
(** ** Properties of the [reverse] function *)
Lemma reverse_nil : reverse [] =@{list A} [].
Proof. done. Qed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment