
huffman@47325: (*  Title:      HOL/Transfer.thy
huffman@47325:     Author:     Brian Huffman, TU Muenchen
kuncar@51956:     Author:     Ondrej Kuncar, TU Muenchen
huffman@47325: *)
huffman@47325: 
huffman@47325: header {* Generic theorem transfer using relations *}
huffman@47325: 
huffman@47325: theory Transfer
blanchet@56654: imports Hilbert_Choice BNF_FP_Base Metis Option
huffman@47325: begin
huffman@47325: 
kuncar@56677: (* We include Option here although it's not needed here. 
kuncar@56524:    By doing this, we avoid a diamond problem for BNF and 
kuncar@56524:    FP sugar interpretation defined in this file. *)
kuncar@56524: 
huffman@47325: subsection {* Relator for function space *}
huffman@47325: 
kuncar@53011: locale lifting_syntax
kuncar@53011: begin
blanchet@55945:   notation rel_fun (infixr "===>" 55)
kuncar@53011:   notation map_fun (infixr "--->" 55)
kuncar@53011: end
kuncar@53011: 
kuncar@53011: context
kuncar@53011: begin
kuncar@53011: interpretation lifting_syntax .
kuncar@53011: 
blanchet@55945: lemma rel_funD2:
blanchet@55945:   assumes "rel_fun A B f g" and "A x x"
kuncar@47937:   shows "B (f x) (g x)"
blanchet@55945:   using assms by (rule rel_funD)
kuncar@47937: 
blanchet@55945: lemma rel_funE:
blanchet@55945:   assumes "rel_fun A B f g" and "A x y"
huffman@47325:   obtains "B (f x) (g y)"
blanchet@55945:   using assms by (simp add: rel_fun_def)
huffman@47325: 
blanchet@55945: lemmas rel_fun_eq = fun.rel_eq
huffman@47325: 
blanchet@55945: lemma rel_fun_eq_rel:
blanchet@55945: shows "rel_fun (op =) R = (\<lambda>f g. \<forall>x. R (f x) (g x))"
blanchet@55945:   by (simp add: rel_fun_def)
huffman@47325: 
huffman@47325: 
huffman@47325: subsection {* Transfer method *}
huffman@47325: 
huffman@47789: text {* Explicit tag for relation membership allows for
huffman@47789:   backward proof methods. *}
huffman@47325: 
huffman@47325: definition Rel :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool"
huffman@47325:   where "Rel r \<equiv> r"
huffman@47325: 
huffman@49975: text {* Handling of equality relations *}
huffman@49975: 
huffman@49975: definition is_equality :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
huffman@49975:   where "is_equality R \<longleftrightarrow> R = (op =)"
huffman@49975: 
kuncar@51437: lemma is_equality_eq: "is_equality (op =)"
kuncar@51437:   unfolding is_equality_def by simp
kuncar@51437: 
huffman@52354: text {* Reverse implication for monotonicity rules *}
huffman@52354: 
huffman@52354: definition rev_implies where
huffman@52354:   "rev_implies x y \<longleftrightarrow> (y \<longrightarrow> x)"
huffman@52354: 
huffman@47325: text {* Handling of meta-logic connectives *}
huffman@47325: 
huffman@47325: definition transfer_forall where
huffman@47325:   "transfer_forall \<equiv> All"
huffman@47325: 
huffman@47325: definition transfer_implies where
huffman@47325:   "transfer_implies \<equiv> op \<longrightarrow>"
huffman@47325: 
huffman@47355: definition transfer_bforall :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool"
huffman@47355:   where "transfer_bforall \<equiv> (\<lambda>P Q. \<forall>x. P x \<longrightarrow> Q x)"
huffman@47355: 
huffman@47325: lemma transfer_forall_eq: "(\<And>x. P x) \<equiv> Trueprop (transfer_forall (\<lambda>x. P x))"
huffman@47325:   unfolding atomize_all transfer_forall_def ..
huffman@47325: 
huffman@47325: lemma transfer_implies_eq: "(A \<Longrightarrow> B) \<equiv> Trueprop (transfer_implies A B)"
huffman@47325:   unfolding atomize_imp transfer_implies_def ..
huffman@47325: 
huffman@47355: lemma transfer_bforall_unfold:
huffman@47355:   "Trueprop (transfer_bforall P (\<lambda>x. Q x)) \<equiv> (\<And>x. P x \<Longrightarrow> Q x)"
huffman@47355:   unfolding transfer_bforall_def atomize_imp atomize_all ..
huffman@47355: 
huffman@47658: lemma transfer_start: "\<lbrakk>P; Rel (op =) P Q\<rbrakk> \<Longrightarrow> Q"
huffman@47325:   unfolding Rel_def by simp
huffman@47325: 
huffman@47658: lemma transfer_start': "\<lbrakk>P; Rel (op \<longrightarrow>) P Q\<rbrakk> \<Longrightarrow> Q"
huffman@47325:   unfolding Rel_def by simp
huffman@47325: 
huffman@47635: lemma transfer_prover_start: "\<lbrakk>x = x'; Rel R x' y\<rbrakk> \<Longrightarrow> Rel R x y"
huffman@47618:   by simp
huffman@47618: 
huffman@52358: lemma untransfer_start: "\<lbrakk>Q; Rel (op =) P Q\<rbrakk> \<Longrightarrow> P"
huffman@52358:   unfolding Rel_def by simp
huffman@52358: 
huffman@47325: lemma Rel_eq_refl: "Rel (op =) x x"
huffman@47325:   unfolding Rel_def ..
huffman@47325: 
huffman@47789: lemma Rel_app:
huffman@47523:   assumes "Rel (A ===> B) f g" and "Rel A x y"
huffman@47789:   shows "Rel B (f x) (g y)"
blanchet@55945:   using assms unfolding Rel_def rel_fun_def by fast
huffman@47523: 
huffman@47789: lemma Rel_abs:
huffman@47523:   assumes "\<And>x y. Rel A x y \<Longrightarrow> Rel B (f x) (g y)"
huffman@47789:   shows "Rel (A ===> B) (\<lambda>x. f x) (\<lambda>y. g y)"
blanchet@55945:   using assms unfolding Rel_def rel_fun_def by fast
huffman@47523: 
huffman@47325: subsection {* Predicates on relations, i.e. ``class constraints'' *}
huffman@47325: 
kuncar@56518: definition left_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
kuncar@56518:   where "left_total R \<longleftrightarrow> (\<forall>x. \<exists>y. R x y)"
kuncar@56518: 
kuncar@56518: definition left_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
kuncar@56518:   where "left_unique R \<longleftrightarrow> (\<forall>x y z. R x z \<longrightarrow> R y z \<longrightarrow> x = y)"
kuncar@56518: 
huffman@47325: definition right_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
huffman@47325:   where "right_total R \<longleftrightarrow> (\<forall>y. \<exists>x. R x y)"
huffman@47325: 
huffman@47325: definition right_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
huffman@47325:   where "right_unique R \<longleftrightarrow> (\<forall>x y z. R x y \<longrightarrow> R x z \<longrightarrow> y = z)"
huffman@47325: 
huffman@47325: definition bi_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
huffman@47325:   where "bi_total R \<longleftrightarrow> (\<forall>x. \<exists>y. R x y) \<and> (\<forall>y. \<exists>x. R x y)"
huffman@47325: 
huffman@47325: definition bi_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
huffman@47325:   where "bi_unique R \<longleftrightarrow>
huffman@47325:     (\<forall>x y z. R x y \<longrightarrow> R x z \<longrightarrow> y = z) \<and>
huffman@47325:     (\<forall>x y z. R x z \<longrightarrow> R y z \<longrightarrow> x = y)"
huffman@47325: 
kuncar@56518: lemma left_uniqueI: "(\<And>x y z. \<lbrakk> A x z; A y z \<rbrakk> \<Longrightarrow> x = y) \<Longrightarrow> left_unique A"
kuncar@56518: unfolding left_unique_def by blast
kuncar@56518: 
kuncar@56518: lemma left_uniqueD: "\<lbrakk> left_unique A; A x z; A y z \<rbrakk> \<Longrightarrow> x = y"
kuncar@56518: unfolding left_unique_def by blast
kuncar@56518: 
kuncar@56518: lemma left_totalI:
kuncar@56518:   "(\<And>x. \<exists>y. R x y) \<Longrightarrow> left_total R"
kuncar@56518: unfolding left_total_def by blast
kuncar@56518: 
kuncar@56518: lemma left_totalE:
kuncar@56518:   assumes "left_total R"
kuncar@56518:   obtains "(\<And>x. \<exists>y. R x y)"
kuncar@56518: using assms unfolding left_total_def by blast
kuncar@56518: 
Andreas@53927: lemma bi_uniqueDr: "\<lbrakk> bi_unique A; A x y; A x z \<rbrakk> \<Longrightarrow> y = z"
Andreas@53927: by(simp add: bi_unique_def)
Andreas@53927: 
Andreas@53927: lemma bi_uniqueDl: "\<lbrakk> bi_unique A; A x y; A z y \<rbrakk> \<Longrightarrow> x = z"
Andreas@53927: by(simp add: bi_unique_def)
Andreas@53927: 
Andreas@53927: lemma right_uniqueI: "(\<And>x y z. \<lbrakk> A x y; A x z \<rbrakk> \<Longrightarrow> y = z) \<Longrightarrow> right_unique A"
blanchet@56085: unfolding right_unique_def by fast
Andreas@53927: 
Andreas@53927: lemma right_uniqueD: "\<lbrakk> right_unique A; A x y; A x z \<rbrakk> \<Longrightarrow> y = z"
blanchet@56085: unfolding right_unique_def by fast
Andreas@53927: 
kuncar@56524: lemma right_total_alt_def2:
huffman@47325:   "right_total R \<longleftrightarrow> ((R ===> op \<longrightarrow>) ===> op \<longrightarrow>) All All"
blanchet@55945:   unfolding right_total_def rel_fun_def
huffman@47325:   apply (rule iffI, fast)
huffman@47325:   apply (rule allI)
huffman@47325:   apply (drule_tac x="\<lambda>x. True" in spec)
huffman@47325:   apply (drule_tac x="\<lambda>y. \<exists>x. R x y" in spec)
huffman@47325:   apply fast
huffman@47325:   done
huffman@47325: 
kuncar@56524: lemma right_unique_alt_def2:
huffman@47325:   "right_unique R \<longleftrightarrow> (R ===> R ===> op \<longrightarrow>) (op =) (op =)"
blanchet@55945:   unfolding right_unique_def rel_fun_def by auto
huffman@47325: 
kuncar@56524: lemma bi_total_alt_def2:
huffman@47325:   "bi_total R \<longleftrightarrow> ((R ===> op =) ===> op =) All All"
blanchet@55945:   unfolding bi_total_def rel_fun_def
huffman@47325:   apply (rule iffI, fast)
huffman@47325:   apply safe
huffman@47325:   apply (drule_tac x="\<lambda>x. \<exists>y. R x y" in spec)
huffman@47325:   apply (drule_tac x="\<lambda>y. True" in spec)
huffman@47325:   apply fast
huffman@47325:   apply (drule_tac x="\<lambda>x. True" in spec)
huffman@47325:   apply (drule_tac x="\<lambda>y. \<exists>x. R x y" in spec)
huffman@47325:   apply fast
huffman@47325:   done
huffman@47325: 
kuncar@56524: lemma bi_unique_alt_def2:
huffman@47325:   "bi_unique R \<longleftrightarrow> (R ===> R ===> op =) (op =) (op =)"
blanchet@55945:   unfolding bi_unique_def rel_fun_def by auto
huffman@47325: 
kuncar@56518: lemma [simp]:
kuncar@56518:   shows left_unique_conversep: "left_unique A\<inverse>\<inverse> \<longleftrightarrow> right_unique A"
kuncar@56518:   and right_unique_conversep: "right_unique A\<inverse>\<inverse> \<longleftrightarrow> left_unique A"
kuncar@56518: by(auto simp add: left_unique_def right_unique_def)
kuncar@56518: 
kuncar@56518: lemma [simp]:
kuncar@56518:   shows left_total_conversep: "left_total A\<inverse>\<inverse> \<longleftrightarrow> right_total A"
kuncar@56518:   and right_total_conversep: "right_total A\<inverse>\<inverse> \<longleftrightarrow> left_total A"
kuncar@56518: by(simp_all add: left_total_def right_total_def)
kuncar@56518: 
Andreas@53944: lemma bi_unique_conversep [simp]: "bi_unique R\<inverse>\<inverse> = bi_unique R"
Andreas@53944: by(auto simp add: bi_unique_def)
Andreas@53944: 
Andreas@53944: lemma bi_total_conversep [simp]: "bi_total R\<inverse>\<inverse> = bi_total R"
Andreas@53944: by(auto simp add: bi_total_def)
Andreas@53944: 
kuncar@56524: lemma right_unique_alt_def: "right_unique R = (conversep R OO R \<le> op=)" unfolding right_unique_def by blast
kuncar@56524: lemma left_unique_alt_def: "left_unique R = (R OO (conversep R) \<le> op=)" unfolding left_unique_def by blast
kuncar@56524: 
kuncar@56524: lemma right_total_alt_def: "right_total R = (conversep R OO R \<ge> op=)" unfolding right_total_def by blast
kuncar@56524: lemma left_total_alt_def: "left_total R = (R OO conversep R \<ge> op=)" unfolding left_total_def by blast
kuncar@56524: 
kuncar@56524: lemma bi_total_alt_def: "bi_total A = (left_total A \<and> right_total A)"
kuncar@56518: unfolding left_total_def right_total_def bi_total_def by blast
kuncar@56518: 
kuncar@56524: lemma bi_unique_alt_def: "bi_unique A = (left_unique A \<and> right_unique A)"
kuncar@56518: unfolding left_unique_def right_unique_def bi_unique_def by blast
kuncar@56518: 
kuncar@56518: lemma bi_totalI: "left_total R \<Longrightarrow> right_total R \<Longrightarrow> bi_total R"
kuncar@56524: unfolding bi_total_alt_def ..
kuncar@56518: 
kuncar@56518: lemma bi_uniqueI: "left_unique R \<Longrightarrow> right_unique R \<Longrightarrow> bi_unique R"
kuncar@56524: unfolding bi_unique_alt_def ..
kuncar@56524: 
kuncar@56524: end
kuncar@56524: 
kuncar@56524: subsection {* Equality restricted by a predicate *}
kuncar@56524: 
kuncar@56524: definition eq_onp :: "('a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" 
kuncar@56524:   where "eq_onp R = (\<lambda>x y. R x \<and> x = y)"
kuncar@56524: 
blanchet@57398: lemma eq_onp_Grp: "eq_onp P = BNF_Def.Grp (Collect P) id" 
kuncar@56524: unfolding eq_onp_def Grp_def by auto 
kuncar@56524: 
kuncar@56524: lemma eq_onp_to_eq:
kuncar@56524:   assumes "eq_onp P x y"
kuncar@56524:   shows "x = y"
kuncar@56524: using assms by (simp add: eq_onp_def)
kuncar@56524: 
kuncar@56677: lemma eq_onp_top_eq_eq: "eq_onp top = op=" 
kuncar@56677: by (simp add: eq_onp_def)
kuncar@56677: 
kuncar@56524: lemma eq_onp_same_args:
kuncar@56524:   shows "eq_onp P x x = P x"
kuncar@56524: using assms by (auto simp add: eq_onp_def)
kuncar@56524: 
kuncar@56524: lemma Ball_Collect: "Ball A P = (A \<subseteq> (Collect P))"
blanchet@57260: by auto
kuncar@56518: 
kuncar@56524: ML_file "Tools/Transfer/transfer.ML"
kuncar@56524: setup Transfer.setup
kuncar@56524: declare refl [transfer_rule]
kuncar@56524: 
kuncar@56524: hide_const (open) Rel
kuncar@56524: 
kuncar@56524: context
kuncar@56524: begin
kuncar@56524: interpretation lifting_syntax .
kuncar@56524: 
kuncar@56524: text {* Handling of domains *}
kuncar@56524: 
kuncar@56524: lemma Domainp_iff: "Domainp T x \<longleftrightarrow> (\<exists>y. T x y)"
kuncar@56524:   by auto
kuncar@56524: 
kuncar@56524: lemma Domaimp_refl[transfer_domain_rule]:
kuncar@56524:   "Domainp T = Domainp T" ..
kuncar@56524: 
kuncar@56524: lemma Domainp_prod_fun_eq[relator_domain]:
kuncar@56524:   "Domainp (op= ===> T) = (\<lambda>f. \<forall>x. (Domainp T) (f x))"
kuncar@56524: by (auto intro: choice simp: Domainp_iff rel_fun_def fun_eq_iff)
kuncar@56518: 
huffman@47660: text {* Properties are preserved by relation composition. *}
huffman@47660: 
huffman@47660: lemma OO_def: "R OO S = (\<lambda>x z. \<exists>y. R x y \<and> S y z)"
huffman@47660:   by auto
huffman@47660: 
huffman@47660: lemma bi_total_OO: "\<lbrakk>bi_total A; bi_total B\<rbrakk> \<Longrightarrow> bi_total (A OO B)"
blanchet@56085:   unfolding bi_total_def OO_def by fast
huffman@47660: 
huffman@47660: lemma bi_unique_OO: "\<lbrakk>bi_unique A; bi_unique B\<rbrakk> \<Longrightarrow> bi_unique (A OO B)"
blanchet@56085:   unfolding bi_unique_def OO_def by blast
huffman@47660: 
huffman@47660: lemma right_total_OO:
huffman@47660:   "\<lbrakk>right_total A; right_total B\<rbrakk> \<Longrightarrow> right_total (A OO B)"
blanchet@56085:   unfolding right_total_def OO_def by fast
huffman@47660: 
huffman@47660: lemma right_unique_OO:
huffman@47660:   "\<lbrakk>right_unique A; right_unique B\<rbrakk> \<Longrightarrow> right_unique (A OO B)"
blanchet@56085:   unfolding right_unique_def OO_def by fast
huffman@47660: 
kuncar@56518: lemma left_total_OO: "left_total R \<Longrightarrow> left_total S \<Longrightarrow> left_total (R OO S)"
kuncar@56518: unfolding left_total_def OO_def by fast
kuncar@56518: 
kuncar@56518: lemma left_unique_OO: "left_unique R \<Longrightarrow> left_unique S \<Longrightarrow> left_unique (R OO S)"
kuncar@56518: unfolding left_unique_def OO_def by blast
kuncar@56518: 
huffman@47325: 
huffman@47325: subsection {* Properties of relators *}
huffman@47325: 
kuncar@56518: lemma left_total_eq[transfer_rule]: "left_total op=" 
kuncar@56518:   unfolding left_total_def by blast
kuncar@56518: 
kuncar@56518: lemma left_unique_eq[transfer_rule]: "left_unique op=" 
kuncar@56518:   unfolding left_unique_def by blast
kuncar@56518: 
kuncar@56518: lemma right_total_eq [transfer_rule]: "right_total op="
huffman@47325:   unfolding right_total_def by simp
huffman@47325: 
kuncar@56518: lemma right_unique_eq [transfer_rule]: "right_unique op="
huffman@47325:   unfolding right_unique_def by simp
huffman@47325: 
kuncar@56518: lemma bi_total_eq[transfer_rule]: "bi_total (op =)"
huffman@47325:   unfolding bi_total_def by simp
huffman@47325: 
kuncar@56518: lemma bi_unique_eq[transfer_rule]: "bi_unique (op =)"
huffman@47325:   unfolding bi_unique_def by simp
huffman@47325: 
kuncar@56518: lemma left_total_fun[transfer_rule]:
kuncar@56518:   "\<lbrakk>left_unique A; left_total B\<rbrakk> \<Longrightarrow> left_total (A ===> B)"
kuncar@56518:   unfolding left_total_def rel_fun_def
kuncar@56518:   apply (rule allI, rename_tac f)
kuncar@56518:   apply (rule_tac x="\<lambda>y. SOME z. B (f (THE x. A x y)) z" in exI)
kuncar@56518:   apply clarify
kuncar@56518:   apply (subgoal_tac "(THE x. A x y) = x", simp)
kuncar@56518:   apply (rule someI_ex)
kuncar@56518:   apply (simp)
kuncar@56518:   apply (rule the_equality)
kuncar@56518:   apply assumption
kuncar@56518:   apply (simp add: left_unique_def)
kuncar@56518:   done
kuncar@56518: 
kuncar@56518: lemma left_unique_fun[transfer_rule]:
kuncar@56518:   "\<lbrakk>left_total A; left_unique B\<rbrakk> \<Longrightarrow> left_unique (A ===> B)"
kuncar@56518:   unfolding left_total_def left_unique_def rel_fun_def
kuncar@56518:   by (clarify, rule ext, fast)
kuncar@56518: 
huffman@47325: lemma right_total_fun [transfer_rule]:
huffman@47325:   "\<lbrakk>right_unique A; right_total B\<rbrakk> \<Longrightarrow> right_total (A ===> B)"
blanchet@55945:   unfolding right_total_def rel_fun_def
huffman@47325:   apply (rule allI, rename_tac g)
huffman@47325:   apply (rule_tac x="\<lambda>x. SOME z. B z (g (THE y. A x y))" in exI)
huffman@47325:   apply clarify
huffman@47325:   apply (subgoal_tac "(THE y. A x y) = y", simp)
huffman@47325:   apply (rule someI_ex)
huffman@47325:   apply (simp)
huffman@47325:   apply (rule the_equality)
huffman@47325:   apply assumption
huffman@47325:   apply (simp add: right_unique_def)
huffman@47325:   done
huffman@47325: 
huffman@47325: lemma right_unique_fun [transfer_rule]:
huffman@47325:   "\<lbrakk>right_total A; right_unique B\<rbrakk> \<Longrightarrow> right_unique (A ===> B)"
blanchet@55945:   unfolding right_total_def right_unique_def rel_fun_def
huffman@47325:   by (clarify, rule ext, fast)
huffman@47325: 
kuncar@56518: lemma bi_total_fun[transfer_rule]:
huffman@47325:   "\<lbrakk>bi_unique A; bi_total B\<rbrakk> \<Longrightarrow> bi_total (A ===> B)"
kuncar@56524:   unfolding bi_unique_alt_def bi_total_alt_def
kuncar@56518:   by (blast intro: right_total_fun left_total_fun)
huffman@47325: 
kuncar@56518: lemma bi_unique_fun[transfer_rule]:
huffman@47325:   "\<lbrakk>bi_total A; bi_unique B\<rbrakk> \<Longrightarrow> bi_unique (A ===> B)"
kuncar@56524:   unfolding bi_unique_alt_def bi_total_alt_def
kuncar@56518:   by (blast intro: right_unique_fun left_unique_fun)
huffman@47325: 
kuncar@56543: end
kuncar@56543: 
kuncar@56543: ML_file "Tools/Transfer/transfer_bnf.ML" 
kuncar@56543: 
kuncar@56543: declare pred_fun_def [simp]
kuncar@56543: declare rel_fun_eq [relator_eq]
kuncar@56543: 
huffman@47635: subsection {* Transfer rules *}
huffman@47325: 
kuncar@56543: context
kuncar@56543: begin
kuncar@56543: interpretation lifting_syntax .
kuncar@56543: 
kuncar@53952: lemma Domainp_forall_transfer [transfer_rule]:
kuncar@53952:   assumes "right_total A"
kuncar@53952:   shows "((A ===> op =) ===> op =)
kuncar@53952:     (transfer_bforall (Domainp A)) transfer_forall"
kuncar@53952:   using assms unfolding right_total_def
blanchet@55945:   unfolding transfer_forall_def transfer_bforall_def rel_fun_def Domainp_iff
blanchet@56085:   by fast
kuncar@53952: 
huffman@47684: text {* Transfer rules using implication instead of equality on booleans. *}
huffman@47684: 
huffman@52354: lemma transfer_forall_transfer [transfer_rule]:
huffman@52354:   "bi_total A \<Longrightarrow> ((A ===> op =) ===> op =) transfer_forall transfer_forall"
huffman@52354:   "right_total A \<Longrightarrow> ((A ===> op =) ===> implies) transfer_forall transfer_forall"
huffman@52354:   "right_total A \<Longrightarrow> ((A ===> implies) ===> implies) transfer_forall transfer_forall"
huffman@52354:   "bi_total A \<Longrightarrow> ((A ===> op =) ===> rev_implies) transfer_forall transfer_forall"
huffman@52354:   "bi_total A \<Longrightarrow> ((A ===> rev_implies) ===> rev_implies) transfer_forall transfer_forall"
blanchet@55945:   unfolding transfer_forall_def rev_implies_def rel_fun_def right_total_def bi_total_def
blanchet@56085:   by fast+
huffman@52354: 
huffman@52354: lemma transfer_implies_transfer [transfer_rule]:
huffman@52354:   "(op =        ===> op =        ===> op =       ) transfer_implies transfer_implies"
huffman@52354:   "(rev_implies ===> implies     ===> implies    ) transfer_implies transfer_implies"
huffman@52354:   "(rev_implies ===> op =        ===> implies    ) transfer_implies transfer_implies"
huffman@52354:   "(op =        ===> implies     ===> implies    ) transfer_implies transfer_implies"
huffman@52354:   "(op =        ===> op =        ===> implies    ) transfer_implies transfer_implies"
huffman@52354:   "(implies     ===> rev_implies ===> rev_implies) transfer_implies transfer_implies"
huffman@52354:   "(implies     ===> op =        ===> rev_implies) transfer_implies transfer_implies"
huffman@52354:   "(op =        ===> rev_implies ===> rev_implies) transfer_implies transfer_implies"
huffman@52354:   "(op =        ===> op =        ===> rev_implies) transfer_implies transfer_implies"
blanchet@55945:   unfolding transfer_implies_def rev_implies_def rel_fun_def by auto
huffman@52354: 
huffman@47684: lemma eq_imp_transfer [transfer_rule]:
huffman@47684:   "right_unique A \<Longrightarrow> (A ===> A ===> op \<longrightarrow>) (op =) (op =)"
kuncar@56524:   unfolding right_unique_alt_def2 .
huffman@47684: 
kuncar@56518: text {* Transfer rules using equality. *}
kuncar@56518: 
kuncar@56518: lemma left_unique_transfer [transfer_rule]:
kuncar@56518:   assumes "right_total A"
kuncar@56518:   assumes "right_total B"
kuncar@56518:   assumes "bi_unique A"
kuncar@56518:   shows "((A ===> B ===> op=) ===> implies) left_unique left_unique"
kuncar@56518: using assms unfolding left_unique_def[abs_def] right_total_def bi_unique_def rel_fun_def
kuncar@56518: by metis
kuncar@56518: 
huffman@47636: lemma eq_transfer [transfer_rule]:
huffman@47325:   assumes "bi_unique A"
huffman@47325:   shows "(A ===> A ===> op =) (op =) (op =)"
blanchet@55945:   using assms unfolding bi_unique_def rel_fun_def by auto
huffman@47325: 
kuncar@51956: lemma right_total_Ex_transfer[transfer_rule]:
kuncar@51956:   assumes "right_total A"
kuncar@51956:   shows "((A ===> op=) ===> op=) (Bex (Collect (Domainp A))) Ex"
blanchet@55945: using assms unfolding right_total_def Bex_def rel_fun_def Domainp_iff[abs_def]
blanchet@56085: by fast
kuncar@51956: 
kuncar@51956: lemma right_total_All_transfer[transfer_rule]:
kuncar@51956:   assumes "right_total A"
kuncar@51956:   shows "((A ===> op =) ===> op =) (Ball (Collect (Domainp A))) All"
blanchet@55945: using assms unfolding right_total_def Ball_def rel_fun_def Domainp_iff[abs_def]
blanchet@56085: by fast
kuncar@51956: 
huffman@47636: lemma All_transfer [transfer_rule]:
huffman@47325:   assumes "bi_total A"
huffman@47325:   shows "((A ===> op =) ===> op =) All All"
blanchet@55945:   using assms unfolding bi_total_def rel_fun_def by fast
huffman@47325: 
huffman@47636: lemma Ex_transfer [transfer_rule]:
huffman@47325:   assumes "bi_total A"
huffman@47325:   shows "((A ===> op =) ===> op =) Ex Ex"
blanchet@55945:   using assms unfolding bi_total_def rel_fun_def by fast
huffman@47325: 
huffman@47636: lemma If_transfer [transfer_rule]: "(op = ===> A ===> A ===> A) If If"
blanchet@55945:   unfolding rel_fun_def by simp
huffman@47325: 
huffman@47636: lemma Let_transfer [transfer_rule]: "(A ===> (A ===> B) ===> B) Let Let"
blanchet@55945:   unfolding rel_fun_def by simp
huffman@47612: 
huffman@47636: lemma id_transfer [transfer_rule]: "(A ===> A) id id"
blanchet@55945:   unfolding rel_fun_def by simp
huffman@47625: 
huffman@47636: lemma comp_transfer [transfer_rule]:
huffman@47325:   "((B ===> C) ===> (A ===> B) ===> (A ===> C)) (op \<circ>) (op \<circ>)"
blanchet@55945:   unfolding rel_fun_def by simp
huffman@47325: 
huffman@47636: lemma fun_upd_transfer [transfer_rule]:
huffman@47325:   assumes [transfer_rule]: "bi_unique A"
huffman@47325:   shows "((A ===> B) ===> A ===> B ===> A ===> B) fun_upd fun_upd"
huffman@47635:   unfolding fun_upd_def [abs_def] by transfer_prover
huffman@47325: 
blanchet@55415: lemma case_nat_transfer [transfer_rule]:
blanchet@55415:   "(A ===> (op = ===> A) ===> op = ===> A) case_nat case_nat"
blanchet@55945:   unfolding rel_fun_def by (simp split: nat.split)
huffman@47627: 
blanchet@55415: lemma rec_nat_transfer [transfer_rule]:
blanchet@55415:   "(A ===> (op = ===> A ===> A) ===> op = ===> A) rec_nat rec_nat"
blanchet@55945:   unfolding rel_fun_def by (clarsimp, rename_tac n, induct_tac n, simp_all)
huffman@47924: 
huffman@47924: lemma funpow_transfer [transfer_rule]:
huffman@47924:   "(op = ===> (A ===> A) ===> (A ===> A)) compow compow"
huffman@47924:   unfolding funpow_def by transfer_prover
huffman@47924: 
kuncar@53952: lemma mono_transfer[transfer_rule]:
kuncar@53952:   assumes [transfer_rule]: "bi_total A"
kuncar@53952:   assumes [transfer_rule]: "(A ===> A ===> op=) op\<le> op\<le>"
kuncar@53952:   assumes [transfer_rule]: "(B ===> B ===> op=) op\<le> op\<le>"
kuncar@53952:   shows "((A ===> B) ===> op=) mono mono"
kuncar@53952: unfolding mono_def[abs_def] by transfer_prover
kuncar@53952: 
kuncar@53952: lemma right_total_relcompp_transfer[transfer_rule]: 
kuncar@53952:   assumes [transfer_rule]: "right_total B"
kuncar@53952:   shows "((A ===> B ===> op=) ===> (B ===> C ===> op=) ===> A ===> C ===> op=) 
kuncar@53952:     (\<lambda>R S x z. \<exists>y\<in>Collect (Domainp B). R x y \<and> S y z) op OO"
kuncar@53952: unfolding OO_def[abs_def] by transfer_prover
kuncar@53952: 
kuncar@53952: lemma relcompp_transfer[transfer_rule]: 
kuncar@53952:   assumes [transfer_rule]: "bi_total B"
kuncar@53952:   shows "((A ===> B ===> op=) ===> (B ===> C ===> op=) ===> A ===> C ===> op=) op OO op OO"
kuncar@53952: unfolding OO_def[abs_def] by transfer_prover
huffman@47627: 
kuncar@53952: lemma right_total_Domainp_transfer[transfer_rule]:
kuncar@53952:   assumes [transfer_rule]: "right_total B"
kuncar@53952:   shows "((A ===> B ===> op=) ===> A ===> op=) (\<lambda>T x. \<exists>y\<in>Collect(Domainp B). T x y) Domainp"
kuncar@53952: apply(subst(2) Domainp_iff[abs_def]) by transfer_prover
kuncar@53952: 
kuncar@53952: lemma Domainp_transfer[transfer_rule]:
kuncar@53952:   assumes [transfer_rule]: "bi_total B"
kuncar@53952:   shows "((A ===> B ===> op=) ===> A ===> op=) Domainp Domainp"
kuncar@53952: unfolding Domainp_iff[abs_def] by transfer_prover
kuncar@53952: 
kuncar@53952: lemma reflp_transfer[transfer_rule]: 
kuncar@53952:   "bi_total A \<Longrightarrow> ((A ===> A ===> op=) ===> op=) reflp reflp"
kuncar@53952:   "right_total A \<Longrightarrow> ((A ===> A ===> implies) ===> implies) reflp reflp"
kuncar@53952:   "right_total A \<Longrightarrow> ((A ===> A ===> op=) ===> implies) reflp reflp"
kuncar@53952:   "bi_total A \<Longrightarrow> ((A ===> A ===> rev_implies) ===> rev_implies) reflp reflp"
kuncar@53952:   "bi_total A \<Longrightarrow> ((A ===> A ===> op=) ===> rev_implies) reflp reflp"
blanchet@55945: using assms unfolding reflp_def[abs_def] rev_implies_def bi_total_def right_total_def rel_fun_def 
kuncar@53952: by fast+
kuncar@53952: 
kuncar@53952: lemma right_unique_transfer [transfer_rule]:
kuncar@53952:   assumes [transfer_rule]: "right_total A"
kuncar@53952:   assumes [transfer_rule]: "right_total B"
kuncar@53952:   assumes [transfer_rule]: "bi_unique B"
kuncar@53952:   shows "((A ===> B ===> op=) ===> implies) right_unique right_unique"
blanchet@55945: using assms unfolding right_unique_def[abs_def] right_total_def bi_unique_def rel_fun_def
kuncar@53952: by metis
huffman@47325: 
kuncar@56524: lemma rel_fun_eq_eq_onp: "(op= ===> eq_onp P) = eq_onp (\<lambda>f. \<forall>x. P(f x))"
kuncar@56524: unfolding eq_onp_def rel_fun_def by auto
kuncar@56524: 
kuncar@56524: lemma rel_fun_eq_onp_rel:
kuncar@56524:   shows "((eq_onp R) ===> S) = (\<lambda>f g. \<forall>x. R x \<longrightarrow> S (f x) (g x))"
kuncar@56524: by (auto simp add: eq_onp_def rel_fun_def)
kuncar@56524: 
kuncar@56524: lemma eq_onp_transfer [transfer_rule]:
kuncar@56524:   assumes [transfer_rule]: "bi_unique A"
kuncar@56524:   shows "((A ===> op=) ===> A ===> A ===> op=) eq_onp eq_onp"
kuncar@56524: unfolding eq_onp_def[abs_def] by transfer_prover
kuncar@56524: 
huffman@47325: end
kuncar@53011: 
kuncar@53011: end




