src/ZF/Constructible/Separation.thy
author wenzelm
Tue Nov 07 19:40:13 2006 +0100 (2006-11-07)
changeset 21233 5a5c8ea5f66a
parent 19931 fb32b43e7f80
child 29223 e09c53289830
permissions -rw-r--r--
tuned specifications;
     1 (*  Title:      ZF/Constructible/Separation.thy
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4 *)
     5 
     6 header{*Early Instances of Separation and Strong Replacement*}
     7 
     8 theory Separation imports L_axioms WF_absolute begin
     9 
    10 text{*This theory proves all instances needed for locale @{text "M_basic"}*}
    11 
    12 text{*Helps us solve for de Bruijn indices!*}
    13 lemma nth_ConsI: "[|nth(n,l) = x; n \<in> nat|] ==> nth(succ(n), Cons(a,l)) = x"
    14 by simp
    15 
    16 lemmas nth_rules = nth_0 nth_ConsI nat_0I nat_succI
    17 lemmas sep_rules = nth_0 nth_ConsI FOL_iff_sats function_iff_sats
    18                    fun_plus_iff_sats
    19 
    20 lemma Collect_conj_in_DPow:
    21      "[| {x\<in>A. P(x)} \<in> DPow(A);  {x\<in>A. Q(x)} \<in> DPow(A) |]
    22       ==> {x\<in>A. P(x) & Q(x)} \<in> DPow(A)"
    23 by (simp add: Int_in_DPow Collect_Int_Collect_eq [symmetric])
    24 
    25 lemma Collect_conj_in_DPow_Lset:
    26      "[|z \<in> Lset(j); {x \<in> Lset(j). P(x)} \<in> DPow(Lset(j))|]
    27       ==> {x \<in> Lset(j). x \<in> z & P(x)} \<in> DPow(Lset(j))"
    28 apply (frule mem_Lset_imp_subset_Lset)
    29 apply (simp add: Collect_conj_in_DPow Collect_mem_eq
    30                  subset_Int_iff2 elem_subset_in_DPow)
    31 done
    32 
    33 lemma separation_CollectI:
    34      "(\<And>z. L(z) ==> L({x \<in> z . P(x)})) ==> separation(L, \<lambda>x. P(x))"
    35 apply (unfold separation_def, clarify)
    36 apply (rule_tac x="{x\<in>z. P(x)}" in rexI)
    37 apply simp_all
    38 done
    39 
    40 text{*Reduces the original comprehension to the reflected one*}
    41 lemma reflection_imp_L_separation:
    42       "[| \<forall>x\<in>Lset(j). P(x) <-> Q(x);
    43           {x \<in> Lset(j) . Q(x)} \<in> DPow(Lset(j));
    44           Ord(j);  z \<in> Lset(j)|] ==> L({x \<in> z . P(x)})"
    45 apply (rule_tac i = "succ(j)" in L_I)
    46  prefer 2 apply simp
    47 apply (subgoal_tac "{x \<in> z. P(x)} = {x \<in> Lset(j). x \<in> z & (Q(x))}")
    48  prefer 2
    49  apply (blast dest: mem_Lset_imp_subset_Lset)
    50 apply (simp add: Lset_succ Collect_conj_in_DPow_Lset)
    51 done
    52 
    53 text{*Encapsulates the standard proof script for proving instances of 
    54       Separation.*}
    55 lemma gen_separation:
    56  assumes reflection: "REFLECTS [P,Q]"
    57      and Lu:         "L(u)"
    58      and collI: "!!j. u \<in> Lset(j)
    59                 \<Longrightarrow> Collect(Lset(j), Q(j)) \<in> DPow(Lset(j))"
    60  shows "separation(L,P)"
    61 apply (rule separation_CollectI)
    62 apply (rule_tac A="{u,z}" in subset_LsetE, blast intro: Lu)
    63 apply (rule ReflectsE [OF reflection], assumption)
    64 apply (drule subset_Lset_ltD, assumption)
    65 apply (erule reflection_imp_L_separation)
    66   apply (simp_all add: lt_Ord2, clarify)
    67 apply (rule collI, assumption)
    68 done
    69 
    70 text{*As above, but typically @{term u} is a finite enumeration such as
    71   @{term "{a,b}"}; thus the new subgoal gets the assumption
    72   @{term "{a,b} \<subseteq> Lset(i)"}, which is logically equivalent to 
    73   @{term "a \<in> Lset(i)"} and @{term "b \<in> Lset(i)"}.*}
    74 lemma gen_separation_multi:
    75  assumes reflection: "REFLECTS [P,Q]"
    76      and Lu:         "L(u)"
    77      and collI: "!!j. u \<subseteq> Lset(j)
    78                 \<Longrightarrow> Collect(Lset(j), Q(j)) \<in> DPow(Lset(j))"
    79  shows "separation(L,P)"
    80 apply (rule gen_separation [OF reflection Lu])
    81 apply (drule mem_Lset_imp_subset_Lset)
    82 apply (erule collI) 
    83 done
    84 
    85 
    86 subsection{*Separation for Intersection*}
    87 
    88 lemma Inter_Reflects:
    89      "REFLECTS[\<lambda>x. \<forall>y[L]. y\<in>A --> x \<in> y,
    90                \<lambda>i x. \<forall>y\<in>Lset(i). y\<in>A --> x \<in> y]"
    91 by (intro FOL_reflections)
    92 
    93 lemma Inter_separation:
    94      "L(A) ==> separation(L, \<lambda>x. \<forall>y[L]. y\<in>A --> x\<in>y)"
    95 apply (rule gen_separation [OF Inter_Reflects], simp)
    96 apply (rule DPow_LsetI)
    97  txt{*I leave this one example of a manual proof.  The tedium of manually
    98       instantiating @{term i}, @{term j} and @{term env} is obvious. *}
    99 apply (rule ball_iff_sats)
   100 apply (rule imp_iff_sats)
   101 apply (rule_tac [2] i=1 and j=0 and env="[y,x,A]" in mem_iff_sats)
   102 apply (rule_tac i=0 and j=2 in mem_iff_sats)
   103 apply (simp_all add: succ_Un_distrib [symmetric])
   104 done
   105 
   106 subsection{*Separation for Set Difference*}
   107 
   108 lemma Diff_Reflects:
   109      "REFLECTS[\<lambda>x. x \<notin> B, \<lambda>i x. x \<notin> B]"
   110 by (intro FOL_reflections)  
   111 
   112 lemma Diff_separation:
   113      "L(B) ==> separation(L, \<lambda>x. x \<notin> B)"
   114 apply (rule gen_separation [OF Diff_Reflects], simp)
   115 apply (rule_tac env="[B]" in DPow_LsetI)
   116 apply (rule sep_rules | simp)+
   117 done
   118 
   119 subsection{*Separation for Cartesian Product*}
   120 
   121 lemma cartprod_Reflects:
   122      "REFLECTS[\<lambda>z. \<exists>x[L]. x\<in>A & (\<exists>y[L]. y\<in>B & pair(L,x,y,z)),
   123                 \<lambda>i z. \<exists>x\<in>Lset(i). x\<in>A & (\<exists>y\<in>Lset(i). y\<in>B &
   124                                    pair(##Lset(i),x,y,z))]"
   125 by (intro FOL_reflections function_reflections)
   126 
   127 lemma cartprod_separation:
   128      "[| L(A); L(B) |]
   129       ==> separation(L, \<lambda>z. \<exists>x[L]. x\<in>A & (\<exists>y[L]. y\<in>B & pair(L,x,y,z)))"
   130 apply (rule gen_separation_multi [OF cartprod_Reflects, of "{A,B}"], auto)
   131 apply (rule_tac env="[A,B]" in DPow_LsetI)
   132 apply (rule sep_rules | simp)+
   133 done
   134 
   135 subsection{*Separation for Image*}
   136 
   137 lemma image_Reflects:
   138      "REFLECTS[\<lambda>y. \<exists>p[L]. p\<in>r & (\<exists>x[L]. x\<in>A & pair(L,x,y,p)),
   139            \<lambda>i y. \<exists>p\<in>Lset(i). p\<in>r & (\<exists>x\<in>Lset(i). x\<in>A & pair(##Lset(i),x,y,p))]"
   140 by (intro FOL_reflections function_reflections)
   141 
   142 lemma image_separation:
   143      "[| L(A); L(r) |]
   144       ==> separation(L, \<lambda>y. \<exists>p[L]. p\<in>r & (\<exists>x[L]. x\<in>A & pair(L,x,y,p)))"
   145 apply (rule gen_separation_multi [OF image_Reflects, of "{A,r}"], auto)
   146 apply (rule_tac env="[A,r]" in DPow_LsetI)
   147 apply (rule sep_rules | simp)+
   148 done
   149 
   150 
   151 subsection{*Separation for Converse*}
   152 
   153 lemma converse_Reflects:
   154   "REFLECTS[\<lambda>z. \<exists>p[L]. p\<in>r & (\<exists>x[L]. \<exists>y[L]. pair(L,x,y,p) & pair(L,y,x,z)),
   155      \<lambda>i z. \<exists>p\<in>Lset(i). p\<in>r & (\<exists>x\<in>Lset(i). \<exists>y\<in>Lset(i).
   156                      pair(##Lset(i),x,y,p) & pair(##Lset(i),y,x,z))]"
   157 by (intro FOL_reflections function_reflections)
   158 
   159 lemma converse_separation:
   160      "L(r) ==> separation(L,
   161          \<lambda>z. \<exists>p[L]. p\<in>r & (\<exists>x[L]. \<exists>y[L]. pair(L,x,y,p) & pair(L,y,x,z)))"
   162 apply (rule gen_separation [OF converse_Reflects], simp)
   163 apply (rule_tac env="[r]" in DPow_LsetI)
   164 apply (rule sep_rules | simp)+
   165 done
   166 
   167 
   168 subsection{*Separation for Restriction*}
   169 
   170 lemma restrict_Reflects:
   171      "REFLECTS[\<lambda>z. \<exists>x[L]. x\<in>A & (\<exists>y[L]. pair(L,x,y,z)),
   172         \<lambda>i z. \<exists>x\<in>Lset(i). x\<in>A & (\<exists>y\<in>Lset(i). pair(##Lset(i),x,y,z))]"
   173 by (intro FOL_reflections function_reflections)
   174 
   175 lemma restrict_separation:
   176    "L(A) ==> separation(L, \<lambda>z. \<exists>x[L]. x\<in>A & (\<exists>y[L]. pair(L,x,y,z)))"
   177 apply (rule gen_separation [OF restrict_Reflects], simp)
   178 apply (rule_tac env="[A]" in DPow_LsetI)
   179 apply (rule sep_rules | simp)+
   180 done
   181 
   182 
   183 subsection{*Separation for Composition*}
   184 
   185 lemma comp_Reflects:
   186      "REFLECTS[\<lambda>xz. \<exists>x[L]. \<exists>y[L]. \<exists>z[L]. \<exists>xy[L]. \<exists>yz[L].
   187                   pair(L,x,z,xz) & pair(L,x,y,xy) & pair(L,y,z,yz) &
   188                   xy\<in>s & yz\<in>r,
   189         \<lambda>i xz. \<exists>x\<in>Lset(i). \<exists>y\<in>Lset(i). \<exists>z\<in>Lset(i). \<exists>xy\<in>Lset(i). \<exists>yz\<in>Lset(i).
   190                   pair(##Lset(i),x,z,xz) & pair(##Lset(i),x,y,xy) &
   191                   pair(##Lset(i),y,z,yz) & xy\<in>s & yz\<in>r]"
   192 by (intro FOL_reflections function_reflections)
   193 
   194 lemma comp_separation:
   195      "[| L(r); L(s) |]
   196       ==> separation(L, \<lambda>xz. \<exists>x[L]. \<exists>y[L]. \<exists>z[L]. \<exists>xy[L]. \<exists>yz[L].
   197                   pair(L,x,z,xz) & pair(L,x,y,xy) & pair(L,y,z,yz) &
   198                   xy\<in>s & yz\<in>r)"
   199 apply (rule gen_separation_multi [OF comp_Reflects, of "{r,s}"], auto)
   200 txt{*Subgoals after applying general ``separation'' rule:
   201      @{subgoals[display,indent=0,margin=65]}*}
   202 apply (rule_tac env="[r,s]" in DPow_LsetI)
   203 txt{*Subgoals ready for automatic synthesis of a formula:
   204      @{subgoals[display,indent=0,margin=65]}*}
   205 apply (rule sep_rules | simp)+
   206 done
   207 
   208 
   209 subsection{*Separation for Predecessors in an Order*}
   210 
   211 lemma pred_Reflects:
   212      "REFLECTS[\<lambda>y. \<exists>p[L]. p\<in>r & pair(L,y,x,p),
   213                     \<lambda>i y. \<exists>p \<in> Lset(i). p\<in>r & pair(##Lset(i),y,x,p)]"
   214 by (intro FOL_reflections function_reflections)
   215 
   216 lemma pred_separation:
   217      "[| L(r); L(x) |] ==> separation(L, \<lambda>y. \<exists>p[L]. p\<in>r & pair(L,y,x,p))"
   218 apply (rule gen_separation_multi [OF pred_Reflects, of "{r,x}"], auto)
   219 apply (rule_tac env="[r,x]" in DPow_LsetI)
   220 apply (rule sep_rules | simp)+
   221 done
   222 
   223 
   224 subsection{*Separation for the Membership Relation*}
   225 
   226 lemma Memrel_Reflects:
   227      "REFLECTS[\<lambda>z. \<exists>x[L]. \<exists>y[L]. pair(L,x,y,z) & x \<in> y,
   228             \<lambda>i z. \<exists>x \<in> Lset(i). \<exists>y \<in> Lset(i). pair(##Lset(i),x,y,z) & x \<in> y]"
   229 by (intro FOL_reflections function_reflections)
   230 
   231 lemma Memrel_separation:
   232      "separation(L, \<lambda>z. \<exists>x[L]. \<exists>y[L]. pair(L,x,y,z) & x \<in> y)"
   233 apply (rule gen_separation [OF Memrel_Reflects nonempty])
   234 apply (rule_tac env="[]" in DPow_LsetI)
   235 apply (rule sep_rules | simp)+
   236 done
   237 
   238 
   239 subsection{*Replacement for FunSpace*}
   240 
   241 lemma funspace_succ_Reflects:
   242  "REFLECTS[\<lambda>z. \<exists>p[L]. p\<in>A & (\<exists>f[L]. \<exists>b[L]. \<exists>nb[L]. \<exists>cnbf[L].
   243             pair(L,f,b,p) & pair(L,n,b,nb) & is_cons(L,nb,f,cnbf) &
   244             upair(L,cnbf,cnbf,z)),
   245         \<lambda>i z. \<exists>p \<in> Lset(i). p\<in>A & (\<exists>f \<in> Lset(i). \<exists>b \<in> Lset(i).
   246               \<exists>nb \<in> Lset(i). \<exists>cnbf \<in> Lset(i).
   247                 pair(##Lset(i),f,b,p) & pair(##Lset(i),n,b,nb) &
   248                 is_cons(##Lset(i),nb,f,cnbf) & upair(##Lset(i),cnbf,cnbf,z))]"
   249 by (intro FOL_reflections function_reflections)
   250 
   251 lemma funspace_succ_replacement:
   252      "L(n) ==>
   253       strong_replacement(L, \<lambda>p z. \<exists>f[L]. \<exists>b[L]. \<exists>nb[L]. \<exists>cnbf[L].
   254                 pair(L,f,b,p) & pair(L,n,b,nb) & is_cons(L,nb,f,cnbf) &
   255                 upair(L,cnbf,cnbf,z))"
   256 apply (rule strong_replacementI)
   257 apply (rule_tac u="{n,B}" in gen_separation_multi [OF funspace_succ_Reflects], 
   258        auto)
   259 apply (rule_tac env="[n,B]" in DPow_LsetI)
   260 apply (rule sep_rules | simp)+
   261 done
   262 
   263 
   264 subsection{*Separation for a Theorem about @{term "is_recfun"}*}
   265 
   266 lemma is_recfun_reflects:
   267   "REFLECTS[\<lambda>x. \<exists>xa[L]. \<exists>xb[L].
   268                 pair(L,x,a,xa) & xa \<in> r & pair(L,x,b,xb) & xb \<in> r &
   269                 (\<exists>fx[L]. \<exists>gx[L]. fun_apply(L,f,x,fx) & fun_apply(L,g,x,gx) &
   270                                    fx \<noteq> gx),
   271    \<lambda>i x. \<exists>xa \<in> Lset(i). \<exists>xb \<in> Lset(i).
   272           pair(##Lset(i),x,a,xa) & xa \<in> r & pair(##Lset(i),x,b,xb) & xb \<in> r &
   273                 (\<exists>fx \<in> Lset(i). \<exists>gx \<in> Lset(i). fun_apply(##Lset(i),f,x,fx) &
   274                   fun_apply(##Lset(i),g,x,gx) & fx \<noteq> gx)]"
   275 by (intro FOL_reflections function_reflections fun_plus_reflections)
   276 
   277 lemma is_recfun_separation:
   278      --{*for well-founded recursion*}
   279      "[| L(r); L(f); L(g); L(a); L(b) |]
   280      ==> separation(L,
   281             \<lambda>x. \<exists>xa[L]. \<exists>xb[L].
   282                 pair(L,x,a,xa) & xa \<in> r & pair(L,x,b,xb) & xb \<in> r &
   283                 (\<exists>fx[L]. \<exists>gx[L]. fun_apply(L,f,x,fx) & fun_apply(L,g,x,gx) &
   284                                    fx \<noteq> gx))"
   285 apply (rule gen_separation_multi [OF is_recfun_reflects, of "{r,f,g,a,b}"], 
   286             auto)
   287 apply (rule_tac env="[r,f,g,a,b]" in DPow_LsetI)
   288 apply (rule sep_rules | simp)+
   289 done
   290 
   291 
   292 subsection{*Instantiating the locale @{text M_basic}*}
   293 text{*Separation (and Strong Replacement) for basic set-theoretic constructions
   294 such as intersection, Cartesian Product and image.*}
   295 
   296 lemma M_basic_axioms_L: "M_basic_axioms(L)"
   297   apply (rule M_basic_axioms.intro)
   298        apply (assumption | rule
   299 	 Inter_separation Diff_separation cartprod_separation image_separation
   300 	 converse_separation restrict_separation
   301 	 comp_separation pred_separation Memrel_separation
   302 	 funspace_succ_replacement is_recfun_separation)+
   303   done
   304 
   305 theorem M_basic_L: "PROP M_basic(L)"
   306 by (rule M_basic.intro [OF M_trivial_L M_basic_axioms_L])
   307 
   308 interpretation M_basic [L] by (rule M_basic_L)
   309 
   310 
   311 end