
diff -r 323414474c1f -r 73fb17ed2e08 src/HOL/IMP/Abs_Int1.thy
--- a/src/HOL/IMP/Abs_Int1.thy	Sun Sep 16 10:33:25 2012 +0200
+++ b/src/HOL/IMP/Abs_Int1.thy	Sun Sep 16 11:50:03 2012 +0200
@@ -13,26 +13,26 @@
 by(auto simp add: le_iff_le_annos_zip set_zip) (metis size_annos_same2)
 
 
-lemma mono_fun_wt[simp]: "wt F X \<Longrightarrow> F \<sqsubseteq> G \<Longrightarrow> x : X \<Longrightarrow> fun F x \<sqsubseteq> fun G x"
-by(simp add: mono_fun wt_st_def)
+lemma mono_fun_L[simp]: "F \<in> L X \<Longrightarrow> F \<sqsubseteq> G \<Longrightarrow> x : X \<Longrightarrow> fun F x \<sqsubseteq> fun G x"
+by(simp add: mono_fun L_st_def)
 
-lemma wt_bot[simp]: "wt (bot c) (vars c)"
-by(simp add: wt_acom_def bot_def)
+lemma bot_in_L[simp]: "bot c \<in> L(vars c)"
+by(simp add: L_acom_def bot_def)
 
-lemma wt_acom_simps[simp]: "wt (SKIP {P}) X \<longleftrightarrow> wt P X"
-  "wt (x ::= e {P}) X \<longleftrightarrow> x : X \<and> vars e \<subseteq> X \<and> wt P X"
-  "wt (C1;C2) X \<longleftrightarrow> wt C1 X \<and> wt C2 X"
-  "wt (IF b THEN {P1} C1 ELSE {P2} C2 {Q}) X \<longleftrightarrow>
-   vars b \<subseteq> X \<and> wt C1 X \<and> wt C2 X \<and> wt P1 X \<and> wt P2 X \<and> wt Q X"
-  "wt ({I} WHILE b DO {P} C {Q}) X \<longleftrightarrow>
-   wt I X \<and> vars b \<subseteq> X \<and> wt P X \<and> wt C X \<and> wt Q X"
-by(auto simp add: wt_acom_def)
+lemma L_acom_simps[simp]: "SKIP {P} \<in> L X \<longleftrightarrow> P \<in> L X"
+  "(x ::= e {P}) \<in> L X \<longleftrightarrow> x : X \<and> vars e \<subseteq> X \<and> P \<in> L X"
+  "(C1;C2) \<in> L X \<longleftrightarrow> C1 \<in> L X \<and> C2 \<in> L X"
+  "(IF b THEN {P1} C1 ELSE {P2} C2 {Q}) \<in> L X \<longleftrightarrow>
+   vars b \<subseteq> X \<and> C1 \<in> L X \<and> C2 \<in> L X \<and> P1 \<in> L X \<and> P2 \<in> L X \<and> Q \<in> L X"
+  "({I} WHILE b DO {P} C {Q}) \<in> L X \<longleftrightarrow>
+   I \<in> L X \<and> vars b \<subseteq> X \<and> P \<in> L X \<and> C \<in> L X \<and> Q \<in> L X"
+by(auto simp add: L_acom_def)
 
 lemma post_in_annos: "post C : set(annos C)"
 by(induction C) auto
 
-lemma wt_post[simp]: "wt C X \<Longrightarrow> wt (post C) X"
-by(simp add: wt_acom_def post_in_annos)
+lemma post_in_L[simp]: "C \<in> L X \<Longrightarrow> post C \<in> L X"
+by(simp add: L_acom_def post_in_annos)
 
 lemma lpfp_inv:
 assumes "lpfp f x0 = Some x" and "\<And>x. P x \<Longrightarrow> P(f x)" and "P(bot x0)"
@@ -63,7 +63,7 @@
 the name of the type parameter @{typ 'av} which would otherwise be renamed to
 @{typ 'a}. *}
 
-locale Abs_Int = Gamma where \<gamma>=\<gamma> for \<gamma> :: "'av::SL_top \<Rightarrow> val set"
+locale Abs_Int = Gamma where \<gamma>=\<gamma> for \<gamma> :: "'av::semilattice \<Rightarrow> val set"
 begin
 
 fun step' :: "'av st option \<Rightarrow> 'av st option acom \<Rightarrow> 'av st option acom" where
@@ -91,29 +91,29 @@
 by(simp add: \<gamma>_st_def)
 
 theorem step_preserves_le:
-  "\<lbrakk> S \<subseteq> \<gamma>\<^isub>o S'; C \<le> \<gamma>\<^isub>c C';  wt C' X; wt S' X \<rbrakk> \<Longrightarrow> step S C \<le> \<gamma>\<^isub>c (step' S' C')"
+  "\<lbrakk> S \<subseteq> \<gamma>\<^isub>o S'; C \<le> \<gamma>\<^isub>c C';  C' \<in> L X; S' \<in> L X \<rbrakk> \<Longrightarrow> step S C \<le> \<gamma>\<^isub>c (step' S' C')"
 proof(induction C arbitrary: C' S S')
   case SKIP thus ?case by(auto simp:SKIP_le map_acom_SKIP)
 next
   case Assign thus ?case
-    by(fastforce simp: Assign_le map_acom_Assign wt_st_def
+    by(fastforce simp: Assign_le map_acom_Assign L_st_def
         intro: aval'_sound in_gamma_update split: option.splits)
 next
   case Seq thus ?case apply (auto simp: Seq_le map_acom_Seq)
-    by (metis le_post post_map_acom wt_post)
+    by (metis le_post post_map_acom post_in_L)
 next
   case (If b P1 C1 P2 C2 Q)
   then obtain P1' P2' C1' C2' Q' where
       "C' = IF b THEN {P1'} C1' ELSE {P2'} C2' {Q'}"
       "P1 \<subseteq> \<gamma>\<^isub>o P1'" "P2 \<subseteq> \<gamma>\<^isub>o P2'" "Q \<subseteq> \<gamma>\<^isub>o Q'" "C1 \<le> \<gamma>\<^isub>c C1'" "C2 \<le> \<gamma>\<^isub>c C2'"
     by (fastforce simp: If_le map_acom_If)
-  moreover from this(1) `wt C' X` have wt: "wt C1' X" "wt C2' X" "wt P1' X" "wt P2' X"
-    by simp_all
+  moreover from this(1) `C' \<in> L X`
+  have L: "C1' \<in> L X" "C2' \<in> L X" "P1' \<in> L X" "P2' \<in> L X" by simp_all
   moreover have "post C1 \<subseteq> \<gamma>\<^isub>o(post C1' \<squnion> post C2')"
-    by (metis (no_types) `C1 \<le> \<gamma>\<^isub>c C1'` join_ge1 le_post mono_gamma_o order_trans post_map_acom wt wt_post)
+    by (metis (no_types) `C1 \<le> \<gamma>\<^isub>c C1'` join_ge1 le_post mono_gamma_o order_trans post_map_acom L post_in_L)
   moreover have "post C2 \<subseteq> \<gamma>\<^isub>o(post C1' \<squnion> post C2')"
-    by (metis (no_types) `C2 \<le> \<gamma>\<^isub>c C2'` join_ge2 le_post mono_gamma_o order_trans post_map_acom wt wt_post)
-  ultimately show ?case using `S \<subseteq> \<gamma>\<^isub>o S'` `wt S' X`
+    by (metis (no_types) `C2 \<le> \<gamma>\<^isub>c C2'` join_ge2 le_post mono_gamma_o order_trans post_map_acom L post_in_L)
+  ultimately show ?case using `S \<subseteq> \<gamma>\<^isub>o S'` `S' \<in> L X`
     by (simp add: If.IH subset_iff)
 next
   case (While I b P1 C1 Q)
@@ -121,35 +121,35 @@
     "C' = {I'} WHILE b DO {P1'} C1' {Q'}"
     "I \<subseteq> \<gamma>\<^isub>o I'" "P1 \<subseteq> \<gamma>\<^isub>o P1'" "C1 \<le> \<gamma>\<^isub>c C1'" "Q \<subseteq> \<gamma>\<^isub>o Q'" 
     by (fastforce simp: map_acom_While While_le)
-  moreover from this(1) `wt C' X`
-  have wt: "wt C1' X" "wt I' X" "wt P1' X" by simp_all
-  moreover note compat = `wt S' X` wt_post[OF wt(1)]
+  moreover from this(1) `C' \<in> L X`
+  have L: "C1' \<in> L X" "I' \<in> L X" "P1' \<in> L X" by simp_all
+  moreover note compat = `S' \<in> L X` post_in_L[OF L(1)]
   moreover have "S \<union> post C1 \<subseteq> \<gamma>\<^isub>o (S' \<squnion> post C1')"
     using `S \<subseteq> \<gamma>\<^isub>o S'` le_post[OF `C1 \<le> \<gamma>\<^isub>c C1'`, simplified]
     by (metis (no_types) join_ge1[OF compat] join_ge2[OF compat] le_sup_iff mono_gamma_o order_trans)
   ultimately show ?case by (simp add: While.IH subset_iff)
 qed
 
-lemma wt_step'[simp]:
-  "\<lbrakk> wt C X; wt S X \<rbrakk> \<Longrightarrow> wt (step' S C) X"
+lemma step'_in_L[simp]:
+  "\<lbrakk> C \<in> L X; S \<in> L X \<rbrakk> \<Longrightarrow> (step' S C) \<in> L X"
 proof(induction C arbitrary: S)
   case Assign thus ?case
-    by(auto simp: wt_st_def update_def split: option.splits)
+    by(auto simp: L_st_def update_def split: option.splits)
 qed auto
 
 theorem AI_sound: "AI c = Some C \<Longrightarrow> CS c \<le> \<gamma>\<^isub>c C"
 proof(simp add: CS_def AI_def)
   assume 1: "lpfp (step' (top c)) c = Some C"
-  have "wt C (vars c)"
-    by(rule lpfp_inv[where P = "%C. wt C (vars c)", OF 1 _ wt_bot])
-      (erule wt_step'[OF _ wt_top])
+  have "C \<in> L(vars c)"
+    by(rule lpfp_inv[where P = "%C. C \<in> L(vars c)", OF 1 _ bot_in_L])
+      (erule step'_in_L[OF _ top_in_L])
   have 2: "step' (top c) C \<sqsubseteq> C" by(rule lpfpc_pfp[OF 1])
   have 3: "strip (\<gamma>\<^isub>c (step' (top c) C)) = c"
     by(simp add: strip_lpfp[OF _ 1])
   have "lfp c (step UNIV) \<le> \<gamma>\<^isub>c (step' (top c) C)"
   proof(rule lfp_lowerbound[simplified,OF 3])
     show "step UNIV (\<gamma>\<^isub>c (step' (top c) C)) \<le> \<gamma>\<^isub>c (step' (top c) C)"
-    proof(rule step_preserves_le[OF _ _ `wt C (vars c)` wt_top])
+    proof(rule step_preserves_le[OF _ _ `C \<in> L(vars c)` top_in_L])
       show "UNIV \<subseteq> \<gamma>\<^isub>o (top c)" by simp
       show "\<gamma>\<^isub>c (step' (top c) C) \<le> \<gamma>\<^isub>c C" by(rule mono_gamma_c[OF 2])
     qed
@@ -163,26 +163,29 @@
 
 subsubsection "Monotonicity"
 
-lemma le_join_disj: "wt y X \<Longrightarrow> wt (z::_::SL_top_wt) X \<Longrightarrow> x \<sqsubseteq> y \<or> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<squnion> z"
+lemma le_join_disj: "y \<in> L X \<Longrightarrow> (z::_::semilatticeL) \<in> L X \<Longrightarrow>
+  x \<sqsubseteq> y \<or> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<squnion> z"
 by (metis join_ge1 join_ge2 preord_class.le_trans)
 
 locale Abs_Int_mono = Abs_Int +
 assumes mono_plus': "a1 \<sqsubseteq> b1 \<Longrightarrow> a2 \<sqsubseteq> b2 \<Longrightarrow> plus' a1 a2 \<sqsubseteq> plus' b1 b2"
 begin
 
-lemma mono_aval': "S1 \<sqsubseteq> S2 \<Longrightarrow> wt S1 X \<Longrightarrow> vars e \<subseteq> X \<Longrightarrow> aval' e S1 \<sqsubseteq> aval' e S2"
-by(induction e) (auto simp: le_st_def mono_plus' wt_st_def)
+lemma mono_aval':
+  "S1 \<sqsubseteq> S2 \<Longrightarrow> S1 \<in> L X \<Longrightarrow> vars e \<subseteq> X \<Longrightarrow> aval' e S1 \<sqsubseteq> aval' e S2"
+by(induction e) (auto simp: le_st_def mono_plus' L_st_def)
 
-theorem mono_step': "wt S1 X \<Longrightarrow> wt S2 X \<Longrightarrow> wt C1 X \<Longrightarrow> wt C2 X \<Longrightarrow>
+theorem mono_step': "S1 \<in> L X \<Longrightarrow> S2 \<in> L X \<Longrightarrow> C1 \<in> L X \<Longrightarrow> C2 \<in> L X \<Longrightarrow>
   S1 \<sqsubseteq> S2 \<Longrightarrow> C1 \<sqsubseteq> C2 \<Longrightarrow> step' S1 C1 \<sqsubseteq> step' S2 C2"
 apply(induction C1 C2 arbitrary: S1 S2 rule: le_acom.induct)
 apply (auto simp: Let_def mono_aval' mono_post
-  le_join_disj le_join_disj[OF  wt_post wt_post]
+  le_join_disj le_join_disj[OF  post_in_L post_in_L]
             split: option.split)
 done
 
-lemma mono_step'_top: "wt c (vars c0) \<Longrightarrow> wt c' (vars c0) \<Longrightarrow> c \<sqsubseteq> c' \<Longrightarrow> step' (top c0) c \<sqsubseteq> step' (top c0) c'"
-by (metis wt_top mono_step' preord_class.le_refl)
+lemma mono_step'_top: "C \<in> L(vars c) \<Longrightarrow> C' \<in> L(vars c) \<Longrightarrow>
+  C \<sqsubseteq> C' \<Longrightarrow> step' (top c) C \<sqsubseteq> step' (top c) C'"
+by (metis top_in_L mono_step' preord_class.le_refl)
 
 end
 
@@ -222,7 +225,7 @@
 
 
 locale Abs_Int_measure =
-  Abs_Int_mono where \<gamma>=\<gamma> for \<gamma> :: "'av::SL_top \<Rightarrow> val set" +
+  Abs_Int_mono where \<gamma>=\<gamma> for \<gamma> :: "'av::semilattice \<Rightarrow> val set" +
 fixes m :: "'av \<Rightarrow> nat"
 fixes h :: "nat"
 assumes m1: "x \<sqsubseteq> y \<Longrightarrow> m x \<ge> m y"
@@ -255,27 +258,27 @@
 "m_o d opt = (case opt of None \<Rightarrow> h*d+1 | Some S \<Rightarrow> m_st S)"
 
 definition m_c :: "'av st option acom \<Rightarrow> nat" where
-"m_c c = (\<Sum>i<size(annos c). m_o (card(vars(strip c))) (annos c ! i))"
+"m_c C = (\<Sum>i<size(annos C). m_o (card(vars(strip C))) (annos C ! i))"
 
-lemma m_st_h: "wt x X \<Longrightarrow> finite X \<Longrightarrow> m_st x \<le> h * card X"
-by(simp add: wt_st_def m_st_def)
+lemma m_st_h: "x \<in> L X \<Longrightarrow> finite X \<Longrightarrow> m_st x \<le> h * card X"
+by(simp add: L_st_def m_st_def)
   (metis nat_mult_commute of_nat_id setsum_bounded[OF h])
 
-lemma m_o1: "finite X \<Longrightarrow> wt o1 X \<Longrightarrow> wt o2 X \<Longrightarrow>
+lemma m_o1: "finite X \<Longrightarrow> o1 \<in> L X \<Longrightarrow> o2 \<in> L X \<Longrightarrow>
   o1 \<sqsubseteq> o2 \<Longrightarrow> m_o (card X) o1 \<ge> m_o (card X) o2"
 proof(induction o1 o2 rule: le_option.induct)
   case 1 thus ?case by (simp add: m_o_def)(metis m_st1)
 next
   case 2 thus ?case
-    by(simp add: wt_option_def m_o_def le_SucI m_st_h split: option.splits)
+    by(simp add: L_option_def m_o_def le_SucI m_st_h split: option.splits)
 next
   case 3 thus ?case by simp
 qed
 
-lemma m_o2: "finite X \<Longrightarrow> wt o1 X \<Longrightarrow> wt o2 X \<Longrightarrow>
+lemma m_o2: "finite X \<Longrightarrow> o1 \<in> L X \<Longrightarrow> o2 \<in> L X \<Longrightarrow>
   o1 \<sqsubset> o2 \<Longrightarrow> m_o (card X) o1 > m_o (card X) o2"
 proof(induction o1 o2 rule: le_option.induct)
-  case 1 thus ?case by (simp add: m_o_def wt_st_def m_st2)
+  case 1 thus ?case by (simp add: m_o_def L_st_def m_st2)
 next
   case 2 thus ?case
     by(auto simp add: m_o_def le_imp_less_Suc m_st_h)
@@ -283,30 +286,30 @@
   case 3 thus ?case by simp
 qed
 
-lemma m_c2: "wt c1 (vars(strip c1)) \<Longrightarrow> wt c2 (vars(strip c2)) \<Longrightarrow>
-  c1 \<sqsubset> c2 \<Longrightarrow> m_c c1 > m_c c2"
-proof(auto simp add: le_iff_le_annos m_c_def size_annos_same[of c1 c2] wt_acom_def)
-  let ?X = "vars(strip c2)"
+lemma m_c2: "C1 \<in> L(vars(strip C1)) \<Longrightarrow> C2 \<in> L(vars(strip C2)) \<Longrightarrow>
+  C1 \<sqsubset> C2 \<Longrightarrow> m_c C1 > m_c C2"
+proof(auto simp add: le_iff_le_annos m_c_def size_annos_same[of C1 C2] L_acom_def)
+  let ?X = "vars(strip C2)"
   let ?n = "card ?X"
-  assume V1: "\<forall>a\<in>set(annos c1). wt a ?X"
-    and V2: "\<forall>a\<in>set(annos c2). wt a ?X"
-    and strip_eq: "strip c1 = strip c2"
-    and 0: "\<forall>i<size(annos c2). annos c1 ! i \<sqsubseteq> annos c2 ! i"
-  hence 1: "\<forall>i<size(annos c2). m_o ?n (annos c1 ! i) \<ge> m_o ?n (annos c2 ! i)"
+  assume V1: "\<forall>a\<in>set(annos C1). a \<in> L ?X"
+    and V2: "\<forall>a\<in>set(annos C2). a \<in> L ?X"
+    and strip_eq: "strip C1 = strip C2"
+    and 0: "\<forall>i<size(annos C2). annos C1 ! i \<sqsubseteq> annos C2 ! i"
+  hence 1: "\<forall>i<size(annos C2). m_o ?n (annos C1 ! i) \<ge> m_o ?n (annos C2 ! i)"
     by (auto simp: all_set_conv_all_nth)
        (metis finite_cvars m_o1 size_annos_same2)
-  fix i assume "i < size(annos c2)" "\<not> annos c2 ! i \<sqsubseteq> annos c1 ! i"
-  hence "m_o ?n (annos c1 ! i) > m_o ?n (annos c2 ! i)" (is "?P i")
-    by(metis m_o2[OF finite_cvars] V1 V2 strip_eq nth_mem size_annos_same 0)
-  hence 2: "\<exists>i < size(annos c2). ?P i" using `i < size(annos c2)` by blast
-  show "(\<Sum>i<size(annos c2). m_o ?n (annos c2 ! i))
-         < (\<Sum>i<size(annos c2). m_o ?n (annos c1 ! i))"
+  fix i assume "i < size(annos C2)" "\<not> annos C2 ! i \<sqsubseteq> annos C1 ! i"
+  hence "m_o ?n (annos C1 ! i) > m_o ?n (annos C2 ! i)" (is "?P i")
+    by(metis m_o2[OF finite_cvars] V1 V2 nth_mem size_annos_same[OF strip_eq] 0)
+  hence 2: "\<exists>i < size(annos C2). ?P i" using `i < size(annos C2)` by blast
+  show "(\<Sum>i<size(annos C2). m_o ?n (annos C2 ! i))
+         < (\<Sum>i<size(annos C2). m_o ?n (annos C1 ! i))"
     apply(rule setsum_strict_mono_ex1) using 1 2 by (auto)
 qed
 
 lemma AI_Some_measure: "\<exists>C. AI c = Some C"
 unfolding AI_def
-apply(rule lpfp_termination[where I = "%C. strip C = c \<and> wt C (vars c)"
+apply(rule lpfp_termination[where I = "%C. strip C = c \<and> C \<in> L(vars c)"
   and m="m_c"])
 apply(simp_all add: m_c2 mono_step'_top)
 done




