src/HOL/Transfer.thy
author kuncar
Thu Apr 10 17:48:15 2014 +0200 (2014-04-10)
changeset 56520 3373f5d1e074
parent 56518 beb3b6851665
child 56524 f4ba736040fa
permissions -rw-r--r--
abstract Domainp in relator_domain rules => more natural statement of the rule
huffman@47325
     1
(*  Title:      HOL/Transfer.thy
huffman@47325
     2
    Author:     Brian Huffman, TU Muenchen
kuncar@51956
     3
    Author:     Ondrej Kuncar, TU Muenchen
huffman@47325
     4
*)
huffman@47325
     5
huffman@47325
     6
header {* Generic theorem transfer using relations *}
huffman@47325
     7
huffman@47325
     8
theory Transfer
traytel@55811
     9
imports Hilbert_Choice Basic_BNFs Metis
huffman@47325
    10
begin
huffman@47325
    11
huffman@47325
    12
subsection {* Relator for function space *}
huffman@47325
    13
kuncar@53011
    14
locale lifting_syntax
kuncar@53011
    15
begin
blanchet@55945
    16
  notation rel_fun (infixr "===>" 55)
kuncar@53011
    17
  notation map_fun (infixr "--->" 55)
kuncar@53011
    18
end
kuncar@53011
    19
kuncar@53011
    20
context
kuncar@53011
    21
begin
kuncar@53011
    22
interpretation lifting_syntax .
kuncar@53011
    23
blanchet@55945
    24
lemma rel_funD2:
blanchet@55945
    25
  assumes "rel_fun A B f g" and "A x x"
kuncar@47937
    26
  shows "B (f x) (g x)"
blanchet@55945
    27
  using assms by (rule rel_funD)
kuncar@47937
    28
blanchet@55945
    29
lemma rel_funE:
blanchet@55945
    30
  assumes "rel_fun A B f g" and "A x y"
huffman@47325
    31
  obtains "B (f x) (g y)"
blanchet@55945
    32
  using assms by (simp add: rel_fun_def)
huffman@47325
    33
blanchet@55945
    34
lemmas rel_fun_eq = fun.rel_eq
huffman@47325
    35
blanchet@55945
    36
lemma rel_fun_eq_rel:
blanchet@55945
    37
shows "rel_fun (op =) R = (\<lambda>f g. \<forall>x. R (f x) (g x))"
blanchet@55945
    38
  by (simp add: rel_fun_def)
huffman@47325
    39
huffman@47325
    40
huffman@47325
    41
subsection {* Transfer method *}
huffman@47325
    42
huffman@47789
    43
text {* Explicit tag for relation membership allows for
huffman@47789
    44
  backward proof methods. *}
huffman@47325
    45
huffman@47325
    46
definition Rel :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool"
huffman@47325
    47
  where "Rel r \<equiv> r"
huffman@47325
    48
huffman@49975
    49
text {* Handling of equality relations *}
huffman@49975
    50
huffman@49975
    51
definition is_equality :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
huffman@49975
    52
  where "is_equality R \<longleftrightarrow> R = (op =)"
huffman@49975
    53
kuncar@51437
    54
lemma is_equality_eq: "is_equality (op =)"
kuncar@51437
    55
  unfolding is_equality_def by simp
kuncar@51437
    56
huffman@52354
    57
text {* Reverse implication for monotonicity rules *}
huffman@52354
    58
huffman@52354
    59
definition rev_implies where
huffman@52354
    60
  "rev_implies x y \<longleftrightarrow> (y \<longrightarrow> x)"
huffman@52354
    61
huffman@47325
    62
text {* Handling of meta-logic connectives *}
huffman@47325
    63
huffman@47325
    64
definition transfer_forall where
huffman@47325
    65
  "transfer_forall \<equiv> All"
huffman@47325
    66
huffman@47325
    67
definition transfer_implies where
huffman@47325
    68
  "transfer_implies \<equiv> op \<longrightarrow>"
huffman@47325
    69
huffman@47355
    70
definition transfer_bforall :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool"
huffman@47355
    71
  where "transfer_bforall \<equiv> (\<lambda>P Q. \<forall>x. P x \<longrightarrow> Q x)"
huffman@47355
    72
huffman@47325
    73
lemma transfer_forall_eq: "(\<And>x. P x) \<equiv> Trueprop (transfer_forall (\<lambda>x. P x))"
huffman@47325
    74
  unfolding atomize_all transfer_forall_def ..
huffman@47325
    75
huffman@47325
    76
lemma transfer_implies_eq: "(A \<Longrightarrow> B) \<equiv> Trueprop (transfer_implies A B)"
huffman@47325
    77
  unfolding atomize_imp transfer_implies_def ..
huffman@47325
    78
huffman@47355
    79
lemma transfer_bforall_unfold:
huffman@47355
    80
  "Trueprop (transfer_bforall P (\<lambda>x. Q x)) \<equiv> (\<And>x. P x \<Longrightarrow> Q x)"
huffman@47355
    81
  unfolding transfer_bforall_def atomize_imp atomize_all ..
huffman@47355
    82
huffman@47658
    83
lemma transfer_start: "\<lbrakk>P; Rel (op =) P Q\<rbrakk> \<Longrightarrow> Q"
huffman@47325
    84
  unfolding Rel_def by simp
huffman@47325
    85
huffman@47658
    86
lemma transfer_start': "\<lbrakk>P; Rel (op \<longrightarrow>) P Q\<rbrakk> \<Longrightarrow> Q"
huffman@47325
    87
  unfolding Rel_def by simp
huffman@47325
    88
huffman@47635
    89
lemma transfer_prover_start: "\<lbrakk>x = x'; Rel R x' y\<rbrakk> \<Longrightarrow> Rel R x y"
huffman@47618
    90
  by simp
huffman@47618
    91
huffman@52358
    92
lemma untransfer_start: "\<lbrakk>Q; Rel (op =) P Q\<rbrakk> \<Longrightarrow> P"
huffman@52358
    93
  unfolding Rel_def by simp
huffman@52358
    94
huffman@47325
    95
lemma Rel_eq_refl: "Rel (op =) x x"
huffman@47325
    96
  unfolding Rel_def ..
huffman@47325
    97
huffman@47789
    98
lemma Rel_app:
huffman@47523
    99
  assumes "Rel (A ===> B) f g" and "Rel A x y"
huffman@47789
   100
  shows "Rel B (f x) (g y)"
blanchet@55945
   101
  using assms unfolding Rel_def rel_fun_def by fast
huffman@47523
   102
huffman@47789
   103
lemma Rel_abs:
huffman@47523
   104
  assumes "\<And>x y. Rel A x y \<Longrightarrow> Rel B (f x) (g y)"
huffman@47789
   105
  shows "Rel (A ===> B) (\<lambda>x. f x) (\<lambda>y. g y)"
blanchet@55945
   106
  using assms unfolding Rel_def rel_fun_def by fast
huffman@47523
   107
kuncar@53011
   108
end
kuncar@53011
   109
wenzelm@48891
   110
ML_file "Tools/transfer.ML"
huffman@47325
   111
setup Transfer.setup
huffman@47325
   112
huffman@49975
   113
declare refl [transfer_rule]
huffman@49975
   114
blanchet@55945
   115
declare rel_fun_eq [relator_eq]
huffman@47503
   116
huffman@47789
   117
hide_const (open) Rel
huffman@47325
   118
kuncar@53011
   119
context
kuncar@53011
   120
begin
kuncar@53011
   121
interpretation lifting_syntax .
kuncar@53011
   122
kuncar@51956
   123
text {* Handling of domains *}
kuncar@51956
   124
kuncar@55760
   125
lemma Domainp_iff: "Domainp T x \<longleftrightarrow> (\<exists>y. T x y)"
kuncar@55760
   126
  by auto
kuncar@55760
   127
kuncar@51956
   128
lemma Domaimp_refl[transfer_domain_rule]:
kuncar@51956
   129
  "Domainp T = Domainp T" ..
huffman@47325
   130
kuncar@56520
   131
lemma Domainp_prod_fun_eq[relator_domain]:
kuncar@56520
   132
  "Domainp (op= ===> T) = (\<lambda>f. \<forall>x. (Domainp T) (f x))"
kuncar@56520
   133
by (auto intro: choice simp: Domainp_iff rel_fun_def fun_eq_iff)
kuncar@55760
   134
huffman@47325
   135
subsection {* Predicates on relations, i.e. ``class constraints'' *}
huffman@47325
   136
kuncar@56518
   137
definition left_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
kuncar@56518
   138
  where "left_total R \<longleftrightarrow> (\<forall>x. \<exists>y. R x y)"
kuncar@56518
   139
kuncar@56518
   140
definition left_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
kuncar@56518
   141
  where "left_unique R \<longleftrightarrow> (\<forall>x y z. R x z \<longrightarrow> R y z \<longrightarrow> x = y)"
kuncar@56518
   142
huffman@47325
   143
definition right_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
huffman@47325
   144
  where "right_total R \<longleftrightarrow> (\<forall>y. \<exists>x. R x y)"
huffman@47325
   145
huffman@47325
   146
definition right_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
huffman@47325
   147
  where "right_unique R \<longleftrightarrow> (\<forall>x y z. R x y \<longrightarrow> R x z \<longrightarrow> y = z)"
huffman@47325
   148
huffman@47325
   149
definition bi_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
huffman@47325
   150
  where "bi_total R \<longleftrightarrow> (\<forall>x. \<exists>y. R x y) \<and> (\<forall>y. \<exists>x. R x y)"
huffman@47325
   151
huffman@47325
   152
definition bi_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
huffman@47325
   153
  where "bi_unique R \<longleftrightarrow>
huffman@47325
   154
    (\<forall>x y z. R x y \<longrightarrow> R x z \<longrightarrow> y = z) \<and>
huffman@47325
   155
    (\<forall>x y z. R x z \<longrightarrow> R y z \<longrightarrow> x = y)"
huffman@47325
   156
kuncar@56518
   157
lemma left_uniqueI: "(\<And>x y z. \<lbrakk> A x z; A y z \<rbrakk> \<Longrightarrow> x = y) \<Longrightarrow> left_unique A"
kuncar@56518
   158
unfolding left_unique_def by blast
kuncar@56518
   159
kuncar@56518
   160
lemma left_uniqueD: "\<lbrakk> left_unique A; A x z; A y z \<rbrakk> \<Longrightarrow> x = y"
kuncar@56518
   161
unfolding left_unique_def by blast
kuncar@56518
   162
kuncar@56518
   163
lemma left_totalI:
kuncar@56518
   164
  "(\<And>x. \<exists>y. R x y) \<Longrightarrow> left_total R"
kuncar@56518
   165
unfolding left_total_def by blast
kuncar@56518
   166
kuncar@56518
   167
lemma left_totalE:
kuncar@56518
   168
  assumes "left_total R"
kuncar@56518
   169
  obtains "(\<And>x. \<exists>y. R x y)"
kuncar@56518
   170
using assms unfolding left_total_def by blast
kuncar@56518
   171
Andreas@53927
   172
lemma bi_uniqueDr: "\<lbrakk> bi_unique A; A x y; A x z \<rbrakk> \<Longrightarrow> y = z"
Andreas@53927
   173
by(simp add: bi_unique_def)
Andreas@53927
   174
Andreas@53927
   175
lemma bi_uniqueDl: "\<lbrakk> bi_unique A; A x y; A z y \<rbrakk> \<Longrightarrow> x = z"
Andreas@53927
   176
by(simp add: bi_unique_def)
Andreas@53927
   177
Andreas@53927
   178
lemma right_uniqueI: "(\<And>x y z. \<lbrakk> A x y; A x z \<rbrakk> \<Longrightarrow> y = z) \<Longrightarrow> right_unique A"
blanchet@56085
   179
unfolding right_unique_def by fast
Andreas@53927
   180
Andreas@53927
   181
lemma right_uniqueD: "\<lbrakk> right_unique A; A x y; A x z \<rbrakk> \<Longrightarrow> y = z"
blanchet@56085
   182
unfolding right_unique_def by fast
Andreas@53927
   183
huffman@47325
   184
lemma right_total_alt_def:
huffman@47325
   185
  "right_total R \<longleftrightarrow> ((R ===> op \<longrightarrow>) ===> op \<longrightarrow>) All All"
blanchet@55945
   186
  unfolding right_total_def rel_fun_def
huffman@47325
   187
  apply (rule iffI, fast)
huffman@47325
   188
  apply (rule allI)
huffman@47325
   189
  apply (drule_tac x="\<lambda>x. True" in spec)
huffman@47325
   190
  apply (drule_tac x="\<lambda>y. \<exists>x. R x y" in spec)
huffman@47325
   191
  apply fast
huffman@47325
   192
  done
huffman@47325
   193
huffman@47325
   194
lemma right_unique_alt_def:
huffman@47325
   195
  "right_unique R \<longleftrightarrow> (R ===> R ===> op \<longrightarrow>) (op =) (op =)"
blanchet@55945
   196
  unfolding right_unique_def rel_fun_def by auto
huffman@47325
   197
huffman@47325
   198
lemma bi_total_alt_def:
huffman@47325
   199
  "bi_total R \<longleftrightarrow> ((R ===> op =) ===> op =) All All"
blanchet@55945
   200
  unfolding bi_total_def rel_fun_def
huffman@47325
   201
  apply (rule iffI, fast)
huffman@47325
   202
  apply safe
huffman@47325
   203
  apply (drule_tac x="\<lambda>x. \<exists>y. R x y" in spec)
huffman@47325
   204
  apply (drule_tac x="\<lambda>y. True" in spec)
huffman@47325
   205
  apply fast
huffman@47325
   206
  apply (drule_tac x="\<lambda>x. True" in spec)
huffman@47325
   207
  apply (drule_tac x="\<lambda>y. \<exists>x. R x y" in spec)
huffman@47325
   208
  apply fast
huffman@47325
   209
  done
huffman@47325
   210
huffman@47325
   211
lemma bi_unique_alt_def:
huffman@47325
   212
  "bi_unique R \<longleftrightarrow> (R ===> R ===> op =) (op =) (op =)"
blanchet@55945
   213
  unfolding bi_unique_def rel_fun_def by auto
huffman@47325
   214
kuncar@56518
   215
lemma [simp]:
kuncar@56518
   216
  shows left_unique_conversep: "left_unique A\<inverse>\<inverse> \<longleftrightarrow> right_unique A"
kuncar@56518
   217
  and right_unique_conversep: "right_unique A\<inverse>\<inverse> \<longleftrightarrow> left_unique A"
kuncar@56518
   218
by(auto simp add: left_unique_def right_unique_def)
kuncar@56518
   219
kuncar@56518
   220
lemma [simp]:
kuncar@56518
   221
  shows left_total_conversep: "left_total A\<inverse>\<inverse> \<longleftrightarrow> right_total A"
kuncar@56518
   222
  and right_total_conversep: "right_total A\<inverse>\<inverse> \<longleftrightarrow> left_total A"
kuncar@56518
   223
by(simp_all add: left_total_def right_total_def)
kuncar@56518
   224
Andreas@53944
   225
lemma bi_unique_conversep [simp]: "bi_unique R\<inverse>\<inverse> = bi_unique R"
Andreas@53944
   226
by(auto simp add: bi_unique_def)
Andreas@53944
   227
Andreas@53944
   228
lemma bi_total_conversep [simp]: "bi_total R\<inverse>\<inverse> = bi_total R"
Andreas@53944
   229
by(auto simp add: bi_total_def)
Andreas@53944
   230
kuncar@56518
   231
lemma bi_total_iff: "bi_total A = (right_total A \<and> left_total A)"
kuncar@56518
   232
unfolding left_total_def right_total_def bi_total_def by blast
kuncar@56518
   233
kuncar@56518
   234
lemma bi_total_conv_left_right: "bi_total R \<longleftrightarrow> left_total R \<and> right_total R"
kuncar@56518
   235
by(simp add: left_total_def right_total_def bi_total_def)
kuncar@56518
   236
kuncar@56518
   237
lemma bi_unique_iff: "bi_unique A  \<longleftrightarrow> right_unique A \<and> left_unique A"
kuncar@56518
   238
unfolding left_unique_def right_unique_def bi_unique_def by blast
kuncar@56518
   239
kuncar@56518
   240
lemma bi_unique_conv_left_right: "bi_unique R \<longleftrightarrow> left_unique R \<and> right_unique R"
kuncar@56518
   241
by(auto simp add: left_unique_def right_unique_def bi_unique_def)
kuncar@56518
   242
kuncar@56518
   243
lemma bi_totalI: "left_total R \<Longrightarrow> right_total R \<Longrightarrow> bi_total R"
kuncar@56518
   244
unfolding bi_total_iff ..
kuncar@56518
   245
kuncar@56518
   246
lemma bi_uniqueI: "left_unique R \<Longrightarrow> right_unique R \<Longrightarrow> bi_unique R"
kuncar@56518
   247
unfolding bi_unique_iff ..
kuncar@56518
   248
kuncar@56518
   249
huffman@47660
   250
text {* Properties are preserved by relation composition. *}
huffman@47660
   251
huffman@47660
   252
lemma OO_def: "R OO S = (\<lambda>x z. \<exists>y. R x y \<and> S y z)"
huffman@47660
   253
  by auto
huffman@47660
   254
huffman@47660
   255
lemma bi_total_OO: "\<lbrakk>bi_total A; bi_total B\<rbrakk> \<Longrightarrow> bi_total (A OO B)"
blanchet@56085
   256
  unfolding bi_total_def OO_def by fast
huffman@47660
   257
huffman@47660
   258
lemma bi_unique_OO: "\<lbrakk>bi_unique A; bi_unique B\<rbrakk> \<Longrightarrow> bi_unique (A OO B)"
blanchet@56085
   259
  unfolding bi_unique_def OO_def by blast
huffman@47660
   260
huffman@47660
   261
lemma right_total_OO:
huffman@47660
   262
  "\<lbrakk>right_total A; right_total B\<rbrakk> \<Longrightarrow> right_total (A OO B)"
blanchet@56085
   263
  unfolding right_total_def OO_def by fast
huffman@47660
   264
huffman@47660
   265
lemma right_unique_OO:
huffman@47660
   266
  "\<lbrakk>right_unique A; right_unique B\<rbrakk> \<Longrightarrow> right_unique (A OO B)"
blanchet@56085
   267
  unfolding right_unique_def OO_def by fast
huffman@47660
   268
kuncar@56518
   269
lemma left_total_OO: "left_total R \<Longrightarrow> left_total S \<Longrightarrow> left_total (R OO S)"
kuncar@56518
   270
unfolding left_total_def OO_def by fast
kuncar@56518
   271
kuncar@56518
   272
lemma left_unique_OO: "left_unique R \<Longrightarrow> left_unique S \<Longrightarrow> left_unique (R OO S)"
kuncar@56518
   273
unfolding left_unique_def OO_def by blast
kuncar@56518
   274
huffman@47325
   275
huffman@47325
   276
subsection {* Properties of relators *}
huffman@47325
   277
kuncar@56518
   278
lemma left_total_eq[transfer_rule]: "left_total op=" 
kuncar@56518
   279
  unfolding left_total_def by blast
kuncar@56518
   280
kuncar@56518
   281
lemma left_unique_eq[transfer_rule]: "left_unique op=" 
kuncar@56518
   282
  unfolding left_unique_def by blast
kuncar@56518
   283
kuncar@56518
   284
lemma right_total_eq [transfer_rule]: "right_total op="
huffman@47325
   285
  unfolding right_total_def by simp
huffman@47325
   286
kuncar@56518
   287
lemma right_unique_eq [transfer_rule]: "right_unique op="
huffman@47325
   288
  unfolding right_unique_def by simp
huffman@47325
   289
kuncar@56518
   290
lemma bi_total_eq[transfer_rule]: "bi_total (op =)"
huffman@47325
   291
  unfolding bi_total_def by simp
huffman@47325
   292
kuncar@56518
   293
lemma bi_unique_eq[transfer_rule]: "bi_unique (op =)"
huffman@47325
   294
  unfolding bi_unique_def by simp
huffman@47325
   295
kuncar@56518
   296
lemma left_total_fun[transfer_rule]:
kuncar@56518
   297
  "\<lbrakk>left_unique A; left_total B\<rbrakk> \<Longrightarrow> left_total (A ===> B)"
kuncar@56518
   298
  unfolding left_total_def rel_fun_def
kuncar@56518
   299
  apply (rule allI, rename_tac f)
kuncar@56518
   300
  apply (rule_tac x="\<lambda>y. SOME z. B (f (THE x. A x y)) z" in exI)
kuncar@56518
   301
  apply clarify
kuncar@56518
   302
  apply (subgoal_tac "(THE x. A x y) = x", simp)
kuncar@56518
   303
  apply (rule someI_ex)
kuncar@56518
   304
  apply (simp)
kuncar@56518
   305
  apply (rule the_equality)
kuncar@56518
   306
  apply assumption
kuncar@56518
   307
  apply (simp add: left_unique_def)
kuncar@56518
   308
  done
kuncar@56518
   309
kuncar@56518
   310
lemma left_unique_fun[transfer_rule]:
kuncar@56518
   311
  "\<lbrakk>left_total A; left_unique B\<rbrakk> \<Longrightarrow> left_unique (A ===> B)"
kuncar@56518
   312
  unfolding left_total_def left_unique_def rel_fun_def
kuncar@56518
   313
  by (clarify, rule ext, fast)
kuncar@56518
   314
huffman@47325
   315
lemma right_total_fun [transfer_rule]:
huffman@47325
   316
  "\<lbrakk>right_unique A; right_total B\<rbrakk> \<Longrightarrow> right_total (A ===> B)"
blanchet@55945
   317
  unfolding right_total_def rel_fun_def
huffman@47325
   318
  apply (rule allI, rename_tac g)
huffman@47325
   319
  apply (rule_tac x="\<lambda>x. SOME z. B z (g (THE y. A x y))" in exI)
huffman@47325
   320
  apply clarify
huffman@47325
   321
  apply (subgoal_tac "(THE y. A x y) = y", simp)
huffman@47325
   322
  apply (rule someI_ex)
huffman@47325
   323
  apply (simp)
huffman@47325
   324
  apply (rule the_equality)
huffman@47325
   325
  apply assumption
huffman@47325
   326
  apply (simp add: right_unique_def)
huffman@47325
   327
  done
huffman@47325
   328
huffman@47325
   329
lemma right_unique_fun [transfer_rule]:
huffman@47325
   330
  "\<lbrakk>right_total A; right_unique B\<rbrakk> \<Longrightarrow> right_unique (A ===> B)"
blanchet@55945
   331
  unfolding right_total_def right_unique_def rel_fun_def
huffman@47325
   332
  by (clarify, rule ext, fast)
huffman@47325
   333
kuncar@56518
   334
lemma bi_total_fun[transfer_rule]:
huffman@47325
   335
  "\<lbrakk>bi_unique A; bi_total B\<rbrakk> \<Longrightarrow> bi_total (A ===> B)"
kuncar@56518
   336
  unfolding bi_unique_iff bi_total_iff
kuncar@56518
   337
  by (blast intro: right_total_fun left_total_fun)
huffman@47325
   338
kuncar@56518
   339
lemma bi_unique_fun[transfer_rule]:
huffman@47325
   340
  "\<lbrakk>bi_total A; bi_unique B\<rbrakk> \<Longrightarrow> bi_unique (A ===> B)"
kuncar@56518
   341
  unfolding bi_unique_iff bi_total_iff
kuncar@56518
   342
  by (blast intro: right_unique_fun left_unique_fun)
huffman@47325
   343
huffman@47635
   344
subsection {* Transfer rules *}
huffman@47325
   345
kuncar@53952
   346
lemma Domainp_forall_transfer [transfer_rule]:
kuncar@53952
   347
  assumes "right_total A"
kuncar@53952
   348
  shows "((A ===> op =) ===> op =)
kuncar@53952
   349
    (transfer_bforall (Domainp A)) transfer_forall"
kuncar@53952
   350
  using assms unfolding right_total_def
blanchet@55945
   351
  unfolding transfer_forall_def transfer_bforall_def rel_fun_def Domainp_iff
blanchet@56085
   352
  by fast
kuncar@53952
   353
huffman@47684
   354
text {* Transfer rules using implication instead of equality on booleans. *}
huffman@47684
   355
huffman@52354
   356
lemma transfer_forall_transfer [transfer_rule]:
huffman@52354
   357
  "bi_total A \<Longrightarrow> ((A ===> op =) ===> op =) transfer_forall transfer_forall"
huffman@52354
   358
  "right_total A \<Longrightarrow> ((A ===> op =) ===> implies) transfer_forall transfer_forall"
huffman@52354
   359
  "right_total A \<Longrightarrow> ((A ===> implies) ===> implies) transfer_forall transfer_forall"
huffman@52354
   360
  "bi_total A \<Longrightarrow> ((A ===> op =) ===> rev_implies) transfer_forall transfer_forall"
huffman@52354
   361
  "bi_total A \<Longrightarrow> ((A ===> rev_implies) ===> rev_implies) transfer_forall transfer_forall"
blanchet@55945
   362
  unfolding transfer_forall_def rev_implies_def rel_fun_def right_total_def bi_total_def
blanchet@56085
   363
  by fast+
huffman@52354
   364
huffman@52354
   365
lemma transfer_implies_transfer [transfer_rule]:
huffman@52354
   366
  "(op =        ===> op =        ===> op =       ) transfer_implies transfer_implies"
huffman@52354
   367
  "(rev_implies ===> implies     ===> implies    ) transfer_implies transfer_implies"
huffman@52354
   368
  "(rev_implies ===> op =        ===> implies    ) transfer_implies transfer_implies"
huffman@52354
   369
  "(op =        ===> implies     ===> implies    ) transfer_implies transfer_implies"
huffman@52354
   370
  "(op =        ===> op =        ===> implies    ) transfer_implies transfer_implies"
huffman@52354
   371
  "(implies     ===> rev_implies ===> rev_implies) transfer_implies transfer_implies"
huffman@52354
   372
  "(implies     ===> op =        ===> rev_implies) transfer_implies transfer_implies"
huffman@52354
   373
  "(op =        ===> rev_implies ===> rev_implies) transfer_implies transfer_implies"
huffman@52354
   374
  "(op =        ===> op =        ===> rev_implies) transfer_implies transfer_implies"
blanchet@55945
   375
  unfolding transfer_implies_def rev_implies_def rel_fun_def by auto
huffman@52354
   376
huffman@47684
   377
lemma eq_imp_transfer [transfer_rule]:
huffman@47684
   378
  "right_unique A \<Longrightarrow> (A ===> A ===> op \<longrightarrow>) (op =) (op =)"
huffman@47684
   379
  unfolding right_unique_alt_def .
huffman@47684
   380
kuncar@56518
   381
text {* Transfer rules using equality. *}
kuncar@56518
   382
kuncar@56518
   383
lemma left_unique_transfer [transfer_rule]:
kuncar@56518
   384
  assumes "right_total A"
kuncar@56518
   385
  assumes "right_total B"
kuncar@56518
   386
  assumes "bi_unique A"
kuncar@56518
   387
  shows "((A ===> B ===> op=) ===> implies) left_unique left_unique"
kuncar@56518
   388
using assms unfolding left_unique_def[abs_def] right_total_def bi_unique_def rel_fun_def
kuncar@56518
   389
by metis
kuncar@56518
   390
huffman@47636
   391
lemma eq_transfer [transfer_rule]:
huffman@47325
   392
  assumes "bi_unique A"
huffman@47325
   393
  shows "(A ===> A ===> op =) (op =) (op =)"
blanchet@55945
   394
  using assms unfolding bi_unique_def rel_fun_def by auto
huffman@47325
   395
kuncar@51956
   396
lemma right_total_Ex_transfer[transfer_rule]:
kuncar@51956
   397
  assumes "right_total A"
kuncar@51956
   398
  shows "((A ===> op=) ===> op=) (Bex (Collect (Domainp A))) Ex"
blanchet@55945
   399
using assms unfolding right_total_def Bex_def rel_fun_def Domainp_iff[abs_def]
blanchet@56085
   400
by fast
kuncar@51956
   401
kuncar@51956
   402
lemma right_total_All_transfer[transfer_rule]:
kuncar@51956
   403
  assumes "right_total A"
kuncar@51956
   404
  shows "((A ===> op =) ===> op =) (Ball (Collect (Domainp A))) All"
blanchet@55945
   405
using assms unfolding right_total_def Ball_def rel_fun_def Domainp_iff[abs_def]
blanchet@56085
   406
by fast
kuncar@51956
   407
huffman@47636
   408
lemma All_transfer [transfer_rule]:
huffman@47325
   409
  assumes "bi_total A"
huffman@47325
   410
  shows "((A ===> op =) ===> op =) All All"
blanchet@55945
   411
  using assms unfolding bi_total_def rel_fun_def by fast
huffman@47325
   412
huffman@47636
   413
lemma Ex_transfer [transfer_rule]:
huffman@47325
   414
  assumes "bi_total A"
huffman@47325
   415
  shows "((A ===> op =) ===> op =) Ex Ex"
blanchet@55945
   416
  using assms unfolding bi_total_def rel_fun_def by fast
huffman@47325
   417
huffman@47636
   418
lemma If_transfer [transfer_rule]: "(op = ===> A ===> A ===> A) If If"
blanchet@55945
   419
  unfolding rel_fun_def by simp
huffman@47325
   420
huffman@47636
   421
lemma Let_transfer [transfer_rule]: "(A ===> (A ===> B) ===> B) Let Let"
blanchet@55945
   422
  unfolding rel_fun_def by simp
huffman@47612
   423
huffman@47636
   424
lemma id_transfer [transfer_rule]: "(A ===> A) id id"
blanchet@55945
   425
  unfolding rel_fun_def by simp
huffman@47625
   426
huffman@47636
   427
lemma comp_transfer [transfer_rule]:
huffman@47325
   428
  "((B ===> C) ===> (A ===> B) ===> (A ===> C)) (op \<circ>) (op \<circ>)"
blanchet@55945
   429
  unfolding rel_fun_def by simp
huffman@47325
   430
huffman@47636
   431
lemma fun_upd_transfer [transfer_rule]:
huffman@47325
   432
  assumes [transfer_rule]: "bi_unique A"
huffman@47325
   433
  shows "((A ===> B) ===> A ===> B ===> A ===> B) fun_upd fun_upd"
huffman@47635
   434
  unfolding fun_upd_def [abs_def] by transfer_prover
huffman@47325
   435
blanchet@55415
   436
lemma case_nat_transfer [transfer_rule]:
blanchet@55415
   437
  "(A ===> (op = ===> A) ===> op = ===> A) case_nat case_nat"
blanchet@55945
   438
  unfolding rel_fun_def by (simp split: nat.split)
huffman@47627
   439
blanchet@55415
   440
lemma rec_nat_transfer [transfer_rule]:
blanchet@55415
   441
  "(A ===> (op = ===> A ===> A) ===> op = ===> A) rec_nat rec_nat"
blanchet@55945
   442
  unfolding rel_fun_def by (clarsimp, rename_tac n, induct_tac n, simp_all)
huffman@47924
   443
huffman@47924
   444
lemma funpow_transfer [transfer_rule]:
huffman@47924
   445
  "(op = ===> (A ===> A) ===> (A ===> A)) compow compow"
huffman@47924
   446
  unfolding funpow_def by transfer_prover
huffman@47924
   447
kuncar@53952
   448
lemma mono_transfer[transfer_rule]:
kuncar@53952
   449
  assumes [transfer_rule]: "bi_total A"
kuncar@53952
   450
  assumes [transfer_rule]: "(A ===> A ===> op=) op\<le> op\<le>"
kuncar@53952
   451
  assumes [transfer_rule]: "(B ===> B ===> op=) op\<le> op\<le>"
kuncar@53952
   452
  shows "((A ===> B) ===> op=) mono mono"
kuncar@53952
   453
unfolding mono_def[abs_def] by transfer_prover
kuncar@53952
   454
kuncar@53952
   455
lemma right_total_relcompp_transfer[transfer_rule]: 
kuncar@53952
   456
  assumes [transfer_rule]: "right_total B"
kuncar@53952
   457
  shows "((A ===> B ===> op=) ===> (B ===> C ===> op=) ===> A ===> C ===> op=) 
kuncar@53952
   458
    (\<lambda>R S x z. \<exists>y\<in>Collect (Domainp B). R x y \<and> S y z) op OO"
kuncar@53952
   459
unfolding OO_def[abs_def] by transfer_prover
kuncar@53952
   460
kuncar@53952
   461
lemma relcompp_transfer[transfer_rule]: 
kuncar@53952
   462
  assumes [transfer_rule]: "bi_total B"
kuncar@53952
   463
  shows "((A ===> B ===> op=) ===> (B ===> C ===> op=) ===> A ===> C ===> op=) op OO op OO"
kuncar@53952
   464
unfolding OO_def[abs_def] by transfer_prover
huffman@47627
   465
kuncar@53952
   466
lemma right_total_Domainp_transfer[transfer_rule]:
kuncar@53952
   467
  assumes [transfer_rule]: "right_total B"
kuncar@53952
   468
  shows "((A ===> B ===> op=) ===> A ===> op=) (\<lambda>T x. \<exists>y\<in>Collect(Domainp B). T x y) Domainp"
kuncar@53952
   469
apply(subst(2) Domainp_iff[abs_def]) by transfer_prover
kuncar@53952
   470
kuncar@53952
   471
lemma Domainp_transfer[transfer_rule]:
kuncar@53952
   472
  assumes [transfer_rule]: "bi_total B"
kuncar@53952
   473
  shows "((A ===> B ===> op=) ===> A ===> op=) Domainp Domainp"
kuncar@53952
   474
unfolding Domainp_iff[abs_def] by transfer_prover
kuncar@53952
   475
kuncar@53952
   476
lemma reflp_transfer[transfer_rule]: 
kuncar@53952
   477
  "bi_total A \<Longrightarrow> ((A ===> A ===> op=) ===> op=) reflp reflp"
kuncar@53952
   478
  "right_total A \<Longrightarrow> ((A ===> A ===> implies) ===> implies) reflp reflp"
kuncar@53952
   479
  "right_total A \<Longrightarrow> ((A ===> A ===> op=) ===> implies) reflp reflp"
kuncar@53952
   480
  "bi_total A \<Longrightarrow> ((A ===> A ===> rev_implies) ===> rev_implies) reflp reflp"
kuncar@53952
   481
  "bi_total A \<Longrightarrow> ((A ===> A ===> op=) ===> rev_implies) reflp reflp"
blanchet@55945
   482
using assms unfolding reflp_def[abs_def] rev_implies_def bi_total_def right_total_def rel_fun_def 
kuncar@53952
   483
by fast+
kuncar@53952
   484
kuncar@53952
   485
lemma right_unique_transfer [transfer_rule]:
kuncar@53952
   486
  assumes [transfer_rule]: "right_total A"
kuncar@53952
   487
  assumes [transfer_rule]: "right_total B"
kuncar@53952
   488
  assumes [transfer_rule]: "bi_unique B"
kuncar@53952
   489
  shows "((A ===> B ===> op=) ===> implies) right_unique right_unique"
blanchet@55945
   490
using assms unfolding right_unique_def[abs_def] right_total_def bi_unique_def rel_fun_def
kuncar@53952
   491
by metis
huffman@47325
   492
huffman@47325
   493
end
kuncar@53011
   494
kuncar@53011
   495
end