author | berghofe |
Fri, 01 Jul 2005 13:54:12 +0200 | |
changeset 16633 | 208ebc9311f2 |
parent 16417 | 9bc16273c2d4 |
child 18372 | 2bffdf62fe7f |
permissions | -rw-r--r-- |
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
1 |
(* Title: HOL/IMP/Expr.thy |
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
2 |
ID: $Id$ |
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
3 |
Author: Heiko Loetzbeyer & Robert Sandner & Tobias Nipkow, TUM |
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
4 |
Copyright 1994 TUM |
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
5 |
*) |
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
6 |
|
12431 | 7 |
header "Expressions" |
8 |
||
16417 | 9 |
theory Expr imports Main begin |
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
10 |
|
12431 | 11 |
text {* |
12 |
Arithmetic expressions and Boolean expressions. |
|
13 |
Not used in the rest of the language, but included for completeness. |
|
14 |
*} |
|
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
15 |
|
12431 | 16 |
subsection "Arithmetic expressions" |
12546 | 17 |
typedecl loc |
12431 | 18 |
|
19 |
types |
|
20 |
state = "loc => nat" |
|
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
21 |
|
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
22 |
datatype |
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
23 |
aexp = N nat |
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
24 |
| X loc |
12546 | 25 |
| Op1 "nat => nat" aexp |
26 |
| Op2 "nat => nat => nat" aexp aexp |
|
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
27 |
|
12431 | 28 |
subsection "Evaluation of arithmetic expressions" |
1729 | 29 |
consts evala :: "((aexp*state) * nat) set" |
12546 | 30 |
syntax "_evala" :: "[aexp*state,nat] => bool" (infixl "-a->" 50) |
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
31 |
translations |
1729 | 32 |
"aesig -a-> n" == "(aesig,n) : evala" |
1789 | 33 |
inductive evala |
12546 | 34 |
intros |
12431 | 35 |
N: "(N(n),s) -a-> n" |
36 |
X: "(X(x),s) -a-> s(x)" |
|
37 |
Op1: "(e,s) -a-> n ==> (Op1 f e,s) -a-> f(n)" |
|
12546 | 38 |
Op2: "[| (e0,s) -a-> n0; (e1,s) -a-> n1 |] |
12431 | 39 |
==> (Op2 f e0 e1,s) -a-> f n0 n1" |
40 |
||
41 |
lemmas [intro] = N X Op1 Op2 |
|
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
42 |
|
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
43 |
|
12431 | 44 |
subsection "Boolean expressions" |
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
45 |
|
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
46 |
datatype |
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
47 |
bexp = true |
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
48 |
| false |
12546 | 49 |
| ROp "nat => nat => bool" aexp aexp |
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
50 |
| noti bexp |
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
51 |
| andi bexp bexp (infixl 60) |
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
52 |
| ori bexp bexp (infixl 60) |
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
53 |
|
12431 | 54 |
subsection "Evaluation of boolean expressions" |
12546 | 55 |
consts evalb :: "((bexp*state) * bool)set" |
56 |
syntax "_evalb" :: "[bexp*state,bool] => bool" (infixl "-b->" 50) |
|
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
57 |
|
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
58 |
translations |
1729 | 59 |
"besig -b-> b" == "(besig,b) : evalb" |
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
60 |
|
1789 | 61 |
inductive evalb |
12431 | 62 |
-- "avoid clash with ML constructors true, false" |
63 |
intros |
|
64 |
tru: "(true,s) -b-> True" |
|
65 |
fls: "(false,s) -b-> False" |
|
12546 | 66 |
ROp: "[| (a0,s) -a-> n0; (a1,s) -a-> n1 |] |
12431 | 67 |
==> (ROp f a0 a1,s) -b-> f n0 n1" |
68 |
noti: "(b,s) -b-> w ==> (noti(b),s) -b-> (~w)" |
|
12546 | 69 |
andi: "[| (b0,s) -b-> w0; (b1,s) -b-> w1 |] |
1729 | 70 |
==> (b0 andi b1,s) -b-> (w0 & w1)" |
12546 | 71 |
ori: "[| (b0,s) -b-> w0; (b1,s) -b-> w1 |] |
12431 | 72 |
==> (b0 ori b1,s) -b-> (w0 | w1)" |
73 |
||
74 |
lemmas [intro] = tru fls ROp noti andi ori |
|
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
75 |
|
12431 | 76 |
subsection "Denotational semantics of arithmetic and boolean expressions" |
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
77 |
consts |
12431 | 78 |
A :: "aexp => state => nat" |
79 |
B :: "bexp => state => bool" |
|
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
80 |
|
5183 | 81 |
primrec |
1900 | 82 |
"A(N(n)) = (%s. n)" |
83 |
"A(X(x)) = (%s. s(x))" |
|
84 |
"A(Op1 f a) = (%s. f(A a s))" |
|
85 |
"A(Op2 f a0 a1) = (%s. f (A a0 s) (A a1 s))" |
|
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
86 |
|
5183 | 87 |
primrec |
1900 | 88 |
"B(true) = (%s. True)" |
89 |
"B(false) = (%s. False)" |
|
90 |
"B(ROp f a0 a1) = (%s. f (A a0 s) (A a1 s))" |
|
91 |
"B(noti(b)) = (%s. ~(B b s))" |
|
92 |
"B(b0 andi b1) = (%s. (B b0 s) & (B b1 s))" |
|
93 |
"B(b0 ori b1) = (%s. (B b0 s) | (B b1 s))" |
|
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
94 |
|
12431 | 95 |
lemma [simp]: "(N(n),s) -a-> n' = (n = n')" |
96 |
by (rule,cases set: evala) auto |
|
97 |
||
12546 | 98 |
lemma [simp]: "(X(x),sigma) -a-> i = (i = sigma x)" |
12431 | 99 |
by (rule,cases set: evala) auto |
100 |
||
12546 | 101 |
lemma [simp]: |
102 |
"(Op1 f e,sigma) -a-> i = (\<exists>n. i = f n \<and> (e,sigma) -a-> n)" |
|
12431 | 103 |
by (rule,cases set: evala) auto |
104 |
||
105 |
lemma [simp]: |
|
12546 | 106 |
"(Op2 f a1 a2,sigma) -a-> i = |
12431 | 107 |
(\<exists>n0 n1. i = f n0 n1 \<and> (a1, sigma) -a-> n0 \<and> (a2, sigma) -a-> n1)" |
108 |
by (rule,cases set: evala) auto |
|
109 |
||
12546 | 110 |
lemma [simp]: "((true,sigma) -b-> w) = (w=True)" |
12431 | 111 |
by (rule,cases set: evalb) auto |
112 |
||
113 |
lemma [simp]: |
|
12546 | 114 |
"((false,sigma) -b-> w) = (w=False)" |
12431 | 115 |
by (rule,cases set: evalb) auto |
116 |
||
117 |
lemma [simp]: |
|
12546 | 118 |
"((ROp f a0 a1,sigma) -b-> w) = |
119 |
(? m. (a0,sigma) -a-> m & (? n. (a1,sigma) -a-> n & w = f m n))" |
|
12431 | 120 |
by (rule,cases set: evalb) auto |
121 |
||
12546 | 122 |
lemma [simp]: |
123 |
"((noti(b),sigma) -b-> w) = (? x. (b,sigma) -b-> x & w = (~x))" |
|
124 |
by (rule,cases set: evalb) auto |
|
125 |
||
126 |
lemma [simp]: |
|
127 |
"((b0 andi b1,sigma) -b-> w) = |
|
128 |
(? x. (b0,sigma) -b-> x & (? y. (b1,sigma) -b-> y & w = (x&y)))" |
|
12431 | 129 |
by (rule,cases set: evalb) auto |
130 |
||
131 |
lemma [simp]: |
|
12546 | 132 |
"((b0 ori b1,sigma) -b-> w) = |
133 |
(? x. (b0,sigma) -b-> x & (? y. (b1,sigma) -b-> y & w = (x|y)))" |
|
12431 | 134 |
by (rule,cases set: evalb) auto |
135 |
||
136 |
||
12546 | 137 |
lemma aexp_iff: |
138 |
"!!n. ((a,s) -a-> n) = (A a s = n)" |
|
139 |
by (induct a) auto |
|
12431 | 140 |
|
12546 | 141 |
lemma bexp_iff: |
142 |
"!!w. ((b,s) -b-> w) = (B b s = w)" |
|
143 |
by (induct b) (auto simp add: aexp_iff) |
|
12431 | 144 |
|
1697
687f0710c22d
Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff
changeset
|
145 |
end |