author | nipkow |
Wed, 17 Apr 2013 21:11:01 +0200 | |
changeset 51711 | df3426139651 |
parent 51390 | 1dff81cf425b |
child 51712 | 30624dab6054 |
permissions | -rw-r--r-- |
47613 | 1 |
(* Author: Tobias Nipkow *) |
2 |
||
3 |
theory Abs_Int1 |
|
4 |
imports Abs_State |
|
5 |
begin |
|
6 |
||
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
7 |
(* FIXME mv *) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
8 |
instantiation acom :: (type) vars |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
9 |
begin |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
10 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
11 |
definition "vars_acom = vars o strip" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
12 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
13 |
instance .. |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
14 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
15 |
end |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
16 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
17 |
lemma finite_Cvars: "finite(vars(C::'a acom))" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
18 |
by(simp add: vars_acom_def) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
19 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
20 |
|
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
21 |
lemma le_iff_le_annos_zip: "C1 \<le> C2 \<longleftrightarrow> |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
22 |
(\<forall> (a1,a2) \<in> set(zip (annos C1) (annos C2)). a1 \<le> a2) \<and> strip C1 = strip C2" |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
23 |
by(induct C1 C2 rule: less_eq_acom.induct) (auto simp: size_annos_same2) |
47613 | 24 |
|
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
25 |
lemma le_iff_le_annos: "C1 \<le> C2 \<longleftrightarrow> |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
26 |
strip C1 = strip C2 \<and> (\<forall> i<size(annos C1). annos C1 ! i \<le> annos C2 ! i)" |
47613 | 27 |
by(auto simp add: le_iff_le_annos_zip set_zip) (metis size_annos_same2) |
28 |
||
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
29 |
(* FIXME mv *) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
30 |
lemma post_in_annos: "post C \<in> set(annos C)" |
49353 | 31 |
by(induction C) auto |
32 |
||
47613 | 33 |
|
34 |
subsection "Computable Abstract Interpretation" |
|
35 |
||
51390 | 36 |
text{* Abstract interpretation over type @{text st} instead of functions. *} |
47613 | 37 |
|
38 |
context Gamma |
|
39 |
begin |
|
40 |
||
41 |
fun aval' :: "aexp \<Rightarrow> 'av st \<Rightarrow> 'av" where |
|
50896 | 42 |
"aval' (N i) S = num' i" | |
47613 | 43 |
"aval' (V x) S = fun S x" | |
44 |
"aval' (Plus a1 a2) S = plus' (aval' a1 S) (aval' a2 S)" |
|
45 |
||
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
46 |
lemma aval'_sound: "s : \<gamma>\<^isub>s S \<Longrightarrow> aval a s : \<gamma>(aval' a S)" |
47613 | 47 |
by (induction a) (auto simp: gamma_num' gamma_plus' \<gamma>_st_def) |
48 |
||
51390 | 49 |
lemma gamma_Step_subcomm: fixes C1 C2 :: "'a::semilattice_sup acom" |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
50 |
assumes "!!x e S. f1 x e (\<gamma>\<^isub>o S) \<subseteq> \<gamma>\<^isub>o (f2 x e S)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
51 |
"!!b S. g1 b (\<gamma>\<^isub>o S) \<subseteq> \<gamma>\<^isub>o (g2 b S)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
52 |
shows "Step f1 g1 (\<gamma>\<^isub>o S) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c (Step f2 g2 S C)" |
51390 | 53 |
proof(induction C arbitrary: S) |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
54 |
qed (auto simp: assms intro!: mono_gamma_o sup_ge1 sup_ge2) |
51390 | 55 |
|
56 |
lemma in_gamma_update: "\<lbrakk> s : \<gamma>\<^isub>s S; i : \<gamma> a \<rbrakk> \<Longrightarrow> s(x := i) : \<gamma>\<^isub>s(update S x a)" |
|
57 |
by(simp add: \<gamma>_st_def) |
|
58 |
||
47613 | 59 |
end |
60 |
||
51390 | 61 |
|
47613 | 62 |
text{* The for-clause (here and elsewhere) only serves the purpose of fixing |
63 |
the name of the type parameter @{typ 'av} which would otherwise be renamed to |
|
64 |
@{typ 'a}. *} |
|
65 |
||
49396 | 66 |
locale Abs_Int = Gamma where \<gamma>=\<gamma> for \<gamma> :: "'av::semilattice \<Rightarrow> val set" |
47613 | 67 |
begin |
68 |
||
51390 | 69 |
definition "step' = Step |
51389 | 70 |
(\<lambda>x e S. case S of None \<Rightarrow> None | Some S \<Rightarrow> Some(update S x (aval' e S))) |
71 |
(\<lambda>b S. S)" |
|
72 |
||
47613 | 73 |
definition AI :: "com \<Rightarrow> 'av st option acom option" where |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
74 |
"AI c = pfp (step' \<top>) (bot c)" |
47613 | 75 |
|
76 |
||
77 |
lemma strip_step'[simp]: "strip(step' S C) = strip C" |
|
51390 | 78 |
by(simp add: step'_def) |
47613 | 79 |
|
80 |
||
81 |
text{* Soundness: *} |
|
82 |
||
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
83 |
lemma step_step': "step (\<gamma>\<^isub>o S) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c (step' S C)" |
51390 | 84 |
unfolding step_def step'_def |
85 |
by(rule gamma_Step_subcomm) |
|
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
86 |
(auto simp: intro!: aval'_sound in_gamma_update split: option.splits) |
47613 | 87 |
|
50986 | 88 |
lemma AI_sound: "AI c = Some C \<Longrightarrow> CS c \<le> \<gamma>\<^isub>c C" |
47613 | 89 |
proof(simp add: CS_def AI_def) |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
90 |
assume 1: "pfp (step' \<top>) (bot c) = Some C" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
91 |
have pfp': "step' \<top> C \<le> C" by(rule pfp_pfp[OF 1]) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
92 |
have 2: "step (\<gamma>\<^isub>o \<top>) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c C" --"transfer the pfp'" |
50986 | 93 |
proof(rule order_trans) |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
94 |
show "step (\<gamma>\<^isub>o \<top>) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c (step' \<top> C)" by(rule step_step') |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
95 |
show "... \<le> \<gamma>\<^isub>c C" by (metis mono_gamma_c[OF pfp']) |
47613 | 96 |
qed |
51390 | 97 |
have 3: "strip (\<gamma>\<^isub>c C) = c" by(simp add: strip_pfp[OF _ 1] step'_def) |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
98 |
have "lfp c (step (\<gamma>\<^isub>o \<top>)) \<le> \<gamma>\<^isub>c C" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
99 |
by(rule lfp_lowerbound[simplified,where f="step (\<gamma>\<^isub>o \<top>)", OF 3 2]) |
50986 | 100 |
thus "lfp c (step UNIV) \<le> \<gamma>\<^isub>c C" by simp |
47613 | 101 |
qed |
102 |
||
103 |
end |
|
104 |
||
105 |
||
106 |
subsubsection "Monotonicity" |
|
107 |
||
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
108 |
lemma le_sup_disj: "x \<le> y \<or> x \<le> z \<Longrightarrow> x \<le> y \<squnion> (z::_::semilattice_sup)" |
51389 | 109 |
by (metis sup_ge1 sup_ge2 order_trans) |
47613 | 110 |
|
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
111 |
theorem mono2_Step: fixes C1 :: "'a::semilattice acom" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
112 |
assumes "!!x e S1 S2. S1 \<le> S2 \<Longrightarrow> f x e S1 \<le> f x e S2" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
113 |
"!!b S1 S2. S1 \<le> S2 \<Longrightarrow> g b S1 \<le> g b S2" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
114 |
shows "S1 \<le> S2 \<Longrightarrow> C1 \<le> C2 \<Longrightarrow> Step f g S1 C1 \<le> Step f g S2 C2" |
51390 | 115 |
by(induction C1 C2 arbitrary: S1 S2 rule: less_eq_acom.induct) |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
116 |
(auto simp: mono_post assms le_sup_disj) |
51390 | 117 |
|
118 |
||
47613 | 119 |
locale Abs_Int_mono = Abs_Int + |
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
120 |
assumes mono_plus': "a1 \<le> b1 \<Longrightarrow> a2 \<le> b2 \<Longrightarrow> plus' a1 a2 \<le> plus' b1 b2" |
47613 | 121 |
begin |
122 |
||
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
123 |
lemma mono_aval': "S1 \<le> S2 \<Longrightarrow> aval' e S1 \<le> aval' e S2" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
124 |
by(induction e) (auto simp: mono_plus' mono_fun) |
47613 | 125 |
|
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
126 |
theorem mono_step': "S1 \<le> S2 \<Longrightarrow> C1 \<le> C2 \<Longrightarrow> step' S1 C1 \<le> step' S2 C2" |
51390 | 127 |
unfolding step'_def |
128 |
by(rule mono2_Step) (auto simp: mono_aval' split: option.split) |
|
47613 | 129 |
|
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
130 |
lemma mono_step'_top: "C \<le> C' \<Longrightarrow> step' \<top> C \<le> step' \<top> C'" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
131 |
by (metis mono_step' order_refl) |
47613 | 132 |
|
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
133 |
lemma AI_least_pfp: assumes "AI c = Some C" "step' \<top> C' \<le> C'" "strip C' = c" |
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
134 |
shows "C \<le> C'" |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
135 |
by(rule pfp_bot_least[OF _ _ assms(2,3) assms(1)[unfolded AI_def]]) |
51390 | 136 |
(simp_all add: mono_step'_top) |
49464 | 137 |
|
47613 | 138 |
end |
139 |
||
140 |
||
141 |
subsubsection "Termination" |
|
142 |
||
143 |
lemma pfp_termination: |
|
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
144 |
fixes x0 :: "'a::order" and m :: "'a \<Rightarrow> nat" |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
145 |
assumes mono: "\<And>x y. I x \<Longrightarrow> I y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y" |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
146 |
and m: "\<And>x y. I x \<Longrightarrow> I y \<Longrightarrow> x < y \<Longrightarrow> m x > m y" |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
147 |
and I: "\<And>x y. I x \<Longrightarrow> I(f x)" and "I x0" and "x0 \<le> f x0" |
49464 | 148 |
shows "\<exists>x. pfp f x0 = Some x" |
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
149 |
proof(simp add: pfp_def, rule wf_while_option_Some[where P = "%x. I x & x \<le> f x"]) |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
150 |
show "wf {(y,x). ((I x \<and> x \<le> f x) \<and> \<not> f x \<le> x) \<and> y = f x}" |
47613 | 151 |
by(rule wf_subset[OF wf_measure[of m]]) (auto simp: m I) |
152 |
next |
|
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
153 |
show "I x0 \<and> x0 \<le> f x0" using `I x0` `x0 \<le> f x0` by blast |
47613 | 154 |
next |
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
155 |
fix x assume "I x \<and> x \<le> f x" thus "I(f x) \<and> f x \<le> f(f x)" |
47613 | 156 |
by (blast intro: I mono) |
157 |
qed |
|
158 |
||
159 |
||
49547 | 160 |
locale Measure1 = |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
161 |
fixes m :: "'av::{order,top} \<Rightarrow> nat" |
47613 | 162 |
fixes h :: "nat" |
163 |
assumes h: "m x \<le> h" |
|
164 |
begin |
|
165 |
||
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
166 |
definition m_s :: "vname set \<Rightarrow> 'av st \<Rightarrow> nat" ("m\<^isub>s") where |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
167 |
"m_s X S = (\<Sum> x \<in> X. m(fun S x))" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
168 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
169 |
lemma m_s_h: "finite X \<Longrightarrow> m_s X S \<le> h * card X" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
170 |
by(simp add: m_s_def) (metis nat_mult_commute of_nat_id setsum_bounded[OF h]) |
47613 | 171 |
|
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
172 |
definition m_o :: "vname set \<Rightarrow> 'av st option \<Rightarrow> nat" ("m\<^isub>o") where |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
173 |
"m_o X opt = (case opt of None \<Rightarrow> h * card X + 1 | Some S \<Rightarrow> m_s X S)" |
49431 | 174 |
|
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
175 |
lemma m_o_h: "finite X \<Longrightarrow> m_o X opt \<le> (h*card X + 1)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
176 |
by(auto simp add: m_o_def m_s_h le_SucI split: option.split dest:m_s_h) |
47613 | 177 |
|
49432 | 178 |
definition m_c :: "'av st option acom \<Rightarrow> nat" ("m\<^isub>c") where |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
179 |
"m_c C = (\<Sum>i<size(annos C). m_o (vars C) (annos C ! i))" |
49431 | 180 |
|
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
181 |
text{* Upper complexity bound: *} |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
182 |
lemma m_c_h: "m_c C \<le> size(annos C) * (h * card(vars C) + 1)" |
49431 | 183 |
proof- |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
184 |
let ?X = "vars C" let ?n = "card ?X" let ?a = "size(annos C)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
185 |
have "m_c C = (\<Sum>i<?a. m_o ?X (annos C ! i))" by(simp add: m_c_def) |
49431 | 186 |
also have "\<dots> \<le> (\<Sum>i<?a. h * ?n + 1)" |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
187 |
apply(rule setsum_mono) using m_o_h[OF finite_Cvars] by simp |
49431 | 188 |
also have "\<dots> = ?a * (h * ?n + 1)" by simp |
189 |
finally show ?thesis . |
|
190 |
qed |
|
191 |
||
49547 | 192 |
end |
193 |
||
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
194 |
text{* The predicates @{text "top_on X a"} that follow describe that @{text a} is some object |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
195 |
that maps all variables in @{text X} to @{term \<top>}. |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
196 |
This is an important invariant for the termination proof where we argue that only |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
197 |
the finitely many variables in the program change. That the others do not change |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
198 |
follows because they remain @{term \<top>}. *} |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
199 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
200 |
class top_on = |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
201 |
fixes top_on :: "vname set \<Rightarrow> 'a \<Rightarrow> bool" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
202 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
203 |
instantiation st :: (top)top_on |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
204 |
begin |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
205 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
206 |
fun top_on_st :: "vname set \<Rightarrow> 'a st \<Rightarrow> bool" where |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
207 |
"top_on_st X F = (\<forall>x\<in>X. fun F x = \<top>)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
208 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
209 |
instance .. |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
210 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
211 |
end |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
212 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
213 |
instantiation option :: (top_on)top_on |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
214 |
begin |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
215 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
216 |
fun top_on_option :: "vname set \<Rightarrow> 'a option \<Rightarrow> bool" where |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
217 |
"top_on_option X (Some F) = top_on X F" | |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
218 |
"top_on_option X None = True" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
219 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
220 |
instance .. |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
221 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
222 |
end |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
223 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
224 |
instantiation acom :: (top_on)top_on |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
225 |
begin |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
226 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
227 |
definition top_on_acom :: "vname set \<Rightarrow> 'a acom \<Rightarrow> bool" where |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
228 |
"top_on_acom X C = (\<forall>a \<in> set(annos C). top_on X a)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
229 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
230 |
instance .. |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
231 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
232 |
end |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
233 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
234 |
lemma top_on_top: "top_on X (\<top>::_ st option)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
235 |
by(auto simp: top_option_def fun_top) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
236 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
237 |
lemma top_on_bot: "top_on X (bot c)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
238 |
by(auto simp add: top_on_acom_def bot_def) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
239 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
240 |
lemma top_on_post: "top_on X C \<Longrightarrow> top_on X (post C)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
241 |
by(simp add: top_on_acom_def post_in_annos) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
242 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
243 |
lemma top_on_acom_simps: |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
244 |
"top_on X (SKIP {Q}) = top_on X Q" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
245 |
"top_on X (x ::= e {Q}) = top_on X Q" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
246 |
"top_on X (C1;C2) = (top_on X C1 \<and> top_on X C2)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
247 |
"top_on X (IF b THEN {P1} C1 ELSE {P2} C2 {Q}) = |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
248 |
(top_on X P1 \<and> top_on X C1 \<and> top_on X P2 \<and> top_on X C2 \<and> top_on X Q)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
249 |
"top_on X ({I} WHILE b DO {P} C {Q}) = |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
250 |
(top_on X I \<and> top_on X C \<and> top_on X P \<and> top_on X Q)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
251 |
by(auto simp add: top_on_acom_def) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
252 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
253 |
lemma top_on_sup: |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
254 |
"top_on X o1 \<Longrightarrow> top_on X o2 \<Longrightarrow> top_on X (o1 \<squnion> o2 :: _ st option)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
255 |
apply(induction o1 o2 rule: sup_option.induct) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
256 |
apply(auto) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
257 |
by transfer simp |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
258 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
259 |
lemma top_on_Step: fixes C :: "('a::semilattice)st option acom" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
260 |
assumes "!!x e S. \<lbrakk>top_on X S; x \<notin> X; vars e \<subseteq> -X\<rbrakk> \<Longrightarrow> top_on X (f x e S)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
261 |
"!!b S. top_on X S \<Longrightarrow> vars b \<subseteq> -X \<Longrightarrow> top_on X (g b S)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
262 |
shows "\<lbrakk> vars C \<subseteq> -X; top_on X S; top_on X C \<rbrakk> \<Longrightarrow> top_on X (Step f g S C)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
263 |
proof(induction C arbitrary: S) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
264 |
qed (auto simp: top_on_acom_simps vars_acom_def top_on_post top_on_sup assms) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
265 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
266 |
|
49547 | 267 |
locale Measure = Measure1 + |
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
268 |
assumes m2: "x < y \<Longrightarrow> m x > m y" |
49547 | 269 |
begin |
270 |
||
51372 | 271 |
lemma m1: "x \<le> y \<Longrightarrow> m x \<ge> m y" |
272 |
by(auto simp: le_less m2) |
|
273 |
||
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
274 |
lemma m_s2_rep: assumes "finite(X)" and "S1 = S2 on -X" and "\<forall>x. S1 x \<le> S2 x" and "S1 \<noteq> S2" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
275 |
shows "(\<Sum>x\<in>X. m (S2 x)) < (\<Sum>x\<in>X. m (S1 x))" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
276 |
proof- |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
277 |
from assms(3) have 1: "\<forall>x\<in>X. m(S1 x) \<ge> m(S2 x)" by (simp add: m1) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
278 |
from assms(2,3,4) have "EX x:X. S1 x < S2 x" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
279 |
by(simp add: fun_eq_iff) (metis Compl_iff le_neq_trans) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
280 |
hence 2: "\<exists>x\<in>X. m(S1 x) > m(S2 x)" by (metis m2) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
281 |
from setsum_strict_mono_ex1[OF `finite X` 1 2] |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
282 |
show "(\<Sum>x\<in>X. m (S2 x)) < (\<Sum>x\<in>X. m (S1 x))" . |
49547 | 283 |
qed |
284 |
||
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
285 |
lemma m_s2: "finite(X) \<Longrightarrow> fun S1 = fun S2 on -X \<Longrightarrow> S1 < S2 \<Longrightarrow> m_s X S1 > m_s X S2" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
286 |
apply(auto simp add: less_st_def m_s_def) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
287 |
apply (transfer fixing: m) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
288 |
apply(simp add: less_eq_st_rep_iff eq_st_def m_s2_rep) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
289 |
done |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
290 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
291 |
lemma m_o2: "finite X \<Longrightarrow> top_on (-X) o1 \<Longrightarrow> top_on (-X) o2 \<Longrightarrow> |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
292 |
o1 < o2 \<Longrightarrow> m_o X o1 > m_o X o2" |
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
293 |
proof(induction o1 o2 rule: less_eq_option.induct) |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
294 |
case 1 thus ?case by (auto simp: m_o_def m_s2 less_option_def) |
49547 | 295 |
next |
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
296 |
case 2 thus ?case by(auto simp: m_o_def less_option_def le_imp_less_Suc m_s_h) |
49547 | 297 |
next |
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
298 |
case 3 thus ?case by (auto simp: less_option_def) |
49547 | 299 |
qed |
300 |
||
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
301 |
lemma m_o1: "finite X \<Longrightarrow> top_on (-X) o1 \<Longrightarrow> top_on (-X) o2 \<Longrightarrow> |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
302 |
o1 \<le> o2 \<Longrightarrow> m_o X o1 \<ge> m_o X o2" |
51372 | 303 |
by(auto simp: le_less m_o2) |
304 |
||
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
305 |
|
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
306 |
lemma m_c2: "top_on (-vars C1) C1 \<Longrightarrow> top_on (-vars C2) C2 \<Longrightarrow> |
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
307 |
C1 < C2 \<Longrightarrow> m_c C1 > m_c C2" |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
308 |
proof(auto simp add: le_iff_le_annos m_c_def size_annos_same[of C1 C2] vars_acom_def less_acom_def) |
49396 | 309 |
let ?X = "vars(strip C2)" |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
310 |
assume top: "top_on (- vars(strip C2)) C1" "top_on (- vars(strip C2)) C2" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
311 |
and strip_eq: "strip C1 = strip C2" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
312 |
and 0: "\<forall>i<size(annos C2). annos C1 ! i \<le> annos C2 ! i" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
313 |
hence 1: "\<forall>i<size(annos C2). m_o ?X (annos C1 ! i) \<ge> m_o ?X (annos C2 ! i)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
314 |
apply (auto simp: all_set_conv_all_nth vars_acom_def top_on_acom_def) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
315 |
by (metis finite_cvars m_o1 size_annos_same2) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
316 |
fix i assume i: "i < size(annos C2)" "\<not> annos C2 ! i \<le> annos C1 ! i" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
317 |
have topo1: "top_on (- ?X) (annos C1 ! i)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
318 |
using i(1) top(1) by(simp add: top_on_acom_def size_annos_same[OF strip_eq]) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
319 |
have topo2: "top_on (- ?X) (annos C2 ! i)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
320 |
using i(1) top(2) by(simp add: top_on_acom_def size_annos_same[OF strip_eq]) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
321 |
from i have "m_o ?X (annos C1 ! i) > m_o ?X (annos C2 ! i)" (is "?P i") |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
322 |
by (metis 0 less_option_def m_o2[OF finite_cvars topo1] topo2) |
49396 | 323 |
hence 2: "\<exists>i < size(annos C2). ?P i" using `i < size(annos C2)` by blast |
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
324 |
show "(\<Sum>i<size(annos C2). m_o ?X (annos C2 ! i)) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
325 |
< (\<Sum>i<size(annos C2). m_o ?X (annos C1 ! i))" |
47613 | 326 |
apply(rule setsum_strict_mono_ex1) using 1 2 by (auto) |
327 |
qed |
|
328 |
||
49547 | 329 |
end |
330 |
||
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
331 |
|
49547 | 332 |
locale Abs_Int_measure = |
333 |
Abs_Int_mono where \<gamma>=\<gamma> + Measure where m=m |
|
334 |
for \<gamma> :: "'av::semilattice \<Rightarrow> val set" and m :: "'av \<Rightarrow> nat" |
|
335 |
begin |
|
336 |
||
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
337 |
lemma top_on_step': "\<lbrakk> vars C \<subseteq> -X; top_on X C \<rbrakk> \<Longrightarrow> top_on X (step' \<top> C)" |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
338 |
unfolding step'_def |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
339 |
by(rule top_on_Step) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
340 |
(auto simp add: top_option_def fun_top split: option.splits) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
341 |
|
47613 | 342 |
lemma AI_Some_measure: "\<exists>C. AI c = Some C" |
343 |
unfolding AI_def |
|
51711
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
344 |
apply(rule pfp_termination[where I = "\<lambda>C. strip C = c \<and> top_on (- vars C) C" and m="m_c"]) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
345 |
apply(simp_all add: m_c2 mono_step'_top bot_least top_on_bot) |
df3426139651
complete revision: finally got rid of annoying L-predicate
nipkow
parents:
51390
diff
changeset
|
346 |
apply(auto simp add: top_on_step' vars_acom_def) |
47613 | 347 |
done |
348 |
||
349 |
end |
|
350 |
||
351 |
end |