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