src/HOL/IMPP/Com.thy
author wenzelm
Sun, 30 Jan 2011 13:02:18 +0100
changeset 41648 6d736d983d5c
parent 41589 bbd861837ebc
child 42174 d0be2722ce9f
permissions -rw-r--r--
clarified example settings for Proof General;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     1
(*  Title:    HOL/IMPP/Com.thy
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     2
    Author:   David von Oheimb (based on a theory by Tobias Nipkow et al), TUM
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     3
*)
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     4
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
     5
header {* Semantics of arithmetic and boolean expressions, Syntax of commands *}
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     6
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
     7
theory Com
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
     8
imports Main
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
     9
begin
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    10
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    11
types    val = nat   (* for the meta theory, this may be anything, but with
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    12
                        current Isabelle, types cannot be refined later *)
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    13
typedecl glb
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    14
typedecl loc
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    15
27362
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    16
axiomatization
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    17
  Arg :: loc and
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    18
  Res :: loc
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    19
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    20
datatype vname  = Glb glb | Loc loc
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    21
types    globs  = "glb => val"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    22
         locals = "loc => val"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    23
datatype state  = st globs locals
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    24
(* for the meta theory, the following would be sufficient:
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    25
typedecl state
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    26
consts   st :: "[globs , locals] => state"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    27
*)
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    28
types    aexp   = "state => val"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    29
         bexp   = "state => bool"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    30
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    31
typedecl pname
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    32
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    33
datatype com
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    34
      = SKIP
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    35
      | Ass   vname aexp        ("_:==_"                [65, 65    ] 60)
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    36
      | Local loc aexp com      ("LOCAL _:=_ IN _"      [65,  0, 61] 60)
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    37
      | Semi  com  com          ("_;; _"                [59, 60    ] 59)
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    38
      | Cond  bexp com com      ("IF _ THEN _ ELSE _"   [65, 60, 61] 60)
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    39
      | While bexp com          ("WHILE _ DO _"         [65,     61] 60)
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    40
      | BODY  pname
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    41
      | Call  vname pname aexp  ("_:=CALL _'(_')"       [65, 65,  0] 60)
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    42
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    43
consts bodies :: "(pname  *  com) list"(* finitely many procedure definitions *)
27362
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    44
definition
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    45
  body :: " pname ~=> com" where
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    46
  "body = map_of bodies"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    47
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    48
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    49
(* Well-typedness: all procedures called must exist *)
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    50
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    51
inductive WT  :: "com => bool" where
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    52
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    53
    Skip:    "WT SKIP"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    54
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    55
  | Assign:  "WT (X :== a)"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    56
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    57
  | Local:   "WT c ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    58
              WT (LOCAL Y := a IN c)"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    59
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    60
  | Semi:    "[| WT c0; WT c1 |] ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    61
              WT (c0;; c1)"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    62
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    63
  | If:      "[| WT c0; WT c1 |] ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    64
              WT (IF b THEN c0 ELSE c1)"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    65
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    66
  | While:   "WT c ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    67
              WT (WHILE b DO c)"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    68
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    69
  | Body:    "body pn ~= None ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    70
              WT (BODY pn)"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    71
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    72
  | Call:    "WT (BODY pn) ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    73
              WT (X:=CALL pn(a))"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    74
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    75
inductive_cases WTs_elim_cases:
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    76
  "WT SKIP"  "WT (X:==a)"  "WT (LOCAL Y:=a IN c)"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    77
  "WT (c1;;c2)"  "WT (IF b THEN c1 ELSE c2)"  "WT (WHILE b DO c)"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    78
  "WT (BODY P)"  "WT (X:=CALL P(a))"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    79
27362
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    80
definition
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    81
  WT_bodies :: bool where
a6dc1769fdda modernized specifications;
wenzelm
parents: 23746
diff changeset
    82
  "WT_bodies = (!(pn,b):set bodies. WT b)"
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 12338
diff changeset
    83
19803
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    84
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    85
ML {* val make_imp_tac = EVERY'[rtac mp, fn i => atac (i+1), etac thin_rl] *}
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    86
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    87
lemma finite_dom_body: "finite (dom body)"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    88
apply (unfold body_def)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    89
apply (rule finite_dom_map_of)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    90
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    91
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    92
lemma WT_bodiesD: "[| WT_bodies; body pn = Some b |] ==> WT b"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    93
apply (unfold WT_bodies_def body_def)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    94
apply (drule map_of_SomeD)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    95
apply fast
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    96
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    97
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    98
declare WTs_elim_cases [elim!]
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    99
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
   100
end