src/ZF/Constructible/Rec_Separation.thy
author paulson
Wed Oct 09 11:07:13 2002 +0200 (2002-10-09)
changeset 13634 99a593b49b04
parent 13566 52a419210d5c
child 13647 7f6f0ffc45c3
permissions -rw-r--r--
Re-organization of Constructible theories
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 rtrancl_closed = M_trancl.rtrancl_closed [OF M_trancl_L]
wenzelm@13428
   208
  and rtrancl_abs = M_trancl.rtrancl_abs [OF M_trancl_L]
wenzelm@13428
   209
  and trancl_closed = M_trancl.trancl_closed [OF M_trancl_L]
wenzelm@13428
   210
  and trancl_abs = M_trancl.trancl_abs [OF M_trancl_L]
wenzelm@13428
   211
  and wellfounded_on_trancl = M_trancl.wellfounded_on_trancl [OF M_trancl_L]
wenzelm@13428
   212
  and wellfounded_trancl = M_trancl.wellfounded_trancl [OF M_trancl_L]
wenzelm@13428
   213
  and wfrec_relativize = M_trancl.wfrec_relativize [OF M_trancl_L]
wenzelm@13428
   214
  and trans_wfrec_relativize = M_trancl.trans_wfrec_relativize [OF M_trancl_L]
wenzelm@13428
   215
  and trans_wfrec_abs = M_trancl.trans_wfrec_abs [OF M_trancl_L]
wenzelm@13428
   216
  and trans_eq_pair_wfrec_iff = M_trancl.trans_eq_pair_wfrec_iff [OF M_trancl_L]
wenzelm@13428
   217
  and eq_pair_wfrec_iff = M_trancl.eq_pair_wfrec_iff [OF M_trancl_L]
paulson@13363
   218
paulson@13363
   219
declare rtrancl_closed [intro,simp]
paulson@13363
   220
declare rtrancl_abs [simp]
paulson@13363
   221
declare trancl_closed [intro,simp]
paulson@13363
   222
declare trancl_abs [simp]
paulson@13363
   223
paulson@13363
   224
wenzelm@13428
   225
subsection{*@{term L} is Closed Under the Operator @{term list}*}
paulson@13363
   226
paulson@13386
   227
subsubsection{*Instances of Replacement for Lists*}
paulson@13386
   228
paulson@13363
   229
lemma list_replacement1_Reflects:
paulson@13363
   230
 "REFLECTS
paulson@13363
   231
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13363
   232
         is_wfrec(L, iterates_MH(L, is_list_functor(L,A), 0), memsn, u, y)),
paulson@13363
   233
    \<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
   234
         is_wfrec(**Lset(i),
wenzelm@13428
   235
                  iterates_MH(**Lset(i),
paulson@13363
   236
                          is_list_functor(**Lset(i), A), 0), memsn, u, y))]"
wenzelm@13428
   237
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   238
          iterates_MH_reflection list_functor_reflection)
paulson@13363
   239
paulson@13441
   240
wenzelm@13428
   241
lemma list_replacement1:
paulson@13363
   242
   "L(A) ==> iterates_replacement(L, is_list_functor(L,A), 0)"
paulson@13363
   243
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   244
apply (rule strong_replacementI)
wenzelm@13428
   245
apply (rename_tac B)
paulson@13566
   246
apply (rule_tac u="{B,A,n,0,Memrel(succ(n))}" 
paulson@13566
   247
         in gen_separation [OF list_replacement1_Reflects], 
paulson@13566
   248
       simp add: nonempty)
paulson@13566
   249
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13385
   250
apply (rule DPow_LsetI)
paulson@13363
   251
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13566
   252
apply (rule_tac env = "[u,x,A,n,B,0,Memrel(succ(n))]" in mem_iff_sats)
paulson@13434
   253
apply (rule sep_rules is_nat_case_iff_sats list_functor_iff_sats
paulson@13441
   254
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13363
   255
done
paulson@13363
   256
paulson@13441
   257
paulson@13363
   258
lemma list_replacement2_Reflects:
paulson@13363
   259
 "REFLECTS
paulson@13363
   260
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
paulson@13363
   261
         (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
paulson@13363
   262
           is_wfrec (L, iterates_MH (L, is_list_functor(L, A), 0),
paulson@13363
   263
                              msn, u, x)),
paulson@13363
   264
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
wenzelm@13428
   265
         (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
paulson@13363
   266
          successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
wenzelm@13428
   267
           is_wfrec (**Lset(i),
paulson@13363
   268
                 iterates_MH (**Lset(i), is_list_functor(**Lset(i), A), 0),
paulson@13363
   269
                     msn, u, x))]"
wenzelm@13428
   270
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   271
          iterates_MH_reflection list_functor_reflection)
paulson@13363
   272
paulson@13363
   273
wenzelm@13428
   274
lemma list_replacement2:
wenzelm@13428
   275
   "L(A) ==> strong_replacement(L,
wenzelm@13428
   276
         \<lambda>n y. n\<in>nat &
paulson@13363
   277
               (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
wenzelm@13428
   278
               is_wfrec(L, iterates_MH(L,is_list_functor(L,A), 0),
paulson@13363
   279
                        msn, n, y)))"
wenzelm@13428
   280
apply (rule strong_replacementI)
wenzelm@13428
   281
apply (rename_tac B)
paulson@13566
   282
apply (rule_tac u="{A,B,0,nat}" 
paulson@13566
   283
         in gen_separation [OF list_replacement2_Reflects], 
paulson@13566
   284
       simp add: L_nat nonempty)
paulson@13566
   285
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13385
   286
apply (rule DPow_LsetI)
paulson@13363
   287
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13566
   288
apply (rule_tac env = "[u,x,A,B,0,nat]" in mem_iff_sats)
paulson@13434
   289
apply (rule sep_rules is_nat_case_iff_sats list_functor_iff_sats
paulson@13441
   290
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13363
   291
done
paulson@13363
   292
paulson@13386
   293
wenzelm@13428
   294
subsection{*@{term L} is Closed Under the Operator @{term formula}*}
paulson@13386
   295
paulson@13386
   296
subsubsection{*Instances of Replacement for Formulas*}
paulson@13386
   297
paulson@13386
   298
lemma formula_replacement1_Reflects:
paulson@13386
   299
 "REFLECTS
paulson@13386
   300
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13386
   301
         is_wfrec(L, iterates_MH(L, is_formula_functor(L), 0), memsn, u, y)),
paulson@13386
   302
    \<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
   303
         is_wfrec(**Lset(i),
wenzelm@13428
   304
                  iterates_MH(**Lset(i),
paulson@13386
   305
                          is_formula_functor(**Lset(i)), 0), memsn, u, y))]"
wenzelm@13428
   306
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   307
          iterates_MH_reflection formula_functor_reflection)
paulson@13386
   308
wenzelm@13428
   309
lemma formula_replacement1:
paulson@13386
   310
   "iterates_replacement(L, is_formula_functor(L), 0)"
paulson@13386
   311
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   312
apply (rule strong_replacementI)
wenzelm@13428
   313
apply (rename_tac B)
paulson@13566
   314
apply (rule_tac u="{B,n,0,Memrel(succ(n))}" 
paulson@13566
   315
         in gen_separation [OF formula_replacement1_Reflects], 
paulson@13566
   316
       simp add: nonempty)
paulson@13566
   317
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13386
   318
apply (rule DPow_LsetI)
paulson@13386
   319
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13566
   320
apply (rule_tac env = "[u,x,n,B,0,Memrel(succ(n))]" in mem_iff_sats)
paulson@13434
   321
apply (rule sep_rules is_nat_case_iff_sats formula_functor_iff_sats
paulson@13441
   322
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13386
   323
done
paulson@13386
   324
paulson@13386
   325
lemma formula_replacement2_Reflects:
paulson@13386
   326
 "REFLECTS
paulson@13386
   327
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
paulson@13386
   328
         (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
paulson@13386
   329
           is_wfrec (L, iterates_MH (L, is_formula_functor(L), 0),
paulson@13386
   330
                              msn, u, x)),
paulson@13386
   331
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
wenzelm@13428
   332
         (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
paulson@13386
   333
          successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
wenzelm@13428
   334
           is_wfrec (**Lset(i),
paulson@13386
   335
                 iterates_MH (**Lset(i), is_formula_functor(**Lset(i)), 0),
paulson@13386
   336
                     msn, u, x))]"
wenzelm@13428
   337
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   338
          iterates_MH_reflection formula_functor_reflection)
paulson@13386
   339
paulson@13386
   340
wenzelm@13428
   341
lemma formula_replacement2:
wenzelm@13428
   342
   "strong_replacement(L,
wenzelm@13428
   343
         \<lambda>n y. n\<in>nat &
paulson@13386
   344
               (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
wenzelm@13428
   345
               is_wfrec(L, iterates_MH(L,is_formula_functor(L), 0),
paulson@13386
   346
                        msn, n, y)))"
wenzelm@13428
   347
apply (rule strong_replacementI)
wenzelm@13428
   348
apply (rename_tac B)
paulson@13566
   349
apply (rule_tac u="{B,0,nat}" 
paulson@13566
   350
         in gen_separation [OF formula_replacement2_Reflects], 
paulson@13566
   351
       simp add: nonempty L_nat)
paulson@13566
   352
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13386
   353
apply (rule DPow_LsetI)
paulson@13386
   354
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13566
   355
apply (rule_tac env = "[u,x,B,0,nat]" in mem_iff_sats)
paulson@13434
   356
apply (rule sep_rules is_nat_case_iff_sats formula_functor_iff_sats
paulson@13441
   357
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13386
   358
done
paulson@13386
   359
paulson@13386
   360
text{*NB The proofs for type @{term formula} are virtually identical to those
paulson@13386
   361
for @{term "list(A)"}.  It was a cut-and-paste job! *}
paulson@13386
   362
paulson@13387
   363
paulson@13437
   364
subsubsection{*The Formula @{term is_nth}, Internalized*}
paulson@13437
   365
paulson@13437
   366
(* "is_nth(M,n,l,Z) == 
paulson@13437
   367
      \<exists>X[M]. \<exists>sn[M]. \<exists>msn[M]. 
paulson@13437
   368
       2       1       0
paulson@13437
   369
       successor(M,n,sn) & membership(M,sn,msn) &
paulson@13437
   370
       is_wfrec(M, iterates_MH(M, is_tl(M), l), msn, n, X) &
paulson@13493
   371
       is_hd(M,X,Z)" *)
paulson@13437
   372
constdefs nth_fm :: "[i,i,i]=>i"
paulson@13437
   373
    "nth_fm(n,l,Z) == 
paulson@13437
   374
       Exists(Exists(Exists(
paulson@13493
   375
         And(succ_fm(n#+3,1),
paulson@13493
   376
          And(Memrel_fm(1,0),
paulson@13493
   377
           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
   378
paulson@13493
   379
lemma nth_fm_type [TC]:
paulson@13493
   380
 "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> nth_fm(x,y,z) \<in> formula"
paulson@13493
   381
by (simp add: nth_fm_def)
paulson@13493
   382
paulson@13493
   383
lemma sats_nth_fm [simp]:
paulson@13493
   384
   "[| x < length(env); y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13493
   385
    ==> sats(A, nth_fm(x,y,z), env) <->
paulson@13493
   386
        is_nth(**A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13493
   387
apply (frule lt_length_in_nat, assumption)  
paulson@13493
   388
apply (simp add: nth_fm_def is_nth_def sats_is_wfrec_fm sats_iterates_MH_fm) 
paulson@13493
   389
done
paulson@13493
   390
paulson@13493
   391
lemma nth_iff_sats:
paulson@13493
   392
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13493
   393
          i < length(env); j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13493
   394
       ==> is_nth(**A, x, y, z) <-> sats(A, nth_fm(i,j,k), env)"
paulson@13493
   395
by (simp add: sats_nth_fm)
paulson@13437
   396
paulson@13437
   397
theorem nth_reflection:
paulson@13437
   398
     "REFLECTS[\<lambda>x. is_nth(L, f(x), g(x), h(x)),  
paulson@13437
   399
               \<lambda>i x. is_nth(**Lset(i), f(x), g(x), h(x))]"
paulson@13437
   400
apply (simp only: is_nth_def setclass_simps)
paulson@13437
   401
apply (intro FOL_reflections function_reflections is_wfrec_reflection 
paulson@13437
   402
             iterates_MH_reflection hd_reflection tl_reflection) 
paulson@13437
   403
done
paulson@13437
   404
paulson@13437
   405
paulson@13409
   406
subsubsection{*An Instance of Replacement for @{term nth}*}
paulson@13409
   407
paulson@13409
   408
lemma nth_replacement_Reflects:
paulson@13409
   409
 "REFLECTS
paulson@13409
   410
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13409
   411
         is_wfrec(L, iterates_MH(L, is_tl(L), z), memsn, u, y)),
paulson@13409
   412
    \<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
   413
         is_wfrec(**Lset(i),
wenzelm@13428
   414
                  iterates_MH(**Lset(i),
paulson@13409
   415
                          is_tl(**Lset(i)), z), memsn, u, y))]"
wenzelm@13428
   416
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   417
          iterates_MH_reflection list_functor_reflection tl_reflection)
paulson@13409
   418
wenzelm@13428
   419
lemma nth_replacement:
paulson@13409
   420
   "L(w) ==> iterates_replacement(L, %l t. is_tl(L,l,t), w)"
paulson@13409
   421
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   422
apply (rule strong_replacementI)
paulson@13566
   423
apply (rule_tac u="{A,n,w,Memrel(succ(n))}" 
paulson@13566
   424
         in gen_separation [OF nth_replacement_Reflects], 
paulson@13566
   425
       simp add: nonempty)
paulson@13566
   426
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13409
   427
apply (rule DPow_LsetI)
paulson@13409
   428
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13566
   429
apply (rule_tac env = "[u,x,A,w,Memrel(succ(n))]" in mem_iff_sats)
paulson@13434
   430
apply (rule sep_rules is_nat_case_iff_sats tl_iff_sats
paulson@13441
   431
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13409
   432
done
paulson@13409
   433
paulson@13422
   434
paulson@13422
   435
subsubsection{*Instantiating the locale @{text M_datatypes}*}
wenzelm@13428
   436
paulson@13437
   437
lemma M_datatypes_axioms_L: "M_datatypes_axioms(L)"
wenzelm@13428
   438
  apply (rule M_datatypes_axioms.intro)
wenzelm@13428
   439
      apply (assumption | rule
wenzelm@13428
   440
        list_replacement1 list_replacement2
wenzelm@13428
   441
        formula_replacement1 formula_replacement2
wenzelm@13428
   442
        nth_replacement)+
wenzelm@13428
   443
  done
paulson@13422
   444
paulson@13437
   445
theorem M_datatypes_L: "PROP M_datatypes(L)"
paulson@13437
   446
  apply (rule M_datatypes.intro)
paulson@13634
   447
      apply (rule M_trancl.axioms [OF M_trancl_L])+
paulson@13441
   448
 apply (rule M_datatypes_axioms_L) 
paulson@13437
   449
 done
paulson@13437
   450
wenzelm@13428
   451
lemmas list_closed = M_datatypes.list_closed [OF M_datatypes_L]
wenzelm@13428
   452
  and formula_closed = M_datatypes.formula_closed [OF M_datatypes_L]
wenzelm@13428
   453
  and list_abs = M_datatypes.list_abs [OF M_datatypes_L]
wenzelm@13428
   454
  and formula_abs = M_datatypes.formula_abs [OF M_datatypes_L]
wenzelm@13428
   455
  and nth_abs = M_datatypes.nth_abs [OF M_datatypes_L]
paulson@13409
   456
paulson@13422
   457
declare list_closed [intro,simp]
paulson@13422
   458
declare formula_closed [intro,simp]
paulson@13422
   459
declare list_abs [simp]
paulson@13422
   460
declare formula_abs [simp]
paulson@13422
   461
declare nth_abs [simp]
paulson@13422
   462
paulson@13422
   463
wenzelm@13428
   464
subsection{*@{term L} is Closed Under the Operator @{term eclose}*}
paulson@13422
   465
paulson@13422
   466
subsubsection{*Instances of Replacement for @{term eclose}*}
paulson@13422
   467
paulson@13422
   468
lemma eclose_replacement1_Reflects:
paulson@13422
   469
 "REFLECTS
paulson@13422
   470
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13422
   471
         is_wfrec(L, iterates_MH(L, big_union(L), A), memsn, u, y)),
paulson@13422
   472
    \<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
   473
         is_wfrec(**Lset(i),
wenzelm@13428
   474
                  iterates_MH(**Lset(i), big_union(**Lset(i)), A),
paulson@13422
   475
                  memsn, u, y))]"
wenzelm@13428
   476
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   477
          iterates_MH_reflection)
paulson@13422
   478
wenzelm@13428
   479
lemma eclose_replacement1:
paulson@13422
   480
   "L(A) ==> iterates_replacement(L, big_union(L), A)"
paulson@13422
   481
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   482
apply (rule strong_replacementI)
wenzelm@13428
   483
apply (rename_tac B)
paulson@13566
   484
apply (rule_tac u="{B,A,n,Memrel(succ(n))}" 
paulson@13566
   485
         in gen_separation [OF eclose_replacement1_Reflects], simp)
paulson@13566
   486
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13422
   487
apply (rule DPow_LsetI)
paulson@13422
   488
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13566
   489
apply (rule_tac env = "[u,x,A,n,B,Memrel(succ(n))]" in mem_iff_sats)
paulson@13434
   490
apply (rule sep_rules iterates_MH_iff_sats is_nat_case_iff_sats
paulson@13441
   491
             is_wfrec_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
paulson@13409
   492
done
paulson@13409
   493
paulson@13422
   494
paulson@13422
   495
lemma eclose_replacement2_Reflects:
paulson@13422
   496
 "REFLECTS
paulson@13422
   497
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
paulson@13422
   498
         (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
paulson@13422
   499
           is_wfrec (L, iterates_MH (L, big_union(L), A),
paulson@13422
   500
                              msn, u, x)),
paulson@13422
   501
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
wenzelm@13428
   502
         (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
paulson@13422
   503
          successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
wenzelm@13428
   504
           is_wfrec (**Lset(i),
paulson@13422
   505
                 iterates_MH (**Lset(i), big_union(**Lset(i)), A),
paulson@13422
   506
                     msn, u, x))]"
wenzelm@13428
   507
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   508
          iterates_MH_reflection)
paulson@13422
   509
paulson@13422
   510
wenzelm@13428
   511
lemma eclose_replacement2:
wenzelm@13428
   512
   "L(A) ==> strong_replacement(L,
wenzelm@13428
   513
         \<lambda>n y. n\<in>nat &
paulson@13422
   514
               (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
wenzelm@13428
   515
               is_wfrec(L, iterates_MH(L,big_union(L), A),
paulson@13422
   516
                        msn, n, y)))"
wenzelm@13428
   517
apply (rule strong_replacementI)
wenzelm@13428
   518
apply (rename_tac B)
paulson@13566
   519
apply (rule_tac u="{A,B,nat}" 
paulson@13566
   520
         in gen_separation [OF eclose_replacement2_Reflects], simp add: L_nat)
paulson@13566
   521
apply (drule mem_Lset_imp_subset_Lset, clarsimp)
paulson@13422
   522
apply (rule DPow_LsetI)
paulson@13422
   523
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13566
   524
apply (rule_tac env = "[u,x,A,B,nat]" in mem_iff_sats)
paulson@13434
   525
apply (rule sep_rules is_nat_case_iff_sats iterates_MH_iff_sats
paulson@13441
   526
              is_wfrec_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
paulson@13422
   527
done
paulson@13422
   528
paulson@13422
   529
paulson@13422
   530
subsubsection{*Instantiating the locale @{text M_eclose}*}
paulson@13422
   531
paulson@13437
   532
lemma M_eclose_axioms_L: "M_eclose_axioms(L)"
paulson@13437
   533
  apply (rule M_eclose_axioms.intro)
paulson@13437
   534
   apply (assumption | rule eclose_replacement1 eclose_replacement2)+
paulson@13437
   535
  done
paulson@13437
   536
wenzelm@13428
   537
theorem M_eclose_L: "PROP M_eclose(L)"
wenzelm@13428
   538
  apply (rule M_eclose.intro)
wenzelm@13429
   539
       apply (rule M_datatypes.axioms [OF M_datatypes_L])+
paulson@13437
   540
  apply (rule M_eclose_axioms_L)
wenzelm@13428
   541
  done
paulson@13422
   542
wenzelm@13428
   543
lemmas eclose_closed [intro, simp] = M_eclose.eclose_closed [OF M_eclose_L]
wenzelm@13428
   544
  and eclose_abs [intro, simp] = M_eclose.eclose_abs [OF M_eclose_L]
paulson@13440
   545
  and transrec_replacementI = M_eclose.transrec_replacementI [OF M_eclose_L]
paulson@13422
   546
paulson@13348
   547
end