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