aboutsummaryrefslogtreecommitdiff
path: root/src/Util/ListUtil.v
diff options
context:
space:
mode:
authorGravatar Jade Philipoom <jadep@google.com>2018-03-08 16:11:06 +0100
committerGravatar jadephilipoom <jade.philipoom@gmail.com>2018-04-03 09:00:55 -0400
commit39a7ef1f4787381bf7013025cae1d8edc980500c (patch)
tree7f3f1ebabf12a8b0d46a0a73e75a3a5f44a95943 /src/Util/ListUtil.v
parentab4bea12d33f3c4225d0af577242c1bbae12d420 (diff)
move some lemmas to ZUtil/ListUtil
Diffstat (limited to 'src/Util/ListUtil.v')
-rw-r--r--src/Util/ListUtil.v18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/Util/ListUtil.v b/src/Util/ListUtil.v
index 081ef54b5..e162c2daf 100644
--- a/src/Util/ListUtil.v
+++ b/src/Util/ListUtil.v
@@ -107,6 +107,9 @@ Module Export List.
End FlatMap.
Hint Rewrite @flat_map_cons @flat_map_nil : push_flat_map.
+ Lemma rev_cons {A} x ls : @rev A (x :: ls) = rev ls ++ [x]. Proof. reflexivity. Qed.
+ Hint Rewrite @rev_cons : list.
+
Section FoldRight.
Context {A B} (f:B->A->A).
Lemma fold_right_nil : forall {A B} (f:B->A->A) a,
@@ -115,8 +118,14 @@ Module Export List.
Lemma fold_right_cons : forall a b bs,
fold_right f a (b::bs) = f b (fold_right f a bs).
Proof. reflexivity. Qed.
+ Lemma fold_right_snoc a x ls:
+ @fold_right A B f a (ls ++ [x]) = fold_right f (f x a) ls.
+ Proof.
+ rewrite <-(rev_involutive ls), <-rev_cons.
+ rewrite !fold_left_rev_right; reflexivity.
+ Qed.
End FoldRight.
- Hint Rewrite @fold_right_nil @fold_right_cons : simpl_fold_right push_fold_right.
+ Hint Rewrite @fold_right_nil @fold_right_cons @fold_right_snoc : simpl_fold_right push_fold_right.
Section Partition.
Lemma partition_nil {A} (f:A->_) : partition f nil = (nil, nil).
@@ -1869,3 +1878,10 @@ Ltac expand_lists _ :=
| _ => idtac
end;
subst v; reflexivity ].
+
+Lemma list_rect_to_match A (P:list A -> Type) (Pnil: P nil) (PS: forall a tl, P (a :: tl)) ls :
+ @list_rect A P Pnil (fun a tl _ => PS a tl) ls = match ls with
+ | cons a tl => PS a tl
+ | nil => Pnil
+ end.
+Proof. destruct ls; reflexivity. Qed.