src/HOL/Transfer.thy
author huffman
Tue Apr 03 22:31:00 2012 +0200 (2012-04-03)
changeset 47325 ec6187036495
child 47355 3d9d98e0f1a4
permissions -rw-r--r--
new transfer proof method
huffman@47325
     1
(*  Title:      HOL/Transfer.thy
huffman@47325
     2
    Author:     Brian Huffman, TU Muenchen
huffman@47325
     3
*)
huffman@47325
     4
huffman@47325
     5
header {* Generic theorem transfer using relations *}
huffman@47325
     6
huffman@47325
     7
theory Transfer
huffman@47325
     8
imports Plain Hilbert_Choice
huffman@47325
     9
uses ("Tools/transfer.ML")
huffman@47325
    10
begin
huffman@47325
    11
huffman@47325
    12
subsection {* Relator for function space *}
huffman@47325
    13
huffman@47325
    14
definition
huffman@47325
    15
  fun_rel :: "('a \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> ('c \<Rightarrow> 'd) \<Rightarrow> bool" (infixr "===>" 55)
huffman@47325
    16
where
huffman@47325
    17
  "fun_rel A B = (\<lambda>f g. \<forall>x y. A x y \<longrightarrow> B (f x) (g y))"
huffman@47325
    18
huffman@47325
    19
lemma fun_relI [intro]:
huffman@47325
    20
  assumes "\<And>x y. A x y \<Longrightarrow> B (f x) (g y)"
huffman@47325
    21
  shows "(A ===> B) f g"
huffman@47325
    22
  using assms by (simp add: fun_rel_def)
huffman@47325
    23
huffman@47325
    24
lemma fun_relD:
huffman@47325
    25
  assumes "(A ===> B) f g" and "A x y"
huffman@47325
    26
  shows "B (f x) (g y)"
huffman@47325
    27
  using assms by (simp add: fun_rel_def)
huffman@47325
    28
huffman@47325
    29
lemma fun_relE:
huffman@47325
    30
  assumes "(A ===> B) f g" and "A x y"
huffman@47325
    31
  obtains "B (f x) (g y)"
huffman@47325
    32
  using assms by (simp add: fun_rel_def)
huffman@47325
    33
huffman@47325
    34
lemma fun_rel_eq:
huffman@47325
    35
  shows "((op =) ===> (op =)) = (op =)"
huffman@47325
    36
  by (auto simp add: fun_eq_iff elim: fun_relE)
huffman@47325
    37
huffman@47325
    38
lemma fun_rel_eq_rel:
huffman@47325
    39
  shows "((op =) ===> R) = (\<lambda>f g. \<forall>x. R (f x) (g x))"
huffman@47325
    40
  by (simp add: fun_rel_def)
huffman@47325
    41
huffman@47325
    42
huffman@47325
    43
subsection {* Transfer method *}
huffman@47325
    44
huffman@47325
    45
text {* Explicit tags for application, abstraction, and relation
huffman@47325
    46
membership allow for backward proof methods. *}
huffman@47325
    47
huffman@47325
    48
definition App :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
huffman@47325
    49
  where "App f \<equiv> f"
huffman@47325
    50
huffman@47325
    51
definition Abs :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
huffman@47325
    52
  where "Abs f \<equiv> f"
huffman@47325
    53
huffman@47325
    54
definition Rel :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool"
huffman@47325
    55
  where "Rel r \<equiv> r"
huffman@47325
    56
huffman@47325
    57
text {* Handling of meta-logic connectives *}
huffman@47325
    58
huffman@47325
    59
definition transfer_forall where
huffman@47325
    60
  "transfer_forall \<equiv> All"
huffman@47325
    61
huffman@47325
    62
definition transfer_implies where
huffman@47325
    63
  "transfer_implies \<equiv> op \<longrightarrow>"
huffman@47325
    64
huffman@47325
    65
lemma transfer_forall_eq: "(\<And>x. P x) \<equiv> Trueprop (transfer_forall (\<lambda>x. P x))"
huffman@47325
    66
  unfolding atomize_all transfer_forall_def ..
huffman@47325
    67
huffman@47325
    68
lemma transfer_implies_eq: "(A \<Longrightarrow> B) \<equiv> Trueprop (transfer_implies A B)"
huffman@47325
    69
  unfolding atomize_imp transfer_implies_def ..
huffman@47325
    70
huffman@47325
    71
lemma transfer_start: "\<lbrakk>Rel (op =) P Q; P\<rbrakk> \<Longrightarrow> Q"
huffman@47325
    72
  unfolding Rel_def by simp
huffman@47325
    73
huffman@47325
    74
lemma transfer_start': "\<lbrakk>Rel (op \<longrightarrow>) P Q; P\<rbrakk> \<Longrightarrow> Q"
huffman@47325
    75
  unfolding Rel_def by simp
huffman@47325
    76
huffman@47325
    77
lemma Rel_eq_refl: "Rel (op =) x x"
huffman@47325
    78
  unfolding Rel_def ..
huffman@47325
    79
huffman@47325
    80
use "Tools/transfer.ML"
huffman@47325
    81
huffman@47325
    82
setup Transfer.setup
huffman@47325
    83
huffman@47325
    84
lemma Rel_App [transfer_raw]:
huffman@47325
    85
  assumes "Rel (A ===> B) f g" and "Rel A x y"
huffman@47325
    86
  shows "Rel B (App f x) (App g y)"
huffman@47325
    87
  using assms unfolding Rel_def App_def fun_rel_def by fast
huffman@47325
    88
huffman@47325
    89
lemma Rel_Abs [transfer_raw]:
huffman@47325
    90
  assumes "\<And>x y. Rel A x y \<Longrightarrow> Rel B (f x) (g y)"
huffman@47325
    91
  shows "Rel (A ===> B) (Abs (\<lambda>x. f x)) (Abs (\<lambda>y. g y))"
huffman@47325
    92
  using assms unfolding Rel_def Abs_def fun_rel_def by fast
huffman@47325
    93
huffman@47325
    94
hide_const (open) App Abs Rel
huffman@47325
    95
huffman@47325
    96
huffman@47325
    97
subsection {* Predicates on relations, i.e. ``class constraints'' *}
huffman@47325
    98
huffman@47325
    99
definition right_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
huffman@47325
   100
  where "right_total R \<longleftrightarrow> (\<forall>y. \<exists>x. R x y)"
huffman@47325
   101
huffman@47325
   102
definition right_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
huffman@47325
   103
  where "right_unique R \<longleftrightarrow> (\<forall>x y z. R x y \<longrightarrow> R x z \<longrightarrow> y = z)"
huffman@47325
   104
huffman@47325
   105
definition bi_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
huffman@47325
   106
  where "bi_total R \<longleftrightarrow> (\<forall>x. \<exists>y. R x y) \<and> (\<forall>y. \<exists>x. R x y)"
huffman@47325
   107
huffman@47325
   108
definition bi_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
huffman@47325
   109
  where "bi_unique R \<longleftrightarrow>
huffman@47325
   110
    (\<forall>x y z. R x y \<longrightarrow> R x z \<longrightarrow> y = z) \<and>
huffman@47325
   111
    (\<forall>x y z. R x z \<longrightarrow> R y z \<longrightarrow> x = y)"
huffman@47325
   112
huffman@47325
   113
lemma right_total_alt_def:
huffman@47325
   114
  "right_total R \<longleftrightarrow> ((R ===> op \<longrightarrow>) ===> op \<longrightarrow>) All All"
huffman@47325
   115
  unfolding right_total_def fun_rel_def
huffman@47325
   116
  apply (rule iffI, fast)
huffman@47325
   117
  apply (rule allI)
huffman@47325
   118
  apply (drule_tac x="\<lambda>x. True" in spec)
huffman@47325
   119
  apply (drule_tac x="\<lambda>y. \<exists>x. R x y" in spec)
huffman@47325
   120
  apply fast
huffman@47325
   121
  done
huffman@47325
   122
huffman@47325
   123
lemma right_unique_alt_def:
huffman@47325
   124
  "right_unique R \<longleftrightarrow> (R ===> R ===> op \<longrightarrow>) (op =) (op =)"
huffman@47325
   125
  unfolding right_unique_def fun_rel_def by auto
huffman@47325
   126
huffman@47325
   127
lemma bi_total_alt_def:
huffman@47325
   128
  "bi_total R \<longleftrightarrow> ((R ===> op =) ===> op =) All All"
huffman@47325
   129
  unfolding bi_total_def fun_rel_def
huffman@47325
   130
  apply (rule iffI, fast)
huffman@47325
   131
  apply safe
huffman@47325
   132
  apply (drule_tac x="\<lambda>x. \<exists>y. R x y" in spec)
huffman@47325
   133
  apply (drule_tac x="\<lambda>y. True" in spec)
huffman@47325
   134
  apply fast
huffman@47325
   135
  apply (drule_tac x="\<lambda>x. True" in spec)
huffman@47325
   136
  apply (drule_tac x="\<lambda>y. \<exists>x. R x y" in spec)
huffman@47325
   137
  apply fast
huffman@47325
   138
  done
huffman@47325
   139
huffman@47325
   140
lemma bi_unique_alt_def:
huffman@47325
   141
  "bi_unique R \<longleftrightarrow> (R ===> R ===> op =) (op =) (op =)"
huffman@47325
   142
  unfolding bi_unique_def fun_rel_def by auto
huffman@47325
   143
huffman@47325
   144
huffman@47325
   145
subsection {* Properties of relators *}
huffman@47325
   146
huffman@47325
   147
lemma right_total_eq [transfer_rule]: "right_total (op =)"
huffman@47325
   148
  unfolding right_total_def by simp
huffman@47325
   149
huffman@47325
   150
lemma right_unique_eq [transfer_rule]: "right_unique (op =)"
huffman@47325
   151
  unfolding right_unique_def by simp
huffman@47325
   152
huffman@47325
   153
lemma bi_total_eq [transfer_rule]: "bi_total (op =)"
huffman@47325
   154
  unfolding bi_total_def by simp
huffman@47325
   155
huffman@47325
   156
lemma bi_unique_eq [transfer_rule]: "bi_unique (op =)"
huffman@47325
   157
  unfolding bi_unique_def by simp
huffman@47325
   158
huffman@47325
   159
lemma right_total_fun [transfer_rule]:
huffman@47325
   160
  "\<lbrakk>right_unique A; right_total B\<rbrakk> \<Longrightarrow> right_total (A ===> B)"
huffman@47325
   161
  unfolding right_total_def fun_rel_def
huffman@47325
   162
  apply (rule allI, rename_tac g)
huffman@47325
   163
  apply (rule_tac x="\<lambda>x. SOME z. B z (g (THE y. A x y))" in exI)
huffman@47325
   164
  apply clarify
huffman@47325
   165
  apply (subgoal_tac "(THE y. A x y) = y", simp)
huffman@47325
   166
  apply (rule someI_ex)
huffman@47325
   167
  apply (simp)
huffman@47325
   168
  apply (rule the_equality)
huffman@47325
   169
  apply assumption
huffman@47325
   170
  apply (simp add: right_unique_def)
huffman@47325
   171
  done
huffman@47325
   172
huffman@47325
   173
lemma right_unique_fun [transfer_rule]:
huffman@47325
   174
  "\<lbrakk>right_total A; right_unique B\<rbrakk> \<Longrightarrow> right_unique (A ===> B)"
huffman@47325
   175
  unfolding right_total_def right_unique_def fun_rel_def
huffman@47325
   176
  by (clarify, rule ext, fast)
huffman@47325
   177
huffman@47325
   178
lemma bi_total_fun [transfer_rule]:
huffman@47325
   179
  "\<lbrakk>bi_unique A; bi_total B\<rbrakk> \<Longrightarrow> bi_total (A ===> B)"
huffman@47325
   180
  unfolding bi_total_def fun_rel_def
huffman@47325
   181
  apply safe
huffman@47325
   182
  apply (rename_tac f)
huffman@47325
   183
  apply (rule_tac x="\<lambda>y. SOME z. B (f (THE x. A x y)) z" in exI)
huffman@47325
   184
  apply clarify
huffman@47325
   185
  apply (subgoal_tac "(THE x. A x y) = x", simp)
huffman@47325
   186
  apply (rule someI_ex)
huffman@47325
   187
  apply (simp)
huffman@47325
   188
  apply (rule the_equality)
huffman@47325
   189
  apply assumption
huffman@47325
   190
  apply (simp add: bi_unique_def)
huffman@47325
   191
  apply (rename_tac g)
huffman@47325
   192
  apply (rule_tac x="\<lambda>x. SOME z. B z (g (THE y. A x y))" in exI)
huffman@47325
   193
  apply clarify
huffman@47325
   194
  apply (subgoal_tac "(THE y. A x y) = y", simp)
huffman@47325
   195
  apply (rule someI_ex)
huffman@47325
   196
  apply (simp)
huffman@47325
   197
  apply (rule the_equality)
huffman@47325
   198
  apply assumption
huffman@47325
   199
  apply (simp add: bi_unique_def)
huffman@47325
   200
  done
huffman@47325
   201
huffman@47325
   202
lemma bi_unique_fun [transfer_rule]:
huffman@47325
   203
  "\<lbrakk>bi_total A; bi_unique B\<rbrakk> \<Longrightarrow> bi_unique (A ===> B)"
huffman@47325
   204
  unfolding bi_total_def bi_unique_def fun_rel_def fun_eq_iff
huffman@47325
   205
  by (safe, metis, fast)
huffman@47325
   206
huffman@47325
   207
huffman@47325
   208
subsection {* Correspondence rules *}
huffman@47325
   209
huffman@47325
   210
lemma eq_parametric [transfer_rule]:
huffman@47325
   211
  assumes "bi_unique A"
huffman@47325
   212
  shows "(A ===> A ===> op =) (op =) (op =)"
huffman@47325
   213
  using assms unfolding bi_unique_def fun_rel_def by auto
huffman@47325
   214
huffman@47325
   215
lemma All_parametric [transfer_rule]:
huffman@47325
   216
  assumes "bi_total A"
huffman@47325
   217
  shows "((A ===> op =) ===> op =) All All"
huffman@47325
   218
  using assms unfolding bi_total_def fun_rel_def by fast
huffman@47325
   219
huffman@47325
   220
lemma Ex_parametric [transfer_rule]:
huffman@47325
   221
  assumes "bi_total A"
huffman@47325
   222
  shows "((A ===> op =) ===> op =) Ex Ex"
huffman@47325
   223
  using assms unfolding bi_total_def fun_rel_def by fast
huffman@47325
   224
huffman@47325
   225
lemma If_parametric [transfer_rule]: "(op = ===> A ===> A ===> A) If If"
huffman@47325
   226
  unfolding fun_rel_def by simp
huffman@47325
   227
huffman@47325
   228
lemma comp_parametric [transfer_rule]:
huffman@47325
   229
  "((B ===> C) ===> (A ===> B) ===> (A ===> C)) (op \<circ>) (op \<circ>)"
huffman@47325
   230
  unfolding fun_rel_def by simp
huffman@47325
   231
huffman@47325
   232
lemma fun_upd_parametric [transfer_rule]:
huffman@47325
   233
  assumes [transfer_rule]: "bi_unique A"
huffman@47325
   234
  shows "((A ===> B) ===> A ===> B ===> A ===> B) fun_upd fun_upd"
huffman@47325
   235
  unfolding fun_upd_def [abs_def] by correspondence
huffman@47325
   236
huffman@47325
   237
lemmas transfer_forall_parametric [transfer_rule]
huffman@47325
   238
  = All_parametric [folded transfer_forall_def]
huffman@47325
   239
huffman@47325
   240
end