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