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