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