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