src/HOL/Induct/Com.thy
author wenzelm
Fri Oct 05 21:52:39 2001 +0200 (2001-10-05)
changeset 11701 3d51fbf81c17
parent 11464 ddea204de5bc
child 12338 de0f4a63baa5
permissions -rw-r--r--
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
"num" syntax (still with "#"), Numeral0, Numeral1;
paulson@3120
     1
(*  Title:      HOL/Induct/Com
paulson@3120
     2
    ID:         $Id$
paulson@3120
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@3120
     4
    Copyright   1997  University of Cambridge
paulson@3120
     5
paulson@3120
     6
Example of Mutual Induction via Iteratived Inductive Definitions: Commands
paulson@3120
     7
*)
paulson@3120
     8
nipkow@10759
     9
Com = Main +
paulson@3120
    10
paulson@3120
    11
types loc
paulson@3120
    12
      state = "loc => nat"
paulson@3120
    13
      n2n2n = "nat => nat => nat"
paulson@3120
    14
paulson@3120
    15
arities loc :: term
paulson@3120
    16
paulson@3120
    17
datatype
paulson@3120
    18
  exp = N nat
paulson@3120
    19
      | X loc
paulson@3120
    20
      | Op n2n2n exp exp
nipkow@10759
    21
      | valOf com exp          ("VALOF _ RESULTIS _"  60)
nipkow@10759
    22
and
nipkow@10759
    23
  com = SKIP
paulson@3120
    24
      | ":="  loc exp          (infixl  60)
nipkow@10759
    25
      | Semi  com com          ("_;;_"  [60, 60] 60)
nipkow@10759
    26
      | Cond  exp com com      ("IF _ THEN _ ELSE _"  60)
nipkow@10759
    27
      | While exp com          ("WHILE _ DO _"  60)
paulson@3120
    28
paulson@3120
    29
(** Execution of commands **)
nipkow@10759
    30
consts  exec    :: "((exp*state) * (nat*state)) set => ((com*state)*state)set"
paulson@3120
    31
       "@exec"  :: "((exp*state) * (nat*state)) set => 
nipkow@10759
    32
                    [com*state,state] => bool"     ("_/ -[_]-> _" [50,0,50] 50)
paulson@3120
    33
paulson@3120
    34
translations  "csig -[eval]-> s" == "(csig,s) : exec eval"
paulson@3120
    35
oheimb@4264
    36
syntax  eval'   :: "[exp*state,nat*state] => 
oheimb@4264
    37
		    ((exp*state) * (nat*state)) set => bool"
oheimb@4264
    38
						   ("_/ -|[_]-> _" [50,0,50] 50)
oheimb@4264
    39
translations
oheimb@4264
    40
    "esig -|[eval]-> ns" => "(esig,ns) : eval"
oheimb@4264
    41
paulson@3120
    42
(*Command execution.  Natural numbers represent Booleans: 0=True, 1=False*)
paulson@3120
    43
inductive "exec eval"
paulson@3120
    44
  intrs
paulson@3120
    45
    Skip    "(SKIP,s) -[eval]-> s"
paulson@3120
    46
nipkow@10759
    47
    Assign  "(e,s) -|[eval]-> (v,s') ==> (x := e, s) -[eval]-> s'(x:=v)"
paulson@3120
    48
paulson@3120
    49
    Semi    "[| (c0,s) -[eval]-> s2; (c1,s2) -[eval]-> s1 |] 
paulson@3120
    50
            ==> (c0 ;; c1, s) -[eval]-> s1"
paulson@3120
    51
oheimb@4264
    52
    IfTrue "[| (e,s) -|[eval]-> (0,s');  (c0,s') -[eval]-> s1 |] 
paulson@3120
    53
            ==> (IF e THEN c0 ELSE c1, s) -[eval]-> s1"
paulson@3120
    54
wenzelm@11701
    55
    IfFalse "[| (e,s) -|[eval]->  (Suc 0, s');  (c1,s') -[eval]-> s1 |] 
paulson@3120
    56
             ==> (IF e THEN c0 ELSE c1, s) -[eval]-> s1"
paulson@3120
    57
wenzelm@11701
    58
    WhileFalse "(e,s) -|[eval]-> (Suc 0, s1) ==> (WHILE e DO c, s) -[eval]-> s1"
paulson@3120
    59
oheimb@4264
    60
    WhileTrue  "[| (e,s) -|[eval]-> (0,s1);
paulson@3120
    61
                (c,s1) -[eval]-> s2;  (WHILE e DO c, s2) -[eval]-> s3 |] 
paulson@3120
    62
                ==> (WHILE e DO c, s) -[eval]-> s3"
paulson@3120
    63
end