src/HOL/Library/Quotient_Set.thy
 author kuncar Thu Apr 26 12:01:58 2012 +0200 (2012-04-26) changeset 47777 f29e7dcd7c40 parent 47680 49aa3686e566 child 47922 bba52dffab2b permissions -rw-r--r--
use a quot_map theorem attribute instead of the complicated map attribute
```     1 (*  Title:      HOL/Library/Quotient_Set.thy
```
```     2     Author:     Cezary Kaliszyk and Christian Urban
```
```     3 *)
```
```     4
```
```     5 header {* Quotient infrastructure for the set type *}
```
```     6
```
```     7 theory Quotient_Set
```
```     8 imports Main Quotient_Syntax
```
```     9 begin
```
```    10
```
```    11 subsection {* Relator for set type *}
```
```    12
```
```    13 definition set_rel :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'b set \<Rightarrow> bool"
```
```    14   where "set_rel R = (\<lambda>A B. (\<forall>x\<in>A. \<exists>y\<in>B. R x y) \<and> (\<forall>y\<in>B. \<exists>x\<in>A. R x y))"
```
```    15
```
```    16 lemma set_relI:
```
```    17   assumes "\<And>x. x \<in> A \<Longrightarrow> \<exists>y\<in>B. R x y"
```
```    18   assumes "\<And>y. y \<in> B \<Longrightarrow> \<exists>x\<in>A. R x y"
```
```    19   shows "set_rel R A B"
```
```    20   using assms unfolding set_rel_def by simp
```
```    21
```
```    22 lemma set_rel_conversep: "set_rel (conversep R) = conversep (set_rel R)"
```
```    23   unfolding set_rel_def by auto
```
```    24
```
```    25 lemma set_rel_OO: "set_rel (R OO S) = set_rel R OO set_rel S"
```
```    26   apply (intro ext, rename_tac X Z)
```
```    27   apply (rule iffI)
```
```    28   apply (rule_tac b="{y. (\<exists>x\<in>X. R x y) \<and> (\<exists>z\<in>Z. S y z)}" in relcomppI)
```
```    29   apply (simp add: set_rel_def, fast)
```
```    30   apply (simp add: set_rel_def, fast)
```
```    31   apply (simp add: set_rel_def, fast)
```
```    32   done
```
```    33
```
```    34 lemma set_rel_eq [relator_eq]: "set_rel (op =) = (op =)"
```
```    35   unfolding set_rel_def fun_eq_iff by auto
```
```    36
```
```    37 lemma reflp_set_rel: "reflp R \<Longrightarrow> reflp (set_rel R)"
```
```    38   unfolding reflp_def set_rel_def by fast
```
```    39
```
```    40 lemma symp_set_rel: "symp R \<Longrightarrow> symp (set_rel R)"
```
```    41   unfolding symp_def set_rel_def by fast
```
```    42
```
```    43 lemma transp_set_rel: "transp R \<Longrightarrow> transp (set_rel R)"
```
```    44   unfolding transp_def set_rel_def by fast
```
```    45
```
```    46 lemma equivp_set_rel: "equivp R \<Longrightarrow> equivp (set_rel R)"
```
```    47   by (blast intro: equivpI reflp_set_rel symp_set_rel transp_set_rel
```
```    48     elim: equivpE)
```
```    49
```
```    50 lemma right_total_set_rel [transfer_rule]:
```
```    51   "right_total A \<Longrightarrow> right_total (set_rel A)"
```
```    52   unfolding right_total_def set_rel_def
```
```    53   by (rule allI, rename_tac Y, rule_tac x="{x. \<exists>y\<in>Y. A x y}" in exI, fast)
```
```    54
```
```    55 lemma right_unique_set_rel [transfer_rule]:
```
```    56   "right_unique A \<Longrightarrow> right_unique (set_rel A)"
```
```    57   unfolding right_unique_def set_rel_def by fast
```
```    58
```
```    59 lemma bi_total_set_rel [transfer_rule]:
```
```    60   "bi_total A \<Longrightarrow> bi_total (set_rel A)"
```
```    61   unfolding bi_total_def set_rel_def
```
```    62   apply safe
```
```    63   apply (rename_tac X, rule_tac x="{y. \<exists>x\<in>X. A x y}" in exI, fast)
```
```    64   apply (rename_tac Y, rule_tac x="{x. \<exists>y\<in>Y. A x y}" in exI, fast)
```
```    65   done
```
```    66
```
```    67 lemma bi_unique_set_rel [transfer_rule]:
```
```    68   "bi_unique A \<Longrightarrow> bi_unique (set_rel A)"
```
```    69   unfolding bi_unique_def set_rel_def by fast
```
```    70
```
```    71 subsection {* Transfer rules for transfer package *}
```
```    72
```
```    73 subsubsection {* Unconditional transfer rules *}
```
```    74
```
```    75 lemma empty_transfer [transfer_rule]: "(set_rel A) {} {}"
```
```    76   unfolding set_rel_def by simp
```
```    77
```
```    78 lemma insert_transfer [transfer_rule]:
```
```    79   "(A ===> set_rel A ===> set_rel A) insert insert"
```
```    80   unfolding fun_rel_def set_rel_def by auto
```
```    81
```
```    82 lemma union_transfer [transfer_rule]:
```
```    83   "(set_rel A ===> set_rel A ===> set_rel A) union union"
```
```    84   unfolding fun_rel_def set_rel_def by auto
```
```    85
```
```    86 lemma Union_transfer [transfer_rule]:
```
```    87   "(set_rel (set_rel A) ===> set_rel A) Union Union"
```
```    88   unfolding fun_rel_def set_rel_def by simp fast
```
```    89
```
```    90 lemma image_transfer [transfer_rule]:
```
```    91   "((A ===> B) ===> set_rel A ===> set_rel B) image image"
```
```    92   unfolding fun_rel_def set_rel_def by simp fast
```
```    93
```
```    94 lemma UNION_transfer [transfer_rule]:
```
```    95   "(set_rel A ===> (A ===> set_rel B) ===> set_rel B) UNION UNION"
```
```    96   unfolding SUP_def [abs_def] by transfer_prover
```
```    97
```
```    98 lemma Ball_transfer [transfer_rule]:
```
```    99   "(set_rel A ===> (A ===> op =) ===> op =) Ball Ball"
```
```   100   unfolding set_rel_def fun_rel_def by fast
```
```   101
```
```   102 lemma Bex_transfer [transfer_rule]:
```
```   103   "(set_rel A ===> (A ===> op =) ===> op =) Bex Bex"
```
```   104   unfolding set_rel_def fun_rel_def by fast
```
```   105
```
```   106 lemma Pow_transfer [transfer_rule]:
```
```   107   "(set_rel A ===> set_rel (set_rel A)) Pow Pow"
```
```   108   apply (rule fun_relI, rename_tac X Y, rule set_relI)
```
```   109   apply (rename_tac X', rule_tac x="{y\<in>Y. \<exists>x\<in>X'. A x y}" in rev_bexI, clarsimp)
```
```   110   apply (simp add: set_rel_def, fast)
```
```   111   apply (rename_tac Y', rule_tac x="{x\<in>X. \<exists>y\<in>Y'. A x y}" in rev_bexI, clarsimp)
```
```   112   apply (simp add: set_rel_def, fast)
```
```   113   done
```
```   114
```
```   115 subsubsection {* Rules requiring bi-unique or bi-total relations *}
```
```   116
```
```   117 lemma member_transfer [transfer_rule]:
```
```   118   assumes "bi_unique A"
```
```   119   shows "(A ===> set_rel A ===> op =) (op \<in>) (op \<in>)"
```
```   120   using assms unfolding fun_rel_def set_rel_def bi_unique_def by fast
```
```   121
```
```   122 lemma Collect_transfer [transfer_rule]:
```
```   123   assumes "bi_total A"
```
```   124   shows "((A ===> op =) ===> set_rel A) Collect Collect"
```
```   125   using assms unfolding fun_rel_def set_rel_def bi_total_def by fast
```
```   126
```
```   127 lemma inter_transfer [transfer_rule]:
```
```   128   assumes "bi_unique A"
```
```   129   shows "(set_rel A ===> set_rel A ===> set_rel A) inter inter"
```
```   130   using assms unfolding fun_rel_def set_rel_def bi_unique_def by fast
```
```   131
```
```   132 lemma Diff_transfer [transfer_rule]:
```
```   133   assumes "bi_unique A"
```
```   134   shows "(set_rel A ===> set_rel A ===> set_rel A) (op -) (op -)"
```
```   135   using assms unfolding fun_rel_def set_rel_def bi_unique_def
```
```   136   unfolding Ball_def Bex_def Diff_eq
```
```   137   by (safe, simp, metis, simp, metis)
```
```   138
```
```   139 lemma subset_transfer [transfer_rule]:
```
```   140   assumes [transfer_rule]: "bi_unique A"
```
```   141   shows "(set_rel A ===> set_rel A ===> op =) (op \<subseteq>) (op \<subseteq>)"
```
```   142   unfolding subset_eq [abs_def] by transfer_prover
```
```   143
```
```   144 lemma UNIV_transfer [transfer_rule]:
```
```   145   assumes "bi_total A"
```
```   146   shows "(set_rel A) UNIV UNIV"
```
```   147   using assms unfolding set_rel_def bi_total_def by simp
```
```   148
```
```   149 lemma Compl_transfer [transfer_rule]:
```
```   150   assumes [transfer_rule]: "bi_unique A" and [transfer_rule]: "bi_total A"
```
```   151   shows "(set_rel A ===> set_rel A) uminus uminus"
```
```   152   unfolding Compl_eq [abs_def] by transfer_prover
```
```   153
```
```   154 lemma Inter_transfer [transfer_rule]:
```
```   155   assumes [transfer_rule]: "bi_unique A" and [transfer_rule]: "bi_total A"
```
```   156   shows "(set_rel (set_rel A) ===> set_rel A) Inter Inter"
```
```   157   unfolding Inter_eq [abs_def] by transfer_prover
```
```   158
```
```   159 lemma finite_transfer [transfer_rule]:
```
```   160   assumes "bi_unique A"
```
```   161   shows "(set_rel A ===> op =) finite finite"
```
```   162   apply (rule fun_relI, rename_tac X Y)
```
```   163   apply (rule iffI)
```
```   164   apply (subgoal_tac "Y \<subseteq> (\<lambda>x. THE y. A x y) ` X")
```
```   165   apply (erule finite_subset, erule finite_imageI)
```
```   166   apply (rule subsetI, rename_tac y)
```
```   167   apply (clarsimp simp add: set_rel_def)
```
```   168   apply (drule (1) bspec, clarify)
```
```   169   apply (rule image_eqI)
```
```   170   apply (rule the_equality [symmetric])
```
```   171   apply assumption
```
```   172   apply (simp add: assms [unfolded bi_unique_def])
```
```   173   apply assumption
```
```   174   apply (subgoal_tac "X \<subseteq> (\<lambda>y. THE x. A x y) ` Y")
```
```   175   apply (erule finite_subset, erule finite_imageI)
```
```   176   apply (rule subsetI, rename_tac x)
```
```   177   apply (clarsimp simp add: set_rel_def)
```
```   178   apply (drule (1) bspec, clarify)
```
```   179   apply (rule image_eqI)
```
```   180   apply (rule the_equality [symmetric])
```
```   181   apply assumption
```
```   182   apply (simp add: assms [unfolded bi_unique_def])
```
```   183   apply assumption
```
```   184   done
```
```   185
```
```   186 subsection {* Setup for lifting package *}
```
```   187
```
```   188 lemma Quotient_set[quot_map]:
```
```   189   assumes "Quotient R Abs Rep T"
```
```   190   shows "Quotient (set_rel R) (image Abs) (image Rep) (set_rel T)"
```
```   191   using assms unfolding Quotient_alt_def4
```
```   192   apply (simp add: set_rel_OO set_rel_conversep)
```
```   193   apply (simp add: set_rel_def, fast)
```
```   194   done
```
```   195
```
```   196 lemma set_invariant_commute [invariant_commute]:
```
```   197   "set_rel (Lifting.invariant P) = Lifting.invariant (\<lambda>A. Ball A P)"
```
```   198   unfolding fun_eq_iff set_rel_def Lifting.invariant_def Ball_def by fast
```
```   199
```
```   200 subsection {* Contravariant set map (vimage) and set relator *}
```
```   201
```
```   202 definition "vset_rel R xs ys \<equiv> \<forall>x y. R x y \<longrightarrow> x \<in> xs \<longleftrightarrow> y \<in> ys"
```
```   203
```
```   204 lemma vset_rel_eq [id_simps]:
```
```   205   "vset_rel op = = op ="
```
```   206   by (subst fun_eq_iff, subst fun_eq_iff) (simp add: set_eq_iff vset_rel_def)
```
```   207
```
```   208 lemma vset_rel_equivp:
```
```   209   assumes e: "equivp R"
```
```   210   shows "vset_rel R xs ys \<longleftrightarrow> xs = ys \<and> (\<forall>x y. x \<in> xs \<longrightarrow> R x y \<longrightarrow> y \<in> xs)"
```
```   211   unfolding vset_rel_def
```
```   212   using equivp_reflp[OF e]
```
```   213   by auto (metis, metis equivp_symp[OF e])
```
```   214
```
```   215 lemma set_quotient [quot_thm]:
```
```   216   assumes "Quotient3 R Abs Rep"
```
```   217   shows "Quotient3 (vset_rel R) (vimage Rep) (vimage Abs)"
```
```   218 proof (rule Quotient3I)
```
```   219   from assms have "\<And>x. Abs (Rep x) = x" by (rule Quotient3_abs_rep)
```
```   220   then show "\<And>xs. Rep -` (Abs -` xs) = xs"
```
```   221     unfolding vimage_def by auto
```
```   222 next
```
```   223   show "\<And>xs. vset_rel R (Abs -` xs) (Abs -` xs)"
```
```   224     unfolding vset_rel_def vimage_def
```
```   225     by auto (metis Quotient3_rel_abs[OF assms])+
```
```   226 next
```
```   227   fix r s
```
```   228   show "vset_rel R r s = (vset_rel R r r \<and> vset_rel R s s \<and> Rep -` r = Rep -` s)"
```
```   229     unfolding vset_rel_def vimage_def set_eq_iff
```
```   230     by auto (metis rep_abs_rsp[OF assms] assms[simplified Quotient3_def])+
```
```   231 qed
```
```   232
```
```   233 declare [[mapQ3 set = (vset_rel, set_quotient)]]
```
```   234
```
```   235 lemma empty_set_rsp[quot_respect]:
```
```   236   "vset_rel R {} {}"
```
```   237   unfolding vset_rel_def by simp
```
```   238
```
```   239 lemma collect_rsp[quot_respect]:
```
```   240   assumes "Quotient3 R Abs Rep"
```
```   241   shows "((R ===> op =) ===> vset_rel R) Collect Collect"
```
```   242   by (intro fun_relI) (simp add: fun_rel_def vset_rel_def)
```
```   243
```
```   244 lemma collect_prs[quot_preserve]:
```
```   245   assumes "Quotient3 R Abs Rep"
```
```   246   shows "((Abs ---> id) ---> op -` Rep) Collect = Collect"
```
```   247   unfolding fun_eq_iff
```
```   248   by (simp add: Quotient3_abs_rep[OF assms])
```
```   249
```
```   250 lemma union_rsp[quot_respect]:
```
```   251   assumes "Quotient3 R Abs Rep"
```
```   252   shows "(vset_rel R ===> vset_rel R ===> vset_rel R) op \<union> op \<union>"
```
```   253   by (intro fun_relI) (simp add: vset_rel_def)
```
```   254
```
```   255 lemma union_prs[quot_preserve]:
```
```   256   assumes "Quotient3 R Abs Rep"
```
```   257   shows "(op -` Abs ---> op -` Abs ---> op -` Rep) op \<union> = op \<union>"
```
```   258   unfolding fun_eq_iff
```
```   259   by (simp add: Quotient3_abs_rep[OF set_quotient[OF assms]])
```
```   260
```
```   261 lemma diff_rsp[quot_respect]:
```
```   262   assumes "Quotient3 R Abs Rep"
```
```   263   shows "(vset_rel R ===> vset_rel R ===> vset_rel R) op - op -"
```
```   264   by (intro fun_relI) (simp add: vset_rel_def)
```
```   265
```
```   266 lemma diff_prs[quot_preserve]:
```
```   267   assumes "Quotient3 R Abs Rep"
```
```   268   shows "(op -` Abs ---> op -` Abs ---> op -` Rep) op - = op -"
```
```   269   unfolding fun_eq_iff
```
```   270   by (simp add: Quotient3_abs_rep[OF set_quotient[OF assms]] vimage_Diff)
```
```   271
```
```   272 lemma inter_rsp[quot_respect]:
```
```   273   assumes "Quotient3 R Abs Rep"
```
```   274   shows "(vset_rel R ===> vset_rel R ===> vset_rel R) op \<inter> op \<inter>"
```
```   275   by (intro fun_relI) (auto simp add: vset_rel_def)
```
```   276
```
```   277 lemma inter_prs[quot_preserve]:
```
```   278   assumes "Quotient3 R Abs Rep"
```
```   279   shows "(op -` Abs ---> op -` Abs ---> op -` Rep) op \<inter> = op \<inter>"
```
```   280   unfolding fun_eq_iff
```
```   281   by (simp add: Quotient3_abs_rep[OF set_quotient[OF assms]])
```
```   282
```
```   283 lemma mem_prs[quot_preserve]:
```
```   284   assumes "Quotient3 R Abs Rep"
```
```   285   shows "(Rep ---> op -` Abs ---> id) op \<in> = op \<in>"
```
```   286   by (simp add: fun_eq_iff Quotient3_abs_rep[OF assms])
```
```   287
```
```   288 lemma mem_rsp[quot_respect]:
```
```   289   shows "(R ===> vset_rel R ===> op =) op \<in> op \<in>"
```
```   290   by (intro fun_relI) (simp add: vset_rel_def)
```
```   291
```
```   292 end
```