Skip to content

Commit 98e393a

Browse files
cassiersgstrub
authored andcommitted
Add lemmas for list count and perm_eq
1 parent 2795594 commit 98e393a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

theories/datatypes/List.ec

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,16 @@ proof.
470470
by case (hs = x) => /= _ //; rewrite addrC ltzS count_ge0.
471471
qed.
472472
473+
lemma le_in_count ['a] (p1 p2 : 'a -> bool) (s : 'a list) :
474+
(forall x, x \in s => p1 x => p2 x) =>
475+
count p1 s <= count p2 s.
476+
proof. elim: s => //#. qed.
477+
478+
lemma countU ['a] (p1 p2 p : 'a -> bool) (s : 'a list) :
479+
(forall x, x \in s => p x => p1 x \/ p2 x) =>
480+
count p s <= count p1 s + count p2 s.
481+
proof. elim s => //#. qed.
482+
473483
op has (p : 'a -> bool) xs =
474484
with xs = [] => false
475485
with xs = y :: ys => (p y) \/ (has p ys).
@@ -1229,6 +1239,9 @@ proof.
12291239
by move=> h; have := h x => /= ->.
12301240
qed.
12311241
1242+
lemma perm_eq_nil (s : 'a list): perm_eq s [] <=> s = [].
1243+
proof. by split; first apply perm_eq_small. qed.
1244+
12321245
lemma perm_eq_filter (p : 'a -> bool) (s1 s2 : 'a list):
12331246
perm_eq s1 s2 => perm_eq (filter p s1) (filter p s2).
12341247
proof.
@@ -3112,6 +3125,23 @@ case/flatten_mapP=> a'; rewrite mem_undup => -[] /mapP[].
31123125
by case=> a2 b2 /= [_ ->>]; rewrite mem_filter /=.
31133126
qed.
31143127

3128+
lemma perm_eq_flatten ['a] (s0 s1 : 'a list list) :
3129+
perm_eq s0 s1 => perm_eq (flatten s0) (flatten s1).
3130+
proof.
3131+
have hs: forall (s: 'a list list), !0 = 1+size s by smt(size_ge0).
3132+
elim s0 s1.
3133+
+ by move => s1; rewrite flatten_nil perm_eq_sym perm_eq_nil.
3134+
move => x0 s0 IH s1 h.
3135+
have hx0: x0 \in s1 by rewrite -(perm_eq_mem _ _ h x0).
3136+
rewrite flatten_cons (perm_eq_trans (x0 ++ flatten (rem x0 s1))).
3137+
+ by rewrite perm_cat2l IH -(perm_cons x0) (perm_eq_trans s1) 1:h perm_to_rem.
3138+
move: hx0 => {h IH}.
3139+
elim s1 => // x1 s1 IH.
3140+
case (x1 = x0); first by move => ->; rewrite flatten_cons perm_eq_refl.
3141+
move => hx; rewrite eq_sym hx /= => hxs.
3142+
by rewrite !flatten_cons catA perm_catCAl -catA perm_cat2l IH.
3143+
qed.
3144+
31153145
(* -------------------------------------------------------------------- *)
31163146
(* Mask *)
31173147
(* -------------------------------------------------------------------- *)

0 commit comments

Comments
 (0)