Skip to content

Commit 642da08

Browse files
committed
Added a few more chanrep meta-theorems, to allow extract of channel information from events.
1 parent 7803286 commit 642da08

File tree

3 files changed

+71
-22
lines changed

3 files changed

+71
-22
lines changed

Channel_Type.ML

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,42 @@ fun make_chantype (name, chans) thy =
150150
ctx1
151151
end;
152152

153+
fun prism_has_chanrep n ctx =
154+
let open Syntax; open HOLogic
155+
val c = read_term ctx n in
156+
Trueprop $ (const @{const_name has_chanrep} $ c)
157+
end
158+
159+
fun prism_has_chanrep_proof ctx (n, t) =
160+
let open Simplifier; open Prism_Lib; open Syntax; open HOLogic
161+
val d = read_term ctx ("is_" ^ n ^ "_C")
162+
val ct = Syntax.check_term ctx ((const @{const_name Chanrep} $ mk_literal n $ mk_typerep (read_typ ctx t)) $ d)
163+
in
164+
Goal.prove ctx [] []
165+
(Syntax.check_term ctx (prism_has_chanrep n ctx))
166+
(fn _ => NO_CONTEXT_TACTIC ctx (Method_Closure.apply_method ctx @{method prism_has_chanrep} [ct] [] [] ctx []))
167+
end
168+
153169
fun prism_chanrep n t ctx =
154170
let open Syntax; open HOLogic
155-
val c = read_term ctx n; val d = read_term ctx ("is_" ^ n ^ "_C") in
156-
Trueprop $ (eq_const dummyT $ (const @{const_name prism_chanrep} $ c)
157-
$ ((const @{const_name Chanrep} $ mk_literal n $ mk_typerep t) $ d))
171+
val c = read_term ctx n; val d = read_term ctx ("is_" ^ n ^ "_C")
172+
val ct = ((const @{const_name Chanrep} $ mk_literal n $ mk_typerep t) $ d) in
173+
Trueprop $ (eq_const dummyT $ (const @{const_name chanrep_of} $ c) $ ct)
158174
end
159175

160176
fun prism_chanrep_proof ctx (n, t) =
161177
let open Simplifier; open Prism_Lib; open Syntax
162178
in
163179
Goal.prove ctx [] []
164180
(Syntax.check_term ctx (prism_chanrep n (read_typ ctx t) ctx))
165-
(fn {context = context, prems = _}
166-
=> NO_CONTEXT_TACTIC ctx (Method_Closure.apply_method ctx @{method prism_chanrep} [] [] [] ctx []))
181+
(fn _ => NO_CONTEXT_TACTIC ctx (Method_Closure.apply_method ctx @{method prism_chanrep} [] [] [] ctx []))
167182
end
168183

169184
fun prism_chanrep_proofs (name, chans) thy =
170185
let val ctx = Named_Target.theory_init thy
171186
in
172-
Local_Theory.exit_global (snd (Local_Theory.note ((Binding.qualify false name (Binding.name "prism_chanreps"), @{attributes [simp, code_unfold]}), map (prism_chanrep_proof ctx) chans) ctx))
187+
Local_Theory.exit_global (snd (Local_Theory.note ((Binding.qualify false name (Binding.name "prism_chanreps")
188+
, @{attributes [simp, code_unfold]}), map (prism_has_chanrep_proof ctx) chans @ map (prism_chanrep_proof ctx) chans) ctx))
173189
end
174190

175191

Channel_Type.thy

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,52 +138,83 @@ definition chan_names :: "'a itself \<Rightarrow> String.literal list" where
138138
lemma distinct_chan_names [simp]: "distinct (chan_names TYPE('a))"
139139
using chan_names_def local.wf_chantyperep wf_chantyperep_def by auto
140140

141-
definition chanrep_of :: "'a \<Rightarrow> 'a chanrep" where
142-
"chanrep_of e = the (find_chanrep CHANTYPEREP('a) e)"
141+
definition ev_chanrep :: "'a \<Rightarrow> 'a chanrep" where
142+
"ev_chanrep e = the (find_chanrep CHANTYPEREP('a) e)"
143143

144-
lemma range_chanrep_of: "range chanrep_of = set CHANTYPEREP('a)"
145-
apply (auto simp add: chanrep_of_def image_def)
144+
lemma range_ev_chanrep: "range ev_chanrep = set CHANTYPEREP('a)"
145+
apply (auto simp add: ev_chanrep_def image_def)
146146
apply (metis find_chanrep_Some local.wf_chantyperep option.sel)
147147
apply (metis find_Some_iff find_chanrep_Some find_chanrep_def local.wf_chantyperep option.sel wf_chantyperep_def)
148148
done
149149

150-
lemma finite_chanreps: "finite (range chanrep_of)"
151-
using range_chanrep_of by auto
150+
lemma finite_chanreps: "finite (range ev_chanrep)"
151+
using range_ev_chanrep by auto
152+
153+
definition ev_set_of :: "'a \<Rightarrow> 'a set" where
154+
"ev_set_of e = Collect (is_chan (ev_chanrep e))"
152155

153156
text \<open> An independent family of events, each corresponding to one set of channels. \<close>
154157

155158
definition ChanBasis :: "'a set set" where
156-
"ChanBasis = evs_of ` range chanrep_of"
159+
"ChanBasis = evs_of ` range ev_chanrep"
157160

158161
lemma family_chan_basis: "\<Union> ChanBasis = UNIV"
159162
apply (auto simp add: ChanBasis_def evs_of_def)
160-
apply (metis chantyperep_ev_has_chan image_iff local.wf_chantyperep range_chanrep_of)
163+
apply (metis chantyperep_ev_has_chan image_iff local.wf_chantyperep range_ev_chanrep)
161164
done
162165

163166
lemma indep_chan_basis: "\<lbrakk> A \<in> ChanBasis; B \<in> ChanBasis; A \<noteq> B \<rbrakk> \<Longrightarrow> A \<inter> B = {}"
164167
apply (auto simp add: ChanBasis_def evs_of_def)
165-
apply (metis local.wf_chantyperep rangeI range_chanrep_of wf_chantyperep_def)+
168+
apply (metis local.wf_chantyperep rangeI range_ev_chanrep wf_chantyperep_def)+
166169
done
167170

168171
end
169172

170173
subsection \<open> Prisms with a Channel Representation \<close>
171174

172-
definition prism_chanrep :: "('a \<Longrightarrow>\<^sub>\<triangle> 'e::chantyperep) \<Rightarrow> 'e chanrep" where
173-
"prism_chanrep c = (SOME d. d \<in> set CHANTYPEREP('e) \<and> evs_of d = dom (match\<^bsub>c\<^esub>))"
175+
definition has_chanrep :: "('a \<Longrightarrow>\<^sub>\<triangle> 'e::chantyperep) \<Rightarrow> bool" where
176+
"has_chanrep c = (\<exists> d. d \<in> set CHANTYPEREP('e) \<and> evs_of d = dom (match\<^bsub>c\<^esub>))"
177+
178+
definition chanrep_of :: "('a \<Longrightarrow>\<^sub>\<triangle> 'e::chantyperep) \<Rightarrow> 'e chanrep" where
179+
"chanrep_of c = (SOME d. d \<in> set CHANTYPEREP('e) \<and> evs_of d = dom (match\<^bsub>c\<^esub>))"
174180

175-
lemma prism_chanrep_eqI:
181+
lemma chanrep_of_eqI:
176182
fixes c :: "'a \<Longrightarrow>\<^sub>\<triangle> 'e::chantyperep" and d :: "'e chanrep"
177183
assumes "wb_prism c" "d \<in> set CHANTYPEREP('e)" "dom match\<^bsub>c\<^esub> = evs_of d"
178-
shows "prism_chanrep c = d"
184+
shows "chanrep_of c = d"
179185
using assms
180-
apply (simp add: prism_chanrep_def)
186+
apply (simp add: chanrep_of_def)
181187
apply (rule some_equality)
182188
apply simp
183189
using evs_of_inj wf_chantyperep apply blast
184190
done
185191

186-
method prism_chanrep = (rule prism_chanrep_eqI, simp, simp add: chantyperep_defs, simp add: chan_defs)
192+
lemma ev_chanrep_build [simp]:
193+
fixes c :: "'a \<Longrightarrow>\<^sub>\<triangle> 'e::chantyperep"
194+
assumes "wb_prism c" "has_chanrep c"
195+
shows "ev_chanrep (build\<^bsub>c\<^esub> v) = chanrep_of c"
196+
proof -
197+
obtain d where d: "d \<in> set CHANTYPEREP('e)" "evs_of d = dom (match\<^bsub>c\<^esub>)"
198+
by (meson assms has_chanrep_def)
199+
hence chanrep_c: "chanrep_of c = d"
200+
by (metis (mono_tags, lifting) chanrep_of_def evs_of_inj someI_ex wf_chantyperep)
201+
have "is_chan d (build\<^bsub>c\<^esub> v)"
202+
using assms(1) d(2) evs_of_def by fastforce
203+
hence "find (\<lambda>Q. is_chan Q (build\<^bsub>c\<^esub> v)) CHANTYPEREP('e) = Some d"
204+
by (metis d(1) find_Some_iff find_chanrep_Some find_chanrep_def wf_chantyperep wf_chantyperep_def)
205+
thus ?thesis
206+
by (simp add: chanrep_c ev_chanrep_def find_chanrep_def)
207+
qed
208+
209+
lemma ev_set_of_build [simp]:
210+
fixes c :: "'a \<Longrightarrow>\<^sub>\<triangle> 'e::chantyperep"
211+
assumes "wb_prism c" "has_chanrep c"
212+
shows "ev_set_of (build\<^bsub>c\<^esub> v) = Collect (is_chan (chanrep_of c))"
213+
by (simp add: assms(1) assms(2) ev_set_of_def)
214+
215+
method prism_has_chanrep for ct :: "'e chanrep" = (simp add: has_chanrep_def, rule exI[where x="ct"], rule conjI, simp add: chantyperep_defs, simp add: chan_defs)
216+
217+
method prism_chanrep = (rule chanrep_of_eqI, simp, simp add: chantyperep_defs, simp add: chan_defs)
187218

188219
subsection \<open> Channel Type Command \<close>
189220

Channel_Type_Example.thy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ chantype ch_single =
88
chantype ch_two =
99
chbool :: bool
1010
chint :: int
11-
11+
1212
chantype ct =
1313
a1 :: int
1414
a2 :: int
@@ -19,6 +19,8 @@ chantype ct =
1919
a7 :: int
2020
a8 :: int
2121

22+
thm ct.prism_chanreps
23+
2224
chantype ch_buffer =
2325
inp :: unit
2426
outp :: nat

0 commit comments

Comments
 (0)