src/HOL/Quotient.thy
author haftmann
Sat Dec 24 15:53:08 2011 +0100 (2011-12-24)
changeset 45961 5cefe17916a6
parent 45802 b16f976db515
child 46468 4db76d47b51a
permissions -rw-r--r--
treatment of type constructor `set`
wenzelm@41959
     1
(*  Title:      HOL/Quotient.thy
kaliszyk@35222
     2
    Author:     Cezary Kaliszyk and Christian Urban
kaliszyk@35222
     3
*)
kaliszyk@35222
     4
huffman@35294
     5
header {* Definition of Quotient Types *}
huffman@35294
     6
kaliszyk@35222
     7
theory Quotient
haftmann@40466
     8
imports Plain Hilbert_Choice Equiv_Relations
kaliszyk@35222
     9
uses
wenzelm@37986
    10
  ("Tools/Quotient/quotient_info.ML")
wenzelm@45680
    11
  ("Tools/Quotient/quotient_type.ML")
wenzelm@37986
    12
  ("Tools/Quotient/quotient_def.ML")
wenzelm@37986
    13
  ("Tools/Quotient/quotient_term.ML")
wenzelm@37986
    14
  ("Tools/Quotient/quotient_tacs.ML")
kaliszyk@35222
    15
begin
kaliszyk@35222
    16
kaliszyk@35222
    17
text {*
haftmann@45961
    18
  An aside: contravariant functorial structure of sets.
haftmann@45961
    19
*}
haftmann@45961
    20
haftmann@45961
    21
enriched_type vimage
haftmann@45961
    22
  by (simp_all add: fun_eq_iff vimage_compose)
haftmann@45961
    23
haftmann@45961
    24
text {*
kaliszyk@35222
    25
  Basic definition for equivalence relations
kaliszyk@35222
    26
  that are represented by predicates.
kaliszyk@35222
    27
*}
kaliszyk@35222
    28
kaliszyk@35222
    29
text {* Composition of Relations *}
kaliszyk@35222
    30
kaliszyk@35222
    31
abbreviation
haftmann@40818
    32
  rel_conj :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool" (infixr "OOO" 75)
kaliszyk@35222
    33
where
kaliszyk@35222
    34
  "r1 OOO r2 \<equiv> r1 OO r2 OO r1"
kaliszyk@35222
    35
kaliszyk@35222
    36
lemma eq_comp_r:
kaliszyk@35222
    37
  shows "((op =) OOO R) = R"
nipkow@39302
    38
  by (auto simp add: fun_eq_iff)
kaliszyk@35222
    39
huffman@35294
    40
subsection {* Respects predicate *}
kaliszyk@35222
    41
kaliszyk@35222
    42
definition
haftmann@40466
    43
  Respects :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a set"
kaliszyk@35222
    44
where
haftmann@44553
    45
  "Respects R = {x. R x x}"
kaliszyk@35222
    46
kaliszyk@35222
    47
lemma in_respects:
haftmann@40466
    48
  shows "x \<in> Respects R \<longleftrightarrow> R x x"
haftmann@44553
    49
  unfolding Respects_def by simp
kaliszyk@35222
    50
huffman@35294
    51
subsection {* Function map and function relation *}
kaliszyk@35222
    52
haftmann@40602
    53
notation map_fun (infixr "--->" 55)
haftmann@40466
    54
haftmann@40602
    55
lemma map_fun_id:
haftmann@40466
    56
  "(id ---> id) = id"
haftmann@40602
    57
  by (simp add: fun_eq_iff)
kaliszyk@35222
    58
kaliszyk@35222
    59
definition
haftmann@40615
    60
  fun_rel :: "('a \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> ('c \<Rightarrow> 'd) \<Rightarrow> bool" (infixr "===>" 55)
kaliszyk@35222
    61
where
haftmann@40814
    62
  "fun_rel R1 R2 = (\<lambda>f g. \<forall>x y. R1 x y \<longrightarrow> R2 (f x) (g y))"
kaliszyk@35222
    63
kaliszyk@36276
    64
lemma fun_relI [intro]:
haftmann@40814
    65
  assumes "\<And>x y. R1 x y \<Longrightarrow> R2 (f x) (g y)"
haftmann@40814
    66
  shows "(R1 ===> R2) f g"
kaliszyk@36276
    67
  using assms by (simp add: fun_rel_def)
kaliszyk@35222
    68
haftmann@40466
    69
lemma fun_relE:
haftmann@40814
    70
  assumes "(R1 ===> R2) f g" and "R1 x y"
haftmann@40814
    71
  obtains "R2 (f x) (g y)"
haftmann@40466
    72
  using assms by (simp add: fun_rel_def)
kaliszyk@35222
    73
kaliszyk@35222
    74
lemma fun_rel_eq:
kaliszyk@35222
    75
  shows "((op =) ===> (op =)) = (op =)"
haftmann@40466
    76
  by (auto simp add: fun_eq_iff elim: fun_relE)
kaliszyk@35222
    77
kaliszyk@44413
    78
subsection {* set map (vimage) and set relation *}
kaliszyk@44413
    79
kaliszyk@44413
    80
definition "set_rel R xs ys \<equiv> \<forall>x y. R x y \<longrightarrow> x \<in> xs \<longleftrightarrow> y \<in> ys"
kaliszyk@44413
    81
kaliszyk@44413
    82
lemma vimage_id:
kaliszyk@44413
    83
  "vimage id = id"
kaliszyk@44413
    84
  unfolding vimage_def fun_eq_iff by auto
kaliszyk@44413
    85
kaliszyk@44413
    86
lemma set_rel_eq:
kaliszyk@44413
    87
  "set_rel op = = op ="
kaliszyk@44413
    88
  by (subst fun_eq_iff, subst fun_eq_iff) (simp add: set_eq_iff set_rel_def)
kaliszyk@44413
    89
kaliszyk@44413
    90
lemma set_rel_equivp:
kaliszyk@44413
    91
  assumes e: "equivp R"
kaliszyk@44413
    92
  shows "set_rel R xs ys \<longleftrightarrow> xs = ys \<and> (\<forall>x y. x \<in> xs \<longrightarrow> R x y \<longrightarrow> y \<in> xs)"
kaliszyk@44413
    93
  unfolding set_rel_def
kaliszyk@44413
    94
  using equivp_reflp[OF e]
huffman@44921
    95
  by auto (metis, metis equivp_symp[OF e])
kaliszyk@35222
    96
huffman@35294
    97
subsection {* Quotient Predicate *}
kaliszyk@35222
    98
kaliszyk@35222
    99
definition
haftmann@40814
   100
  "Quotient R Abs Rep \<longleftrightarrow>
haftmann@40814
   101
     (\<forall>a. Abs (Rep a) = a) \<and> (\<forall>a. R (Rep a) (Rep a)) \<and>
haftmann@40818
   102
     (\<forall>r s. R r s \<longleftrightarrow> R r r \<and> R s s \<and> Abs r = Abs s)"
haftmann@40818
   103
haftmann@40818
   104
lemma QuotientI:
haftmann@40818
   105
  assumes "\<And>a. Abs (Rep a) = a"
haftmann@40818
   106
    and "\<And>a. R (Rep a) (Rep a)"
haftmann@40818
   107
    and "\<And>r s. R r s \<longleftrightarrow> R r r \<and> R s s \<and> Abs r = Abs s"
haftmann@40818
   108
  shows "Quotient R Abs Rep"
haftmann@40818
   109
  using assms unfolding Quotient_def by blast
kaliszyk@35222
   110
kaliszyk@35222
   111
lemma Quotient_abs_rep:
haftmann@40814
   112
  assumes a: "Quotient R Abs Rep"
kaliszyk@35222
   113
  shows "Abs (Rep a) = a"
kaliszyk@35222
   114
  using a
kaliszyk@35222
   115
  unfolding Quotient_def
kaliszyk@35222
   116
  by simp
kaliszyk@35222
   117
kaliszyk@35222
   118
lemma Quotient_rep_reflp:
haftmann@40814
   119
  assumes a: "Quotient R Abs Rep"
haftmann@40814
   120
  shows "R (Rep a) (Rep a)"
kaliszyk@35222
   121
  using a
kaliszyk@35222
   122
  unfolding Quotient_def
kaliszyk@35222
   123
  by blast
kaliszyk@35222
   124
kaliszyk@35222
   125
lemma Quotient_rel:
haftmann@40814
   126
  assumes a: "Quotient R Abs Rep"
haftmann@40818
   127
  shows "R r r \<and> R s s \<and> Abs r = Abs s \<longleftrightarrow> R r s" -- {* orientation does not loop on rewriting *}
kaliszyk@35222
   128
  using a
kaliszyk@35222
   129
  unfolding Quotient_def
kaliszyk@35222
   130
  by blast
kaliszyk@35222
   131
kaliszyk@35222
   132
lemma Quotient_rel_rep:
kaliszyk@35222
   133
  assumes a: "Quotient R Abs Rep"
haftmann@40818
   134
  shows "R (Rep a) (Rep b) \<longleftrightarrow> a = b"
kaliszyk@35222
   135
  using a
kaliszyk@35222
   136
  unfolding Quotient_def
kaliszyk@35222
   137
  by metis
kaliszyk@35222
   138
kaliszyk@35222
   139
lemma Quotient_rep_abs:
kaliszyk@35222
   140
  assumes a: "Quotient R Abs Rep"
kaliszyk@35222
   141
  shows "R r r \<Longrightarrow> R (Rep (Abs r)) r"
kaliszyk@35222
   142
  using a unfolding Quotient_def
kaliszyk@35222
   143
  by blast
kaliszyk@35222
   144
kaliszyk@35222
   145
lemma Quotient_rel_abs:
haftmann@40814
   146
  assumes a: "Quotient R Abs Rep"
haftmann@40814
   147
  shows "R r s \<Longrightarrow> Abs r = Abs s"
kaliszyk@35222
   148
  using a unfolding Quotient_def
kaliszyk@35222
   149
  by blast
kaliszyk@35222
   150
kaliszyk@35222
   151
lemma Quotient_symp:
haftmann@40814
   152
  assumes a: "Quotient R Abs Rep"
haftmann@40814
   153
  shows "symp R"
haftmann@40814
   154
  using a unfolding Quotient_def using sympI by metis
kaliszyk@35222
   155
kaliszyk@35222
   156
lemma Quotient_transp:
haftmann@40814
   157
  assumes a: "Quotient R Abs Rep"
haftmann@40814
   158
  shows "transp R"
haftmann@40814
   159
  using a unfolding Quotient_def using transpI by metis
kaliszyk@35222
   160
kaliszyk@35222
   161
lemma identity_quotient:
kaliszyk@35222
   162
  shows "Quotient (op =) id id"
kaliszyk@35222
   163
  unfolding Quotient_def id_def
kaliszyk@35222
   164
  by blast
kaliszyk@35222
   165
kaliszyk@35222
   166
lemma fun_quotient:
kaliszyk@35222
   167
  assumes q1: "Quotient R1 abs1 rep1"
kaliszyk@35222
   168
  and     q2: "Quotient R2 abs2 rep2"
kaliszyk@35222
   169
  shows "Quotient (R1 ===> R2) (rep1 ---> abs2) (abs1 ---> rep2)"
kaliszyk@35222
   170
proof -
haftmann@40466
   171
  have "\<And>a. (rep1 ---> abs2) ((abs1 ---> rep2) a) = a"
haftmann@40466
   172
    using q1 q2 by (simp add: Quotient_def fun_eq_iff)
kaliszyk@35222
   173
  moreover
haftmann@40466
   174
  have "\<And>a. (R1 ===> R2) ((abs1 ---> rep2) a) ((abs1 ---> rep2) a)"
haftmann@40466
   175
    by (rule fun_relI)
haftmann@40466
   176
      (insert q1 q2 Quotient_rel_abs [of R1 abs1 rep1] Quotient_rel_rep [of R2 abs2 rep2],
haftmann@40466
   177
        simp (no_asm) add: Quotient_def, simp)
kaliszyk@35222
   178
  moreover
haftmann@40466
   179
  have "\<And>r s. (R1 ===> R2) r s = ((R1 ===> R2) r r \<and> (R1 ===> R2) s s \<and>
kaliszyk@35222
   180
        (rep1 ---> abs2) r  = (rep1 ---> abs2) s)"
haftmann@40466
   181
    apply(auto simp add: fun_rel_def fun_eq_iff)
kaliszyk@35222
   182
    using q1 q2 unfolding Quotient_def
kaliszyk@35222
   183
    apply(metis)
kaliszyk@35222
   184
    using q1 q2 unfolding Quotient_def
kaliszyk@35222
   185
    apply(metis)
kaliszyk@35222
   186
    using q1 q2 unfolding Quotient_def
kaliszyk@35222
   187
    apply(metis)
kaliszyk@35222
   188
    using q1 q2 unfolding Quotient_def
kaliszyk@35222
   189
    apply(metis)
kaliszyk@35222
   190
    done
kaliszyk@35222
   191
  ultimately
kaliszyk@35222
   192
  show "Quotient (R1 ===> R2) (rep1 ---> abs2) (abs1 ---> rep2)"
kaliszyk@35222
   193
    unfolding Quotient_def by blast
kaliszyk@35222
   194
qed
kaliszyk@35222
   195
kaliszyk@35222
   196
lemma abs_o_rep:
kaliszyk@35222
   197
  assumes a: "Quotient R Abs Rep"
kaliszyk@35222
   198
  shows "Abs o Rep = id"
nipkow@39302
   199
  unfolding fun_eq_iff
kaliszyk@35222
   200
  by (simp add: Quotient_abs_rep[OF a])
kaliszyk@35222
   201
kaliszyk@35222
   202
lemma equals_rsp:
kaliszyk@35222
   203
  assumes q: "Quotient R Abs Rep"
kaliszyk@35222
   204
  and     a: "R xa xb" "R ya yb"
kaliszyk@35222
   205
  shows "R xa ya = R xb yb"
kaliszyk@35222
   206
  using a Quotient_symp[OF q] Quotient_transp[OF q]
haftmann@40814
   207
  by (blast elim: sympE transpE)
kaliszyk@35222
   208
kaliszyk@35222
   209
lemma lambda_prs:
kaliszyk@35222
   210
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
   211
  and     q2: "Quotient R2 Abs2 Rep2"
kaliszyk@35222
   212
  shows "(Rep1 ---> Abs2) (\<lambda>x. Rep2 (f (Abs1 x))) = (\<lambda>x. f x)"
nipkow@39302
   213
  unfolding fun_eq_iff
kaliszyk@35222
   214
  using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2]
haftmann@40814
   215
  by simp
kaliszyk@35222
   216
kaliszyk@35222
   217
lemma lambda_prs1:
kaliszyk@35222
   218
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
   219
  and     q2: "Quotient R2 Abs2 Rep2"
kaliszyk@35222
   220
  shows "(Rep1 ---> Abs2) (\<lambda>x. (Abs1 ---> Rep2) f x) = (\<lambda>x. f x)"
nipkow@39302
   221
  unfolding fun_eq_iff
kaliszyk@35222
   222
  using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2]
haftmann@40814
   223
  by simp
kaliszyk@35222
   224
kaliszyk@35222
   225
lemma rep_abs_rsp:
kaliszyk@35222
   226
  assumes q: "Quotient R Abs Rep"
kaliszyk@35222
   227
  and     a: "R x1 x2"
kaliszyk@35222
   228
  shows "R x1 (Rep (Abs x2))"
kaliszyk@35222
   229
  using a Quotient_rel[OF q] Quotient_abs_rep[OF q] Quotient_rep_reflp[OF q]
kaliszyk@35222
   230
  by metis
kaliszyk@35222
   231
kaliszyk@35222
   232
lemma rep_abs_rsp_left:
kaliszyk@35222
   233
  assumes q: "Quotient R Abs Rep"
kaliszyk@35222
   234
  and     a: "R x1 x2"
kaliszyk@35222
   235
  shows "R (Rep (Abs x1)) x2"
kaliszyk@35222
   236
  using a Quotient_rel[OF q] Quotient_abs_rep[OF q] Quotient_rep_reflp[OF q]
kaliszyk@35222
   237
  by metis
kaliszyk@35222
   238
kaliszyk@35222
   239
text{*
kaliszyk@35222
   240
  In the following theorem R1 can be instantiated with anything,
kaliszyk@35222
   241
  but we know some of the types of the Rep and Abs functions;
kaliszyk@35222
   242
  so by solving Quotient assumptions we can get a unique R1 that
kaliszyk@35236
   243
  will be provable; which is why we need to use @{text apply_rsp} and
kaliszyk@35222
   244
  not the primed version *}
kaliszyk@35222
   245
kaliszyk@35222
   246
lemma apply_rsp:
kaliszyk@35222
   247
  fixes f g::"'a \<Rightarrow> 'c"
kaliszyk@35222
   248
  assumes q: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
   249
  and     a: "(R1 ===> R2) f g" "R1 x y"
kaliszyk@35222
   250
  shows "R2 (f x) (g y)"
haftmann@40466
   251
  using a by (auto elim: fun_relE)
kaliszyk@35222
   252
kaliszyk@35222
   253
lemma apply_rsp':
kaliszyk@35222
   254
  assumes a: "(R1 ===> R2) f g" "R1 x y"
kaliszyk@35222
   255
  shows "R2 (f x) (g y)"
haftmann@40466
   256
  using a by (auto elim: fun_relE)
kaliszyk@35222
   257
huffman@35294
   258
subsection {* lemmas for regularisation of ball and bex *}
kaliszyk@35222
   259
kaliszyk@35222
   260
lemma ball_reg_eqv:
kaliszyk@35222
   261
  fixes P :: "'a \<Rightarrow> bool"
kaliszyk@35222
   262
  assumes a: "equivp R"
kaliszyk@35222
   263
  shows "Ball (Respects R) P = (All P)"
kaliszyk@35222
   264
  using a
kaliszyk@35222
   265
  unfolding equivp_def
kaliszyk@35222
   266
  by (auto simp add: in_respects)
kaliszyk@35222
   267
kaliszyk@35222
   268
lemma bex_reg_eqv:
kaliszyk@35222
   269
  fixes P :: "'a \<Rightarrow> bool"
kaliszyk@35222
   270
  assumes a: "equivp R"
kaliszyk@35222
   271
  shows "Bex (Respects R) P = (Ex P)"
kaliszyk@35222
   272
  using a
kaliszyk@35222
   273
  unfolding equivp_def
kaliszyk@35222
   274
  by (auto simp add: in_respects)
kaliszyk@35222
   275
kaliszyk@35222
   276
lemma ball_reg_right:
haftmann@44553
   277
  assumes a: "\<And>x. x \<in> R \<Longrightarrow> P x \<longrightarrow> Q x"
kaliszyk@35222
   278
  shows "All P \<longrightarrow> Ball R Q"
huffman@44921
   279
  using a by fast
kaliszyk@35222
   280
kaliszyk@35222
   281
lemma bex_reg_left:
haftmann@44553
   282
  assumes a: "\<And>x. x \<in> R \<Longrightarrow> Q x \<longrightarrow> P x"
kaliszyk@35222
   283
  shows "Bex R Q \<longrightarrow> Ex P"
huffman@44921
   284
  using a by fast
kaliszyk@35222
   285
kaliszyk@35222
   286
lemma ball_reg_left:
kaliszyk@35222
   287
  assumes a: "equivp R"
kaliszyk@35222
   288
  shows "(\<And>x. (Q x \<longrightarrow> P x)) \<Longrightarrow> Ball (Respects R) Q \<longrightarrow> All P"
kaliszyk@35222
   289
  using a by (metis equivp_reflp in_respects)
kaliszyk@35222
   290
kaliszyk@35222
   291
lemma bex_reg_right:
kaliszyk@35222
   292
  assumes a: "equivp R"
kaliszyk@35222
   293
  shows "(\<And>x. (Q x \<longrightarrow> P x)) \<Longrightarrow> Ex Q \<longrightarrow> Bex (Respects R) P"
kaliszyk@35222
   294
  using a by (metis equivp_reflp in_respects)
kaliszyk@35222
   295
kaliszyk@35222
   296
lemma ball_reg_eqv_range:
kaliszyk@35222
   297
  fixes P::"'a \<Rightarrow> bool"
kaliszyk@35222
   298
  and x::"'a"
kaliszyk@35222
   299
  assumes a: "equivp R2"
kaliszyk@35222
   300
  shows   "(Ball (Respects (R1 ===> R2)) (\<lambda>f. P (f x)) = All (\<lambda>f. P (f x)))"
kaliszyk@35222
   301
  apply(rule iffI)
kaliszyk@35222
   302
  apply(rule allI)
kaliszyk@35222
   303
  apply(drule_tac x="\<lambda>y. f x" in bspec)
haftmann@40466
   304
  apply(simp add: in_respects fun_rel_def)
kaliszyk@35222
   305
  apply(rule impI)
kaliszyk@35222
   306
  using a equivp_reflp_symp_transp[of "R2"]
haftmann@40814
   307
  apply (auto elim: equivpE reflpE)
kaliszyk@35222
   308
  done
kaliszyk@35222
   309
kaliszyk@35222
   310
lemma bex_reg_eqv_range:
kaliszyk@35222
   311
  assumes a: "equivp R2"
kaliszyk@35222
   312
  shows   "(Bex (Respects (R1 ===> R2)) (\<lambda>f. P (f x)) = Ex (\<lambda>f. P (f x)))"
kaliszyk@35222
   313
  apply(auto)
kaliszyk@35222
   314
  apply(rule_tac x="\<lambda>y. f x" in bexI)
kaliszyk@35222
   315
  apply(simp)
haftmann@40466
   316
  apply(simp add: Respects_def in_respects fun_rel_def)
kaliszyk@35222
   317
  apply(rule impI)
kaliszyk@35222
   318
  using a equivp_reflp_symp_transp[of "R2"]
haftmann@40814
   319
  apply (auto elim: equivpE reflpE)
kaliszyk@35222
   320
  done
kaliszyk@35222
   321
kaliszyk@35222
   322
(* Next four lemmas are unused *)
kaliszyk@35222
   323
lemma all_reg:
kaliszyk@35222
   324
  assumes a: "!x :: 'a. (P x --> Q x)"
kaliszyk@35222
   325
  and     b: "All P"
kaliszyk@35222
   326
  shows "All Q"
huffman@44921
   327
  using a b by fast
kaliszyk@35222
   328
kaliszyk@35222
   329
lemma ex_reg:
kaliszyk@35222
   330
  assumes a: "!x :: 'a. (P x --> Q x)"
kaliszyk@35222
   331
  and     b: "Ex P"
kaliszyk@35222
   332
  shows "Ex Q"
huffman@44921
   333
  using a b by fast
kaliszyk@35222
   334
kaliszyk@35222
   335
lemma ball_reg:
haftmann@44553
   336
  assumes a: "!x :: 'a. (x \<in> R --> P x --> Q x)"
kaliszyk@35222
   337
  and     b: "Ball R P"
kaliszyk@35222
   338
  shows "Ball R Q"
huffman@44921
   339
  using a b by fast
kaliszyk@35222
   340
kaliszyk@35222
   341
lemma bex_reg:
haftmann@44553
   342
  assumes a: "!x :: 'a. (x \<in> R --> P x --> Q x)"
kaliszyk@35222
   343
  and     b: "Bex R P"
kaliszyk@35222
   344
  shows "Bex R Q"
huffman@44921
   345
  using a b by fast
kaliszyk@35222
   346
kaliszyk@35222
   347
kaliszyk@35222
   348
lemma ball_all_comm:
kaliszyk@35222
   349
  assumes "\<And>y. (\<forall>x\<in>P. A x y) \<longrightarrow> (\<forall>x. B x y)"
kaliszyk@35222
   350
  shows "(\<forall>x\<in>P. \<forall>y. A x y) \<longrightarrow> (\<forall>x. \<forall>y. B x y)"
kaliszyk@35222
   351
  using assms by auto
kaliszyk@35222
   352
kaliszyk@35222
   353
lemma bex_ex_comm:
kaliszyk@35222
   354
  assumes "(\<exists>y. \<exists>x. A x y) \<longrightarrow> (\<exists>y. \<exists>x\<in>P. B x y)"
kaliszyk@35222
   355
  shows "(\<exists>x. \<exists>y. A x y) \<longrightarrow> (\<exists>x\<in>P. \<exists>y. B x y)"
kaliszyk@35222
   356
  using assms by auto
kaliszyk@35222
   357
huffman@35294
   358
subsection {* Bounded abstraction *}
kaliszyk@35222
   359
kaliszyk@35222
   360
definition
haftmann@40466
   361
  Babs :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
kaliszyk@35222
   362
where
kaliszyk@35222
   363
  "x \<in> p \<Longrightarrow> Babs p m x = m x"
kaliszyk@35222
   364
kaliszyk@35222
   365
lemma babs_rsp:
kaliszyk@35222
   366
  assumes q: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
   367
  and     a: "(R1 ===> R2) f g"
kaliszyk@35222
   368
  shows      "(R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)"
haftmann@40466
   369
  apply (auto simp add: Babs_def in_respects fun_rel_def)
kaliszyk@35222
   370
  apply (subgoal_tac "x \<in> Respects R1 \<and> y \<in> Respects R1")
haftmann@40466
   371
  using a apply (simp add: Babs_def fun_rel_def)
haftmann@40466
   372
  apply (simp add: in_respects fun_rel_def)
kaliszyk@35222
   373
  using Quotient_rel[OF q]
kaliszyk@35222
   374
  by metis
kaliszyk@35222
   375
kaliszyk@35222
   376
lemma babs_prs:
kaliszyk@35222
   377
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
   378
  and     q2: "Quotient R2 Abs2 Rep2"
kaliszyk@35222
   379
  shows "((Rep1 ---> Abs2) (Babs (Respects R1) ((Abs1 ---> Rep2) f))) = f"
kaliszyk@35222
   380
  apply (rule ext)
haftmann@40466
   381
  apply (simp add:)
kaliszyk@35222
   382
  apply (subgoal_tac "Rep1 x \<in> Respects R1")
kaliszyk@35222
   383
  apply (simp add: Babs_def Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2])
kaliszyk@35222
   384
  apply (simp add: in_respects Quotient_rel_rep[OF q1])
kaliszyk@35222
   385
  done
kaliszyk@35222
   386
kaliszyk@35222
   387
lemma babs_simp:
kaliszyk@35222
   388
  assumes q: "Quotient R1 Abs Rep"
kaliszyk@35222
   389
  shows "((R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)) = ((R1 ===> R2) f g)"
kaliszyk@35222
   390
  apply(rule iffI)
kaliszyk@35222
   391
  apply(simp_all only: babs_rsp[OF q])
haftmann@40466
   392
  apply(auto simp add: Babs_def fun_rel_def)
kaliszyk@35222
   393
  apply (subgoal_tac "x \<in> Respects R1 \<and> y \<in> Respects R1")
kaliszyk@35222
   394
  apply(metis Babs_def)
kaliszyk@35222
   395
  apply (simp add: in_respects)
kaliszyk@35222
   396
  using Quotient_rel[OF q]
kaliszyk@35222
   397
  by metis
kaliszyk@35222
   398
kaliszyk@35222
   399
(* If a user proves that a particular functional relation
kaliszyk@35222
   400
   is an equivalence this may be useful in regularising *)
kaliszyk@35222
   401
lemma babs_reg_eqv:
kaliszyk@35222
   402
  shows "equivp R \<Longrightarrow> Babs (Respects R) P = P"
nipkow@39302
   403
  by (simp add: fun_eq_iff Babs_def in_respects equivp_reflp)
kaliszyk@35222
   404
kaliszyk@35222
   405
kaliszyk@35222
   406
(* 3 lemmas needed for proving repabs_inj *)
kaliszyk@35222
   407
lemma ball_rsp:
kaliszyk@35222
   408
  assumes a: "(R ===> (op =)) f g"
kaliszyk@35222
   409
  shows "Ball (Respects R) f = Ball (Respects R) g"
haftmann@40466
   410
  using a by (auto simp add: Ball_def in_respects elim: fun_relE)
kaliszyk@35222
   411
kaliszyk@35222
   412
lemma bex_rsp:
kaliszyk@35222
   413
  assumes a: "(R ===> (op =)) f g"
kaliszyk@35222
   414
  shows "(Bex (Respects R) f = Bex (Respects R) g)"
haftmann@40466
   415
  using a by (auto simp add: Bex_def in_respects elim: fun_relE)
kaliszyk@35222
   416
kaliszyk@35222
   417
lemma bex1_rsp:
kaliszyk@35222
   418
  assumes a: "(R ===> (op =)) f g"
kaliszyk@35222
   419
  shows "Ex1 (\<lambda>x. x \<in> Respects R \<and> f x) = Ex1 (\<lambda>x. x \<in> Respects R \<and> g x)"
haftmann@40466
   420
  using a by (auto elim: fun_relE simp add: Ex1_def in_respects) 
kaliszyk@35222
   421
kaliszyk@35222
   422
(* 2 lemmas needed for cleaning of quantifiers *)
kaliszyk@35222
   423
lemma all_prs:
kaliszyk@35222
   424
  assumes a: "Quotient R absf repf"
kaliszyk@35222
   425
  shows "Ball (Respects R) ((absf ---> id) f) = All f"
haftmann@40602
   426
  using a unfolding Quotient_def Ball_def in_respects id_apply comp_def map_fun_def
kaliszyk@35222
   427
  by metis
kaliszyk@35222
   428
kaliszyk@35222
   429
lemma ex_prs:
kaliszyk@35222
   430
  assumes a: "Quotient R absf repf"
kaliszyk@35222
   431
  shows "Bex (Respects R) ((absf ---> id) f) = Ex f"
haftmann@40602
   432
  using a unfolding Quotient_def Bex_def in_respects id_apply comp_def map_fun_def
kaliszyk@35222
   433
  by metis
kaliszyk@35222
   434
huffman@35294
   435
subsection {* @{text Bex1_rel} quantifier *}
kaliszyk@35222
   436
kaliszyk@35222
   437
definition
kaliszyk@35222
   438
  Bex1_rel :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool"
kaliszyk@35222
   439
where
kaliszyk@35222
   440
  "Bex1_rel R P \<longleftrightarrow> (\<exists>x \<in> Respects R. P x) \<and> (\<forall>x \<in> Respects R. \<forall>y \<in> Respects R. ((P x \<and> P y) \<longrightarrow> (R x y)))"
kaliszyk@35222
   441
kaliszyk@35222
   442
lemma bex1_rel_aux:
kaliszyk@35222
   443
  "\<lbrakk>\<forall>xa ya. R xa ya \<longrightarrow> x xa = y ya; Bex1_rel R x\<rbrakk> \<Longrightarrow> Bex1_rel R y"
kaliszyk@35222
   444
  unfolding Bex1_rel_def
kaliszyk@35222
   445
  apply (erule conjE)+
kaliszyk@35222
   446
  apply (erule bexE)
kaliszyk@35222
   447
  apply rule
kaliszyk@35222
   448
  apply (rule_tac x="xa" in bexI)
kaliszyk@35222
   449
  apply metis
kaliszyk@35222
   450
  apply metis
kaliszyk@35222
   451
  apply rule+
kaliszyk@35222
   452
  apply (erule_tac x="xaa" in ballE)
kaliszyk@35222
   453
  prefer 2
kaliszyk@35222
   454
  apply (metis)
kaliszyk@35222
   455
  apply (erule_tac x="ya" in ballE)
kaliszyk@35222
   456
  prefer 2
kaliszyk@35222
   457
  apply (metis)
kaliszyk@35222
   458
  apply (metis in_respects)
kaliszyk@35222
   459
  done
kaliszyk@35222
   460
kaliszyk@35222
   461
lemma bex1_rel_aux2:
kaliszyk@35222
   462
  "\<lbrakk>\<forall>xa ya. R xa ya \<longrightarrow> x xa = y ya; Bex1_rel R y\<rbrakk> \<Longrightarrow> Bex1_rel R x"
kaliszyk@35222
   463
  unfolding Bex1_rel_def
kaliszyk@35222
   464
  apply (erule conjE)+
kaliszyk@35222
   465
  apply (erule bexE)
kaliszyk@35222
   466
  apply rule
kaliszyk@35222
   467
  apply (rule_tac x="xa" in bexI)
kaliszyk@35222
   468
  apply metis
kaliszyk@35222
   469
  apply metis
kaliszyk@35222
   470
  apply rule+
kaliszyk@35222
   471
  apply (erule_tac x="xaa" in ballE)
kaliszyk@35222
   472
  prefer 2
kaliszyk@35222
   473
  apply (metis)
kaliszyk@35222
   474
  apply (erule_tac x="ya" in ballE)
kaliszyk@35222
   475
  prefer 2
kaliszyk@35222
   476
  apply (metis)
kaliszyk@35222
   477
  apply (metis in_respects)
kaliszyk@35222
   478
  done
kaliszyk@35222
   479
kaliszyk@35222
   480
lemma bex1_rel_rsp:
kaliszyk@35222
   481
  assumes a: "Quotient R absf repf"
kaliszyk@35222
   482
  shows "((R ===> op =) ===> op =) (Bex1_rel R) (Bex1_rel R)"
haftmann@40466
   483
  apply (simp add: fun_rel_def)
kaliszyk@35222
   484
  apply clarify
kaliszyk@35222
   485
  apply rule
kaliszyk@35222
   486
  apply (simp_all add: bex1_rel_aux bex1_rel_aux2)
kaliszyk@35222
   487
  apply (erule bex1_rel_aux2)
kaliszyk@35222
   488
  apply assumption
kaliszyk@35222
   489
  done
kaliszyk@35222
   490
kaliszyk@35222
   491
kaliszyk@35222
   492
lemma ex1_prs:
kaliszyk@35222
   493
  assumes a: "Quotient R absf repf"
kaliszyk@35222
   494
  shows "((absf ---> id) ---> id) (Bex1_rel R) f = Ex1 f"
haftmann@40466
   495
apply (simp add:)
kaliszyk@35222
   496
apply (subst Bex1_rel_def)
kaliszyk@35222
   497
apply (subst Bex_def)
kaliszyk@35222
   498
apply (subst Ex1_def)
kaliszyk@35222
   499
apply simp
kaliszyk@35222
   500
apply rule
kaliszyk@35222
   501
 apply (erule conjE)+
kaliszyk@35222
   502
 apply (erule_tac exE)
kaliszyk@35222
   503
 apply (erule conjE)
kaliszyk@35222
   504
 apply (subgoal_tac "\<forall>y. R y y \<longrightarrow> f (absf y) \<longrightarrow> R x y")
kaliszyk@35222
   505
  apply (rule_tac x="absf x" in exI)
kaliszyk@35222
   506
  apply (simp)
kaliszyk@35222
   507
  apply rule+
kaliszyk@35222
   508
  using a unfolding Quotient_def
kaliszyk@35222
   509
  apply metis
kaliszyk@35222
   510
 apply rule+
kaliszyk@35222
   511
 apply (erule_tac x="x" in ballE)
kaliszyk@35222
   512
  apply (erule_tac x="y" in ballE)
kaliszyk@35222
   513
   apply simp
kaliszyk@35222
   514
  apply (simp add: in_respects)
kaliszyk@35222
   515
 apply (simp add: in_respects)
kaliszyk@35222
   516
apply (erule_tac exE)
kaliszyk@35222
   517
 apply rule
kaliszyk@35222
   518
 apply (rule_tac x="repf x" in exI)
kaliszyk@35222
   519
 apply (simp only: in_respects)
kaliszyk@35222
   520
  apply rule
kaliszyk@35222
   521
 apply (metis Quotient_rel_rep[OF a])
kaliszyk@35222
   522
using a unfolding Quotient_def apply (simp)
kaliszyk@35222
   523
apply rule+
kaliszyk@35222
   524
using a unfolding Quotient_def in_respects
kaliszyk@35222
   525
apply metis
kaliszyk@35222
   526
done
kaliszyk@35222
   527
kaliszyk@38702
   528
lemma bex1_bexeq_reg:
kaliszyk@38702
   529
  shows "(\<exists>!x\<in>Respects R. P x) \<longrightarrow> (Bex1_rel R (\<lambda>x. P x))"
kaliszyk@35222
   530
  apply (simp add: Ex1_def Bex1_rel_def in_respects)
kaliszyk@35222
   531
  apply clarify
kaliszyk@35222
   532
  apply auto
kaliszyk@35222
   533
  apply (rule bexI)
kaliszyk@35222
   534
  apply assumption
kaliszyk@35222
   535
  apply (simp add: in_respects)
kaliszyk@35222
   536
  apply (simp add: in_respects)
kaliszyk@35222
   537
  apply auto
kaliszyk@35222
   538
  done
kaliszyk@35222
   539
kaliszyk@38702
   540
lemma bex1_bexeq_reg_eqv:
kaliszyk@38702
   541
  assumes a: "equivp R"
kaliszyk@38702
   542
  shows "(\<exists>!x. P x) \<longrightarrow> Bex1_rel R P"
kaliszyk@38702
   543
  using equivp_reflp[OF a]
kaliszyk@38702
   544
  apply (intro impI)
kaliszyk@38702
   545
  apply (elim ex1E)
kaliszyk@38702
   546
  apply (rule mp[OF bex1_bexeq_reg])
kaliszyk@38702
   547
  apply (rule_tac a="x" in ex1I)
kaliszyk@38702
   548
  apply (subst in_respects)
kaliszyk@38702
   549
  apply (rule conjI)
kaliszyk@38702
   550
  apply assumption
kaliszyk@38702
   551
  apply assumption
kaliszyk@38702
   552
  apply clarify
kaliszyk@38702
   553
  apply (erule_tac x="xa" in allE)
kaliszyk@38702
   554
  apply simp
kaliszyk@38702
   555
  done
kaliszyk@38702
   556
huffman@35294
   557
subsection {* Various respects and preserve lemmas *}
kaliszyk@35222
   558
kaliszyk@35222
   559
lemma quot_rel_rsp:
kaliszyk@35222
   560
  assumes a: "Quotient R Abs Rep"
kaliszyk@35222
   561
  shows "(R ===> R ===> op =) R R"
urbanc@38317
   562
  apply(rule fun_relI)+
kaliszyk@35222
   563
  apply(rule equals_rsp[OF a])
kaliszyk@35222
   564
  apply(assumption)+
kaliszyk@35222
   565
  done
kaliszyk@35222
   566
kaliszyk@35222
   567
lemma o_prs:
kaliszyk@35222
   568
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
   569
  and     q2: "Quotient R2 Abs2 Rep2"
kaliszyk@35222
   570
  and     q3: "Quotient R3 Abs3 Rep3"
kaliszyk@36215
   571
  shows "((Abs2 ---> Rep3) ---> (Abs1 ---> Rep2) ---> (Rep1 ---> Abs3)) op \<circ> = op \<circ>"
kaliszyk@36215
   572
  and   "(id ---> (Abs1 ---> id) ---> Rep1 ---> id) op \<circ> = op \<circ>"
kaliszyk@35222
   573
  using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] Quotient_abs_rep[OF q3]
haftmann@40466
   574
  by (simp_all add: fun_eq_iff)
kaliszyk@35222
   575
kaliszyk@35222
   576
lemma o_rsp:
kaliszyk@36215
   577
  "((R2 ===> R3) ===> (R1 ===> R2) ===> (R1 ===> R3)) op \<circ> op \<circ>"
kaliszyk@36215
   578
  "(op = ===> (R1 ===> op =) ===> R1 ===> op =) op \<circ> op \<circ>"
huffman@44921
   579
  by (force elim: fun_relE)+
kaliszyk@35222
   580
kaliszyk@35222
   581
lemma cond_prs:
kaliszyk@35222
   582
  assumes a: "Quotient R absf repf"
kaliszyk@35222
   583
  shows "absf (if a then repf b else repf c) = (if a then b else c)"
kaliszyk@35222
   584
  using a unfolding Quotient_def by auto
kaliszyk@35222
   585
kaliszyk@35222
   586
lemma if_prs:
kaliszyk@35222
   587
  assumes q: "Quotient R Abs Rep"
kaliszyk@36123
   588
  shows "(id ---> Rep ---> Rep ---> Abs) If = If"
kaliszyk@36123
   589
  using Quotient_abs_rep[OF q]
nipkow@39302
   590
  by (auto simp add: fun_eq_iff)
kaliszyk@35222
   591
kaliszyk@35222
   592
lemma if_rsp:
kaliszyk@35222
   593
  assumes q: "Quotient R Abs Rep"
kaliszyk@36123
   594
  shows "(op = ===> R ===> R ===> R) If If"
huffman@44921
   595
  by force
kaliszyk@35222
   596
kaliszyk@35222
   597
lemma let_prs:
kaliszyk@35222
   598
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
   599
  and     q2: "Quotient R2 Abs2 Rep2"
kaliszyk@37049
   600
  shows "(Rep2 ---> (Abs2 ---> Rep1) ---> Abs1) Let = Let"
kaliszyk@37049
   601
  using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2]
nipkow@39302
   602
  by (auto simp add: fun_eq_iff)
kaliszyk@35222
   603
kaliszyk@35222
   604
lemma let_rsp:
kaliszyk@37049
   605
  shows "(R1 ===> (R1 ===> R2) ===> R2) Let Let"
huffman@44921
   606
  by (force elim: fun_relE)
kaliszyk@35222
   607
kaliszyk@39669
   608
lemma id_rsp:
kaliszyk@39669
   609
  shows "(R ===> R) id id"
huffman@44921
   610
  by auto
kaliszyk@39669
   611
kaliszyk@39669
   612
lemma id_prs:
kaliszyk@39669
   613
  assumes a: "Quotient R Abs Rep"
kaliszyk@39669
   614
  shows "(Rep ---> Abs) id = id"
haftmann@40466
   615
  by (simp add: fun_eq_iff Quotient_abs_rep [OF a])
kaliszyk@39669
   616
kaliszyk@39669
   617
kaliszyk@35222
   618
locale quot_type =
kaliszyk@35222
   619
  fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
kaliszyk@44204
   620
  and   Abs :: "'a set \<Rightarrow> 'b"
kaliszyk@44204
   621
  and   Rep :: "'b \<Rightarrow> 'a set"
kaliszyk@37493
   622
  assumes equivp: "part_equivp R"
kaliszyk@44204
   623
  and     rep_prop: "\<And>y. \<exists>x. R x x \<and> Rep y = Collect (R x)"
kaliszyk@35222
   624
  and     rep_inverse: "\<And>x. Abs (Rep x) = x"
kaliszyk@44204
   625
  and     abs_inverse: "\<And>c. (\<exists>x. ((R x x) \<and> (c = Collect (R x)))) \<Longrightarrow> (Rep (Abs c)) = c"
kaliszyk@35222
   626
  and     rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)"
kaliszyk@35222
   627
begin
kaliszyk@35222
   628
kaliszyk@35222
   629
definition
haftmann@40466
   630
  abs :: "'a \<Rightarrow> 'b"
kaliszyk@35222
   631
where
kaliszyk@44204
   632
  "abs x = Abs (Collect (R x))"
kaliszyk@35222
   633
kaliszyk@35222
   634
definition
haftmann@40466
   635
  rep :: "'b \<Rightarrow> 'a"
kaliszyk@35222
   636
where
kaliszyk@44204
   637
  "rep a = (SOME x. x \<in> Rep a)"
kaliszyk@35222
   638
kaliszyk@44204
   639
lemma some_collect:
kaliszyk@37493
   640
  assumes "R r r"
kaliszyk@44204
   641
  shows "R (SOME x. x \<in> Collect (R r)) = R r"
kaliszyk@44204
   642
  apply simp
kaliszyk@44204
   643
  by (metis assms exE_some equivp[simplified part_equivp_def])
kaliszyk@35222
   644
kaliszyk@35222
   645
lemma Quotient:
kaliszyk@35222
   646
  shows "Quotient R abs rep"
kaliszyk@37493
   647
  unfolding Quotient_def abs_def rep_def
kaliszyk@37493
   648
  proof (intro conjI allI)
kaliszyk@37493
   649
    fix a r s
kaliszyk@44204
   650
    show x: "R (SOME x. x \<in> Rep a) (SOME x. x \<in> Rep a)" proof -
kaliszyk@44204
   651
      obtain x where r: "R x x" and rep: "Rep a = Collect (R x)" using rep_prop[of a] by auto
kaliszyk@44204
   652
      have "R (SOME x. x \<in> Rep a) x"  using r rep some_collect by metis
kaliszyk@44204
   653
      then have "R x (SOME x. x \<in> Rep a)" using part_equivp_symp[OF equivp] by fast
kaliszyk@44204
   654
      then show "R (SOME x. x \<in> Rep a) (SOME x. x \<in> Rep a)"
kaliszyk@44204
   655
        using part_equivp_transp[OF equivp] by (metis `R (SOME x. x \<in> Rep a) x`)
kaliszyk@37493
   656
    qed
kaliszyk@44204
   657
    have "Collect (R (SOME x. x \<in> Rep a)) = (Rep a)" by (metis some_collect rep_prop)
kaliszyk@44204
   658
    then show "Abs (Collect (R (SOME x. x \<in> Rep a))) = a" using rep_inverse by auto
kaliszyk@44204
   659
    have "R r r \<Longrightarrow> R s s \<Longrightarrow> Abs (Collect (R r)) = Abs (Collect (R s)) \<longleftrightarrow> R r = R s"
haftmann@44242
   660
    proof -
haftmann@44242
   661
      assume "R r r" and "R s s"
haftmann@44242
   662
      then have "Abs (Collect (R r)) = Abs (Collect (R s)) \<longleftrightarrow> Collect (R r) = Collect (R s)"
haftmann@44242
   663
        by (metis abs_inverse)
haftmann@44242
   664
      also have "Collect (R r) = Collect (R s) \<longleftrightarrow> (\<lambda>A x. x \<in> A) (Collect (R r)) = (\<lambda>A x. x \<in> A) (Collect (R s))"
haftmann@44242
   665
        by rule simp_all
haftmann@44242
   666
      finally show "Abs (Collect (R r)) = Abs (Collect (R s)) \<longleftrightarrow> R r = R s" by simp
haftmann@44242
   667
    qed
kaliszyk@44204
   668
    then show "R r s \<longleftrightarrow> R r r \<and> R s s \<and> (Abs (Collect (R r)) = Abs (Collect (R s)))"
kaliszyk@44204
   669
      using equivp[simplified part_equivp_def] by metis
kaliszyk@44204
   670
    qed
haftmann@44242
   671
kaliszyk@35222
   672
end
kaliszyk@35222
   673
huffman@35294
   674
subsection {* ML setup *}
kaliszyk@35222
   675
kaliszyk@35222
   676
text {* Auxiliary data for the quotient package *}
kaliszyk@35222
   677
wenzelm@37986
   678
use "Tools/Quotient/quotient_info.ML"
wenzelm@41452
   679
setup Quotient_Info.setup
kaliszyk@35222
   680
kuncar@45802
   681
declare [[map "fun" = fun_rel]]
kuncar@45802
   682
declare [[map set = set_rel]]
kaliszyk@35222
   683
kaliszyk@35222
   684
lemmas [quot_thm] = fun_quotient
haftmann@44553
   685
lemmas [quot_respect] = quot_rel_rsp if_rsp o_rsp let_rsp id_rsp
haftmann@44553
   686
lemmas [quot_preserve] = if_prs o_prs let_prs id_prs
kaliszyk@35222
   687
lemmas [quot_equiv] = identity_equivp
kaliszyk@35222
   688
kaliszyk@35222
   689
kaliszyk@35222
   690
text {* Lemmas about simplifying id's. *}
kaliszyk@35222
   691
lemmas [id_simps] =
kaliszyk@35222
   692
  id_def[symmetric]
haftmann@40602
   693
  map_fun_id
kaliszyk@35222
   694
  id_apply
kaliszyk@35222
   695
  id_o
kaliszyk@35222
   696
  o_id
kaliszyk@35222
   697
  eq_comp_r
kaliszyk@44413
   698
  set_rel_eq
kaliszyk@44413
   699
  vimage_id
kaliszyk@35222
   700
kaliszyk@35222
   701
text {* Translation functions for the lifting process. *}
wenzelm@37986
   702
use "Tools/Quotient/quotient_term.ML"
kaliszyk@35222
   703
kaliszyk@35222
   704
kaliszyk@35222
   705
text {* Definitions of the quotient types. *}
wenzelm@45680
   706
use "Tools/Quotient/quotient_type.ML"
kaliszyk@35222
   707
kaliszyk@35222
   708
kaliszyk@35222
   709
text {* Definitions for quotient constants. *}
wenzelm@37986
   710
use "Tools/Quotient/quotient_def.ML"
kaliszyk@35222
   711
kaliszyk@35222
   712
kaliszyk@35222
   713
text {*
kaliszyk@35222
   714
  An auxiliary constant for recording some information
kaliszyk@35222
   715
  about the lifted theorem in a tactic.
kaliszyk@35222
   716
*}
kaliszyk@35222
   717
definition
haftmann@40466
   718
  Quot_True :: "'a \<Rightarrow> bool"
haftmann@40466
   719
where
haftmann@40466
   720
  "Quot_True x \<longleftrightarrow> True"
kaliszyk@35222
   721
kaliszyk@35222
   722
lemma
kaliszyk@35222
   723
  shows QT_all: "Quot_True (All P) \<Longrightarrow> Quot_True P"
kaliszyk@35222
   724
  and   QT_ex:  "Quot_True (Ex P) \<Longrightarrow> Quot_True P"
kaliszyk@35222
   725
  and   QT_ex1: "Quot_True (Ex1 P) \<Longrightarrow> Quot_True P"
kaliszyk@35222
   726
  and   QT_lam: "Quot_True (\<lambda>x. P x) \<Longrightarrow> (\<And>x. Quot_True (P x))"
kaliszyk@35222
   727
  and   QT_ext: "(\<And>x. Quot_True (a x) \<Longrightarrow> f x = g x) \<Longrightarrow> (Quot_True a \<Longrightarrow> f = g)"
kaliszyk@35222
   728
  by (simp_all add: Quot_True_def ext)
kaliszyk@35222
   729
kaliszyk@35222
   730
lemma QT_imp: "Quot_True a \<equiv> Quot_True b"
kaliszyk@35222
   731
  by (simp add: Quot_True_def)
kaliszyk@35222
   732
kaliszyk@35222
   733
kaliszyk@35222
   734
text {* Tactics for proving the lifted theorems *}
wenzelm@37986
   735
use "Tools/Quotient/quotient_tacs.ML"
kaliszyk@35222
   736
huffman@35294
   737
subsection {* Methods / Interface *}
kaliszyk@35222
   738
kaliszyk@35222
   739
method_setup lifting =
urbanc@37593
   740
  {* Attrib.thms >> (fn thms => fn ctxt => 
urbanc@38859
   741
       SIMPLE_METHOD (HEADGOAL (Quotient_Tacs.lift_tac ctxt [] thms))) *}
wenzelm@42814
   742
  {* lift theorems to quotient types *}
kaliszyk@35222
   743
kaliszyk@35222
   744
method_setup lifting_setup =
urbanc@37593
   745
  {* Attrib.thm >> (fn thm => fn ctxt => 
urbanc@38859
   746
       SIMPLE_METHOD (HEADGOAL (Quotient_Tacs.lift_procedure_tac ctxt [] thm))) *}
wenzelm@42814
   747
  {* set up the three goals for the quotient lifting procedure *}
kaliszyk@35222
   748
urbanc@37593
   749
method_setup descending =
urbanc@38859
   750
  {* Scan.succeed (fn ctxt => SIMPLE_METHOD (HEADGOAL (Quotient_Tacs.descend_tac ctxt []))) *}
wenzelm@42814
   751
  {* decend theorems to the raw level *}
urbanc@37593
   752
urbanc@37593
   753
method_setup descending_setup =
urbanc@38859
   754
  {* Scan.succeed (fn ctxt => SIMPLE_METHOD (HEADGOAL (Quotient_Tacs.descend_procedure_tac ctxt []))) *}
wenzelm@42814
   755
  {* set up the three goals for the decending theorems *}
urbanc@37593
   756
urbanc@45782
   757
method_setup partiality_descending =
urbanc@45782
   758
  {* Scan.succeed (fn ctxt => SIMPLE_METHOD (HEADGOAL (Quotient_Tacs.partiality_descend_tac ctxt []))) *}
urbanc@45782
   759
  {* decend theorems to the raw level *}
urbanc@45782
   760
urbanc@45782
   761
method_setup partiality_descending_setup =
urbanc@45782
   762
  {* Scan.succeed (fn ctxt => 
urbanc@45782
   763
       SIMPLE_METHOD (HEADGOAL (Quotient_Tacs.partiality_descend_procedure_tac ctxt []))) *}
urbanc@45782
   764
  {* set up the three goals for the decending theorems *}
urbanc@45782
   765
kaliszyk@35222
   766
method_setup regularize =
kaliszyk@35222
   767
  {* Scan.succeed (fn ctxt => SIMPLE_METHOD (HEADGOAL (Quotient_Tacs.regularize_tac ctxt))) *}
wenzelm@42814
   768
  {* prove the regularization goals from the quotient lifting procedure *}
kaliszyk@35222
   769
kaliszyk@35222
   770
method_setup injection =
kaliszyk@35222
   771
  {* Scan.succeed (fn ctxt => SIMPLE_METHOD (HEADGOAL (Quotient_Tacs.all_injection_tac ctxt))) *}
wenzelm@42814
   772
  {* prove the rep/abs injection goals from the quotient lifting procedure *}
kaliszyk@35222
   773
kaliszyk@35222
   774
method_setup cleaning =
kaliszyk@35222
   775
  {* Scan.succeed (fn ctxt => SIMPLE_METHOD (HEADGOAL (Quotient_Tacs.clean_tac ctxt))) *}
wenzelm@42814
   776
  {* prove the cleaning goals from the quotient lifting procedure *}
kaliszyk@35222
   777
kaliszyk@35222
   778
attribute_setup quot_lifted =
kaliszyk@35222
   779
  {* Scan.succeed Quotient_Tacs.lifted_attrib *}
wenzelm@42814
   780
  {* lift theorems to quotient types *}
kaliszyk@35222
   781
kaliszyk@35222
   782
no_notation
kaliszyk@35222
   783
  rel_conj (infixr "OOO" 75) and
haftmann@40602
   784
  map_fun (infixr "--->" 55) and
kaliszyk@35222
   785
  fun_rel (infixr "===>" 55)
kaliszyk@35222
   786
kaliszyk@35222
   787
end