-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBExp.v
76 lines (65 loc) · 1.67 KB
/
BExp.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
(* Boolean expressions *)
Require Import imports.
Require Import AExp.
Local Open Scope Z_scope.
Inductive bexpr :=
| Bval : bool -> bexpr
| Bnot : bexpr -> bexpr
| Band : bexpr -> bexpr -> bexpr
| Bless : aexpr -> aexpr -> bexpr.
Fixpoint bval (s : state) (e : bexpr) :=
match e with
| Bval b => b
| Bnot e1 => negb (bval s e1)
| Band e1 e2 => bval s e1 && bval s e2
| Bless a1 a2 => aval s a1 <? aval s a2
end.
Fixpoint not (e : bexpr) :=
match e with
| Bval true => Bval false
| Bval false => Bval true
| _ => Bnot e
end.
Fixpoint and (e1 e2 : bexpr) :=
match e1, e2 with
| Bval true, _ => e2
| _, Bval true => e1
| Bval false, _ => Bval false
| _, Bval false => Bval false
| _, _ => Band e1 e2
end.
Definition less (a1 a2 : aexpr) :=
match a1, a2 with
| Anum n1, Anum n2 => Bval (n1 <? n2)
| _, _ => Bless a1 a2
end.
Fixpoint bsimp (e : bexpr) :=
match e with
| Bnot e1 => not (bsimp e1)
| Band e1 e2 => and (bsimp e1) (bsimp e2)
| Bless a1 a2 => less a1 a2
| _ => e
end.
Lemma lem_bval_not : forall s e, bval s (not e) = negb (bval s e).
Proof.
induction e; sauto.
Qed.
Lemma lem_bval_and : forall s e1 e2, bval s (and e1 e2) = bval s e1 && bval s e2.
Proof.
induction e1; sauto.
Qed.
Lemma lem_bval_less : forall s a1 a2, bval s (less a1 a2) = (aval s a1 <? aval s a2).
Proof.
induction a1; sauto.
Qed.
Lemma lem_bval_bsimp : forall s e, bval s (bsimp e) = bval s e.
Proof.
induction e; sauto.
Reconstr.htrivial Reconstr.AllHyps
(@lem_bval_not)
Reconstr.Empty.
Reconstr.htrivial Reconstr.AllHyps
(@lem_bval_and)
Reconstr.Empty.
scrush.
Qed.