author  nipkow 
Wed, 19 Jun 2013 17:16:45 +0200  
changeset 52396  432777f2e372 
parent 52395  7cc3f42930f3 
child 52401  56e83c57f953 
permissions  rwrr 
43143  1 
(* Authors: Heiko Loetzbeyer, Robert Sandner, Tobias Nipkow *) 
924
806721cfbf46
new version of HOL/IMP with curried function application
clasohm
parents:
diff
changeset

2 

12431  3 
header "Denotational Semantics of Commands" 
924
806721cfbf46
new version of HOL/IMP with curried function application
clasohm
parents:
diff
changeset

4 

52394  5 
theory Denotational imports Big_Step begin 
12431  6 

42174  7 
type_synonym com_den = "(state \<times> state) set" 
1696  8 

52396  9 
definition W :: "(state \<Rightarrow> bool) \<Rightarrow> com_den \<Rightarrow> (com_den \<Rightarrow> com_den)" where 
10 
"W db dc = (\<lambda>dw. {(s,t). if db s then (s,t) \<in> dc O dw else s=t})" 

18372  11 

52389  12 
fun D :: "com \<Rightarrow> com_den" where 
13 
"D SKIP = Id"  

14 
"D (x ::= a) = {(s,t). t = s(x := aval a s)}"  

52395  15 
"D (c1;;c2) = D(c1) O D(c2)"  
52389  16 
"D (IF b THEN c1 ELSE c2) 
17 
= {(s,t). if bval b s then (s,t) \<in> D c1 else (s,t) \<in> D c2}"  

52396  18 
"D (WHILE b DO c) = lfp (W (bval b) (D c))" 
12431  19 

52387  20 
lemma W_mono: "mono (W b r)" 
21 
by (unfold W_def mono_def) auto 

12431  22 

52389  23 
lemma D_While_If: 
24 
"D(WHILE b DO c) = D(IF b THEN c;;WHILE b DO c ELSE SKIP)" 

25 
proof 

52396  26 
let ?w = "WHILE b DO c" let ?f = "W (bval b) (D c)" 
27 
have "D ?w = lfp ?f" by simp 

28 
also have "\<dots> = ?f (lfp ?f)" by(rule lfp_unfold [OF W_mono]) 

52389  29 
also have "\<dots> = D(IF b THEN c;;?w ELSE SKIP)" by (simp add: W_def) 
30 
finally show ?thesis . 

31 
qed 

12431  32 

43144  33 
text{* Equivalence of denotational and bigstep semantics: *} 
12431  34 

52389  35 
lemma D_if_big_step: "(c,s) \<Rightarrow> t \<Longrightarrow> (s,t) \<in> D(c)" 
52387  36 
proof (induction rule: big_step_induct) 
37 
case WhileFalse 

52389  38 
with D_While_If show ?case by auto 
52387  39 
next 
40 
case WhileTrue 

52389  41 
show ?case unfolding D_While_If using WhileTrue by auto 
52387  42 
qed auto 
43 

44 
abbreviation Big_step :: "com \<Rightarrow> com_den" where 

45 
"Big_step c \<equiv> {(s,t). (c,s) \<Rightarrow> t}" 

12431  46 

52389  47 
lemma Big_step_if_D: "(s,t) \<in> D(c) \<Longrightarrow> (s,t) : Big_step c" 
52387  48 
proof (induction c arbitrary: s t) 
49 
case Seq thus ?case by fastforce 

50 
next 

51 
case (While b c) 

52396  52 
let ?B = "Big_step (WHILE b DO c)" let ?f = "W (bval b) (D c)" 
53 
have "?f ?B \<subseteq> ?B" using While.IH by (auto simp: W_def) 

54 
from lfp_lowerbound[where ?f = "?f", OF this] While.prems 

52387  55 
show ?case by auto 
56 
qed (auto split: if_splits) 

12431  57 

52387  58 
theorem denotational_is_big_step: 
52389  59 
"(s,t) \<in> D(c) = ((c,s) \<Rightarrow> t)" 
60 
by (metis D_if_big_step Big_step_if_D[simplified]) 

61 

62 

63 
subsection "Continuity" 

64 

65 
definition chain :: "(nat \<Rightarrow> 'a set) \<Rightarrow> bool" where 

66 
"chain S = (\<forall>i. S i \<subseteq> S(Suc i))" 

67 

68 
lemma chain_total: "chain S \<Longrightarrow> S i \<le> S j \<or> S j \<le> S i" 

69 
by (metis chain_def le_cases lift_Suc_mono_le) 

70 

71 
definition cont :: "('a set \<Rightarrow> 'a set) \<Rightarrow> bool" where 

72 
"cont f = (\<forall>S. chain S \<longrightarrow> f(UN n. S n) = (UN n. f(S n)))" 

73 

74 
lemma mono_if_cont: fixes f :: "'a set \<Rightarrow> 'a set" 

75 
assumes "cont f" shows "mono f" 

76 
proof 

77 
fix a b :: "'a set" assume "a \<subseteq> b" 

78 
let ?S = "\<lambda>n::nat. if n=0 then a else b" 

79 
have "chain ?S" using `a \<subseteq> b` by(auto simp: chain_def) 

52396  80 
hence "f(UN n. ?S n) = (UN n. f(?S n))" 
81 
using assms by(simp add: cont_def) 

52389  82 
moreover have "(UN n. ?S n) = b" using `a \<subseteq> b` by (auto split: if_splits) 
83 
moreover have "(UN n. f(?S n)) = f a \<union> f b" by (auto split: if_splits) 

84 
ultimately show "f a \<subseteq> f b" by (metis Un_upper1) 

85 
qed 

86 

87 
lemma chain_iterates: fixes f :: "'a set \<Rightarrow> 'a set" 

88 
assumes "mono f" shows "chain(\<lambda>n. (f^^n) {})" 

89 
proof 

90 
{ fix n have "(f ^^ n) {} \<subseteq> (f ^^ Suc n) {}" using assms 

91 
by(induction n) (auto simp: mono_def) } 

92 
thus ?thesis by(auto simp: chain_def) 

93 
qed 

94 

95 
theorem lfp_if_cont: 

96 
assumes "cont f" shows "lfp f = (UN n. (f^^n) {})" (is "_ = ?U") 

97 
proof 

98 
show "lfp f \<subseteq> ?U" 

99 
proof (rule lfp_lowerbound) 

100 
have "f ?U = (UN n. (f^^Suc n){})" 

101 
using chain_iterates[OF mono_if_cont[OF assms]] assms 

102 
by(simp add: cont_def) 

103 
also have "\<dots> = (f^^0){} \<union> \<dots>" by simp 

104 
also have "\<dots> = ?U" 

105 
by(auto simp del: funpow.simps) (metis not0_implies_Suc) 

106 
finally show "f ?U \<subseteq> ?U" by simp 

107 
qed 

108 
next 

109 
{ fix n p assume "f p \<subseteq> p" 

110 
have "(f^^n){} \<subseteq> p" 

111 
proof(induction n) 

112 
case 0 show ?case by simp 

113 
next 

114 
case Suc 

115 
from monoD[OF mono_if_cont[OF assms] Suc] `f p \<subseteq> p` 

116 
show ?case by simp 

117 
qed 

118 
} 

119 
thus "?U \<subseteq> lfp f" by(auto simp: lfp_def) 

120 
qed 

121 

122 
lemma cont_W: "cont(W b r)" 

123 
by(auto simp: cont_def W_def) 

124 

52392  125 

52389  126 
subsection{*The denotational semantics is deterministic*} 
127 

128 
lemma single_valued_UN_chain: 

129 
assumes "chain S" "(\<And>n. single_valued (S n))" 

130 
shows "single_valued(UN n. S n)" 

131 
proof(auto simp: single_valued_def) 

132 
fix m n x y z assume "(x, y) \<in> S m" "(x, z) \<in> S n" 

133 
with chain_total[OF assms(1), of m n] assms(2) 

134 
show "y = z" by (auto simp: single_valued_def) 

135 
qed 

136 

137 
lemma single_valued_lfp: fixes f :: "com_den \<Rightarrow> com_den" 

138 
assumes "cont f" "\<And>r. single_valued r \<Longrightarrow> single_valued (f r)" 

139 
shows "single_valued(lfp f)" 

140 
unfolding lfp_if_cont[OF assms(1)] 

141 
proof(rule single_valued_UN_chain[OF chain_iterates[OF mono_if_cont[OF assms(1)]]]) 

142 
fix n show "single_valued ((f ^^ n) {})" 

143 
by(induction n)(auto simp: assms(2)) 

144 
qed 

145 

146 
lemma single_valued_D: "single_valued (D c)" 

147 
proof(induction c) 

148 
case Seq thus ?case by(simp add: single_valued_relcomp) 

149 
next 

150 
case (While b c) 

52396  151 
let ?f = "W (bval b) (D c)" 
152 
have "single_valued (lfp ?f)" 

52389  153 
proof(rule single_valued_lfp[OF cont_W]) 
52396  154 
show "\<And>r. single_valued r \<Longrightarrow> single_valued (?f r)" 
52389  155 
using While.IH by(force simp: single_valued_def W_def) 
156 
qed 

157 
thus ?case by simp 

158 
qed (auto simp add: single_valued_def) 

924
806721cfbf46
new version of HOL/IMP with curried function application
clasohm
parents:
diff
changeset

159 

806721cfbf46
new version of HOL/IMP with curried function application
clasohm
parents:
diff
changeset

160 
end 