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