src/HOL/IMP/Expr.thy
author nipkow
Sat Apr 27 18:49:21 1996 +0200 (1996-04-27)
changeset 1697 687f0710c22d
child 1729 e4f8682eea2e
permissions -rw-r--r--
Arithemtic and boolean expressions are now in a separate theory.
The commands don not use them directly. Instead they are based on
the semantics (rather than the syntax) of expressions.
nipkow@1697
     1
(*  Title:      HOL/IMP/Expr.thy
nipkow@1697
     2
    ID:         $Id$
nipkow@1697
     3
    Author:     Heiko Loetzbeyer & Robert Sandner & Tobias Nipkow, TUM
nipkow@1697
     4
    Copyright   1994 TUM
nipkow@1697
     5
nipkow@1697
     6
Arithmetic expressions and Boolean expressions.
nipkow@1697
     7
Not used in the rest of the language, but included for completeness.
nipkow@1697
     8
*)
nipkow@1697
     9
nipkow@1697
    10
Expr = Arith +
nipkow@1697
    11
nipkow@1697
    12
(** Arithmetic expressions **)
nipkow@1697
    13
types loc
nipkow@1697
    14
      state = "loc => nat"
nipkow@1697
    15
      n2n = "nat => nat"
nipkow@1697
    16
      n2n2n = "nat => nat => nat"
nipkow@1697
    17
nipkow@1697
    18
arities loc :: term
nipkow@1697
    19
nipkow@1697
    20
datatype
nipkow@1697
    21
  aexp = N nat
nipkow@1697
    22
       | X loc
nipkow@1697
    23
       | Op1 n2n aexp
nipkow@1697
    24
       | Op2 n2n2n aexp aexp
nipkow@1697
    25
nipkow@1697
    26
(** Evaluation of arithmetic expressions **)
nipkow@1697
    27
consts  evala    :: "(aexp*state*nat)set"
nipkow@1697
    28
       "@evala"  :: [aexp,state,nat] => bool ("<_,_>/ -a-> _"  [0,0,50] 50)
nipkow@1697
    29
translations
nipkow@1697
    30
    "<ae,sig> -a-> n" == "(ae,sig,n) : evala"
nipkow@1697
    31
inductive "evala"
nipkow@1697
    32
  intrs 
nipkow@1697
    33
    N   "<N(n),s> -a-> n"
nipkow@1697
    34
    X   "<X(x),s> -a-> s(x)"
nipkow@1697
    35
    Op1 "<e,s> -a-> n ==> <Op1 f e,s> -a-> f(n)"
nipkow@1697
    36
    Op2 "[| <e0,s> -a-> n0;  <e1,s>  -a-> n1 |] 
nipkow@1697
    37
           ==> <Op2 f e0 e1,s> -a-> f n0 n1"
nipkow@1697
    38
nipkow@1697
    39
types n2n2b = "[nat,nat] => bool"
nipkow@1697
    40
nipkow@1697
    41
(** Boolean expressions **)
nipkow@1697
    42
nipkow@1697
    43
datatype
nipkow@1697
    44
  bexp = true
nipkow@1697
    45
       | false
nipkow@1697
    46
       | ROp  n2n2b aexp aexp
nipkow@1697
    47
       | noti bexp
nipkow@1697
    48
       | andi bexp bexp         (infixl 60)
nipkow@1697
    49
       | ori  bexp bexp         (infixl 60)
nipkow@1697
    50
nipkow@1697
    51
(** Evaluation of boolean expressions **)
nipkow@1697
    52
consts evalb    :: "(bexp*state*bool)set"       
nipkow@1697
    53
       "@evalb" :: [bexp,state,bool] => bool ("<_,_>/ -b-> _"  [0,0,50] 50)
nipkow@1697
    54
nipkow@1697
    55
translations
nipkow@1697
    56
    "<be,sig> -b-> b" == "(be,sig,b) : evalb"
nipkow@1697
    57
nipkow@1697
    58
inductive "evalb"
nipkow@1697
    59
 intrs (*avoid clash with ML constructors true, false*)
nipkow@1697
    60
    tru   "<true,s> -b-> True"
nipkow@1697
    61
    fls   "<false,s> -b-> False"
nipkow@1697
    62
    ROp   "[| <a0,s> -a-> n0; <a1,s> -a-> n1 |] 
nipkow@1697
    63
           ==> <ROp f a0 a1,s> -b-> f n0 n1"
nipkow@1697
    64
    noti  "<b,s> -b-> w ==> <noti(b),s> -b-> (~w)"
nipkow@1697
    65
    andi  "[| <b0,s> -b-> w0; <b1,s> -b-> w1 |] 
nipkow@1697
    66
          ==> <b0 andi b1,s> -b-> (w0 & w1)"
nipkow@1697
    67
    ori   "[| <b0,s> -b-> w0; <b1,s> -b-> w1 |] 
nipkow@1697
    68
            ==> <b0 ori b1,s> -b-> (w0 | w1)"
nipkow@1697
    69
nipkow@1697
    70
(** Denotational semantics of arithemtic and boolean expressions **)
nipkow@1697
    71
consts
nipkow@1697
    72
  A     :: aexp => state => nat
nipkow@1697
    73
  B     :: bexp => state => bool
nipkow@1697
    74
nipkow@1697
    75
primrec A aexp
nipkow@1697
    76
  A_nat "A(N(n)) = (%s. n)"
nipkow@1697
    77
  A_loc "A(X(x)) = (%s. s(x))" 
nipkow@1697
    78
  A_op1 "A(Op1 f a) = (%s. f(A a s))"
nipkow@1697
    79
  A_op2 "A(Op2 f a0 a1) = (%s. f (A a0 s) (A a1 s))"
nipkow@1697
    80
nipkow@1697
    81
primrec B bexp
nipkow@1697
    82
  B_true  "B(true) = (%s. True)"
nipkow@1697
    83
  B_false "B(false) = (%s. False)"
nipkow@1697
    84
  B_op    "B(ROp f a0 a1) = (%s. f (A a0 s) (A a1 s))" 
nipkow@1697
    85
  B_not   "B(noti(b)) = (%s. ~(B b s))"
nipkow@1697
    86
  B_and   "B(b0 andi b1) = (%s. (B b0 s) & (B b1 s))"
nipkow@1697
    87
  B_or    "B(b0 ori b1) = (%s. (B b0 s) | (B b1 s))"
nipkow@1697
    88
nipkow@1697
    89
end