huffman@47325: (* Title: HOL/Transfer.thy
huffman@47325: Author: Brian Huffman, TU Muenchen
huffman@47325: *)
huffman@47325:
huffman@47325: header {* Generic theorem transfer using relations *}
huffman@47325:
huffman@47325: theory Transfer
huffman@47325: imports Plain Hilbert_Choice
huffman@47325: uses ("Tools/transfer.ML")
huffman@47325: begin
huffman@47325:
huffman@47325: subsection {* Relator for function space *}
huffman@47325:
huffman@47325: definition
huffman@47325: fun_rel :: "('a \ 'c \ bool) \ ('b \ 'd \ bool) \ ('a \ 'b) \ ('c \ 'd) \ bool" (infixr "===>" 55)
huffman@47325: where
huffman@47325: "fun_rel A B = (\f g. \x y. A x y \ B (f x) (g y))"
huffman@47325:
huffman@47325: lemma fun_relI [intro]:
huffman@47325: assumes "\x y. A x y \ B (f x) (g y)"
huffman@47325: shows "(A ===> B) f g"
huffman@47325: using assms by (simp add: fun_rel_def)
huffman@47325:
huffman@47325: lemma fun_relD:
huffman@47325: assumes "(A ===> B) f g" and "A x y"
huffman@47325: shows "B (f x) (g y)"
huffman@47325: using assms by (simp add: fun_rel_def)
huffman@47325:
huffman@47325: lemma fun_relE:
huffman@47325: assumes "(A ===> B) f g" and "A x y"
huffman@47325: obtains "B (f x) (g y)"
huffman@47325: using assms by (simp add: fun_rel_def)
huffman@47325:
huffman@47325: lemma fun_rel_eq:
huffman@47325: shows "((op =) ===> (op =)) = (op =)"
huffman@47325: by (auto simp add: fun_eq_iff elim: fun_relE)
huffman@47325:
huffman@47325: lemma fun_rel_eq_rel:
huffman@47325: shows "((op =) ===> R) = (\f g. \x. R (f x) (g x))"
huffman@47325: by (simp add: fun_rel_def)
huffman@47325:
huffman@47325:
huffman@47325: subsection {* Transfer method *}
huffman@47325:
huffman@47325: text {* Explicit tags for application, abstraction, and relation
huffman@47325: membership allow for backward proof methods. *}
huffman@47325:
huffman@47325: definition App :: "('a \ 'b) \ 'a \ 'b"
huffman@47325: where "App f \ f"
huffman@47325:
huffman@47325: definition Abs :: "('a \ 'b) \ 'a \ 'b"
huffman@47325: where "Abs f \ f"
huffman@47325:
huffman@47325: definition Rel :: "('a \ 'b \ bool) \ 'a \ 'b \ bool"
huffman@47325: where "Rel r \ r"
huffman@47325:
huffman@47325: text {* Handling of meta-logic connectives *}
huffman@47325:
huffman@47325: definition transfer_forall where
huffman@47325: "transfer_forall \ All"
huffman@47325:
huffman@47325: definition transfer_implies where
huffman@47325: "transfer_implies \ op \"
huffman@47325:
huffman@47325: lemma transfer_forall_eq: "(\x. P x) \ Trueprop (transfer_forall (\x. P x))"
huffman@47325: unfolding atomize_all transfer_forall_def ..
huffman@47325:
huffman@47325: lemma transfer_implies_eq: "(A \ B) \ Trueprop (transfer_implies A B)"
huffman@47325: unfolding atomize_imp transfer_implies_def ..
huffman@47325:
huffman@47325: lemma transfer_start: "\Rel (op =) P Q; P\ \ Q"
huffman@47325: unfolding Rel_def by simp
huffman@47325:
huffman@47325: lemma transfer_start': "\Rel (op \) P Q; P\ \ Q"
huffman@47325: unfolding Rel_def by simp
huffman@47325:
huffman@47325: lemma Rel_eq_refl: "Rel (op =) x x"
huffman@47325: unfolding Rel_def ..
huffman@47325:
huffman@47325: use "Tools/transfer.ML"
huffman@47325:
huffman@47325: setup Transfer.setup
huffman@47325:
huffman@47325: lemma Rel_App [transfer_raw]:
huffman@47325: assumes "Rel (A ===> B) f g" and "Rel A x y"
huffman@47325: shows "Rel B (App f x) (App g y)"
huffman@47325: using assms unfolding Rel_def App_def fun_rel_def by fast
huffman@47325:
huffman@47325: lemma Rel_Abs [transfer_raw]:
huffman@47325: assumes "\x y. Rel A x y \ Rel B (f x) (g y)"
huffman@47325: shows "Rel (A ===> B) (Abs (\x. f x)) (Abs (\y. g y))"
huffman@47325: using assms unfolding Rel_def Abs_def fun_rel_def by fast
huffman@47325:
huffman@47325: hide_const (open) App Abs Rel
huffman@47325:
huffman@47325:
huffman@47325: subsection {* Predicates on relations, i.e. ``class constraints'' *}
huffman@47325:
huffman@47325: definition right_total :: "('a \ 'b \ bool) \ bool"
huffman@47325: where "right_total R \ (\y. \x. R x y)"
huffman@47325:
huffman@47325: definition right_unique :: "('a \ 'b \ bool) \ bool"
huffman@47325: where "right_unique R \ (\x y z. R x y \ R x z \ y = z)"
huffman@47325:
huffman@47325: definition bi_total :: "('a \ 'b \ bool) \ bool"
huffman@47325: where "bi_total R \ (\x. \y. R x y) \ (\y. \x. R x y)"
huffman@47325:
huffman@47325: definition bi_unique :: "('a \ 'b \ bool) \ bool"
huffman@47325: where "bi_unique R \
huffman@47325: (\x y z. R x y \ R x z \ y = z) \
huffman@47325: (\x y z. R x z \ R y z \ x = y)"
huffman@47325:
huffman@47325: lemma right_total_alt_def:
huffman@47325: "right_total R \ ((R ===> op \) ===> op \) All All"
huffman@47325: unfolding right_total_def fun_rel_def
huffman@47325: apply (rule iffI, fast)
huffman@47325: apply (rule allI)
huffman@47325: apply (drule_tac x="\x. True" in spec)
huffman@47325: apply (drule_tac x="\y. \x. R x y" in spec)
huffman@47325: apply fast
huffman@47325: done
huffman@47325:
huffman@47325: lemma right_unique_alt_def:
huffman@47325: "right_unique R \ (R ===> R ===> op \) (op =) (op =)"
huffman@47325: unfolding right_unique_def fun_rel_def by auto
huffman@47325:
huffman@47325: lemma bi_total_alt_def:
huffman@47325: "bi_total R \ ((R ===> op =) ===> op =) All All"
huffman@47325: unfolding bi_total_def fun_rel_def
huffman@47325: apply (rule iffI, fast)
huffman@47325: apply safe
huffman@47325: apply (drule_tac x="\x. \y. R x y" in spec)
huffman@47325: apply (drule_tac x="\y. True" in spec)
huffman@47325: apply fast
huffman@47325: apply (drule_tac x="\x. True" in spec)
huffman@47325: apply (drule_tac x="\y. \x. R x y" in spec)
huffman@47325: apply fast
huffman@47325: done
huffman@47325:
huffman@47325: lemma bi_unique_alt_def:
huffman@47325: "bi_unique R \ (R ===> R ===> op =) (op =) (op =)"
huffman@47325: unfolding bi_unique_def fun_rel_def by auto
huffman@47325:
huffman@47325:
huffman@47325: subsection {* Properties of relators *}
huffman@47325:
huffman@47325: lemma right_total_eq [transfer_rule]: "right_total (op =)"
huffman@47325: unfolding right_total_def by simp
huffman@47325:
huffman@47325: lemma right_unique_eq [transfer_rule]: "right_unique (op =)"
huffman@47325: unfolding right_unique_def by simp
huffman@47325:
huffman@47325: lemma bi_total_eq [transfer_rule]: "bi_total (op =)"
huffman@47325: unfolding bi_total_def by simp
huffman@47325:
huffman@47325: lemma bi_unique_eq [transfer_rule]: "bi_unique (op =)"
huffman@47325: unfolding bi_unique_def by simp
huffman@47325:
huffman@47325: lemma right_total_fun [transfer_rule]:
huffman@47325: "\right_unique A; right_total B\ \ right_total (A ===> B)"
huffman@47325: unfolding right_total_def fun_rel_def
huffman@47325: apply (rule allI, rename_tac g)
huffman@47325: apply (rule_tac x="\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: "\right_total A; right_unique B\ \ right_unique (A ===> B)"
huffman@47325: unfolding right_total_def right_unique_def fun_rel_def
huffman@47325: by (clarify, rule ext, fast)
huffman@47325:
huffman@47325: lemma bi_total_fun [transfer_rule]:
huffman@47325: "\bi_unique A; bi_total B\ \ bi_total (A ===> B)"
huffman@47325: unfolding bi_total_def fun_rel_def
huffman@47325: apply safe
huffman@47325: apply (rename_tac f)
huffman@47325: apply (rule_tac x="\y. SOME z. B (f (THE x. A x y)) z" in exI)
huffman@47325: apply clarify
huffman@47325: apply (subgoal_tac "(THE x. A x y) = x", 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: bi_unique_def)
huffman@47325: apply (rename_tac g)
huffman@47325: apply (rule_tac x="\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: bi_unique_def)
huffman@47325: done
huffman@47325:
huffman@47325: lemma bi_unique_fun [transfer_rule]:
huffman@47325: "\bi_total A; bi_unique B\ \ bi_unique (A ===> B)"
huffman@47325: unfolding bi_total_def bi_unique_def fun_rel_def fun_eq_iff
huffman@47325: by (safe, metis, fast)
huffman@47325:
huffman@47325:
huffman@47325: subsection {* Correspondence rules *}
huffman@47325:
huffman@47325: lemma eq_parametric [transfer_rule]:
huffman@47325: assumes "bi_unique A"
huffman@47325: shows "(A ===> A ===> op =) (op =) (op =)"
huffman@47325: using assms unfolding bi_unique_def fun_rel_def by auto
huffman@47325:
huffman@47325: lemma All_parametric [transfer_rule]:
huffman@47325: assumes "bi_total A"
huffman@47325: shows "((A ===> op =) ===> op =) All All"
huffman@47325: using assms unfolding bi_total_def fun_rel_def by fast
huffman@47325:
huffman@47325: lemma Ex_parametric [transfer_rule]:
huffman@47325: assumes "bi_total A"
huffman@47325: shows "((A ===> op =) ===> op =) Ex Ex"
huffman@47325: using assms unfolding bi_total_def fun_rel_def by fast
huffman@47325:
huffman@47325: lemma If_parametric [transfer_rule]: "(op = ===> A ===> A ===> A) If If"
huffman@47325: unfolding fun_rel_def by simp
huffman@47325:
huffman@47325: lemma comp_parametric [transfer_rule]:
huffman@47325: "((B ===> C) ===> (A ===> B) ===> (A ===> C)) (op \) (op \)"
huffman@47325: unfolding fun_rel_def by simp
huffman@47325:
huffman@47325: lemma fun_upd_parametric [transfer_rule]:
huffman@47325: assumes [transfer_rule]: "bi_unique A"
huffman@47325: shows "((A ===> B) ===> A ===> B ===> A ===> B) fun_upd fun_upd"
huffman@47325: unfolding fun_upd_def [abs_def] by correspondence
huffman@47325:
huffman@47325: lemmas transfer_forall_parametric [transfer_rule]
huffman@47325: = All_parametric [folded transfer_forall_def]
huffman@47325:
huffman@47325: end