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