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