src/ZF/Constructible/Rec_Separation.thy
author paulson
Thu Oct 17 10:54:11 2002 +0200 (2002-10-17)
changeset 13651 ac80e101306a
parent 13647 7f6f0ffc45c3
child 13655 95b95cdb4704
permissions -rw-r--r--
Cosmetic changes suggested by writing the paper. Deleted some
redundant arity proofs
paulson@13437
     1
(*  Title:      ZF/Constructible/Rec_Separation.thy
paulson@13634
     2
    ID:   $Id$
paulson@13437
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@13437
     4
*)
wenzelm@13429
     5
wenzelm@13429
     6
header {*Separation for Facts About Recursion*}
paulson@13348
     7
paulson@13496
     8
theory Rec_Separation = Separation + Internalize:
paulson@13348
     9
paulson@13348
    10
text{*This theory proves all instances needed for locales @{text
paulson@13634
    11
"M_trancl"} and @{text "M_datatypes"}*}
paulson@13348
    12
paulson@13363
    13
lemma eq_succ_imp_lt: "[|i = succ(j); Ord(i)|] ==> j<i"
wenzelm@13428
    14
by simp
paulson@13363
    15
paulson@13493
    16
paulson@13348
    17
subsection{*The Locale @{text "M_trancl"}*}
paulson@13348
    18
paulson@13348
    19
subsubsection{*Separation for Reflexive/Transitive Closure*}
paulson@13348
    20
paulson@13348
    21
text{*First, The Defining Formula*}
paulson@13348
    22
paulson@13348
    23
(* "rtran_closure_mem(M,A,r,p) ==
wenzelm@13428
    24
      \<exists>nnat[M]. \<exists>n[M]. \<exists>n'[M].
paulson@13348
    25
       omega(M,nnat) & n\<in>nnat & successor(M,n,n') &
paulson@13348
    26
       (\<exists>f[M]. typed_function(M,n',A,f) &
wenzelm@13428
    27
        (\<exists>x[M]. \<exists>y[M]. \<exists>zero[M]. pair(M,x,y,p) & empty(M,zero) &
wenzelm@13428
    28
          fun_apply(M,f,zero,x) & fun_apply(M,f,n,y)) &
wenzelm@13428
    29
        (\<forall>j[M]. j\<in>n -->
wenzelm@13428
    30
          (\<exists>fj[M]. \<exists>sj[M]. \<exists>fsj[M]. \<exists>ffp[M].
wenzelm@13428
    31
            fun_apply(M,f,j,fj) & successor(M,j,sj) &
wenzelm@13428
    32
            fun_apply(M,f,sj,fsj) & pair(M,fj,fsj,ffp) & ffp \<in> r)))"*)
paulson@13348
    33
constdefs rtran_closure_mem_fm :: "[i,i,i]=>i"
wenzelm@13428
    34
 "rtran_closure_mem_fm(A,r,p) ==
paulson@13348
    35
   Exists(Exists(Exists(
paulson@13348
    36
    And(omega_fm(2),
paulson@13348
    37
     And(Member(1,2),
paulson@13348
    38
      And(succ_fm(1,0),
paulson@13348
    39
       Exists(And(typed_function_fm(1, A#+4, 0),
wenzelm@13428
    40
        And(Exists(Exists(Exists(
wenzelm@13428
    41
              And(pair_fm(2,1,p#+7),
wenzelm@13428
    42
               And(empty_fm(0),
wenzelm@13428
    43
                And(fun_apply_fm(3,0,2), fun_apply_fm(3,5,1))))))),
wenzelm@13428
    44
            Forall(Implies(Member(0,3),
wenzelm@13428
    45
             Exists(Exists(Exists(Exists(
wenzelm@13428
    46
              And(fun_apply_fm(5,4,3),
wenzelm@13428
    47
               And(succ_fm(4,2),
wenzelm@13428
    48
                And(fun_apply_fm(5,2,1),
wenzelm@13428
    49
                 And(pair_fm(3,1,0), Member(0,r#+9))))))))))))))))))))"
paulson@13348
    50
paulson@13348
    51
paulson@13348
    52
lemma rtran_closure_mem_type [TC]:
paulson@13348
    53
 "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> rtran_closure_mem_fm(x,y,z) \<in> formula"
wenzelm@13428
    54
by (simp add: rtran_closure_mem_fm_def)
paulson@13348
    55
paulson@13348
    56
lemma sats_rtran_closure_mem_fm [simp]:
paulson@13348
    57
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
wenzelm@13428
    58
    ==> sats(A, rtran_closure_mem_fm(x,y,z), env) <->
paulson@13348
    59
        rtran_closure_mem(**A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13348
    60
by (simp add: rtran_closure_mem_fm_def rtran_closure_mem_def)
paulson@13348
    61
paulson@13348
    62
lemma rtran_closure_mem_iff_sats:
wenzelm@13428
    63
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13348
    64
          i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13348
    65
       ==> rtran_closure_mem(**A, x, y, z) <-> sats(A, rtran_closure_mem_fm(i,j,k), env)"
paulson@13348
    66
by (simp add: sats_rtran_closure_mem_fm)
paulson@13348
    67
paulson@13566
    68
lemma rtran_closure_mem_reflection:
wenzelm@13428
    69
     "REFLECTS[\<lambda>x. rtran_closure_mem(L,f(x),g(x),h(x)),
paulson@13348
    70
               \<lambda>i x. rtran_closure_mem(**Lset(i),f(x),g(x),h(x))]"
paulson@13348
    71
apply (simp only: rtran_closure_mem_def setclass_simps)
wenzelm@13428
    72
apply (intro FOL_reflections function_reflections fun_plus_reflections)
paulson@13348
    73
done
paulson@13348
    74
paulson@13348
    75
text{*Separation for @{term "rtrancl(r)"}.*}
paulson@13348
    76
lemma rtrancl_separation:
paulson@13348
    77
     "[| L(r); L(A) |] ==> separation (L, rtran_closure_mem(L,A,r))"
paulson@13566
    78
apply (rule gen_separation [OF rtran_closure_mem_reflection, of "{r,A}"], simp)
paulson@13566
    79
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13385
    80
apply (rule DPow_LsetI)
paulson@13566
    81
apply (rule_tac env = "[x,r,A]" in rtran_closure_mem_iff_sats)
paulson@13348
    82
apply (rule sep_rules | simp)+
paulson@13348
    83
done
paulson@13348
    84
paulson@13348
    85
paulson@13348
    86
subsubsection{*Reflexive/Transitive Closure, Internalized*}
paulson@13348
    87
wenzelm@13428
    88
(*  "rtran_closure(M,r,s) ==
paulson@13348
    89
        \<forall>A[M]. is_field(M,r,A) -->
wenzelm@13428
    90
         (\<forall>p[M]. p \<in> s <-> rtran_closure_mem(M,A,r,p))" *)
paulson@13348
    91
constdefs rtran_closure_fm :: "[i,i]=>i"
wenzelm@13428
    92
 "rtran_closure_fm(r,s) ==
paulson@13348
    93
   Forall(Implies(field_fm(succ(r),0),
paulson@13348
    94
                  Forall(Iff(Member(0,succ(succ(s))),
paulson@13348
    95
                             rtran_closure_mem_fm(1,succ(succ(r)),0)))))"
paulson@13348
    96
paulson@13348
    97
lemma rtran_closure_type [TC]:
paulson@13348
    98
     "[| x \<in> nat; y \<in> nat |] ==> rtran_closure_fm(x,y) \<in> formula"
wenzelm@13428
    99
by (simp add: rtran_closure_fm_def)
paulson@13348
   100
paulson@13348
   101
lemma sats_rtran_closure_fm [simp]:
paulson@13348
   102
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
wenzelm@13428
   103
    ==> sats(A, rtran_closure_fm(x,y), env) <->
paulson@13348
   104
        rtran_closure(**A, nth(x,env), nth(y,env))"
paulson@13348
   105
by (simp add: rtran_closure_fm_def rtran_closure_def)
paulson@13348
   106
paulson@13348
   107
lemma rtran_closure_iff_sats:
wenzelm@13428
   108
      "[| nth(i,env) = x; nth(j,env) = y;
paulson@13348
   109
          i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@13348
   110
       ==> rtran_closure(**A, x, y) <-> sats(A, rtran_closure_fm(i,j), env)"
paulson@13348
   111
by simp
paulson@13348
   112
paulson@13348
   113
theorem rtran_closure_reflection:
wenzelm@13428
   114
     "REFLECTS[\<lambda>x. rtran_closure(L,f(x),g(x)),
paulson@13348
   115
               \<lambda>i x. rtran_closure(**Lset(i),f(x),g(x))]"
paulson@13348
   116
apply (simp only: rtran_closure_def setclass_simps)
paulson@13348
   117
apply (intro FOL_reflections function_reflections rtran_closure_mem_reflection)
paulson@13348
   118
done
paulson@13348
   119
paulson@13348
   120
paulson@13348
   121
subsubsection{*Transitive Closure of a Relation, Internalized*}
paulson@13348
   122
paulson@13348
   123
(*  "tran_closure(M,r,t) ==
paulson@13348
   124
         \<exists>s[M]. rtran_closure(M,r,s) & composition(M,r,s,t)" *)
paulson@13348
   125
constdefs tran_closure_fm :: "[i,i]=>i"
wenzelm@13428
   126
 "tran_closure_fm(r,s) ==
paulson@13348
   127
   Exists(And(rtran_closure_fm(succ(r),0), composition_fm(succ(r),0,succ(s))))"
paulson@13348
   128
paulson@13348
   129
lemma tran_closure_type [TC]:
paulson@13348
   130
     "[| x \<in> nat; y \<in> nat |] ==> tran_closure_fm(x,y) \<in> formula"
wenzelm@13428
   131
by (simp add: tran_closure_fm_def)
paulson@13348
   132
paulson@13348
   133
lemma sats_tran_closure_fm [simp]:
paulson@13348
   134
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
wenzelm@13428
   135
    ==> sats(A, tran_closure_fm(x,y), env) <->
paulson@13348
   136
        tran_closure(**A, nth(x,env), nth(y,env))"
paulson@13348
   137
by (simp add: tran_closure_fm_def tran_closure_def)
paulson@13348
   138
paulson@13348
   139
lemma tran_closure_iff_sats:
wenzelm@13428
   140
      "[| nth(i,env) = x; nth(j,env) = y;
paulson@13348
   141
          i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@13348
   142
       ==> tran_closure(**A, x, y) <-> sats(A, tran_closure_fm(i,j), env)"
paulson@13348
   143
by simp
paulson@13348
   144
paulson@13348
   145
theorem tran_closure_reflection:
wenzelm@13428
   146
     "REFLECTS[\<lambda>x. tran_closure(L,f(x),g(x)),
paulson@13348
   147
               \<lambda>i x. tran_closure(**Lset(i),f(x),g(x))]"
paulson@13348
   148
apply (simp only: tran_closure_def setclass_simps)
wenzelm@13428
   149
apply (intro FOL_reflections function_reflections
paulson@13348
   150
             rtran_closure_reflection composition_reflection)
paulson@13348
   151
done
paulson@13348
   152
paulson@13348
   153
paulson@13506
   154
subsubsection{*Separation for the Proof of @{text "wellfounded_on_trancl"}*}
paulson@13348
   155
paulson@13348
   156
lemma wellfounded_trancl_reflects:
wenzelm@13428
   157
  "REFLECTS[\<lambda>x. \<exists>w[L]. \<exists>wx[L]. \<exists>rp[L].
wenzelm@13428
   158
                 w \<in> Z & pair(L,w,x,wx) & tran_closure(L,r,rp) & wx \<in> rp,
wenzelm@13428
   159
   \<lambda>i x. \<exists>w \<in> Lset(i). \<exists>wx \<in> Lset(i). \<exists>rp \<in> Lset(i).
paulson@13348
   160
       w \<in> Z & pair(**Lset(i),w,x,wx) & tran_closure(**Lset(i),r,rp) &
paulson@13348
   161
       wx \<in> rp]"
wenzelm@13428
   162
by (intro FOL_reflections function_reflections fun_plus_reflections
paulson@13348
   163
          tran_closure_reflection)
paulson@13348
   164
paulson@13348
   165
lemma wellfounded_trancl_separation:
wenzelm@13428
   166
         "[| L(r); L(Z) |] ==>
wenzelm@13428
   167
          separation (L, \<lambda>x.
wenzelm@13428
   168
              \<exists>w[L]. \<exists>wx[L]. \<exists>rp[L].
wenzelm@13428
   169
               w \<in> Z & pair(L,w,x,wx) & tran_closure(L,r,rp) & wx \<in> rp)"
paulson@13566
   170
apply (rule gen_separation [OF wellfounded_trancl_reflects, of "{r,Z}"], simp)
paulson@13566
   171
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13385
   172
apply (rule DPow_LsetI)
paulson@13348
   173
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13566
   174
apply (rule_tac env = "[w,x,r,Z]" in mem_iff_sats)
paulson@13348
   175
apply (rule sep_rules tran_closure_iff_sats | simp)+
paulson@13348
   176
done
paulson@13348
   177
paulson@13363
   178
paulson@13363
   179
subsubsection{*Instantiating the locale @{text M_trancl}*}
wenzelm@13428
   180
paulson@13437
   181
lemma M_trancl_axioms_L: "M_trancl_axioms(L)"
wenzelm@13428
   182
  apply (rule M_trancl_axioms.intro)
paulson@13437
   183
   apply (assumption | rule rtrancl_separation wellfounded_trancl_separation)+
wenzelm@13428
   184
  done
paulson@13363
   185
paulson@13437
   186
theorem M_trancl_L: "PROP M_trancl(L)"
paulson@13437
   187
by (rule M_trancl.intro
paulson@13564
   188
         [OF M_trivial_L M_basic_axioms_L M_trancl_axioms_L])
paulson@13437
   189
wenzelm@13428
   190
lemmas iterates_abs = M_trancl.iterates_abs [OF M_trancl_L]
wenzelm@13428
   191
  and rtran_closure_rtrancl = M_trancl.rtran_closure_rtrancl [OF M_trancl_L]
wenzelm@13428
   192
  and trans_wfrec_abs = M_trancl.trans_wfrec_abs [OF M_trancl_L]
wenzelm@13428
   193
  and eq_pair_wfrec_iff = M_trancl.eq_pair_wfrec_iff [OF M_trancl_L]
paulson@13363
   194
paulson@13363
   195
paulson@13363
   196
wenzelm@13428
   197
subsection{*@{term L} is Closed Under the Operator @{term list}*}
paulson@13363
   198
paulson@13386
   199
subsubsection{*Instances of Replacement for Lists*}
paulson@13386
   200
paulson@13363
   201
lemma list_replacement1_Reflects:
paulson@13363
   202
 "REFLECTS
paulson@13363
   203
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13363
   204
         is_wfrec(L, iterates_MH(L, is_list_functor(L,A), 0), memsn, u, y)),
paulson@13363
   205
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
wenzelm@13428
   206
         is_wfrec(**Lset(i),
wenzelm@13428
   207
                  iterates_MH(**Lset(i),
paulson@13363
   208
                          is_list_functor(**Lset(i), A), 0), memsn, u, y))]"
wenzelm@13428
   209
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   210
          iterates_MH_reflection list_functor_reflection)
paulson@13363
   211
paulson@13441
   212
wenzelm@13428
   213
lemma list_replacement1:
paulson@13363
   214
   "L(A) ==> iterates_replacement(L, is_list_functor(L,A), 0)"
paulson@13363
   215
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   216
apply (rule strong_replacementI)
wenzelm@13428
   217
apply (rename_tac B)
paulson@13566
   218
apply (rule_tac u="{B,A,n,0,Memrel(succ(n))}" 
paulson@13566
   219
         in gen_separation [OF list_replacement1_Reflects], 
paulson@13566
   220
       simp add: nonempty)
paulson@13566
   221
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13385
   222
apply (rule DPow_LsetI)
paulson@13363
   223
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13566
   224
apply (rule_tac env = "[u,x,A,n,B,0,Memrel(succ(n))]" in mem_iff_sats)
paulson@13434
   225
apply (rule sep_rules is_nat_case_iff_sats list_functor_iff_sats
paulson@13441
   226
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13363
   227
done
paulson@13363
   228
paulson@13441
   229
paulson@13363
   230
lemma list_replacement2_Reflects:
paulson@13363
   231
 "REFLECTS
paulson@13363
   232
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
paulson@13363
   233
         (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
paulson@13363
   234
           is_wfrec (L, iterates_MH (L, is_list_functor(L, A), 0),
paulson@13363
   235
                              msn, u, x)),
paulson@13363
   236
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
wenzelm@13428
   237
         (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
paulson@13363
   238
          successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
wenzelm@13428
   239
           is_wfrec (**Lset(i),
paulson@13363
   240
                 iterates_MH (**Lset(i), is_list_functor(**Lset(i), A), 0),
paulson@13363
   241
                     msn, u, x))]"
wenzelm@13428
   242
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   243
          iterates_MH_reflection list_functor_reflection)
paulson@13363
   244
paulson@13363
   245
wenzelm@13428
   246
lemma list_replacement2:
wenzelm@13428
   247
   "L(A) ==> strong_replacement(L,
wenzelm@13428
   248
         \<lambda>n y. n\<in>nat &
paulson@13363
   249
               (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
wenzelm@13428
   250
               is_wfrec(L, iterates_MH(L,is_list_functor(L,A), 0),
paulson@13363
   251
                        msn, n, y)))"
wenzelm@13428
   252
apply (rule strong_replacementI)
wenzelm@13428
   253
apply (rename_tac B)
paulson@13566
   254
apply (rule_tac u="{A,B,0,nat}" 
paulson@13566
   255
         in gen_separation [OF list_replacement2_Reflects], 
paulson@13566
   256
       simp add: L_nat nonempty)
paulson@13566
   257
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13385
   258
apply (rule DPow_LsetI)
paulson@13363
   259
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13566
   260
apply (rule_tac env = "[u,x,A,B,0,nat]" in mem_iff_sats)
paulson@13434
   261
apply (rule sep_rules is_nat_case_iff_sats list_functor_iff_sats
paulson@13441
   262
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13363
   263
done
paulson@13363
   264
paulson@13386
   265
wenzelm@13428
   266
subsection{*@{term L} is Closed Under the Operator @{term formula}*}
paulson@13386
   267
paulson@13386
   268
subsubsection{*Instances of Replacement for Formulas*}
paulson@13386
   269
paulson@13386
   270
lemma formula_replacement1_Reflects:
paulson@13386
   271
 "REFLECTS
paulson@13386
   272
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13386
   273
         is_wfrec(L, iterates_MH(L, is_formula_functor(L), 0), memsn, u, y)),
paulson@13386
   274
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
wenzelm@13428
   275
         is_wfrec(**Lset(i),
wenzelm@13428
   276
                  iterates_MH(**Lset(i),
paulson@13386
   277
                          is_formula_functor(**Lset(i)), 0), memsn, u, y))]"
wenzelm@13428
   278
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   279
          iterates_MH_reflection formula_functor_reflection)
paulson@13386
   280
wenzelm@13428
   281
lemma formula_replacement1:
paulson@13386
   282
   "iterates_replacement(L, is_formula_functor(L), 0)"
paulson@13386
   283
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   284
apply (rule strong_replacementI)
wenzelm@13428
   285
apply (rename_tac B)
paulson@13566
   286
apply (rule_tac u="{B,n,0,Memrel(succ(n))}" 
paulson@13566
   287
         in gen_separation [OF formula_replacement1_Reflects], 
paulson@13566
   288
       simp add: nonempty)
paulson@13566
   289
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13386
   290
apply (rule DPow_LsetI)
paulson@13386
   291
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13566
   292
apply (rule_tac env = "[u,x,n,B,0,Memrel(succ(n))]" in mem_iff_sats)
paulson@13434
   293
apply (rule sep_rules is_nat_case_iff_sats formula_functor_iff_sats
paulson@13441
   294
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13386
   295
done
paulson@13386
   296
paulson@13386
   297
lemma formula_replacement2_Reflects:
paulson@13386
   298
 "REFLECTS
paulson@13386
   299
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
paulson@13386
   300
         (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
paulson@13386
   301
           is_wfrec (L, iterates_MH (L, is_formula_functor(L), 0),
paulson@13386
   302
                              msn, u, x)),
paulson@13386
   303
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
wenzelm@13428
   304
         (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
paulson@13386
   305
          successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
wenzelm@13428
   306
           is_wfrec (**Lset(i),
paulson@13386
   307
                 iterates_MH (**Lset(i), is_formula_functor(**Lset(i)), 0),
paulson@13386
   308
                     msn, u, x))]"
wenzelm@13428
   309
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   310
          iterates_MH_reflection formula_functor_reflection)
paulson@13386
   311
paulson@13386
   312
wenzelm@13428
   313
lemma formula_replacement2:
wenzelm@13428
   314
   "strong_replacement(L,
wenzelm@13428
   315
         \<lambda>n y. n\<in>nat &
paulson@13386
   316
               (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
wenzelm@13428
   317
               is_wfrec(L, iterates_MH(L,is_formula_functor(L), 0),
paulson@13386
   318
                        msn, n, y)))"
wenzelm@13428
   319
apply (rule strong_replacementI)
wenzelm@13428
   320
apply (rename_tac B)
paulson@13566
   321
apply (rule_tac u="{B,0,nat}" 
paulson@13566
   322
         in gen_separation [OF formula_replacement2_Reflects], 
paulson@13566
   323
       simp add: nonempty L_nat)
paulson@13566
   324
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13386
   325
apply (rule DPow_LsetI)
paulson@13386
   326
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13566
   327
apply (rule_tac env = "[u,x,B,0,nat]" in mem_iff_sats)
paulson@13434
   328
apply (rule sep_rules is_nat_case_iff_sats formula_functor_iff_sats
paulson@13441
   329
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13386
   330
done
paulson@13386
   331
paulson@13386
   332
text{*NB The proofs for type @{term formula} are virtually identical to those
paulson@13386
   333
for @{term "list(A)"}.  It was a cut-and-paste job! *}
paulson@13386
   334
paulson@13387
   335
paulson@13437
   336
subsubsection{*The Formula @{term is_nth}, Internalized*}
paulson@13437
   337
paulson@13437
   338
(* "is_nth(M,n,l,Z) == 
paulson@13437
   339
      \<exists>X[M]. \<exists>sn[M]. \<exists>msn[M]. 
paulson@13437
   340
       2       1       0
paulson@13437
   341
       successor(M,n,sn) & membership(M,sn,msn) &
paulson@13437
   342
       is_wfrec(M, iterates_MH(M, is_tl(M), l), msn, n, X) &
paulson@13493
   343
       is_hd(M,X,Z)" *)
paulson@13437
   344
constdefs nth_fm :: "[i,i,i]=>i"
paulson@13437
   345
    "nth_fm(n,l,Z) == 
paulson@13437
   346
       Exists(Exists(Exists(
paulson@13493
   347
         And(succ_fm(n#+3,1),
paulson@13493
   348
          And(Memrel_fm(1,0),
paulson@13493
   349
           And(is_wfrec_fm(iterates_MH_fm(tl_fm(1,0),l#+8,2,1,0), 0, n#+3, 2), hd_fm(2,Z#+3)))))))"
paulson@13493
   350
paulson@13493
   351
lemma nth_fm_type [TC]:
paulson@13493
   352
 "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> nth_fm(x,y,z) \<in> formula"
paulson@13493
   353
by (simp add: nth_fm_def)
paulson@13493
   354
paulson@13493
   355
lemma sats_nth_fm [simp]:
paulson@13493
   356
   "[| x < length(env); y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13493
   357
    ==> sats(A, nth_fm(x,y,z), env) <->
paulson@13493
   358
        is_nth(**A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13493
   359
apply (frule lt_length_in_nat, assumption)  
paulson@13493
   360
apply (simp add: nth_fm_def is_nth_def sats_is_wfrec_fm sats_iterates_MH_fm) 
paulson@13493
   361
done
paulson@13493
   362
paulson@13493
   363
lemma nth_iff_sats:
paulson@13493
   364
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13493
   365
          i < length(env); j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13493
   366
       ==> is_nth(**A, x, y, z) <-> sats(A, nth_fm(i,j,k), env)"
paulson@13493
   367
by (simp add: sats_nth_fm)
paulson@13437
   368
paulson@13437
   369
theorem nth_reflection:
paulson@13437
   370
     "REFLECTS[\<lambda>x. is_nth(L, f(x), g(x), h(x)),  
paulson@13437
   371
               \<lambda>i x. is_nth(**Lset(i), f(x), g(x), h(x))]"
paulson@13437
   372
apply (simp only: is_nth_def setclass_simps)
paulson@13437
   373
apply (intro FOL_reflections function_reflections is_wfrec_reflection 
paulson@13437
   374
             iterates_MH_reflection hd_reflection tl_reflection) 
paulson@13437
   375
done
paulson@13437
   376
paulson@13437
   377
paulson@13409
   378
subsubsection{*An Instance of Replacement for @{term nth}*}
paulson@13409
   379
paulson@13409
   380
lemma nth_replacement_Reflects:
paulson@13409
   381
 "REFLECTS
paulson@13409
   382
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13409
   383
         is_wfrec(L, iterates_MH(L, is_tl(L), z), memsn, u, y)),
paulson@13409
   384
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
wenzelm@13428
   385
         is_wfrec(**Lset(i),
wenzelm@13428
   386
                  iterates_MH(**Lset(i),
paulson@13409
   387
                          is_tl(**Lset(i)), z), memsn, u, y))]"
wenzelm@13428
   388
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   389
          iterates_MH_reflection list_functor_reflection tl_reflection)
paulson@13409
   390
wenzelm@13428
   391
lemma nth_replacement:
paulson@13409
   392
   "L(w) ==> iterates_replacement(L, %l t. is_tl(L,l,t), w)"
paulson@13409
   393
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   394
apply (rule strong_replacementI)
paulson@13566
   395
apply (rule_tac u="{A,n,w,Memrel(succ(n))}" 
paulson@13566
   396
         in gen_separation [OF nth_replacement_Reflects], 
paulson@13566
   397
       simp add: nonempty)
paulson@13566
   398
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13409
   399
apply (rule DPow_LsetI)
paulson@13409
   400
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13566
   401
apply (rule_tac env = "[u,x,A,w,Memrel(succ(n))]" in mem_iff_sats)
paulson@13434
   402
apply (rule sep_rules is_nat_case_iff_sats tl_iff_sats
paulson@13441
   403
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13409
   404
done
paulson@13409
   405
paulson@13422
   406
paulson@13422
   407
subsubsection{*Instantiating the locale @{text M_datatypes}*}
wenzelm@13428
   408
paulson@13437
   409
lemma M_datatypes_axioms_L: "M_datatypes_axioms(L)"
wenzelm@13428
   410
  apply (rule M_datatypes_axioms.intro)
wenzelm@13428
   411
      apply (assumption | rule
wenzelm@13428
   412
        list_replacement1 list_replacement2
wenzelm@13428
   413
        formula_replacement1 formula_replacement2
wenzelm@13428
   414
        nth_replacement)+
wenzelm@13428
   415
  done
paulson@13422
   416
paulson@13437
   417
theorem M_datatypes_L: "PROP M_datatypes(L)"
paulson@13437
   418
  apply (rule M_datatypes.intro)
paulson@13634
   419
      apply (rule M_trancl.axioms [OF M_trancl_L])+
paulson@13441
   420
 apply (rule M_datatypes_axioms_L) 
paulson@13437
   421
 done
paulson@13437
   422
wenzelm@13428
   423
lemmas list_closed = M_datatypes.list_closed [OF M_datatypes_L]
wenzelm@13428
   424
  and formula_closed = M_datatypes.formula_closed [OF M_datatypes_L]
wenzelm@13428
   425
  and list_abs = M_datatypes.list_abs [OF M_datatypes_L]
wenzelm@13428
   426
  and formula_abs = M_datatypes.formula_abs [OF M_datatypes_L]
wenzelm@13428
   427
  and nth_abs = M_datatypes.nth_abs [OF M_datatypes_L]
paulson@13409
   428
paulson@13422
   429
declare list_closed [intro,simp]
paulson@13422
   430
declare formula_closed [intro,simp]
paulson@13422
   431
declare list_abs [simp]
paulson@13422
   432
declare formula_abs [simp]
paulson@13422
   433
declare nth_abs [simp]
paulson@13422
   434
paulson@13422
   435
wenzelm@13428
   436
subsection{*@{term L} is Closed Under the Operator @{term eclose}*}
paulson@13422
   437
paulson@13422
   438
subsubsection{*Instances of Replacement for @{term eclose}*}
paulson@13422
   439
paulson@13422
   440
lemma eclose_replacement1_Reflects:
paulson@13422
   441
 "REFLECTS
paulson@13422
   442
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13422
   443
         is_wfrec(L, iterates_MH(L, big_union(L), A), memsn, u, y)),
paulson@13422
   444
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
wenzelm@13428
   445
         is_wfrec(**Lset(i),
wenzelm@13428
   446
                  iterates_MH(**Lset(i), big_union(**Lset(i)), A),
paulson@13422
   447
                  memsn, u, y))]"
wenzelm@13428
   448
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   449
          iterates_MH_reflection)
paulson@13422
   450
wenzelm@13428
   451
lemma eclose_replacement1:
paulson@13422
   452
   "L(A) ==> iterates_replacement(L, big_union(L), A)"
paulson@13422
   453
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   454
apply (rule strong_replacementI)
wenzelm@13428
   455
apply (rename_tac B)
paulson@13566
   456
apply (rule_tac u="{B,A,n,Memrel(succ(n))}" 
paulson@13566
   457
         in gen_separation [OF eclose_replacement1_Reflects], simp)
paulson@13566
   458
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13422
   459
apply (rule DPow_LsetI)
paulson@13422
   460
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13566
   461
apply (rule_tac env = "[u,x,A,n,B,Memrel(succ(n))]" in mem_iff_sats)
paulson@13434
   462
apply (rule sep_rules iterates_MH_iff_sats is_nat_case_iff_sats
paulson@13441
   463
             is_wfrec_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
paulson@13409
   464
done
paulson@13409
   465
paulson@13422
   466
paulson@13422
   467
lemma eclose_replacement2_Reflects:
paulson@13422
   468
 "REFLECTS
paulson@13422
   469
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
paulson@13422
   470
         (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
paulson@13422
   471
           is_wfrec (L, iterates_MH (L, big_union(L), A),
paulson@13422
   472
                              msn, u, x)),
paulson@13422
   473
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
wenzelm@13428
   474
         (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
paulson@13422
   475
          successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
wenzelm@13428
   476
           is_wfrec (**Lset(i),
paulson@13422
   477
                 iterates_MH (**Lset(i), big_union(**Lset(i)), A),
paulson@13422
   478
                     msn, u, x))]"
wenzelm@13428
   479
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   480
          iterates_MH_reflection)
paulson@13422
   481
paulson@13422
   482
wenzelm@13428
   483
lemma eclose_replacement2:
wenzelm@13428
   484
   "L(A) ==> strong_replacement(L,
wenzelm@13428
   485
         \<lambda>n y. n\<in>nat &
paulson@13422
   486
               (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
wenzelm@13428
   487
               is_wfrec(L, iterates_MH(L,big_union(L), A),
paulson@13422
   488
                        msn, n, y)))"
wenzelm@13428
   489
apply (rule strong_replacementI)
wenzelm@13428
   490
apply (rename_tac B)
paulson@13566
   491
apply (rule_tac u="{A,B,nat}" 
paulson@13566
   492
         in gen_separation [OF eclose_replacement2_Reflects], simp add: L_nat)
paulson@13566
   493
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13422
   494
apply (rule DPow_LsetI)
paulson@13422
   495
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13566
   496
apply (rule_tac env = "[u,x,A,B,nat]" in mem_iff_sats)
paulson@13434
   497
apply (rule sep_rules is_nat_case_iff_sats iterates_MH_iff_sats
paulson@13441
   498
              is_wfrec_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
paulson@13422
   499
done
paulson@13422
   500
paulson@13422
   501
paulson@13422
   502
subsubsection{*Instantiating the locale @{text M_eclose}*}
paulson@13422
   503
paulson@13437
   504
lemma M_eclose_axioms_L: "M_eclose_axioms(L)"
paulson@13437
   505
  apply (rule M_eclose_axioms.intro)
paulson@13437
   506
   apply (assumption | rule eclose_replacement1 eclose_replacement2)+
paulson@13437
   507
  done
paulson@13437
   508
wenzelm@13428
   509
theorem M_eclose_L: "PROP M_eclose(L)"
wenzelm@13428
   510
  apply (rule M_eclose.intro)
wenzelm@13429
   511
       apply (rule M_datatypes.axioms [OF M_datatypes_L])+
paulson@13437
   512
  apply (rule M_eclose_axioms_L)
wenzelm@13428
   513
  done
paulson@13422
   514
wenzelm@13428
   515
lemmas eclose_closed [intro, simp] = M_eclose.eclose_closed [OF M_eclose_L]
wenzelm@13428
   516
  and eclose_abs [intro, simp] = M_eclose.eclose_abs [OF M_eclose_L]
paulson@13440
   517
  and transrec_replacementI = M_eclose.transrec_replacementI [OF M_eclose_L]
paulson@13422
   518
paulson@13348
   519
end