src/HOL/Lifting.thy
author huffman
Wed Apr 18 15:48:32 2012 +0200 (2012-04-18)
changeset 47544 e455cdaac479
parent 47538 1f0ec5b8135a
child 47545 a2850a16e30f
permissions -rw-r--r--
move constant 'Respects' into Lifting.thy;
add quantifier transfer rules for quotients
kuncar@47308
     1
(*  Title:      HOL/Lifting.thy
kuncar@47308
     2
    Author:     Brian Huffman and Ondrej Kuncar
kuncar@47308
     3
    Author:     Cezary Kaliszyk and Christian Urban
kuncar@47308
     4
*)
kuncar@47308
     5
kuncar@47308
     6
header {* Lifting package *}
kuncar@47308
     7
kuncar@47308
     8
theory Lifting
huffman@47325
     9
imports Plain Equiv_Relations Transfer
kuncar@47308
    10
keywords
kuncar@47308
    11
  "print_quotmaps" "print_quotients" :: diag and
kuncar@47308
    12
  "lift_definition" :: thy_goal and
kuncar@47308
    13
  "setup_lifting" :: thy_decl
kuncar@47308
    14
uses
kuncar@47308
    15
  ("Tools/Lifting/lifting_info.ML")
kuncar@47308
    16
  ("Tools/Lifting/lifting_term.ML")
kuncar@47308
    17
  ("Tools/Lifting/lifting_def.ML")
kuncar@47308
    18
  ("Tools/Lifting/lifting_setup.ML")
kuncar@47308
    19
begin
kuncar@47308
    20
huffman@47325
    21
subsection {* Function map *}
kuncar@47308
    22
kuncar@47308
    23
notation map_fun (infixr "--->" 55)
kuncar@47308
    24
kuncar@47308
    25
lemma map_fun_id:
kuncar@47308
    26
  "(id ---> id) = id"
kuncar@47308
    27
  by (simp add: fun_eq_iff)
kuncar@47308
    28
kuncar@47308
    29
subsection {* Quotient Predicate *}
kuncar@47308
    30
kuncar@47308
    31
definition
kuncar@47308
    32
  "Quotient R Abs Rep T \<longleftrightarrow>
kuncar@47308
    33
     (\<forall>a. Abs (Rep a) = a) \<and> 
kuncar@47308
    34
     (\<forall>a. R (Rep a) (Rep a)) \<and>
kuncar@47308
    35
     (\<forall>r s. R r s \<longleftrightarrow> R r r \<and> R s s \<and> Abs r = Abs s) \<and>
kuncar@47308
    36
     T = (\<lambda>x y. R x x \<and> Abs x = y)"
kuncar@47308
    37
kuncar@47308
    38
lemma QuotientI:
kuncar@47308
    39
  assumes "\<And>a. Abs (Rep a) = a"
kuncar@47308
    40
    and "\<And>a. R (Rep a) (Rep a)"
kuncar@47308
    41
    and "\<And>r s. R r s \<longleftrightarrow> R r r \<and> R s s \<and> Abs r = Abs s"
kuncar@47308
    42
    and "T = (\<lambda>x y. R x x \<and> Abs x = y)"
kuncar@47308
    43
  shows "Quotient R Abs Rep T"
kuncar@47308
    44
  using assms unfolding Quotient_def by blast
kuncar@47308
    45
huffman@47536
    46
context
huffman@47536
    47
  fixes R Abs Rep T
kuncar@47308
    48
  assumes a: "Quotient R Abs Rep T"
huffman@47536
    49
begin
huffman@47536
    50
huffman@47536
    51
lemma Quotient_abs_rep: "Abs (Rep a) = a"
huffman@47536
    52
  using a unfolding Quotient_def
kuncar@47308
    53
  by simp
kuncar@47308
    54
huffman@47536
    55
lemma Quotient_rep_reflp: "R (Rep a) (Rep a)"
huffman@47536
    56
  using a unfolding Quotient_def
kuncar@47308
    57
  by blast
kuncar@47308
    58
kuncar@47308
    59
lemma Quotient_rel:
huffman@47536
    60
  "R r r \<and> R s s \<and> Abs r = Abs s \<longleftrightarrow> R r s" -- {* orientation does not loop on rewriting *}
huffman@47536
    61
  using a unfolding Quotient_def
kuncar@47308
    62
  by blast
kuncar@47308
    63
huffman@47536
    64
lemma Quotient_cr_rel: "T = (\<lambda>x y. R x x \<and> Abs x = y)"
kuncar@47308
    65
  using a unfolding Quotient_def
kuncar@47308
    66
  by blast
kuncar@47308
    67
huffman@47536
    68
lemma Quotient_refl1: "R r s \<Longrightarrow> R r r"
huffman@47536
    69
  using a unfolding Quotient_def
huffman@47536
    70
  by fast
huffman@47536
    71
huffman@47536
    72
lemma Quotient_refl2: "R r s \<Longrightarrow> R s s"
huffman@47536
    73
  using a unfolding Quotient_def
huffman@47536
    74
  by fast
huffman@47536
    75
huffman@47536
    76
lemma Quotient_rel_rep: "R (Rep a) (Rep b) \<longleftrightarrow> a = b"
huffman@47536
    77
  using a unfolding Quotient_def
huffman@47536
    78
  by metis
huffman@47536
    79
huffman@47536
    80
lemma Quotient_rep_abs: "R r r \<Longrightarrow> R (Rep (Abs r)) r"
kuncar@47308
    81
  using a unfolding Quotient_def
kuncar@47308
    82
  by blast
kuncar@47308
    83
huffman@47536
    84
lemma Quotient_rel_abs: "R r s \<Longrightarrow> Abs r = Abs s"
huffman@47536
    85
  using a unfolding Quotient_def
huffman@47536
    86
  by blast
huffman@47536
    87
huffman@47536
    88
lemma Quotient_symp: "symp R"
kuncar@47308
    89
  using a unfolding Quotient_def using sympI by (metis (full_types))
kuncar@47308
    90
huffman@47536
    91
lemma Quotient_transp: "transp R"
kuncar@47308
    92
  using a unfolding Quotient_def using transpI by (metis (full_types))
kuncar@47308
    93
huffman@47536
    94
lemma Quotient_part_equivp: "part_equivp R"
huffman@47536
    95
by (metis Quotient_rep_reflp Quotient_symp Quotient_transp part_equivpI)
huffman@47536
    96
huffman@47536
    97
end
kuncar@47308
    98
kuncar@47308
    99
lemma identity_quotient: "Quotient (op =) id id (op =)"
kuncar@47308
   100
unfolding Quotient_def by simp 
kuncar@47308
   101
kuncar@47308
   102
lemma Quotient_alt_def:
kuncar@47308
   103
  "Quotient R Abs Rep T \<longleftrightarrow>
kuncar@47308
   104
    (\<forall>a b. T a b \<longrightarrow> Abs a = b) \<and>
kuncar@47308
   105
    (\<forall>b. T (Rep b) b) \<and>
kuncar@47308
   106
    (\<forall>x y. R x y \<longleftrightarrow> T x (Abs x) \<and> T y (Abs y) \<and> Abs x = Abs y)"
kuncar@47308
   107
apply safe
kuncar@47308
   108
apply (simp (no_asm_use) only: Quotient_def, fast)
kuncar@47308
   109
apply (simp (no_asm_use) only: Quotient_def, fast)
kuncar@47308
   110
apply (simp (no_asm_use) only: Quotient_def, fast)
kuncar@47308
   111
apply (simp (no_asm_use) only: Quotient_def, fast)
kuncar@47308
   112
apply (simp (no_asm_use) only: Quotient_def, fast)
kuncar@47308
   113
apply (simp (no_asm_use) only: Quotient_def, fast)
kuncar@47308
   114
apply (rule QuotientI)
kuncar@47308
   115
apply simp
kuncar@47308
   116
apply metis
kuncar@47308
   117
apply simp
kuncar@47308
   118
apply (rule ext, rule ext, metis)
kuncar@47308
   119
done
kuncar@47308
   120
kuncar@47308
   121
lemma Quotient_alt_def2:
kuncar@47308
   122
  "Quotient R Abs Rep T \<longleftrightarrow>
kuncar@47308
   123
    (\<forall>a b. T a b \<longrightarrow> Abs a = b) \<and>
kuncar@47308
   124
    (\<forall>b. T (Rep b) b) \<and>
kuncar@47308
   125
    (\<forall>x y. R x y \<longleftrightarrow> T x (Abs y) \<and> T y (Abs x))"
kuncar@47308
   126
  unfolding Quotient_alt_def by (safe, metis+)
kuncar@47308
   127
kuncar@47308
   128
lemma fun_quotient:
kuncar@47308
   129
  assumes 1: "Quotient R1 abs1 rep1 T1"
kuncar@47308
   130
  assumes 2: "Quotient R2 abs2 rep2 T2"
kuncar@47308
   131
  shows "Quotient (R1 ===> R2) (rep1 ---> abs2) (abs1 ---> rep2) (T1 ===> T2)"
kuncar@47308
   132
  using assms unfolding Quotient_alt_def2
kuncar@47308
   133
  unfolding fun_rel_def fun_eq_iff map_fun_apply
kuncar@47308
   134
  by (safe, metis+)
kuncar@47308
   135
kuncar@47308
   136
lemma apply_rsp:
kuncar@47308
   137
  fixes f g::"'a \<Rightarrow> 'c"
kuncar@47308
   138
  assumes q: "Quotient R1 Abs1 Rep1 T1"
kuncar@47308
   139
  and     a: "(R1 ===> R2) f g" "R1 x y"
kuncar@47308
   140
  shows "R2 (f x) (g y)"
kuncar@47308
   141
  using a by (auto elim: fun_relE)
kuncar@47308
   142
kuncar@47308
   143
lemma apply_rsp':
kuncar@47308
   144
  assumes a: "(R1 ===> R2) f g" "R1 x y"
kuncar@47308
   145
  shows "R2 (f x) (g y)"
kuncar@47308
   146
  using a by (auto elim: fun_relE)
kuncar@47308
   147
kuncar@47308
   148
lemma apply_rsp'':
kuncar@47308
   149
  assumes "Quotient R Abs Rep T"
kuncar@47308
   150
  and "(R ===> S) f f"
kuncar@47308
   151
  shows "S (f (Rep x)) (f (Rep x))"
kuncar@47308
   152
proof -
kuncar@47308
   153
  from assms(1) have "R (Rep x) (Rep x)" by (rule Quotient_rep_reflp)
kuncar@47308
   154
  then show ?thesis using assms(2) by (auto intro: apply_rsp')
kuncar@47308
   155
qed
kuncar@47308
   156
kuncar@47308
   157
subsection {* Quotient composition *}
kuncar@47308
   158
kuncar@47308
   159
lemma Quotient_compose:
kuncar@47308
   160
  assumes 1: "Quotient R1 Abs1 Rep1 T1"
kuncar@47308
   161
  assumes 2: "Quotient R2 Abs2 Rep2 T2"
kuncar@47308
   162
  shows "Quotient (T1 OO R2 OO conversep T1) (Abs2 \<circ> Abs1) (Rep1 \<circ> Rep2) (T1 OO T2)"
kuncar@47308
   163
proof -
kuncar@47308
   164
  from 1 have Abs1: "\<And>a b. T1 a b \<Longrightarrow> Abs1 a = b"
kuncar@47308
   165
    unfolding Quotient_alt_def by simp
kuncar@47308
   166
  from 1 have Rep1: "\<And>b. T1 (Rep1 b) b"
kuncar@47308
   167
    unfolding Quotient_alt_def by simp
kuncar@47308
   168
  from 2 have Abs2: "\<And>a b. T2 a b \<Longrightarrow> Abs2 a = b"
kuncar@47308
   169
    unfolding Quotient_alt_def by simp
kuncar@47308
   170
  from 2 have Rep2: "\<And>b. T2 (Rep2 b) b"
kuncar@47308
   171
    unfolding Quotient_alt_def by simp
kuncar@47308
   172
  from 2 have R2:
kuncar@47308
   173
    "\<And>x y. R2 x y \<longleftrightarrow> T2 x (Abs2 x) \<and> T2 y (Abs2 y) \<and> Abs2 x = Abs2 y"
kuncar@47308
   174
    unfolding Quotient_alt_def by simp
kuncar@47308
   175
  show ?thesis
kuncar@47308
   176
    unfolding Quotient_alt_def
kuncar@47308
   177
    apply simp
kuncar@47308
   178
    apply safe
kuncar@47308
   179
    apply (drule Abs1, simp)
kuncar@47308
   180
    apply (erule Abs2)
griff@47435
   181
    apply (rule relcomppI)
kuncar@47308
   182
    apply (rule Rep1)
kuncar@47308
   183
    apply (rule Rep2)
griff@47435
   184
    apply (rule relcomppI, assumption)
kuncar@47308
   185
    apply (drule Abs1, simp)
kuncar@47308
   186
    apply (clarsimp simp add: R2)
griff@47435
   187
    apply (rule relcomppI, assumption)
kuncar@47308
   188
    apply (drule Abs1, simp)+
kuncar@47308
   189
    apply (clarsimp simp add: R2)
kuncar@47308
   190
    apply (drule Abs1, simp)+
kuncar@47308
   191
    apply (clarsimp simp add: R2)
griff@47435
   192
    apply (rule relcomppI, assumption)
griff@47435
   193
    apply (rule relcomppI [rotated])
kuncar@47308
   194
    apply (erule conversepI)
kuncar@47308
   195
    apply (drule Abs1, simp)+
kuncar@47308
   196
    apply (simp add: R2)
kuncar@47308
   197
    done
kuncar@47308
   198
qed
kuncar@47308
   199
kuncar@47521
   200
lemma equivp_reflp2:
kuncar@47521
   201
  "equivp R \<Longrightarrow> reflp R"
kuncar@47521
   202
  by (erule equivpE)
kuncar@47521
   203
huffman@47544
   204
subsection {* Respects predicate *}
huffman@47544
   205
huffman@47544
   206
definition Respects :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a set"
huffman@47544
   207
  where "Respects R = {x. R x x}"
huffman@47544
   208
huffman@47544
   209
lemma in_respects: "x \<in> Respects R \<longleftrightarrow> R x x"
huffman@47544
   210
  unfolding Respects_def by simp
huffman@47544
   211
kuncar@47308
   212
subsection {* Invariant *}
kuncar@47308
   213
kuncar@47308
   214
definition invariant :: "('a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" 
kuncar@47308
   215
  where "invariant R = (\<lambda>x y. R x \<and> x = y)"
kuncar@47308
   216
kuncar@47308
   217
lemma invariant_to_eq:
kuncar@47308
   218
  assumes "invariant P x y"
kuncar@47308
   219
  shows "x = y"
kuncar@47308
   220
using assms by (simp add: invariant_def)
kuncar@47308
   221
kuncar@47308
   222
lemma fun_rel_eq_invariant:
kuncar@47308
   223
  shows "((invariant R) ===> S) = (\<lambda>f g. \<forall>x. R x \<longrightarrow> S (f x) (g x))"
kuncar@47308
   224
by (auto simp add: invariant_def fun_rel_def)
kuncar@47308
   225
kuncar@47308
   226
lemma invariant_same_args:
kuncar@47308
   227
  shows "invariant P x x \<equiv> P x"
kuncar@47308
   228
using assms by (auto simp add: invariant_def)
kuncar@47308
   229
kuncar@47361
   230
lemma UNIV_typedef_to_Quotient:
kuncar@47308
   231
  assumes "type_definition Rep Abs UNIV"
kuncar@47361
   232
  and T_def: "T \<equiv> (\<lambda>x y. x = Rep y)"
kuncar@47308
   233
  shows "Quotient (op =) Abs Rep T"
kuncar@47308
   234
proof -
kuncar@47308
   235
  interpret type_definition Rep Abs UNIV by fact
kuncar@47361
   236
  from Abs_inject Rep_inverse Abs_inverse T_def show ?thesis 
kuncar@47361
   237
    by (fastforce intro!: QuotientI fun_eq_iff)
kuncar@47308
   238
qed
kuncar@47308
   239
kuncar@47361
   240
lemma UNIV_typedef_to_equivp:
kuncar@47308
   241
  fixes Abs :: "'a \<Rightarrow> 'b"
kuncar@47308
   242
  and Rep :: "'b \<Rightarrow> 'a"
kuncar@47308
   243
  assumes "type_definition Rep Abs (UNIV::'a set)"
kuncar@47308
   244
  shows "equivp (op=::'a\<Rightarrow>'a\<Rightarrow>bool)"
kuncar@47308
   245
by (rule identity_equivp)
kuncar@47308
   246
huffman@47354
   247
lemma typedef_to_Quotient:
kuncar@47361
   248
  assumes "type_definition Rep Abs S"
kuncar@47361
   249
  and T_def: "T \<equiv> (\<lambda>x y. x = Rep y)"
kuncar@47501
   250
  shows "Quotient (invariant (\<lambda>x. x \<in> S)) Abs Rep T"
kuncar@47361
   251
proof -
kuncar@47361
   252
  interpret type_definition Rep Abs S by fact
kuncar@47361
   253
  from Rep Abs_inject Rep_inverse Abs_inverse T_def show ?thesis
kuncar@47361
   254
    by (auto intro!: QuotientI simp: invariant_def fun_eq_iff)
kuncar@47361
   255
qed
kuncar@47361
   256
kuncar@47361
   257
lemma typedef_to_part_equivp:
kuncar@47361
   258
  assumes "type_definition Rep Abs S"
kuncar@47501
   259
  shows "part_equivp (invariant (\<lambda>x. x \<in> S))"
kuncar@47361
   260
proof (intro part_equivpI)
kuncar@47361
   261
  interpret type_definition Rep Abs S by fact
kuncar@47501
   262
  show "\<exists>x. invariant (\<lambda>x. x \<in> S) x x" using Rep by (auto simp: invariant_def)
kuncar@47361
   263
next
kuncar@47501
   264
  show "symp (invariant (\<lambda>x. x \<in> S))" by (auto intro: sympI simp: invariant_def)
kuncar@47361
   265
next
kuncar@47501
   266
  show "transp (invariant (\<lambda>x. x \<in> S))" by (auto intro: transpI simp: invariant_def)
kuncar@47361
   267
qed
kuncar@47361
   268
kuncar@47361
   269
lemma open_typedef_to_Quotient:
kuncar@47308
   270
  assumes "type_definition Rep Abs {x. P x}"
huffman@47354
   271
  and T_def: "T \<equiv> (\<lambda>x y. x = Rep y)"
kuncar@47308
   272
  shows "Quotient (invariant P) Abs Rep T"
kuncar@47308
   273
proof -
kuncar@47308
   274
  interpret type_definition Rep Abs "{x. P x}" by fact
huffman@47354
   275
  from Rep Abs_inject Rep_inverse Abs_inverse T_def show ?thesis
huffman@47354
   276
    by (auto intro!: QuotientI simp: invariant_def fun_eq_iff)
kuncar@47308
   277
qed
kuncar@47308
   278
kuncar@47361
   279
lemma open_typedef_to_part_equivp:
kuncar@47308
   280
  assumes "type_definition Rep Abs {x. P x}"
kuncar@47308
   281
  shows "part_equivp (invariant P)"
kuncar@47308
   282
proof (intro part_equivpI)
kuncar@47308
   283
  interpret type_definition Rep Abs "{x. P x}" by fact
kuncar@47308
   284
  show "\<exists>x. invariant P x x" using Rep by (auto simp: invariant_def)
kuncar@47308
   285
next
kuncar@47308
   286
  show "symp (invariant P)" by (auto intro: sympI simp: invariant_def)
kuncar@47308
   287
next
kuncar@47308
   288
  show "transp (invariant P)" by (auto intro: transpI simp: invariant_def)
kuncar@47308
   289
qed
kuncar@47308
   290
huffman@47376
   291
text {* Generating transfer rules for quotients. *}
huffman@47376
   292
huffman@47537
   293
context
huffman@47537
   294
  fixes R Abs Rep T
huffman@47537
   295
  assumes 1: "Quotient R Abs Rep T"
huffman@47537
   296
begin
huffman@47376
   297
huffman@47537
   298
lemma Quotient_right_unique: "right_unique T"
huffman@47537
   299
  using 1 unfolding Quotient_alt_def right_unique_def by metis
huffman@47537
   300
huffman@47537
   301
lemma Quotient_right_total: "right_total T"
huffman@47537
   302
  using 1 unfolding Quotient_alt_def right_total_def by metis
huffman@47537
   303
huffman@47537
   304
lemma Quotient_rel_eq_transfer: "(T ===> T ===> op =) R (op =)"
huffman@47537
   305
  using 1 unfolding Quotient_alt_def fun_rel_def by simp
huffman@47376
   306
huffman@47538
   307
lemma Quotient_abs_induct:
huffman@47538
   308
  assumes "\<And>y. R y y \<Longrightarrow> P (Abs y)" shows "P x"
huffman@47538
   309
  using 1 assms unfolding Quotient_def by metis
huffman@47538
   310
huffman@47544
   311
lemma Quotient_All_transfer:
huffman@47544
   312
  "((T ===> op =) ===> op =) (Ball (Respects R)) All"
huffman@47544
   313
  unfolding fun_rel_def Respects_def Quotient_cr_rel [OF 1]
huffman@47544
   314
  by (auto, metis Quotient_abs_induct)
huffman@47544
   315
huffman@47544
   316
lemma Quotient_Ex_transfer:
huffman@47544
   317
  "((T ===> op =) ===> op =) (Bex (Respects R)) Ex"
huffman@47544
   318
  unfolding fun_rel_def Respects_def Quotient_cr_rel [OF 1]
huffman@47544
   319
  by (auto, metis Quotient_rep_reflp [OF 1] Quotient_abs_rep [OF 1])
huffman@47544
   320
huffman@47544
   321
lemma Quotient_forall_transfer:
huffman@47544
   322
  "((T ===> op =) ===> op =) (transfer_bforall (\<lambda>x. R x x)) transfer_forall"
huffman@47544
   323
  using Quotient_All_transfer
huffman@47544
   324
  unfolding transfer_forall_def transfer_bforall_def
huffman@47544
   325
    Ball_def [abs_def] in_respects .
huffman@47544
   326
huffman@47537
   327
end
huffman@47537
   328
huffman@47537
   329
text {* Generating transfer rules for total quotients. *}
huffman@47376
   330
huffman@47537
   331
context
huffman@47537
   332
  fixes R Abs Rep T
huffman@47537
   333
  assumes 1: "Quotient R Abs Rep T" and 2: "reflp R"
huffman@47537
   334
begin
huffman@47376
   335
huffman@47537
   336
lemma Quotient_bi_total: "bi_total T"
huffman@47537
   337
  using 1 2 unfolding Quotient_alt_def bi_total_def reflp_def by auto
huffman@47537
   338
huffman@47537
   339
lemma Quotient_id_abs_transfer: "(op = ===> T) (\<lambda>x. x) Abs"
huffman@47537
   340
  using 1 2 unfolding Quotient_alt_def reflp_def fun_rel_def by simp
huffman@47537
   341
huffman@47537
   342
end
huffman@47376
   343
huffman@47368
   344
text {* Generating transfer rules for a type defined with @{text "typedef"}. *}
huffman@47368
   345
huffman@47534
   346
context
huffman@47534
   347
  fixes Rep Abs A T
huffman@47368
   348
  assumes type: "type_definition Rep Abs A"
huffman@47534
   349
  assumes T_def: "T \<equiv> (\<lambda>(x::'a) (y::'b). x = Rep y)"
huffman@47534
   350
begin
huffman@47534
   351
huffman@47534
   352
lemma typedef_bi_unique: "bi_unique T"
huffman@47368
   353
  unfolding bi_unique_def T_def
huffman@47368
   354
  by (simp add: type_definition.Rep_inject [OF type])
huffman@47368
   355
huffman@47534
   356
lemma typedef_right_total: "right_total T"
huffman@47368
   357
  unfolding right_total_def T_def by simp
huffman@47368
   358
huffman@47535
   359
lemma typedef_rep_transfer: "(T ===> op =) (\<lambda>x. x) Rep"
huffman@47535
   360
  unfolding fun_rel_def T_def by simp
huffman@47535
   361
huffman@47534
   362
lemma typedef_transfer_All: "((T ===> op =) ===> op =) (Ball A) All"
huffman@47534
   363
  unfolding T_def fun_rel_def
huffman@47534
   364
  by (metis type_definition.Rep [OF type]
huffman@47534
   365
    type_definition.Abs_inverse [OF type])
huffman@47534
   366
huffman@47534
   367
lemma typedef_transfer_Ex: "((T ===> op =) ===> op =) (Bex A) Ex"
huffman@47534
   368
  unfolding T_def fun_rel_def
huffman@47534
   369
  by (metis type_definition.Rep [OF type]
huffman@47534
   370
    type_definition.Abs_inverse [OF type])
huffman@47534
   371
huffman@47534
   372
lemma typedef_transfer_bforall:
huffman@47534
   373
  "((T ===> op =) ===> op =)
huffman@47534
   374
    (transfer_bforall (\<lambda>x. x \<in> A)) transfer_forall"
huffman@47534
   375
  unfolding transfer_bforall_def transfer_forall_def Ball_def [symmetric]
huffman@47535
   376
  by (rule typedef_transfer_All)
huffman@47534
   377
huffman@47534
   378
end
huffman@47534
   379
huffman@47537
   380
text {* Generating transfer rules for a type copy. *}
huffman@47537
   381
huffman@47368
   382
lemma copy_type_bi_total:
huffman@47368
   383
  assumes type: "type_definition Rep Abs UNIV"
huffman@47368
   384
  assumes T_def: "T \<equiv> (\<lambda>x y. x = Rep y)"
huffman@47368
   385
  shows "bi_total T"
huffman@47368
   386
  unfolding bi_total_def T_def
huffman@47368
   387
  by (metis type_definition.Abs_inverse [OF type] UNIV_I)
huffman@47368
   388
huffman@47368
   389
text {* Generating the correspondence rule for a constant defined with
huffman@47368
   390
  @{text "lift_definition"}. *}
huffman@47368
   391
huffman@47351
   392
lemma Quotient_to_transfer:
huffman@47351
   393
  assumes "Quotient R Abs Rep T" and "R c c" and "c' \<equiv> Abs c"
huffman@47351
   394
  shows "T c c'"
huffman@47351
   395
  using assms by (auto dest: Quotient_cr_rel)
huffman@47351
   396
kuncar@47308
   397
subsection {* ML setup *}
kuncar@47308
   398
kuncar@47308
   399
text {* Auxiliary data for the lifting package *}
kuncar@47308
   400
kuncar@47308
   401
use "Tools/Lifting/lifting_info.ML"
kuncar@47308
   402
setup Lifting_Info.setup
kuncar@47308
   403
kuncar@47308
   404
declare [[map "fun" = (fun_rel, fun_quotient)]]
kuncar@47308
   405
kuncar@47308
   406
use "Tools/Lifting/lifting_term.ML"
kuncar@47308
   407
kuncar@47308
   408
use "Tools/Lifting/lifting_def.ML"
kuncar@47308
   409
kuncar@47308
   410
use "Tools/Lifting/lifting_setup.ML"
kuncar@47308
   411
kuncar@47308
   412
hide_const (open) invariant
kuncar@47308
   413
kuncar@47308
   414
end