src/HOL/Transfer.thy
author hoelzl
Fri Feb 19 13:40:50 2016 +0100 (2016-02-19)
changeset 62378 85ed00c1fe7c
parent 62324 ae44f16dcea5
child 63092 a949b2a5f51d
permissions -rw-r--r--
generalize more theorems to support enat and ennreal
     1 (*  Title:      HOL/Transfer.thy
     2     Author:     Brian Huffman, TU Muenchen
     3     Author:     Ondrej Kuncar, TU Muenchen
     4 *)
     5 
     6 section \<open>Generic theorem transfer using relations\<close>
     7 
     8 theory Transfer
     9 imports Basic_BNF_LFPs Hilbert_Choice Metis
    10 begin
    11 
    12 subsection \<open>Relator for function space\<close>
    13 
    14 locale lifting_syntax
    15 begin
    16   notation rel_fun (infixr "===>" 55)
    17   notation map_fun (infixr "--->" 55)
    18 end
    19 
    20 context
    21 begin
    22 interpretation lifting_syntax .
    23 
    24 lemma rel_funD2:
    25   assumes "rel_fun A B f g" and "A x x"
    26   shows "B (f x) (g x)"
    27   using assms by (rule rel_funD)
    28 
    29 lemma rel_funE:
    30   assumes "rel_fun A B f g" and "A x y"
    31   obtains "B (f x) (g y)"
    32   using assms by (simp add: rel_fun_def)
    33 
    34 lemmas rel_fun_eq = fun.rel_eq
    35 
    36 lemma rel_fun_eq_rel:
    37 shows "rel_fun (op =) R = (\<lambda>f g. \<forall>x. R (f x) (g x))"
    38   by (simp add: rel_fun_def)
    39 
    40 
    41 subsection \<open>Transfer method\<close>
    42 
    43 text \<open>Explicit tag for relation membership allows for
    44   backward proof methods.\<close>
    45 
    46 definition Rel :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool"
    47   where "Rel r \<equiv> r"
    48 
    49 text \<open>Handling of equality relations\<close>
    50 
    51 definition is_equality :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
    52   where "is_equality R \<longleftrightarrow> R = (op =)"
    53 
    54 lemma is_equality_eq: "is_equality (op =)"
    55   unfolding is_equality_def by simp
    56 
    57 text \<open>Reverse implication for monotonicity rules\<close>
    58 
    59 definition rev_implies where
    60   "rev_implies x y \<longleftrightarrow> (y \<longrightarrow> x)"
    61 
    62 text \<open>Handling of meta-logic connectives\<close>
    63 
    64 definition transfer_forall where
    65   "transfer_forall \<equiv> All"
    66 
    67 definition transfer_implies where
    68   "transfer_implies \<equiv> op \<longrightarrow>"
    69 
    70 definition transfer_bforall :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool"
    71   where "transfer_bforall \<equiv> (\<lambda>P Q. \<forall>x. P x \<longrightarrow> Q x)"
    72 
    73 lemma transfer_forall_eq: "(\<And>x. P x) \<equiv> Trueprop (transfer_forall (\<lambda>x. P x))"
    74   unfolding atomize_all transfer_forall_def ..
    75 
    76 lemma transfer_implies_eq: "(A \<Longrightarrow> B) \<equiv> Trueprop (transfer_implies A B)"
    77   unfolding atomize_imp transfer_implies_def ..
    78 
    79 lemma transfer_bforall_unfold:
    80   "Trueprop (transfer_bforall P (\<lambda>x. Q x)) \<equiv> (\<And>x. P x \<Longrightarrow> Q x)"
    81   unfolding transfer_bforall_def atomize_imp atomize_all ..
    82 
    83 lemma transfer_start: "\<lbrakk>P; Rel (op =) P Q\<rbrakk> \<Longrightarrow> Q"
    84   unfolding Rel_def by simp
    85 
    86 lemma transfer_start': "\<lbrakk>P; Rel (op \<longrightarrow>) P Q\<rbrakk> \<Longrightarrow> Q"
    87   unfolding Rel_def by simp
    88 
    89 lemma transfer_prover_start: "\<lbrakk>x = x'; Rel R x' y\<rbrakk> \<Longrightarrow> Rel R x y"
    90   by simp
    91 
    92 lemma untransfer_start: "\<lbrakk>Q; Rel (op =) P Q\<rbrakk> \<Longrightarrow> P"
    93   unfolding Rel_def by simp
    94 
    95 lemma Rel_eq_refl: "Rel (op =) x x"
    96   unfolding Rel_def ..
    97 
    98 lemma Rel_app:
    99   assumes "Rel (A ===> B) f g" and "Rel A x y"
   100   shows "Rel B (f x) (g y)"
   101   using assms unfolding Rel_def rel_fun_def by fast
   102 
   103 lemma Rel_abs:
   104   assumes "\<And>x y. Rel A x y \<Longrightarrow> Rel B (f x) (g y)"
   105   shows "Rel (A ===> B) (\<lambda>x. f x) (\<lambda>y. g y)"
   106   using assms unfolding Rel_def rel_fun_def by fast
   107 
   108 subsection \<open>Predicates on relations, i.e. ``class constraints''\<close>
   109 
   110 definition left_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
   111   where "left_total R \<longleftrightarrow> (\<forall>x. \<exists>y. R x y)"
   112 
   113 definition left_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
   114   where "left_unique R \<longleftrightarrow> (\<forall>x y z. R x z \<longrightarrow> R y z \<longrightarrow> x = y)"
   115 
   116 definition right_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
   117   where "right_total R \<longleftrightarrow> (\<forall>y. \<exists>x. R x y)"
   118 
   119 definition right_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
   120   where "right_unique R \<longleftrightarrow> (\<forall>x y z. R x y \<longrightarrow> R x z \<longrightarrow> y = z)"
   121 
   122 definition bi_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
   123   where "bi_total R \<longleftrightarrow> (\<forall>x. \<exists>y. R x y) \<and> (\<forall>y. \<exists>x. R x y)"
   124 
   125 definition bi_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
   126   where "bi_unique R \<longleftrightarrow>
   127     (\<forall>x y z. R x y \<longrightarrow> R x z \<longrightarrow> y = z) \<and>
   128     (\<forall>x y z. R x z \<longrightarrow> R y z \<longrightarrow> x = y)"
   129 
   130 lemma left_uniqueI: "(\<And>x y z. \<lbrakk> A x z; A y z \<rbrakk> \<Longrightarrow> x = y) \<Longrightarrow> left_unique A"
   131 unfolding left_unique_def by blast
   132 
   133 lemma left_uniqueD: "\<lbrakk> left_unique A; A x z; A y z \<rbrakk> \<Longrightarrow> x = y"
   134 unfolding left_unique_def by blast
   135 
   136 lemma left_totalI:
   137   "(\<And>x. \<exists>y. R x y) \<Longrightarrow> left_total R"
   138 unfolding left_total_def by blast
   139 
   140 lemma left_totalE:
   141   assumes "left_total R"
   142   obtains "(\<And>x. \<exists>y. R x y)"
   143 using assms unfolding left_total_def by blast
   144 
   145 lemma bi_uniqueDr: "\<lbrakk> bi_unique A; A x y; A x z \<rbrakk> \<Longrightarrow> y = z"
   146 by(simp add: bi_unique_def)
   147 
   148 lemma bi_uniqueDl: "\<lbrakk> bi_unique A; A x y; A z y \<rbrakk> \<Longrightarrow> x = z"
   149 by(simp add: bi_unique_def)
   150 
   151 lemma right_uniqueI: "(\<And>x y z. \<lbrakk> A x y; A x z \<rbrakk> \<Longrightarrow> y = z) \<Longrightarrow> right_unique A"
   152 unfolding right_unique_def by fast
   153 
   154 lemma right_uniqueD: "\<lbrakk> right_unique A; A x y; A x z \<rbrakk> \<Longrightarrow> y = z"
   155 unfolding right_unique_def by fast
   156 
   157 lemma right_totalI: "(\<And>y. \<exists>x. A x y) \<Longrightarrow> right_total A"
   158 by(simp add: right_total_def)
   159 
   160 lemma right_totalE:
   161   assumes "right_total A"
   162   obtains x where "A x y"
   163 using assms by(auto simp add: right_total_def)
   164 
   165 lemma right_total_alt_def2:
   166   "right_total R \<longleftrightarrow> ((R ===> op \<longrightarrow>) ===> op \<longrightarrow>) All All"
   167   unfolding right_total_def rel_fun_def
   168   apply (rule iffI, fast)
   169   apply (rule allI)
   170   apply (drule_tac x="\<lambda>x. True" in spec)
   171   apply (drule_tac x="\<lambda>y. \<exists>x. R x y" in spec)
   172   apply fast
   173   done
   174 
   175 lemma right_unique_alt_def2:
   176   "right_unique R \<longleftrightarrow> (R ===> R ===> op \<longrightarrow>) (op =) (op =)"
   177   unfolding right_unique_def rel_fun_def by auto
   178 
   179 lemma bi_total_alt_def2:
   180   "bi_total R \<longleftrightarrow> ((R ===> op =) ===> op =) All All"
   181   unfolding bi_total_def rel_fun_def
   182   apply (rule iffI, fast)
   183   apply safe
   184   apply (drule_tac x="\<lambda>x. \<exists>y. R x y" in spec)
   185   apply (drule_tac x="\<lambda>y. True" in spec)
   186   apply fast
   187   apply (drule_tac x="\<lambda>x. True" in spec)
   188   apply (drule_tac x="\<lambda>y. \<exists>x. R x y" in spec)
   189   apply fast
   190   done
   191 
   192 lemma bi_unique_alt_def2:
   193   "bi_unique R \<longleftrightarrow> (R ===> R ===> op =) (op =) (op =)"
   194   unfolding bi_unique_def rel_fun_def by auto
   195 
   196 lemma [simp]:
   197   shows left_unique_conversep: "left_unique A\<inverse>\<inverse> \<longleftrightarrow> right_unique A"
   198   and right_unique_conversep: "right_unique A\<inverse>\<inverse> \<longleftrightarrow> left_unique A"
   199 by(auto simp add: left_unique_def right_unique_def)
   200 
   201 lemma [simp]:
   202   shows left_total_conversep: "left_total A\<inverse>\<inverse> \<longleftrightarrow> right_total A"
   203   and right_total_conversep: "right_total A\<inverse>\<inverse> \<longleftrightarrow> left_total A"
   204 by(simp_all add: left_total_def right_total_def)
   205 
   206 lemma bi_unique_conversep [simp]: "bi_unique R\<inverse>\<inverse> = bi_unique R"
   207 by(auto simp add: bi_unique_def)
   208 
   209 lemma bi_total_conversep [simp]: "bi_total R\<inverse>\<inverse> = bi_total R"
   210 by(auto simp add: bi_total_def)
   211 
   212 lemma right_unique_alt_def: "right_unique R = (conversep R OO R \<le> op=)" unfolding right_unique_def by blast
   213 lemma left_unique_alt_def: "left_unique R = (R OO (conversep R) \<le> op=)" unfolding left_unique_def by blast
   214 
   215 lemma right_total_alt_def: "right_total R = (conversep R OO R \<ge> op=)" unfolding right_total_def by blast
   216 lemma left_total_alt_def: "left_total R = (R OO conversep R \<ge> op=)" unfolding left_total_def by blast
   217 
   218 lemma bi_total_alt_def: "bi_total A = (left_total A \<and> right_total A)"
   219 unfolding left_total_def right_total_def bi_total_def by blast
   220 
   221 lemma bi_unique_alt_def: "bi_unique A = (left_unique A \<and> right_unique A)"
   222 unfolding left_unique_def right_unique_def bi_unique_def by blast
   223 
   224 lemma bi_totalI: "left_total R \<Longrightarrow> right_total R \<Longrightarrow> bi_total R"
   225 unfolding bi_total_alt_def ..
   226 
   227 lemma bi_uniqueI: "left_unique R \<Longrightarrow> right_unique R \<Longrightarrow> bi_unique R"
   228 unfolding bi_unique_alt_def ..
   229 
   230 end
   231 
   232 
   233 
   234 ML_file "Tools/Transfer/transfer.ML"
   235 declare refl [transfer_rule]
   236 
   237 hide_const (open) Rel
   238 
   239 context
   240 begin
   241 interpretation lifting_syntax .
   242 
   243 text \<open>Handling of domains\<close>
   244 
   245 lemma Domainp_iff: "Domainp T x \<longleftrightarrow> (\<exists>y. T x y)"
   246   by auto
   247 
   248 lemma Domainp_refl[transfer_domain_rule]:
   249   "Domainp T = Domainp T" ..
   250 
   251 lemma Domain_eq_top: "Domainp op= = top" by auto
   252 
   253 lemma Domainp_prod_fun_eq[relator_domain]:
   254   "Domainp (op= ===> T) = (\<lambda>f. \<forall>x. (Domainp T) (f x))"
   255 by (auto intro: choice simp: Domainp_iff rel_fun_def fun_eq_iff)
   256 
   257 text \<open>Properties are preserved by relation composition.\<close>
   258 
   259 lemma OO_def: "R OO S = (\<lambda>x z. \<exists>y. R x y \<and> S y z)"
   260   by auto
   261 
   262 lemma bi_total_OO: "\<lbrakk>bi_total A; bi_total B\<rbrakk> \<Longrightarrow> bi_total (A OO B)"
   263   unfolding bi_total_def OO_def by fast
   264 
   265 lemma bi_unique_OO: "\<lbrakk>bi_unique A; bi_unique B\<rbrakk> \<Longrightarrow> bi_unique (A OO B)"
   266   unfolding bi_unique_def OO_def by blast
   267 
   268 lemma right_total_OO:
   269   "\<lbrakk>right_total A; right_total B\<rbrakk> \<Longrightarrow> right_total (A OO B)"
   270   unfolding right_total_def OO_def by fast
   271 
   272 lemma right_unique_OO:
   273   "\<lbrakk>right_unique A; right_unique B\<rbrakk> \<Longrightarrow> right_unique (A OO B)"
   274   unfolding right_unique_def OO_def by fast
   275 
   276 lemma left_total_OO: "left_total R \<Longrightarrow> left_total S \<Longrightarrow> left_total (R OO S)"
   277 unfolding left_total_def OO_def by fast
   278 
   279 lemma left_unique_OO: "left_unique R \<Longrightarrow> left_unique S \<Longrightarrow> left_unique (R OO S)"
   280 unfolding left_unique_def OO_def by blast
   281 
   282 
   283 subsection \<open>Properties of relators\<close>
   284 
   285 lemma left_total_eq[transfer_rule]: "left_total op="
   286   unfolding left_total_def by blast
   287 
   288 lemma left_unique_eq[transfer_rule]: "left_unique op="
   289   unfolding left_unique_def by blast
   290 
   291 lemma right_total_eq [transfer_rule]: "right_total op="
   292   unfolding right_total_def by simp
   293 
   294 lemma right_unique_eq [transfer_rule]: "right_unique op="
   295   unfolding right_unique_def by simp
   296 
   297 lemma bi_total_eq[transfer_rule]: "bi_total (op =)"
   298   unfolding bi_total_def by simp
   299 
   300 lemma bi_unique_eq[transfer_rule]: "bi_unique (op =)"
   301   unfolding bi_unique_def by simp
   302 
   303 lemma left_total_fun[transfer_rule]:
   304   "\<lbrakk>left_unique A; left_total B\<rbrakk> \<Longrightarrow> left_total (A ===> B)"
   305   unfolding left_total_def rel_fun_def
   306   apply (rule allI, rename_tac f)
   307   apply (rule_tac x="\<lambda>y. SOME z. B (f (THE x. A x y)) z" in exI)
   308   apply clarify
   309   apply (subgoal_tac "(THE x. A x y) = x", simp)
   310   apply (rule someI_ex)
   311   apply (simp)
   312   apply (rule the_equality)
   313   apply assumption
   314   apply (simp add: left_unique_def)
   315   done
   316 
   317 lemma left_unique_fun[transfer_rule]:
   318   "\<lbrakk>left_total A; left_unique B\<rbrakk> \<Longrightarrow> left_unique (A ===> B)"
   319   unfolding left_total_def left_unique_def rel_fun_def
   320   by (clarify, rule ext, fast)
   321 
   322 lemma right_total_fun [transfer_rule]:
   323   "\<lbrakk>right_unique A; right_total B\<rbrakk> \<Longrightarrow> right_total (A ===> B)"
   324   unfolding right_total_def rel_fun_def
   325   apply (rule allI, rename_tac g)
   326   apply (rule_tac x="\<lambda>x. SOME z. B z (g (THE y. A x y))" in exI)
   327   apply clarify
   328   apply (subgoal_tac "(THE y. A x y) = y", simp)
   329   apply (rule someI_ex)
   330   apply (simp)
   331   apply (rule the_equality)
   332   apply assumption
   333   apply (simp add: right_unique_def)
   334   done
   335 
   336 lemma right_unique_fun [transfer_rule]:
   337   "\<lbrakk>right_total A; right_unique B\<rbrakk> \<Longrightarrow> right_unique (A ===> B)"
   338   unfolding right_total_def right_unique_def rel_fun_def
   339   by (clarify, rule ext, fast)
   340 
   341 lemma bi_total_fun[transfer_rule]:
   342   "\<lbrakk>bi_unique A; bi_total B\<rbrakk> \<Longrightarrow> bi_total (A ===> B)"
   343   unfolding bi_unique_alt_def bi_total_alt_def
   344   by (blast intro: right_total_fun left_total_fun)
   345 
   346 lemma bi_unique_fun[transfer_rule]:
   347   "\<lbrakk>bi_total A; bi_unique B\<rbrakk> \<Longrightarrow> bi_unique (A ===> B)"
   348   unfolding bi_unique_alt_def bi_total_alt_def
   349   by (blast intro: right_unique_fun left_unique_fun)
   350 
   351 end
   352 
   353 lemma if_conn:
   354   "(if P \<and> Q then t else e) = (if P then if Q then t else e else e)"
   355   "(if P \<or> Q then t else e) = (if P then t else if Q then t else e)"
   356   "(if P \<longrightarrow> Q then t else e) = (if P then if Q then t else e else t)"
   357   "(if \<not> P then t else e) = (if P then e else t)"
   358 by auto
   359 
   360 ML_file "Tools/Transfer/transfer_bnf.ML"
   361 ML_file "Tools/BNF/bnf_fp_rec_sugar_transfer.ML"
   362 
   363 declare pred_fun_def [simp]
   364 declare rel_fun_eq [relator_eq]
   365 
   366 subsection \<open>Transfer rules\<close>
   367 
   368 context
   369 begin
   370 interpretation lifting_syntax .
   371 
   372 lemma Domainp_forall_transfer [transfer_rule]:
   373   assumes "right_total A"
   374   shows "((A ===> op =) ===> op =)
   375     (transfer_bforall (Domainp A)) transfer_forall"
   376   using assms unfolding right_total_def
   377   unfolding transfer_forall_def transfer_bforall_def rel_fun_def Domainp_iff
   378   by fast
   379 
   380 text \<open>Transfer rules using implication instead of equality on booleans.\<close>
   381 
   382 lemma transfer_forall_transfer [transfer_rule]:
   383   "bi_total A \<Longrightarrow> ((A ===> op =) ===> op =) transfer_forall transfer_forall"
   384   "right_total A \<Longrightarrow> ((A ===> op =) ===> implies) transfer_forall transfer_forall"
   385   "right_total A \<Longrightarrow> ((A ===> implies) ===> implies) transfer_forall transfer_forall"
   386   "bi_total A \<Longrightarrow> ((A ===> op =) ===> rev_implies) transfer_forall transfer_forall"
   387   "bi_total A \<Longrightarrow> ((A ===> rev_implies) ===> rev_implies) transfer_forall transfer_forall"
   388   unfolding transfer_forall_def rev_implies_def rel_fun_def right_total_def bi_total_def
   389   by fast+
   390 
   391 lemma transfer_implies_transfer [transfer_rule]:
   392   "(op =        ===> op =        ===> op =       ) transfer_implies transfer_implies"
   393   "(rev_implies ===> implies     ===> implies    ) transfer_implies transfer_implies"
   394   "(rev_implies ===> op =        ===> implies    ) transfer_implies transfer_implies"
   395   "(op =        ===> implies     ===> implies    ) transfer_implies transfer_implies"
   396   "(op =        ===> op =        ===> implies    ) transfer_implies transfer_implies"
   397   "(implies     ===> rev_implies ===> rev_implies) transfer_implies transfer_implies"
   398   "(implies     ===> op =        ===> rev_implies) transfer_implies transfer_implies"
   399   "(op =        ===> rev_implies ===> rev_implies) transfer_implies transfer_implies"
   400   "(op =        ===> op =        ===> rev_implies) transfer_implies transfer_implies"
   401   unfolding transfer_implies_def rev_implies_def rel_fun_def by auto
   402 
   403 lemma eq_imp_transfer [transfer_rule]:
   404   "right_unique A \<Longrightarrow> (A ===> A ===> op \<longrightarrow>) (op =) (op =)"
   405   unfolding right_unique_alt_def2 .
   406 
   407 text \<open>Transfer rules using equality.\<close>
   408 
   409 lemma left_unique_transfer [transfer_rule]:
   410   assumes "right_total A"
   411   assumes "right_total B"
   412   assumes "bi_unique A"
   413   shows "((A ===> B ===> op=) ===> implies) left_unique left_unique"
   414 using assms unfolding left_unique_def[abs_def] right_total_def bi_unique_def rel_fun_def
   415 by metis
   416 
   417 lemma eq_transfer [transfer_rule]:
   418   assumes "bi_unique A"
   419   shows "(A ===> A ===> op =) (op =) (op =)"
   420   using assms unfolding bi_unique_def rel_fun_def by auto
   421 
   422 lemma right_total_Ex_transfer[transfer_rule]:
   423   assumes "right_total A"
   424   shows "((A ===> op=) ===> op=) (Bex (Collect (Domainp A))) Ex"
   425 using assms unfolding right_total_def Bex_def rel_fun_def Domainp_iff[abs_def]
   426 by fast
   427 
   428 lemma right_total_All_transfer[transfer_rule]:
   429   assumes "right_total A"
   430   shows "((A ===> op =) ===> op =) (Ball (Collect (Domainp A))) All"
   431 using assms unfolding right_total_def Ball_def rel_fun_def Domainp_iff[abs_def]
   432 by fast
   433 
   434 lemma All_transfer [transfer_rule]:
   435   assumes "bi_total A"
   436   shows "((A ===> op =) ===> op =) All All"
   437   using assms unfolding bi_total_def rel_fun_def by fast
   438 
   439 lemma Ex_transfer [transfer_rule]:
   440   assumes "bi_total A"
   441   shows "((A ===> op =) ===> op =) Ex Ex"
   442   using assms unfolding bi_total_def rel_fun_def by fast
   443 
   444 lemma Ex1_parametric [transfer_rule]:
   445   assumes [transfer_rule]: "bi_unique A" "bi_total A"
   446   shows "((A ===> op =) ===> op =) Ex1 Ex1"
   447 unfolding Ex1_def[abs_def] by transfer_prover
   448 
   449 declare If_transfer [transfer_rule]
   450 
   451 lemma Let_transfer [transfer_rule]: "(A ===> (A ===> B) ===> B) Let Let"
   452   unfolding rel_fun_def by simp
   453 
   454 declare id_transfer [transfer_rule]
   455 
   456 declare comp_transfer [transfer_rule]
   457 
   458 lemma curry_transfer [transfer_rule]:
   459   "((rel_prod A B ===> C) ===> A ===> B ===> C) curry curry"
   460   unfolding curry_def by transfer_prover
   461 
   462 lemma fun_upd_transfer [transfer_rule]:
   463   assumes [transfer_rule]: "bi_unique A"
   464   shows "((A ===> B) ===> A ===> B ===> A ===> B) fun_upd fun_upd"
   465   unfolding fun_upd_def [abs_def] by transfer_prover
   466 
   467 lemma case_nat_transfer [transfer_rule]:
   468   "(A ===> (op = ===> A) ===> op = ===> A) case_nat case_nat"
   469   unfolding rel_fun_def by (simp split: nat.split)
   470 
   471 lemma rec_nat_transfer [transfer_rule]:
   472   "(A ===> (op = ===> A ===> A) ===> op = ===> A) rec_nat rec_nat"
   473   unfolding rel_fun_def by (clarsimp, rename_tac n, induct_tac n, simp_all)
   474 
   475 lemma funpow_transfer [transfer_rule]:
   476   "(op = ===> (A ===> A) ===> (A ===> A)) compow compow"
   477   unfolding funpow_def by transfer_prover
   478 
   479 lemma mono_transfer[transfer_rule]:
   480   assumes [transfer_rule]: "bi_total A"
   481   assumes [transfer_rule]: "(A ===> A ===> op=) op\<le> op\<le>"
   482   assumes [transfer_rule]: "(B ===> B ===> op=) op\<le> op\<le>"
   483   shows "((A ===> B) ===> op=) mono mono"
   484 unfolding mono_def[abs_def] by transfer_prover
   485 
   486 lemma right_total_relcompp_transfer[transfer_rule]:
   487   assumes [transfer_rule]: "right_total B"
   488   shows "((A ===> B ===> op=) ===> (B ===> C ===> op=) ===> A ===> C ===> op=)
   489     (\<lambda>R S x z. \<exists>y\<in>Collect (Domainp B). R x y \<and> S y z) op OO"
   490 unfolding OO_def[abs_def] by transfer_prover
   491 
   492 lemma relcompp_transfer[transfer_rule]:
   493   assumes [transfer_rule]: "bi_total B"
   494   shows "((A ===> B ===> op=) ===> (B ===> C ===> op=) ===> A ===> C ===> op=) op OO op OO"
   495 unfolding OO_def[abs_def] by transfer_prover
   496 
   497 lemma right_total_Domainp_transfer[transfer_rule]:
   498   assumes [transfer_rule]: "right_total B"
   499   shows "((A ===> B ===> op=) ===> A ===> op=) (\<lambda>T x. \<exists>y\<in>Collect(Domainp B). T x y) Domainp"
   500 apply(subst(2) Domainp_iff[abs_def]) by transfer_prover
   501 
   502 lemma Domainp_transfer[transfer_rule]:
   503   assumes [transfer_rule]: "bi_total B"
   504   shows "((A ===> B ===> op=) ===> A ===> op=) Domainp Domainp"
   505 unfolding Domainp_iff[abs_def] by transfer_prover
   506 
   507 lemma reflp_transfer[transfer_rule]:
   508   "bi_total A \<Longrightarrow> ((A ===> A ===> op=) ===> op=) reflp reflp"
   509   "right_total A \<Longrightarrow> ((A ===> A ===> implies) ===> implies) reflp reflp"
   510   "right_total A \<Longrightarrow> ((A ===> A ===> op=) ===> implies) reflp reflp"
   511   "bi_total A \<Longrightarrow> ((A ===> A ===> rev_implies) ===> rev_implies) reflp reflp"
   512   "bi_total A \<Longrightarrow> ((A ===> A ===> op=) ===> rev_implies) reflp reflp"
   513 using assms unfolding reflp_def[abs_def] rev_implies_def bi_total_def right_total_def rel_fun_def
   514 by fast+
   515 
   516 lemma right_unique_transfer [transfer_rule]:
   517   "\<lbrakk> right_total A; right_total B; bi_unique B \<rbrakk>
   518   \<Longrightarrow> ((A ===> B ===> op=) ===> implies) right_unique right_unique"
   519 unfolding right_unique_def[abs_def] right_total_def bi_unique_def rel_fun_def
   520 by metis
   521 
   522 lemma left_total_parametric [transfer_rule]:
   523   assumes [transfer_rule]: "bi_total A" "bi_total B"
   524   shows "((A ===> B ===> op =) ===> op =) left_total left_total"
   525 unfolding left_total_def[abs_def] by transfer_prover
   526 
   527 lemma right_total_parametric [transfer_rule]:
   528   assumes [transfer_rule]: "bi_total A" "bi_total B"
   529   shows "((A ===> B ===> op =) ===> op =) right_total right_total"
   530 unfolding right_total_def[abs_def] by transfer_prover
   531 
   532 lemma left_unique_parametric [transfer_rule]:
   533   assumes [transfer_rule]: "bi_unique A" "bi_total A" "bi_total B"
   534   shows "((A ===> B ===> op =) ===> op =) left_unique left_unique"
   535 unfolding left_unique_def[abs_def] by transfer_prover
   536 
   537 lemma prod_pred_parametric [transfer_rule]:
   538   "((A ===> op =) ===> (B ===> op =) ===> rel_prod A B ===> op =) pred_prod pred_prod"
   539 unfolding prod.pred_set[abs_def] Basic_BNFs.fsts_def Basic_BNFs.snds_def fstsp.simps sndsp.simps 
   540 by simp transfer_prover
   541 
   542 lemma apfst_parametric [transfer_rule]:
   543   "((A ===> B) ===> rel_prod A C ===> rel_prod B C) apfst apfst"
   544 unfolding apfst_def[abs_def] by transfer_prover
   545 
   546 lemma rel_fun_eq_eq_onp: "(op= ===> eq_onp P) = eq_onp (\<lambda>f. \<forall>x. P(f x))"
   547 unfolding eq_onp_def rel_fun_def by auto
   548 
   549 lemma rel_fun_eq_onp_rel:
   550   shows "((eq_onp R) ===> S) = (\<lambda>f g. \<forall>x. R x \<longrightarrow> S (f x) (g x))"
   551 by (auto simp add: eq_onp_def rel_fun_def)
   552 
   553 lemma eq_onp_transfer [transfer_rule]:
   554   assumes [transfer_rule]: "bi_unique A"
   555   shows "((A ===> op=) ===> A ===> A ===> op=) eq_onp eq_onp"
   556 unfolding eq_onp_def[abs_def] by transfer_prover
   557 
   558 lemma rtranclp_parametric [transfer_rule]:
   559   assumes "bi_unique A" "bi_total A"
   560   shows "((A ===> A ===> op =) ===> A ===> A ===> op =) rtranclp rtranclp"
   561 proof(rule rel_funI iffI)+
   562   fix R :: "'a \<Rightarrow> 'a \<Rightarrow> bool" and R' x y x' y'
   563   assume R: "(A ===> A ===> op =) R R'" and "A x x'"
   564   {
   565     assume "R\<^sup>*\<^sup>* x y" "A y y'"
   566     thus "R'\<^sup>*\<^sup>* x' y'"
   567     proof(induction arbitrary: y')
   568       case base
   569       with \<open>bi_unique A\<close> \<open>A x x'\<close> have "x' = y'" by(rule bi_uniqueDr)
   570       thus ?case by simp
   571     next
   572       case (step y z z')
   573       from \<open>bi_total A\<close> obtain y' where "A y y'" unfolding bi_total_def by blast
   574       hence "R'\<^sup>*\<^sup>* x' y'" by(rule step.IH)
   575       moreover from R \<open>A y y'\<close> \<open>A z z'\<close> \<open>R y z\<close>
   576       have "R' y' z'" by(auto dest: rel_funD)
   577       ultimately show ?case ..
   578     qed
   579   next
   580     assume "R'\<^sup>*\<^sup>* x' y'" "A y y'"
   581     thus "R\<^sup>*\<^sup>* x y"
   582     proof(induction arbitrary: y)
   583       case base
   584       with \<open>bi_unique A\<close> \<open>A x x'\<close> have "x = y" by(rule bi_uniqueDl)
   585       thus ?case by simp
   586     next
   587       case (step y' z' z)
   588       from \<open>bi_total A\<close> obtain y where "A y y'" unfolding bi_total_def by blast
   589       hence "R\<^sup>*\<^sup>* x y" by(rule step.IH)
   590       moreover from R \<open>A y y'\<close> \<open>A z z'\<close> \<open>R' y' z'\<close>
   591       have "R y z" by(auto dest: rel_funD)
   592       ultimately show ?case ..
   593     qed
   594   }
   595 qed
   596 
   597 lemma right_unique_parametric [transfer_rule]:
   598   assumes [transfer_rule]: "bi_total A" "bi_unique B" "bi_total B"
   599   shows "((A ===> B ===> op =) ===> op =) right_unique right_unique"
   600 unfolding right_unique_def[abs_def] by transfer_prover
   601 
   602 lemma map_fun_parametric [transfer_rule]:
   603   "((A ===> B) ===> (C ===> D) ===> (B ===> C) ===> A ===> D) map_fun map_fun"
   604 unfolding map_fun_def[abs_def] by transfer_prover
   605 
   606 end
   607 
   608 end