src/HOL/IMP/Denotation.thy
author paulson
Sun, 15 Feb 2004 10:46:37 +0100
changeset 14387 e96d5c42c4b0
parent 12434 ff2efde4574d
child 15481 fc075ae929e4
permissions -rw-r--r--
Polymorphic treatment of binary arithmetic using axclasses
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1476
608483c2122a expanded tabs; incorporated Konrad's changes
clasohm
parents: 1374
diff changeset
     1
(*  Title:      HOL/IMP/Denotation.thy
924
806721cfbf46 new version of HOL/IMP with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1476
608483c2122a expanded tabs; incorporated Konrad's changes
clasohm
parents: 1374
diff changeset
     3
    Author:     Heiko Loetzbeyer & Robert Sandner, TUM
924
806721cfbf46 new version of HOL/IMP with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1994 TUM
806721cfbf46 new version of HOL/IMP with curried function application
clasohm
parents:
diff changeset
     5
*)
806721cfbf46 new version of HOL/IMP with curried function application
clasohm
parents:
diff changeset
     6
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
     7
header "Denotational Semantics of Commands"
924
806721cfbf46 new version of HOL/IMP with curried function application
clasohm
parents:
diff changeset
     8
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
     9
theory Denotation = Natural:
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    10
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    11
types com_den = "(state\<times>state)set"
1696
e84bff5c519b A completely new version of IMP.
nipkow
parents: 1481
diff changeset
    12
e84bff5c519b A completely new version of IMP.
nipkow
parents: 1481
diff changeset
    13
constdefs
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    14
  Gamma :: "[bexp,com_den] => (com_den => com_den)"
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    15
  "Gamma b cd == (\<lambda>phi. {(s,t). (s,t) \<in> (phi O cd) \<and> b s} \<union> 
12434
kleing
parents: 12431
diff changeset
    16
                       {(s,t). s=t \<and> \<not>b s})"
1696
e84bff5c519b A completely new version of IMP.
nipkow
parents: 1481
diff changeset
    17
    
e84bff5c519b A completely new version of IMP.
nipkow
parents: 1481
diff changeset
    18
consts
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    19
  C :: "com => com_den"
924
806721cfbf46 new version of HOL/IMP with curried function application
clasohm
parents:
diff changeset
    20
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 4897
diff changeset
    21
primrec
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    22
  C_skip:   "C \<SKIP>   = Id"
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    23
  C_assign: "C (x :== a) = {(s,t). t = s[x\<mapsto>a(s)]}"
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    24
  C_comp:   "C (c0;c1)   = C(c1) O C(c0)"
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    25
  C_if:     "C (\<IF> b \<THEN> c1 \<ELSE> c2) = {(s,t). (s,t) \<in> C c1 \<and> b s} \<union>
12434
kleing
parents: 12431
diff changeset
    26
                                                {(s,t). (s,t) \<in> C c2 \<and> \<not>b s}"
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    27
  C_while:  "C(\<WHILE> b \<DO> c) = lfp (Gamma b (C c))"
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    28
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    29
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    30
(**** mono (Gamma(b,c)) ****)
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    31
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    32
lemma Gamma_mono: "mono (Gamma b c)"
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    33
  by (unfold Gamma_def mono_def) fast
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    34
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    35
lemma C_While_If: "C(\<WHILE> b \<DO> c) = C(\<IF> b \<THEN> c;\<WHILE> b \<DO> c \<ELSE> \<SKIP>)"
12434
kleing
parents: 12431
diff changeset
    36
apply (simp (no_asm)) 
kleing
parents: 12431
diff changeset
    37
apply (subst lfp_unfold [OF Gamma_mono]) back back
kleing
parents: 12431
diff changeset
    38
apply (subst Gamma_def [THEN meta_eq_to_obj_eq, THEN fun_cong]) 
kleing
parents: 12431
diff changeset
    39
apply simp
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    40
done
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    41
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    42
(* Operational Semantics implies Denotational Semantics *)
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    43
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    44
lemma com1: "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c t \<Longrightarrow> (s,t) \<in> C(c)"
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    45
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    46
(* start with rule induction *)
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    47
apply (erule evalc.induct)
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    48
apply auto
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    49
(* while *)
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    50
apply (unfold Gamma_def)
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    51
apply (subst lfp_unfold[OF Gamma_mono, simplified Gamma_def])
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    52
apply fast
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    53
apply (subst lfp_unfold[OF Gamma_mono, simplified Gamma_def])
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    54
apply fast
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    55
done
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    56
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    57
(* Denotational Semantics implies Operational Semantics *)
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    58
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    59
lemma com2 [rule_format]: "\<forall>s t. (s,t)\<in>C(c) \<longrightarrow> \<langle>c,s\<rangle> \<longrightarrow>\<^sub>c t"
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    60
apply (induct_tac "c")
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    61
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    62
apply (simp_all (no_asm_use))
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    63
apply fast
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    64
apply fast
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    65
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    66
(* while *)
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    67
apply (intro strip)
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    68
apply (erule lfp_induct [OF _ Gamma_mono])
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    69
apply (unfold Gamma_def)
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    70
apply fast
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    71
done
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    72
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    73
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    74
(**** Proof of Equivalence ****)
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    75
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    76
lemma denotational_is_natural: "(s,t) \<in> C(c)  =  (\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c t)"
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    77
apply (fast elim: com2 dest: com1)
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    78
done
924
806721cfbf46 new version of HOL/IMP with curried function application
clasohm
parents:
diff changeset
    79
806721cfbf46 new version of HOL/IMP with curried function application
clasohm
parents:
diff changeset
    80
end