src/HOL/Lifting_Set.thy
 author wenzelm Mon Apr 25 16:09:26 2016 +0200 (2016-04-25) changeset 63040 eb4ddd18d635 parent 62343 24106dc44def child 63343 fb5d8a50c641 permissions -rw-r--r--
eliminated old 'def';
```     1 (*  Title:      HOL/Lifting_Set.thy
```
```     2     Author:     Brian Huffman and Ondrej Kuncar
```
```     3 *)
```
```     4
```
```     5 section \<open>Setup for Lifting/Transfer for the set type\<close>
```
```     6
```
```     7 theory Lifting_Set
```
```     8 imports Lifting
```
```     9 begin
```
```    10
```
```    11 subsection \<open>Relator and predicator properties\<close>
```
```    12
```
```    13 lemma rel_setD1: "\<lbrakk> rel_set R A B; x \<in> A \<rbrakk> \<Longrightarrow> \<exists>y \<in> B. R x y"
```
```    14   and rel_setD2: "\<lbrakk> rel_set R A B; y \<in> B \<rbrakk> \<Longrightarrow> \<exists>x \<in> A. R x y"
```
```    15   by (simp_all add: rel_set_def)
```
```    16
```
```    17 lemma rel_set_conversep [simp]: "rel_set A\<inverse>\<inverse> = (rel_set A)\<inverse>\<inverse>"
```
```    18   unfolding rel_set_def by auto
```
```    19
```
```    20 lemma rel_set_eq [relator_eq]: "rel_set (op =) = (op =)"
```
```    21   unfolding rel_set_def fun_eq_iff by auto
```
```    22
```
```    23 lemma rel_set_mono[relator_mono]:
```
```    24   assumes "A \<le> B"
```
```    25   shows "rel_set A \<le> rel_set B"
```
```    26   using assms unfolding rel_set_def by blast
```
```    27
```
```    28 lemma rel_set_OO[relator_distr]: "rel_set R OO rel_set S = rel_set (R OO S)"
```
```    29   apply (rule sym)
```
```    30   apply (intro ext)
```
```    31   subgoal for X Z
```
```    32     apply (rule iffI)
```
```    33     apply (rule relcomppI [where b="{y. (\<exists>x\<in>X. R x y) \<and> (\<exists>z\<in>Z. S y z)}"])
```
```    34     apply (simp add: rel_set_def, fast)+
```
```    35     done
```
```    36   done
```
```    37
```
```    38 lemma Domainp_set[relator_domain]:
```
```    39   "Domainp (rel_set T) = (\<lambda>A. Ball A (Domainp T))"
```
```    40   unfolding rel_set_def Domainp_iff[abs_def]
```
```    41   apply (intro ext)
```
```    42   apply (rule iffI)
```
```    43   apply blast
```
```    44   subgoal for A by (rule exI [where x="{y. \<exists>x\<in>A. T x y}"]) fast
```
```    45   done
```
```    46
```
```    47 lemma left_total_rel_set[transfer_rule]:
```
```    48   "left_total A \<Longrightarrow> left_total (rel_set A)"
```
```    49   unfolding left_total_def rel_set_def
```
```    50   apply safe
```
```    51   subgoal for X by (rule exI [where x="{y. \<exists>x\<in>X. A x y}"]) fast
```
```    52   done
```
```    53
```
```    54 lemma left_unique_rel_set[transfer_rule]:
```
```    55   "left_unique A \<Longrightarrow> left_unique (rel_set A)"
```
```    56   unfolding left_unique_def rel_set_def
```
```    57   by fast
```
```    58
```
```    59 lemma right_total_rel_set [transfer_rule]:
```
```    60   "right_total A \<Longrightarrow> right_total (rel_set A)"
```
```    61   using left_total_rel_set[of "A\<inverse>\<inverse>"] by simp
```
```    62
```
```    63 lemma right_unique_rel_set [transfer_rule]:
```
```    64   "right_unique A \<Longrightarrow> right_unique (rel_set A)"
```
```    65   unfolding right_unique_def rel_set_def by fast
```
```    66
```
```    67 lemma bi_total_rel_set [transfer_rule]:
```
```    68   "bi_total A \<Longrightarrow> bi_total (rel_set A)"
```
```    69   by(simp add: bi_total_alt_def left_total_rel_set right_total_rel_set)
```
```    70
```
```    71 lemma bi_unique_rel_set [transfer_rule]:
```
```    72   "bi_unique A \<Longrightarrow> bi_unique (rel_set A)"
```
```    73   unfolding bi_unique_def rel_set_def by fast
```
```    74
```
```    75 lemma set_relator_eq_onp [relator_eq_onp]:
```
```    76   "rel_set (eq_onp P) = eq_onp (\<lambda>A. Ball A P)"
```
```    77   unfolding fun_eq_iff rel_set_def eq_onp_def Ball_def by fast
```
```    78
```
```    79 lemma bi_unique_rel_set_lemma:
```
```    80   assumes "bi_unique R" and "rel_set R X Y"
```
```    81   obtains f where "Y = image f X" and "inj_on f X" and "\<forall>x\<in>X. R x (f x)"
```
```    82 proof
```
```    83   define f where "f x = (THE y. R x y)" for x
```
```    84   { fix x assume "x \<in> X"
```
```    85     with \<open>rel_set R X Y\<close> \<open>bi_unique R\<close> have "R x (f x)"
```
```    86       by (simp add: bi_unique_def rel_set_def f_def) (metis theI)
```
```    87     with assms \<open>x \<in> X\<close>
```
```    88     have  "R x (f x)" "\<forall>x'\<in>X. R x' (f x) \<longrightarrow> x = x'" "\<forall>y\<in>Y. R x y \<longrightarrow> y = f x" "f x \<in> Y"
```
```    89       by (fastforce simp add: bi_unique_def rel_set_def)+ }
```
```    90   note * = this
```
```    91   moreover
```
```    92   { fix y assume "y \<in> Y"
```
```    93     with \<open>rel_set R X Y\<close> *(3) \<open>y \<in> Y\<close> have "\<exists>x\<in>X. y = f x"
```
```    94       by (fastforce simp: rel_set_def) }
```
```    95   ultimately show "\<forall>x\<in>X. R x (f x)" "Y = image f X" "inj_on f X"
```
```    96     by (auto simp: inj_on_def image_iff)
```
```    97 qed
```
```    98
```
```    99 subsection \<open>Quotient theorem for the Lifting package\<close>
```
```   100
```
```   101 lemma Quotient_set[quot_map]:
```
```   102   assumes "Quotient R Abs Rep T"
```
```   103   shows "Quotient (rel_set R) (image Abs) (image Rep) (rel_set T)"
```
```   104   using assms unfolding Quotient_alt_def4
```
```   105   apply (simp add: rel_set_OO[symmetric])
```
```   106   apply (simp add: rel_set_def)
```
```   107   apply fast
```
```   108   done
```
```   109
```
```   110
```
```   111 subsection \<open>Transfer rules for the Transfer package\<close>
```
```   112
```
```   113 subsubsection \<open>Unconditional transfer rules\<close>
```
```   114
```
```   115 context
```
```   116 begin
```
```   117
```
```   118 interpretation lifting_syntax .
```
```   119
```
```   120 lemma empty_transfer [transfer_rule]: "(rel_set A) {} {}"
```
```   121   unfolding rel_set_def by simp
```
```   122
```
```   123 lemma insert_transfer [transfer_rule]:
```
```   124   "(A ===> rel_set A ===> rel_set A) insert insert"
```
```   125   unfolding rel_fun_def rel_set_def by auto
```
```   126
```
```   127 lemma union_transfer [transfer_rule]:
```
```   128   "(rel_set A ===> rel_set A ===> rel_set A) union union"
```
```   129   unfolding rel_fun_def rel_set_def by auto
```
```   130
```
```   131 lemma Union_transfer [transfer_rule]:
```
```   132   "(rel_set (rel_set A) ===> rel_set A) Union Union"
```
```   133   unfolding rel_fun_def rel_set_def by simp fast
```
```   134
```
```   135 lemma image_transfer [transfer_rule]:
```
```   136   "((A ===> B) ===> rel_set A ===> rel_set B) image image"
```
```   137   unfolding rel_fun_def rel_set_def by simp fast
```
```   138
```
```   139 lemma UNION_transfer [transfer_rule]:
```
```   140   "(rel_set A ===> (A ===> rel_set B) ===> rel_set B) UNION UNION"
```
```   141   by transfer_prover
```
```   142
```
```   143 lemma Ball_transfer [transfer_rule]:
```
```   144   "(rel_set A ===> (A ===> op =) ===> op =) Ball Ball"
```
```   145   unfolding rel_set_def rel_fun_def by fast
```
```   146
```
```   147 lemma Bex_transfer [transfer_rule]:
```
```   148   "(rel_set A ===> (A ===> op =) ===> op =) Bex Bex"
```
```   149   unfolding rel_set_def rel_fun_def by fast
```
```   150
```
```   151 lemma Pow_transfer [transfer_rule]:
```
```   152   "(rel_set A ===> rel_set (rel_set A)) Pow Pow"
```
```   153   apply (rule rel_funI)
```
```   154   apply (rule rel_setI)
```
```   155   subgoal for X Y X'
```
```   156     apply (rule rev_bexI [where x="{y\<in>Y. \<exists>x\<in>X'. A x y}"])
```
```   157     apply clarsimp
```
```   158     apply (simp add: rel_set_def)
```
```   159     apply fast
```
```   160     done
```
```   161   subgoal for X Y Y'
```
```   162     apply (rule rev_bexI [where x="{x\<in>X. \<exists>y\<in>Y'. A x y}"])
```
```   163     apply clarsimp
```
```   164     apply (simp add: rel_set_def)
```
```   165     apply fast
```
```   166     done
```
```   167   done
```
```   168
```
```   169 lemma rel_set_transfer [transfer_rule]:
```
```   170   "((A ===> B ===> op =) ===> rel_set A ===> rel_set B ===> op =) rel_set rel_set"
```
```   171   unfolding rel_fun_def rel_set_def by fast
```
```   172
```
```   173 lemma bind_transfer [transfer_rule]:
```
```   174   "(rel_set A ===> (A ===> rel_set B) ===> rel_set B) Set.bind Set.bind"
```
```   175   unfolding bind_UNION [abs_def] by transfer_prover
```
```   176
```
```   177 lemma INF_parametric [transfer_rule]:
```
```   178   "(rel_set A ===> (A ===> HOL.eq) ===> HOL.eq) INFIMUM INFIMUM"
```
```   179   by transfer_prover
```
```   180
```
```   181 lemma SUP_parametric [transfer_rule]:
```
```   182   "(rel_set R ===> (R ===> HOL.eq) ===> HOL.eq) SUPREMUM SUPREMUM"
```
```   183   by transfer_prover
```
```   184
```
```   185
```
```   186 subsubsection \<open>Rules requiring bi-unique, bi-total or right-total relations\<close>
```
```   187
```
```   188 lemma member_transfer [transfer_rule]:
```
```   189   assumes "bi_unique A"
```
```   190   shows "(A ===> rel_set A ===> op =) (op \<in>) (op \<in>)"
```
```   191   using assms unfolding rel_fun_def rel_set_def bi_unique_def by fast
```
```   192
```
```   193 lemma right_total_Collect_transfer[transfer_rule]:
```
```   194   assumes "right_total A"
```
```   195   shows "((A ===> op =) ===> rel_set A) (\<lambda>P. Collect (\<lambda>x. P x \<and> Domainp A x)) Collect"
```
```   196   using assms unfolding right_total_def rel_set_def rel_fun_def Domainp_iff by fast
```
```   197
```
```   198 lemma Collect_transfer [transfer_rule]:
```
```   199   assumes "bi_total A"
```
```   200   shows "((A ===> op =) ===> rel_set A) Collect Collect"
```
```   201   using assms unfolding rel_fun_def rel_set_def bi_total_def by fast
```
```   202
```
```   203 lemma inter_transfer [transfer_rule]:
```
```   204   assumes "bi_unique A"
```
```   205   shows "(rel_set A ===> rel_set A ===> rel_set A) inter inter"
```
```   206   using assms unfolding rel_fun_def rel_set_def bi_unique_def by fast
```
```   207
```
```   208 lemma Diff_transfer [transfer_rule]:
```
```   209   assumes "bi_unique A"
```
```   210   shows "(rel_set A ===> rel_set A ===> rel_set A) (op -) (op -)"
```
```   211   using assms unfolding rel_fun_def rel_set_def bi_unique_def
```
```   212   unfolding Ball_def Bex_def Diff_eq
```
```   213   by (safe, simp, metis, simp, metis)
```
```   214
```
```   215 lemma subset_transfer [transfer_rule]:
```
```   216   assumes [transfer_rule]: "bi_unique A"
```
```   217   shows "(rel_set A ===> rel_set A ===> op =) (op \<subseteq>) (op \<subseteq>)"
```
```   218   unfolding subset_eq [abs_def] by transfer_prover
```
```   219
```
```   220 declare right_total_UNIV_transfer[transfer_rule]
```
```   221
```
```   222 lemma UNIV_transfer [transfer_rule]:
```
```   223   assumes "bi_total A"
```
```   224   shows "(rel_set A) UNIV UNIV"
```
```   225   using assms unfolding rel_set_def bi_total_def by simp
```
```   226
```
```   227 lemma right_total_Compl_transfer [transfer_rule]:
```
```   228   assumes [transfer_rule]: "bi_unique A" and [transfer_rule]: "right_total A"
```
```   229   shows "(rel_set A ===> rel_set A) (\<lambda>S. uminus S \<inter> Collect (Domainp A)) uminus"
```
```   230   unfolding Compl_eq [abs_def]
```
```   231   by (subst Collect_conj_eq[symmetric]) transfer_prover
```
```   232
```
```   233 lemma Compl_transfer [transfer_rule]:
```
```   234   assumes [transfer_rule]: "bi_unique A" and [transfer_rule]: "bi_total A"
```
```   235   shows "(rel_set A ===> rel_set A) uminus uminus"
```
```   236   unfolding Compl_eq [abs_def] by transfer_prover
```
```   237
```
```   238 lemma right_total_Inter_transfer [transfer_rule]:
```
```   239   assumes [transfer_rule]: "bi_unique A" and [transfer_rule]: "right_total A"
```
```   240   shows "(rel_set (rel_set A) ===> rel_set A) (\<lambda>S. \<Inter>S \<inter> Collect (Domainp A)) Inter"
```
```   241   unfolding Inter_eq[abs_def]
```
```   242   by (subst Collect_conj_eq[symmetric]) transfer_prover
```
```   243
```
```   244 lemma Inter_transfer [transfer_rule]:
```
```   245   assumes [transfer_rule]: "bi_unique A" and [transfer_rule]: "bi_total A"
```
```   246   shows "(rel_set (rel_set A) ===> rel_set A) Inter Inter"
```
```   247   unfolding Inter_eq [abs_def] by transfer_prover
```
```   248
```
```   249 lemma filter_transfer [transfer_rule]:
```
```   250   assumes [transfer_rule]: "bi_unique A"
```
```   251   shows "((A ===> op=) ===> rel_set A ===> rel_set A) Set.filter Set.filter"
```
```   252   unfolding Set.filter_def[abs_def] rel_fun_def rel_set_def by blast
```
```   253
```
```   254 lemma finite_transfer [transfer_rule]:
```
```   255   "bi_unique A \<Longrightarrow> (rel_set A ===> op =) finite finite"
```
```   256   by (rule rel_funI, erule (1) bi_unique_rel_set_lemma)
```
```   257      (auto dest: finite_imageD)
```
```   258
```
```   259 lemma card_transfer [transfer_rule]:
```
```   260   "bi_unique A \<Longrightarrow> (rel_set A ===> op =) card card"
```
```   261   by (rule rel_funI, erule (1) bi_unique_rel_set_lemma)
```
```   262      (simp add: card_image)
```
```   263
```
```   264 lemma vimage_parametric [transfer_rule]:
```
```   265   assumes [transfer_rule]: "bi_total A" "bi_unique B"
```
```   266   shows "((A ===> B) ===> rel_set B ===> rel_set A) vimage vimage"
```
```   267   unfolding vimage_def[abs_def] by transfer_prover
```
```   268
```
```   269 lemma Image_parametric [transfer_rule]:
```
```   270   assumes "bi_unique A"
```
```   271   shows "(rel_set (rel_prod A B) ===> rel_set A ===> rel_set B) op `` op ``"
```
```   272   by (intro rel_funI rel_setI)
```
```   273     (force dest: rel_setD1 bi_uniqueDr[OF assms], force dest: rel_setD2 bi_uniqueDl[OF assms])
```
```   274
```
```   275 end
```
```   276
```
```   277 lemma (in comm_monoid_set) F_parametric [transfer_rule]:
```
```   278   fixes A :: "'b \<Rightarrow> 'c \<Rightarrow> bool"
```
```   279   assumes "bi_unique A"
```
```   280   shows "rel_fun (rel_fun A (op =)) (rel_fun (rel_set A) (op =)) F F"
```
```   281 proof (rule rel_funI)+
```
```   282   fix f :: "'b \<Rightarrow> 'a" and g S T
```
```   283   assume "rel_fun A (op =) f g" "rel_set A S T"
```
```   284   with \<open>bi_unique A\<close> obtain i where "bij_betw i S T" "\<And>x. x \<in> S \<Longrightarrow> f x = g (i x)"
```
```   285     by (auto elim: bi_unique_rel_set_lemma simp: rel_fun_def bij_betw_def)
```
```   286   then show "F f S = F g T"
```
```   287     by (simp add: reindex_bij_betw)
```
```   288 qed
```
```   289
```
```   290 lemmas setsum_parametric = setsum.F_parametric
```
```   291 lemmas setprod_parametric = setprod.F_parametric
```
```   292
```
```   293 lemma rel_set_UNION:
```
```   294   assumes [transfer_rule]: "rel_set Q A B" "rel_fun Q (rel_set R) f g"
```
```   295   shows "rel_set R (UNION A f) (UNION B g)"
```
```   296   by transfer_prover
```
```   297
```
```   298 end
```