# HG changeset patch # User nipkow # Date 1348489327 -7200 # Node ID 8192dc55bda9b7ab0178752faa4233c7e3c2338c # Parent 78be750222cf4963f3e44c3be435046a8bce5d29 generalized types diff -r 78be750222cf -r 8192dc55bda9 src/HOL/IMP/Abs_Int3.thy --- a/src/HOL/IMP/Abs_Int3.thy Mon Sep 24 06:58:09 2012 +0200 +++ b/src/HOL/IMP/Abs_Int3.thy Mon Sep 24 14:22:07 2012 +0200 @@ -178,23 +178,32 @@ "map2_acom f ({a1} WHILE b DO {p} C {a2}) ({a3} WHILE b' DO {p'} C' {a4}) = ({f a1 a3} WHILE b DO {f p p'} map2_acom f C C' {f a2 a4})" + +instantiation acom :: (widen)widen +begin +definition "widen_acom = map2_acom (op \)" +instance .. +end + +instantiation acom :: (narrow)narrow +begin +definition "narrow_acom = map2_acom (op \)" +instance .. +end + instantiation acom :: (WN_Lc)WN_Lc begin -definition "widen_acom = map2_acom (op \)" - -definition "narrow_acom = map2_acom (op \)" - -lemma widen_acom1: - "\\a\set(annos x). a \ Lc c; \a\set (annos y). a \ Lc c; strip x = strip y\ - \ x \ x \ y" -by(induct x y rule: le_acom.induct) +lemma widen_acom1: fixes C1 :: "'a acom" shows + "\\a\set(annos C1). a \ Lc c; \a\set (annos C2). a \ Lc c; strip C1 = strip C2\ + \ C1 \ C1 \ C2" +by(induct C1 C2 rule: le_acom.induct) (auto simp: widen_acom_def widen1 Lc_acom_def) -lemma widen_acom2: - "\\a\set(annos x). a \ Lc c; \a\set (annos y). a \ Lc c; strip x = strip y\ - \ y \ x \ y" -by(induct x y rule: le_acom.induct) +lemma widen_acom2: fixes C1 :: "'a acom" shows + "\\a\set(annos C1). a \ Lc c; \a\set (annos C2). a \ Lc c; strip C1 = strip C2\ + \ C2 \ C1 \ C2" +by(induct C1 C2 rule: le_acom.induct) (auto simp: widen_acom_def widen2 Lc_acom_def) lemma strip_map2_acom[simp]: @@ -203,11 +212,11 @@ lemma strip_widen_acom[simp]: "strip C1 = strip C2 \ strip(C1 \ C2) = strip C1" -by(simp add: widen_acom_def strip_map2_acom) +by(simp add: widen_acom_def) lemma strip_narrow_acom[simp]: "strip C1 = strip C2 \ strip(C1 \ C2) = strip C1" -by(simp add: narrow_acom_def strip_map2_acom) +by(simp add: narrow_acom_def) lemma annos_map2_acom[simp]: "strip C2 = strip C1 \ annos(map2_acom f C1 C2) = map (%(x,y).f x y) (zip (annos C1) (annos C2))" @@ -261,17 +270,17 @@ subsubsection "Post-fixed point computation" definition iter_widen :: "('a \ 'a) \ 'a \ ('a::{preord,widen})option" -where "iter_widen f = while_option (\c. \ f c \ c) (\c. c \ f c)" +where "iter_widen f = while_option (\x. \ f x \ x) (\x. x \ f x)" definition iter_narrow :: "('a \ 'a) \ 'a \ ('a::{preord,narrow})option" -where "iter_narrow f = while_option (\c. \ c \ c \ f c) (\c. c \ f c)" +where "iter_narrow f = while_option (\x. \ x \ x \ f x) (\x. x \ f x)" -definition pfp_wn :: "(('a::WN_Lc option acom) \ 'a option acom) \ com \ 'a option acom option" -where "pfp_wn f c = - (case iter_widen f (bot c) of None \ None | Some c' \ iter_narrow f c')" +definition pfp_wn :: "('a::{preord,widen,narrow} \ 'a) \ 'a \ 'a option" +where "pfp_wn f x = + (case iter_widen f x of None \ None | Some y \ iter_narrow f y)" -lemma iter_widen_pfp: "iter_widen f c = Some c' \ f c' \ c'" +lemma iter_widen_pfp: "iter_widen f x = Some p \ f p \ p" by(auto simp add: iter_widen_def dest: while_option_stop) lemma iter_widen_inv: @@ -286,7 +295,7 @@ using while_option_rule[where P = "\C'. strip C' = strip C", OF _ assms(2)] by (metis assms(1)) -lemma strip_iter_widen: fixes f :: "'a::WN_Lc acom \ 'a acom" +lemma strip_iter_widen: fixes f :: "'a::{preord,widen} acom \ 'a acom" assumes "\C. strip (f C) = strip C" and "iter_widen f C = Some C'" shows "strip C' = strip C" proof- @@ -296,25 +305,25 @@ qed lemma iter_narrow_pfp: -assumes mono: "!!c1 c2::_::WN_Lc. P c1 \ P c2 \ c1 \ c2 \ f c1 \ f c2" -and Pinv: "!!c. P c \ P(f c)" "!!c1 c2. P c1 \ P c2 \ P(c1 \ c2)" and "P c0" -and "f c0 \ c0" and "iter_narrow f c0 = Some c" -shows "P c \ f c \ c" +assumes mono: "!!x1 x2::_::WN_Lc. P x1 \ P x2 \ x1 \ x2 \ f x1 \ f x2" +and Pinv: "!!x. P x \ P(f x)" "!!x1 x2. P x1 \ P x2 \ P(x1 \ x2)" and "P x0" +and "f x0 \ x0" and "iter_narrow f x0 = Some x" +shows "P x \ f x \ x" proof- - let ?Q = "%c. P c \ f c \ c \ c \ c0" - { fix c assume "?Q c" + let ?Q = "%x. P x \ f x \ x \ x \ x0" + { fix x assume "?Q x" note P = conjunct1[OF this] and 12 = conjunct2[OF this] note 1 = conjunct1[OF 12] and 2 = conjunct2[OF 12] - let ?c' = "c \ f c" - have "?Q ?c'" + let ?x' = "x \ f x" + have "?Q ?x'" proof auto - show "P ?c'" by (blast intro: P Pinv) - have "f ?c' \ f c" by(rule mono[OF `P (c \ f c)` P narrow2[OF 1]]) - also have "\ \ ?c'" by(rule narrow1[OF 1]) - finally show "f ?c' \ ?c'" . - have "?c' \ c" by (rule narrow2[OF 1]) - also have "c \ c0" by(rule 2) - finally show "?c' \ c0" . + show "P ?x'" by (blast intro: P Pinv) + have "f ?x' \ f x" by(rule mono[OF `P (x \ f x)` P narrow2[OF 1]]) + also have "\ \ ?x'" by(rule narrow1[OF 1]) + finally show "f ?x' \ ?x'" . + have "?x' \ x" by (rule narrow2[OF 1]) + also have "x \ x0" by(rule 2) + finally show "?x' \ x0" . qed } thus ?thesis @@ -323,14 +332,14 @@ qed lemma pfp_wn_pfp: -assumes mono: "!!c1 c2::_::WN_Lc option acom. P c1 \ P c2 \ c1 \ c2 \ f c1 \ f c2" -and Pinv: "P (bot c)" "!!c. P c \ P(f c)" - "!!c1 c2. P c1 \ P c2 \ P(c1 \ c2)" - "!!c1 c2. P c1 \ P c2 \ P(c1 \ c2)" -and pfp_wn: "pfp_wn f c = Some c'" shows "P c' \ f c' \ c'" +assumes mono: "!!x1 x2::_::WN_Lc. P x1 \ P x2 \ x1 \ x2 \ f x1 \ f x2" +and Pinv: "P x" "!!x. P x \ P(f x)" + "!!x1 x2. P x1 \ P x2 \ P(x1 \ x2)" + "!!x1 x2. P x1 \ P x2 \ P(x1 \ x2)" +and pfp_wn: "pfp_wn f x = Some x'" shows "P x' \ f x' \ x'" proof- from pfp_wn obtain p - where its: "iter_widen f (bot c) = Some p" "iter_narrow f p = Some c'" + where its: "iter_widen f x = Some p" "iter_narrow f p = Some x'" by(auto simp: pfp_wn_def split: option.splits) have "P p" by (blast intro: iter_widen_inv[where P="P"] its(1) Pinv(1-3)) thus ?thesis @@ -339,9 +348,9 @@ qed lemma strip_pfp_wn: - "\ \c. strip(f c) = strip c; pfp_wn f c = Some c' \ \ strip c' = c" + "\ \C. strip(f C) = strip C; pfp_wn f C = Some C' \ \ strip C' = strip C" by(auto simp add: pfp_wn_def iter_narrow_def split: option.splits) - (metis (no_types) narrow_acom_def strip_bot strip_iter_widen strip_map2_acom strip_while) + (metis (no_types) narrow_acom_def strip_iter_widen strip_map2_acom strip_while) locale Abs_Int2 = Abs_Int1_mono @@ -349,13 +358,13 @@ begin definition AI_wn :: "com \ 'av st option acom option" where -"AI_wn c = pfp_wn (step' (top c)) c" +"AI_wn c = pfp_wn (step' (top c)) (bot c)" lemma AI_wn_sound: "AI_wn c = Some C \ CS c \ \\<^isub>c C" proof(simp add: CS_def AI_wn_def) - assume 1: "pfp_wn (step' (top c)) c = Some C" + assume 1: "pfp_wn (step' (top c)) (bot c) = Some C" have 2: "(strip C = c & C \ L(vars c)) \ step' \\<^bsub>c\<^esub> C \ C" - by(rule pfp_wn_pfp[where c=c]) + by(rule pfp_wn_pfp[where x="bot c"]) (simp_all add: 1 mono_step'_top widen_c_in_L narrow_c_in_L) have 3: "strip (\\<^isub>c (step' \\<^bsub>c\<^esub> C)) = c" by(simp add: strip_pfp_wn[OF _ 1]) have "lfp c (step UNIV) \ \\<^isub>c (step' \\<^bsub>c\<^esub> C)"