# HG changeset patch # User nipkow # Date 1367915695 -7200 # Node ID 93a976fcb01f8d558aa17f32fdafeb4876ca260c # Parent 150d3494a8f273b184dff46de7049a61589f2b95 tuned name: filter -> constrain (longer but more intuitive) diff -r 150d3494a8f2 -r 93a976fcb01f src/HOL/IMP/Abs_Int2.thy --- a/src/HOL/IMP/Abs_Int2.thy Tue May 07 03:24:23 2013 +0200 +++ b/src/HOL/IMP/Abs_Int2.thy Tue May 07 10:34:55 2013 +0200 @@ -48,12 +48,12 @@ locale Val_abs1 = Val_abs1_gamma where \ = \ for \ :: "'av::bounded_lattice \ val set" + fixes test_num' :: "val \ 'av \ bool" -and filter_plus' :: "'av \ 'av \ 'av \ 'av * 'av" -and filter_less' :: "bool \ 'av \ 'av \ 'av * 'av" +and constrain_plus' :: "'av \ 'av \ 'av \ 'av * 'av" +and constrain_less' :: "bool \ 'av \ 'av \ 'av * 'av" assumes test_num': "test_num' i a = (i : \ a)" -and filter_plus': "filter_plus' a a1 a2 = (a\<^isub>1',a\<^isub>2') \ +and constrain_plus': "constrain_plus' a a1 a2 = (a\<^isub>1',a\<^isub>2') \ i1 : \ a1 \ i2 : \ a2 \ i1+i2 : \ a \ i1 : \ a\<^isub>1' \ i2 : \ a\<^isub>2'" -and filter_less': "filter_less' (i11',a\<^isub>2') \ +and constrain_less': "constrain_less' (i11',a\<^isub>2') \ i1 : \ a1 \ i2 : \ a2 \ i1 : \ a\<^isub>1' \ i2 : \ a\<^isub>2'" @@ -74,14 +74,14 @@ subsubsection "Backward analysis" -fun afilter :: "aexp \ 'av \ 'av st option \ 'av st option" where -"afilter (N n) a S = (if test_num' n a then S else None)" | -"afilter (V x) a S = (case S of None \ None | Some S \ +fun aconstrain :: "aexp \ 'av \ 'av st option \ 'av st option" where +"aconstrain (N n) a S = (if test_num' n a then S else None)" | +"aconstrain (V x) a S = (case S of None \ None | Some S \ let a' = fun S x \ a in if a' = \ then None else Some(update S x a'))" | -"afilter (Plus e1 e2) a S = - (let (a1,a2) = filter_plus' a (aval'' e1 S) (aval'' e2 S) - in afilter e1 a1 (afilter e2 a2 S))" +"aconstrain (Plus e1 e2) a S = + (let (a1,a2) = constrain_plus' a (aval'' e1 S) (aval'' e2 S) + in aconstrain e1 a1 (aconstrain e2 a2 S))" text{* The test for @{const bot} in the @{const V}-case is important: @{const bot} indicates that a variable has no possible values, i.e.\ that the current @@ -93,17 +93,17 @@ making the analysis less precise. *} -fun bfilter :: "bexp \ bool \ 'av st option \ 'av st option" where -"bfilter (Bc v) res S = (if v=res then S else None)" | -"bfilter (Not b) res S = bfilter b (\ res) S" | -"bfilter (And b1 b2) res S = - (if res then bfilter b1 True (bfilter b2 True S) - else bfilter b1 False S \ bfilter b2 False S)" | -"bfilter (Less e1 e2) res S = - (let (a1,a2) = filter_less' res (aval'' e1 S) (aval'' e2 S) - in afilter e1 a1 (afilter e2 a2 S))" +fun bconstrain :: "bexp \ bool \ 'av st option \ 'av st option" where +"bconstrain (Bc v) res S = (if v=res then S else None)" | +"bconstrain (Not b) res S = bconstrain b (\ res) S" | +"bconstrain (And b1 b2) res S = + (if res then bconstrain b1 True (bconstrain b2 True S) + else bconstrain b1 False S \ bconstrain b2 False S)" | +"bconstrain (Less e1 e2) res S = + (let (a1,a2) = constrain_less' res (aval'' e1 S) (aval'' e2 S) + in aconstrain e1 a1 (aconstrain e2 a2 S))" -lemma afilter_sound: "s : \\<^isub>o S \ aval e s : \ a \ s : \\<^isub>o (afilter e a S)" +lemma aconstrain_sound: "s : \\<^isub>o S \ aval e s : \ a \ s : \\<^isub>o (aconstrain e a S)" proof(induction e arbitrary: a S) case N thus ?case by simp (metis test_num') next @@ -118,11 +118,11 @@ (metis mono_gamma emptyE in_gamma_inf gamma_bot subset_empty) next case (Plus e1 e2) thus ?case - using filter_plus'[OF _ aval''_sound aval''_sound] + using constrain_plus'[OF _ aval''_sound aval''_sound] by (auto split: prod.split) qed -lemma bfilter_sound: "s : \\<^isub>o S \ bv = bval b s \ s : \\<^isub>o(bfilter b bv S)" +lemma bconstrain_sound: "s : \\<^isub>o S \ bv = bval b s \ s : \\<^isub>o(bconstrain b bv S)" proof(induction b arbitrary: S bv) case Bc thus ?case by simp next @@ -133,12 +133,12 @@ next case (Less e1 e2) thus ?case by(auto split: prod.split) - (metis (lifting) afilter_sound aval''_sound filter_less') + (metis (lifting) aconstrain_sound aval''_sound constrain_less') qed definition "step' = Step (\x e S. case S of None \ None | Some S \ Some(update S x (aval' e S))) - (\b S. bfilter b True S)" + (\b S. bconstrain b True S)" definition AI :: "com \ 'av st option acom option" where "AI c = pfp (step' \) (bot c)" @@ -146,23 +146,23 @@ lemma strip_step'[simp]: "strip(step' S c) = strip c" by(simp add: step'_def) -lemma top_on_afilter: "\ top_on_opt S X; vars e \ -X \ \ top_on_opt (afilter e a S) X" +lemma top_on_aconstrain: "\ top_on_opt S X; vars e \ -X \ \ top_on_opt (aconstrain e a S) X" by(induction e arbitrary: a S) (auto simp: Let_def split: option.splits prod.split) -lemma top_on_bfilter: "\top_on_opt S X; vars b \ -X\ \ top_on_opt (bfilter b r S) X" -by(induction b arbitrary: r S) (auto simp: top_on_afilter top_on_sup split: prod.split) +lemma top_on_bconstrain: "\top_on_opt S X; vars b \ -X\ \ top_on_opt (bconstrain b r S) X" +by(induction b arbitrary: r S) (auto simp: top_on_aconstrain top_on_sup split: prod.split) lemma top_on_step': "top_on_acom C (- vars C) \ top_on_acom (step' \ C) (- vars C)" unfolding step'_def by(rule top_on_Step) - (auto simp add: top_on_top top_on_bfilter split: option.split) + (auto simp add: top_on_top top_on_bconstrain split: option.split) subsubsection "Soundness" lemma step_step': "step (\\<^isub>o S) (\\<^isub>c C) \ \\<^isub>c (step' S C)" unfolding step_def step'_def by(rule gamma_Step_subcomm) - (auto simp: intro!: aval'_sound bfilter_sound in_gamma_update split: option.splits) + (auto simp: intro!: aval'_sound bconstrain_sound in_gamma_update split: option.splits) lemma AI_sound: "AI c = Some C \ CS c \ \\<^isub>c C" proof(simp add: CS_def AI_def) @@ -186,10 +186,10 @@ locale Abs_Int1_mono = Abs_Int1 + assumes mono_plus': "a1 \ b1 \ a2 \ b2 \ plus' a1 a2 \ plus' b1 b2" -and mono_filter_plus': "a1 \ b1 \ a2 \ b2 \ r \ r' \ - filter_plus' r a1 a2 \ filter_plus' r' b1 b2" -and mono_filter_less': "a1 \ b1 \ a2 \ b2 \ - filter_less' bv a1 a2 \ filter_less' bv b1 b2" +and mono_constrain_plus': "a1 \ b1 \ a2 \ b2 \ r \ r' \ + constrain_plus' r a1 a2 \ constrain_plus' r' b1 b2" +and mono_constrain_less': "a1 \ b1 \ a2 \ b2 \ + constrain_less' bv a1 a2 \ constrain_less' bv b1 b2" begin lemma mono_aval': @@ -204,28 +204,28 @@ apply simp by (simp add: mono_aval') -lemma mono_afilter: "r1 \ r2 \ S1 \ S2 \ afilter e r1 S1 \ afilter e r2 S2" +lemma mono_aconstrain: "r1 \ r2 \ S1 \ S2 \ aconstrain e r1 S1 \ aconstrain e r2 S2" apply(induction e arbitrary: r1 r2 S1 S2) apply(auto simp: test_num' Let_def inf_mono split: option.splits prod.splits) apply (metis mono_gamma subsetD) apply (metis le_bot inf_mono le_st_iff) apply (metis inf_mono mono_update le_st_iff) -apply(metis mono_aval'' mono_filter_plus'[simplified less_eq_prod_def] fst_conv snd_conv) +apply(metis mono_aval'' mono_constrain_plus'[simplified less_eq_prod_def] fst_conv snd_conv) done -lemma mono_bfilter: "S1 \ S2 \ bfilter b bv S1 \ bfilter b bv S2" +lemma mono_bconstrain: "S1 \ S2 \ bconstrain b bv S1 \ bconstrain b bv S2" apply(induction b arbitrary: bv S1 S2) apply(simp) apply(simp) apply simp apply(metis order_trans[OF _ sup_ge1] order_trans[OF _ sup_ge2]) apply (simp split: prod.splits) -apply(metis mono_aval'' mono_afilter mono_filter_less'[simplified less_eq_prod_def] fst_conv snd_conv) +apply(metis mono_aval'' mono_aconstrain mono_constrain_less'[simplified less_eq_prod_def] fst_conv snd_conv) done theorem mono_step': "S1 \ S2 \ C1 \ C2 \ step' S1 C1 \ step' S2 C2" unfolding step'_def -by(rule mono2_Step) (auto simp: mono_aval' mono_bfilter split: option.split) +by(rule mono2_Step) (auto simp: mono_aval' mono_bconstrain split: option.split) lemma mono_step'_top: "C1 \ C2 \ step' \ C1 \ step' \ C2" by (metis mono_step' order_refl) diff -r 150d3494a8f2 -r 93a976fcb01f src/HOL/IMP/Abs_Int2_ivl.thy --- a/src/HOL/IMP/Abs_Int2_ivl.thy Tue May 07 03:24:23 2013 +0200 +++ b/src/HOL/IMP/Abs_Int2_ivl.thy Tue May 07 10:34:55 2013 +0200 @@ -259,8 +259,8 @@ end -definition filter_plus_ivl :: "ivl \ ivl \ ivl \ ivl*ivl" where -"filter_plus_ivl iv iv1 iv2 = (iv1 \ (iv - iv2), iv2 \ (iv - iv1))" +definition constrain_plus_ivl :: "ivl \ ivl \ ivl \ ivl*ivl" where +"constrain_plus_ivl iv iv1 iv2 = (iv1 \ (iv - iv2), iv2 \ (iv - iv1))" definition above_rep :: "eint2 \ eint2" where "above_rep p = (if is_empty_rep p then empty_rep else let (l,h) = p in (l,\))" @@ -284,8 +284,8 @@ (auto simp add: below_rep_def \_rep_cases is_empty_rep_def split: extended.splits) -definition filter_less_ivl :: "bool \ ivl \ ivl \ ivl * ivl" where -"filter_less_ivl res iv1 iv2 = +definition constrain_less_ivl :: "bool \ ivl \ ivl \ ivl * ivl" where +"constrain_less_ivl res iv1 iv2 = (if res then (iv1 \ (below iv2 - [Fin 1\Fin 1]), iv2 \ (above iv1 + [Fin 1\Fin 1])) @@ -333,18 +333,18 @@ interpretation Val_abs1 where \ = \_ivl and num' = num_ivl and plus' = "op +" and test_num' = in_ivl -and filter_plus' = filter_plus_ivl and filter_less' = filter_less_ivl +and constrain_plus' = constrain_plus_ivl and constrain_less' = constrain_less_ivl proof case goal1 thus ?case by transfer (auto simp: \_rep_def) next case goal2 thus ?case - unfolding filter_plus_ivl_def minus_ivl_def + unfolding constrain_plus_ivl_def minus_ivl_def apply(clarsimp simp add: \_inf) using gamma_plus'[of "i1+i2" _ "-i1"] gamma_plus'[of "i1+i2" _ "-i2"] by(simp add: \_uminus) next case goal3 thus ?case - unfolding filter_less_ivl_def minus_ivl_def + unfolding constrain_less_ivl_def minus_ivl_def apply(clarsimp simp add: \_inf split: if_splits) using gamma_plus'[of "i1+1" _ "-1"] gamma_plus'[of "i2 - 1" _ "1"] apply(simp add: \_belowI[of i2] \_aboveI[of i1] @@ -356,9 +356,9 @@ interpretation Abs_Int1 where \ = \_ivl and num' = num_ivl and plus' = "op +" and test_num' = in_ivl -and filter_plus' = filter_plus_ivl and filter_less' = filter_less_ivl -defines afilter_ivl is afilter -and bfilter_ivl is bfilter +and constrain_plus' = constrain_plus_ivl and constrain_less' = constrain_less_ivl +defines aconstrain_ivl is aconstrain +and bconstrain_ivl is bconstrain and step_ivl is step' and AI_ivl is AI and aval_ivl' is aval'' @@ -390,16 +390,16 @@ interpretation Abs_Int1_mono where \ = \_ivl and num' = num_ivl and plus' = "op +" and test_num' = in_ivl -and filter_plus' = filter_plus_ivl and filter_less' = filter_less_ivl +and constrain_plus' = constrain_plus_ivl and constrain_less' = constrain_less_ivl proof case goal1 thus ?case by (rule mono_plus_ivl) next case goal2 thus ?case - unfolding filter_plus_ivl_def minus_ivl_def less_eq_prod_def + unfolding constrain_plus_ivl_def minus_ivl_def less_eq_prod_def by (auto simp: le_infI1 le_infI2 mono_plus_ivl mono_minus_ivl) next case goal3 thus ?case - unfolding less_eq_prod_def filter_less_ivl_def minus_ivl_def + unfolding less_eq_prod_def constrain_less_ivl_def minus_ivl_def by (auto simp: le_infI1 le_infI2 mono_plus_ivl mono_above mono_below) qed diff -r 150d3494a8f2 -r 93a976fcb01f src/HOL/IMP/Abs_Int3.thy --- a/src/HOL/IMP/Abs_Int3.thy Tue May 07 03:24:23 2013 +0200 +++ b/src/HOL/IMP/Abs_Int3.thy Tue May 07 10:34:55 2013 +0200 @@ -271,7 +271,7 @@ interpretation Abs_Int2 where \ = \_ivl and num' = num_ivl and plus' = "op +" and test_num' = in_ivl -and filter_plus' = filter_plus_ivl and filter_less' = filter_less_ivl +and constrain_plus' = constrain_plus_ivl and constrain_less' = constrain_less_ivl defines AI_ivl' is AI_wn .. @@ -551,7 +551,7 @@ interpretation Abs_Int2_measure where \ = \_ivl and num' = num_ivl and plus' = "op +" and test_num' = in_ivl -and filter_plus' = filter_plus_ivl and filter_less' = filter_less_ivl +and constrain_plus' = constrain_plus_ivl and constrain_less' = constrain_less_ivl and m = m_ivl and n = n_ivl and h = 3 proof case goal2 thus ?case by(rule m_ivl_anti_mono)