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