named_theorems if_distribs "Distributivity theorems for If"
lemma if_mono_cong: "[b ==> x ≤ x'; ¬ b ==> y ≤ y' ]==> If b x y ≤ If b x' y'" by simp
lemma if_cong_then: "[ b = b'; b' ==> t = t'; e = e' ]==> If b t e = If b' t' e'" by simp
lemma if_False_eq: "[ b ==> False; e = e' ]==> If b t e = e'" by auto
lemma imp_OO_imp [simp]: "(⟶) OO (⟶) = (⟶)" by auto
lemma inj_on_fun_updD: "[ inj_on (f(x := y)) A; x ∉ A ]==> inj_on f A" by(auto simp add: inj_on_def split: if_split_asm)
lemma disjoint_notin1: "[ A ∩ B = {}; x ∈ B ]==> x ∉ A"by auto
lemma Least_le_Least: fixes x :: "'a :: wellorder" assumes"Q x" and Q: "∧x. Q x ==>∃y≤x. P y" shows"Least P ≤ Least Q" by (metis assms order_trans wellorder_Least_lemma)
inductive Imagep :: "('a ==> 'b ==> bool) ==> ('a ==> bool) ==> 'b ==> bool" for R P where ImagepI: "[ P x; R x y ]==> Imagep R P y"
lemma r_r_into_tranclp: "[ r x y; r y z ]==> r^++ x z" by(rule tranclp.trancl_into_trancl)(rule tranclp.r_into_trancl)
lemma transp_tranclp_id: assumes"transp R" shows"tranclp R = R" proof(intro ext iffI) fix x y assume"R^++ x y" thus"R x y"byinduction(blast dest: transpD[OF assms])+ qed simp
lemma transp_inv_image: "transp r ==> transp (λx y. r (f x) (f y))" using trans_inv_image[where r="{(x, y). r x y}"and f = f] by(simp add: transp_trans inv_image_def)
lemma bi_unique_rel_set_bij_betw: assumes unique: "bi_unique R" and rel: "rel_set R A B" shows"∃f. bij_betw f A B ∧ (∀x∈A. R x (f x))" proof - from assms obtain f where f: "∧x. x ∈ A ==> R x (f x)"and B: "∧x. x ∈ A ==> f x ∈ B" apply(atomize_elim) apply(fold all_conj_distrib) apply(subst choice_iff[symmetric]) apply(auto dest: rel_setD1) done have"inj_on f A"by(rule inj_onI)(auto dest!: f dest: bi_uniqueDl[OF unique]) moreoverhave"f ` A = B"using rel by(auto 43 intro: B dest: rel_setD2 f bi_uniqueDr[OF unique]) ultimatelyhave"bij_betw f A B"unfolding bij_betw_def .. thus ?thesis using f by blast qed
definition restrict_relp :: "('a ==> 'b ==> bool) ==> ('a ==> bool) ==> ('b ==> bool) ==> 'a ==> 'b ==> bool"
(‹_ ↿ (_ ⊗ _)› [53, 54, 54] 53) where"restrict_relp R P Q = (λx y. R x y ∧ P x ∧ Q y)"
lemma restrict_relp_apply [simp]: "(R ↿ P ⊗ Q) x y ⟷ R x y ∧ P x ∧ Q y" by(simp add: restrict_relp_def)
lemma restrict_relpI [intro?]: "[ R x y; P x; Q y ]==> (R ↿ P ⊗ Q) x y" by(simp add: restrict_relp_def)
lemma restrict_relpE [elim?, cases pred]: assumes"(R ↿ P ⊗ Q) x y" obtains (restrict_relp) "R x y""P x""Q y" using assms by(simp add: restrict_relp_def)
lemma restrict_relp_restrict_relp [simp]: "R ↿ P ⊗ Q ↿ P' ⊗ Q' = R ↿ inf P P' ⊗ inf Q Q'" by(auto simp add: fun_eq_iff)
lemma restrict_relp_cong: "[ P = P'; Q = Q'; ∧x y. [ P x; Q y ]==> R x y = R' x y ]==> R ↿ P ⊗ Q = R' ↿ P'⊗ Q'" by(auto simp add: fun_eq_iff)
lemma restrict_relp_cong_simp: "[ P = P'; Q = Q'; ∧x y. P x =simp=> Q y =simp=> R x y = R' x y ]==> R ↿ P ⊗ Q = R' ↿ P' ⊗ Q'" by(rule restrict_relp_cong; simp add: simp_implies_def)
lemma restrict_relp_parametric [transfer_rule]: includes lifting_syntax shows "((A ===> B ===> (=)) ===> (A ===> (=)) ===> (B ===> (=)) ===> A ===> B ===> (=)) restrict_relp restrict_relp" unfolding restrict_relp_def[abs_def] by transfer_prover
lemma restrict_relp_mono: "[ R ≤ R'; P ≤ P'; Q ≤ Q' ]==> R ↿ P ⊗ Q ≤ R' ↿ P' ⊗ Q'" by(simp add: le_fun_def)
lemma restrict_relp_mono': "[ (R ↿ P ⊗ Q) x y; [ R x y; P x; Q y ]==> R' x y &&& P' x &&& Q' y ] ==> (R' ↿ P' ⊗ Q') x y" by(auto dest: conjunctionD1 conjunctionD2)
lemma restrict_relp_DomainpD: "Domainp (R ↿ P ⊗ Q) x ==> Domainp R x ∧ P x" by(auto simp add: Domainp.simps)
lemma relcompp_witness_eq [simp]: "relcompp_witness (=) (=) (x, x) = x" using relcompp_witness(1)[of "(=)""(=)" x x] by(simp add: eq_OO)
subsection‹Pairs›
lemma split_apfst [simp]: "case_prod h (apfst f xy) = case_prod (h ∘ f) xy" by(cases xy) simp
definition corec_prod :: "('s ==> 'a) ==> ('s ==> 'b) ==> 's ==> 'a × 'b" where"corec_prod f g = (λs. (f s, g s))"
lemma corec_prod_apply: "corec_prod f g s = (f s, g s)" by(simp add: corec_prod_def)
lemma corec_prod_sel [simp]: shows fst_corec_prod: "fst (corec_prod f g s) = f s" and snd_corec_prod: "snd (corec_prod f g s) = g s" by(simp_all add: corec_prod_apply)
lemma apfst_corec_prod [simp]: "apfst h (corec_prod f g s) = corec_prod (h ∘ f) g s" by(simp add: corec_prod_apply)
lemma apsnd_corec_prod [simp]: "apsnd h (corec_prod f g s) = corec_prod f (h ∘ g) s" by(simp add: corec_prod_apply)
lemma map_corec_prod [simp]: "map_prod f g (corec_prod h k s) = corec_prod (f ∘ h) (g ∘ k) s" by(simp add: corec_prod_apply)
lemma split_corec_prod [simp]: "case_prod h (corec_prod f g s) = h (f s) (g s)" by(simp add: corec_prod_apply)
lemma rprodl_parametric [transfer_rule]: includes lifting_syntax shows "(rel_prod (rel_prod A B) C ===> rel_prod A (rel_prod B C)) rprodl rprodl" unfolding rprodl_def by transfer_prover
lemma lprodr_parametric [transfer_rule]: includes lifting_syntax shows "(rel_prod A (rel_prod B C) ===> rel_prod (rel_prod A B) C) lprodr lprodr" unfolding lprodr_def by transfer_prover
lemma islE: assumes"isl x" obtains l where"x = Inl l" using assms by(cases x) auto
lemma Inl_in_Plus [simp]: "Inl x ∈ A <+> B ⟷ x ∈ A" by auto
lemma Inr_in_Plus [simp]: "Inr x ∈ A <+> B ⟷ x ∈ B" by auto
lemma Inl_eq_map_sum_iff: "Inl x = map_sum f g y ⟷ (∃z. y = Inl z ∧ x = f z)" by(cases y) auto
lemma Inr_eq_map_sum_iff: "Inr x = map_sum f g y ⟷ (∃z. y = Inr z ∧ x = g z)" by(cases y) auto
lemma inj_on_map_sum [simp]: "[ inj_on f A; inj_on g B ]==> inj_on (map_sum f g) (A <+> B)" proof(rule inj_onI, goal_cases) case (1 x y) thenshow ?caseby(cases x; cases y; auto simp add: inj_on_def) qed
lemma inv_into_map_sum: "inv_into (A <+> B) (map_sum f g) x = map_sum (inv_into A f) (inv_into B g) x" if"x ∈ f ` A <+> g ` B""inj_on f A""inj_on g B" using that by(cases rule: PlusE[consumes 1])(auto simp add: inv_into_f_eq f_inv_into_f)
lemma rel_option_restrict_relpI [intro?]: "[ rel_option R x y; pred_option P x; pred_option Q y ]==> rel_option (R ↿ P ⊗ Q) x y" by(erule option.rel_mono_strong) simp
lemma rel_option_restrict_relpE [elim?]: assumes"rel_option (R ↿ P ⊗ Q) x y" obtains"rel_option R x y""pred_option P x""pred_option Q y" proof show"rel_option R x y"using assms by(auto elim!: option.rel_mono_strong) have"pred_option (Domainp (R ↿ P ⊗ Q)) x"using assms by(fold option.Domainp_rel) blast thenshow"pred_option P x"by(rule option_pred_mono_strong)(blast dest!: restrict_relp_DomainpD) have"pred_option (Domainp (R ↿ P ⊗ Q)-1-1) y"using assms by(fold option.Domainp_rel)(auto simp only: option.rel_conversep Domainp_conversep) thenshow"pred_option Q y"by(rule option_pred_mono_strong)(auto dest!: restrict_relp_DomainpD) qed
lemma rel_option_restrict_relp_iff: "rel_option (R ↿ P ⊗ Q) x y ⟷ rel_option R x y ∧ pred_option P x ∧ pred_option Q y" by(blast intro: rel_option_restrict_relpI elim: rel_option_restrict_relpE)
lemma option_rel_map_restrict_relp: shows option_rel_map_restrict_relp1: "rel_option (R ↿ P ⊗ Q) (map_option f x) = rel_option (R ∘ f ↿ P ∘ f ⊗ Q) x" and option_rel_map_restrict_relp2: "rel_option (R ↿ P ⊗ Q) x (map_option g y) = rel_option ((λx. R x ∘ g) ↿ P ⊗ Q ∘ g) x y" by(simp_all add: option.rel_map restrict_relp_def fun_eq_iff)
fun rel_witness_option :: "'a option × 'b option ==> ('a × 'b) option"where "rel_witness_option (Some x, Some y) = Some (x, y)"
| "rel_witness_option (None, None) = None"
| "rel_witness_option _ = None" ― ‹Just to make the definition complete›
lemma rel_witness_option: shows set_rel_witness_option: "[ rel_option A x y; (a, b) ∈ set_option (rel_witness_option (x, y)) ]==> A a b" and map1_rel_witness_option: "rel_option A x y ==> map_option fst (rel_witness_option (x, y)) = x" and map2_rel_witness_option: "rel_option A x y ==> map_option snd (rel_witness_option (x, y)) = y" by(cases "(x, y)" rule: rel_witness_option.cases; simp; fail)+
lemma rel_witness_option1: assumes"rel_option A x y" shows"rel_option (λa (a', b). a = a' ∧ A a' b) x (rel_witness_option (x, y))" using map1_rel_witness_option[OF assms, symmetric] unfolding option.rel_eq[symmetric] option.rel_map by(rule option.rel_mono_strong)(auto intro: set_rel_witness_option[OF assms])
lemma rel_witness_option2: assumes"rel_option A x y" shows"rel_option (λ(a, b') b. b = b' ∧ A a b') (rel_witness_option (x, y)) y" using map2_rel_witness_option[OF assms] unfolding option.rel_eq[symmetric] option.rel_map by(rule option.rel_mono_strong)(auto intro: set_rel_witness_option[OF assms])
lemma le_option_bind_mono: "[ le_option x y; ∧a. a ∈ set_option x ==> le_option (f a) (g a) ] ==> le_option (Option.bind x f) (Option.bind y g)" by(cases x) simp_all
lemma le_option_refl [simp]: "le_option x x" by(cases x) simp_all
definition pcr_Some :: "('a ==> 'b ==> bool) ==> 'a ==> 'b option ==> bool" where"pcr_Some R x y ⟷ (∃z. y = Some z ∧ R x z)"
lemma pcr_Some_simps [simp]: "pcr_Some R x (Some y) ⟷ R x y" by(simp add: pcr_Some_def)
lemma pcr_SomeE [cases pred]: assumes"pcr_Some R x y" obtains (pcr_Some) z where"y = Some z""R x z" using assms by(auto simp add: pcr_Some_def)
subsubsection‹Filter for option›
fun filter_option :: "('a ==> bool) ==> 'a option ==> 'a option" where "filter_option P None = None"
| "filter_option P (Some x) = (if P x then Some x else None)"
lemma set_filter_option [simp]: "set_option (filter_option P x) = {y ∈ set_option x. P y}" by(cases x) auto
lemma filter_map_option: "filter_option P (map_option f x) = map_option f (filter_option (P ∘ f) x)" by(cases x) simp_all
lemma is_none_filter_option [simp]: "Option.is_none (filter_option P x) ⟷ Option.is_none x ∨¬ P (the x)" by(cases x) simp_all
lemma filter_option_eq_Some_iff [simp]: "filter_option P x = Some y ⟷ x = Some y ∧P y" by(cases x) auto
lemma Some_eq_filter_option_iff [simp]: "Some y = filter_option P x ⟷ x = Some y ∧P y" by(cases x) auto
lemma filter_conv_bind_option: "filter_option P x = Option.bind x (λy. if P y then Some y else None)" by(cases x) simp_all
subsubsection‹Assert for option›
primrec assert_option :: "bool ==> unit option"where "assert_option True = Some ()"
| "assert_option False = None"
lemma set_assert_option_conv: "set_option (assert_option b) = (if b then {()} else {})" by(simp)
lemma in_set_assert_option [simp]: "x ∈ set_option (assert_option b) ⟷ b" by(cases b) simp_all
subsubsection‹Join on options›
definition join_option :: "'a option option ==> 'a option" where"join_option x = (case x of Some y ==> y | None ==> None)"
primrec (transfer) enforce_option :: "('a ==> bool) ==> 'a option ==> 'a option"where "enforce_option P (Some x) = (if P x then Some x else None)"
| "enforce_option P None = None"
lemma set_enforce_option [simp]: "set_option (enforce_option P x) = {a ∈ set_option x. P a}" by(cases x) auto
lemma enforce_map_option: "enforce_option P (map_option f x) = map_option f (enforce_option (P ∘ f) x)" by(cases x) auto
lemma enforce_bind_option [simp]: "enforce_option P (Option.bind x f) = Option.bind x (enforce_option P ∘ f)" by(cases x) auto
lemma enforce_option_alt_def: "enforce_option P x = Option.bind x (λa. Option.bind (assert_option (P a)) (λ_ :: unit. Some a))" by(cases x) simp_all
lemma enforce_option_eq_None_iff [simp]: "enforce_option P x = None ⟷ (∀a. x = Some a ⟶¬ P a)" by(cases x) auto
lemma enforce_option_eq_Some_iff [simp]: "enforce_option P x = Some y ⟷ x = Some y ∧ P y" by(cases x) auto
lemma Some_eq_enforce_option_iff [simp]: "Some y = enforce_option P x ⟷ x = Some y ∧ P y" by(cases x) auto
lemma map_le_map_upd2: "[ f ⊆m g; ∧y'. f x = Some y' ==> y' = y ]==> f ⊆m g(x ↦ y)" by(cases "x ∈ dom f")(auto simp add: map_le_def Ball_def)
lemma eq_None_iff_not_dom: "f x = None ⟷ x ∉ dom f" by auto
lemma card_ran_le_dom: "finite (dom m) ==> card (ran m) ≤ card (dom m)" by(simp add: ran_alt_def card_image_le)
lemma dom_subset_ran_iff: assumes"finite (ran m)" shows"dom m ⊆ ran m ⟷ dom m = ran m" proof assume le: "dom m ⊆ ran m" thenhave"card (dom m) ≤ card (ran m)"by(simp add: card_mono assms) moreoverhave"card (ran m) ≤ card (dom m)"by(simp add: finite_subset[OF le assms] card_ran_le_dom) ultimatelyshow"dom m = ran m"using card_subset_eq[OF assms le] by simp qed simp
text‹
We need a polymorphic constant for the empty map such that ‹transfer_prover›
can use a custom transfer rule for @{const Map.empty} › definition Map_empty where [simp]: "Map_empty ≡ Map.empty"
lemma map_le_Some1D: "[ m ⊆m m'; m x = Some y ]==> m' x = Some y" by(auto simp add: map_le_def Ball_def)
lemma map_le_fun_upd2: "[ f ⊆m g; x ∉ dom f ]==> f ⊆m g(x := y)" by(auto simp add: map_le_def)
lemma map_eqI: "∀x∈dom m ∪ dom m'. m x = m' x ==> m = m'" by(auto simp add: fun_eq_iff domIff intro: option.expand)
lemma SUP_enat_add_right: assumes"I ≠ {}" shows"(SUP i∈I. c + f i :: enat) = c + (SUP i∈I. f i)" using SUP_enat_add_left[OF assms, of f c] by(simp add: add.commute)
lemma iadd_SUP_le_iff: "n + (SUP x∈A. f x :: enat) ≤ y ⟷ (if A = {} then n ≤ y else ∀x∈A. n + f x ≤ y)" by(simp add: bot_enat_def SUP_enat_add_right[symmetric] SUP_le_iff)
lemma SUP_iadd_le_iff: "(SUP x∈A. f x :: enat) + n ≤ y ⟷ (if A = {} then n ≤ y else ∀x∈A. f x + n ≤ y)" using iadd_SUP_le_iff[of n f A y] by(simp add: add.commute)
subsection‹Extended non-negative reals›
lemma (in finite_measure) nn_integral_indicator_neq_infty: "f -` A ∈ sets M ==> (∫+ x. indicator A (f x) ∂M) ≠∞" unfolding ennreal_indicator[symmetric] apply(rule integrableD) apply(rule integrable_const_bound[where B=1]) apply(simp_all add: indicator_vimage[symmetric]) done
lemma (in finite_measure) nn_integral_indicator_neq_top: "f -` A ∈ sets M ==> (∫+ x. indicator A (f x) ∂M) ≠⊤" by(drule nn_integral_indicator_neq_infty) simp
lemma nn_integral_indicator_map: assumes [measurable]: "f ∈ measurable M N""{x∈space N. P x} ∈ sets N" shows"(∫+x. indicator {x∈space N. P x} (f x) ∂M) = emeasure M {x∈space M. P (f x)}" using assms(1)[THEN measurable_space] by (subst nn_integral_indicator[symmetric])
(auto intro!: nn_integral_cong split: split_indicator simp del: nn_integral_indicator)
lemma type_copy_id: "type_definition id id UNIV" by(simp add: id_def type_copy_id')
lemma GrpE [cases pred]: assumes"BNF_Def.Grp A f x y" obtains (Grp) "y = f x""x ∈ A" using assms by(simp add: Grp_def)
lemma rel_fun_Grp_copy_Abs: includes lifting_syntax assumes"type_definition Rep Abs A" shows"rel_fun (BNF_Def.Grp A Abs) (BNF_Def.Grp B g) = BNF_Def.Grp {f. f ` A ⊆ B} (Rep ---> g)" proof - interpret type_definition Rep Abs A by fact show ?thesis by(auto simp add: rel_fun_def Grp_def fun_eq_iff Abs_inverse Rep_inverse intro!: Rep) qed
lemma rel_set_Grp: "rel_set (BNF_Def.Grp A f) = BNF_Def.Grp {B. B ⊆ A} (image f)" by(auto simp add: rel_set_def BNF_Def.Grp_def fun_eq_iff)
lemma rel_set_comp_Grp: "rel_set R = (BNF_Def.Grp {x. x ⊆ {(x, y). R x y}} ((`) fst))-1-1 OO BNF_Def.Grp {x. x ⊆ {(x, y). R x y}} ((`) snd)" apply(auto 44 del: ext intro!: ext simp add: BNF_Def.Grp_def intro!: rel_setI intro: rev_bexI) apply(simp add: relcompp_apply)
subgoal for A B apply(rule exI[where x="A × B ∩ {(x, y). R x y}"]) apply(auto 43 dest: rel_setD1 rel_setD2 intro: rev_image_eqI) done done
lemma Domainp_Grp: "Domainp (BNF_Def.Grp A f) = (λx. x ∈ A)" by(auto simp add: fun_eq_iff Grp_def)
lemma pred_prod_conj [simp]: shows pred_prod_conj1: "∧P Q R. pred_prod (λx. P x ∧ Q x) R = (λx. pred_prod P R x ∧ pred_prod Q R x)" and pred_prod_conj2: "∧P Q R. pred_prod P (λx. Q x ∧ R x) = (λx. pred_prod P Q x ∧ pred_prod P R x)" by(auto simp add: pred_prod.simps)
lemma pred_sum_conj [simp]: shows pred_sum_conj1: "∧P Q R. pred_sum (λx. P x ∧ Q x) R = (λx. pred_sum P R x ∧ pred_sum Q R x)" and pred_sum_conj2: "∧P Q R. pred_sum P (λx. Q x ∧ R x) = (λx. pred_sum P Q x ∧ pred_sum P R x)" by(auto simp add: pred_sum.simps fun_eq_iff)
lemma pred_list_conj [simp]: "list_all (λx. P x ∧ Q x) = (λx. list_all P x ∧ list_all Q x)" by(auto simp add: list_all_def)
lemma bi_unique_Grp [iff]: "bi_unique (BNF_Def.Grp A f) ⟷ inj_on f A" by(simp add: bi_unique_alt_def)
lemma left_total_Grp [iff]: "left_total (BNF_Def.Grp A f) ⟷ A = UNIV" by(auto simp add: left_total_def Grp_def)
lemma right_total_Grp [iff]: "right_total (BNF_Def.Grp A f) ⟷ f ` A = UNIV" by(auto simp add: right_total_def BNF_Def.Grp_def image_def)
lemma bi_total_Grp [iff]: "bi_total (BNF_Def.Grp A f) ⟷ A = UNIV ∧ surj f" by(auto simp add: bi_total_alt_def)
lemma left_unique_vimage2p [simp]: "[ left_unique P; inj f ]==> left_unique (BNF_Def.vimage2p f g P)" unfolding vimage2p_Grp by(intro left_unique_OO) simp_all
lemma right_unique_vimage2p [simp]: "[ right_unique P; inj g ]==> right_unique (BNF_Def.vimage2p f g P)" unfolding vimage2p_Grp by(intro right_unique_OO) simp_all
lemma bi_unique_vimage2p [simp]: "[ bi_unique P; inj f; inj g ]==> bi_unique (BNF_Def.vimage2p f g P)" unfolding bi_unique_alt_def by simp
lemma left_total_vimage2p [simp]: "[ left_total P; surj g ]==> left_total (BNF_Def.vimage2p f g P)" unfolding vimage2p_Grp by(intro left_total_OO) simp_all
lemma right_total_vimage2p [simp]: "[ right_total P; surj f ]==> right_total (BNF_Def.vimage2p f g P)" unfolding vimage2p_Grp by(intro right_total_OO) simp_all
lemma bi_total_vimage2p [simp]: "[ bi_total P; surj f; surj g ]==> bi_total (BNF_Def.vimage2p f g P)" unfolding bi_total_alt_def by simp
lemma vimage2p_eq [simp]: "inj f ==> BNF_Def.vimage2p f f (=) = (=)" by(auto simp add: vimage2p_def fun_eq_iff inj_on_def)
lemma vimage2p_conversep: "BNF_Def.vimage2p f g R^--1 = (BNF_Def.vimage2p g f R)^--1" by(simp add: vimage2p_def fun_eq_iff)
lemma rel_fun_refl: "[ A ≤ (=); (=) ≤ B ]==> (=) ≤ rel_fun A B" by(subst fun.rel_eq[symmetric])(rule fun_mono)
lemma rel_fun_mono_strong: "[ rel_fun A B f g; A' ≤ A; ∧x y. [ x ∈ f ` {x. Domainp A' x}; y ∈ g ` {x. Rangep A' x}; B x y ]==> B' x y ]==> rel_fun A' B' f g" by(auto simp add: rel_fun_def) fastforce
lemma rel_fun_refl_strong: assumes"A ≤ (=)""∧x. x ∈ f ` {x. Domainp A x} ==> B x x" shows"rel_fun A B f f" proof - have"rel_fun (=) (=) f f"by(simp add: rel_fun_eq) thenshow ?thesis using assms(1) by(rule rel_fun_mono_strong) (auto intro: assms(2)) qed
lemma Grp_iff: "BNF_Def.Grp B g x y ⟷ y = g x ∧ x ∈ B"by(simp add: Grp_def)
lemma Rangep_Grp: "Rangep (BNF_Def.Grp A f) = (λx. x ∈ f ` A)" by(auto simp add: fun_eq_iff Grp_iff)
lemma rel_fun_Grp: "rel_fun (BNF_Def.Grp UNIV h)-1-1 (BNF_Def.Grp A g) = BNF_Def.Grp {f. f ` range h ⊆ A} (map_fun h g)" by(auto simp add: rel_fun_def fun_eq_iff Grp_iff)
subsection‹Transfer and lifting material›
contextincludes lifting_syntax begin
lemma monotone_parametric [transfer_rule]: assumes [transfer_rule]: "bi_total A" shows"((A ===> A ===> (=)) ===> (B ===> B ===> (=)) ===> (A ===> B) ===> (=)) monotone monotone" unfolding monotone_def[abs_def] by transfer_prover
lemma fun_ord_parametric [transfer_rule]: assumes [transfer_rule]: "bi_total C" shows"((A ===> B ===> (=)) ===> (C ===> A) ===> (C ===> B) ===> (=)) fun_ord fun_ord" unfolding fun_ord_def[abs_def] by transfer_prover
lemma Plus_parametric [transfer_rule]: "(rel_set A ===> rel_set B ===> rel_set (rel_sum A B)) (<+>) (<+>)" unfolding Plus_def[abs_def] by transfer_prover
lemma rel_fun_eq_OO: "((=) ===> A) OO ((=) ===> B) = ((=) ===> A OO B)" by(clarsimp simp add: rel_fun_def fun_eq_iff relcompp.simps) metis
end
lemma Quotient_set_rel_eq: includes lifting_syntax assumes"Quotient R Abs Rep T" shows"(rel_set T ===> rel_set T ===> (=)) (rel_set R) (=)" proof(rule rel_funI iffI)+ fix A B C D assume AB: "rel_set T A B"andCD: "rel_set T C D" have *: "∧x y. R x y = (T x (Abs x) ∧ T y (Abs y) ∧ Abs x = Abs y)" "∧a b. T a b ==> Abs a = b" using assms unfolding Quotient_alt_def by simp_all
lemma rel_fun_eq_conversep: includes lifting_syntax shows"(A-1-1 ===> (=)) = (A ===> (=))-1-1" by(auto simp add: fun_eq_iff rel_fun_def)
lemma rel_fun_comp: "∧f g h. rel_fun A B (f ∘ g) h = rel_fun A (λx. B (f x)) g h" "∧f g h. rel_fun A B f (g ∘ h) = rel_fun A (λx y. B x (g y)) f h" by(auto simp add: rel_fun_def)
lemma rel_fun_map_fun1: "rel_fun (BNF_Def.Grp UNIV h)-1-1 A f g ==> rel_fun (=) A (map_fun h id f) g" by(auto simp add: rel_fun_def Grp_def)
lemma map_fun2_id: "map_fun f g x = g ∘ map_fun f id x" by(simp add: map_fun_def o_assoc)
lemma map_fun_id2_in: "map_fun g h f = map_fun g id (h ∘ f)" by(simp add: map_fun_def)
lemma Domainp_rel_fun_le: "Domainp (rel_fun A B) ≤ pred_fun (Domainp A) (Domainp B)" by(auto dest: rel_funD)
definition rel_witness_fun :: "('a ==> 'b ==> bool) ==> ('b ==> 'c ==> bool) ==> ('a ==> 'd) × ('c ==> 'e) ==> ('b ==> 'd × 'e)"where "rel_witness_fun A A' = (λ(f, g) b. (f (THE a. A a b), g (THE c. A' b c)))"
lemma assumes fg: "rel_fun (A OO A') B f g" and A: "left_unique A""right_total A" and A': "right_unique A'""left_total A'" shows rel_witness_fun1: "rel_fun A (λx (x', y). x = x' ∧ B x' y) f (rel_witness_fun A A' (f, g))" and rel_witness_fun2: "rel_fun A' (λ(x, y') y. y = y' ∧ B x y') (rel_witness_fun A A' (f, g)) g" proof (goal_cases) case1 have"A x y ==> f x = f (THE a. A a y) ∧ B (f (THE a. A a y)) (g (The (A' y)))"for x y by(rule left_totalE[OF A'(2)]; erule meta_allE[of _ y]; erule exE; frule (1) fg[THEN rel_funD, OF relcomppI])
(auto intro!: arg_cong[where f=f] arg_cong[where f=g] rel_funI the_equality the_equality[symmetric] dest: left_uniqueD[OF A(1)] right_uniqueD[OF A'(1)] elim!: arg_cong2[where f=B, THEN iffD2, rotated -1])
with1show ?caseby(clarsimp simp add: rel_fun_def rel_witness_fun_def) next case2 have"A' x y ==> g y = g (The (A' x)) ∧ B (f (THE a. A a x)) (g (The (A' x)))"forx y by(rule right_totalE[OF A(2), of x]; frule (1) fg[THEN rel_funD, OF relcomppI])
(auto intro!: arg_cong[where f=f] arg_cong[where f=g] rel_funI the_equality the_equality[symmetric] dest: left_uniqueD[OF A(1)] right_uniqueD[OF A'(1)] elim!: arg_cong2[where f=B, THEN iffD2, rotated -1])
with2show ?caseby(clarsimp simp add: rel_fun_def rel_witness_fun_def) qed
lemma (in ordered_ab_semigroup_add) add_left_mono_trans: "[ x ≤ a + b; b ≤ c ]==> x ≤ a + c" by(erule order_trans)(rule add_left_mono)
lemma of_nat_le_one_cancel_iff [simp]: fixes n :: nat shows"real n ≤ 1 ⟷ n ≤ 1" by linarith
lemma (in linordered_semidom) mult_right_le: "c ≤ 1 ==> 0 ≤ a ==> c * a ≤ a" by(subst mult.commute)(rule mult_left_le)
subsection‹Chain-complete partial orders and ‹partial_function››
lemma fun_ordD: "fun_ord ord f g ==> ord (f x) (g x)" by(simp add: fun_ord_def)
lemma assumes ccpo1: "class.ccpo luba orda (mk_less orda)"
ccpo2k_lessimp<>OL> and adm: "ccpo.admissible (prod_lub luba lubb) (rel_prod orda ordb) (\lambdax. P (ffst x) (snd x))" and f: "monotone orda orda f" and g:monotone and bot: "P (luba {}) (lubb {})" and step: "\<dy showsP(c.fip uaororddaa ) (cpo.o.fixp lbb od g" proof let ?P="λ \and ordb y (ccpo.fixp lubb ordb g) ∧ show ?thesis using ccpo1 ccpo2 _ f g proof(rule parallel_fixp_induct[wher note [ont_itro= admissible_leI[OF ccpo1]comcontont[F cpo] admissible_leI[OF ccpo2] ccpo.mcoletra: how "admissibleuba>y. ?P (fst ysnd using adm show"?P (lubproof - "( (g if yfor using that apply apply(subst ccpodOF apply(auto intronotoneD[F] done
ed qed
lemmal_fixp_induct_strong_uc assmselp_def assumesartial_function_definitionsal_function_definitions orda" and b: "partial_function_definitionsubb and F: "∧ andG">. monotone (fun_ord ordbb (lambdag. U2(G (C2 y))" and eq1: "(ruleplies_def and and inverse: "∧ and inverse:<. (2g =g and and bot: "P (λ_. lubb and step: <>f g.<> \And. orda (U1 f' x) (U1 f x); ∧y. ordb (U2 g' y) (U2 g y) U1<><Longrightarrow> P (U1 (F f'))G) showsU2 apply(unfoldnverse2 apply(rule parallel_fixp_induct_strongrtial_function_definitionsion_definitions[apartial_function_definitionsinitionsb]m] using ply_ef usingdmonotone_def apply(simp add: fun_lub_def t apply(rule step;mp nverse2 done
lemmas parallel_fixp_induct_strong_1_1 = parallel_fixp_induct_strong_uc[
of _ _ _ _ "λl. x" _ "λ OF _ _ _ _ _ _ ref ef
emmas_ct_strog_2 = aall_fxpidct_soguc of _ _ _ _ "case_prod" _ "curry" "case_prod" _ "curry
: 'b) × 'a × c ere((a, b), c). (a, (b, c)" nfoldedca_pod_rycryae_od cur_, __ __rf ef, split_format (complete), unfolded prod.case] for P
lemma fixp_induct_option': ― < ('c × 'd) ==> (('a × 'c) × ('b × 'd))"where fixes F :: "'c ==> 'c"and
U :: "'c ==> 'b ==> 'a option"and
C :: "('b ==> 'a option) ==> 'c"and
P :: "'b ==> 'a ==> bool" assumesx. mono_option (<lambdaf assumes eq: "f ≡ C (ccpo.fixp (fun_lub (flatlub None)) (un_ord option_ordr (\lambdaf. U (F (C f))))" assumesnverse2f. U (C f) = f" assumes step: "∧x y. U g x y\ ==> assumes defined: "U f x = Some y" shows using step defined option.by(cases unfolding fun_lub_def flat_lub_def fun_ord_def by(simp (no_asm_use)) blast inj_onI
lemma finite_chains_flat_ord [simp, intro!]:obtainsption proof
x assume chain show"nite" proof(casesupharpoonleft P ⊗ f ↿ f ⊗ case True thenobtain y where y: "y ∈ hence "Y ⊆(Some thus ?thesis by(rule finite_subset) simp next case False
java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37 thus qed qed
lemma_ assumes finitee_def and mono: "monotone ord ord' f"
ndpoess andr_optiony<>set_option x. P y}" ows r" proof(intro mcontI contI) fix( ) assume chain: "Complete_Partial_Order from finite chain ha \openAssert for option› t_option_convpsst)(fbh}l{)
have chain': "Complete_Partial_Order.chain
( chain_imageI
ubusing by(rulecases
lemmaption x = None x = Some None" have "ordlub ( ) sing by(rule ccpo'.ccpo_Sup_least)(blast intro: monotoneD[OF mono] ccpo.ccpo_Sup_upper[OF ccpo chain]) ultimatelyshow"f (lubY) = lu' ( ` ) by(ue cpo'.rer.ntsy) qedonon)
lemma rel_fun_curry: includes lifting_syntax shows "(A ===> B ===> C) f g ⟷ to
lemma (in ccpo) Sup_image_mono assumes ccpo(ases ip_option and mono: "monotone orda (≤ chain "e_Partial_Order and"A ≠ {}" shows"Sup (f ` A) ≤ proof(rule ccpo_Sup_least) from chain show "Complete_Partial_Order by(rule chain_imageI)(rule(rewrite]p)
ix assume"x ∈ f ` A"
henin A" by blast from ‹ hence "fy\<le>f(lubaA)"by(rulemonotoneD thus"x\<le>luba)""sing\<open>x=fy\<close>bysimp qedjava.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
lemma(inccpo)admissible_le_mono: assumes"monotone(\<le>)(\<le>)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 shows"ccpo.admissibleSup(\<le>)(\<lambda>x.x\<le>fx)" proof(ruleccpo.admissibleI) fixY assumechain:"Complete_Partial_Order.chain(\<le>)" andY:Map_emptyre:p_emptyMap.empty" andlejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 have"\<Squnion>Y\<le>\<Squnion>(f`Y)"usingchain by by(ruleSup_image_mono[OF_assmschainY,wherebyus_lfpntsimpdable_funpowjava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74 <>Y\<le>\<dots>". qed
java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 36 assumesadm:"ccpo.admissiblebyp:t_enat_def_ymmetric and(cases,eym andbot:"P(\<Squnion>{} ?lhs". shows"P(\>Ic+(Pi\>.fi)" proof(rulefixp_strong_induct[whereP="\<lambda>x.x\<le>fx\<and show"ccpo.admissibleSup(\<le>)(\\openExtendednon-negativereals\<close> usingadmissible_le_mono(simp_allddator_vimage] next show"\<Squnion>{}\lemmann_integral_indicator_map_indicator_map: by(autosimpadd:botchain_emptyintro:ccpo_Sup_least) next fixx assume"x\<le>ccpo_classrel_funDadds_equality_def thus"fx\<le>f)<P(fx)" by(autodest:monotoneD[OFmono]intro:step) qed(rulemono)
contextpartial_function_definitionsbegin
lemmafixp_induct_strong2_uc: fixes"rel_setBNF_Defrp.<>{.}(`fstinverse\<inverse>OOBNF_Def.Grp{x.x\<subseteq>{(x,y).x})d andU::"'c\<Rightarrow>'b\<Rightarrow>'a" andC::"('b\<Rightarrow>'a)\<Rightarrow>'c" andP::"('b\<Rightarrow>'a)\<Rightarrow>bool" sono<>.mono_body(\<lambda>f.U(F(Cf))x)" andeq:"f\<equiv>Cxp_funlambdaf.U(F(Cf)java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63 andinverse:"\<And>f.U(Cf)=f" andadm:"ccpo.admissiblelub_funle_funP" andbot:"P(\<lambda>_.lub{})" andstep:"\<And>f'.\<lemmafl\>A\<le>(=);(=)\<le>B\<rbrakk>\<Longrightarrow>(=)\<le>rel_funAB" shows"P(Uf)" unfoldingeqinverse apply(ruleccpo.fixp_induct_strong2[OFbytoprp_iff apply(insertmono,autosimp:monotone_deffun_ord_defbotfun_lub_def)[2] apply(rule_tacf'5=
java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 32 done
end
lemmasparallel_fixp_induct_2_4proof_) case_prod_ry"<f.case_prod(case_prod(ase_prod"<lambdafcurry(curryrrycurryfjava.lang.StringIndexOutOfBoundsException: Index 125 out of bounds for length 125 whereP="\<lambda>fg.P(curryf)(curry(curry(curryg)))"apply1bexE unfoldedrel_fun_eq_onpI"q_onpred_funf<>rel_fun(pq_onp)g OF____reflrefl] forP lemma(inccpoixp_greatest assumesf:"monotone(\<le>)(\<le>)f" andge:"(mp:p_fun_defjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27 shows<>cpoixpup\le)f" by(rulege)(simpadd:fixp_unfold[OFf,symmetric])
lemma_g: assumes"class.ccpolub1leq1(mk_lessleq1)" and"class.ccpolub2leq2(mk_lessleq2)" andf:"monotoneleq1leq2f" andg:"monotoneleq2leq1g" shows"ccpo.fixplub1leq1(\<lambda>x.g(fx))=g(ccpo(autointro!:arg_congwhere=]arg_cong[wherefgrel_funIthe_equalitythe_equality[symmetric]dest:left_uniqueDOFA1]right_uniqueD[OF')elim!:[wherefBiffD2,-1) proof- interpretc1:ccpolub1leq1"mk_lessleq1"byfact interpretc2:ccpolub2leq2"mk_lessleq2"byfact show?thesis proof(rulec1.orderlet?=">xy.rda(fixpubaf<ordby(ccpo.fixplubbordbg)\<and>Px" havefg:"monotoneleq2leq2(\<lambda>x.f(gx))"usingfgby(rulemonotone2monotone)simp_all :notoneeq111\<ambdax.g(fx))"usinggfby(rulemonotone2monotone)simp_all show"leq1(c1.fixp(\<lambda>x.g(fx)))(g(c2.fixp(\<lambda>x.f(gx))))"usinggf by(rulec1.fixp_lowerbound)(subst(2)c2.fixp_unfold[OFfg],simp) show"leq1(g(c2.fixp(\<lambda>x.f(gx))))(c1.fixp(\<assumes<f.U(Cf)=f" proof(rulec1.fixp_greatest) fixu assumeu:"leq1(g(fu))u" haveq1(c2ixpplambdax.f(gx))))(gf)" by(intromonotoneD[OFg]c2.fixp_lowerbound[OFfg]monotoneD[OFfu]) thenshow"leq1(gc2xp<lambdax.f(gx))))u"usingby1order_trans qed qed qed
lemmamono2mono_map_option[THENoption.mono2mono,simp,cont_intro]: showsmonotone_map_option:"monotoneoption_ordoption_ord(map_optionjava.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4 by(rulemonotoneI)(autosimpadd:flat_ord_def)
lemmamcont2mcont_map_option[THENoption.anderse<>f(=java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39 showsmcont_map_option:"mcont(flat_lubNone)option_ord(flat_lubNone)option_ord(map_optionunfoldingse by(rulemcont_finite_chains[OF__flat_interpretation[THENccpo]flat_interpretation[THENccpo]])simp_all
lemma(incomp_fun_commute)fold_invariant_remove[consumes1,case_namesstartstep]: assumesfin:"finiteA" andstart:"IAs" andstep:"\<And>xsA'.\<lbrakk>x shows"I{}(Finite_Set.foldfsA)" proof- defineA'where"A'==A" withfinstarthave"finiteA'""A'\<subseteq>A""IA's"bysimp_all thus"I{}(Finite_Set.foldfsA')" proof(inductionarbitrary:s) caseemptythus?casebysimp next case(insertassms(1nductionall let?A'="insert' have"x\<in>?A'""I?A's""?AAttribnmetricity> hence"I(?A'-{x})(fxs)"yulep withinserthave"A'\<subseteq>A""IA'(fxs)"byauto hence"I{}(Finite_Set.foldf(fxs)A')"by(ruleinsert.IH) thus?caseusinginsertbymoreoverhave(,y)strict_prefix<subseteq>inv_imagey}length"by(autointro:prefix_length_less) qed qed
lemma(incomp_fun_commute)fold_invariant_insert[consumes1,case_namesstartstep]: assumess_empty_gt0:<Longrightarrow>nlists=}java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73 andstartI}s andstep: shows"IA(Finite_Set.foldfsA)" usingfinstart proof(rulefold_invariant_remove[whereI="\<lambda>A'.I('andAandndssimplified) fix assume*:"x\<in>A'""I(A-A')s""A'\<subseteq>A" hence"x\<notin>A-A'""x\<in>A""A-A'\<subseteq>A"byauto ith<penI(A-A')s\<close>have"I(insertx(A-A'))(fxs)"by(rulestep) alsohave"insertx(A-A')=A-(A'-{x})"using*byauto finallyshow"I\<dots>(fxs)". qed
attribute_setuptransfer_parametric=\<open> Attrib.thm>>(fnparametricity=> Thm.rule_attribute[](fncontext=>fntransfer_rule=> let valctxt=Context.proof_ofcontext; valthm'java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 inLifting_Def.generate_parametric_transfer_rulectxtthm'parametricity end handleLifting_Term.MERGE_TRANSFER_RELmsg=>error(Pretty.string_ofmsg) )) \<close>"combinetransferrulewithparametricitytheorem"
lemmadisjointpD: "\<lbrakk>disjointpxs;(xs!n)x;(xs!m)x;"\And>moreenv(d_optionail_env)sjava.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67 by(auto43simpadd:disjointp_defdisjoint_family_on_def)
lemmawf_strict_prefix:"wfPstrict_prefix" proof- fromwfhave"wf(inv_image(,y.y}length)"by(rulewf_inv_image) moreoverhave"{(x,shows"P(xinS.Px)=(\<integral>\<^sup>+x.\<P>(x'inS.P(comb_seqixx'))\>java.lang.StringIndexOutOfBoundsException: Index 100 out of bounds for length 100 ultimatelyshow?thesisunfoldingwfp_defby(rulewf_subset) qed
emma_java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25 "strict_prefixxsys\<Longrightarrow>setdefinel<ightarrowboolpmf"where"g=return_pmf" by(autosimpadd:strict_prefix_defprefix_def)
lemmanlists_empty:"nlists{}n=(ifn=0then{[java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 by(by(impddpmf_def
lemmanlists_empty_gt0[simp]:"nassumesfupharpoonleftP\<otimes>Q)xjava.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58 by(simpadd:nlists_empty)
lemmain_nlists_Suc_iff:"xs\<in>nlistsA(Sucn)\<longleftrightarrow>\existsxxs'.xs=x#xs'\<dinA\<and>xs'\<in>nlistsA)java.lang.StringIndexOutOfBoundsException: Index 150 out of bounds for length 150 by(casesxs)simp_all
lemmanlists_Suc:"nlistsA(Sucn)=(\<Union>x\<in>A.(#)x`nlistsAnapply(substmultjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25 by(auto43simpadd:in_nlists_Suc_iffintro:rev_image_eqI)
lemmafinite_nlistsD: assumes"finite(nlistsAn)" shows"finiteA\<or>n=0" proof(ruledisjCI) assume"n\<>0" thenobtainn'wheren:"n=Sucn'"by(casesn)auto thenhave"A=hd`nlistsAn"by(auto44simpadd:nlists_Sucintro:rev_image_eqIrev_bexI) alsohave"finite\<dots>"usingassms.. finallyshow"finiteA"usingemeasure_cond_pmfOFtfjava.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46 qed
lemmate_nlists_iffs_iffinitetelistssts<>finiteA<>n0java.lang.StringIndexOutOfBoundsException: Index 89 out of bounds for length 89 ystnite_nlistsD
lemmacard_nlists:"card(nlistsAn)=cardA^n" proof(inductionn) case(Sucn) vecard\<Unionx\<in>A.(#)x`nlistsAn)=cardA*card(nlistsAn)" proof(cases"finiteA") lhs<e>measure(measure_spmfp'){y.\<exists>x\<in>A.Rxy}"using*by(ruleel_spmf_measureD owhesisbysubststard_UN_disjointUN_disjointautooimpadddard_imagemagenj_on_defef next caseFalse hence"\<not>finite(\<Union>x\<in>A.(#)x`nlistsAn)" unfoldingnlists_Suc[symmetric]by(autodest:finite_nlistsD) thenshow?thesisusingFalsebysimp qed thenshow?caseusingSuc.IHby(simpadd:nlists_Suc) qedsimp
typedef(overloaded)('a,'b::len0)nlist="nlists(UNIV::'aset)(LENGTH('b))" proof show"replicateLENGTH('b)lemmaspmf_rel_mono_strong qed
setup_liftingtype_definition_nlist
subsection\<open>Streamsandinfinitelists\<close>
primrecsprefix::"'alist\<Rightarrow>'astream\<Rightarrow>bool"where sprefix_Nil:"sprefix[]ys=True" |sprefix_Cons:"sprefix(x#xs)ys\<longleftrightarrow>x=shdys\<>sprefixrefixixxs(tlys)java.lang.StringIndexOutOfBoundsException: Index 97 out of bounds for length 97
lemmasprefix_same_imp_eq: assumes"sprefixxsys""sprefixxs'ys" and"lengthxs=lengthxs'" ord_spmf_return_spmf[simp]:"rd_spmf(=)(return_spmfx)<longleftrightarrowpturn_spmfjava.lang.StringIndexOutOfBoundsException: Index 107 out of bounds for length 107 usingassms(3,1,2)by(inductarbitrary:ysrule:list_induct2)auto
lemma(insigma_algebra)sets_Collect_countable_Ex1: "(\<And>i::'i::countablerel_witness_spmf1:"rel_spmf(\<lambdaa(')a'\and>Aa')p(A(p,q)" usingsets_Collect_countable_Ex1"UNIV::iset]byjava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
lemmameasurable_snd_count_space["enforce_spmfP(bind_spmfpf)=bind_spmfp(enforce_spmfP\circf" "A\<ubseteq>B\Longrightarrow>snd\<in>measurable(\<^sub>Mcount_spaceA)(count_spaceB)java.lang.StringIndexOutOfBoundsException: Index 111 out of bounds for length 111 by(autosimpadd:measurable_defspace_pair_measuresnd_vimage_eq_TimesTimes_Int_Times)
textopenrule@{thm[source]rel_pmf_bindI}isnotcompleteasaprogramlogic.\<close> notepad(add:mk_lossless_defweight_scale_spmfmin_defmax_definverse_eq_divide) definexwhere"x=pmf_of_set{True,False}" yhere"=pmf_of_set{True,False}" definefwhere"fx=pmf_of_set{True,False}"forx::bool defineg::"bool\<Rightarrow>boolpmf"where"g=return_pmf" defineP::"bool\<Rightarrow>bool\<Rightarrow>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 have"rel_pmfP(bind_pmfxf)(bind_pmfyg)" by(add:P_deff_def[bs_def]g_defy_defbind_return_pmf'pmf.rel_eq) tarrow>rel_pmfPfx)(gy)forR \<comment>\<open>Onlytheemptyrelationsatisfies@{thm[source]rel_pmf_bindI}'ssecondpremise.\<close> proof assume"Rxy" hence"rel_pmfP(fx)(gy)"by(rulethat) thusFalseby(autosimpadd:P_deff_defg_defrel_pmf_return_pmf2) qed defineRwhere"Rxy=False"forxy::bool have"\<not>rel_pmfRxy"by(simpadd:R_def[abs_def]) end
lemmarel_pmf_restrict_relp_iff: "rel_pmf(R\<upharpoonleft>P\<otimes>Q)xy\<longleftrightarrow>rel_pmfR<java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8 by(blastintro:rel_pmf_restrict_relpIelim:rel_pmf_restrict_relpE)
lemmapred_pmf_bind[simp]:"pred_pmfP(bind_pmfpf)=pred_pmf(pred_pmfP\<circ>f)pjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 by(simpadd:pred_pmf_def)
imp:"\lbrakk>finiteA;A\<noteq>{}\<rbrakk>\<Longrightarrow>pred_pmfP(of_set= byoption_le_spmfjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
lemmapred_pmf_of_multiset[simp]"\<noteq>{\Longrightarrowpred_pmfP(pmf_of_multisetM)=Ballt_msetmsetjava.lang.StringIndexOutOfBoundsException: Index 122 out of bounds for length 122 ypmf_def
lemma rel_spmf_restrict_relpI [intro?]: "[ rel_spmf R p q; pred_spmf P p; pred_spmf Q q ]==> rel_spmf (R ↿ P ⊗ Q) p q" by(erule spmf_rel_mono_strong)(simp add: pred_spmf_def)
lemma rel_spmf_restrict_relpE [elim?]: assumes"rel_spmf (R ↿ P ⊗ Q) x y" obtains"rel_spmf R x y""pred_spmf P x""pred_spmf Q y" proof show"rel_spmf R x y"using assms by(auto elim!: spmf_rel_mono_strong) have"pred_spmf (Domainp (R ↿ P ⊗ Q)) x"using assms by(fold spmf_Domainp_rel) blast thenshow"pred_spmf P x"by(rule spmf_pred_mono_strong)(blast dest!: restrict_relp_DomainpD) have"pred_spmf (Domainp (R ↿ P ⊗ Q)-1-1) y"using assms by(fold spmf_Domainp_rel)(auto simp only: spmf_rel_conversep Domainp_conversep) thenshow"pred_spmf Q y"by(rule spmf_pred_mono_strong)(auto dest!: restrict_relp_DomainpD) qed
lemma rel_spmf_restrict_relp_iff: "rel_spmf (R ↿ P ⊗ Q) x y ⟷ rel_spmf R x y ∧ pred_spmf P x ∧ pred_spmf Q y" by(blast intro: rel_spmf_restrict_relpI elim: rel_spmf_restrict_relpE)
lemma spmf_pred_map: "pred_spmf P (map_spmf f p) = pred_spmf (P ∘ f) p" by(simp)
lemma pred_spmf_bind [simp]: "pred_spmf P (bind_spmf p f) = pred_spmf (pred_spmf P ∘ f) p" by(simp add: pred_spmf_def bind_UNION)
lemma pred_spmf_return: "pred_spmf P (return_spmf x) = P x" by simp
lemma pred_spmf_return_pmf_None: "pred_spmf P (return_pmf None)" by simp
lemma pred_spmf_spmf_of_pmf [simp]: "pred_spmf P (spmf_of_pmf p) = pred_pmf P p" unfolding pred_spmf_def by(simp add: pred_pmf_def)
lemma pred_spmf_of_set [simp]: "pred_spmf P (spmf_of_set A) = (finite A ⟶ Ball A P)" by(auto simp add: pred_spmf_def set_spmf_of_set)
lemma pred_spmf_assert_spmf [simp]: "pred_spmf P (assert_spmf b) = (b ⟶ P ())" by(cases b) simp_all
lemma pred_spmf_try [simp]: "pred_spmf P (try_spmf p q) = (pred_spmf P p ∧ (¬ lossless_spmf p ⟶ pred_spmf P q))" by(auto simp add: pred_spmf_def)
lemma pred_spmf_cond [simp]: "pred_spmf P (cond_spmf p A) = pred_spmf (λx. x ∈ A ⟶ P x) p" by(auto simp add: pred_spmf_def)
lemma spmf_rel_map_restrict_relp: shows spmf_rel_map_restrict_relp1: "rel_spmf (R ↿ P ⊗ Q) (map_spmf f p) = rel_spmf (R ∘ f ↿ P ∘ f ⊗ Q) p" and spmf_rel_map_restrict_relp2: "rel_spmf (R ↿ P ⊗ Q) p (map_spmf g q) = rel_spmf ((λx. R x ∘ g) ↿ P ⊗ Q ∘ g) p q" by(simp_all add: spmf_rel_map restrict_relp_def)
lemma pred_spmf_conj: "pred_spmf (λx. P x ∧ Q x) = (λx. pred_spmf P x ∧ pred_spmf Q x)" by simp
lemma spmf_of_pmf_parametric [transfer_rule]: includes lifting_syntax shows "(rel_pmf A ===> rel_spmf A) spmf_of_pmf spmf_of_pmf" unfolding spmf_of_pmf_def[abs_def] by transfer_prover
lemma rel_spmf_restrict_relpI' [intro?]: "[ rel_spmf (λx y. P x ⟶ Q y ⟶ R x y) p q; pred_spmf P p; pred_spmf Q q ]==> rel_spmf (R ↿ P ⊗ Q) p q" by(erule spmf_rel_mono_strong)(simp add: pred_spmf_def)
lemma set_spmf_map_pmf_MATCH [simp]: assumes"NO_MATCH (map_option g) f" shows"set_spmf (map_pmf f p) = (∪x∈set_pmf p. set_option (f x))" by(rule set_spmf_map_pmf)
lemma rel_spmf_bindI': "[ rel_spmf A p q; ∧x y. [ A x y; x ∈ set_spmf p; y ∈ set_spmf q ]==> rel_spmf B (f x) (g y) ] ==> rel_spmf B (p 🍋 f) (q 🍋 g)" apply(rule rel_spmf_bindI[where R="λx y. A x y ∧ x ∈ set_spmf p ∧ y ∈ set_spmf q"]) apply(erule spmf_rel_mono_strong; simp) apply simp done
lemmaassumes"rel_spmf A p q" shows rel_witness_spmf1: "rel_spmf (λa (a', b). a = a' ∧ A a' b) p (rel_witness_spmf A (p, q))" and rel_witness_spmf2: "rel_spmf (λ(a, b') b. b = b' ∧ A a b') (rel_witness_spmf A (p, q)) q" by(auto simp add: pmf.rel_map rel_witness_spmf_def intro: pmf.rel_mono_strong[OF rel_witness_pmf1[OF assms]] rel_witness_option1 pmf.rel_mono_strong[OF rel_witness_pmf2[OF assms]] rel_witness_option2)
lemma enforce_map_spmf: "enforce_spmf P (map_spmf f p) = map_spmf f (enforce_spmf (P ∘ f) p)" by(simp add: enforce_spmf_def pmf.map_comp o_def enforce_map_option)
lemma enforce_bind_spmf [simp]: "enforce_spmf P (bind_spmf p f) = bind_spmf p (enforce_spmf P ∘ f)" by(auto simp add: enforce_spmf_def bind_spmf_def map_bind_pmf intro!: bind_pmf_cong split: option.split)
lemma set_enforce_spmf [simp]: "set_spmf (enforce_spmf P p) = {a ∈ set_spmf p. P a}" by(auto simp add: enforce_spmf_def in_set_spmf)
lemma enforce_spmf_alt_def: "enforce_spmf P p = bind_spmf p (λa. bind_spmf (assert_spmf (P a)) (λ_ :: unit. return_spmf a))" by(auto simp add: enforce_spmf_def assert_spmf_def map_pmf_def bind_spmf_def bind_return_pmf intro!: bind_pmf_cong split: option.split)
lemma bind_enforce_spmf [simp]: "bind_spmf (enforce_spmf P p) f = bind_spmf p (λx. if P x then f x else return_pmf None)" by(auto simp add: enforce_spmf_alt_def assert_spmf_def intro!: bind_spmf_cong)
lemma weight_enforce_spmf: "weight_spmf (enforce_spmf P p) = weight_spmf p - measure (measure_spmf p) {x. ¬ P x}" (is"?lhs = ?rhs") proof - have"?lhs = LINT x|measure_spmf p. indicator {x. P x} x" by(auto simp add: enforce_spmf_alt_def weight_bind_spmf o_def simp del: Bochner_Integration.integral_indicator intro!: Bochner_Integration.integral_cong split: split_indicator) alsohave"… = ?rhs" by(subst measure_spmf.finite_measure_Diff[symmetric])(auto simp add: space_measure_spmf intro!: arg_cong2[where f=measure]) finallyshow ?thesis . qed
lemma lossless_enforce_spmf [simp]: "lossless_spmf (enforce_spmf P p) ⟷ lossless_spmf p ∧ set_spmf p ⊆ {x. P x}" by(auto simp add: enforce_spmf_alt_def)
lemma enforce_spmf_K_False [simp]: "enforce_spmf (λ_. False) p = return_pmf None" using enforce_spmf_bot[THEN fun_cong, of p] by(simp add: bot_fun_def)
lemma enforce_pred_id_spmf: "enforce_spmf P p = p"if"pred_spmf P p" proof - have"enforce_spmf P p = map_pmf id p"using that by(auto simp add: enforce_spmf_def enforce_pred_id_option simp del: map_pmf_id intro!: pmf.map_cong_pred[OF refl] elim!: pmf_pred_mono_strong) thenshow ?thesis by simp qed
lemma bind_bind_conv_pair_spmf: "bind_spmf p (λx. bind_spmf q (f x)) = bind_spmf (pair_spmf p q) (λ(x, y). f x y)" by(simp add: pair_spmf_alt_def)
lemma cond_spmf_spmf_of_set: "cond_spmf (spmf_of_set A) B = spmf_of_set (A ∩ B)"if"finite A" by(rule spmf_eqI)(auto simp add: spmf_of_set measure_spmf_of_set that split: split_indicator)
lemma pair_spmf_of_set: "pair_spmf (spmf_of_set A) (spmf_of_set B) = spmf_of_set (A × B)" by(rule spmf_eqI)(clarsimp simp add: spmf_of_set card_cartesian_product split: split_indicator)
lemma emeasure_cond_spmf: "emeasure (measure_spmf (cond_spmf p A)) B = emeasure (measure_spmf p) (A ∩ B) / emeasure (measure_spmf p) A" apply(clarsimp simp add: cond_spmf_def emeasure_measure_spmf_conv_measure_pmf emeasure_measure_pmf_zero_iff set_pmf_Int_Some split!: if_split) apply blast apply(subst (asm) emeasure_cond_pmf) by(auto simp add: set_pmf_Int_Some image_Int)
lemma measure_cond_spmf: "measure (measure_spmf (cond_spmf p A)) B = measure (measure_spmf p) (A ∩ B) / measure (measure_spmf p) A" apply(clarsimp simp add: cond_spmf_def measure_measure_spmf_conv_measure_pmf measure_pmf_zero_iff set_pmf_Int_Some split!: if_split) apply(subst (asm) measure_cond_pmf) by(auto simp add: image_Int set_pmf_Int_Some)
lemma lossless_cond_spmf [simp]: "lossless_spmf (cond_spmf p A) ⟷ set_spmf p ∩ A ≠{}" by(clarsimp simp add: cond_spmf_def lossless_iff_set_pmf_None set_pmf_Int_Some)
lemma measure_spmf_eq_density: "measure_spmf p = density (count_space UNIV) (spmf p)" by(rule measure_eqI)(simp_all add: emeasure_density nn_integral_spmf[symmetric] nn_integral_count_space_indicator)
lemma integral_measure_spmf: fixes f :: "'a ==> 'b::{banach, second_countable_topology}" assumes A: "finite A" shows"(∧a. a ∈ set_spmf M ==> f a ≠ 0 ==> a ∈ A) ==> (LINT x|measure_spmf M. f x) = (∑a∈A. spmf M a *R f a)" unfolding measure_spmf_eq_density apply (simp add: integral_density) apply (subst lebesgue_integral_count_space_finite_support) by (auto intro!: finite_subset[OF _ ‹finite A›] sum.mono_neutral_left simp: spmf_eq_0_set_spmf)
lemma image_set_spmf_eq: "f ` set_spmf p = g ` set_spmf q"if"ASSUMPTION (map_spmf f p = map_spmf g q)" using that[unfolded ASSUMPTION_def, THEN arg_cong[where f=set_spmf]] by simp
lemma mk_lossless_parametric [transfer_rule]: includes lifting_syntax shows "(rel_spmf A ===> rel_spmf A) mk_lossless mk_lossless" by(simp add: mk_lossless_def rel_fun_def rel_spmf_weightD rel_spmf_scaleI)
lemma rel_spmf_mk_losslessI: "rel_spmf A p q ==> rel_spmf A (mk_lossless p) (mk_lossless q)" by(rule mk_lossless_parametric[THEN rel_funD])
lemma rel_spmf_restrict_spmfI: "rel_spmf (λx y. (x ∈ A ∧ y ∈ B ∧ R x y) ∨ x ∉ A ∧ y ∉ B) p q ==> rel_spmf R (restrict_spmf p A) (restrict_spmf q B)" by(auto simp add: restrict_spmf_def pmf.rel_map elim!: option.rel_cases pmf.rel_mono_strong)
lemma cond_spmf_alt: "cond_spmf p A = mk_lossless (restrict_spmf p A)" proof(cases "set_spmf p ∩ A = {}") case True thenshow ?thesis by(simp add: cond_spmf_def measure_spmf_zero_iff) next case False show ?thesis by(rule spmf_eqI)(simp add: False cond_spmf_def pmf_cond set_pmf_Int_Some image_iff measure_measure_spmf_conv_measure_pmf[symmetric] spmf_scale_spmf max_def inverse_eq_divide) qed
lemma cond_spmf_bind: "cond_spmf (bind_spmf p f) A = mk_lossless (p 🍋 (λx. f x ↿ A))" by(simp add: cond_spmf_alt restrict_bind_spmf scale_bind_spmf)
lemma cond_pmf_singleton: "cond_pmf p A = return_pmf x"if"set_pmf p ∩ A = {x}" proof - have[simp]: "set_pmf p ∩ A = {x} ==> x ∈ A ==> measure_pmf.prob p A = pmf p x" by(auto simp add: measure_pmf_single[symmetric] AE_measure_pmf_iff intro!: measure_pmf.finite_measure_eq_AE)
have"pmf (cond_pmf p A) i = pmf (return_pmf x) i"for i using that by(auto simp add: pmf_cond measure_pmf_zero_iff pmf_eq_0_set_pmf split: split_indicator)
thenshow ?thesis by(rule pmf_eqI) qed
definition cond_spmf_fst :: "('a × 'b) spmf ==> 'a ==> 'b spmf"where "cond_spmf_fst p a = map_spmf snd (cond_spmf p ({a} × UNIV))"
lemma cond_spmf_fst_map_Pair1: "cond_spmf_fst (map_spmf (λx. (f x, g x)) p) (f x) = return_spmf (g (inv_into (set_spmf p) f (f x)))" if"x ∈ set_spmf p""inj_on f (set_spmf p)" proof - let ?foo="λy. map_option (λx. (f x, g x)) -` Some ` ({f y} × UNIV)" have[simp]: "y ∈ set_spmf p ==> f x = f y ==> set_pmf p ∩ (?foo y) ≠ {}"for y by(auto simp add: vimage_def image_def in_set_spmf)
have[simp]: "y ∈ set_spmf p ==> f x = f y ==> map_spmf snd (map_spmf (λx. (f x, g x)) (cond_pmf p (?foo y))) = return_spmf (g x)"for y using that by(subst cond_pmf_singleton[where x="Some x"]) (auto simp add: in_set_spmf elim: inj_onD)
show ?thesis using that by(auto simp add: cond_spmf_fst_def cond_spmf_def)
(erule notE, subst cond_map_pmf, simp_all) qed
lemma lossless_cond_spmf_fst [simp]: "lossless_spmf (cond_spmf_fst p x) ⟷ x ∈ fst ` set_spmf p" by(auto simp add: cond_spmf_fst_def intro: rev_image_eqI)
subsubsection‹Embedding of @{typ "'a option"} into @{typ "'a spmf"}›
text‹This theoretically follows from the embedding between @{typ "_ id"} into @{typ "_ prob"} and the isomorphism
between @{typ "(_, _ prob) optionT"} and @{typ "_ spmf"}, but we would only get the monomorphic
version via this connection. So we do it directly. ›
lemma map_option_le_spmf_transfer [transfer_rule]: "(((=) ===> (=)) ===> cr_option_le_spmf ===> cr_option_le_spmf) map_option map_spmf" unfolding rel_fun_eq apply(clarsimp simp add: rel_fun_def cr_option_le_spmf_def rel_pmf_return_pmf1 ord_option_map1 ord_option_map2)
subgoal for f x p y by(cases x; simp add: ord_option_reflI) done
lemma bind_option_le_spmf_transfer [transfer_rule]: "(cr_option_le_spmf ===> ((=) ===> cr_option_le_spmf) ===> cr_option_le_spmf) Option.bind bind_spmf" apply(clarsimp simp add: rel_fun_def cr_option_le_spmf_def)
subgoal for x p f g by(cases x; auto 43 simp add: rel_pmf_return_pmf1 set_pmf_bind_spmf) done
end
end
interpretation rel_spmf_characterisation by unfold_locales(rule rel_pmf_measureI)
lemma if_distrib_bind_spmf1 [if_distribs]: "bind_spmf (if b then x else y) f = (if b then bind_spmf x f else bind_spmf y f)" by simp
lemma if_distrib_bind_spmf2 [if_distribs]: "bind_spmf x (λy. if b then f y else g y) = (if b then bind_spmf x f else bind_spmf x g)" by simp
lemma rel_spmf_if_distrib [if_distribs]: "rel_spmf R (if b then x else y) (if b then x' else y') ⟷ (b ⟶ rel_spmf R x x') ∧ (¬ b ⟶ rel_spmf R y y')" by(simp)
lemma if_distrib_map_spmf [if_distribs]: "map_spmf f (if b then p else q) = (if b then map_spmf f p else map_spmf f q)" by simp
lemma if_distrib_restrict_spmf1 [if_distribs]: "restrict_spmf (if b then p else q) A = (if b then restrict_spmf p A else restrict_spmf q A)" by simp
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.