author  nipkow 
Wed, 19 Jun 2013 10:54:34 +0200  
changeset 52395  7cc3f42930f3 
parent 52394  fe33d456b36c 
child 52396  432777f2e372 
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 

52387  9 
definition W :: "bexp \<Rightarrow> com_den \<Rightarrow> (com_den \<Rightarrow> com_den)" where 
10 
"W b rc = (\<lambda>rw. {(s,t). if bval b s then (s,t) \<in> rc O rw 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}"  

18 
"D (WHILE b DO c) = lfp (W 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 

26 
let ?w = "WHILE b DO c" 

27 
have "D ?w = lfp (W b (D c))" by simp 

28 
also have "\<dots> = W b (D c) (lfp (W b (D c)))" by(rule lfp_unfold [OF W_mono]) 

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) 

52 
let ?B = "Big_step (WHILE b DO c)" 

52389  53 
have "W b (D c) ?B <= ?B" using While.IH by (auto simp: W_def) 
54 
from lfp_lowerbound[where ?f = "W b (D c)", 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) 

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

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

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

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

84 
qed 

85 

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

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

88 
proof 

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

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

91 
thus ?thesis by(auto simp: chain_def) 

92 
qed 

93 

94 
theorem lfp_if_cont: 

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

96 
proof 

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

98 
proof (rule lfp_lowerbound) 

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

100 
using chain_iterates[OF mono_if_cont[OF assms]] assms 

101 
by(simp add: cont_def) 

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

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

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

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

106 
qed 

107 
next 

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

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

110 
proof(induction n) 

111 
case 0 show ?case by simp 

112 
next 

113 
case Suc 

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

115 
show ?case by simp 

116 
qed 

117 
} 

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

119 
qed 

120 

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

122 
by(auto simp: cont_def W_def) 

123 

52392  124 

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

127 
lemma single_valued_UN_chain: 

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

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

130 
proof(auto simp: single_valued_def) 

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

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

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

134 
qed 

135 

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

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

138 
shows "single_valued(lfp f)" 

139 
unfolding lfp_if_cont[OF assms(1)] 

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

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

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

143 
qed 

144 

145 
lemma single_valued_D: "single_valued (D c)" 

146 
proof(induction c) 

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

148 
next 

149 
case (While b c) 

150 
have "single_valued (lfp (W b (D c)))" 

151 
proof(rule single_valued_lfp[OF cont_W]) 

152 
show "!!r. single_valued r \<Longrightarrow> single_valued (W b (D c) r)" 

153 
using While.IH by(force simp: single_valued_def W_def) 

154 
qed 

155 
thus ?case by simp 

156 
qed (auto simp add: single_valued_def) 

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

157 

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

158 
end 