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