src/HOL/Induct/Com.thy
changeset 10759 994877ee68cb
parent 5184 9b8547a9496a
child 11464 ddea204de5bc
equal deleted inserted replaced
10758:9d766f21cf41 10759:994877ee68cb
     4     Copyright   1997  University of Cambridge
     4     Copyright   1997  University of Cambridge
     5 
     5 
     6 Example of Mutual Induction via Iteratived Inductive Definitions: Commands
     6 Example of Mutual Induction via Iteratived Inductive Definitions: Commands
     7 *)
     7 *)
     8 
     8 
     9 Com = Datatype +
     9 Com = Main +
    10 
    10 
    11 types loc
    11 types loc
    12       state = "loc => nat"
    12       state = "loc => nat"
    13       n2n2n = "nat => nat => nat"
    13       n2n2n = "nat => nat => nat"
    14 
    14 
    15 arities loc :: term
    15 arities loc :: term
    16 
    16 
    17 (*To avoid a mutually recursive datatype declaration, expressions and commands
       
    18   are combined to form a single datatype.*)
       
    19 datatype
    17 datatype
    20   exp = N nat
    18   exp = N nat
    21       | X loc
    19       | X loc
    22       | Op n2n2n exp exp
    20       | Op n2n2n exp exp
    23       | valOf exp exp          ("VALOF _ RESULTIS _"  60)
    21       | valOf com exp          ("VALOF _ RESULTIS _"  60)
    24       | SKIP
    22 and
       
    23   com = SKIP
    25       | ":="  loc exp          (infixl  60)
    24       | ":="  loc exp          (infixl  60)
    26       | Semi  exp exp          ("_;;_"  [60, 60] 60)
    25       | Semi  com com          ("_;;_"  [60, 60] 60)
    27       | Cond  exp exp exp      ("IF _ THEN _ ELSE _"  60)
    26       | Cond  exp com com      ("IF _ THEN _ ELSE _"  60)
    28       | While exp exp          ("WHILE _ DO _"  60)
    27       | While exp com          ("WHILE _ DO _"  60)
    29 
    28 
    30 (** Execution of commands **)
    29 (** Execution of commands **)
    31 consts  exec    :: "((exp*state) * (nat*state)) set => ((exp*state)*state)set"
    30 consts  exec    :: "((exp*state) * (nat*state)) set => ((com*state)*state)set"
    32        "@exec"  :: "((exp*state) * (nat*state)) set => 
    31        "@exec"  :: "((exp*state) * (nat*state)) set => 
    33                     [exp*state,state] => bool"     ("_/ -[_]-> _" [50,0,50] 50)
    32                     [com*state,state] => bool"     ("_/ -[_]-> _" [50,0,50] 50)
    34 
    33 
    35 translations  "csig -[eval]-> s" == "(csig,s) : exec eval"
    34 translations  "csig -[eval]-> s" == "(csig,s) : exec eval"
    36 
    35 
    37 syntax  eval'   :: "[exp*state,nat*state] => 
    36 syntax  eval'   :: "[exp*state,nat*state] => 
    38 		    ((exp*state) * (nat*state)) set => bool"
    37 		    ((exp*state) * (nat*state)) set => bool"
    39 						   ("_/ -|[_]-> _" [50,0,50] 50)
    38 						   ("_/ -|[_]-> _" [50,0,50] 50)
    40 translations
    39 translations
    41     "esig -|[eval]-> ns" => "(esig,ns) : eval"
    40     "esig -|[eval]-> ns" => "(esig,ns) : eval"
    42 
    41 
    43 constdefs assign :: [state,nat,loc] => state    ("_[_'/_]" [95,0,0] 95)
       
    44   "s[m/x] ==  (%y. if y=x then m else s y)"
       
    45 
       
    46 
       
    47 (*Command execution.  Natural numbers represent Booleans: 0=True, 1=False*)
    42 (*Command execution.  Natural numbers represent Booleans: 0=True, 1=False*)
    48 inductive "exec eval"
    43 inductive "exec eval"
    49   intrs
    44   intrs
    50     Skip    "(SKIP,s) -[eval]-> s"
    45     Skip    "(SKIP,s) -[eval]-> s"
    51 
    46 
    52     Assign  "(e,s) -|[eval]-> (v,s') ==> (x := e, s) -[eval]-> s'[v/x]"
    47     Assign  "(e,s) -|[eval]-> (v,s') ==> (x := e, s) -[eval]-> s'(x:=v)"
    53 
    48 
    54     Semi    "[| (c0,s) -[eval]-> s2; (c1,s2) -[eval]-> s1 |] 
    49     Semi    "[| (c0,s) -[eval]-> s2; (c1,s2) -[eval]-> s1 |] 
    55             ==> (c0 ;; c1, s) -[eval]-> s1"
    50             ==> (c0 ;; c1, s) -[eval]-> s1"
    56 
    51 
    57     IfTrue "[| (e,s) -|[eval]-> (0,s');  (c0,s') -[eval]-> s1 |] 
    52     IfTrue "[| (e,s) -|[eval]-> (0,s');  (c0,s') -[eval]-> s1 |] 
    63     WhileFalse "(e,s) -|[eval]-> (1,s1) ==> (WHILE e DO c, s) -[eval]-> s1"
    58     WhileFalse "(e,s) -|[eval]-> (1,s1) ==> (WHILE e DO c, s) -[eval]-> s1"
    64 
    59 
    65     WhileTrue  "[| (e,s) -|[eval]-> (0,s1);
    60     WhileTrue  "[| (e,s) -|[eval]-> (0,s1);
    66                 (c,s1) -[eval]-> s2;  (WHILE e DO c, s2) -[eval]-> s3 |] 
    61                 (c,s1) -[eval]-> s2;  (WHILE e DO c, s2) -[eval]-> s3 |] 
    67                 ==> (WHILE e DO c, s) -[eval]-> s3"
    62                 ==> (WHILE e DO c, s) -[eval]-> s3"
    68 
       
    69 constdefs
       
    70     Unique   :: "['a, 'b, ('a*'b) set] => bool"
       
    71     "Unique x y r == ALL y'. (x,y'): r --> y = y'"
       
    72 
       
    73     Function :: "('a*'b) set => bool"
       
    74     "Function r == ALL x y. (x,y): r --> Unique x y r"
       
    75 end
    63 end