src/ZF/Constructible/Rec_Separation.thy
author ballarin
Thu Dec 11 18:30:26 2008 +0100 (2008-12-11)
changeset 29223 e09c53289830
parent 21404 eb85850d3eb7
child 30729 461ee3e49ad3
permissions -rw-r--r--
Conversion of HOL-Main and ZF to new locales.
     1 (*  Title:      ZF/Constructible/Rec_Separation.thy
     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     3 *)
     4 
     5 header {*Separation for Facts About Recursion*}
     6 
     7 theory Rec_Separation imports Separation Internalize begin
     8 
     9 text{*This theory proves all instances needed for locales @{text
    10 "M_trancl"} and @{text "M_datatypes"}*}
    11 
    12 lemma eq_succ_imp_lt: "[|i = succ(j); Ord(i)|] ==> j<i"
    13 by simp
    14 
    15 
    16 subsection{*The Locale @{text "M_trancl"}*}
    17 
    18 subsubsection{*Separation for Reflexive/Transitive Closure*}
    19 
    20 text{*First, The Defining Formula*}
    21 
    22 (* "rtran_closure_mem(M,A,r,p) ==
    23       \<exists>nnat[M]. \<exists>n[M]. \<exists>n'[M].
    24        omega(M,nnat) & n\<in>nnat & successor(M,n,n') &
    25        (\<exists>f[M]. typed_function(M,n',A,f) &
    26         (\<exists>x[M]. \<exists>y[M]. \<exists>zero[M]. pair(M,x,y,p) & empty(M,zero) &
    27           fun_apply(M,f,zero,x) & fun_apply(M,f,n,y)) &
    28         (\<forall>j[M]. j\<in>n -->
    29           (\<exists>fj[M]. \<exists>sj[M]. \<exists>fsj[M]. \<exists>ffp[M].
    30             fun_apply(M,f,j,fj) & successor(M,j,sj) &
    31             fun_apply(M,f,sj,fsj) & pair(M,fj,fsj,ffp) & ffp \<in> r)))"*)
    32 definition
    33   rtran_closure_mem_fm :: "[i,i,i]=>i" where
    34  "rtran_closure_mem_fm(A,r,p) ==
    35    Exists(Exists(Exists(
    36     And(omega_fm(2),
    37      And(Member(1,2),
    38       And(succ_fm(1,0),
    39        Exists(And(typed_function_fm(1, A#+4, 0),
    40         And(Exists(Exists(Exists(
    41               And(pair_fm(2,1,p#+7),
    42                And(empty_fm(0),
    43                 And(fun_apply_fm(3,0,2), fun_apply_fm(3,5,1))))))),
    44             Forall(Implies(Member(0,3),
    45              Exists(Exists(Exists(Exists(
    46               And(fun_apply_fm(5,4,3),
    47                And(succ_fm(4,2),
    48                 And(fun_apply_fm(5,2,1),
    49                  And(pair_fm(3,1,0), Member(0,r#+9))))))))))))))))))))"
    50 
    51 
    52 lemma rtran_closure_mem_type [TC]:
    53  "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> rtran_closure_mem_fm(x,y,z) \<in> formula"
    54 by (simp add: rtran_closure_mem_fm_def)
    55 
    56 lemma sats_rtran_closure_mem_fm [simp]:
    57    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
    58     ==> sats(A, rtran_closure_mem_fm(x,y,z), env) <->
    59         rtran_closure_mem(##A, nth(x,env), nth(y,env), nth(z,env))"
    60 by (simp add: rtran_closure_mem_fm_def rtran_closure_mem_def)
    61 
    62 lemma rtran_closure_mem_iff_sats:
    63       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
    64           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
    65        ==> rtran_closure_mem(##A, x, y, z) <-> sats(A, rtran_closure_mem_fm(i,j,k), env)"
    66 by (simp add: sats_rtran_closure_mem_fm)
    67 
    68 lemma rtran_closure_mem_reflection:
    69      "REFLECTS[\<lambda>x. rtran_closure_mem(L,f(x),g(x),h(x)),
    70                \<lambda>i x. rtran_closure_mem(##Lset(i),f(x),g(x),h(x))]"
    71 apply (simp only: rtran_closure_mem_def)
    72 apply (intro FOL_reflections function_reflections fun_plus_reflections)
    73 done
    74 
    75 text{*Separation for @{term "rtrancl(r)"}.*}
    76 lemma rtrancl_separation:
    77      "[| L(r); L(A) |] ==> separation (L, rtran_closure_mem(L,A,r))"
    78 apply (rule gen_separation_multi [OF rtran_closure_mem_reflection, of "{r,A}"],
    79        auto)
    80 apply (rule_tac env="[r,A]" in DPow_LsetI)
    81 apply (rule rtran_closure_mem_iff_sats sep_rules | simp)+
    82 done
    83 
    84 
    85 subsubsection{*Reflexive/Transitive Closure, Internalized*}
    86 
    87 (*  "rtran_closure(M,r,s) ==
    88         \<forall>A[M]. is_field(M,r,A) -->
    89          (\<forall>p[M]. p \<in> s <-> rtran_closure_mem(M,A,r,p))" *)
    90 definition
    91   rtran_closure_fm :: "[i,i]=>i" where
    92   "rtran_closure_fm(r,s) ==
    93    Forall(Implies(field_fm(succ(r),0),
    94                   Forall(Iff(Member(0,succ(succ(s))),
    95                              rtran_closure_mem_fm(1,succ(succ(r)),0)))))"
    96 
    97 lemma rtran_closure_type [TC]:
    98      "[| x \<in> nat; y \<in> nat |] ==> rtran_closure_fm(x,y) \<in> formula"
    99 by (simp add: rtran_closure_fm_def)
   100 
   101 lemma sats_rtran_closure_fm [simp]:
   102    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   103     ==> sats(A, rtran_closure_fm(x,y), env) <->
   104         rtran_closure(##A, nth(x,env), nth(y,env))"
   105 by (simp add: rtran_closure_fm_def rtran_closure_def)
   106 
   107 lemma rtran_closure_iff_sats:
   108       "[| nth(i,env) = x; nth(j,env) = y;
   109           i \<in> nat; j \<in> nat; env \<in> list(A)|]
   110        ==> rtran_closure(##A, x, y) <-> sats(A, rtran_closure_fm(i,j), env)"
   111 by simp
   112 
   113 theorem rtran_closure_reflection:
   114      "REFLECTS[\<lambda>x. rtran_closure(L,f(x),g(x)),
   115                \<lambda>i x. rtran_closure(##Lset(i),f(x),g(x))]"
   116 apply (simp only: rtran_closure_def)
   117 apply (intro FOL_reflections function_reflections rtran_closure_mem_reflection)
   118 done
   119 
   120 
   121 subsubsection{*Transitive Closure of a Relation, Internalized*}
   122 
   123 (*  "tran_closure(M,r,t) ==
   124          \<exists>s[M]. rtran_closure(M,r,s) & composition(M,r,s,t)" *)
   125 definition
   126   tran_closure_fm :: "[i,i]=>i" where
   127   "tran_closure_fm(r,s) ==
   128    Exists(And(rtran_closure_fm(succ(r),0), composition_fm(succ(r),0,succ(s))))"
   129 
   130 lemma tran_closure_type [TC]:
   131      "[| x \<in> nat; y \<in> nat |] ==> tran_closure_fm(x,y) \<in> formula"
   132 by (simp add: tran_closure_fm_def)
   133 
   134 lemma sats_tran_closure_fm [simp]:
   135    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   136     ==> sats(A, tran_closure_fm(x,y), env) <->
   137         tran_closure(##A, nth(x,env), nth(y,env))"
   138 by (simp add: tran_closure_fm_def tran_closure_def)
   139 
   140 lemma tran_closure_iff_sats:
   141       "[| nth(i,env) = x; nth(j,env) = y;
   142           i \<in> nat; j \<in> nat; env \<in> list(A)|]
   143        ==> tran_closure(##A, x, y) <-> sats(A, tran_closure_fm(i,j), env)"
   144 by simp
   145 
   146 theorem tran_closure_reflection:
   147      "REFLECTS[\<lambda>x. tran_closure(L,f(x),g(x)),
   148                \<lambda>i x. tran_closure(##Lset(i),f(x),g(x))]"
   149 apply (simp only: tran_closure_def)
   150 apply (intro FOL_reflections function_reflections
   151              rtran_closure_reflection composition_reflection)
   152 done
   153 
   154 
   155 subsubsection{*Separation for the Proof of @{text "wellfounded_on_trancl"}*}
   156 
   157 lemma wellfounded_trancl_reflects:
   158   "REFLECTS[\<lambda>x. \<exists>w[L]. \<exists>wx[L]. \<exists>rp[L].
   159                  w \<in> Z & pair(L,w,x,wx) & tran_closure(L,r,rp) & wx \<in> rp,
   160    \<lambda>i x. \<exists>w \<in> Lset(i). \<exists>wx \<in> Lset(i). \<exists>rp \<in> Lset(i).
   161        w \<in> Z & pair(##Lset(i),w,x,wx) & tran_closure(##Lset(i),r,rp) &
   162        wx \<in> rp]"
   163 by (intro FOL_reflections function_reflections fun_plus_reflections
   164           tran_closure_reflection)
   165 
   166 lemma wellfounded_trancl_separation:
   167          "[| L(r); L(Z) |] ==>
   168           separation (L, \<lambda>x.
   169               \<exists>w[L]. \<exists>wx[L]. \<exists>rp[L].
   170                w \<in> Z & pair(L,w,x,wx) & tran_closure(L,r,rp) & wx \<in> rp)"
   171 apply (rule gen_separation_multi [OF wellfounded_trancl_reflects, of "{r,Z}"],
   172        auto)
   173 apply (rule_tac env="[r,Z]" in DPow_LsetI)
   174 apply (rule sep_rules tran_closure_iff_sats | simp)+
   175 done
   176 
   177 
   178 subsubsection{*Instantiating the locale @{text M_trancl}*}
   179 
   180 lemma M_trancl_axioms_L: "M_trancl_axioms(L)"
   181   apply (rule M_trancl_axioms.intro)
   182    apply (assumption | rule rtrancl_separation wellfounded_trancl_separation)+
   183   done
   184 
   185 theorem M_trancl_L: "PROP M_trancl(L)"
   186 by (rule M_trancl.intro [OF M_basic_L M_trancl_axioms_L])
   187 
   188 interpretation L: M_trancl L by (rule M_trancl_L)
   189 
   190 
   191 subsection{*@{term L} is Closed Under the Operator @{term list}*}
   192 
   193 subsubsection{*Instances of Replacement for Lists*}
   194 
   195 lemma list_replacement1_Reflects:
   196  "REFLECTS
   197    [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
   198          is_wfrec(L, iterates_MH(L, is_list_functor(L,A), 0), memsn, u, y)),
   199     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(##Lset(i), u, y, x) \<and>
   200          is_wfrec(##Lset(i),
   201                   iterates_MH(##Lset(i),
   202                           is_list_functor(##Lset(i), A), 0), memsn, u, y))]"
   203 by (intro FOL_reflections function_reflections is_wfrec_reflection
   204           iterates_MH_reflection list_functor_reflection)
   205 
   206 
   207 lemma list_replacement1:
   208    "L(A) ==> iterates_replacement(L, is_list_functor(L,A), 0)"
   209 apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
   210 apply (rule strong_replacementI)
   211 apply (rule_tac u="{B,A,n,0,Memrel(succ(n))}" 
   212          in gen_separation_multi [OF list_replacement1_Reflects], 
   213        auto simp add: nonempty)
   214 apply (rule_tac env="[B,A,n,0,Memrel(succ(n))]" in DPow_LsetI)
   215 apply (rule sep_rules is_nat_case_iff_sats list_functor_iff_sats
   216             is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
   217 done
   218 
   219 
   220 lemma list_replacement2_Reflects:
   221  "REFLECTS
   222    [\<lambda>x. \<exists>u[L]. u \<in> B & u \<in> nat &
   223                 is_iterates(L, is_list_functor(L, A), 0, u, x),
   224     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & u \<in> nat &
   225                is_iterates(##Lset(i), is_list_functor(##Lset(i), A), 0, u, x)]"
   226 by (intro FOL_reflections 
   227           is_iterates_reflection list_functor_reflection)
   228 
   229 lemma list_replacement2:
   230    "L(A) ==> strong_replacement(L,
   231          \<lambda>n y. n\<in>nat & is_iterates(L, is_list_functor(L,A), 0, n, y))"
   232 apply (rule strong_replacementI)
   233 apply (rule_tac u="{A,B,0,nat}" 
   234          in gen_separation_multi [OF list_replacement2_Reflects], 
   235        auto simp add: L_nat nonempty)
   236 apply (rule_tac env="[A,B,0,nat]" in DPow_LsetI)
   237 apply (rule sep_rules list_functor_iff_sats is_iterates_iff_sats | simp)+
   238 done
   239 
   240 
   241 subsection{*@{term L} is Closed Under the Operator @{term formula}*}
   242 
   243 subsubsection{*Instances of Replacement for Formulas*}
   244 
   245 (*FIXME: could prove a lemma iterates_replacementI to eliminate the 
   246 need to expand iterates_replacement and wfrec_replacement*)
   247 lemma formula_replacement1_Reflects:
   248  "REFLECTS
   249    [\<lambda>x. \<exists>u[L]. u \<in> B & (\<exists>y[L]. pair(L,u,y,x) &
   250          is_wfrec(L, iterates_MH(L, is_formula_functor(L), 0), memsn, u, y)),
   251     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & (\<exists>y \<in> Lset(i). pair(##Lset(i), u, y, x) &
   252          is_wfrec(##Lset(i),
   253                   iterates_MH(##Lset(i),
   254                           is_formula_functor(##Lset(i)), 0), memsn, u, y))]"
   255 by (intro FOL_reflections function_reflections is_wfrec_reflection
   256           iterates_MH_reflection formula_functor_reflection)
   257 
   258 lemma formula_replacement1:
   259    "iterates_replacement(L, is_formula_functor(L), 0)"
   260 apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
   261 apply (rule strong_replacementI)
   262 apply (rule_tac u="{B,n,0,Memrel(succ(n))}" 
   263          in gen_separation_multi [OF formula_replacement1_Reflects], 
   264        auto simp add: nonempty)
   265 apply (rule_tac env="[n,B,0,Memrel(succ(n))]" in DPow_LsetI)
   266 apply (rule sep_rules is_nat_case_iff_sats formula_functor_iff_sats
   267             is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
   268 done
   269 
   270 lemma formula_replacement2_Reflects:
   271  "REFLECTS
   272    [\<lambda>x. \<exists>u[L]. u \<in> B & u \<in> nat &
   273                 is_iterates(L, is_formula_functor(L), 0, u, x),
   274     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & u \<in> nat &
   275                is_iterates(##Lset(i), is_formula_functor(##Lset(i)), 0, u, x)]"
   276 by (intro FOL_reflections 
   277           is_iterates_reflection formula_functor_reflection)
   278 
   279 lemma formula_replacement2:
   280    "strong_replacement(L,
   281          \<lambda>n y. n\<in>nat & is_iterates(L, is_formula_functor(L), 0, n, y))"
   282 apply (rule strong_replacementI)
   283 apply (rule_tac u="{B,0,nat}" 
   284          in gen_separation_multi [OF formula_replacement2_Reflects], 
   285        auto simp add: nonempty L_nat)
   286 apply (rule_tac env="[B,0,nat]" in DPow_LsetI)
   287 apply (rule sep_rules formula_functor_iff_sats is_iterates_iff_sats | simp)+
   288 done
   289 
   290 text{*NB The proofs for type @{term formula} are virtually identical to those
   291 for @{term "list(A)"}.  It was a cut-and-paste job! *}
   292 
   293 
   294 subsubsection{*The Formula @{term is_nth}, Internalized*}
   295 
   296 (* "is_nth(M,n,l,Z) ==
   297       \<exists>X[M]. is_iterates(M, is_tl(M), l, n, X) & is_hd(M,X,Z)" *)
   298 definition
   299   nth_fm :: "[i,i,i]=>i" where
   300     "nth_fm(n,l,Z) == 
   301        Exists(And(is_iterates_fm(tl_fm(1,0), succ(l), succ(n), 0), 
   302               hd_fm(0,succ(Z))))"
   303 
   304 lemma nth_fm_type [TC]:
   305  "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> nth_fm(x,y,z) \<in> formula"
   306 by (simp add: nth_fm_def)
   307 
   308 lemma sats_nth_fm [simp]:
   309    "[| x < length(env); y \<in> nat; z \<in> nat; env \<in> list(A)|]
   310     ==> sats(A, nth_fm(x,y,z), env) <->
   311         is_nth(##A, nth(x,env), nth(y,env), nth(z,env))"
   312 apply (frule lt_length_in_nat, assumption)  
   313 apply (simp add: nth_fm_def is_nth_def sats_is_iterates_fm) 
   314 done
   315 
   316 lemma nth_iff_sats:
   317       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
   318           i < length(env); j \<in> nat; k \<in> nat; env \<in> list(A)|]
   319        ==> is_nth(##A, x, y, z) <-> sats(A, nth_fm(i,j,k), env)"
   320 by (simp add: sats_nth_fm)
   321 
   322 theorem nth_reflection:
   323      "REFLECTS[\<lambda>x. is_nth(L, f(x), g(x), h(x)),  
   324                \<lambda>i x. is_nth(##Lset(i), f(x), g(x), h(x))]"
   325 apply (simp only: is_nth_def)
   326 apply (intro FOL_reflections is_iterates_reflection
   327              hd_reflection tl_reflection) 
   328 done
   329 
   330 
   331 subsubsection{*An Instance of Replacement for @{term nth}*}
   332 
   333 (*FIXME: could prove a lemma iterates_replacementI to eliminate the 
   334 need to expand iterates_replacement and wfrec_replacement*)
   335 lemma nth_replacement_Reflects:
   336  "REFLECTS
   337    [\<lambda>x. \<exists>u[L]. u \<in> B & (\<exists>y[L]. pair(L,u,y,x) &
   338          is_wfrec(L, iterates_MH(L, is_tl(L), z), memsn, u, y)),
   339     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & (\<exists>y \<in> Lset(i). pair(##Lset(i), u, y, x) &
   340          is_wfrec(##Lset(i),
   341                   iterates_MH(##Lset(i),
   342                           is_tl(##Lset(i)), z), memsn, u, y))]"
   343 by (intro FOL_reflections function_reflections is_wfrec_reflection
   344           iterates_MH_reflection tl_reflection)
   345 
   346 lemma nth_replacement:
   347    "L(w) ==> iterates_replacement(L, is_tl(L), w)"
   348 apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
   349 apply (rule strong_replacementI)
   350 apply (rule_tac u="{B,w,Memrel(succ(n))}" 
   351          in gen_separation_multi [OF nth_replacement_Reflects], 
   352        auto)
   353 apply (rule_tac env="[B,w,Memrel(succ(n))]" in DPow_LsetI)
   354 apply (rule sep_rules is_nat_case_iff_sats tl_iff_sats
   355             is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
   356 done
   357 
   358 
   359 subsubsection{*Instantiating the locale @{text M_datatypes}*}
   360 
   361 lemma M_datatypes_axioms_L: "M_datatypes_axioms(L)"
   362   apply (rule M_datatypes_axioms.intro)
   363       apply (assumption | rule
   364         list_replacement1 list_replacement2
   365         formula_replacement1 formula_replacement2
   366         nth_replacement)+
   367   done
   368 
   369 theorem M_datatypes_L: "PROP M_datatypes(L)"
   370   apply (rule M_datatypes.intro)
   371    apply (rule M_trancl_L)
   372   apply (rule M_datatypes_axioms_L) 
   373   done
   374 
   375 interpretation L: M_datatypes L by (rule M_datatypes_L)
   376 
   377 
   378 subsection{*@{term L} is Closed Under the Operator @{term eclose}*}
   379 
   380 subsubsection{*Instances of Replacement for @{term eclose}*}
   381 
   382 lemma eclose_replacement1_Reflects:
   383  "REFLECTS
   384    [\<lambda>x. \<exists>u[L]. u \<in> B & (\<exists>y[L]. pair(L,u,y,x) &
   385          is_wfrec(L, iterates_MH(L, big_union(L), A), memsn, u, y)),
   386     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & (\<exists>y \<in> Lset(i). pair(##Lset(i), u, y, x) &
   387          is_wfrec(##Lset(i),
   388                   iterates_MH(##Lset(i), big_union(##Lset(i)), A),
   389                   memsn, u, y))]"
   390 by (intro FOL_reflections function_reflections is_wfrec_reflection
   391           iterates_MH_reflection)
   392 
   393 lemma eclose_replacement1:
   394    "L(A) ==> iterates_replacement(L, big_union(L), A)"
   395 apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
   396 apply (rule strong_replacementI)
   397 apply (rule_tac u="{B,A,n,Memrel(succ(n))}" 
   398          in gen_separation_multi [OF eclose_replacement1_Reflects], auto)
   399 apply (rule_tac env="[B,A,n,Memrel(succ(n))]" in DPow_LsetI)
   400 apply (rule sep_rules iterates_MH_iff_sats is_nat_case_iff_sats
   401              is_wfrec_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
   402 done
   403 
   404 
   405 lemma eclose_replacement2_Reflects:
   406  "REFLECTS
   407    [\<lambda>x. \<exists>u[L]. u \<in> B & u \<in> nat &
   408                 is_iterates(L, big_union(L), A, u, x),
   409     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & u \<in> nat &
   410                is_iterates(##Lset(i), big_union(##Lset(i)), A, u, x)]"
   411 by (intro FOL_reflections function_reflections is_iterates_reflection)
   412 
   413 lemma eclose_replacement2:
   414    "L(A) ==> strong_replacement(L,
   415          \<lambda>n y. n\<in>nat & is_iterates(L, big_union(L), A, n, y))"
   416 apply (rule strong_replacementI)
   417 apply (rule_tac u="{A,B,nat}" 
   418          in gen_separation_multi [OF eclose_replacement2_Reflects],
   419        auto simp add: L_nat)
   420 apply (rule_tac env="[A,B,nat]" in DPow_LsetI)
   421 apply (rule sep_rules is_iterates_iff_sats big_union_iff_sats | simp)+
   422 done
   423 
   424 
   425 subsubsection{*Instantiating the locale @{text M_eclose}*}
   426 
   427 lemma M_eclose_axioms_L: "M_eclose_axioms(L)"
   428   apply (rule M_eclose_axioms.intro)
   429    apply (assumption | rule eclose_replacement1 eclose_replacement2)+
   430   done
   431 
   432 theorem M_eclose_L: "PROP M_eclose(L)"
   433   apply (rule M_eclose.intro)
   434    apply (rule M_datatypes_L)
   435   apply (rule M_eclose_axioms_L)
   436   done
   437 
   438 interpretation L: M_eclose L by (rule M_eclose_L)
   439 
   440 
   441 end