-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPartially_Filled_Array_Iter.thy
72 lines (62 loc) · 1.96 KB
/
Partially_Filled_Array_Iter.thy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
theory Partially_Filled_Array_Iter
imports
Partially_Filled_Array
"Separation_Logic_Imperative_HOL.Imp_List_Spec"
begin
subsubsection \<open>Iterator\<close>
type_synonym 'a pfa_it = "'a pfarray \<times> nat"
definition "pfa_is_it c ls lsi ls2
\<equiv> (\<lambda>(lsi',i). is_pfa c ls lsi * \<up>(ls2 = drop i ls \<and> i \<le> length ls \<and> lsi' = lsi))"
definition pfa_it_init :: "'a pfarray \<Rightarrow> ('a pfa_it) Heap"
where "pfa_it_init l = return (l,0)"
fun pfa_it_next where
"pfa_it_next (p,i) = do {
x \<leftarrow> pfa_get p i;
return (x, (p,Suc i))
}"
definition pfa_it_has_next :: "('a::heap) pfa_it \<Rightarrow> bool Heap" where
"pfa_it_has_next it \<equiv> do {
l \<leftarrow> pfa_length (fst it);
return (snd it \<noteq> l)
}"
lemma pfa_iterate_impl:
"imp_list_iterate (is_pfa k) (pfa_is_it k) pfa_it_init pfa_it_has_next pfa_it_next"
apply unfold_locales
unfolding pfa_it_init_def pfa_is_it_def[abs_def]
proof(goal_cases)
case 1
then show ?case
by (simp add: is_pfa_prec)
next
case (2 l p)
then show ?case
by sep_auto
next
case (3 l' l p it)
then show ?case
apply (case_tac it, simp)
apply (case_tac l', simp)
apply sep_auto
subgoal by (metis drop_all list.simps(3) not_le_imp_less)
apply (sep_auto)
apply (metis drop_eq_ConsD list.sel(3))
subgoal by (meson Suc_leI \<open>\<And>list ba b aa a. \<lbrakk>it = ((a, b), ba); l' = drop ba l; aa # list = drop ba l; ba \<le> length l; p = (a, b)\<rbrakk> \<Longrightarrow> ba < length l\<close>)
subgoal by (metis list.sel(1) nth_via_drop)
subgoal using ent_refl_true by presburger
done
next
case (4 l p l' it)
then show ?case
unfolding pfa_it_has_next_def
apply (case_tac it, simp)
by (sep_auto)
next
case (5 l p l' it)
then show ?case
apply (case_tac it, simp)
by sep_auto
qed
interpretation pfa_iter:
imp_list_iterate "is_pfa k" "pfa_is_it k" pfa_it_init pfa_it_has_next pfa_it_next
by (rule pfa_iterate_impl)
end