src/ZF/IMP/Com.thy
author lcp
Mon, 24 Oct 1994 10:34:28 +0100
changeset 653 6eeff82979df
parent 518 4530c45370b4
child 658 368aa02631d8
permissions -rw-r--r--
HOL,ZF/IMP/Com.thy: tightening precedences to eliminate syntactic ambiguities. constructor ";" now yields a low precedence; the reduction relations are now more like infixes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
482
3a4e092ba69c Initial revision
nipkow
parents:
diff changeset
     1
(*  Title: 	ZF/IMP/Com.thy
3a4e092ba69c Initial revision
nipkow
parents:
diff changeset
     2
    ID:         $Id$
3a4e092ba69c Initial revision
nipkow
parents:
diff changeset
     3
    Author: 	Heiko Loetzbeyer & Robert Sandner, TUM
3a4e092ba69c Initial revision
nipkow
parents:
diff changeset
     4
    Copyright   1994 TUM
3a4e092ba69c Initial revision
nipkow
parents:
diff changeset
     5
511
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
     6
Arithmetic expressions, Boolean expressions, Commands
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
     7
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
     8
And their Operational semantics
482
3a4e092ba69c Initial revision
nipkow
parents:
diff changeset
     9
*)
3a4e092ba69c Initial revision
nipkow
parents:
diff changeset
    10
511
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    11
Com = Univ + "Datatype" +
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    12
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    13
(** Arithmetic expressions **)
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    14
consts  loc  :: "i"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    15
        aexp :: "i"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    16
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    17
datatype <= "univ(loc Un (nat->nat) Un ((nat*nat) -> nat) )"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    18
  "aexp" = N ("n: nat")
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    19
         | X ("x: loc")
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    20
         | Op1 ("f: nat -> nat", "a : aexp")
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    21
         | Op2 ("f: (nat*nat) -> nat", "a0 : aexp", "a1 : aexp")
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    22
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    23
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    24
(** Evaluation of arithmetic expressions **)
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    25
consts  evala    :: "i"
653
6eeff82979df HOL,ZF/IMP/Com.thy: tightening precedences to eliminate syntactic ambiguities.
lcp
parents: 518
diff changeset
    26
       "@evala"  :: "[i,i,i] => o"		("<_,_>/ -a-> _"  [0,0,50] 50)
511
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    27
translations
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    28
    "<ae,sig> -a-> n" == "<ae,sig,n> : evala"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    29
inductive
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    30
  domains "evala" <= "aexp * (loc -> nat) * nat"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    31
  intrs 
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    32
    N   "[| n:nat ; sigma:loc->nat |] ==> <N(n),sigma> -a-> n"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    33
    X  	"[| x:loc;  sigma:loc->nat |] ==> <X(x),sigma> -a-> sigma`x"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    34
    Op1 "[| <e,sigma> -a-> n;  f: nat -> nat |] ==> <Op1(f,e),sigma> -a-> f`n"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    35
    Op2 "[| <e0,sigma> -a-> n0;  <e1,sigma>  -a-> n1; f: (nat*nat) -> nat |] \
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    36
\           ==> <Op2(f,e0,e1),sigma> -a-> f`<n0,n1>"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    37
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    38
  type_intrs "aexp.intrs@[apply_funtype]"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    39
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    40
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    41
(** Boolean expressions **)
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    42
consts  bexp :: "i"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    43
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    44
datatype <= "univ(aexp Un ((nat*nat)->bool) )"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    45
  "bexp" = true
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    46
         | false
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    47
         | ROp  ("f: (nat*nat)->bool", "a0 : aexp", "a1 : aexp")
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    48
         | noti ("b : bexp")
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    49
         | andi ("b0 : bexp", "b1 : bexp")	(infixl 60)
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    50
         | ori  ("b0 : bexp", "b1 : bexp")	(infixl 60)
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    51
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    52
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    53
(** Evaluation of boolean expressions **)
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    54
consts evalb	:: "i"	
653
6eeff82979df HOL,ZF/IMP/Com.thy: tightening precedences to eliminate syntactic ambiguities.
lcp
parents: 518
diff changeset
    55
       "@evalb" :: "[i,i,i] => o"		("<_,_>/ -b-> _" [0,0,50] 50)
511
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    56
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    57
translations
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    58
    "<be,sig> -b-> b" == "<be,sig,b> : evalb"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    59
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    60
inductive
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    61
  domains "evalb" <= "bexp * (loc -> nat) * bool"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    62
  intrs (*avoid clash with ML constructors true, false*)
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    63
    tru   "[| sigma:loc -> nat |] ==> <true,sigma> -b-> 1"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    64
    fls   "[| sigma:loc -> nat |] ==> <false,sigma> -b-> 0"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    65
    ROp   "[| <a0,sigma> -a-> n0; <a1,sigma> -a-> n1; f: (nat*nat)->bool |] \
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    66
\	   ==> <ROp(f,a0,a1),sigma> -b-> f`<n0,n1> "
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    67
    noti  "[| <b,sigma> -b-> w |] ==> <noti(b),sigma> -b-> not(w)"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    68
    andi  "[| <b0,sigma> -b-> w0; <b1,sigma> -b-> w1 |] \
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    69
\          ==> <b0 andi b1,sigma> -b-> (w0 and w1)"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    70
    ori   "[| <b0,sigma> -b-> w0; <b1,sigma> -b-> w1 |] \
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    71
\	    ==> <b0 ori b1,sigma> -b-> (w0 or w1)"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    72
514
ab2c867829ec addition of string escapes
lcp
parents: 511
diff changeset
    73
  type_intrs "bexp.intrs @   \
ab2c867829ec addition of string escapes
lcp
parents: 511
diff changeset
    74
\	      [apply_funtype, and_type, or_type, bool_1I, bool_0I, not_type]"
511
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    75
  type_elims "[make_elim(evala.dom_subset RS subsetD)]"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    76
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    77
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    78
(** Commands **)
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    79
consts  com :: "i"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    80
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    81
datatype <= "univ(loc Un aexp Un bexp)"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    82
  "com" = skip
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    83
        | ":="  ("x:loc", "a:aexp")		(infixl 60)
653
6eeff82979df HOL,ZF/IMP/Com.thy: tightening precedences to eliminate syntactic ambiguities.
lcp
parents: 518
diff changeset
    84
        | semic ("c0:com", "c1:com")		("_; _"  [60, 60] 10)
6eeff82979df HOL,ZF/IMP/Com.thy: tightening precedences to eliminate syntactic ambiguities.
lcp
parents: 518
diff changeset
    85
	| while ("b:bexp", "c:com")		("while _ do _"  60)
6eeff82979df HOL,ZF/IMP/Com.thy: tightening precedences to eliminate syntactic ambiguities.
lcp
parents: 518
diff changeset
    86
	| ifc   ("b:bexp", "c0:com", "c1:com")	("ifc _ then _ else _"  60)
511
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    87
  type_intrs "aexp.intrs"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    88
653
6eeff82979df HOL,ZF/IMP/Com.thy: tightening precedences to eliminate syntactic ambiguities.
lcp
parents: 518
diff changeset
    89
(*Constructor ";" has low precedence to avoid syntactic ambiguities
6eeff82979df HOL,ZF/IMP/Com.thy: tightening precedences to eliminate syntactic ambiguities.
lcp
parents: 518
diff changeset
    90
  with [| m: nat; x: loc; ... |] ==> ...  It usually will need parentheses.*)
511
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    91
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    92
(** Execution of commands **)
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    93
consts  evalc    :: "i"
653
6eeff82979df HOL,ZF/IMP/Com.thy: tightening precedences to eliminate syntactic ambiguities.
lcp
parents: 518
diff changeset
    94
        "@evalc" :: "[i,i,i] => o"   		("<_,_>/ -c-> _" [0,0,50] 50)
6eeff82979df HOL,ZF/IMP/Com.thy: tightening precedences to eliminate syntactic ambiguities.
lcp
parents: 518
diff changeset
    95
	"assign" :: "[i,i,i] => i"   		("_[_'/_]"       [95,0,0] 95)
511
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    96
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    97
translations
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    98
       "<ce,sig> -c-> s" == "<ce,sig,s> : evalc"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
    99
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   100
rules 
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   101
	assign_def	"sigma[m/x] == lam y:loc. if(y=x,m,sigma`y)"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   102
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   103
inductive
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   104
  domains "evalc" <= "com * (loc -> nat) * (loc -> nat)"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   105
  intrs
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   106
    skip    "[| sigma: loc -> nat |] ==> <skip,sigma> -c-> sigma"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   107
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   108
    assign  "[| m: nat; x: loc; <a,sigma> -a-> m |] ==> \
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   109
\            <x := a,sigma> -c-> sigma[m/x]"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   110
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   111
    semi    "[| <c0,sigma> -c-> sigma2; <c1,sigma2> -c-> sigma1 |] ==> \
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   112
\            <c0 ; c1, sigma> -c-> sigma1"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   113
518
4530c45370b4 Proof beautification
nipkow
parents: 514
diff changeset
   114
    ifc1     "[| b:bexp; c1:com; sigma:loc->nat;   \
4530c45370b4 Proof beautification
nipkow
parents: 514
diff changeset
   115
\		 <b,sigma> -b-> 1; <c0,sigma> -c-> sigma1 |] ==> \
511
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   116
\             <ifc b then c0 else c1, sigma> -c-> sigma1"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   117
518
4530c45370b4 Proof beautification
nipkow
parents: 514
diff changeset
   118
    ifc0     "[| b:bexp; c0:com; sigma:loc->nat;   \
4530c45370b4 Proof beautification
nipkow
parents: 514
diff changeset
   119
\		 <b,sigma> -b-> 0; <c1,sigma> -c-> sigma1 |] ==> \
511
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   120
\             <ifc b then c0 else c1, sigma> -c-> sigma1"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   121
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   122
    while0   "[| c: com; <b, sigma> -b-> 0 |] ==> \
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   123
\             <while b do c,sigma> -c-> sigma "
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   124
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   125
    while1   "[| c : com; <b,sigma> -b-> 1; <c,sigma> -c-> sigma2; \
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   126
\                <while b do c, sigma2> -c-> sigma1 |] ==> \
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   127
\             <while b do c, sigma> -c-> sigma1 "
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   128
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   129
  con_defs   "[assign_def]"
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   130
  type_intrs "bexp.intrs @ com.intrs @ [if_type,lam_type,apply_type]"
514
ab2c867829ec addition of string escapes
lcp
parents: 511
diff changeset
   131
  type_elims "[make_elim(evala.dom_subset RS subsetD),   \
ab2c867829ec addition of string escapes
lcp
parents: 511
diff changeset
   132
\	      make_elim(evalb.dom_subset RS subsetD) ]"
511
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   133
b2be4790da7a re-organized using new theory sections
lcp
parents: 482
diff changeset
   134
end