Skip to content

Commit d1c9458

Browse files
committed
More Proofs
1 parent 9f4d790 commit d1c9458

File tree

3 files changed

+64
-61
lines changed

3 files changed

+64
-61
lines changed

Uppaal_Networks/UPPAAL_Asm_AbsInt.thy

Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ qed
6464
fun domain :: "('b::bot) state_map \<Rightarrow> addr set" where
6565
"domain (SM m) = {a. m a \<noteq> \<bottom>}"
6666

67-
fun deepen :: "(addr * 'a) set \<Rightarrow> 'a set state_map" where
68-
"deepen states = SM (\<lambda>pc. {st. (\<exists>(spc, st) \<in> states. pc = spc)})"
69-
70-
fun flatten :: "'a set state_map \<Rightarrow> (addr * 'a) set" where
71-
"flatten sm = {(pc, st). st \<in> lookup sm pc}"
72-
7367
lemma state_map_eq_fwd: "(\<forall>p. lookup m p = lookup n p) \<Longrightarrow> m = n"
7468
proof -
7569
assume lookeq: "\<forall>p. lookup m p = lookup n p"
@@ -184,6 +178,24 @@ instance proof standard
184178
qed
185179
end
186180

181+
inductive_set states_at for states pc where
182+
"(pc, s) \<in> states \<Longrightarrow> s \<in> states_at states pc"
183+
184+
fun deepen :: "(addr * 'a) set \<Rightarrow> 'a set state_map" where
185+
"deepen states = SM (states_at states)"
186+
187+
lemma deepen_fwd: "(pc, st) \<in> flat \<Longrightarrow> st \<in> lookup (deepen flat) pc" by (simp add: states_at.intros)
188+
lemma deepen_bwd: "st \<in> lookup (deepen flat) pc \<Longrightarrow> (pc, st) \<in> flat" by (simp add: states_at.simps)
189+
190+
(*fun flatten :: "'a set state_map \<Rightarrow> (addr * 'a) set" where
191+
"flatten sm = {(pc, st). st \<in> lookup sm pc}"*)
192+
193+
inductive_set flatten for sm where
194+
"st \<in> lookup sm pc \<Longrightarrow> (pc, st) \<in> flatten sm"
195+
196+
lemma flatten_fwd: "st \<in> lookup deep pc \<Longrightarrow> (pc, st) \<in> flatten deep" by (simp add: flatten.intros)
197+
lemma flatten_bwd: "(pc, st) \<in> flatten deep \<Longrightarrow> st \<in> lookup deep pc" by (meson flatten.cases)
198+
187199
subsection "Collecting Semantics"
188200

189201
type_synonym collect_state = "stack * rstate * flag * nat list"
@@ -192,69 +204,46 @@ type_synonym collect_ctx = "collect_state set state_map"
192204
fun states_domain :: "(addr * 'a) set \<Rightarrow> addr set" where
193205
"states_domain states = fst ` states"
194206

195-
fun states_at :: "(addr * 'a) set \<Rightarrow> addr \<Rightarrow> 'a set" where
196-
"states_at states pc = snd ` {s\<in>states. fst s = pc}"
197-
198207
fun propagate :: "'a set state_map \<Rightarrow> (addr * 'a) set \<Rightarrow> 'a set state_map" where
199-
"propagate (SM oldmap) ss =
200-
(let newmap = (\<lambda>pc. oldmap pc \<union> (states_at ss pc))
201-
in (SM newmap))"
208+
"propagate oldmap ss = oldmap \<squnion> deepen ss"
202209

203-
lemma propagate_preserve: "inm \<le> propagate inm sts" sorry
210+
lemma propagate_preserve: "inm \<le> propagate inm sts" by simp
204211

205-
lemma mono_inside: "a \<le> b \<Longrightarrow> x \<in> lookup_def a pc \<Longrightarrow> x \<in> lookup_def b pc" sorry
206-
lemma inside_mono: "x \<in> lookup_def a pc \<Longrightarrow> x \<in> lookup_def b pc \<Longrightarrow> a \<le> b" sorry
212+
inductive_set stepped_to for prog ctx pc where
213+
"ist \<in> lookup ctx ipc
214+
\<Longrightarrow> program ipc = Some op
215+
\<Longrightarrow> step op (ipc, ist) = Some (pc, st)
216+
\<Longrightarrow> st \<in> stepped_to prog ctx pc"
207217

208-
definition step_all :: "instr \<Rightarrow> addr \<Rightarrow> collect_state set \<Rightarrow> (state set * interpret_error set)" where
209-
"step_all op pc instates =
210-
({outs. (\<exists>ins\<in>instates. step op (pc, ins) = Some outs)},
211-
(if (\<exists>ins\<in>instates. step op (pc, ins) = None) then {StepFailed pc} else {}))"
212-
213-
fun collect_step_single :: "program \<Rightarrow> addr \<Rightarrow> (collect_ctx * interpret_error set) \<Rightarrow> (collect_ctx * interpret_error set)" where
214-
"collect_step_single prog pc (ctx, inerrs) =
215-
(case prog pc of
216-
Some op \<Rightarrow>
217-
let res = step_all op pc (lookup ctx pc) in
218-
(propagate ctx (fst res), snd res \<union> inerrs) |
219-
None \<Rightarrow> (ctx, { InvalAddr pc } \<union> inerrs))"
220-
221-
lemma collect_step_single_preserve:
222-
assumes "collect_step_single prog pc (inctx, inerrs) = (outctx, errors)"
223-
shows "inctx \<le> outctx"
224-
proof (cases "prog pc")
225-
case None then show ?thesis using assms by simp
226-
next
227-
case (Some op)
228-
from this assms have "outctx = propagate inctx (fst (step_all op pc (lookup inctx pc)))" unfolding Let_def
229-
by (metis (no_types, lifting) collect_step_single.simps fstI option.simps(5))
230-
then show ?thesis using propagate_preserve by blast
231-
qed
218+
(*lemma "stepped_to prog ctx pc = {st. \<exists>ipc ist op. (ist \<in> lookup ctx ipc) \<and> (program ipc = Some op) \<and> (step op (ipc, ist) = Some (pc, st))}"*)
232219

233-
fun collect_step :: "program \<Rightarrow> collect_ctx \<Rightarrow> collect_ctx" where
234-
"collect_step prog ctx =
235-
fst (fold (collect_step_single prog) (sorted_list_of_set (domain ctx)) (ctx, {}))"
236-
237-
lemma fold_preserve: "(\<forall>x acc. acc \<le> f x acc) \<Longrightarrow> (a::'a::order) \<le> fold f l a"
238-
proof (induction l arbitrary: a)
239-
case Nil
240-
have "fold f [] a = a" by simp
241-
have "a \<le> a" by auto
242-
then show ?case by auto
243-
next
244-
case (Cons el l)
245-
hence unf: "f el a \<le> fold f (el # l) a" by simp
246-
from Cons have "a \<le> f el a" by simp
247-
from unf this Cons(2) show ?case using order.trans by blast
248-
qed
220+
fun step_all :: "program \<Rightarrow> collect_ctx \<Rightarrow> collect_ctx" where
221+
"step_all prog ctx = SM (stepped_to prog ctx)"
249222

250-
lemma fold_preserve_option: "(\<forall>x acc accy. (f x (Some acc) = Some accy) \<longrightarrow> (acc \<le> accy)) \<Longrightarrow> (\<forall>x. f x None = None) \<Longrightarrow> fold f l (Some a) = Some ay \<Longrightarrow> (a::'a::order) \<le> ay" sorry
223+
(*definition step_all :: "instr \<Rightarrow> addr \<Rightarrow> collect_state set \<Rightarrow> state set" where
224+
"step_all op pc instates =
225+
{outs. (\<exists>ins\<in>instates. step op (pc, ins) = Some outs)}"*)
251226

252-
lemma collect_step_preserve: "collect_step prog inctx = outctx \<Longrightarrow> inctx \<le> outctx"
253-
proof -
254-
assume "collect_step prog inctx = outctx"
255-
show "inctx \<le> outctx" sorry
227+
lemma step_all_correct: "flatten (step_all prog (deepen flat)) = step_all_flat prog flat"
228+
proof standard
229+
show "flatten (step_all prog (deepen flat)) \<subseteq> step_all_flat prog flat"
230+
proof standard
231+
fix x assume ass: "x \<in> flatten (step_all prog (deepen flat))"
232+
then obtain pc st where splitx: "x = (pc, st)" using prod.exhaust_sel by blast
233+
from this ass have "st \<in> lookup (step_all prog (deepen flat)) pc" using flatten_bwd by fastforce
234+
hence "st \<in> stepped_to prog (deepen flat) pc" by simp
235+
have "x \<in> step_all_flat_induct prog flat" sorry
236+
thus "x \<in> step_all_flat prog flat" using step_all_flat_eq by blast
237+
qed
238+
show "step_all_flat prog flat \<subseteq> flatten (step_all prog (deepen flat))" sorry
256239
qed
257240

241+
definition error_all :: "instr \<Rightarrow> addr \<Rightarrow> collect_state set \<Rightarrow> interpret_error set" where
242+
"error_all op pc instates =
243+
(if (\<exists>ins\<in>instates. step op (pc, ins) = None) then {StepFailed pc} else {})"
244+
245+
fun collect_step :: "program \<Rightarrow> collect_ctx \<Rightarrow> collect_ctx" where
246+
"collect_step prog ctx = ctx \<squnion> step_all prog ctx"
258247

259248
fun collect_loop :: "program \<Rightarrow> fuel \<Rightarrow> collect_ctx \<Rightarrow> collect_ctx" where
260249
"collect_loop prog 0 st = st" |

Uppaal_Networks/UPPAAL_Asm_AbsInt_Flat.thy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ inductive_set step_all_flat_induct for prog instates where
135135
\<Longrightarrow> step instr (pc, st) = Some outst
136136
\<Longrightarrow> outst \<in> step_all_flat_induct (prog::program) instates"
137137

138-
lemma "step_all_flat prog instates = step_all_flat_induct prog instates"
138+
lemma step_all_flat_eq: "step_all_flat prog instates = step_all_flat_induct prog instates"
139139
proof (standard)
140140
show "step_all_flat prog instates \<subseteq> step_all_flat_induct prog instates" using step_all_flat_def step_all_flat_induct.simps by fastforce
141141
show "step_all_flat_induct prog instates \<subseteq> step_all_flat prog instates"

Uppaal_Networks/UPPAAL_Asm_AbsInt_Refine.thy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ imports
44
UPPAAL_Asm_AbsInt
55
begin
66

7+
lemma "states_at states pc = snd ` {s\<in>states. fst s = pc}"
8+
proof standard
9+
show "states_at states pc \<subseteq> snd ` {s \<in> states. fst s = pc}" using image_iff states_at.simps by fastforce
10+
show "snd ` {s \<in> states. fst s = pc} \<subseteq> states_at states pc" by standard (auto simp: states_at.intros)
11+
qed
12+
713
datatype 'a rbt_state_map = RBT_SM "(addr * 'a) rbt"
814

915
fun def :: "'a \<Rightarrow> 'a option \<Rightarrow> 'a" where
@@ -24,6 +30,14 @@ lemma lookup_RBT_SM[code]:
2430
lemma domain_RBT_SM[code]:
2531
"domain (RBT_SM tree) = fst ` set (inorder tree)" sorry
2632

33+
(*lemma "propagate (SM oldmap) ss =
34+
(SM (\<lambda>pc. oldmap pc \<union> (states_at ss pc)))"
35+
proof -
36+
have fwd: "propagate (SM oldmap) ss \<le> (SM (\<lambda>pc. oldmap pc \<union> (states_at ss pc)))" sorry
37+
have bwd: "(SM (\<lambda>pc. oldmap pc \<union> (states_at ss pc))) \<le> propagate (SM oldmap) ss" sorry
38+
from fwd bwd have "propagate (SM oldmap) ss = (SM (\<lambda>pc. oldmap pc \<union> (states_at ss pc)))" using antisym by blast
39+
qed*)
40+
2741
lemma propagate_RBT_SM[code]:
2842
"propagate (RBT_SM oldtree) (set ss) =
2943
RBT_SM (fold (\<lambda>(pc, st) tree.

0 commit comments

Comments
 (0)