src/HOL/Lifting.thy
author kuncar
Thu Apr 10 17:48:15 2014 +0200 (2014-04-10)
changeset 56519 c1048f5bbb45
parent 56518 beb3b6851665
child 56524 f4ba736040fa
permissions -rw-r--r--
more appropriate name (Lifting.invariant -> eq_onp)
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
haftmann@51112
     9
imports Equiv_Relations Transfer
kuncar@47308
    10
keywords
kuncar@51374
    11
  "parametric" and
kuncar@53219
    12
  "print_quot_maps" "print_quotients" :: diag and
kuncar@47308
    13
  "lift_definition" :: thy_goal and
kuncar@53651
    14
  "setup_lifting" "lifting_forget" "lifting_update" :: thy_decl
kuncar@47308
    15
begin
kuncar@47308
    16
huffman@47325
    17
subsection {* Function map *}
kuncar@47308
    18
kuncar@53011
    19
context
kuncar@53011
    20
begin
kuncar@53011
    21
interpretation lifting_syntax .
kuncar@47308
    22
kuncar@47308
    23
lemma map_fun_id:
kuncar@47308
    24
  "(id ---> id) = id"
kuncar@47308
    25
  by (simp add: fun_eq_iff)
kuncar@47308
    26
kuncar@47308
    27
subsection {* Quotient Predicate *}
kuncar@47308
    28
kuncar@47308
    29
definition
kuncar@47308
    30
  "Quotient R Abs Rep T \<longleftrightarrow>
kuncar@47308
    31
     (\<forall>a. Abs (Rep a) = a) \<and> 
kuncar@47308
    32
     (\<forall>a. R (Rep a) (Rep a)) \<and>
kuncar@47308
    33
     (\<forall>r s. R r s \<longleftrightarrow> R r r \<and> R s s \<and> Abs r = Abs s) \<and>
kuncar@47308
    34
     T = (\<lambda>x y. R x x \<and> Abs x = y)"
kuncar@47308
    35
kuncar@47308
    36
lemma QuotientI:
kuncar@47308
    37
  assumes "\<And>a. Abs (Rep a) = a"
kuncar@47308
    38
    and "\<And>a. R (Rep a) (Rep a)"
kuncar@47308
    39
    and "\<And>r s. R r s \<longleftrightarrow> R r r \<and> R s s \<and> Abs r = Abs s"
kuncar@47308
    40
    and "T = (\<lambda>x y. R x x \<and> Abs x = y)"
kuncar@47308
    41
  shows "Quotient R Abs Rep T"
kuncar@47308
    42
  using assms unfolding Quotient_def by blast
kuncar@47308
    43
huffman@47536
    44
context
huffman@47536
    45
  fixes R Abs Rep T
kuncar@47308
    46
  assumes a: "Quotient R Abs Rep T"
huffman@47536
    47
begin
huffman@47536
    48
huffman@47536
    49
lemma Quotient_abs_rep: "Abs (Rep a) = a"
huffman@47536
    50
  using a unfolding Quotient_def
kuncar@47308
    51
  by simp
kuncar@47308
    52
huffman@47536
    53
lemma Quotient_rep_reflp: "R (Rep a) (Rep a)"
huffman@47536
    54
  using a unfolding Quotient_def
kuncar@47308
    55
  by blast
kuncar@47308
    56
kuncar@47308
    57
lemma Quotient_rel:
huffman@47536
    58
  "R r r \<and> R s s \<and> Abs r = Abs s \<longleftrightarrow> R r s" -- {* orientation does not loop on rewriting *}
huffman@47536
    59
  using a unfolding Quotient_def
kuncar@47308
    60
  by blast
kuncar@47308
    61
huffman@47536
    62
lemma Quotient_cr_rel: "T = (\<lambda>x y. R x x \<and> Abs x = y)"
kuncar@47308
    63
  using a unfolding Quotient_def
kuncar@47308
    64
  by blast
kuncar@47308
    65
huffman@47536
    66
lemma Quotient_refl1: "R r s \<Longrightarrow> R r r"
huffman@47536
    67
  using a unfolding Quotient_def
huffman@47536
    68
  by fast
huffman@47536
    69
huffman@47536
    70
lemma Quotient_refl2: "R r s \<Longrightarrow> R s s"
huffman@47536
    71
  using a unfolding Quotient_def
huffman@47536
    72
  by fast
huffman@47536
    73
huffman@47536
    74
lemma Quotient_rel_rep: "R (Rep a) (Rep b) \<longleftrightarrow> a = b"
huffman@47536
    75
  using a unfolding Quotient_def
huffman@47536
    76
  by metis
huffman@47536
    77
huffman@47536
    78
lemma Quotient_rep_abs: "R r r \<Longrightarrow> R (Rep (Abs r)) r"
kuncar@47308
    79
  using a unfolding Quotient_def
kuncar@47308
    80
  by blast
kuncar@47308
    81
kuncar@55610
    82
lemma Quotient_rep_abs_eq: "R t t \<Longrightarrow> R \<le> op= \<Longrightarrow> Rep (Abs t) = t"
kuncar@55610
    83
  using a unfolding Quotient_def
kuncar@55610
    84
  by blast
kuncar@55610
    85
kuncar@47937
    86
lemma Quotient_rep_abs_fold_unmap: 
kuncar@47937
    87
  assumes "x' \<equiv> Abs x" and "R x x" and "Rep x' \<equiv> Rep' x'" 
kuncar@47937
    88
  shows "R (Rep' x') x"
kuncar@47937
    89
proof -
kuncar@47937
    90
  have "R (Rep x') x" using assms(1-2) Quotient_rep_abs by auto
kuncar@47937
    91
  then show ?thesis using assms(3) by simp
kuncar@47937
    92
qed
kuncar@47937
    93
kuncar@47937
    94
lemma Quotient_Rep_eq:
kuncar@47937
    95
  assumes "x' \<equiv> Abs x" 
kuncar@47937
    96
  shows "Rep x' \<equiv> Rep x'"
kuncar@47937
    97
by simp
kuncar@47937
    98
huffman@47536
    99
lemma Quotient_rel_abs: "R r s \<Longrightarrow> Abs r = Abs s"
huffman@47536
   100
  using a unfolding Quotient_def
huffman@47536
   101
  by blast
huffman@47536
   102
kuncar@47937
   103
lemma Quotient_rel_abs2:
kuncar@47937
   104
  assumes "R (Rep x) y"
kuncar@47937
   105
  shows "x = Abs y"
kuncar@47937
   106
proof -
kuncar@47937
   107
  from assms have "Abs (Rep x) = Abs y" by (auto intro: Quotient_rel_abs)
kuncar@47937
   108
  then show ?thesis using assms(1) by (simp add: Quotient_abs_rep)
kuncar@47937
   109
qed
kuncar@47937
   110
huffman@47536
   111
lemma Quotient_symp: "symp R"
kuncar@47308
   112
  using a unfolding Quotient_def using sympI by (metis (full_types))
kuncar@47308
   113
huffman@47536
   114
lemma Quotient_transp: "transp R"
kuncar@47308
   115
  using a unfolding Quotient_def using transpI by (metis (full_types))
kuncar@47308
   116
huffman@47536
   117
lemma Quotient_part_equivp: "part_equivp R"
huffman@47536
   118
by (metis Quotient_rep_reflp Quotient_symp Quotient_transp part_equivpI)
huffman@47536
   119
huffman@47536
   120
end
kuncar@47308
   121
kuncar@47308
   122
lemma identity_quotient: "Quotient (op =) id id (op =)"
kuncar@47308
   123
unfolding Quotient_def by simp 
kuncar@47308
   124
huffman@47652
   125
text {* TODO: Use one of these alternatives as the real definition. *}
huffman@47652
   126
kuncar@47308
   127
lemma Quotient_alt_def:
kuncar@47308
   128
  "Quotient R Abs Rep T \<longleftrightarrow>
kuncar@47308
   129
    (\<forall>a b. T a b \<longrightarrow> Abs a = b) \<and>
kuncar@47308
   130
    (\<forall>b. T (Rep b) b) \<and>
kuncar@47308
   131
    (\<forall>x y. R x y \<longleftrightarrow> T x (Abs x) \<and> T y (Abs y) \<and> Abs x = Abs y)"
kuncar@47308
   132
apply safe
kuncar@47308
   133
apply (simp (no_asm_use) only: Quotient_def, fast)
kuncar@47308
   134
apply (simp (no_asm_use) only: Quotient_def, fast)
kuncar@47308
   135
apply (simp (no_asm_use) only: Quotient_def, fast)
kuncar@47308
   136
apply (simp (no_asm_use) only: Quotient_def, fast)
kuncar@47308
   137
apply (simp (no_asm_use) only: Quotient_def, fast)
kuncar@47308
   138
apply (simp (no_asm_use) only: Quotient_def, fast)
kuncar@47308
   139
apply (rule QuotientI)
kuncar@47308
   140
apply simp
kuncar@47308
   141
apply metis
kuncar@47308
   142
apply simp
kuncar@47308
   143
apply (rule ext, rule ext, metis)
kuncar@47308
   144
done
kuncar@47308
   145
kuncar@47308
   146
lemma Quotient_alt_def2:
kuncar@47308
   147
  "Quotient R Abs Rep T \<longleftrightarrow>
kuncar@47308
   148
    (\<forall>a b. T a b \<longrightarrow> Abs a = b) \<and>
kuncar@47308
   149
    (\<forall>b. T (Rep b) b) \<and>
kuncar@47308
   150
    (\<forall>x y. R x y \<longleftrightarrow> T x (Abs y) \<and> T y (Abs x))"
kuncar@47308
   151
  unfolding Quotient_alt_def by (safe, metis+)
kuncar@47308
   152
huffman@47652
   153
lemma Quotient_alt_def3:
huffman@47652
   154
  "Quotient R Abs Rep T \<longleftrightarrow>
huffman@47652
   155
    (\<forall>a b. T a b \<longrightarrow> Abs a = b) \<and> (\<forall>b. T (Rep b) b) \<and>
huffman@47652
   156
    (\<forall>x y. R x y \<longleftrightarrow> (\<exists>z. T x z \<and> T y z))"
huffman@47652
   157
  unfolding Quotient_alt_def2 by (safe, metis+)
huffman@47652
   158
huffman@47652
   159
lemma Quotient_alt_def4:
huffman@47652
   160
  "Quotient R Abs Rep T \<longleftrightarrow>
huffman@47652
   161
    (\<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
   162
  unfolding Quotient_alt_def3 fun_eq_iff by auto
huffman@47652
   163
kuncar@47308
   164
lemma fun_quotient:
kuncar@47308
   165
  assumes 1: "Quotient R1 abs1 rep1 T1"
kuncar@47308
   166
  assumes 2: "Quotient R2 abs2 rep2 T2"
kuncar@47308
   167
  shows "Quotient (R1 ===> R2) (rep1 ---> abs2) (abs1 ---> rep2) (T1 ===> T2)"
kuncar@47308
   168
  using assms unfolding Quotient_alt_def2
blanchet@55945
   169
  unfolding rel_fun_def fun_eq_iff map_fun_apply
kuncar@47308
   170
  by (safe, metis+)
kuncar@47308
   171
kuncar@47308
   172
lemma apply_rsp:
kuncar@47308
   173
  fixes f g::"'a \<Rightarrow> 'c"
kuncar@47308
   174
  assumes q: "Quotient R1 Abs1 Rep1 T1"
kuncar@47308
   175
  and     a: "(R1 ===> R2) f g" "R1 x y"
kuncar@47308
   176
  shows "R2 (f x) (g y)"
blanchet@55945
   177
  using a by (auto elim: rel_funE)
kuncar@47308
   178
kuncar@47308
   179
lemma apply_rsp':
kuncar@47308
   180
  assumes a: "(R1 ===> R2) f g" "R1 x y"
kuncar@47308
   181
  shows "R2 (f x) (g y)"
blanchet@55945
   182
  using a by (auto elim: rel_funE)
kuncar@47308
   183
kuncar@47308
   184
lemma apply_rsp'':
kuncar@47308
   185
  assumes "Quotient R Abs Rep T"
kuncar@47308
   186
  and "(R ===> S) f f"
kuncar@47308
   187
  shows "S (f (Rep x)) (f (Rep x))"
kuncar@47308
   188
proof -
kuncar@47308
   189
  from assms(1) have "R (Rep x) (Rep x)" by (rule Quotient_rep_reflp)
kuncar@47308
   190
  then show ?thesis using assms(2) by (auto intro: apply_rsp')
kuncar@47308
   191
qed
kuncar@47308
   192
kuncar@47308
   193
subsection {* Quotient composition *}
kuncar@47308
   194
kuncar@47308
   195
lemma Quotient_compose:
kuncar@47308
   196
  assumes 1: "Quotient R1 Abs1 Rep1 T1"
kuncar@47308
   197
  assumes 2: "Quotient R2 Abs2 Rep2 T2"
kuncar@47308
   198
  shows "Quotient (T1 OO R2 OO conversep T1) (Abs2 \<circ> Abs1) (Rep1 \<circ> Rep2) (T1 OO T2)"
kuncar@51994
   199
  using assms unfolding Quotient_alt_def4 by fastforce
kuncar@47308
   200
kuncar@47521
   201
lemma equivp_reflp2:
kuncar@47521
   202
  "equivp R \<Longrightarrow> reflp R"
kuncar@47521
   203
  by (erule equivpE)
kuncar@47521
   204
huffman@47544
   205
subsection {* Respects predicate *}
huffman@47544
   206
huffman@47544
   207
definition Respects :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a set"
huffman@47544
   208
  where "Respects R = {x. R x x}"
huffman@47544
   209
huffman@47544
   210
lemma in_respects: "x \<in> Respects R \<longleftrightarrow> R x x"
huffman@47544
   211
  unfolding Respects_def by simp
huffman@47544
   212
kuncar@47308
   213
subsection {* Invariant *}
kuncar@47308
   214
kuncar@56519
   215
definition eq_onp :: "('a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" 
kuncar@56519
   216
  where "eq_onp R = (\<lambda>x y. R x \<and> x = y)"
kuncar@47308
   217
kuncar@56519
   218
lemma eq_onp_to_eq:
kuncar@56519
   219
  assumes "eq_onp P x y"
kuncar@47308
   220
  shows "x = y"
kuncar@56519
   221
using assms by (simp add: eq_onp_def)
kuncar@47308
   222
kuncar@56519
   223
lemma rel_fun_eq_eq_onp: "(op= ===> eq_onp P) = eq_onp (\<lambda>f. \<forall>x. P(f x))"
kuncar@56519
   224
unfolding eq_onp_def rel_fun_def by auto
kuncar@55737
   225
kuncar@56519
   226
lemma rel_fun_eq_onp_rel:
kuncar@56519
   227
  shows "((eq_onp R) ===> S) = (\<lambda>f g. \<forall>x. R x \<longrightarrow> S (f x) (g x))"
kuncar@56519
   228
by (auto simp add: eq_onp_def rel_fun_def)
kuncar@47308
   229
kuncar@56519
   230
lemma eq_onp_same_args:
kuncar@56519
   231
  shows "eq_onp P x x \<equiv> P x"
kuncar@56519
   232
using assms by (auto simp add: eq_onp_def)
kuncar@47308
   233
kuncar@56519
   234
lemma eq_onp_transfer [transfer_rule]:
kuncar@53952
   235
  assumes [transfer_rule]: "bi_unique A"
kuncar@56519
   236
  shows "((A ===> op=) ===> A ===> A ===> op=) eq_onp eq_onp"
kuncar@56519
   237
unfolding eq_onp_def[abs_def] by transfer_prover
kuncar@53952
   238
kuncar@47361
   239
lemma UNIV_typedef_to_Quotient:
kuncar@47308
   240
  assumes "type_definition Rep Abs UNIV"
kuncar@47361
   241
  and T_def: "T \<equiv> (\<lambda>x y. x = Rep y)"
kuncar@47308
   242
  shows "Quotient (op =) Abs Rep T"
kuncar@47308
   243
proof -
kuncar@47308
   244
  interpret type_definition Rep Abs UNIV by fact
kuncar@47361
   245
  from Abs_inject Rep_inverse Abs_inverse T_def show ?thesis 
kuncar@47361
   246
    by (fastforce intro!: QuotientI fun_eq_iff)
kuncar@47308
   247
qed
kuncar@47308
   248
kuncar@47361
   249
lemma UNIV_typedef_to_equivp:
kuncar@47308
   250
  fixes Abs :: "'a \<Rightarrow> 'b"
kuncar@47308
   251
  and Rep :: "'b \<Rightarrow> 'a"
kuncar@47308
   252
  assumes "type_definition Rep Abs (UNIV::'a set)"
kuncar@47308
   253
  shows "equivp (op=::'a\<Rightarrow>'a\<Rightarrow>bool)"
kuncar@47308
   254
by (rule identity_equivp)
kuncar@47308
   255
huffman@47354
   256
lemma typedef_to_Quotient:
kuncar@47361
   257
  assumes "type_definition Rep Abs S"
kuncar@47361
   258
  and T_def: "T \<equiv> (\<lambda>x y. x = Rep y)"
kuncar@56519
   259
  shows "Quotient (eq_onp (\<lambda>x. x \<in> S)) Abs Rep T"
kuncar@47361
   260
proof -
kuncar@47361
   261
  interpret type_definition Rep Abs S by fact
kuncar@47361
   262
  from Rep Abs_inject Rep_inverse Abs_inverse T_def show ?thesis
kuncar@56519
   263
    by (auto intro!: QuotientI simp: eq_onp_def fun_eq_iff)
kuncar@47361
   264
qed
kuncar@47361
   265
kuncar@47361
   266
lemma typedef_to_part_equivp:
kuncar@47361
   267
  assumes "type_definition Rep Abs S"
kuncar@56519
   268
  shows "part_equivp (eq_onp (\<lambda>x. x \<in> S))"
kuncar@47361
   269
proof (intro part_equivpI)
kuncar@47361
   270
  interpret type_definition Rep Abs S by fact
kuncar@56519
   271
  show "\<exists>x. eq_onp (\<lambda>x. x \<in> S) x x" using Rep by (auto simp: eq_onp_def)
kuncar@47361
   272
next
kuncar@56519
   273
  show "symp (eq_onp (\<lambda>x. x \<in> S))" by (auto intro: sympI simp: eq_onp_def)
kuncar@47361
   274
next
kuncar@56519
   275
  show "transp (eq_onp (\<lambda>x. x \<in> S))" by (auto intro: transpI simp: eq_onp_def)
kuncar@47361
   276
qed
kuncar@47361
   277
kuncar@47361
   278
lemma open_typedef_to_Quotient:
kuncar@47308
   279
  assumes "type_definition Rep Abs {x. P x}"
huffman@47354
   280
  and T_def: "T \<equiv> (\<lambda>x y. x = Rep y)"
kuncar@56519
   281
  shows "Quotient (eq_onp P) Abs Rep T"
huffman@47651
   282
  using typedef_to_Quotient [OF assms] by simp
kuncar@47308
   283
kuncar@47361
   284
lemma open_typedef_to_part_equivp:
kuncar@47308
   285
  assumes "type_definition Rep Abs {x. P x}"
kuncar@56519
   286
  shows "part_equivp (eq_onp P)"
huffman@47651
   287
  using typedef_to_part_equivp [OF assms] by simp
kuncar@47308
   288
huffman@47376
   289
text {* Generating transfer rules for quotients. *}
huffman@47376
   290
huffman@47537
   291
context
huffman@47537
   292
  fixes R Abs Rep T
huffman@47537
   293
  assumes 1: "Quotient R Abs Rep T"
huffman@47537
   294
begin
huffman@47376
   295
huffman@47537
   296
lemma Quotient_right_unique: "right_unique T"
huffman@47537
   297
  using 1 unfolding Quotient_alt_def right_unique_def by metis
huffman@47537
   298
huffman@47537
   299
lemma Quotient_right_total: "right_total T"
huffman@47537
   300
  using 1 unfolding Quotient_alt_def right_total_def by metis
huffman@47537
   301
huffman@47537
   302
lemma Quotient_rel_eq_transfer: "(T ===> T ===> op =) R (op =)"
blanchet@55945
   303
  using 1 unfolding Quotient_alt_def rel_fun_def by simp
huffman@47376
   304
huffman@47538
   305
lemma Quotient_abs_induct:
huffman@47538
   306
  assumes "\<And>y. R y y \<Longrightarrow> P (Abs y)" shows "P x"
huffman@47538
   307
  using 1 assms unfolding Quotient_def by metis
huffman@47538
   308
huffman@47537
   309
end
huffman@47537
   310
huffman@47537
   311
text {* Generating transfer rules for total quotients. *}
huffman@47376
   312
huffman@47537
   313
context
huffman@47537
   314
  fixes R Abs Rep T
huffman@47537
   315
  assumes 1: "Quotient R Abs Rep T" and 2: "reflp R"
huffman@47537
   316
begin
huffman@47376
   317
kuncar@56518
   318
lemma Quotient_left_total: "left_total T"
kuncar@56518
   319
  using 1 2 unfolding Quotient_alt_def left_total_def reflp_def by auto
kuncar@56518
   320
huffman@47537
   321
lemma Quotient_bi_total: "bi_total T"
huffman@47537
   322
  using 1 2 unfolding Quotient_alt_def bi_total_def reflp_def by auto
huffman@47537
   323
huffman@47537
   324
lemma Quotient_id_abs_transfer: "(op = ===> T) (\<lambda>x. x) Abs"
blanchet@55945
   325
  using 1 2 unfolding Quotient_alt_def reflp_def rel_fun_def by simp
huffman@47537
   326
huffman@47575
   327
lemma Quotient_total_abs_induct: "(\<And>y. P (Abs y)) \<Longrightarrow> P x"
huffman@47575
   328
  using 1 2 assms unfolding Quotient_alt_def reflp_def by metis
huffman@47575
   329
huffman@47889
   330
lemma Quotient_total_abs_eq_iff: "Abs x = Abs y \<longleftrightarrow> R x y"
huffman@47889
   331
  using Quotient_rel [OF 1] 2 unfolding reflp_def by simp
huffman@47889
   332
huffman@47537
   333
end
huffman@47376
   334
huffman@47368
   335
text {* Generating transfer rules for a type defined with @{text "typedef"}. *}
huffman@47368
   336
huffman@47534
   337
context
huffman@47534
   338
  fixes Rep Abs A T
huffman@47368
   339
  assumes type: "type_definition Rep Abs A"
huffman@47534
   340
  assumes T_def: "T \<equiv> (\<lambda>(x::'a) (y::'b). x = Rep y)"
huffman@47534
   341
begin
huffman@47534
   342
kuncar@51994
   343
lemma typedef_left_unique: "left_unique T"
kuncar@51994
   344
  unfolding left_unique_def T_def
kuncar@51994
   345
  by (simp add: type_definition.Rep_inject [OF type])
kuncar@51994
   346
huffman@47534
   347
lemma typedef_bi_unique: "bi_unique T"
huffman@47368
   348
  unfolding bi_unique_def T_def
huffman@47368
   349
  by (simp add: type_definition.Rep_inject [OF type])
huffman@47368
   350
kuncar@51374
   351
(* the following two theorems are here only for convinience *)
kuncar@51374
   352
kuncar@51374
   353
lemma typedef_right_unique: "right_unique T"
kuncar@51374
   354
  using T_def type Quotient_right_unique typedef_to_Quotient 
kuncar@51374
   355
  by blast
kuncar@51374
   356
kuncar@51374
   357
lemma typedef_right_total: "right_total T"
kuncar@51374
   358
  using T_def type Quotient_right_total typedef_to_Quotient 
kuncar@51374
   359
  by blast
kuncar@51374
   360
huffman@47535
   361
lemma typedef_rep_transfer: "(T ===> op =) (\<lambda>x. x) Rep"
blanchet@55945
   362
  unfolding rel_fun_def T_def by simp
huffman@47535
   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
lemma Quotient_to_left_total:
kuncar@47982
   377
  assumes q: "Quotient R Abs Rep T"
kuncar@47982
   378
  and r_R: "reflp R"
kuncar@47982
   379
  shows "left_total T"
kuncar@47982
   380
using r_R Quotient_cr_rel[OF q] unfolding left_total_def by (auto elim: reflpE)
kuncar@47982
   381
kuncar@55563
   382
lemma Quotient_composition_ge_eq:
kuncar@55563
   383
  assumes "left_total T"
kuncar@55563
   384
  assumes "R \<ge> op="
kuncar@55563
   385
  shows "(T OO R OO T\<inverse>\<inverse>) \<ge> op="
kuncar@55563
   386
using assms unfolding left_total_def by fast
kuncar@51994
   387
kuncar@55563
   388
lemma Quotient_composition_le_eq:
kuncar@55563
   389
  assumes "left_unique T"
kuncar@55563
   390
  assumes "R \<le> op="
kuncar@55563
   391
  shows "(T OO R OO T\<inverse>\<inverse>) \<le> op="
noschinl@55604
   392
using assms unfolding left_unique_def by blast
kuncar@47982
   393
kuncar@56519
   394
lemma eq_onp_le_eq:
kuncar@56519
   395
  "eq_onp P \<le> op=" unfolding eq_onp_def by blast
kuncar@55563
   396
kuncar@55563
   397
lemma reflp_ge_eq:
kuncar@55563
   398
  "reflp R \<Longrightarrow> R \<ge> op=" unfolding reflp_def by blast
kuncar@55563
   399
kuncar@55563
   400
lemma ge_eq_refl:
kuncar@55563
   401
  "R \<ge> op= \<Longrightarrow> R x x" by blast
kuncar@47982
   402
kuncar@51374
   403
text {* Proving a parametrized correspondence relation *}
kuncar@51374
   404
kuncar@51374
   405
definition POS :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool" where
kuncar@51374
   406
"POS A B \<equiv> A \<le> B"
kuncar@51374
   407
kuncar@51374
   408
definition  NEG :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool" where
kuncar@51374
   409
"NEG A B \<equiv> B \<le> A"
kuncar@51374
   410
kuncar@51374
   411
lemma pos_OO_eq:
kuncar@51374
   412
  shows "POS (A OO op=) A"
kuncar@51374
   413
unfolding POS_def OO_def by blast
kuncar@51374
   414
kuncar@51374
   415
lemma pos_eq_OO:
kuncar@51374
   416
  shows "POS (op= OO A) A"
kuncar@51374
   417
unfolding POS_def OO_def by blast
kuncar@51374
   418
kuncar@51374
   419
lemma neg_OO_eq:
kuncar@51374
   420
  shows "NEG (A OO op=) A"
kuncar@51374
   421
unfolding NEG_def OO_def by auto
kuncar@51374
   422
kuncar@51374
   423
lemma neg_eq_OO:
kuncar@51374
   424
  shows "NEG (op= OO A) A"
kuncar@51374
   425
unfolding NEG_def OO_def by blast
kuncar@51374
   426
kuncar@51374
   427
lemma POS_trans:
kuncar@51374
   428
  assumes "POS A B"
kuncar@51374
   429
  assumes "POS B C"
kuncar@51374
   430
  shows "POS A C"
kuncar@51374
   431
using assms unfolding POS_def by auto
kuncar@51374
   432
kuncar@51374
   433
lemma NEG_trans:
kuncar@51374
   434
  assumes "NEG A B"
kuncar@51374
   435
  assumes "NEG B C"
kuncar@51374
   436
  shows "NEG A C"
kuncar@51374
   437
using assms unfolding NEG_def by auto
kuncar@51374
   438
kuncar@51374
   439
lemma POS_NEG:
kuncar@51374
   440
  "POS A B \<equiv> NEG B A"
kuncar@51374
   441
  unfolding POS_def NEG_def by auto
kuncar@51374
   442
kuncar@51374
   443
lemma NEG_POS:
kuncar@51374
   444
  "NEG A B \<equiv> POS B A"
kuncar@51374
   445
  unfolding POS_def NEG_def by auto
kuncar@51374
   446
kuncar@51374
   447
lemma POS_pcr_rule:
kuncar@51374
   448
  assumes "POS (A OO B) C"
kuncar@51374
   449
  shows "POS (A OO B OO X) (C OO X)"
kuncar@51374
   450
using assms unfolding POS_def OO_def by blast
kuncar@51374
   451
kuncar@51374
   452
lemma NEG_pcr_rule:
kuncar@51374
   453
  assumes "NEG (A OO B) C"
kuncar@51374
   454
  shows "NEG (A OO B OO X) (C OO X)"
kuncar@51374
   455
using assms unfolding NEG_def OO_def by blast
kuncar@51374
   456
kuncar@51374
   457
lemma POS_apply:
kuncar@51374
   458
  assumes "POS R R'"
kuncar@51374
   459
  assumes "R f g"
kuncar@51374
   460
  shows "R' f g"
kuncar@51374
   461
using assms unfolding POS_def by auto
kuncar@51374
   462
kuncar@51374
   463
text {* Proving a parametrized correspondence relation *}
kuncar@51374
   464
kuncar@51374
   465
lemma fun_mono:
kuncar@51374
   466
  assumes "A \<ge> C"
kuncar@51374
   467
  assumes "B \<le> D"
kuncar@51374
   468
  shows   "(A ===> B) \<le> (C ===> D)"
blanchet@55945
   469
using assms unfolding rel_fun_def by blast
kuncar@51374
   470
kuncar@51374
   471
lemma pos_fun_distr: "((R ===> S) OO (R' ===> S')) \<le> ((R OO R') ===> (S OO S'))"
blanchet@55945
   472
unfolding OO_def rel_fun_def by blast
kuncar@51374
   473
kuncar@51374
   474
lemma functional_relation: "right_unique R \<Longrightarrow> left_total R \<Longrightarrow> \<forall>x. \<exists>!y. R x y"
kuncar@51374
   475
unfolding right_unique_def left_total_def by blast
kuncar@51374
   476
kuncar@51374
   477
lemma functional_converse_relation: "left_unique R \<Longrightarrow> right_total R \<Longrightarrow> \<forall>y. \<exists>!x. R x y"
kuncar@51374
   478
unfolding left_unique_def right_total_def by blast
kuncar@51374
   479
kuncar@51374
   480
lemma neg_fun_distr1:
kuncar@51374
   481
assumes 1: "left_unique R" "right_total R"
kuncar@51374
   482
assumes 2: "right_unique R'" "left_total R'"
kuncar@51374
   483
shows "(R OO R' ===> S OO S') \<le> ((R ===> S) OO (R' ===> S')) "
kuncar@51374
   484
  using functional_relation[OF 2] functional_converse_relation[OF 1]
blanchet@55945
   485
  unfolding rel_fun_def OO_def
kuncar@51374
   486
  apply clarify
kuncar@51374
   487
  apply (subst all_comm)
kuncar@51374
   488
  apply (subst all_conj_distrib[symmetric])
kuncar@51374
   489
  apply (intro choice)
kuncar@51374
   490
  by metis
kuncar@51374
   491
kuncar@51374
   492
lemma neg_fun_distr2:
kuncar@51374
   493
assumes 1: "right_unique R'" "left_total R'"
kuncar@51374
   494
assumes 2: "left_unique S'" "right_total S'"
kuncar@51374
   495
shows "(R OO R' ===> S OO S') \<le> ((R ===> S) OO (R' ===> S'))"
kuncar@51374
   496
  using functional_converse_relation[OF 2] functional_relation[OF 1]
blanchet@55945
   497
  unfolding rel_fun_def OO_def
kuncar@51374
   498
  apply clarify
kuncar@51374
   499
  apply (subst all_comm)
kuncar@51374
   500
  apply (subst all_conj_distrib[symmetric])
kuncar@51374
   501
  apply (intro choice)
kuncar@51374
   502
  by metis
kuncar@51374
   503
kuncar@51956
   504
subsection {* Domains *}
kuncar@51956
   505
kuncar@56519
   506
lemma composed_equiv_rel_eq_onp:
kuncar@55731
   507
  assumes "left_unique R"
kuncar@55731
   508
  assumes "(R ===> op=) P P'"
kuncar@55731
   509
  assumes "Domainp R = P''"
kuncar@56519
   510
  shows "(R OO eq_onp P' OO R\<inverse>\<inverse>) = eq_onp (inf P'' P)"
kuncar@56519
   511
using assms unfolding OO_def conversep_iff Domainp_iff[abs_def] left_unique_def rel_fun_def eq_onp_def
kuncar@55731
   512
fun_eq_iff by blast
kuncar@55731
   513
kuncar@56519
   514
lemma composed_equiv_rel_eq_eq_onp:
kuncar@55731
   515
  assumes "left_unique R"
kuncar@55731
   516
  assumes "Domainp R = P"
kuncar@56519
   517
  shows "(R OO op= OO R\<inverse>\<inverse>) = eq_onp P"
kuncar@56519
   518
using assms unfolding OO_def conversep_iff Domainp_iff[abs_def] left_unique_def eq_onp_def
kuncar@55731
   519
fun_eq_iff is_equality_def by metis
kuncar@55731
   520
kuncar@51956
   521
lemma pcr_Domainp_par_left_total:
kuncar@51956
   522
  assumes "Domainp B = P"
kuncar@51956
   523
  assumes "left_total A"
kuncar@51956
   524
  assumes "(A ===> op=) P' P"
kuncar@51956
   525
  shows "Domainp (A OO B) = P'"
kuncar@51956
   526
using assms
blanchet@55945
   527
unfolding Domainp_iff[abs_def] OO_def bi_unique_def left_total_def rel_fun_def 
kuncar@51956
   528
by (fast intro: fun_eq_iff)
kuncar@51956
   529
kuncar@51956
   530
lemma pcr_Domainp_par:
kuncar@51956
   531
assumes "Domainp B = P2"
kuncar@51956
   532
assumes "Domainp A = P1"
kuncar@51956
   533
assumes "(A ===> op=) P2' P2"
kuncar@51956
   534
shows "Domainp (A OO B) = (inf P1 P2')"
blanchet@55945
   535
using assms unfolding rel_fun_def Domainp_iff[abs_def] OO_def
kuncar@51956
   536
by (fast intro: fun_eq_iff)
kuncar@51956
   537
kuncar@53151
   538
definition rel_pred_comp :: "('a => 'b => bool) => ('b => bool) => 'a => bool"
kuncar@51956
   539
where "rel_pred_comp R P \<equiv> \<lambda>x. \<exists>y. R x y \<and> P y"
kuncar@51956
   540
kuncar@51956
   541
lemma pcr_Domainp:
kuncar@51956
   542
assumes "Domainp B = P"
kuncar@53151
   543
shows "Domainp (A OO B) = (\<lambda>x. \<exists>y. A x y \<and> P y)"
kuncar@53151
   544
using assms by blast
kuncar@51956
   545
kuncar@51956
   546
lemma pcr_Domainp_total:
kuncar@56518
   547
  assumes "left_total B"
kuncar@51956
   548
  assumes "Domainp A = P"
kuncar@51956
   549
  shows "Domainp (A OO B) = P"
kuncar@56518
   550
using assms unfolding left_total_def 
kuncar@51956
   551
by fast
kuncar@51956
   552
kuncar@51956
   553
lemma Quotient_to_Domainp:
kuncar@51956
   554
  assumes "Quotient R Abs Rep T"
kuncar@51956
   555
  shows "Domainp T = (\<lambda>x. R x x)"  
kuncar@51956
   556
by (simp add: Domainp_iff[abs_def] Quotient_cr_rel[OF assms])
kuncar@51956
   557
kuncar@56519
   558
lemma eq_onp_to_Domainp:
kuncar@56519
   559
  assumes "Quotient (eq_onp P) Abs Rep T"
kuncar@51956
   560
  shows "Domainp T = P"
kuncar@56519
   561
by (simp add: eq_onp_def Domainp_iff[abs_def] Quotient_cr_rel[OF assms])
kuncar@51956
   562
kuncar@53011
   563
end
kuncar@53011
   564
kuncar@47308
   565
subsection {* ML setup *}
kuncar@47308
   566
wenzelm@48891
   567
ML_file "Tools/Lifting/lifting_util.ML"
kuncar@47308
   568
wenzelm@48891
   569
ML_file "Tools/Lifting/lifting_info.ML"
kuncar@47308
   570
setup Lifting_Info.setup
kuncar@47308
   571
kuncar@51374
   572
(* setup for the function type *)
kuncar@47777
   573
declare fun_quotient[quot_map]
kuncar@51374
   574
declare fun_mono[relator_mono]
kuncar@51374
   575
lemmas [relator_distr] = pos_fun_distr neg_fun_distr1 neg_fun_distr2
kuncar@47308
   576
wenzelm@48891
   577
ML_file "Tools/Lifting/lifting_term.ML"
kuncar@47308
   578
wenzelm@48891
   579
ML_file "Tools/Lifting/lifting_def.ML"
kuncar@47308
   580
wenzelm@48891
   581
ML_file "Tools/Lifting/lifting_setup.ML"
kuncar@56518
   582
                           
kuncar@56519
   583
hide_const (open) POS NEG
kuncar@47308
   584
kuncar@47308
   585
end