src/ZF/Constructible/Rec_Separation.thy
author paulson
Tue Jul 30 11:39:57 2002 +0200 (2002-07-30)
changeset 13434 78b93a667c01
parent 13429 2232810416fc
child 13437 01b3fc0cc1b8
permissions -rw-r--r--
better sats rules for higher-order operators
wenzelm@13429
     1
wenzelm@13429
     2
header {*Separation for Facts About Recursion*}
paulson@13348
     3
paulson@13363
     4
theory Rec_Separation = Separation + Datatype_absolute:
paulson@13348
     5
paulson@13348
     6
text{*This theory proves all instances needed for locales @{text
paulson@13348
     7
"M_trancl"}, @{text "M_wfrank"} and @{text "M_datatypes"}*}
paulson@13348
     8
paulson@13363
     9
lemma eq_succ_imp_lt: "[|i = succ(j); Ord(i)|] ==> j<i"
wenzelm@13428
    10
by simp
paulson@13363
    11
paulson@13348
    12
subsection{*The Locale @{text "M_trancl"}*}
paulson@13348
    13
paulson@13348
    14
subsubsection{*Separation for Reflexive/Transitive Closure*}
paulson@13348
    15
paulson@13348
    16
text{*First, The Defining Formula*}
paulson@13348
    17
paulson@13348
    18
(* "rtran_closure_mem(M,A,r,p) ==
wenzelm@13428
    19
      \<exists>nnat[M]. \<exists>n[M]. \<exists>n'[M].
paulson@13348
    20
       omega(M,nnat) & n\<in>nnat & successor(M,n,n') &
paulson@13348
    21
       (\<exists>f[M]. typed_function(M,n',A,f) &
wenzelm@13428
    22
        (\<exists>x[M]. \<exists>y[M]. \<exists>zero[M]. pair(M,x,y,p) & empty(M,zero) &
wenzelm@13428
    23
          fun_apply(M,f,zero,x) & fun_apply(M,f,n,y)) &
wenzelm@13428
    24
        (\<forall>j[M]. j\<in>n -->
wenzelm@13428
    25
          (\<exists>fj[M]. \<exists>sj[M]. \<exists>fsj[M]. \<exists>ffp[M].
wenzelm@13428
    26
            fun_apply(M,f,j,fj) & successor(M,j,sj) &
wenzelm@13428
    27
            fun_apply(M,f,sj,fsj) & pair(M,fj,fsj,ffp) & ffp \<in> r)))"*)
paulson@13348
    28
constdefs rtran_closure_mem_fm :: "[i,i,i]=>i"
wenzelm@13428
    29
 "rtran_closure_mem_fm(A,r,p) ==
paulson@13348
    30
   Exists(Exists(Exists(
paulson@13348
    31
    And(omega_fm(2),
paulson@13348
    32
     And(Member(1,2),
paulson@13348
    33
      And(succ_fm(1,0),
paulson@13348
    34
       Exists(And(typed_function_fm(1, A#+4, 0),
wenzelm@13428
    35
        And(Exists(Exists(Exists(
wenzelm@13428
    36
              And(pair_fm(2,1,p#+7),
wenzelm@13428
    37
               And(empty_fm(0),
wenzelm@13428
    38
                And(fun_apply_fm(3,0,2), fun_apply_fm(3,5,1))))))),
wenzelm@13428
    39
            Forall(Implies(Member(0,3),
wenzelm@13428
    40
             Exists(Exists(Exists(Exists(
wenzelm@13428
    41
              And(fun_apply_fm(5,4,3),
wenzelm@13428
    42
               And(succ_fm(4,2),
wenzelm@13428
    43
                And(fun_apply_fm(5,2,1),
wenzelm@13428
    44
                 And(pair_fm(3,1,0), Member(0,r#+9))))))))))))))))))))"
paulson@13348
    45
paulson@13348
    46
paulson@13348
    47
lemma rtran_closure_mem_type [TC]:
paulson@13348
    48
 "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> rtran_closure_mem_fm(x,y,z) \<in> formula"
wenzelm@13428
    49
by (simp add: rtran_closure_mem_fm_def)
paulson@13348
    50
paulson@13348
    51
lemma arity_rtran_closure_mem_fm [simp]:
wenzelm@13428
    52
     "[| x \<in> nat; y \<in> nat; z \<in> nat |]
paulson@13348
    53
      ==> arity(rtran_closure_mem_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
wenzelm@13428
    54
by (simp add: rtran_closure_mem_fm_def succ_Un_distrib [symmetric] Un_ac)
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@13348
    68
theorem 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))"
wenzelm@13428
    78
apply (rule separation_CollectI)
wenzelm@13428
    79
apply (rule_tac A="{r,A,z}" in subset_LsetE, blast )
paulson@13348
    80
apply (rule ReflectsE [OF rtran_closure_mem_reflection], assumption)
wenzelm@13428
    81
apply (drule subset_Lset_ltD, assumption)
paulson@13348
    82
apply (erule reflection_imp_L_separation)
paulson@13348
    83
  apply (simp_all add: lt_Ord2)
paulson@13385
    84
apply (rule DPow_LsetI)
paulson@13348
    85
apply (rename_tac u)
paulson@13348
    86
apply (rule_tac env = "[u,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@13348
   169
subsection{*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
paulson@13348
   181
lemma wellfounded_trancl_separation:
wenzelm@13428
   182
         "[| L(r); L(Z) |] ==>
wenzelm@13428
   183
          separation (L, \<lambda>x.
wenzelm@13428
   184
              \<exists>w[L]. \<exists>wx[L]. \<exists>rp[L].
wenzelm@13428
   185
               w \<in> Z & pair(L,w,x,wx) & tran_closure(L,r,rp) & wx \<in> rp)"
wenzelm@13428
   186
apply (rule separation_CollectI)
wenzelm@13428
   187
apply (rule_tac A="{r,Z,z}" in subset_LsetE, blast )
paulson@13348
   188
apply (rule ReflectsE [OF wellfounded_trancl_reflects], assumption)
wenzelm@13428
   189
apply (drule subset_Lset_ltD, assumption)
paulson@13348
   190
apply (erule reflection_imp_L_separation)
paulson@13348
   191
  apply (simp_all add: lt_Ord2)
paulson@13385
   192
apply (rule DPow_LsetI)
wenzelm@13428
   193
apply (rename_tac u)
paulson@13348
   194
apply (rule bex_iff_sats conj_iff_sats)+
wenzelm@13428
   195
apply (rule_tac env = "[w,u,r,Z]" in mem_iff_sats)
paulson@13348
   196
apply (rule sep_rules tran_closure_iff_sats | simp)+
paulson@13348
   197
done
paulson@13348
   198
paulson@13363
   199
paulson@13363
   200
subsubsection{*Instantiating the locale @{text M_trancl}*}
wenzelm@13428
   201
wenzelm@13429
   202
theorem M_trancl_L: "PROP M_trancl(L)"
wenzelm@13429
   203
  apply (rule M_trancl.intro)
wenzelm@13429
   204
    apply (rule M_axioms.axioms [OF M_axioms_L])+
wenzelm@13428
   205
  apply (rule M_trancl_axioms.intro)
wenzelm@13428
   206
   apply (assumption | rule
wenzelm@13428
   207
     rtrancl_separation wellfounded_trancl_separation)+
wenzelm@13428
   208
  done
paulson@13363
   209
wenzelm@13428
   210
lemmas iterates_abs = M_trancl.iterates_abs [OF M_trancl_L]
wenzelm@13428
   211
  and rtran_closure_rtrancl = M_trancl.rtran_closure_rtrancl [OF M_trancl_L]
wenzelm@13428
   212
  and rtrancl_closed = M_trancl.rtrancl_closed [OF M_trancl_L]
wenzelm@13428
   213
  and rtrancl_abs = M_trancl.rtrancl_abs [OF M_trancl_L]
wenzelm@13428
   214
  and trancl_closed = M_trancl.trancl_closed [OF M_trancl_L]
wenzelm@13428
   215
  and trancl_abs = M_trancl.trancl_abs [OF M_trancl_L]
wenzelm@13428
   216
  and wellfounded_on_trancl = M_trancl.wellfounded_on_trancl [OF M_trancl_L]
wenzelm@13428
   217
  and wellfounded_trancl = M_trancl.wellfounded_trancl [OF M_trancl_L]
wenzelm@13428
   218
  and wfrec_relativize = M_trancl.wfrec_relativize [OF M_trancl_L]
wenzelm@13428
   219
  and trans_wfrec_relativize = M_trancl.trans_wfrec_relativize [OF M_trancl_L]
wenzelm@13428
   220
  and trans_wfrec_abs = M_trancl.trans_wfrec_abs [OF M_trancl_L]
wenzelm@13428
   221
  and trans_eq_pair_wfrec_iff = M_trancl.trans_eq_pair_wfrec_iff [OF M_trancl_L]
wenzelm@13428
   222
  and eq_pair_wfrec_iff = M_trancl.eq_pair_wfrec_iff [OF M_trancl_L]
paulson@13363
   223
paulson@13363
   224
declare rtrancl_closed [intro,simp]
paulson@13363
   225
declare rtrancl_abs [simp]
paulson@13363
   226
declare trancl_closed [intro,simp]
paulson@13363
   227
declare trancl_abs [simp]
paulson@13363
   228
paulson@13363
   229
paulson@13348
   230
subsection{*Well-Founded Recursion!*}
paulson@13348
   231
paulson@13352
   232
(* M_is_recfun :: "[i=>o, [i,i,i]=>o, i, i, i] => o"
wenzelm@13428
   233
   "M_is_recfun(M,MH,r,a,f) ==
wenzelm@13428
   234
     \<forall>z[M]. z \<in> f <->
paulson@13348
   235
            5      4       3       2       1           0
wenzelm@13428
   236
            (\<exists>x[M]. \<exists>y[M]. \<exists>xa[M]. \<exists>sx[M]. \<exists>r_sx[M]. \<exists>f_r_sx[M].
wenzelm@13428
   237
               pair(M,x,y,z) & pair(M,x,a,xa) & upair(M,x,x,sx) &
paulson@13348
   238
               pre_image(M,r,sx,r_sx) & restriction(M,f,r_sx,f_r_sx) &
paulson@13348
   239
               xa \<in> r & MH(x, f_r_sx, y))"
paulson@13348
   240
*)
paulson@13348
   241
paulson@13434
   242
text{*The three arguments of @{term p} are always 5, 0, 4.*}
paulson@13434
   243
constdefs is_recfun_fm :: "[i, i, i, i]=>i"
paulson@13434
   244
 "is_recfun_fm(p,r,a,f) == 
paulson@13348
   245
   Forall(Iff(Member(0,succ(f)),
paulson@13348
   246
    Exists(Exists(Exists(Exists(Exists(Exists(
paulson@13348
   247
     And(pair_fm(5,4,6),
paulson@13348
   248
      And(pair_fm(5,a#+7,3),
paulson@13348
   249
       And(upair_fm(5,5,2),
paulson@13348
   250
        And(pre_image_fm(r#+7,2,1),
paulson@13348
   251
         And(restriction_fm(f#+7,1,0),
paulson@13434
   252
          And(Member(3,r#+7), p))))))))))))))"
paulson@13348
   253
paulson@13348
   254
paulson@13348
   255
lemma is_recfun_type [TC]:
paulson@13434
   256
     "[| p \<in> formula; x \<in> nat; y \<in> nat; z \<in> nat |] 
paulson@13348
   257
      ==> is_recfun_fm(p,x,y,z) \<in> formula"
wenzelm@13428
   258
by (simp add: is_recfun_fm_def)
paulson@13348
   259
paulson@13348
   260
lemma sats_is_recfun_fm:
paulson@13434
   261
  assumes MH_iff_sats: 
paulson@13434
   262
      "!!a0 a1 a2 a3 a4 a5 a6. 
paulson@13434
   263
        [|a0\<in>A; a1\<in>A; a2\<in>A; a3\<in>A; a4\<in>A; a5\<in>A; a6\<in>A|] ==> 
paulson@13434
   264
        MH(a5, a0, a4) <-> 
paulson@13434
   265
       sats(A, p, Cons(a0,Cons(a1,Cons(a2,Cons(a3,Cons(a4,Cons(a5,Cons(a6,env))))))))"
paulson@13434
   266
  shows 
paulson@13348
   267
      "[|x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
wenzelm@13428
   268
       ==> sats(A, is_recfun_fm(p,x,y,z), env) <->
paulson@13352
   269
           M_is_recfun(**A, MH, nth(x,env), nth(y,env), nth(z,env))"
paulson@13348
   270
by (simp add: is_recfun_fm_def M_is_recfun_def MH_iff_sats [THEN iff_sym])
paulson@13434
   271
(*
paulson@13434
   272
apply (rule ball_cong bex_cong iff_cong conj_cong refl iff_refl) +
paulson@13434
   273
 sats(A, p,
paulson@13434
   274
   Cons(xf, Cons(xe, Cons(xd, Cons(xc, Cons(xb, Cons(xaa, Cons(xa, env)))))))) 
paulson@13434
   275
\<longleftrightarrow> MH(xaa, xf, xb)
paulson@13434
   276
paulson@13434
   277
MH(nth(5,env), nth(0,env), nth(4,env)) <-> sats(A, p, env);
paulson@13434
   278
*)
paulson@13434
   279
paulson@13434
   280
(*      "!!x y z. [|x\<in>A; y\<in>A; z\<in>A|] ==> MH(x,y,z) <-> sats(A, p, env)"
paulson@13434
   281
*)
paulson@13348
   282
paulson@13348
   283
lemma is_recfun_iff_sats:
paulson@13434
   284
  assumes MH_iff_sats: 
paulson@13434
   285
      "!!a0 a1 a2 a3 a4 a5 a6. 
paulson@13434
   286
        [|a0\<in>A; a1\<in>A; a2\<in>A; a3\<in>A; a4\<in>A; a5\<in>A; a6\<in>A|] ==> 
paulson@13434
   287
        MH(a5, a0, a4) <-> 
paulson@13434
   288
       sats(A, p, Cons(a0,Cons(a1,Cons(a2,Cons(a3,Cons(a4,Cons(a5,Cons(a6,env))))))))"
paulson@13434
   289
  shows
paulson@13434
   290
  "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
paulson@13348
   291
      i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
wenzelm@13428
   292
   ==> M_is_recfun(**A, MH, x, y, z) <-> sats(A, is_recfun_fm(p,i,j,k), env)"
paulson@13434
   293
apply (rule iff_sym) 
paulson@13434
   294
apply (rule iff_trans)
paulson@13434
   295
apply (rule sats_is_recfun_fm [of A MH]) 
paulson@13434
   296
apply (rule MH_iff_sats, simp_all) 
paulson@13434
   297
done
paulson@13434
   298
(*FIXME: surely proof can be improved?*)
paulson@13434
   299
paulson@13348
   300
paulson@13348
   301
theorem is_recfun_reflection:
paulson@13348
   302
  assumes MH_reflection:
wenzelm@13428
   303
    "!!f g h. REFLECTS[\<lambda>x. MH(L, f(x), g(x), h(x)),
paulson@13348
   304
                     \<lambda>i x. MH(**Lset(i), f(x), g(x), h(x))]"
wenzelm@13428
   305
  shows "REFLECTS[\<lambda>x. M_is_recfun(L, MH(L), f(x), g(x), h(x)),
paulson@13352
   306
               \<lambda>i x. M_is_recfun(**Lset(i), MH(**Lset(i)), f(x), g(x), h(x))]"
paulson@13348
   307
apply (simp (no_asm_use) only: M_is_recfun_def setclass_simps)
wenzelm@13428
   308
apply (intro FOL_reflections function_reflections
wenzelm@13428
   309
             restriction_reflection MH_reflection)
paulson@13348
   310
done
paulson@13348
   311
paulson@13363
   312
text{*Currently, @{text sats}-theorems for higher-order operators don't seem
paulson@13363
   313
useful.  Reflection theorems do work, though.  This one avoids the repetition
paulson@13363
   314
of the @{text MH}-term.*}
paulson@13363
   315
theorem is_wfrec_reflection:
paulson@13363
   316
  assumes MH_reflection:
wenzelm@13428
   317
    "!!f g h. REFLECTS[\<lambda>x. MH(L, f(x), g(x), h(x)),
paulson@13363
   318
                     \<lambda>i x. MH(**Lset(i), f(x), g(x), h(x))]"
wenzelm@13428
   319
  shows "REFLECTS[\<lambda>x. is_wfrec(L, MH(L), f(x), g(x), h(x)),
paulson@13363
   320
               \<lambda>i x. is_wfrec(**Lset(i), MH(**Lset(i)), f(x), g(x), h(x))]"
paulson@13363
   321
apply (simp (no_asm_use) only: is_wfrec_def setclass_simps)
wenzelm@13428
   322
apply (intro FOL_reflections MH_reflection is_recfun_reflection)
paulson@13363
   323
done
paulson@13363
   324
paulson@13363
   325
subsection{*The Locale @{text "M_wfrank"}*}
paulson@13363
   326
paulson@13363
   327
subsubsection{*Separation for @{term "wfrank"}*}
paulson@13348
   328
paulson@13348
   329
lemma wfrank_Reflects:
paulson@13348
   330
 "REFLECTS[\<lambda>x. \<forall>rplus[L]. tran_closure(L,r,rplus) -->
paulson@13352
   331
              ~ (\<exists>f[L]. M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f)),
paulson@13348
   332
      \<lambda>i x. \<forall>rplus \<in> Lset(i). tran_closure(**Lset(i),r,rplus) -->
wenzelm@13428
   333
         ~ (\<exists>f \<in> Lset(i).
wenzelm@13428
   334
            M_is_recfun(**Lset(i), %x f y. is_range(**Lset(i),f,y),
paulson@13352
   335
                        rplus, x, f))]"
wenzelm@13428
   336
by (intro FOL_reflections function_reflections is_recfun_reflection tran_closure_reflection)
paulson@13348
   337
paulson@13348
   338
lemma wfrank_separation:
paulson@13348
   339
     "L(r) ==>
paulson@13348
   340
      separation (L, \<lambda>x. \<forall>rplus[L]. tran_closure(L,r,rplus) -->
paulson@13352
   341
         ~ (\<exists>f[L]. M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f)))"
wenzelm@13428
   342
apply (rule separation_CollectI)
wenzelm@13428
   343
apply (rule_tac A="{r,z}" in subset_LsetE, blast )
paulson@13348
   344
apply (rule ReflectsE [OF wfrank_Reflects], assumption)
wenzelm@13428
   345
apply (drule subset_Lset_ltD, assumption)
paulson@13348
   346
apply (erule reflection_imp_L_separation)
paulson@13348
   347
  apply (simp_all add: lt_Ord2, clarify)
paulson@13385
   348
apply (rule DPow_LsetI)
wenzelm@13428
   349
apply (rename_tac u)
paulson@13348
   350
apply (rule ball_iff_sats imp_iff_sats)+
paulson@13348
   351
apply (rule_tac env="[rplus,u,r]" in tran_closure_iff_sats)
paulson@13348
   352
apply (rule sep_rules is_recfun_iff_sats | simp)+
paulson@13348
   353
done
paulson@13348
   354
paulson@13348
   355
paulson@13363
   356
subsubsection{*Replacement for @{term "wfrank"}*}
paulson@13348
   357
paulson@13348
   358
lemma wfrank_replacement_Reflects:
wenzelm@13428
   359
 "REFLECTS[\<lambda>z. \<exists>x[L]. x \<in> A &
paulson@13348
   360
        (\<forall>rplus[L]. tran_closure(L,r,rplus) -->
wenzelm@13428
   361
         (\<exists>y[L]. \<exists>f[L]. pair(L,x,y,z)  &
paulson@13352
   362
                        M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f) &
paulson@13348
   363
                        is_range(L,f,y))),
wenzelm@13428
   364
 \<lambda>i z. \<exists>x \<in> Lset(i). x \<in> A &
paulson@13348
   365
      (\<forall>rplus \<in> Lset(i). tran_closure(**Lset(i),r,rplus) -->
wenzelm@13428
   366
       (\<exists>y \<in> Lset(i). \<exists>f \<in> Lset(i). pair(**Lset(i),x,y,z)  &
paulson@13352
   367
         M_is_recfun(**Lset(i), %x f y. is_range(**Lset(i),f,y), rplus, x, f) &
paulson@13348
   368
         is_range(**Lset(i),f,y)))]"
paulson@13348
   369
by (intro FOL_reflections function_reflections fun_plus_reflections
paulson@13348
   370
             is_recfun_reflection tran_closure_reflection)
paulson@13348
   371
paulson@13348
   372
paulson@13348
   373
lemma wfrank_strong_replacement:
paulson@13348
   374
     "L(r) ==>
wenzelm@13428
   375
      strong_replacement(L, \<lambda>x z.
paulson@13348
   376
         \<forall>rplus[L]. tran_closure(L,r,rplus) -->
wenzelm@13428
   377
         (\<exists>y[L]. \<exists>f[L]. pair(L,x,y,z)  &
paulson@13352
   378
                        M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f) &
paulson@13348
   379
                        is_range(L,f,y)))"
wenzelm@13428
   380
apply (rule strong_replacementI)
paulson@13348
   381
apply (rule rallI)
wenzelm@13428
   382
apply (rename_tac B)
wenzelm@13428
   383
apply (rule separation_CollectI)
wenzelm@13428
   384
apply (rule_tac A="{B,r,z}" in subset_LsetE, blast )
paulson@13348
   385
apply (rule ReflectsE [OF wfrank_replacement_Reflects], assumption)
wenzelm@13428
   386
apply (drule subset_Lset_ltD, assumption)
paulson@13348
   387
apply (erule reflection_imp_L_separation)
paulson@13348
   388
  apply (simp_all add: lt_Ord2)
paulson@13385
   389
apply (rule DPow_LsetI)
wenzelm@13428
   390
apply (rename_tac u)
paulson@13348
   391
apply (rule bex_iff_sats ball_iff_sats conj_iff_sats)+
wenzelm@13428
   392
apply (rule_tac env = "[x,u,B,r]" in mem_iff_sats)
paulson@13348
   393
apply (rule sep_rules tran_closure_iff_sats is_recfun_iff_sats | simp)+
paulson@13348
   394
done
paulson@13348
   395
paulson@13348
   396
paulson@13363
   397
subsubsection{*Separation for Proving @{text Ord_wfrank_range}*}
paulson@13348
   398
paulson@13348
   399
lemma Ord_wfrank_Reflects:
wenzelm@13428
   400
 "REFLECTS[\<lambda>x. \<forall>rplus[L]. tran_closure(L,r,rplus) -->
wenzelm@13428
   401
          ~ (\<forall>f[L]. \<forall>rangef[L].
paulson@13348
   402
             is_range(L,f,rangef) -->
paulson@13352
   403
             M_is_recfun(L, \<lambda>x f y. is_range(L,f,y), rplus, x, f) -->
paulson@13348
   404
             ordinal(L,rangef)),
wenzelm@13428
   405
      \<lambda>i x. \<forall>rplus \<in> Lset(i). tran_closure(**Lset(i),r,rplus) -->
wenzelm@13428
   406
          ~ (\<forall>f \<in> Lset(i). \<forall>rangef \<in> Lset(i).
paulson@13348
   407
             is_range(**Lset(i),f,rangef) -->
wenzelm@13428
   408
             M_is_recfun(**Lset(i), \<lambda>x f y. is_range(**Lset(i),f,y),
paulson@13352
   409
                         rplus, x, f) -->
paulson@13348
   410
             ordinal(**Lset(i),rangef))]"
wenzelm@13428
   411
by (intro FOL_reflections function_reflections is_recfun_reflection
paulson@13348
   412
          tran_closure_reflection ordinal_reflection)
paulson@13348
   413
paulson@13348
   414
lemma  Ord_wfrank_separation:
paulson@13348
   415
     "L(r) ==>
paulson@13348
   416
      separation (L, \<lambda>x.
wenzelm@13428
   417
         \<forall>rplus[L]. tran_closure(L,r,rplus) -->
wenzelm@13428
   418
          ~ (\<forall>f[L]. \<forall>rangef[L].
paulson@13348
   419
             is_range(L,f,rangef) -->
paulson@13352
   420
             M_is_recfun(L, \<lambda>x f y. is_range(L,f,y), rplus, x, f) -->
wenzelm@13428
   421
             ordinal(L,rangef)))"
wenzelm@13428
   422
apply (rule separation_CollectI)
wenzelm@13428
   423
apply (rule_tac A="{r,z}" in subset_LsetE, blast )
paulson@13348
   424
apply (rule ReflectsE [OF Ord_wfrank_Reflects], assumption)
wenzelm@13428
   425
apply (drule subset_Lset_ltD, assumption)
paulson@13348
   426
apply (erule reflection_imp_L_separation)
paulson@13348
   427
  apply (simp_all add: lt_Ord2, clarify)
paulson@13385
   428
apply (rule DPow_LsetI)
wenzelm@13428
   429
apply (rename_tac u)
paulson@13348
   430
apply (rule ball_iff_sats imp_iff_sats)+
paulson@13348
   431
apply (rule_tac env="[rplus,u,r]" in tran_closure_iff_sats)
paulson@13348
   432
apply (rule sep_rules is_recfun_iff_sats | simp)+
paulson@13348
   433
done
paulson@13348
   434
paulson@13348
   435
paulson@13363
   436
subsubsection{*Instantiating the locale @{text M_wfrank}*}
wenzelm@13428
   437
wenzelm@13428
   438
theorem M_wfrank_L: "PROP M_wfrank(L)"
wenzelm@13428
   439
  apply (rule M_wfrank.intro)
wenzelm@13429
   440
     apply (rule M_trancl.axioms [OF M_trancl_L])+
wenzelm@13429
   441
  apply (rule M_wfrank_axioms.intro)
wenzelm@13429
   442
   apply (assumption | rule
wenzelm@13429
   443
     wfrank_separation wfrank_strong_replacement Ord_wfrank_separation)+
wenzelm@13428
   444
  done
paulson@13363
   445
wenzelm@13428
   446
lemmas iterates_closed = M_wfrank.iterates_closed [OF M_wfrank_L]
wenzelm@13428
   447
  and exists_wfrank = M_wfrank.exists_wfrank [OF M_wfrank_L]
wenzelm@13428
   448
  and M_wellfoundedrank = M_wfrank.M_wellfoundedrank [OF M_wfrank_L]
wenzelm@13428
   449
  and Ord_wfrank_range = M_wfrank.Ord_wfrank_range [OF M_wfrank_L]
wenzelm@13428
   450
  and Ord_range_wellfoundedrank = M_wfrank.Ord_range_wellfoundedrank [OF M_wfrank_L]
wenzelm@13428
   451
  and function_wellfoundedrank = M_wfrank.function_wellfoundedrank [OF M_wfrank_L]
wenzelm@13428
   452
  and domain_wellfoundedrank = M_wfrank.domain_wellfoundedrank [OF M_wfrank_L]
wenzelm@13428
   453
  and wellfoundedrank_type = M_wfrank.wellfoundedrank_type [OF M_wfrank_L]
wenzelm@13428
   454
  and Ord_wellfoundedrank = M_wfrank.Ord_wellfoundedrank [OF M_wfrank_L]
wenzelm@13428
   455
  and wellfoundedrank_eq = M_wfrank.wellfoundedrank_eq [OF M_wfrank_L]
wenzelm@13428
   456
  and wellfoundedrank_lt = M_wfrank.wellfoundedrank_lt [OF M_wfrank_L]
wenzelm@13428
   457
  and wellfounded_imp_subset_rvimage = M_wfrank.wellfounded_imp_subset_rvimage [OF M_wfrank_L]
wenzelm@13428
   458
  and wellfounded_imp_wf = M_wfrank.wellfounded_imp_wf [OF M_wfrank_L]
wenzelm@13428
   459
  and wellfounded_on_imp_wf_on = M_wfrank.wellfounded_on_imp_wf_on [OF M_wfrank_L]
wenzelm@13428
   460
  and wf_abs = M_wfrank.wf_abs [OF M_wfrank_L]
wenzelm@13428
   461
  and wf_on_abs = M_wfrank.wf_on_abs [OF M_wfrank_L]
wenzelm@13428
   462
  and wfrec_replacement_iff = M_wfrank.wfrec_replacement_iff [OF M_wfrank_L]
wenzelm@13428
   463
  and trans_wfrec_closed = M_wfrank.trans_wfrec_closed [OF M_wfrank_L]
wenzelm@13428
   464
  and wfrec_closed = M_wfrank.wfrec_closed [OF M_wfrank_L]
paulson@13363
   465
paulson@13363
   466
declare iterates_closed [intro,simp]
paulson@13363
   467
declare Ord_wfrank_range [rule_format]
paulson@13363
   468
declare wf_abs [simp]
paulson@13363
   469
declare wf_on_abs [simp]
paulson@13363
   470
paulson@13363
   471
paulson@13363
   472
subsection{*For Datatypes*}
paulson@13363
   473
paulson@13363
   474
subsubsection{*Binary Products, Internalized*}
paulson@13363
   475
paulson@13363
   476
constdefs cartprod_fm :: "[i,i,i]=>i"
wenzelm@13428
   477
(* "cartprod(M,A,B,z) ==
wenzelm@13428
   478
        \<forall>u[M]. u \<in> z <-> (\<exists>x[M]. x\<in>A & (\<exists>y[M]. y\<in>B & pair(M,x,y,u)))" *)
wenzelm@13428
   479
    "cartprod_fm(A,B,z) ==
paulson@13363
   480
       Forall(Iff(Member(0,succ(z)),
paulson@13363
   481
                  Exists(And(Member(0,succ(succ(A))),
paulson@13363
   482
                         Exists(And(Member(0,succ(succ(succ(B)))),
paulson@13363
   483
                                    pair_fm(1,0,2)))))))"
paulson@13363
   484
paulson@13363
   485
lemma cartprod_type [TC]:
paulson@13363
   486
     "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> cartprod_fm(x,y,z) \<in> formula"
wenzelm@13428
   487
by (simp add: cartprod_fm_def)
paulson@13363
   488
paulson@13363
   489
lemma arity_cartprod_fm [simp]:
wenzelm@13428
   490
     "[| x \<in> nat; y \<in> nat; z \<in> nat |]
paulson@13363
   491
      ==> arity(cartprod_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
wenzelm@13428
   492
by (simp add: cartprod_fm_def succ_Un_distrib [symmetric] Un_ac)
paulson@13363
   493
paulson@13363
   494
lemma sats_cartprod_fm [simp]:
paulson@13363
   495
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
wenzelm@13428
   496
    ==> sats(A, cartprod_fm(x,y,z), env) <->
paulson@13363
   497
        cartprod(**A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13363
   498
by (simp add: cartprod_fm_def cartprod_def)
paulson@13363
   499
paulson@13363
   500
lemma cartprod_iff_sats:
wenzelm@13428
   501
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13363
   502
          i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13363
   503
       ==> cartprod(**A, x, y, z) <-> sats(A, cartprod_fm(i,j,k), env)"
paulson@13363
   504
by (simp add: sats_cartprod_fm)
paulson@13363
   505
paulson@13363
   506
theorem cartprod_reflection:
wenzelm@13428
   507
     "REFLECTS[\<lambda>x. cartprod(L,f(x),g(x),h(x)),
paulson@13363
   508
               \<lambda>i x. cartprod(**Lset(i),f(x),g(x),h(x))]"
paulson@13363
   509
apply (simp only: cartprod_def setclass_simps)
wenzelm@13428
   510
apply (intro FOL_reflections pair_reflection)
paulson@13363
   511
done
paulson@13363
   512
paulson@13363
   513
paulson@13363
   514
subsubsection{*Binary Sums, Internalized*}
paulson@13363
   515
wenzelm@13428
   516
(* "is_sum(M,A,B,Z) ==
wenzelm@13428
   517
       \<exists>A0[M]. \<exists>n1[M]. \<exists>s1[M]. \<exists>B1[M].
paulson@13363
   518
         3      2       1        0
paulson@13363
   519
       number1(M,n1) & cartprod(M,n1,A,A0) & upair(M,n1,n1,s1) &
paulson@13363
   520
       cartprod(M,s1,B,B1) & union(M,A0,B1,Z)"  *)
paulson@13363
   521
constdefs sum_fm :: "[i,i,i]=>i"
wenzelm@13428
   522
    "sum_fm(A,B,Z) ==
paulson@13363
   523
       Exists(Exists(Exists(Exists(
wenzelm@13428
   524
        And(number1_fm(2),
paulson@13363
   525
            And(cartprod_fm(2,A#+4,3),
paulson@13363
   526
                And(upair_fm(2,2,1),
paulson@13363
   527
                    And(cartprod_fm(1,B#+4,0), union_fm(3,0,Z#+4)))))))))"
paulson@13363
   528
paulson@13363
   529
lemma sum_type [TC]:
paulson@13363
   530
     "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> sum_fm(x,y,z) \<in> formula"
wenzelm@13428
   531
by (simp add: sum_fm_def)
paulson@13363
   532
paulson@13363
   533
lemma arity_sum_fm [simp]:
wenzelm@13428
   534
     "[| x \<in> nat; y \<in> nat; z \<in> nat |]
paulson@13363
   535
      ==> arity(sum_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
wenzelm@13428
   536
by (simp add: sum_fm_def succ_Un_distrib [symmetric] Un_ac)
paulson@13363
   537
paulson@13363
   538
lemma sats_sum_fm [simp]:
paulson@13363
   539
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
wenzelm@13428
   540
    ==> sats(A, sum_fm(x,y,z), env) <->
paulson@13363
   541
        is_sum(**A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13363
   542
by (simp add: sum_fm_def is_sum_def)
paulson@13363
   543
paulson@13363
   544
lemma sum_iff_sats:
wenzelm@13428
   545
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13363
   546
          i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13363
   547
       ==> is_sum(**A, x, y, z) <-> sats(A, sum_fm(i,j,k), env)"
paulson@13363
   548
by simp
paulson@13363
   549
paulson@13363
   550
theorem sum_reflection:
wenzelm@13428
   551
     "REFLECTS[\<lambda>x. is_sum(L,f(x),g(x),h(x)),
paulson@13363
   552
               \<lambda>i x. is_sum(**Lset(i),f(x),g(x),h(x))]"
paulson@13363
   553
apply (simp only: is_sum_def setclass_simps)
wenzelm@13428
   554
apply (intro FOL_reflections function_reflections cartprod_reflection)
paulson@13363
   555
done
paulson@13363
   556
paulson@13363
   557
paulson@13363
   558
subsubsection{*The Operator @{term quasinat}*}
paulson@13363
   559
paulson@13363
   560
(* "is_quasinat(M,z) == empty(M,z) | (\<exists>m[M]. successor(M,m,z))" *)
paulson@13363
   561
constdefs quasinat_fm :: "i=>i"
paulson@13363
   562
    "quasinat_fm(z) == Or(empty_fm(z), Exists(succ_fm(0,succ(z))))"
paulson@13363
   563
paulson@13363
   564
lemma quasinat_type [TC]:
paulson@13363
   565
     "x \<in> nat ==> quasinat_fm(x) \<in> formula"
wenzelm@13428
   566
by (simp add: quasinat_fm_def)
paulson@13363
   567
paulson@13363
   568
lemma arity_quasinat_fm [simp]:
paulson@13363
   569
     "x \<in> nat ==> arity(quasinat_fm(x)) = succ(x)"
wenzelm@13428
   570
by (simp add: quasinat_fm_def succ_Un_distrib [symmetric] Un_ac)
paulson@13363
   571
paulson@13363
   572
lemma sats_quasinat_fm [simp]:
paulson@13363
   573
   "[| x \<in> nat; env \<in> list(A)|]
paulson@13363
   574
    ==> sats(A, quasinat_fm(x), env) <-> is_quasinat(**A, nth(x,env))"
paulson@13363
   575
by (simp add: quasinat_fm_def is_quasinat_def)
paulson@13363
   576
paulson@13363
   577
lemma quasinat_iff_sats:
wenzelm@13428
   578
      "[| nth(i,env) = x; nth(j,env) = y;
paulson@13363
   579
          i \<in> nat; env \<in> list(A)|]
paulson@13363
   580
       ==> is_quasinat(**A, x) <-> sats(A, quasinat_fm(i), env)"
paulson@13363
   581
by simp
paulson@13363
   582
paulson@13363
   583
theorem quasinat_reflection:
wenzelm@13428
   584
     "REFLECTS[\<lambda>x. is_quasinat(L,f(x)),
paulson@13363
   585
               \<lambda>i x. is_quasinat(**Lset(i),f(x))]"
paulson@13363
   586
apply (simp only: is_quasinat_def setclass_simps)
wenzelm@13428
   587
apply (intro FOL_reflections function_reflections)
paulson@13363
   588
done
paulson@13363
   589
paulson@13363
   590
paulson@13363
   591
subsubsection{*The Operator @{term is_nat_case}*}
paulson@13434
   592
text{*I could not get it to work with the more natural assumption that 
paulson@13434
   593
 @{term is_b} takes two arguments.  Instead it must be a formula where 1 and 0
paulson@13434
   594
 stand for @{term m} and @{term b}, respectively.*}
paulson@13363
   595
paulson@13363
   596
(* is_nat_case :: "[i=>o, i, [i,i]=>o, i, i] => o"
wenzelm@13428
   597
    "is_nat_case(M, a, is_b, k, z) ==
paulson@13363
   598
       (empty(M,k) --> z=a) &
paulson@13363
   599
       (\<forall>m[M]. successor(M,m,k) --> is_b(m,z)) &
paulson@13363
   600
       (is_quasinat(M,k) | empty(M,z))" *)
paulson@13363
   601
text{*The formula @{term is_b} has free variables 1 and 0.*}
paulson@13434
   602
constdefs is_nat_case_fm :: "[i, i, i, i]=>i"
paulson@13434
   603
 "is_nat_case_fm(a,is_b,k,z) == 
paulson@13363
   604
    And(Implies(empty_fm(k), Equal(z,a)),
paulson@13434
   605
        And(Forall(Implies(succ_fm(0,succ(k)), 
paulson@13434
   606
                   Forall(Implies(Equal(0,succ(succ(z))), is_b)))),
paulson@13363
   607
            Or(quasinat_fm(k), empty_fm(z))))"
paulson@13363
   608
paulson@13363
   609
lemma is_nat_case_type [TC]:
paulson@13434
   610
     "[| is_b \<in> formula;  
paulson@13434
   611
         x \<in> nat; y \<in> nat; z \<in> nat |] 
paulson@13363
   612
      ==> is_nat_case_fm(x,is_b,y,z) \<in> formula"
wenzelm@13428
   613
by (simp add: is_nat_case_fm_def)
paulson@13363
   614
paulson@13363
   615
lemma sats_is_nat_case_fm:
paulson@13434
   616
  assumes is_b_iff_sats: 
paulson@13434
   617
      "!!a. a \<in> A ==> is_b(a,nth(z, env)) <-> 
paulson@13434
   618
                      sats(A, p, Cons(nth(z,env), Cons(a, env)))"
paulson@13434
   619
  shows 
paulson@13363
   620
      "[|x \<in> nat; y \<in> nat; z < length(env); env \<in> list(A)|]
wenzelm@13428
   621
       ==> sats(A, is_nat_case_fm(x,p,y,z), env) <->
paulson@13363
   622
           is_nat_case(**A, nth(x,env), is_b, nth(y,env), nth(z,env))"
wenzelm@13428
   623
apply (frule lt_length_in_nat, assumption)
paulson@13363
   624
apply (simp add: is_nat_case_fm_def is_nat_case_def is_b_iff_sats [THEN iff_sym])
paulson@13363
   625
done
paulson@13363
   626
paulson@13363
   627
lemma is_nat_case_iff_sats:
paulson@13434
   628
  "[| (!!a. a \<in> A ==> is_b(a,z) <->
paulson@13434
   629
                      sats(A, p, Cons(z, Cons(a,env))));
paulson@13434
   630
      nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
paulson@13363
   631
      i \<in> nat; j \<in> nat; k < length(env); env \<in> list(A)|]
wenzelm@13428
   632
   ==> is_nat_case(**A, x, is_b, y, z) <-> sats(A, is_nat_case_fm(i,p,j,k), env)"
paulson@13363
   633
by (simp add: sats_is_nat_case_fm [of A is_b])
paulson@13363
   634
paulson@13363
   635
paulson@13363
   636
text{*The second argument of @{term is_b} gives it direct access to @{term x},
wenzelm@13428
   637
  which is essential for handling free variable references.  Without this
paulson@13363
   638
  argument, we cannot prove reflection for @{term iterates_MH}.*}
paulson@13363
   639
theorem is_nat_case_reflection:
paulson@13363
   640
  assumes is_b_reflection:
wenzelm@13428
   641
    "!!h f g. REFLECTS[\<lambda>x. is_b(L, h(x), f(x), g(x)),
paulson@13363
   642
                     \<lambda>i x. is_b(**Lset(i), h(x), f(x), g(x))]"
wenzelm@13428
   643
  shows "REFLECTS[\<lambda>x. is_nat_case(L, f(x), is_b(L,x), g(x), h(x)),
paulson@13363
   644
               \<lambda>i x. is_nat_case(**Lset(i), f(x), is_b(**Lset(i), x), g(x), h(x))]"
paulson@13363
   645
apply (simp (no_asm_use) only: is_nat_case_def setclass_simps)
wenzelm@13428
   646
apply (intro FOL_reflections function_reflections
wenzelm@13428
   647
             restriction_reflection is_b_reflection quasinat_reflection)
paulson@13363
   648
done
paulson@13363
   649
paulson@13363
   650
paulson@13363
   651
paulson@13363
   652
subsection{*The Operator @{term iterates_MH}, Needed for Iteration*}
paulson@13363
   653
paulson@13363
   654
(*  iterates_MH :: "[i=>o, [i,i]=>o, i, i, i, i] => o"
paulson@13363
   655
   "iterates_MH(M,isF,v,n,g,z) ==
paulson@13363
   656
        is_nat_case(M, v, \<lambda>m u. \<exists>gm[M]. fun_apply(M,g,m,gm) & isF(gm,u),
paulson@13363
   657
                    n, z)" *)
paulson@13434
   658
constdefs iterates_MH_fm :: "[i, i, i, i, i]=>i"
paulson@13434
   659
 "iterates_MH_fm(isF,v,n,g,z) == 
paulson@13434
   660
    is_nat_case_fm(v, 
paulson@13434
   661
      Exists(And(fun_apply_fm(succ(succ(succ(g))),2,0), 
paulson@13434
   662
                     Forall(Implies(Equal(0,2), isF)))), 
paulson@13363
   663
      n, z)"
paulson@13363
   664
paulson@13363
   665
lemma iterates_MH_type [TC]:
paulson@13434
   666
     "[| p \<in> formula;  
paulson@13434
   667
         v \<in> nat; x \<in> nat; y \<in> nat; z \<in> nat |] 
paulson@13363
   668
      ==> iterates_MH_fm(p,v,x,y,z) \<in> formula"
wenzelm@13428
   669
by (simp add: iterates_MH_fm_def)
paulson@13363
   670
paulson@13363
   671
lemma sats_iterates_MH_fm:
wenzelm@13428
   672
  assumes is_F_iff_sats:
wenzelm@13428
   673
      "!!a b c d. [| a \<in> A; b \<in> A; c \<in> A; d \<in> A|]
paulson@13363
   674
              ==> is_F(a,b) <->
paulson@13434
   675
                  sats(A, p, Cons(b, Cons(a, Cons(c, Cons(d,env)))))"
paulson@13434
   676
  shows 
paulson@13363
   677
      "[|v \<in> nat; x \<in> nat; y \<in> nat; z < length(env); env \<in> list(A)|]
wenzelm@13428
   678
       ==> sats(A, iterates_MH_fm(p,v,x,y,z), env) <->
paulson@13363
   679
           iterates_MH(**A, is_F, nth(v,env), nth(x,env), nth(y,env), nth(z,env))"
paulson@13434
   680
apply (frule lt_length_in_nat, assumption)  
paulson@13434
   681
apply (simp add: iterates_MH_fm_def iterates_MH_def sats_is_nat_case_fm 
paulson@13363
   682
              is_F_iff_sats [symmetric])
paulson@13434
   683
apply (rule is_nat_case_cong) 
paulson@13434
   684
apply (simp_all add: setclass_def)
paulson@13434
   685
done
paulson@13434
   686
paulson@13363
   687
paulson@13363
   688
lemma iterates_MH_iff_sats:
wenzelm@13428
   689
  "[| (!!a b c d. [| a \<in> A; b \<in> A; c \<in> A; d \<in> A|]
paulson@13363
   690
              ==> is_F(a,b) <->
paulson@13434
   691
                  sats(A, p, Cons(b, Cons(a, Cons(c, Cons(d,env))))));
paulson@13434
   692
      nth(i',env) = v; nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
paulson@13363
   693
      i' \<in> nat; i \<in> nat; j \<in> nat; k < length(env); env \<in> list(A)|]
wenzelm@13428
   694
   ==> iterates_MH(**A, is_F, v, x, y, z) <->
paulson@13363
   695
       sats(A, iterates_MH_fm(p,i',i,j,k), env)"
paulson@13434
   696
apply (rule iff_sym) 
wenzelm@13428
   697
apply (rule iff_trans)
paulson@13434
   698
apply (rule sats_iterates_MH_fm [of A is_F], blast)  
paulson@13434
   699
apply simp_all 
paulson@13363
   700
done
paulson@13434
   701
(*FIXME: surely proof can be improved?*)
paulson@13434
   702
paulson@13363
   703
paulson@13363
   704
theorem iterates_MH_reflection:
paulson@13363
   705
  assumes p_reflection:
wenzelm@13428
   706
    "!!f g h. REFLECTS[\<lambda>x. p(L, f(x), g(x)),
paulson@13363
   707
                     \<lambda>i x. p(**Lset(i), f(x), g(x))]"
wenzelm@13428
   708
 shows "REFLECTS[\<lambda>x. iterates_MH(L, p(L), e(x), f(x), g(x), h(x)),
paulson@13363
   709
               \<lambda>i x. iterates_MH(**Lset(i), p(**Lset(i)), e(x), f(x), g(x), h(x))]"
paulson@13363
   710
apply (simp (no_asm_use) only: iterates_MH_def)
paulson@13363
   711
txt{*Must be careful: simplifying with @{text setclass_simps} above would
paulson@13363
   712
     change @{text "\<exists>gm[**Lset(i)]"} into @{text "\<exists>gm \<in> Lset(i)"}, when
paulson@13363
   713
     it would no longer match rule @{text is_nat_case_reflection}. *}
wenzelm@13428
   714
apply (rule is_nat_case_reflection)
paulson@13363
   715
apply (simp (no_asm_use) only: setclass_simps)
paulson@13363
   716
apply (intro FOL_reflections function_reflections is_nat_case_reflection
wenzelm@13428
   717
             restriction_reflection p_reflection)
paulson@13363
   718
done
paulson@13363
   719
paulson@13363
   720
paulson@13363
   721
wenzelm@13428
   722
subsection{*@{term L} is Closed Under the Operator @{term list}*}
paulson@13363
   723
paulson@13386
   724
subsubsection{*The List Functor, Internalized*}
paulson@13386
   725
paulson@13386
   726
constdefs list_functor_fm :: "[i,i,i]=>i"
wenzelm@13428
   727
(* "is_list_functor(M,A,X,Z) ==
wenzelm@13428
   728
        \<exists>n1[M]. \<exists>AX[M].
paulson@13386
   729
         number1(M,n1) & cartprod(M,A,X,AX) & is_sum(M,n1,AX,Z)" *)
wenzelm@13428
   730
    "list_functor_fm(A,X,Z) ==
paulson@13386
   731
       Exists(Exists(
wenzelm@13428
   732
        And(number1_fm(1),
paulson@13386
   733
            And(cartprod_fm(A#+2,X#+2,0), sum_fm(1,0,Z#+2)))))"
paulson@13386
   734
paulson@13386
   735
lemma list_functor_type [TC]:
paulson@13386
   736
     "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> list_functor_fm(x,y,z) \<in> formula"
wenzelm@13428
   737
by (simp add: list_functor_fm_def)
paulson@13386
   738
paulson@13386
   739
lemma arity_list_functor_fm [simp]:
wenzelm@13428
   740
     "[| x \<in> nat; y \<in> nat; z \<in> nat |]
paulson@13386
   741
      ==> arity(list_functor_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
wenzelm@13428
   742
by (simp add: list_functor_fm_def succ_Un_distrib [symmetric] Un_ac)
paulson@13386
   743
paulson@13386
   744
lemma sats_list_functor_fm [simp]:
paulson@13386
   745
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
wenzelm@13428
   746
    ==> sats(A, list_functor_fm(x,y,z), env) <->
paulson@13386
   747
        is_list_functor(**A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13386
   748
by (simp add: list_functor_fm_def is_list_functor_def)
paulson@13386
   749
paulson@13386
   750
lemma list_functor_iff_sats:
wenzelm@13428
   751
  "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13386
   752
      i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13386
   753
   ==> is_list_functor(**A, x, y, z) <-> sats(A, list_functor_fm(i,j,k), env)"
paulson@13386
   754
by simp
paulson@13386
   755
paulson@13386
   756
theorem list_functor_reflection:
wenzelm@13428
   757
     "REFLECTS[\<lambda>x. is_list_functor(L,f(x),g(x),h(x)),
paulson@13386
   758
               \<lambda>i x. is_list_functor(**Lset(i),f(x),g(x),h(x))]"
paulson@13386
   759
apply (simp only: is_list_functor_def setclass_simps)
paulson@13386
   760
apply (intro FOL_reflections number1_reflection
wenzelm@13428
   761
             cartprod_reflection sum_reflection)
paulson@13386
   762
done
paulson@13386
   763
paulson@13386
   764
paulson@13386
   765
subsubsection{*Instances of Replacement for Lists*}
paulson@13386
   766
paulson@13363
   767
lemma list_replacement1_Reflects:
paulson@13363
   768
 "REFLECTS
paulson@13363
   769
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13363
   770
         is_wfrec(L, iterates_MH(L, is_list_functor(L,A), 0), memsn, u, y)),
paulson@13363
   771
    \<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
   772
         is_wfrec(**Lset(i),
wenzelm@13428
   773
                  iterates_MH(**Lset(i),
paulson@13363
   774
                          is_list_functor(**Lset(i), A), 0), memsn, u, y))]"
wenzelm@13428
   775
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   776
          iterates_MH_reflection list_functor_reflection)
paulson@13363
   777
wenzelm@13428
   778
lemma list_replacement1:
paulson@13363
   779
   "L(A) ==> iterates_replacement(L, is_list_functor(L,A), 0)"
paulson@13363
   780
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   781
apply (rule strong_replacementI)
paulson@13363
   782
apply (rule rallI)
wenzelm@13428
   783
apply (rename_tac B)
wenzelm@13428
   784
apply (rule separation_CollectI)
wenzelm@13428
   785
apply (insert nonempty)
wenzelm@13428
   786
apply (subgoal_tac "L(Memrel(succ(n)))")
wenzelm@13428
   787
apply (rule_tac A="{B,A,n,z,0,Memrel(succ(n))}" in subset_LsetE, blast )
paulson@13363
   788
apply (rule ReflectsE [OF list_replacement1_Reflects], assumption)
wenzelm@13428
   789
apply (drule subset_Lset_ltD, assumption)
paulson@13363
   790
apply (erule reflection_imp_L_separation)
paulson@13386
   791
  apply (simp_all add: lt_Ord2 Memrel_closed)
wenzelm@13428
   792
apply (elim conjE)
paulson@13385
   793
apply (rule DPow_LsetI)
wenzelm@13428
   794
apply (rename_tac v)
paulson@13363
   795
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13363
   796
apply (rule_tac env = "[u,v,A,n,B,0,Memrel(succ(n))]" in mem_iff_sats)
paulson@13363
   797
apply (rule sep_rules | simp)+
paulson@13434
   798
apply (simp add: is_wfrec_def)
paulson@13434
   799
apply (rule sep_rules is_nat_case_iff_sats list_functor_iff_sats
paulson@13434
   800
            is_recfun_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13363
   801
done
paulson@13363
   802
paulson@13363
   803
lemma list_replacement2_Reflects:
paulson@13363
   804
 "REFLECTS
paulson@13363
   805
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
paulson@13363
   806
         (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
paulson@13363
   807
           is_wfrec (L, iterates_MH (L, is_list_functor(L, A), 0),
paulson@13363
   808
                              msn, u, x)),
paulson@13363
   809
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
wenzelm@13428
   810
         (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
paulson@13363
   811
          successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
wenzelm@13428
   812
           is_wfrec (**Lset(i),
paulson@13363
   813
                 iterates_MH (**Lset(i), is_list_functor(**Lset(i), A), 0),
paulson@13363
   814
                     msn, u, x))]"
wenzelm@13428
   815
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   816
          iterates_MH_reflection list_functor_reflection)
paulson@13363
   817
paulson@13363
   818
wenzelm@13428
   819
lemma list_replacement2:
wenzelm@13428
   820
   "L(A) ==> strong_replacement(L,
wenzelm@13428
   821
         \<lambda>n y. n\<in>nat &
paulson@13363
   822
               (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
wenzelm@13428
   823
               is_wfrec(L, iterates_MH(L,is_list_functor(L,A), 0),
paulson@13363
   824
                        msn, n, y)))"
wenzelm@13428
   825
apply (rule strong_replacementI)
paulson@13363
   826
apply (rule rallI)
wenzelm@13428
   827
apply (rename_tac B)
wenzelm@13428
   828
apply (rule separation_CollectI)
wenzelm@13428
   829
apply (insert nonempty)
wenzelm@13428
   830
apply (rule_tac A="{A,B,z,0,nat}" in subset_LsetE)
wenzelm@13428
   831
apply (blast intro: L_nat)
paulson@13363
   832
apply (rule ReflectsE [OF list_replacement2_Reflects], assumption)
wenzelm@13428
   833
apply (drule subset_Lset_ltD, assumption)
paulson@13363
   834
apply (erule reflection_imp_L_separation)
paulson@13363
   835
  apply (simp_all add: lt_Ord2)
paulson@13385
   836
apply (rule DPow_LsetI)
wenzelm@13428
   837
apply (rename_tac v)
paulson@13363
   838
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13363
   839
apply (rule_tac env = "[u,v,A,B,0,nat]" in mem_iff_sats)
paulson@13363
   840
apply (rule sep_rules | simp)+
paulson@13434
   841
apply (simp add: is_wfrec_def)
paulson@13434
   842
apply (rule sep_rules is_nat_case_iff_sats list_functor_iff_sats
paulson@13434
   843
            is_recfun_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13363
   844
done
paulson@13363
   845
paulson@13386
   846
wenzelm@13428
   847
subsection{*@{term L} is Closed Under the Operator @{term formula}*}
paulson@13386
   848
paulson@13386
   849
subsubsection{*The Formula Functor, Internalized*}
paulson@13386
   850
paulson@13386
   851
constdefs formula_functor_fm :: "[i,i]=>i"
wenzelm@13428
   852
(*     "is_formula_functor(M,X,Z) ==
wenzelm@13428
   853
        \<exists>nat'[M]. \<exists>natnat[M]. \<exists>natnatsum[M]. \<exists>XX[M]. \<exists>X3[M].
paulson@13398
   854
           4           3               2       1       0
wenzelm@13428
   855
          omega(M,nat') & cartprod(M,nat',nat',natnat) &
paulson@13386
   856
          is_sum(M,natnat,natnat,natnatsum) &
wenzelm@13428
   857
          cartprod(M,X,X,XX) & is_sum(M,XX,X,X3) &
wenzelm@13428
   858
          is_sum(M,natnatsum,X3,Z)" *)
wenzelm@13428
   859
    "formula_functor_fm(X,Z) ==
paulson@13398
   860
       Exists(Exists(Exists(Exists(Exists(
wenzelm@13428
   861
        And(omega_fm(4),
paulson@13398
   862
         And(cartprod_fm(4,4,3),
paulson@13398
   863
          And(sum_fm(3,3,2),
paulson@13398
   864
           And(cartprod_fm(X#+5,X#+5,1),
paulson@13398
   865
            And(sum_fm(1,X#+5,0), sum_fm(2,0,Z#+5)))))))))))"
paulson@13386
   866
paulson@13386
   867
lemma formula_functor_type [TC]:
paulson@13386
   868
     "[| x \<in> nat; y \<in> nat |] ==> formula_functor_fm(x,y) \<in> formula"
wenzelm@13428
   869
by (simp add: formula_functor_fm_def)
paulson@13386
   870
paulson@13386
   871
lemma sats_formula_functor_fm [simp]:
paulson@13386
   872
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
wenzelm@13428
   873
    ==> sats(A, formula_functor_fm(x,y), env) <->
paulson@13386
   874
        is_formula_functor(**A, nth(x,env), nth(y,env))"
paulson@13386
   875
by (simp add: formula_functor_fm_def is_formula_functor_def)
paulson@13386
   876
paulson@13386
   877
lemma formula_functor_iff_sats:
wenzelm@13428
   878
  "[| nth(i,env) = x; nth(j,env) = y;
paulson@13386
   879
      i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@13386
   880
   ==> is_formula_functor(**A, x, y) <-> sats(A, formula_functor_fm(i,j), env)"
paulson@13386
   881
by simp
paulson@13386
   882
paulson@13386
   883
theorem formula_functor_reflection:
wenzelm@13428
   884
     "REFLECTS[\<lambda>x. is_formula_functor(L,f(x),g(x)),
paulson@13386
   885
               \<lambda>i x. is_formula_functor(**Lset(i),f(x),g(x))]"
paulson@13386
   886
apply (simp only: is_formula_functor_def setclass_simps)
paulson@13386
   887
apply (intro FOL_reflections omega_reflection
wenzelm@13428
   888
             cartprod_reflection sum_reflection)
paulson@13386
   889
done
paulson@13386
   890
paulson@13386
   891
subsubsection{*Instances of Replacement for Formulas*}
paulson@13386
   892
paulson@13386
   893
lemma formula_replacement1_Reflects:
paulson@13386
   894
 "REFLECTS
paulson@13386
   895
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13386
   896
         is_wfrec(L, iterates_MH(L, is_formula_functor(L), 0), memsn, u, y)),
paulson@13386
   897
    \<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
   898
         is_wfrec(**Lset(i),
wenzelm@13428
   899
                  iterates_MH(**Lset(i),
paulson@13386
   900
                          is_formula_functor(**Lset(i)), 0), memsn, u, y))]"
wenzelm@13428
   901
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   902
          iterates_MH_reflection formula_functor_reflection)
paulson@13386
   903
wenzelm@13428
   904
lemma formula_replacement1:
paulson@13386
   905
   "iterates_replacement(L, is_formula_functor(L), 0)"
paulson@13386
   906
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   907
apply (rule strong_replacementI)
paulson@13386
   908
apply (rule rallI)
wenzelm@13428
   909
apply (rename_tac B)
wenzelm@13428
   910
apply (rule separation_CollectI)
wenzelm@13428
   911
apply (insert nonempty)
wenzelm@13428
   912
apply (subgoal_tac "L(Memrel(succ(n)))")
wenzelm@13428
   913
apply (rule_tac A="{B,n,z,0,Memrel(succ(n))}" in subset_LsetE, blast )
paulson@13386
   914
apply (rule ReflectsE [OF formula_replacement1_Reflects], assumption)
wenzelm@13428
   915
apply (drule subset_Lset_ltD, assumption)
paulson@13386
   916
apply (erule reflection_imp_L_separation)
paulson@13386
   917
  apply (simp_all add: lt_Ord2 Memrel_closed)
paulson@13386
   918
apply (rule DPow_LsetI)
wenzelm@13428
   919
apply (rename_tac v)
paulson@13386
   920
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13386
   921
apply (rule_tac env = "[u,v,n,B,0,Memrel(succ(n))]" in mem_iff_sats)
paulson@13386
   922
apply (rule sep_rules | simp)+
paulson@13434
   923
apply (simp add: is_wfrec_def)
paulson@13434
   924
apply (rule sep_rules is_nat_case_iff_sats formula_functor_iff_sats
paulson@13434
   925
            is_recfun_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13386
   926
done
paulson@13386
   927
paulson@13386
   928
lemma formula_replacement2_Reflects:
paulson@13386
   929
 "REFLECTS
paulson@13386
   930
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
paulson@13386
   931
         (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
paulson@13386
   932
           is_wfrec (L, iterates_MH (L, is_formula_functor(L), 0),
paulson@13386
   933
                              msn, u, x)),
paulson@13386
   934
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
wenzelm@13428
   935
         (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
paulson@13386
   936
          successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
wenzelm@13428
   937
           is_wfrec (**Lset(i),
paulson@13386
   938
                 iterates_MH (**Lset(i), is_formula_functor(**Lset(i)), 0),
paulson@13386
   939
                     msn, u, x))]"
wenzelm@13428
   940
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   941
          iterates_MH_reflection formula_functor_reflection)
paulson@13386
   942
paulson@13386
   943
wenzelm@13428
   944
lemma formula_replacement2:
wenzelm@13428
   945
   "strong_replacement(L,
wenzelm@13428
   946
         \<lambda>n y. n\<in>nat &
paulson@13386
   947
               (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
wenzelm@13428
   948
               is_wfrec(L, iterates_MH(L,is_formula_functor(L), 0),
paulson@13386
   949
                        msn, n, y)))"
wenzelm@13428
   950
apply (rule strong_replacementI)
paulson@13386
   951
apply (rule rallI)
wenzelm@13428
   952
apply (rename_tac B)
wenzelm@13428
   953
apply (rule separation_CollectI)
wenzelm@13428
   954
apply (insert nonempty)
wenzelm@13428
   955
apply (rule_tac A="{B,z,0,nat}" in subset_LsetE)
wenzelm@13428
   956
apply (blast intro: L_nat)
paulson@13386
   957
apply (rule ReflectsE [OF formula_replacement2_Reflects], assumption)
wenzelm@13428
   958
apply (drule subset_Lset_ltD, assumption)
paulson@13386
   959
apply (erule reflection_imp_L_separation)
paulson@13386
   960
  apply (simp_all add: lt_Ord2)
paulson@13386
   961
apply (rule DPow_LsetI)
wenzelm@13428
   962
apply (rename_tac v)
paulson@13386
   963
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13386
   964
apply (rule_tac env = "[u,v,B,0,nat]" in mem_iff_sats)
paulson@13386
   965
apply (rule sep_rules | simp)+
paulson@13434
   966
apply (simp add: is_wfrec_def)
paulson@13434
   967
apply (rule sep_rules is_nat_case_iff_sats formula_functor_iff_sats
paulson@13434
   968
            is_recfun_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13386
   969
done
paulson@13386
   970
paulson@13386
   971
text{*NB The proofs for type @{term formula} are virtually identical to those
paulson@13386
   972
for @{term "list(A)"}.  It was a cut-and-paste job! *}
paulson@13386
   973
paulson@13387
   974
paulson@13409
   975
subsection{*Internalized Forms of Data Structuring Operators*}
paulson@13409
   976
paulson@13409
   977
subsubsection{*The Formula @{term is_Inl}, Internalized*}
paulson@13409
   978
paulson@13409
   979
(*  is_Inl(M,a,z) == \<exists>zero[M]. empty(M,zero) & pair(M,zero,a,z) *)
paulson@13409
   980
constdefs Inl_fm :: "[i,i]=>i"
paulson@13409
   981
    "Inl_fm(a,z) == Exists(And(empty_fm(0), pair_fm(0,succ(a),succ(z))))"
paulson@13409
   982
paulson@13409
   983
lemma Inl_type [TC]:
paulson@13409
   984
     "[| x \<in> nat; z \<in> nat |] ==> Inl_fm(x,z) \<in> formula"
wenzelm@13428
   985
by (simp add: Inl_fm_def)
paulson@13409
   986
paulson@13409
   987
lemma sats_Inl_fm [simp]:
paulson@13409
   988
   "[| x \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13409
   989
    ==> sats(A, Inl_fm(x,z), env) <-> is_Inl(**A, nth(x,env), nth(z,env))"
paulson@13409
   990
by (simp add: Inl_fm_def is_Inl_def)
paulson@13409
   991
paulson@13409
   992
lemma Inl_iff_sats:
wenzelm@13428
   993
      "[| nth(i,env) = x; nth(k,env) = z;
paulson@13409
   994
          i \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13409
   995
       ==> is_Inl(**A, x, z) <-> sats(A, Inl_fm(i,k), env)"
paulson@13409
   996
by simp
paulson@13409
   997
paulson@13409
   998
theorem Inl_reflection:
wenzelm@13428
   999
     "REFLECTS[\<lambda>x. is_Inl(L,f(x),h(x)),
paulson@13409
  1000
               \<lambda>i x. is_Inl(**Lset(i),f(x),h(x))]"
paulson@13409
  1001
apply (simp only: is_Inl_def setclass_simps)
wenzelm@13428
  1002
apply (intro FOL_reflections function_reflections)
paulson@13409
  1003
done
paulson@13409
  1004
paulson@13409
  1005
paulson@13409
  1006
subsubsection{*The Formula @{term is_Inr}, Internalized*}
paulson@13409
  1007
paulson@13409
  1008
(*  is_Inr(M,a,z) == \<exists>n1[M]. number1(M,n1) & pair(M,n1,a,z) *)
paulson@13409
  1009
constdefs Inr_fm :: "[i,i]=>i"
paulson@13409
  1010
    "Inr_fm(a,z) == Exists(And(number1_fm(0), pair_fm(0,succ(a),succ(z))))"
paulson@13409
  1011
paulson@13409
  1012
lemma Inr_type [TC]:
paulson@13409
  1013
     "[| x \<in> nat; z \<in> nat |] ==> Inr_fm(x,z) \<in> formula"
wenzelm@13428
  1014
by (simp add: Inr_fm_def)
paulson@13409
  1015
paulson@13409
  1016
lemma sats_Inr_fm [simp]:
paulson@13409
  1017
   "[| x \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13409
  1018
    ==> sats(A, Inr_fm(x,z), env) <-> is_Inr(**A, nth(x,env), nth(z,env))"
paulson@13409
  1019
by (simp add: Inr_fm_def is_Inr_def)
paulson@13409
  1020
paulson@13409
  1021
lemma Inr_iff_sats:
wenzelm@13428
  1022
      "[| nth(i,env) = x; nth(k,env) = z;
paulson@13409
  1023
          i \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13409
  1024
       ==> is_Inr(**A, x, z) <-> sats(A, Inr_fm(i,k), env)"
paulson@13409
  1025
by simp
paulson@13409
  1026
paulson@13409
  1027
theorem Inr_reflection:
wenzelm@13428
  1028
     "REFLECTS[\<lambda>x. is_Inr(L,f(x),h(x)),
paulson@13409
  1029
               \<lambda>i x. is_Inr(**Lset(i),f(x),h(x))]"
paulson@13409
  1030
apply (simp only: is_Inr_def setclass_simps)
wenzelm@13428
  1031
apply (intro FOL_reflections function_reflections)
paulson@13409
  1032
done
paulson@13409
  1033
paulson@13409
  1034
paulson@13409
  1035
subsubsection{*The Formula @{term is_Nil}, Internalized*}
paulson@13409
  1036
paulson@13409
  1037
(* is_Nil(M,xs) == \<exists>zero[M]. empty(M,zero) & is_Inl(M,zero,xs) *)
paulson@13409
  1038
paulson@13409
  1039
constdefs Nil_fm :: "i=>i"
paulson@13409
  1040
    "Nil_fm(x) == Exists(And(empty_fm(0), Inl_fm(0,succ(x))))"
wenzelm@13428
  1041
paulson@13409
  1042
lemma Nil_type [TC]: "x \<in> nat ==> Nil_fm(x) \<in> formula"
wenzelm@13428
  1043
by (simp add: Nil_fm_def)
paulson@13409
  1044
paulson@13409
  1045
lemma sats_Nil_fm [simp]:
paulson@13409
  1046
   "[| x \<in> nat; env \<in> list(A)|]
paulson@13409
  1047
    ==> sats(A, Nil_fm(x), env) <-> is_Nil(**A, nth(x,env))"
paulson@13409
  1048
by (simp add: Nil_fm_def is_Nil_def)
paulson@13409
  1049
paulson@13409
  1050
lemma Nil_iff_sats:
paulson@13409
  1051
      "[| nth(i,env) = x; i \<in> nat; env \<in> list(A)|]
paulson@13409
  1052
       ==> is_Nil(**A, x) <-> sats(A, Nil_fm(i), env)"
paulson@13409
  1053
by simp
paulson@13409
  1054
paulson@13409
  1055
theorem Nil_reflection:
wenzelm@13428
  1056
     "REFLECTS[\<lambda>x. is_Nil(L,f(x)),
paulson@13409
  1057
               \<lambda>i x. is_Nil(**Lset(i),f(x))]"
paulson@13409
  1058
apply (simp only: is_Nil_def setclass_simps)
wenzelm@13428
  1059
apply (intro FOL_reflections function_reflections Inl_reflection)
paulson@13409
  1060
done
paulson@13409
  1061
paulson@13409
  1062
paulson@13422
  1063
subsubsection{*The Formula @{term is_Cons}, Internalized*}
paulson@13395
  1064
paulson@13387
  1065
paulson@13409
  1066
(*  "is_Cons(M,a,l,Z) == \<exists>p[M]. pair(M,a,l,p) & is_Inr(M,p,Z)" *)
paulson@13409
  1067
constdefs Cons_fm :: "[i,i,i]=>i"
wenzelm@13428
  1068
    "Cons_fm(a,l,Z) ==
paulson@13409
  1069
       Exists(And(pair_fm(succ(a),succ(l),0), Inr_fm(0,succ(Z))))"
paulson@13409
  1070
paulson@13409
  1071
lemma Cons_type [TC]:
paulson@13409
  1072
     "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> Cons_fm(x,y,z) \<in> formula"
wenzelm@13428
  1073
by (simp add: Cons_fm_def)
paulson@13409
  1074
paulson@13409
  1075
lemma sats_Cons_fm [simp]:
paulson@13409
  1076
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
wenzelm@13428
  1077
    ==> sats(A, Cons_fm(x,y,z), env) <->
paulson@13409
  1078
       is_Cons(**A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13409
  1079
by (simp add: Cons_fm_def is_Cons_def)
paulson@13409
  1080
paulson@13409
  1081
lemma Cons_iff_sats:
wenzelm@13428
  1082
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13409
  1083
          i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13409
  1084
       ==>is_Cons(**A, x, y, z) <-> sats(A, Cons_fm(i,j,k), env)"
paulson@13409
  1085
by simp
paulson@13409
  1086
paulson@13409
  1087
theorem Cons_reflection:
wenzelm@13428
  1088
     "REFLECTS[\<lambda>x. is_Cons(L,f(x),g(x),h(x)),
paulson@13409
  1089
               \<lambda>i x. is_Cons(**Lset(i),f(x),g(x),h(x))]"
paulson@13409
  1090
apply (simp only: is_Cons_def setclass_simps)
wenzelm@13428
  1091
apply (intro FOL_reflections pair_reflection Inr_reflection)
paulson@13409
  1092
done
paulson@13409
  1093
paulson@13409
  1094
subsubsection{*The Formula @{term is_quasilist}, Internalized*}
paulson@13409
  1095
paulson@13409
  1096
(* is_quasilist(M,xs) == is_Nil(M,z) | (\<exists>x[M]. \<exists>l[M]. is_Cons(M,x,l,z))" *)
paulson@13409
  1097
paulson@13409
  1098
constdefs quasilist_fm :: "i=>i"
wenzelm@13428
  1099
    "quasilist_fm(x) ==
paulson@13409
  1100
       Or(Nil_fm(x), Exists(Exists(Cons_fm(1,0,succ(succ(x))))))"
wenzelm@13428
  1101
paulson@13409
  1102
lemma quasilist_type [TC]: "x \<in> nat ==> quasilist_fm(x) \<in> formula"
wenzelm@13428
  1103
by (simp add: quasilist_fm_def)
paulson@13409
  1104
paulson@13409
  1105
lemma sats_quasilist_fm [simp]:
paulson@13409
  1106
   "[| x \<in> nat; env \<in> list(A)|]
paulson@13409
  1107
    ==> sats(A, quasilist_fm(x), env) <-> is_quasilist(**A, nth(x,env))"
paulson@13409
  1108
by (simp add: quasilist_fm_def is_quasilist_def)
paulson@13409
  1109
paulson@13409
  1110
lemma quasilist_iff_sats:
paulson@13409
  1111
      "[| nth(i,env) = x; i \<in> nat; env \<in> list(A)|]
paulson@13409
  1112
       ==> is_quasilist(**A, x) <-> sats(A, quasilist_fm(i), env)"
paulson@13409
  1113
by simp
paulson@13409
  1114
paulson@13409
  1115
theorem quasilist_reflection:
wenzelm@13428
  1116
     "REFLECTS[\<lambda>x. is_quasilist(L,f(x)),
paulson@13409
  1117
               \<lambda>i x. is_quasilist(**Lset(i),f(x))]"
paulson@13409
  1118
apply (simp only: is_quasilist_def setclass_simps)
wenzelm@13428
  1119
apply (intro FOL_reflections Nil_reflection Cons_reflection)
paulson@13409
  1120
done
paulson@13409
  1121
paulson@13409
  1122
paulson@13409
  1123
subsection{*Absoluteness for the Function @{term nth}*}
paulson@13409
  1124
paulson@13409
  1125
paulson@13409
  1126
subsubsection{*The Formula @{term is_tl}, Internalized*}
paulson@13409
  1127
wenzelm@13428
  1128
(*     "is_tl(M,xs,T) ==
paulson@13409
  1129
       (is_Nil(M,xs) --> T=xs) &
paulson@13409
  1130
       (\<forall>x[M]. \<forall>l[M]. ~ is_Cons(M,x,l,xs) | T=l) &
paulson@13409
  1131
       (is_quasilist(M,xs) | empty(M,T))" *)
paulson@13409
  1132
constdefs tl_fm :: "[i,i]=>i"
wenzelm@13428
  1133
    "tl_fm(xs,T) ==
paulson@13409
  1134
       And(Implies(Nil_fm(xs), Equal(T,xs)),
paulson@13409
  1135
           And(Forall(Forall(Or(Neg(Cons_fm(1,0,xs#+2)), Equal(T#+2,0)))),
paulson@13409
  1136
               Or(quasilist_fm(xs), empty_fm(T))))"
paulson@13409
  1137
paulson@13409
  1138
lemma tl_type [TC]:
paulson@13409
  1139
     "[| x \<in> nat; y \<in> nat |] ==> tl_fm(x,y) \<in> formula"
wenzelm@13428
  1140
by (simp add: tl_fm_def)
paulson@13409
  1141
paulson@13409
  1142
lemma sats_tl_fm [simp]:
paulson@13409
  1143
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
paulson@13409
  1144
    ==> sats(A, tl_fm(x,y), env) <-> is_tl(**A, nth(x,env), nth(y,env))"
paulson@13409
  1145
by (simp add: tl_fm_def is_tl_def)
paulson@13409
  1146
paulson@13409
  1147
lemma tl_iff_sats:
paulson@13409
  1148
      "[| nth(i,env) = x; nth(j,env) = y;
paulson@13409
  1149
          i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@13409
  1150
       ==> is_tl(**A, x, y) <-> sats(A, tl_fm(i,j), env)"
paulson@13409
  1151
by simp
paulson@13409
  1152
paulson@13409
  1153
theorem tl_reflection:
wenzelm@13428
  1154
     "REFLECTS[\<lambda>x. is_tl(L,f(x),g(x)),
paulson@13409
  1155
               \<lambda>i x. is_tl(**Lset(i),f(x),g(x))]"
paulson@13409
  1156
apply (simp only: is_tl_def setclass_simps)
paulson@13409
  1157
apply (intro FOL_reflections Nil_reflection Cons_reflection
wenzelm@13428
  1158
             quasilist_reflection empty_reflection)
paulson@13409
  1159
done
paulson@13409
  1160
paulson@13409
  1161
paulson@13409
  1162
subsubsection{*An Instance of Replacement for @{term nth}*}
paulson@13409
  1163
paulson@13409
  1164
lemma nth_replacement_Reflects:
paulson@13409
  1165
 "REFLECTS
paulson@13409
  1166
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13409
  1167
         is_wfrec(L, iterates_MH(L, is_tl(L), z), memsn, u, y)),
paulson@13409
  1168
    \<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
  1169
         is_wfrec(**Lset(i),
wenzelm@13428
  1170
                  iterates_MH(**Lset(i),
paulson@13409
  1171
                          is_tl(**Lset(i)), z), memsn, u, y))]"
wenzelm@13428
  1172
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
  1173
          iterates_MH_reflection list_functor_reflection tl_reflection)
paulson@13409
  1174
wenzelm@13428
  1175
lemma nth_replacement:
paulson@13409
  1176
   "L(w) ==> iterates_replacement(L, %l t. is_tl(L,l,t), w)"
paulson@13409
  1177
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
  1178
apply (rule strong_replacementI)
wenzelm@13428
  1179
apply (rule rallI)
wenzelm@13428
  1180
apply (rule separation_CollectI)
wenzelm@13428
  1181
apply (subgoal_tac "L(Memrel(succ(n)))")
wenzelm@13428
  1182
apply (rule_tac A="{A,n,w,z,Memrel(succ(n))}" in subset_LsetE, blast )
paulson@13409
  1183
apply (rule ReflectsE [OF nth_replacement_Reflects], assumption)
wenzelm@13428
  1184
apply (drule subset_Lset_ltD, assumption)
paulson@13409
  1185
apply (erule reflection_imp_L_separation)
paulson@13409
  1186
  apply (simp_all add: lt_Ord2 Memrel_closed)
wenzelm@13428
  1187
apply (elim conjE)
paulson@13409
  1188
apply (rule DPow_LsetI)
wenzelm@13428
  1189
apply (rename_tac v)
paulson@13409
  1190
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13409
  1191
apply (rule_tac env = "[u,v,A,z,w,Memrel(succ(n))]" in mem_iff_sats)
paulson@13409
  1192
apply (rule sep_rules | simp)+
paulson@13434
  1193
apply (simp add: is_wfrec_def)
paulson@13434
  1194
apply (rule sep_rules is_nat_case_iff_sats tl_iff_sats
paulson@13434
  1195
            is_recfun_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13409
  1196
done
paulson@13409
  1197
paulson@13422
  1198
paulson@13422
  1199
paulson@13422
  1200
subsubsection{*Instantiating the locale @{text M_datatypes}*}
wenzelm@13428
  1201
wenzelm@13429
  1202
theorem M_datatypes_L: "PROP M_datatypes(L)"
wenzelm@13429
  1203
  apply (rule M_datatypes.intro)
wenzelm@13429
  1204
      apply (rule M_wfrank.axioms [OF M_wfrank_L])+
wenzelm@13428
  1205
  apply (rule M_datatypes_axioms.intro)
wenzelm@13428
  1206
      apply (assumption | rule
wenzelm@13428
  1207
        list_replacement1 list_replacement2
wenzelm@13428
  1208
        formula_replacement1 formula_replacement2
wenzelm@13428
  1209
        nth_replacement)+
wenzelm@13428
  1210
  done
paulson@13422
  1211
wenzelm@13428
  1212
lemmas list_closed = M_datatypes.list_closed [OF M_datatypes_L]
wenzelm@13428
  1213
  and formula_closed = M_datatypes.formula_closed [OF M_datatypes_L]
wenzelm@13428
  1214
  and list_abs = M_datatypes.list_abs [OF M_datatypes_L]
wenzelm@13428
  1215
  and formula_abs = M_datatypes.formula_abs [OF M_datatypes_L]
wenzelm@13428
  1216
  and nth_abs = M_datatypes.nth_abs [OF M_datatypes_L]
paulson@13409
  1217
paulson@13422
  1218
declare list_closed [intro,simp]
paulson@13422
  1219
declare formula_closed [intro,simp]
paulson@13422
  1220
declare list_abs [simp]
paulson@13422
  1221
declare formula_abs [simp]
paulson@13422
  1222
declare nth_abs [simp]
paulson@13422
  1223
paulson@13422
  1224
wenzelm@13428
  1225
subsection{*@{term L} is Closed Under the Operator @{term eclose}*}
paulson@13422
  1226
paulson@13422
  1227
subsubsection{*Instances of Replacement for @{term eclose}*}
paulson@13422
  1228
paulson@13422
  1229
lemma eclose_replacement1_Reflects:
paulson@13422
  1230
 "REFLECTS
paulson@13422
  1231
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13422
  1232
         is_wfrec(L, iterates_MH(L, big_union(L), A), memsn, u, y)),
paulson@13422
  1233
    \<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
  1234
         is_wfrec(**Lset(i),
wenzelm@13428
  1235
                  iterates_MH(**Lset(i), big_union(**Lset(i)), A),
paulson@13422
  1236
                  memsn, u, y))]"
wenzelm@13428
  1237
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
  1238
          iterates_MH_reflection)
paulson@13422
  1239
wenzelm@13428
  1240
lemma eclose_replacement1:
paulson@13422
  1241
   "L(A) ==> iterates_replacement(L, big_union(L), A)"
paulson@13422
  1242
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
  1243
apply (rule strong_replacementI)
paulson@13422
  1244
apply (rule rallI)
wenzelm@13428
  1245
apply (rename_tac B)
wenzelm@13428
  1246
apply (rule separation_CollectI)
wenzelm@13428
  1247
apply (subgoal_tac "L(Memrel(succ(n)))")
wenzelm@13428
  1248
apply (rule_tac A="{B,A,n,z,Memrel(succ(n))}" in subset_LsetE, blast )
paulson@13422
  1249
apply (rule ReflectsE [OF eclose_replacement1_Reflects], assumption)
wenzelm@13428
  1250
apply (drule subset_Lset_ltD, assumption)
paulson@13422
  1251
apply (erule reflection_imp_L_separation)
paulson@13422
  1252
  apply (simp_all add: lt_Ord2 Memrel_closed)
wenzelm@13428
  1253
apply (elim conjE)
paulson@13422
  1254
apply (rule DPow_LsetI)
wenzelm@13428
  1255
apply (rename_tac v)
paulson@13422
  1256
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13422
  1257
apply (rule_tac env = "[u,v,A,n,B,Memrel(succ(n))]" in mem_iff_sats)
paulson@13422
  1258
apply (rule sep_rules | simp)+
paulson@13434
  1259
apply (simp add: is_wfrec_def)
paulson@13434
  1260
apply (rule sep_rules iterates_MH_iff_sats is_nat_case_iff_sats
paulson@13434
  1261
             is_recfun_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
paulson@13409
  1262
done
paulson@13409
  1263
paulson@13422
  1264
paulson@13422
  1265
lemma eclose_replacement2_Reflects:
paulson@13422
  1266
 "REFLECTS
paulson@13422
  1267
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
paulson@13422
  1268
         (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
paulson@13422
  1269
           is_wfrec (L, iterates_MH (L, big_union(L), A),
paulson@13422
  1270
                              msn, u, x)),
paulson@13422
  1271
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
wenzelm@13428
  1272
         (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
paulson@13422
  1273
          successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
wenzelm@13428
  1274
           is_wfrec (**Lset(i),
paulson@13422
  1275
                 iterates_MH (**Lset(i), big_union(**Lset(i)), A),
paulson@13422
  1276
                     msn, u, x))]"
wenzelm@13428
  1277
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
  1278
          iterates_MH_reflection)
paulson@13422
  1279
paulson@13422
  1280
wenzelm@13428
  1281
lemma eclose_replacement2:
wenzelm@13428
  1282
   "L(A) ==> strong_replacement(L,
wenzelm@13428
  1283
         \<lambda>n y. n\<in>nat &
paulson@13422
  1284
               (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
wenzelm@13428
  1285
               is_wfrec(L, iterates_MH(L,big_union(L), A),
paulson@13422
  1286
                        msn, n, y)))"
wenzelm@13428
  1287
apply (rule strong_replacementI)
paulson@13422
  1288
apply (rule rallI)
wenzelm@13428
  1289
apply (rename_tac B)
wenzelm@13428
  1290
apply (rule separation_CollectI)
wenzelm@13428
  1291
apply (rule_tac A="{A,B,z,nat}" in subset_LsetE)
wenzelm@13428
  1292
apply (blast intro: L_nat)
paulson@13422
  1293
apply (rule ReflectsE [OF eclose_replacement2_Reflects], assumption)
wenzelm@13428
  1294
apply (drule subset_Lset_ltD, assumption)
paulson@13422
  1295
apply (erule reflection_imp_L_separation)
paulson@13422
  1296
  apply (simp_all add: lt_Ord2)
paulson@13422
  1297
apply (rule DPow_LsetI)
wenzelm@13428
  1298
apply (rename_tac v)
paulson@13422
  1299
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13422
  1300
apply (rule_tac env = "[u,v,A,B,nat]" in mem_iff_sats)
paulson@13422
  1301
apply (rule sep_rules | simp)+
paulson@13434
  1302
apply (simp add: is_wfrec_def)
paulson@13434
  1303
apply (rule sep_rules is_nat_case_iff_sats iterates_MH_iff_sats
paulson@13434
  1304
              is_recfun_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
paulson@13422
  1305
done
paulson@13422
  1306
paulson@13422
  1307
paulson@13422
  1308
subsubsection{*Instantiating the locale @{text M_eclose}*}
paulson@13422
  1309
wenzelm@13428
  1310
theorem M_eclose_L: "PROP M_eclose(L)"
wenzelm@13428
  1311
  apply (rule M_eclose.intro)
wenzelm@13429
  1312
       apply (rule M_datatypes.axioms [OF M_datatypes_L])+
wenzelm@13429
  1313
  apply (rule M_eclose_axioms.intro)
wenzelm@13429
  1314
   apply (assumption | rule eclose_replacement1 eclose_replacement2)+
wenzelm@13428
  1315
  done
paulson@13422
  1316
wenzelm@13428
  1317
lemmas eclose_closed [intro, simp] = M_eclose.eclose_closed [OF M_eclose_L]
wenzelm@13428
  1318
  and eclose_abs [intro, simp] = M_eclose.eclose_abs [OF M_eclose_L]
paulson@13422
  1319
paulson@13348
  1320
end