This repository has been archived by the owner on Feb 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Nelist.v
75 lines (54 loc) · 1.76 KB
/
Nelist.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
(** * Nelist.v: A general theory of non empty lists on Type *)
Set Implicit Arguments.
Set Strict Implicit.
Section NELIST.
Variable A : Type.
Inductive nelist : Type :=
singl : A -> nelist | add : A -> nelist -> nelist.
Definition hd (l:nelist) : A :=
match l with (singl a) => a | (add a _) => a end.
Fixpoint app (l m : nelist) {struct l} : nelist :=
match l with (singl a) => add a m | (add a l1) => add a (app l1 m) end.
Fixpoint rev_app (l m : nelist) {struct l} : nelist :=
match l with (singl a) => add a m | (add a l1) => rev_app l1 (add a m) end.
Definition rev (l:nelist) : nelist :=
match l with (singl a) => l | (add a l1) => rev_app l1 (singl a) end.
Lemma app_assoc : forall l1 l2 l3, app l1 (app l2 l3) = app (app l1 l2) l3.
intros; induction l1; simpl; auto.
rewrite IHl1; auto.
Qed.
Hint Resolve app_assoc.
Lemma rev_app_rev : forall l m, rev_app l m = app (rev l) m.
induction l; simpl; intros; auto.
rewrite IHl.
rewrite IHl.
rewrite <- app_assoc; trivial.
Qed.
Hint Resolve rev_app_rev.
Lemma rev_app_app_rev : forall l m, rev (rev_app l m) = app (rev m) l.
induction l; intros;simpl; auto.
rewrite IHl; simpl.
rewrite rev_app_rev.
rewrite <- app_assoc; trivial.
Qed.
Lemma rev_rev : forall l, rev (rev l) = l.
destruct l; simpl; intros; auto.
rewrite rev_app_app_rev; trivial.
Qed.
Lemma rev_app_distr : forall l m, rev (app l m) = app (rev m) (rev l).
induction l; intros;simpl; auto.
rewrite rev_app_rev.
rewrite rev_app_rev.
rewrite IHl; auto.
Qed.
Hint Resolve rev_rev rev_app_distr.
Lemma hd_app : forall l m, hd (app l m) = hd l.
destruct l; simpl; auto.
Qed.
Hint Resolve hd_app.
Lemma hd_rev_add : forall a l, hd (rev (add a l)) = hd (rev l).
simpl; intros.
rewrite rev_app_rev; auto.
Qed.
Hint Resolve hd_rev_add.
End NELIST.