-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAExp.v
65 lines (54 loc) · 1.36 KB
/
AExp.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
(* Arithmetic expressions *)
Require Import imports.
Require Import String.
Local Open Scope Z_scope.
Definition vname := string.
Definition val := Z.
Inductive aexpr :=
| Anum : val -> aexpr
| Avar : vname -> aexpr
| Aplus : aexpr -> aexpr -> aexpr.
Definition state := vname -> val.
Fixpoint aval (s : state) (e : aexpr) :=
match e with
| Anum n => n
| Avar x => s x
| Aplus x y => aval s x + aval s y
end.
Fixpoint asimp_const (e : aexpr) :=
match e with
| Anum n => Anum n
| Avar x => Avar x
| Aplus e1 e2 =>
match asimp_const e1, asimp_const e2 with
| Anum n1, Anum n2 => Anum (n1 + n2)
| e1', e2' => Aplus e1' e2'
end
end.
Lemma lem_aval_asimp_const : forall s e, aval s (asimp_const e) = aval s e.
Proof.
induction e; sauto.
Qed.
Fixpoint plus (e1 e2 : aexpr) :=
match e1, e2 with
| Anum n1, Anum n2 => Anum (n1 + n2)
| Anum 0, _ => e2
| _, Anum 0 => e1
| _, _ => Aplus e1 e2
end.
Lemma lem_aval_plus : forall s e1 e2, aval s (plus e1 e2) = aval s e1 + aval s e2.
Proof.
Reconstr.scrush (** hammer *).
Qed.
Fixpoint asimp (e : aexpr) :=
match e with
| Aplus x y => plus (asimp x) (asimp y)
| _ => e
end.
Lemma lem_aval_asimp : forall s e, aval s (asimp e) = aval s e.
Proof.
induction e; sauto.
Reconstr.htrivial Reconstr.AllHyps
(@lem_aval_plus)
Reconstr.Empty.
Qed.