302 by (blast intro: I mono) |
302 by (blast intro: I mono) |
303 qed |
303 qed |
304 |
304 |
305 |
305 |
306 locale Measure1_fun = |
306 locale Measure1_fun = |
307 fixes m :: "'av::{order,top} \<Rightarrow> nat" |
307 fixes m :: "'av::top \<Rightarrow> nat" |
308 fixes h :: "nat" |
308 fixes h :: "nat" |
309 assumes h: "m x \<le> h" |
309 assumes h: "m x \<le> h" |
310 begin |
310 begin |
311 |
311 |
312 definition m_s :: "vname set \<Rightarrow> 'av st \<Rightarrow> nat" ("m\<^isub>s") where |
312 definition m_s :: "vname set \<Rightarrow> 'av st \<Rightarrow> nat" ("m\<^isub>s") where |
313 "m_s X S = (\<Sum> x \<in> X. m(S x))" |
313 "m_s X S = (\<Sum> x \<in> X. m(S x))" |
314 |
314 |
315 lemma m_s_h: "finite X \<Longrightarrow> m_s X S \<le> h * card X" |
315 lemma m_s_h: "finite X \<Longrightarrow> m_s X S \<le> h * card X" |
316 by(simp add: m_s_def) (metis nat_mult_commute of_nat_id setsum_bounded[OF h]) |
316 by(simp add: m_s_def) (metis nat_mult_commute of_nat_id setsum_bounded[OF h]) |
317 |
317 |
318 definition m_o :: "vname set \<Rightarrow> 'av st option \<Rightarrow> nat" ("m\<^isub>o") where |
318 fun m_o :: "vname set \<Rightarrow> 'av st option \<Rightarrow> nat" ("m\<^isub>o") where |
319 "m_o X opt = (case opt of None \<Rightarrow> h * card X + 1 | Some S \<Rightarrow> m_s X S)" |
319 "m_o X (Some S) = m_s X S" | |
|
320 "m_o X None = h * card X + 1" |
320 |
321 |
321 lemma m_o_h: "finite X \<Longrightarrow> m_o X opt \<le> (h*card X + 1)" |
322 lemma m_o_h: "finite X \<Longrightarrow> m_o X opt \<le> (h*card X + 1)" |
322 by(auto simp add: m_o_def m_s_h le_SucI split: option.split dest:m_s_h) |
323 by(cases opt)(auto simp add: m_s_h le_SucI dest: m_s_h) |
323 |
324 |
324 definition m_c :: "'av st option acom \<Rightarrow> nat" ("m\<^isub>c") where |
325 definition m_c :: "'av st option acom \<Rightarrow> nat" ("m\<^isub>c") where |
325 "m_c C = (\<Sum>i<size(annos C). m_o (vars C) (annos C ! i))" |
326 "m_c C = (\<Sum>i<size(annos C). m_o (vars C) (annos C ! i))" |
326 |
327 |
327 text{* Upper complexity bound: *} |
328 text{* Upper complexity bound: *} |
345 lemma le_iff_le_annos: "C1 \<le> C2 \<longleftrightarrow> |
346 lemma le_iff_le_annos: "C1 \<le> C2 \<longleftrightarrow> |
346 strip C1 = strip C2 \<and> (\<forall> i<size(annos C1). annos C1 ! i \<le> annos C2 ! i)" |
347 strip C1 = strip C2 \<and> (\<forall> i<size(annos C1). annos C1 ! i \<le> annos C2 ! i)" |
347 by(auto simp add: le_iff_le_annos_zip set_zip) (metis size_annos_same2) |
348 by(auto simp add: le_iff_le_annos_zip set_zip) (metis size_annos_same2) |
348 |
349 |
349 |
350 |
350 text{* The predicates @{text "top_on_ty X a"} that follow describe that @{text a} is some object |
351 locale Measure_fun = Measure1_fun where m=m for m :: "'av::semilattice \<Rightarrow> nat" + |
351 that maps all variables in @{text X} to @{term \<top>}. |
352 assumes m2: "x < y \<Longrightarrow> m x > m y" |
|
353 begin |
|
354 |
|
355 text{* The predicates @{text "top_on_ty X a"} that follow describe that any abstract |
|
356 state in @{text a} maps all variables in @{text X} to @{term \<top>}. |
352 This is an important invariant for the termination proof where we argue that only |
357 This is an important invariant for the termination proof where we argue that only |
353 the finitely many variables in the program change. That the others do not change |
358 the finitely many variables in the program change. That the others do not change |
354 follows because they remain @{term \<top>}. *} |
359 follows because they remain @{term \<top>}. *} |
355 |
360 |
356 fun top_on_st :: "vname set \<Rightarrow> 'a::top st \<Rightarrow> bool" where |
361 fun top_on_st :: "vname set \<Rightarrow> 'av st \<Rightarrow> bool" ("top'_on\<^isub>s") where |
357 "top_on_st X f = (\<forall>x\<in>X. f x = \<top>)" |
362 "top_on_st X S = (\<forall>x\<in>X. S x = \<top>)" |
358 |
363 |
359 fun top_on_opt :: "vname set \<Rightarrow> 'a::top st option \<Rightarrow> bool" where |
364 fun top_on_opt :: "vname set \<Rightarrow> 'av st option \<Rightarrow> bool" ("top'_on\<^isub>o") where |
360 "top_on_opt X (Some F) = top_on_st X F" | |
365 "top_on_opt X (Some S) = top_on_st X S" | |
361 "top_on_opt X None = True" |
366 "top_on_opt X None = True" |
362 |
367 |
363 definition top_on_acom :: "vname set \<Rightarrow> 'a::top st option acom \<Rightarrow> bool" where |
368 definition top_on_acom :: "vname set \<Rightarrow> 'av st option acom \<Rightarrow> bool" ("top'_on\<^isub>c") where |
364 "top_on_acom X C = (\<forall>a \<in> set(annos C). top_on_opt X a)" |
369 "top_on_acom X C = (\<forall>a \<in> set(annos C). top_on_opt X a)" |
365 |
370 |
366 lemma top_on_top: "top_on_opt X (\<top>::_ st option)" |
371 lemma top_on_top: "top_on_opt X \<top>" |
367 by(auto simp: top_option_def) |
372 by(auto simp: top_option_def) |
368 |
373 |
369 lemma top_on_bot: "top_on_acom X (bot c)" |
374 lemma top_on_bot: "top_on_acom X (bot c)" |
370 by(auto simp add: top_on_acom_def bot_def) |
375 by(auto simp add: top_on_acom_def bot_def) |
371 |
376 |
381 "top_on_acom X ({I} WHILE b DO {P} C {Q}) = |
386 "top_on_acom X ({I} WHILE b DO {P} C {Q}) = |
382 (top_on_opt X I \<and> top_on_acom X C \<and> top_on_opt X P \<and> top_on_opt X Q)" |
387 (top_on_opt X I \<and> top_on_acom X C \<and> top_on_opt X P \<and> top_on_opt X Q)" |
383 by(auto simp add: top_on_acom_def) |
388 by(auto simp add: top_on_acom_def) |
384 |
389 |
385 lemma top_on_sup: |
390 lemma top_on_sup: |
386 "top_on_opt X o1 \<Longrightarrow> top_on_opt X o2 \<Longrightarrow> top_on_opt X (o1 \<squnion> o2 :: _ st option)" |
391 "top_on_opt X o1 \<Longrightarrow> top_on_opt X o2 \<Longrightarrow> top_on_opt X (o1 \<squnion> o2)" |
387 apply(induction o1 o2 rule: sup_option.induct) |
392 apply(induction o1 o2 rule: sup_option.induct) |
388 apply(auto) |
393 apply(auto) |
389 done |
394 done |
390 |
395 |
391 lemma top_on_Step: fixes C :: "('a::semilattice)st option acom" |
396 lemma top_on_Step: fixes C :: "'av st option acom" |
392 assumes "!!x e S. \<lbrakk>top_on_opt X S; x \<notin> X; vars e \<subseteq> -X\<rbrakk> \<Longrightarrow> top_on_opt X (f x e S)" |
397 assumes "!!x e S. \<lbrakk>top_on_opt X S; x \<notin> X; vars e \<subseteq> -X\<rbrakk> \<Longrightarrow> top_on_opt X (f x e S)" |
393 "!!b S. top_on_opt X S \<Longrightarrow> vars b \<subseteq> -X \<Longrightarrow> top_on_opt X (g b S)" |
398 "!!b S. top_on_opt X S \<Longrightarrow> vars b \<subseteq> -X \<Longrightarrow> top_on_opt X (g b S)" |
394 shows "\<lbrakk> vars C \<subseteq> -X; top_on_opt X S; top_on_acom X C \<rbrakk> \<Longrightarrow> top_on_acom X (Step f g S C)" |
399 shows "\<lbrakk> vars C \<subseteq> -X; top_on_opt X S; top_on_acom X C \<rbrakk> \<Longrightarrow> top_on_acom X (Step f g S C)" |
395 proof(induction C arbitrary: S) |
400 proof(induction C arbitrary: S) |
396 qed (auto simp: top_on_acom_simps vars_acom_def top_on_post top_on_sup assms) |
401 qed (auto simp: top_on_acom_simps vars_acom_def top_on_post top_on_sup assms) |
397 |
|
398 |
|
399 locale Measure_fun = Measure1_fun + |
|
400 assumes m2: "x < y \<Longrightarrow> m x > m y" |
|
401 begin |
|
402 |
402 |
403 lemma m1: "x \<le> y \<Longrightarrow> m x \<ge> m y" |
403 lemma m1: "x \<le> y \<Longrightarrow> m x \<ge> m y" |
404 by(auto simp: le_less m2) |
404 by(auto simp: le_less m2) |
405 |
405 |
406 lemma m_s2_rep: assumes "finite(X)" and "S1 = S2 on -X" and "\<forall>x. S1 x \<le> S2 x" and "S1 \<noteq> S2" |
406 lemma m_s2_rep: assumes "finite(X)" and "S1 = S2 on -X" and "\<forall>x. S1 x \<le> S2 x" and "S1 \<noteq> S2" |
420 done |
420 done |
421 |
421 |
422 lemma m_o2: "finite X \<Longrightarrow> top_on_opt (-X) o1 \<Longrightarrow> top_on_opt (-X) o2 \<Longrightarrow> |
422 lemma m_o2: "finite X \<Longrightarrow> top_on_opt (-X) o1 \<Longrightarrow> top_on_opt (-X) o2 \<Longrightarrow> |
423 o1 < o2 \<Longrightarrow> m_o X o1 > m_o X o2" |
423 o1 < o2 \<Longrightarrow> m_o X o1 > m_o X o2" |
424 proof(induction o1 o2 rule: less_eq_option.induct) |
424 proof(induction o1 o2 rule: less_eq_option.induct) |
425 case 1 thus ?case by (auto simp: m_o_def m_s2 less_option_def) |
425 case 1 thus ?case by (auto simp: m_s2 less_option_def) |
426 next |
426 next |
427 case 2 thus ?case by(auto simp: m_o_def less_option_def le_imp_less_Suc m_s_h) |
427 case 2 thus ?case by(auto simp: less_option_def le_imp_less_Suc m_s_h) |
428 next |
428 next |
429 case 3 thus ?case by (auto simp: less_option_def) |
429 case 3 thus ?case by (auto simp: less_option_def) |
430 qed |
430 qed |
431 |
431 |
432 lemma m_o1: "finite X \<Longrightarrow> top_on_opt (-X) o1 \<Longrightarrow> top_on_opt (-X) o2 \<Longrightarrow> |
432 lemma m_o1: "finite X \<Longrightarrow> top_on_opt (-X) o1 \<Longrightarrow> top_on_opt (-X) o2 \<Longrightarrow> |
463 locale Abs_Int_fun_measure = |
463 locale Abs_Int_fun_measure = |
464 Abs_Int_fun_mono where \<gamma>=\<gamma> + Measure_fun where m=m |
464 Abs_Int_fun_mono where \<gamma>=\<gamma> + Measure_fun where m=m |
465 for \<gamma> :: "'av::semilattice \<Rightarrow> val set" and m :: "'av \<Rightarrow> nat" |
465 for \<gamma> :: "'av::semilattice \<Rightarrow> val set" and m :: "'av \<Rightarrow> nat" |
466 begin |
466 begin |
467 |
467 |
468 lemma top_on_step': "\<lbrakk> vars C \<subseteq> -X; top_on_acom X C \<rbrakk> \<Longrightarrow> top_on_acom X (step' \<top> C)" |
468 lemma top_on_step': "\<lbrakk> vars C \<subseteq> X; top_on_acom (-X) C \<rbrakk> \<Longrightarrow> top_on_acom (-X) (step' \<top> C)" |
469 unfolding step'_def |
469 unfolding step'_def |
470 by(rule top_on_Step) |
470 by(rule top_on_Step) |
471 (auto simp add: top_option_def fa_def split: option.splits) |
471 (auto simp add: top_option_def fa_def split: option.splits) |
472 |
472 |
473 lemma AI_Some_measure: "\<exists>C. AI c = Some C" |
473 lemma AI_Some_measure: "\<exists>C. AI c = Some C" |