src/HOL/IMP/Expr.thy
author wenzelm
Sun, 16 Jan 2011 15:53:03 +0100
changeset 41589 bbd861837ebc
parent 37736 2bf3a2cb5e58
child 42174 d0be2722ce9f
permissions -rw-r--r--
tuned headers;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
    Author:     Heiko Loetzbeyer & Robert Sandner & Tobias Nipkow, TUM
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
     3
*)
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
     4
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
     5
header "Expressions"
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
     6
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 12546
diff changeset
     7
theory Expr imports Main begin
1697
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
     8
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
     9
text {*
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    10
  Arithmetic expressions and Boolean expressions.
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    11
  Not used in the rest of the language, but included for completeness.
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    12
*}
1697
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    13
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    14
subsection "Arithmetic expressions"
12546
wenzelm
parents: 12431
diff changeset
    15
typedecl loc
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    16
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    17
types
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    18
  state = "loc => nat"
1697
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    19
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    20
datatype
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    21
  aexp = N nat
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    22
       | X loc
12546
wenzelm
parents: 12431
diff changeset
    23
       | Op1 "nat => nat" aexp
wenzelm
parents: 12431
diff changeset
    24
       | Op2 "nat => nat => nat" aexp aexp
1697
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    25
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    26
subsection "Evaluation of arithmetic expressions"
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 22818
diff changeset
    27
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 22818
diff changeset
    28
inductive
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 22818
diff changeset
    29
  evala :: "[aexp*state,nat] => bool"  (infixl "-a->" 50)
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 22818
diff changeset
    30
where
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    31
  N:   "(N(n),s) -a-> n"
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 22818
diff changeset
    32
| X:   "(X(x),s) -a-> s(x)"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 22818
diff changeset
    33
| Op1: "(e,s) -a-> n ==> (Op1 f e,s) -a-> f(n)"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 22818
diff changeset
    34
| Op2: "[| (e0,s) -a-> n0;  (e1,s)  -a-> n1 |]
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    35
        ==> (Op2 f e0 e1,s) -a-> f n0 n1"
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    36
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    37
lemmas [intro] = N X Op1 Op2
1697
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    38
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    39
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    40
subsection "Boolean expressions"
1697
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    41
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    42
datatype
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    43
  bexp = true
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    44
       | false
12546
wenzelm
parents: 12431
diff changeset
    45
       | ROp  "nat => nat => bool" aexp aexp
1697
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    46
       | noti bexp
22818
c0695a818c09 eliminated unnamed infixes;
wenzelm
parents: 20503
diff changeset
    47
       | andi bexp bexp         (infixl "andi" 60)
c0695a818c09 eliminated unnamed infixes;
wenzelm
parents: 20503
diff changeset
    48
       | ori  bexp bexp         (infixl "ori" 60)
1697
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    49
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    50
subsection "Evaluation of boolean expressions"
1697
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    51
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 22818
diff changeset
    52
inductive
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 22818
diff changeset
    53
  evalb :: "[bexp*state,bool] => bool"  (infixl "-b->" 50)
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    54
  -- "avoid clash with ML constructors true, false"
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 22818
diff changeset
    55
where
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    56
  tru:   "(true,s) -b-> True"
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 22818
diff changeset
    57
| fls:   "(false,s) -b-> False"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 22818
diff changeset
    58
| ROp:   "[| (a0,s) -a-> n0; (a1,s) -a-> n1 |]
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    59
          ==> (ROp f a0 a1,s) -b-> f n0 n1"
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 22818
diff changeset
    60
| noti:  "(b,s) -b-> w ==> (noti(b),s) -b-> (~w)"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 22818
diff changeset
    61
| andi:  "[| (b0,s) -b-> w0; (b1,s) -b-> w1 |]
1729
e4f8682eea2e Removal of special syntax for -a-> and -b->
paulson
parents: 1697
diff changeset
    62
          ==> (b0 andi b1,s) -b-> (w0 & w1)"
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 22818
diff changeset
    63
| ori:   "[| (b0,s) -b-> w0; (b1,s) -b-> w1 |]
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    64
          ==> (b0 ori b1,s) -b-> (w0 | w1)"
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    65
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    66
lemmas [intro] = tru fls ROp noti andi ori
1697
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    67
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    68
subsection "Denotational semantics of arithmetic and boolean expressions"
1697
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
    69
27362
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    70
primrec A :: "aexp => state => nat"
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    71
where
1900
c7a869229091 Simplified primrec definitions.
berghofe
parents: 1789
diff changeset
    72
  "A(N(n)) = (%s. n)"
27362
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    73
| "A(X(x)) = (%s. s(x))"
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    74
| "A(Op1 f a) = (%s. f(A a s))"
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    75
| "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
    76
27362
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    77
primrec B :: "bexp => state => bool"
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    78
where
1900
c7a869229091 Simplified primrec definitions.
berghofe
parents: 1789
diff changeset
    79
  "B(true) = (%s. True)"
27362
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    80
| "B(false) = (%s. False)"
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    81
| "B(ROp f a0 a1) = (%s. f (A a0 s) (A a1 s))"
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    82
| "B(noti(b)) = (%s. ~(B b s))"
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    83
| "B(b0 andi b1) = (%s. (B b0 s) & (B b1 s))"
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    84
| "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
    85
37736
2bf3a2cb5e58 replaced manual derivation of equations for inductive predicates by automatic derivation by inductive_simps
bulwahn
parents: 27362
diff changeset
    86
inductive_simps
2bf3a2cb5e58 replaced manual derivation of equations for inductive predicates by automatic derivation by inductive_simps
bulwahn
parents: 27362
diff changeset
    87
  evala_simps [simp]:
2bf3a2cb5e58 replaced manual derivation of equations for inductive predicates by automatic derivation by inductive_simps
bulwahn
parents: 27362
diff changeset
    88
  "(N(n),s) -a-> n'" 
2bf3a2cb5e58 replaced manual derivation of equations for inductive predicates by automatic derivation by inductive_simps
bulwahn
parents: 27362
diff changeset
    89
  "(X(x),sigma) -a-> i"
2bf3a2cb5e58 replaced manual derivation of equations for inductive predicates by automatic derivation by inductive_simps
bulwahn
parents: 27362
diff changeset
    90
  "(Op1 f e,sigma) -a-> i"
2bf3a2cb5e58 replaced manual derivation of equations for inductive predicates by automatic derivation by inductive_simps
bulwahn
parents: 27362
diff changeset
    91
  "(Op2 f a1 a2,sigma) -a-> i"
2bf3a2cb5e58 replaced manual derivation of equations for inductive predicates by automatic derivation by inductive_simps
bulwahn
parents: 27362
diff changeset
    92
  "((true,sigma) -b-> w)"
2bf3a2cb5e58 replaced manual derivation of equations for inductive predicates by automatic derivation by inductive_simps
bulwahn
parents: 27362
diff changeset
    93
  "((false,sigma) -b-> w)"
2bf3a2cb5e58 replaced manual derivation of equations for inductive predicates by automatic derivation by inductive_simps
bulwahn
parents: 27362
diff changeset
    94
  "((ROp f a0 a1,sigma) -b-> w)"
2bf3a2cb5e58 replaced manual derivation of equations for inductive predicates by automatic derivation by inductive_simps
bulwahn
parents: 27362
diff changeset
    95
  "((noti(b),sigma) -b-> w)"
2bf3a2cb5e58 replaced manual derivation of equations for inductive predicates by automatic derivation by inductive_simps
bulwahn
parents: 27362
diff changeset
    96
  "((b0 andi b1,sigma) -b-> w)"
2bf3a2cb5e58 replaced manual derivation of equations for inductive predicates by automatic derivation by inductive_simps
bulwahn
parents: 27362
diff changeset
    97
  "((b0 ori b1,sigma) -b-> w)"
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    98
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
    99
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   100
lemma aexp_iff: "((a,s) -a-> n) = (A a s = n)"
20503
503ac4c5ef91 induct method: renamed 'fixing' to 'arbitrary';
wenzelm
parents: 18372
diff changeset
   101
  by (induct a arbitrary: n) auto
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
   102
12546
wenzelm
parents: 12431
diff changeset
   103
lemma bexp_iff:
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   104
  "((b,s) -b-> w) = (B b s = w)"
20503
503ac4c5ef91 induct method: renamed 'fixing' to 'arbitrary';
wenzelm
parents: 18372
diff changeset
   105
  by (induct b arbitrary: w) (auto simp add: aexp_iff)
12431
07ec657249e5 converted to Isar
kleing
parents: 12338
diff changeset
   106
1697
687f0710c22d Arithemtic and boolean expressions are now in a separate theory.
nipkow
parents:
diff changeset
   107
end