-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util.v
107 lines (96 loc) · 2.17 KB
/
Util.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Require Import Arith Bool List.
Require Import Omega.
Set Implicit Arguments.
Lemma seq_minimum : forall m n x, In x (seq n m) -> n <= x.
Proof.
induction m.
- simpl.
intro; contradiction.
- intros n x.
simpl.
intro.
destruct H; try omega.
apply IHm in H.
omega.
Qed.
Lemma seq_nodup : forall m n, NoDup (seq n m).
Proof.
induction m; intros; simpl; constructor.
- unfold not; intro.
apply seq_minimum in H.
omega.
- auto.
Qed.
Lemma count_occ_app A dec :
forall (x : A) (ys zs : list A),
count_occ dec (ys ++ zs) x = count_occ dec ys x + count_occ dec zs x.
Proof.
induction ys; auto.
intro zs.
simpl.
rewrite (IHys zs).
destruct (dec a x); omega.
Qed.
Fixpoint scan_left (A B : Type) (f : A -> B -> A) (bs : list B)
(a : A): list A :=
match bs with
| nil => a :: nil
| b :: bs' => let a' := f a b in a :: scan_left f bs' a'
end.
Lemma scanl_exist_tl A B :
forall (f : A -> B -> A) bs a, exists as', scan_left f bs a = a :: as'.
Proof.
intros.
destruct bs.
- simpl.
exists nil.
reflexivity.
- simpl.
exists (scan_left f bs (f a b)).
reflexivity.
Qed.
Lemma foldl_scanl_last A B :
forall f (bs : list B) (a : A) d,
fold_left f bs a = last (scan_left f bs a) d.
Proof.
induction bs as [| b bs' IHbs'].
- intros a d.
reflexivity.
- intros.
simpl fold_left.
specialize (IHbs' (f a b) d).
rewrite IHbs'.
simpl scan_left.
remember (scanl_exist_tl f bs' (f a b)) as Extl; clear HeqExtl.
destruct Extl.
rewrite H.
reflexivity.
Qed.
Fixpoint rep A (a : A) (n : nat): list A :=
match n with
| O => nil
| S n' => a :: rep a n'
end.
Lemma rep_length A a n : length (@rep A a n) = n.
Proof.
induction n; simpl; auto.
Qed.
Lemma rep_in A a n : forall x, In x (@rep A a n) -> a = x.
Proof.
induction n; simpl; intuition.
Qed.
Lemma rep_count A dec a n : count_occ dec (@rep A a n) a = n.
Proof.
induction n; auto.
simpl.
case (dec a a); intro; auto.
exfalso; apply n0.
reflexivity.
Qed.
Lemma rep_count_0 A dec a b n : a <> b -> count_occ dec (@rep A a n) b = 0.
Proof.
intro a_ne_b.
induction n; auto.
simpl.
case (dec a b); intro; try contradiction; auto.
Qed.