src/ZF/Constructible/Internalize.thy
author ballarin
Thu Dec 11 18:30:26 2008 +0100 (2008-12-11)
changeset 29223 e09c53289830
parent 21404 eb85850d3eb7
child 32960 69916a850301
permissions -rw-r--r--
Conversion of HOL-Main and ZF to new locales.
paulson@13505
     1
(*  Title:      ZF/Constructible/Internalize.thy
paulson@13505
     2
    ID: $Id$
paulson@13505
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@13505
     4
*)
paulson@13505
     5
haftmann@16417
     6
theory Internalize imports L_axioms Datatype_absolute begin
paulson@13496
     7
paulson@13496
     8
subsection{*Internalized Forms of Data Structuring Operators*}
paulson@13496
     9
paulson@13496
    10
subsubsection{*The Formula @{term is_Inl}, Internalized*}
paulson@13496
    11
paulson@13496
    12
(*  is_Inl(M,a,z) == \<exists>zero[M]. empty(M,zero) & pair(M,zero,a,z) *)
wenzelm@21404
    13
definition
wenzelm@21404
    14
  Inl_fm :: "[i,i]=>i" where
paulson@13496
    15
    "Inl_fm(a,z) == Exists(And(empty_fm(0), pair_fm(0,succ(a),succ(z))))"
paulson@13496
    16
paulson@13496
    17
lemma Inl_type [TC]:
paulson@13496
    18
     "[| x \<in> nat; z \<in> nat |] ==> Inl_fm(x,z) \<in> formula"
paulson@13496
    19
by (simp add: Inl_fm_def)
paulson@13496
    20
paulson@13496
    21
lemma sats_Inl_fm [simp]:
paulson@13496
    22
   "[| x \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13807
    23
    ==> sats(A, Inl_fm(x,z), env) <-> is_Inl(##A, nth(x,env), nth(z,env))"
paulson@13496
    24
by (simp add: Inl_fm_def is_Inl_def)
paulson@13496
    25
paulson@13496
    26
lemma Inl_iff_sats:
paulson@13496
    27
      "[| nth(i,env) = x; nth(k,env) = z;
paulson@13496
    28
          i \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13807
    29
       ==> is_Inl(##A, x, z) <-> sats(A, Inl_fm(i,k), env)"
paulson@13496
    30
by simp
paulson@13496
    31
paulson@13496
    32
theorem Inl_reflection:
paulson@13496
    33
     "REFLECTS[\<lambda>x. is_Inl(L,f(x),h(x)),
paulson@13807
    34
               \<lambda>i x. is_Inl(##Lset(i),f(x),h(x))]"
paulson@13655
    35
apply (simp only: is_Inl_def)
paulson@13496
    36
apply (intro FOL_reflections function_reflections)
paulson@13496
    37
done
paulson@13496
    38
paulson@13496
    39
paulson@13496
    40
subsubsection{*The Formula @{term is_Inr}, Internalized*}
paulson@13496
    41
paulson@13496
    42
(*  is_Inr(M,a,z) == \<exists>n1[M]. number1(M,n1) & pair(M,n1,a,z) *)
wenzelm@21404
    43
definition
wenzelm@21404
    44
  Inr_fm :: "[i,i]=>i" where
paulson@13496
    45
    "Inr_fm(a,z) == Exists(And(number1_fm(0), pair_fm(0,succ(a),succ(z))))"
paulson@13496
    46
paulson@13496
    47
lemma Inr_type [TC]:
paulson@13496
    48
     "[| x \<in> nat; z \<in> nat |] ==> Inr_fm(x,z) \<in> formula"
paulson@13496
    49
by (simp add: Inr_fm_def)
paulson@13496
    50
paulson@13496
    51
lemma sats_Inr_fm [simp]:
paulson@13496
    52
   "[| x \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13807
    53
    ==> sats(A, Inr_fm(x,z), env) <-> is_Inr(##A, nth(x,env), nth(z,env))"
paulson@13496
    54
by (simp add: Inr_fm_def is_Inr_def)
paulson@13496
    55
paulson@13496
    56
lemma Inr_iff_sats:
paulson@13496
    57
      "[| nth(i,env) = x; nth(k,env) = z;
paulson@13496
    58
          i \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13807
    59
       ==> is_Inr(##A, x, z) <-> sats(A, Inr_fm(i,k), env)"
paulson@13496
    60
by simp
paulson@13496
    61
paulson@13496
    62
theorem Inr_reflection:
paulson@13496
    63
     "REFLECTS[\<lambda>x. is_Inr(L,f(x),h(x)),
paulson@13807
    64
               \<lambda>i x. is_Inr(##Lset(i),f(x),h(x))]"
paulson@13655
    65
apply (simp only: is_Inr_def)
paulson@13496
    66
apply (intro FOL_reflections function_reflections)
paulson@13496
    67
done
paulson@13496
    68
paulson@13496
    69
paulson@13496
    70
subsubsection{*The Formula @{term is_Nil}, Internalized*}
paulson@13496
    71
paulson@13496
    72
(* is_Nil(M,xs) == \<exists>zero[M]. empty(M,zero) & is_Inl(M,zero,xs) *)
paulson@13496
    73
wenzelm@21404
    74
definition
wenzelm@21404
    75
  Nil_fm :: "i=>i" where
paulson@13496
    76
    "Nil_fm(x) == Exists(And(empty_fm(0), Inl_fm(0,succ(x))))"
paulson@13496
    77
paulson@13496
    78
lemma Nil_type [TC]: "x \<in> nat ==> Nil_fm(x) \<in> formula"
paulson@13496
    79
by (simp add: Nil_fm_def)
paulson@13496
    80
paulson@13496
    81
lemma sats_Nil_fm [simp]:
paulson@13496
    82
   "[| x \<in> nat; env \<in> list(A)|]
paulson@13807
    83
    ==> sats(A, Nil_fm(x), env) <-> is_Nil(##A, nth(x,env))"
paulson@13496
    84
by (simp add: Nil_fm_def is_Nil_def)
paulson@13496
    85
paulson@13496
    86
lemma Nil_iff_sats:
paulson@13496
    87
      "[| nth(i,env) = x; i \<in> nat; env \<in> list(A)|]
paulson@13807
    88
       ==> is_Nil(##A, x) <-> sats(A, Nil_fm(i), env)"
paulson@13496
    89
by simp
paulson@13496
    90
paulson@13496
    91
theorem Nil_reflection:
paulson@13496
    92
     "REFLECTS[\<lambda>x. is_Nil(L,f(x)),
paulson@13807
    93
               \<lambda>i x. is_Nil(##Lset(i),f(x))]"
paulson@13655
    94
apply (simp only: is_Nil_def)
paulson@13496
    95
apply (intro FOL_reflections function_reflections Inl_reflection)
paulson@13496
    96
done
paulson@13496
    97
paulson@13496
    98
paulson@13496
    99
subsubsection{*The Formula @{term is_Cons}, Internalized*}
paulson@13496
   100
paulson@13496
   101
paulson@13496
   102
(*  "is_Cons(M,a,l,Z) == \<exists>p[M]. pair(M,a,l,p) & is_Inr(M,p,Z)" *)
wenzelm@21404
   103
definition
wenzelm@21404
   104
  Cons_fm :: "[i,i,i]=>i" where
paulson@13496
   105
    "Cons_fm(a,l,Z) ==
paulson@13496
   106
       Exists(And(pair_fm(succ(a),succ(l),0), Inr_fm(0,succ(Z))))"
paulson@13496
   107
paulson@13496
   108
lemma Cons_type [TC]:
paulson@13496
   109
     "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> Cons_fm(x,y,z) \<in> formula"
paulson@13496
   110
by (simp add: Cons_fm_def)
paulson@13496
   111
paulson@13496
   112
lemma sats_Cons_fm [simp]:
paulson@13496
   113
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13496
   114
    ==> sats(A, Cons_fm(x,y,z), env) <->
paulson@13807
   115
       is_Cons(##A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13496
   116
by (simp add: Cons_fm_def is_Cons_def)
paulson@13496
   117
paulson@13496
   118
lemma Cons_iff_sats:
paulson@13496
   119
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13496
   120
          i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13807
   121
       ==>is_Cons(##A, x, y, z) <-> sats(A, Cons_fm(i,j,k), env)"
paulson@13496
   122
by simp
paulson@13496
   123
paulson@13496
   124
theorem Cons_reflection:
paulson@13496
   125
     "REFLECTS[\<lambda>x. is_Cons(L,f(x),g(x),h(x)),
paulson@13807
   126
               \<lambda>i x. is_Cons(##Lset(i),f(x),g(x),h(x))]"
paulson@13655
   127
apply (simp only: is_Cons_def)
paulson@13496
   128
apply (intro FOL_reflections pair_reflection Inr_reflection)
paulson@13496
   129
done
paulson@13496
   130
paulson@13496
   131
subsubsection{*The Formula @{term is_quasilist}, Internalized*}
paulson@13496
   132
paulson@13496
   133
(* is_quasilist(M,xs) == is_Nil(M,z) | (\<exists>x[M]. \<exists>l[M]. is_Cons(M,x,l,z))" *)
paulson@13496
   134
wenzelm@21404
   135
definition
wenzelm@21404
   136
  quasilist_fm :: "i=>i" where
paulson@13496
   137
    "quasilist_fm(x) ==
paulson@13496
   138
       Or(Nil_fm(x), Exists(Exists(Cons_fm(1,0,succ(succ(x))))))"
paulson@13496
   139
paulson@13496
   140
lemma quasilist_type [TC]: "x \<in> nat ==> quasilist_fm(x) \<in> formula"
paulson@13496
   141
by (simp add: quasilist_fm_def)
paulson@13496
   142
paulson@13496
   143
lemma sats_quasilist_fm [simp]:
paulson@13496
   144
   "[| x \<in> nat; env \<in> list(A)|]
paulson@13807
   145
    ==> sats(A, quasilist_fm(x), env) <-> is_quasilist(##A, nth(x,env))"
paulson@13496
   146
by (simp add: quasilist_fm_def is_quasilist_def)
paulson@13496
   147
paulson@13496
   148
lemma quasilist_iff_sats:
paulson@13496
   149
      "[| nth(i,env) = x; i \<in> nat; env \<in> list(A)|]
paulson@13807
   150
       ==> is_quasilist(##A, x) <-> sats(A, quasilist_fm(i), env)"
paulson@13496
   151
by simp
paulson@13496
   152
paulson@13496
   153
theorem quasilist_reflection:
paulson@13496
   154
     "REFLECTS[\<lambda>x. is_quasilist(L,f(x)),
paulson@13807
   155
               \<lambda>i x. is_quasilist(##Lset(i),f(x))]"
paulson@13655
   156
apply (simp only: is_quasilist_def)
paulson@13496
   157
apply (intro FOL_reflections Nil_reflection Cons_reflection)
paulson@13496
   158
done
paulson@13496
   159
paulson@13496
   160
paulson@13496
   161
subsection{*Absoluteness for the Function @{term nth}*}
paulson@13496
   162
paulson@13496
   163
paulson@13496
   164
subsubsection{*The Formula @{term is_hd}, Internalized*}
paulson@13496
   165
paulson@13496
   166
(*   "is_hd(M,xs,H) == 
paulson@13496
   167
       (is_Nil(M,xs) --> empty(M,H)) &
paulson@13496
   168
       (\<forall>x[M]. \<forall>l[M]. ~ is_Cons(M,x,l,xs) | H=x) &
paulson@13496
   169
       (is_quasilist(M,xs) | empty(M,H))" *)
wenzelm@21404
   170
definition
wenzelm@21404
   171
  hd_fm :: "[i,i]=>i" where
paulson@13496
   172
    "hd_fm(xs,H) == 
paulson@13496
   173
       And(Implies(Nil_fm(xs), empty_fm(H)),
paulson@13496
   174
           And(Forall(Forall(Or(Neg(Cons_fm(1,0,xs#+2)), Equal(H#+2,1)))),
paulson@13496
   175
               Or(quasilist_fm(xs), empty_fm(H))))"
paulson@13496
   176
paulson@13496
   177
lemma hd_type [TC]:
paulson@13496
   178
     "[| x \<in> nat; y \<in> nat |] ==> hd_fm(x,y) \<in> formula"
paulson@13496
   179
by (simp add: hd_fm_def) 
paulson@13496
   180
paulson@13496
   181
lemma sats_hd_fm [simp]:
paulson@13496
   182
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
paulson@13807
   183
    ==> sats(A, hd_fm(x,y), env) <-> is_hd(##A, nth(x,env), nth(y,env))"
paulson@13496
   184
by (simp add: hd_fm_def is_hd_def)
paulson@13496
   185
paulson@13496
   186
lemma hd_iff_sats:
paulson@13496
   187
      "[| nth(i,env) = x; nth(j,env) = y;
paulson@13496
   188
          i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@13807
   189
       ==> is_hd(##A, x, y) <-> sats(A, hd_fm(i,j), env)"
paulson@13496
   190
by simp
paulson@13496
   191
paulson@13496
   192
theorem hd_reflection:
paulson@13496
   193
     "REFLECTS[\<lambda>x. is_hd(L,f(x),g(x)), 
paulson@13807
   194
               \<lambda>i x. is_hd(##Lset(i),f(x),g(x))]"
paulson@13655
   195
apply (simp only: is_hd_def)
paulson@13496
   196
apply (intro FOL_reflections Nil_reflection Cons_reflection
paulson@13496
   197
             quasilist_reflection empty_reflection)  
paulson@13496
   198
done
paulson@13496
   199
paulson@13496
   200
paulson@13496
   201
subsubsection{*The Formula @{term is_tl}, Internalized*}
paulson@13496
   202
paulson@13496
   203
(*     "is_tl(M,xs,T) ==
paulson@13496
   204
       (is_Nil(M,xs) --> T=xs) &
paulson@13496
   205
       (\<forall>x[M]. \<forall>l[M]. ~ is_Cons(M,x,l,xs) | T=l) &
paulson@13496
   206
       (is_quasilist(M,xs) | empty(M,T))" *)
wenzelm@21404
   207
definition
wenzelm@21404
   208
  tl_fm :: "[i,i]=>i" where
paulson@13496
   209
    "tl_fm(xs,T) ==
paulson@13496
   210
       And(Implies(Nil_fm(xs), Equal(T,xs)),
paulson@13496
   211
           And(Forall(Forall(Or(Neg(Cons_fm(1,0,xs#+2)), Equal(T#+2,0)))),
paulson@13496
   212
               Or(quasilist_fm(xs), empty_fm(T))))"
paulson@13496
   213
paulson@13496
   214
lemma tl_type [TC]:
paulson@13496
   215
     "[| x \<in> nat; y \<in> nat |] ==> tl_fm(x,y) \<in> formula"
paulson@13496
   216
by (simp add: tl_fm_def)
paulson@13496
   217
paulson@13496
   218
lemma sats_tl_fm [simp]:
paulson@13496
   219
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
paulson@13807
   220
    ==> sats(A, tl_fm(x,y), env) <-> is_tl(##A, nth(x,env), nth(y,env))"
paulson@13496
   221
by (simp add: tl_fm_def is_tl_def)
paulson@13496
   222
paulson@13496
   223
lemma tl_iff_sats:
paulson@13496
   224
      "[| nth(i,env) = x; nth(j,env) = y;
paulson@13496
   225
          i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@13807
   226
       ==> is_tl(##A, x, y) <-> sats(A, tl_fm(i,j), env)"
paulson@13496
   227
by simp
paulson@13496
   228
paulson@13496
   229
theorem tl_reflection:
paulson@13496
   230
     "REFLECTS[\<lambda>x. is_tl(L,f(x),g(x)),
paulson@13807
   231
               \<lambda>i x. is_tl(##Lset(i),f(x),g(x))]"
paulson@13655
   232
apply (simp only: is_tl_def)
paulson@13496
   233
apply (intro FOL_reflections Nil_reflection Cons_reflection
paulson@13496
   234
             quasilist_reflection empty_reflection)
paulson@13496
   235
done
paulson@13496
   236
paulson@13496
   237
paulson@13496
   238
subsubsection{*The Operator @{term is_bool_of_o}*}
paulson@13496
   239
paulson@13496
   240
(*   is_bool_of_o :: "[i=>o, o, i] => o"
paulson@13496
   241
   "is_bool_of_o(M,P,z) == (P & number1(M,z)) | (~P & empty(M,z))" *)
paulson@13496
   242
paulson@13496
   243
text{*The formula @{term p} has no free variables.*}
wenzelm@21404
   244
definition
wenzelm@21404
   245
  bool_of_o_fm :: "[i, i]=>i" where
wenzelm@21404
   246
  "bool_of_o_fm(p,z) == 
paulson@13496
   247
    Or(And(p,number1_fm(z)),
paulson@13496
   248
       And(Neg(p),empty_fm(z)))"
paulson@13496
   249
paulson@13496
   250
lemma is_bool_of_o_type [TC]:
paulson@13496
   251
     "[| p \<in> formula; z \<in> nat |] ==> bool_of_o_fm(p,z) \<in> formula"
paulson@13496
   252
by (simp add: bool_of_o_fm_def)
paulson@13496
   253
paulson@13496
   254
lemma sats_bool_of_o_fm:
paulson@13496
   255
  assumes p_iff_sats: "P <-> sats(A, p, env)"
paulson@13496
   256
  shows 
paulson@13496
   257
      "[|z \<in> nat; env \<in> list(A)|]
paulson@13496
   258
       ==> sats(A, bool_of_o_fm(p,z), env) <->
paulson@13807
   259
           is_bool_of_o(##A, P, nth(z,env))"
paulson@13496
   260
by (simp add: bool_of_o_fm_def is_bool_of_o_def p_iff_sats [THEN iff_sym])
paulson@13496
   261
paulson@13496
   262
lemma is_bool_of_o_iff_sats:
paulson@13496
   263
  "[| P <-> sats(A, p, env); nth(k,env) = z; k \<in> nat; env \<in> list(A)|]
paulson@13807
   264
   ==> is_bool_of_o(##A, P, z) <-> sats(A, bool_of_o_fm(p,k), env)"
paulson@13496
   265
by (simp add: sats_bool_of_o_fm)
paulson@13496
   266
paulson@13496
   267
theorem bool_of_o_reflection:
paulson@13807
   268
     "REFLECTS [P(L), \<lambda>i. P(##Lset(i))] ==>
paulson@13496
   269
      REFLECTS[\<lambda>x. is_bool_of_o(L, P(L,x), f(x)),  
paulson@13807
   270
               \<lambda>i x. is_bool_of_o(##Lset(i), P(##Lset(i),x), f(x))]"
paulson@13655
   271
apply (simp (no_asm) only: is_bool_of_o_def)
paulson@13496
   272
apply (intro FOL_reflections function_reflections, assumption+)
paulson@13496
   273
done
paulson@13496
   274
paulson@13496
   275
paulson@13496
   276
subsection{*More Internalizations*}
paulson@13496
   277
paulson@13496
   278
subsubsection{*The Operator @{term is_lambda}*}
paulson@13496
   279
paulson@13496
   280
text{*The two arguments of @{term p} are always 1, 0. Remember that
paulson@13496
   281
 @{term p} will be enclosed by three quantifiers.*}
paulson@13496
   282
paulson@13496
   283
(* is_lambda :: "[i=>o, i, [i,i]=>o, i] => o"
paulson@13496
   284
    "is_lambda(M, A, is_b, z) == 
paulson@13496
   285
       \<forall>p[M]. p \<in> z <->
paulson@13496
   286
        (\<exists>u[M]. \<exists>v[M]. u\<in>A & pair(M,u,v,p) & is_b(u,v))" *)
wenzelm@21404
   287
definition
wenzelm@21404
   288
  lambda_fm :: "[i, i, i]=>i" where
wenzelm@21404
   289
  "lambda_fm(p,A,z) == 
paulson@13496
   290
    Forall(Iff(Member(0,succ(z)),
paulson@13496
   291
            Exists(Exists(And(Member(1,A#+3),
paulson@13496
   292
                           And(pair_fm(1,0,2), p))))))"
paulson@13496
   293
paulson@13496
   294
text{*We call @{term p} with arguments x, y by equating them with 
paulson@13496
   295
  the corresponding quantified variables with de Bruijn indices 1, 0.*}
paulson@13496
   296
paulson@13496
   297
lemma is_lambda_type [TC]:
paulson@13496
   298
     "[| p \<in> formula; x \<in> nat; y \<in> nat |] 
paulson@13496
   299
      ==> lambda_fm(p,x,y) \<in> formula"
paulson@13496
   300
by (simp add: lambda_fm_def) 
paulson@13496
   301
paulson@13496
   302
lemma sats_lambda_fm:
paulson@13496
   303
  assumes is_b_iff_sats: 
paulson@13496
   304
      "!!a0 a1 a2. 
paulson@13496
   305
        [|a0\<in>A; a1\<in>A; a2\<in>A|] 
paulson@13496
   306
        ==> is_b(a1, a0) <-> sats(A, p, Cons(a0,Cons(a1,Cons(a2,env))))"
paulson@13496
   307
  shows 
paulson@13496
   308
      "[|x \<in> nat; y \<in> nat; env \<in> list(A)|]
paulson@13496
   309
       ==> sats(A, lambda_fm(p,x,y), env) <-> 
paulson@13807
   310
           is_lambda(##A, nth(x,env), is_b, nth(y,env))"
paulson@13496
   311
by (simp add: lambda_fm_def is_lambda_def is_b_iff_sats [THEN iff_sym]) 
paulson@13496
   312
paulson@13496
   313
theorem is_lambda_reflection:
paulson@13496
   314
  assumes is_b_reflection:
paulson@13702
   315
    "!!f g h. REFLECTS[\<lambda>x. is_b(L, f(x), g(x), h(x)), 
paulson@13807
   316
                     \<lambda>i x. is_b(##Lset(i), f(x), g(x), h(x))]"
paulson@13496
   317
  shows "REFLECTS[\<lambda>x. is_lambda(L, A(x), is_b(L,x), f(x)), 
paulson@13807
   318
               \<lambda>i x. is_lambda(##Lset(i), A(x), is_b(##Lset(i),x), f(x))]"
paulson@13655
   319
apply (simp (no_asm_use) only: is_lambda_def)
paulson@13496
   320
apply (intro FOL_reflections is_b_reflection pair_reflection)
paulson@13496
   321
done
paulson@13496
   322
paulson@13496
   323
subsubsection{*The Operator @{term is_Member}, Internalized*}
paulson@13496
   324
paulson@13496
   325
(*    "is_Member(M,x,y,Z) ==
paulson@13496
   326
	\<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inl(M,p,u) & is_Inl(M,u,Z)" *)
wenzelm@21404
   327
definition
wenzelm@21404
   328
  Member_fm :: "[i,i,i]=>i" where
paulson@13496
   329
    "Member_fm(x,y,Z) ==
paulson@13496
   330
       Exists(Exists(And(pair_fm(x#+2,y#+2,1), 
paulson@13496
   331
                      And(Inl_fm(1,0), Inl_fm(0,Z#+2)))))"
paulson@13496
   332
paulson@13496
   333
lemma is_Member_type [TC]:
paulson@13496
   334
     "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> Member_fm(x,y,z) \<in> formula"
paulson@13496
   335
by (simp add: Member_fm_def)
paulson@13496
   336
paulson@13496
   337
lemma sats_Member_fm [simp]:
paulson@13496
   338
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13496
   339
    ==> sats(A, Member_fm(x,y,z), env) <->
paulson@13807
   340
        is_Member(##A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13496
   341
by (simp add: Member_fm_def is_Member_def)
paulson@13496
   342
paulson@13496
   343
lemma Member_iff_sats:
paulson@13496
   344
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13496
   345
          i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13807
   346
       ==> is_Member(##A, x, y, z) <-> sats(A, Member_fm(i,j,k), env)"
paulson@13496
   347
by (simp add: sats_Member_fm)
paulson@13496
   348
paulson@13496
   349
theorem Member_reflection:
paulson@13496
   350
     "REFLECTS[\<lambda>x. is_Member(L,f(x),g(x),h(x)),
paulson@13807
   351
               \<lambda>i x. is_Member(##Lset(i),f(x),g(x),h(x))]"
paulson@13655
   352
apply (simp only: is_Member_def)
paulson@13496
   353
apply (intro FOL_reflections pair_reflection Inl_reflection)
paulson@13496
   354
done
paulson@13496
   355
paulson@13496
   356
subsubsection{*The Operator @{term is_Equal}, Internalized*}
paulson@13496
   357
paulson@13496
   358
(*    "is_Equal(M,x,y,Z) ==
paulson@13496
   359
	\<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inr(M,p,u) & is_Inl(M,u,Z)" *)
wenzelm@21404
   360
definition
wenzelm@21404
   361
  Equal_fm :: "[i,i,i]=>i" where
paulson@13496
   362
    "Equal_fm(x,y,Z) ==
paulson@13496
   363
       Exists(Exists(And(pair_fm(x#+2,y#+2,1), 
paulson@13496
   364
                      And(Inr_fm(1,0), Inl_fm(0,Z#+2)))))"
paulson@13496
   365
paulson@13496
   366
lemma is_Equal_type [TC]:
paulson@13496
   367
     "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> Equal_fm(x,y,z) \<in> formula"
paulson@13496
   368
by (simp add: Equal_fm_def)
paulson@13496
   369
paulson@13496
   370
lemma sats_Equal_fm [simp]:
paulson@13496
   371
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13496
   372
    ==> sats(A, Equal_fm(x,y,z), env) <->
paulson@13807
   373
        is_Equal(##A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13496
   374
by (simp add: Equal_fm_def is_Equal_def)
paulson@13496
   375
paulson@13496
   376
lemma Equal_iff_sats:
paulson@13496
   377
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13496
   378
          i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13807
   379
       ==> is_Equal(##A, x, y, z) <-> sats(A, Equal_fm(i,j,k), env)"
paulson@13496
   380
by (simp add: sats_Equal_fm)
paulson@13496
   381
paulson@13496
   382
theorem Equal_reflection:
paulson@13496
   383
     "REFLECTS[\<lambda>x. is_Equal(L,f(x),g(x),h(x)),
paulson@13807
   384
               \<lambda>i x. is_Equal(##Lset(i),f(x),g(x),h(x))]"
paulson@13655
   385
apply (simp only: is_Equal_def)
paulson@13496
   386
apply (intro FOL_reflections pair_reflection Inl_reflection Inr_reflection)
paulson@13496
   387
done
paulson@13496
   388
paulson@13496
   389
subsubsection{*The Operator @{term is_Nand}, Internalized*}
paulson@13496
   390
paulson@13496
   391
(*    "is_Nand(M,x,y,Z) ==
paulson@13496
   392
	\<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inl(M,p,u) & is_Inr(M,u,Z)" *)
wenzelm@21404
   393
definition
wenzelm@21404
   394
  Nand_fm :: "[i,i,i]=>i" where
paulson@13496
   395
    "Nand_fm(x,y,Z) ==
paulson@13496
   396
       Exists(Exists(And(pair_fm(x#+2,y#+2,1), 
paulson@13496
   397
                      And(Inl_fm(1,0), Inr_fm(0,Z#+2)))))"
paulson@13496
   398
paulson@13496
   399
lemma is_Nand_type [TC]:
paulson@13496
   400
     "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> Nand_fm(x,y,z) \<in> formula"
paulson@13496
   401
by (simp add: Nand_fm_def)
paulson@13496
   402
paulson@13496
   403
lemma sats_Nand_fm [simp]:
paulson@13496
   404
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13496
   405
    ==> sats(A, Nand_fm(x,y,z), env) <->
paulson@13807
   406
        is_Nand(##A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13496
   407
by (simp add: Nand_fm_def is_Nand_def)
paulson@13496
   408
paulson@13496
   409
lemma Nand_iff_sats:
paulson@13496
   410
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13496
   411
          i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13807
   412
       ==> is_Nand(##A, x, y, z) <-> sats(A, Nand_fm(i,j,k), env)"
paulson@13496
   413
by (simp add: sats_Nand_fm)
paulson@13496
   414
paulson@13496
   415
theorem Nand_reflection:
paulson@13496
   416
     "REFLECTS[\<lambda>x. is_Nand(L,f(x),g(x),h(x)),
paulson@13807
   417
               \<lambda>i x. is_Nand(##Lset(i),f(x),g(x),h(x))]"
paulson@13655
   418
apply (simp only: is_Nand_def)
paulson@13496
   419
apply (intro FOL_reflections pair_reflection Inl_reflection Inr_reflection)
paulson@13496
   420
done
paulson@13496
   421
paulson@13496
   422
subsubsection{*The Operator @{term is_Forall}, Internalized*}
paulson@13496
   423
paulson@13496
   424
(* "is_Forall(M,p,Z) == \<exists>u[M]. is_Inr(M,p,u) & is_Inr(M,u,Z)" *)
wenzelm@21404
   425
definition
wenzelm@21404
   426
  Forall_fm :: "[i,i]=>i" where
paulson@13496
   427
    "Forall_fm(x,Z) ==
paulson@13496
   428
       Exists(And(Inr_fm(succ(x),0), Inr_fm(0,succ(Z))))"
paulson@13496
   429
paulson@13496
   430
lemma is_Forall_type [TC]:
paulson@13496
   431
     "[| x \<in> nat; y \<in> nat |] ==> Forall_fm(x,y) \<in> formula"
paulson@13496
   432
by (simp add: Forall_fm_def)
paulson@13496
   433
paulson@13496
   434
lemma sats_Forall_fm [simp]:
paulson@13496
   435
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
paulson@13496
   436
    ==> sats(A, Forall_fm(x,y), env) <->
paulson@13807
   437
        is_Forall(##A, nth(x,env), nth(y,env))"
paulson@13496
   438
by (simp add: Forall_fm_def is_Forall_def)
paulson@13496
   439
paulson@13496
   440
lemma Forall_iff_sats:
paulson@13496
   441
      "[| nth(i,env) = x; nth(j,env) = y; 
paulson@13496
   442
          i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@13807
   443
       ==> is_Forall(##A, x, y) <-> sats(A, Forall_fm(i,j), env)"
paulson@13496
   444
by (simp add: sats_Forall_fm)
paulson@13496
   445
paulson@13496
   446
theorem Forall_reflection:
paulson@13496
   447
     "REFLECTS[\<lambda>x. is_Forall(L,f(x),g(x)),
paulson@13807
   448
               \<lambda>i x. is_Forall(##Lset(i),f(x),g(x))]"
paulson@13655
   449
apply (simp only: is_Forall_def)
paulson@13496
   450
apply (intro FOL_reflections pair_reflection Inr_reflection)
paulson@13496
   451
done
paulson@13496
   452
paulson@13496
   453
paulson@13496
   454
subsubsection{*The Operator @{term is_and}, Internalized*}
paulson@13496
   455
paulson@13496
   456
(* is_and(M,a,b,z) == (number1(M,a)  & z=b) | 
paulson@13496
   457
                       (~number1(M,a) & empty(M,z)) *)
wenzelm@21404
   458
definition
wenzelm@21404
   459
  and_fm :: "[i,i,i]=>i" where
paulson@13496
   460
    "and_fm(a,b,z) ==
paulson@13496
   461
       Or(And(number1_fm(a), Equal(z,b)),
paulson@13496
   462
          And(Neg(number1_fm(a)),empty_fm(z)))"
paulson@13496
   463
paulson@13496
   464
lemma is_and_type [TC]:
paulson@13496
   465
     "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> and_fm(x,y,z) \<in> formula"
paulson@13496
   466
by (simp add: and_fm_def)
paulson@13496
   467
paulson@13496
   468
lemma sats_and_fm [simp]:
paulson@13496
   469
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13496
   470
    ==> sats(A, and_fm(x,y,z), env) <->
paulson@13807
   471
        is_and(##A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13496
   472
by (simp add: and_fm_def is_and_def)
paulson@13496
   473
paulson@13496
   474
lemma is_and_iff_sats:
paulson@13496
   475
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13496
   476
          i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13807
   477
       ==> is_and(##A, x, y, z) <-> sats(A, and_fm(i,j,k), env)"
paulson@13496
   478
by simp
paulson@13496
   479
paulson@13496
   480
theorem is_and_reflection:
paulson@13496
   481
     "REFLECTS[\<lambda>x. is_and(L,f(x),g(x),h(x)),
paulson@13807
   482
               \<lambda>i x. is_and(##Lset(i),f(x),g(x),h(x))]"
paulson@13655
   483
apply (simp only: is_and_def)
paulson@13496
   484
apply (intro FOL_reflections function_reflections)
paulson@13496
   485
done
paulson@13496
   486
paulson@13496
   487
paulson@13496
   488
subsubsection{*The Operator @{term is_or}, Internalized*}
paulson@13496
   489
paulson@13496
   490
(* is_or(M,a,b,z) == (number1(M,a)  & number1(M,z)) | 
paulson@13496
   491
                     (~number1(M,a) & z=b) *)
paulson@13496
   492
wenzelm@21404
   493
definition
wenzelm@21404
   494
  or_fm :: "[i,i,i]=>i" where
paulson@13496
   495
    "or_fm(a,b,z) ==
paulson@13496
   496
       Or(And(number1_fm(a), number1_fm(z)),
paulson@13496
   497
          And(Neg(number1_fm(a)), Equal(z,b)))"
paulson@13496
   498
paulson@13496
   499
lemma is_or_type [TC]:
paulson@13496
   500
     "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> or_fm(x,y,z) \<in> formula"
paulson@13496
   501
by (simp add: or_fm_def)
paulson@13496
   502
paulson@13496
   503
lemma sats_or_fm [simp]:
paulson@13496
   504
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13496
   505
    ==> sats(A, or_fm(x,y,z), env) <->
paulson@13807
   506
        is_or(##A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13496
   507
by (simp add: or_fm_def is_or_def)
paulson@13496
   508
paulson@13496
   509
lemma is_or_iff_sats:
paulson@13496
   510
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13496
   511
          i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13807
   512
       ==> is_or(##A, x, y, z) <-> sats(A, or_fm(i,j,k), env)"
paulson@13496
   513
by simp
paulson@13496
   514
paulson@13496
   515
theorem is_or_reflection:
paulson@13496
   516
     "REFLECTS[\<lambda>x. is_or(L,f(x),g(x),h(x)),
paulson@13807
   517
               \<lambda>i x. is_or(##Lset(i),f(x),g(x),h(x))]"
paulson@13655
   518
apply (simp only: is_or_def)
paulson@13496
   519
apply (intro FOL_reflections function_reflections)
paulson@13496
   520
done
paulson@13496
   521
paulson@13496
   522
paulson@13496
   523
paulson@13496
   524
subsubsection{*The Operator @{term is_not}, Internalized*}
paulson@13496
   525
paulson@13496
   526
(* is_not(M,a,z) == (number1(M,a)  & empty(M,z)) | 
paulson@13496
   527
                     (~number1(M,a) & number1(M,z)) *)
wenzelm@21404
   528
definition
wenzelm@21404
   529
  not_fm :: "[i,i]=>i" where
paulson@13496
   530
    "not_fm(a,z) ==
paulson@13496
   531
       Or(And(number1_fm(a), empty_fm(z)),
paulson@13496
   532
          And(Neg(number1_fm(a)), number1_fm(z)))"
paulson@13496
   533
paulson@13496
   534
lemma is_not_type [TC]:
paulson@13496
   535
     "[| x \<in> nat; z \<in> nat |] ==> not_fm(x,z) \<in> formula"
paulson@13496
   536
by (simp add: not_fm_def)
paulson@13496
   537
paulson@13496
   538
lemma sats_is_not_fm [simp]:
paulson@13496
   539
   "[| x \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13807
   540
    ==> sats(A, not_fm(x,z), env) <-> is_not(##A, nth(x,env), nth(z,env))"
paulson@13496
   541
by (simp add: not_fm_def is_not_def)
paulson@13496
   542
paulson@13496
   543
lemma is_not_iff_sats:
paulson@13496
   544
      "[| nth(i,env) = x; nth(k,env) = z;
paulson@13496
   545
          i \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13807
   546
       ==> is_not(##A, x, z) <-> sats(A, not_fm(i,k), env)"
paulson@13496
   547
by simp
paulson@13496
   548
paulson@13496
   549
theorem is_not_reflection:
paulson@13496
   550
     "REFLECTS[\<lambda>x. is_not(L,f(x),g(x)),
paulson@13807
   551
               \<lambda>i x. is_not(##Lset(i),f(x),g(x))]"
paulson@13655
   552
apply (simp only: is_not_def)
paulson@13496
   553
apply (intro FOL_reflections function_reflections)
paulson@13496
   554
done
paulson@13496
   555
paulson@13496
   556
paulson@13496
   557
lemmas extra_reflections = 
paulson@13496
   558
    Inl_reflection Inr_reflection Nil_reflection Cons_reflection
paulson@13496
   559
    quasilist_reflection hd_reflection tl_reflection bool_of_o_reflection
paulson@13496
   560
    is_lambda_reflection Member_reflection Equal_reflection Nand_reflection
paulson@13496
   561
    Forall_reflection is_and_reflection is_or_reflection is_not_reflection
paulson@13496
   562
paulson@13503
   563
subsection{*Well-Founded Recursion!*}
paulson@13503
   564
paulson@13506
   565
subsubsection{*The Operator @{term M_is_recfun}*}
paulson@13503
   566
paulson@13503
   567
text{*Alternative definition, minimizing nesting of quantifiers around MH*}
paulson@13503
   568
lemma M_is_recfun_iff:
paulson@13503
   569
   "M_is_recfun(M,MH,r,a,f) <->
paulson@13503
   570
    (\<forall>z[M]. z \<in> f <-> 
paulson@13503
   571
     (\<exists>x[M]. \<exists>f_r_sx[M]. \<exists>y[M]. 
paulson@13503
   572
             MH(x, f_r_sx, y) & pair(M,x,y,z) &
paulson@13503
   573
             (\<exists>xa[M]. \<exists>sx[M]. \<exists>r_sx[M]. 
paulson@13503
   574
                pair(M,x,a,xa) & upair(M,x,x,sx) &
paulson@13503
   575
               pre_image(M,r,sx,r_sx) & restriction(M,f,r_sx,f_r_sx) &
paulson@13503
   576
               xa \<in> r)))"
paulson@13503
   577
apply (simp add: M_is_recfun_def)
paulson@13503
   578
apply (rule rall_cong, blast) 
paulson@13503
   579
done
paulson@13503
   580
paulson@13503
   581
paulson@13503
   582
(* M_is_recfun :: "[i=>o, [i,i,i]=>o, i, i, i] => o"
paulson@13503
   583
   "M_is_recfun(M,MH,r,a,f) ==
paulson@13503
   584
     \<forall>z[M]. z \<in> f <->
paulson@13503
   585
               2      1           0
paulson@13503
   586
new def     (\<exists>x[M]. \<exists>f_r_sx[M]. \<exists>y[M]. 
paulson@13503
   587
             MH(x, f_r_sx, y) & pair(M,x,y,z) &
paulson@13503
   588
             (\<exists>xa[M]. \<exists>sx[M]. \<exists>r_sx[M]. 
paulson@13503
   589
                pair(M,x,a,xa) & upair(M,x,x,sx) &
paulson@13503
   590
               pre_image(M,r,sx,r_sx) & restriction(M,f,r_sx,f_r_sx) &
paulson@13503
   591
               xa \<in> r)"
paulson@13503
   592
*)
paulson@13503
   593
paulson@13503
   594
text{*The three arguments of @{term p} are always 2, 1, 0 and z*}
wenzelm@21404
   595
definition
wenzelm@21404
   596
  is_recfun_fm :: "[i, i, i, i]=>i" where
wenzelm@21404
   597
  "is_recfun_fm(p,r,a,f) == 
paulson@13503
   598
   Forall(Iff(Member(0,succ(f)),
paulson@13503
   599
    Exists(Exists(Exists(
paulson@13503
   600
     And(p, 
paulson@13503
   601
      And(pair_fm(2,0,3),
paulson@13503
   602
       Exists(Exists(Exists(
paulson@13503
   603
	And(pair_fm(5,a#+7,2),
paulson@13503
   604
	 And(upair_fm(5,5,1),
paulson@13503
   605
	  And(pre_image_fm(r#+7,1,0),
paulson@13503
   606
	   And(restriction_fm(f#+7,0,4), Member(2,r#+7)))))))))))))))"
paulson@13503
   607
paulson@13503
   608
lemma is_recfun_type [TC]:
paulson@13503
   609
     "[| p \<in> formula; x \<in> nat; y \<in> nat; z \<in> nat |] 
paulson@13503
   610
      ==> is_recfun_fm(p,x,y,z) \<in> formula"
paulson@13503
   611
by (simp add: is_recfun_fm_def)
paulson@13503
   612
paulson@13503
   613
paulson@13503
   614
lemma sats_is_recfun_fm:
paulson@13503
   615
  assumes MH_iff_sats: 
paulson@13503
   616
      "!!a0 a1 a2 a3. 
paulson@13503
   617
        [|a0\<in>A; a1\<in>A; a2\<in>A; a3\<in>A|] 
paulson@13503
   618
        ==> MH(a2, a1, a0) <-> sats(A, p, Cons(a0,Cons(a1,Cons(a2,Cons(a3,env)))))"
paulson@13503
   619
  shows 
paulson@13503
   620
      "[|x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13503
   621
       ==> sats(A, is_recfun_fm(p,x,y,z), env) <->
paulson@13807
   622
           M_is_recfun(##A, MH, nth(x,env), nth(y,env), nth(z,env))"
paulson@13503
   623
by (simp add: is_recfun_fm_def M_is_recfun_iff MH_iff_sats [THEN iff_sym])
paulson@13503
   624
paulson@13503
   625
lemma is_recfun_iff_sats:
paulson@13503
   626
  assumes MH_iff_sats: 
paulson@13503
   627
      "!!a0 a1 a2 a3. 
paulson@13503
   628
        [|a0\<in>A; a1\<in>A; a2\<in>A; a3\<in>A|] 
paulson@13503
   629
        ==> MH(a2, a1, a0) <-> sats(A, p, Cons(a0,Cons(a1,Cons(a2,Cons(a3,env)))))"
paulson@13503
   630
  shows
paulson@13503
   631
  "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
paulson@13503
   632
      i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13807
   633
   ==> M_is_recfun(##A, MH, x, y, z) <-> sats(A, is_recfun_fm(p,i,j,k), env)"
paulson@13503
   634
by (simp add: sats_is_recfun_fm [OF MH_iff_sats]) 
paulson@13503
   635
paulson@13503
   636
text{*The additional variable in the premise, namely @{term f'}, is essential.
paulson@13503
   637
It lets @{term MH} depend upon @{term x}, which seems often necessary.
paulson@13503
   638
The same thing occurs in @{text is_wfrec_reflection}.*}
paulson@13503
   639
theorem is_recfun_reflection:
paulson@13503
   640
  assumes MH_reflection:
paulson@13503
   641
    "!!f' f g h. REFLECTS[\<lambda>x. MH(L, f'(x), f(x), g(x), h(x)), 
paulson@13807
   642
                     \<lambda>i x. MH(##Lset(i), f'(x), f(x), g(x), h(x))]"
paulson@13503
   643
  shows "REFLECTS[\<lambda>x. M_is_recfun(L, MH(L,x), f(x), g(x), h(x)), 
paulson@13807
   644
             \<lambda>i x. M_is_recfun(##Lset(i), MH(##Lset(i),x), f(x), g(x), h(x))]"
paulson@13655
   645
apply (simp (no_asm_use) only: M_is_recfun_def)
paulson@13503
   646
apply (intro FOL_reflections function_reflections
paulson@13503
   647
             restriction_reflection MH_reflection)
paulson@13503
   648
done
paulson@13503
   649
paulson@13503
   650
subsubsection{*The Operator @{term is_wfrec}*}
paulson@13503
   651
paulson@13655
   652
text{*The three arguments of @{term p} are always 2, 1, 0;
paulson@13655
   653
      @{term p} is enclosed by 5 quantifiers.*}
paulson@13503
   654
paulson@13503
   655
(* is_wfrec :: "[i=>o, i, [i,i,i]=>o, i, i] => o"
paulson@13503
   656
    "is_wfrec(M,MH,r,a,z) == 
paulson@13503
   657
      \<exists>f[M]. M_is_recfun(M,MH,r,a,f) & MH(a,f,z)" *)
wenzelm@21404
   658
definition
wenzelm@21404
   659
  is_wfrec_fm :: "[i, i, i, i]=>i" where
wenzelm@21404
   660
  "is_wfrec_fm(p,r,a,z) == 
paulson@13503
   661
    Exists(And(is_recfun_fm(p, succ(r), succ(a), 0),
paulson@13503
   662
           Exists(Exists(Exists(Exists(
paulson@13503
   663
             And(Equal(2,a#+5), And(Equal(1,4), And(Equal(0,z#+5), p)))))))))"
paulson@13503
   664
paulson@13503
   665
text{*We call @{term p} with arguments a, f, z by equating them with 
paulson@13503
   666
  the corresponding quantified variables with de Bruijn indices 2, 1, 0.*}
paulson@13503
   667
paulson@13503
   668
text{*There's an additional existential quantifier to ensure that the
paulson@13503
   669
      environments in both calls to MH have the same length.*}
paulson@13503
   670
paulson@13503
   671
lemma is_wfrec_type [TC]:
paulson@13503
   672
     "[| p \<in> formula; x \<in> nat; y \<in> nat; z \<in> nat |] 
paulson@13503
   673
      ==> is_wfrec_fm(p,x,y,z) \<in> formula"
paulson@13503
   674
by (simp add: is_wfrec_fm_def) 
paulson@13503
   675
paulson@13503
   676
lemma sats_is_wfrec_fm:
paulson@13503
   677
  assumes MH_iff_sats: 
paulson@13503
   678
      "!!a0 a1 a2 a3 a4. 
paulson@13503
   679
        [|a0\<in>A; a1\<in>A; a2\<in>A; a3\<in>A; a4\<in>A|] 
paulson@13503
   680
        ==> MH(a2, a1, a0) <-> sats(A, p, Cons(a0,Cons(a1,Cons(a2,Cons(a3,Cons(a4,env))))))"
paulson@13503
   681
  shows 
paulson@13503
   682
      "[|x \<in> nat; y < length(env); z < length(env); env \<in> list(A)|]
paulson@13503
   683
       ==> sats(A, is_wfrec_fm(p,x,y,z), env) <-> 
paulson@13807
   684
           is_wfrec(##A, MH, nth(x,env), nth(y,env), nth(z,env))"
paulson@13503
   685
apply (frule_tac x=z in lt_length_in_nat, assumption)  
paulson@13503
   686
apply (frule lt_length_in_nat, assumption)  
paulson@13503
   687
apply (simp add: is_wfrec_fm_def sats_is_recfun_fm is_wfrec_def MH_iff_sats [THEN iff_sym], blast) 
paulson@13503
   688
done
paulson@13503
   689
paulson@13503
   690
paulson@13503
   691
lemma is_wfrec_iff_sats:
paulson@13503
   692
  assumes MH_iff_sats: 
paulson@13503
   693
      "!!a0 a1 a2 a3 a4. 
paulson@13503
   694
        [|a0\<in>A; a1\<in>A; a2\<in>A; a3\<in>A; a4\<in>A|] 
paulson@13503
   695
        ==> MH(a2, a1, a0) <-> sats(A, p, Cons(a0,Cons(a1,Cons(a2,Cons(a3,Cons(a4,env))))))"
paulson@13503
   696
  shows
paulson@13503
   697
  "[|nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
paulson@13503
   698
      i \<in> nat; j < length(env); k < length(env); env \<in> list(A)|]
paulson@13807
   699
   ==> is_wfrec(##A, MH, x, y, z) <-> sats(A, is_wfrec_fm(p,i,j,k), env)" 
paulson@13503
   700
by (simp add: sats_is_wfrec_fm [OF MH_iff_sats])
paulson@13503
   701
paulson@13503
   702
theorem is_wfrec_reflection:
paulson@13503
   703
  assumes MH_reflection:
paulson@13503
   704
    "!!f' f g h. REFLECTS[\<lambda>x. MH(L, f'(x), f(x), g(x), h(x)), 
paulson@13807
   705
                     \<lambda>i x. MH(##Lset(i), f'(x), f(x), g(x), h(x))]"
paulson@13503
   706
  shows "REFLECTS[\<lambda>x. is_wfrec(L, MH(L,x), f(x), g(x), h(x)), 
paulson@13807
   707
               \<lambda>i x. is_wfrec(##Lset(i), MH(##Lset(i),x), f(x), g(x), h(x))]"
paulson@13655
   708
apply (simp (no_asm_use) only: is_wfrec_def)
paulson@13503
   709
apply (intro FOL_reflections MH_reflection is_recfun_reflection)
paulson@13503
   710
done
paulson@13503
   711
paulson@13503
   712
paulson@13503
   713
subsection{*For Datatypes*}
paulson@13503
   714
paulson@13503
   715
subsubsection{*Binary Products, Internalized*}
paulson@13503
   716
wenzelm@21404
   717
definition
wenzelm@21404
   718
  cartprod_fm :: "[i,i,i]=>i" where
paulson@13503
   719
(* "cartprod(M,A,B,z) ==
paulson@13503
   720
        \<forall>u[M]. u \<in> z <-> (\<exists>x[M]. x\<in>A & (\<exists>y[M]. y\<in>B & pair(M,x,y,u)))" *)
paulson@13503
   721
    "cartprod_fm(A,B,z) ==
paulson@13503
   722
       Forall(Iff(Member(0,succ(z)),
paulson@13503
   723
                  Exists(And(Member(0,succ(succ(A))),
paulson@13503
   724
                         Exists(And(Member(0,succ(succ(succ(B)))),
paulson@13503
   725
                                    pair_fm(1,0,2)))))))"
paulson@13503
   726
paulson@13503
   727
lemma cartprod_type [TC]:
paulson@13503
   728
     "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> cartprod_fm(x,y,z) \<in> formula"
paulson@13503
   729
by (simp add: cartprod_fm_def)
paulson@13503
   730
paulson@13503
   731
lemma sats_cartprod_fm [simp]:
paulson@13503
   732
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13503
   733
    ==> sats(A, cartprod_fm(x,y,z), env) <->
paulson@13807
   734
        cartprod(##A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13503
   735
by (simp add: cartprod_fm_def cartprod_def)
paulson@13503
   736
paulson@13503
   737
lemma cartprod_iff_sats:
paulson@13503
   738
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13503
   739
          i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13807
   740
       ==> cartprod(##A, x, y, z) <-> sats(A, cartprod_fm(i,j,k), env)"
paulson@13503
   741
by (simp add: sats_cartprod_fm)
paulson@13503
   742
paulson@13503
   743
theorem cartprod_reflection:
paulson@13503
   744
     "REFLECTS[\<lambda>x. cartprod(L,f(x),g(x),h(x)),
paulson@13807
   745
               \<lambda>i x. cartprod(##Lset(i),f(x),g(x),h(x))]"
paulson@13655
   746
apply (simp only: cartprod_def)
paulson@13503
   747
apply (intro FOL_reflections pair_reflection)
paulson@13503
   748
done
paulson@13503
   749
paulson@13503
   750
paulson@13503
   751
subsubsection{*Binary Sums, Internalized*}
paulson@13503
   752
paulson@13503
   753
(* "is_sum(M,A,B,Z) ==
paulson@13503
   754
       \<exists>A0[M]. \<exists>n1[M]. \<exists>s1[M]. \<exists>B1[M].
paulson@13503
   755
         3      2       1        0
paulson@13503
   756
       number1(M,n1) & cartprod(M,n1,A,A0) & upair(M,n1,n1,s1) &
paulson@13503
   757
       cartprod(M,s1,B,B1) & union(M,A0,B1,Z)"  *)
wenzelm@21404
   758
definition
wenzelm@21404
   759
  sum_fm :: "[i,i,i]=>i" where
paulson@13503
   760
    "sum_fm(A,B,Z) ==
paulson@13503
   761
       Exists(Exists(Exists(Exists(
paulson@13503
   762
        And(number1_fm(2),
paulson@13503
   763
            And(cartprod_fm(2,A#+4,3),
paulson@13503
   764
                And(upair_fm(2,2,1),
paulson@13503
   765
                    And(cartprod_fm(1,B#+4,0), union_fm(3,0,Z#+4)))))))))"
paulson@13503
   766
paulson@13503
   767
lemma sum_type [TC]:
paulson@13503
   768
     "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> sum_fm(x,y,z) \<in> formula"
paulson@13503
   769
by (simp add: sum_fm_def)
paulson@13503
   770
paulson@13503
   771
lemma sats_sum_fm [simp]:
paulson@13503
   772
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13503
   773
    ==> sats(A, sum_fm(x,y,z), env) <->
paulson@13807
   774
        is_sum(##A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13503
   775
by (simp add: sum_fm_def is_sum_def)
paulson@13503
   776
paulson@13503
   777
lemma sum_iff_sats:
paulson@13503
   778
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13503
   779
          i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13807
   780
       ==> is_sum(##A, x, y, z) <-> sats(A, sum_fm(i,j,k), env)"
paulson@13503
   781
by simp
paulson@13503
   782
paulson@13503
   783
theorem sum_reflection:
paulson@13503
   784
     "REFLECTS[\<lambda>x. is_sum(L,f(x),g(x),h(x)),
paulson@13807
   785
               \<lambda>i x. is_sum(##Lset(i),f(x),g(x),h(x))]"
paulson@13655
   786
apply (simp only: is_sum_def)
paulson@13503
   787
apply (intro FOL_reflections function_reflections cartprod_reflection)
paulson@13503
   788
done
paulson@13503
   789
paulson@13503
   790
paulson@13503
   791
subsubsection{*The Operator @{term quasinat}*}
paulson@13503
   792
paulson@13503
   793
(* "is_quasinat(M,z) == empty(M,z) | (\<exists>m[M]. successor(M,m,z))" *)
wenzelm@21404
   794
definition
wenzelm@21404
   795
  quasinat_fm :: "i=>i" where
paulson@13503
   796
    "quasinat_fm(z) == Or(empty_fm(z), Exists(succ_fm(0,succ(z))))"
paulson@13503
   797
paulson@13503
   798
lemma quasinat_type [TC]:
paulson@13503
   799
     "x \<in> nat ==> quasinat_fm(x) \<in> formula"
paulson@13503
   800
by (simp add: quasinat_fm_def)
paulson@13503
   801
paulson@13503
   802
lemma sats_quasinat_fm [simp]:
paulson@13503
   803
   "[| x \<in> nat; env \<in> list(A)|]
paulson@13807
   804
    ==> sats(A, quasinat_fm(x), env) <-> is_quasinat(##A, nth(x,env))"
paulson@13503
   805
by (simp add: quasinat_fm_def is_quasinat_def)
paulson@13503
   806
paulson@13503
   807
lemma quasinat_iff_sats:
paulson@13503
   808
      "[| nth(i,env) = x; nth(j,env) = y;
paulson@13503
   809
          i \<in> nat; env \<in> list(A)|]
paulson@13807
   810
       ==> is_quasinat(##A, x) <-> sats(A, quasinat_fm(i), env)"
paulson@13503
   811
by simp
paulson@13503
   812
paulson@13503
   813
theorem quasinat_reflection:
paulson@13503
   814
     "REFLECTS[\<lambda>x. is_quasinat(L,f(x)),
paulson@13807
   815
               \<lambda>i x. is_quasinat(##Lset(i),f(x))]"
paulson@13655
   816
apply (simp only: is_quasinat_def)
paulson@13503
   817
apply (intro FOL_reflections function_reflections)
paulson@13503
   818
done
paulson@13503
   819
paulson@13503
   820
paulson@13503
   821
subsubsection{*The Operator @{term is_nat_case}*}
paulson@13503
   822
text{*I could not get it to work with the more natural assumption that 
paulson@13503
   823
 @{term is_b} takes two arguments.  Instead it must be a formula where 1 and 0
paulson@13503
   824
 stand for @{term m} and @{term b}, respectively.*}
paulson@13503
   825
paulson@13503
   826
(* is_nat_case :: "[i=>o, i, [i,i]=>o, i, i] => o"
paulson@13503
   827
    "is_nat_case(M, a, is_b, k, z) ==
paulson@13503
   828
       (empty(M,k) --> z=a) &
paulson@13503
   829
       (\<forall>m[M]. successor(M,m,k) --> is_b(m,z)) &
paulson@13503
   830
       (is_quasinat(M,k) | empty(M,z))" *)
paulson@13503
   831
text{*The formula @{term is_b} has free variables 1 and 0.*}
wenzelm@21404
   832
definition
wenzelm@21404
   833
  is_nat_case_fm :: "[i, i, i, i]=>i" where
paulson@13503
   834
 "is_nat_case_fm(a,is_b,k,z) == 
paulson@13503
   835
    And(Implies(empty_fm(k), Equal(z,a)),
paulson@13503
   836
        And(Forall(Implies(succ_fm(0,succ(k)), 
paulson@13503
   837
                   Forall(Implies(Equal(0,succ(succ(z))), is_b)))),
paulson@13503
   838
            Or(quasinat_fm(k), empty_fm(z))))"
paulson@13503
   839
paulson@13503
   840
lemma is_nat_case_type [TC]:
paulson@13503
   841
     "[| is_b \<in> formula;  
paulson@13503
   842
         x \<in> nat; y \<in> nat; z \<in> nat |] 
paulson@13503
   843
      ==> is_nat_case_fm(x,is_b,y,z) \<in> formula"
paulson@13503
   844
by (simp add: is_nat_case_fm_def)
paulson@13503
   845
paulson@13503
   846
lemma sats_is_nat_case_fm:
paulson@13503
   847
  assumes is_b_iff_sats: 
paulson@13503
   848
      "!!a. a \<in> A ==> is_b(a,nth(z, env)) <-> 
paulson@13503
   849
                      sats(A, p, Cons(nth(z,env), Cons(a, env)))"
paulson@13503
   850
  shows 
paulson@13503
   851
      "[|x \<in> nat; y \<in> nat; z < length(env); env \<in> list(A)|]
paulson@13503
   852
       ==> sats(A, is_nat_case_fm(x,p,y,z), env) <->
paulson@13807
   853
           is_nat_case(##A, nth(x,env), is_b, nth(y,env), nth(z,env))"
paulson@13503
   854
apply (frule lt_length_in_nat, assumption)
paulson@13503
   855
apply (simp add: is_nat_case_fm_def is_nat_case_def is_b_iff_sats [THEN iff_sym])
paulson@13503
   856
done
paulson@13503
   857
paulson@13503
   858
lemma is_nat_case_iff_sats:
paulson@13503
   859
  "[| (!!a. a \<in> A ==> is_b(a,z) <->
paulson@13503
   860
                      sats(A, p, Cons(z, Cons(a,env))));
paulson@13503
   861
      nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
paulson@13503
   862
      i \<in> nat; j \<in> nat; k < length(env); env \<in> list(A)|]
paulson@13807
   863
   ==> is_nat_case(##A, x, is_b, y, z) <-> sats(A, is_nat_case_fm(i,p,j,k), env)"
paulson@13503
   864
by (simp add: sats_is_nat_case_fm [of A is_b])
paulson@13503
   865
paulson@13503
   866
paulson@13503
   867
text{*The second argument of @{term is_b} gives it direct access to @{term x},
paulson@13503
   868
  which is essential for handling free variable references.  Without this
paulson@13503
   869
  argument, we cannot prove reflection for @{term iterates_MH}.*}
paulson@13503
   870
theorem is_nat_case_reflection:
paulson@13503
   871
  assumes is_b_reflection:
paulson@13503
   872
    "!!h f g. REFLECTS[\<lambda>x. is_b(L, h(x), f(x), g(x)),
paulson@13807
   873
                     \<lambda>i x. is_b(##Lset(i), h(x), f(x), g(x))]"
paulson@13503
   874
  shows "REFLECTS[\<lambda>x. is_nat_case(L, f(x), is_b(L,x), g(x), h(x)),
paulson@13807
   875
               \<lambda>i x. is_nat_case(##Lset(i), f(x), is_b(##Lset(i), x), g(x), h(x))]"
paulson@13655
   876
apply (simp (no_asm_use) only: is_nat_case_def)
paulson@13503
   877
apply (intro FOL_reflections function_reflections
paulson@13503
   878
             restriction_reflection is_b_reflection quasinat_reflection)
paulson@13503
   879
done
paulson@13503
   880
paulson@13503
   881
paulson@13503
   882
subsection{*The Operator @{term iterates_MH}, Needed for Iteration*}
paulson@13503
   883
paulson@13503
   884
(*  iterates_MH :: "[i=>o, [i,i]=>o, i, i, i, i] => o"
paulson@13503
   885
   "iterates_MH(M,isF,v,n,g,z) ==
paulson@13503
   886
        is_nat_case(M, v, \<lambda>m u. \<exists>gm[M]. fun_apply(M,g,m,gm) & isF(gm,u),
paulson@13503
   887
                    n, z)" *)
wenzelm@21404
   888
definition
wenzelm@21404
   889
  iterates_MH_fm :: "[i, i, i, i, i]=>i" where
paulson@13503
   890
 "iterates_MH_fm(isF,v,n,g,z) == 
paulson@13503
   891
    is_nat_case_fm(v, 
paulson@13503
   892
      Exists(And(fun_apply_fm(succ(succ(succ(g))),2,0), 
paulson@13503
   893
                     Forall(Implies(Equal(0,2), isF)))), 
paulson@13503
   894
      n, z)"
paulson@13503
   895
paulson@13503
   896
lemma iterates_MH_type [TC]:
paulson@13503
   897
     "[| p \<in> formula;  
paulson@13503
   898
         v \<in> nat; x \<in> nat; y \<in> nat; z \<in> nat |] 
paulson@13503
   899
      ==> iterates_MH_fm(p,v,x,y,z) \<in> formula"
paulson@13503
   900
by (simp add: iterates_MH_fm_def)
paulson@13503
   901
paulson@13503
   902
lemma sats_iterates_MH_fm:
paulson@13503
   903
  assumes is_F_iff_sats:
paulson@13503
   904
      "!!a b c d. [| a \<in> A; b \<in> A; c \<in> A; d \<in> A|]
paulson@13503
   905
              ==> is_F(a,b) <->
paulson@13503
   906
                  sats(A, p, Cons(b, Cons(a, Cons(c, Cons(d,env)))))"
paulson@13503
   907
  shows 
paulson@13503
   908
      "[|v \<in> nat; x \<in> nat; y \<in> nat; z < length(env); env \<in> list(A)|]
paulson@13503
   909
       ==> sats(A, iterates_MH_fm(p,v,x,y,z), env) <->
paulson@13807
   910
           iterates_MH(##A, is_F, nth(v,env), nth(x,env), nth(y,env), nth(z,env))"
paulson@13503
   911
apply (frule lt_length_in_nat, assumption)  
paulson@13503
   912
apply (simp add: iterates_MH_fm_def iterates_MH_def sats_is_nat_case_fm 
paulson@13503
   913
              is_F_iff_sats [symmetric])
paulson@13503
   914
apply (rule is_nat_case_cong) 
paulson@13503
   915
apply (simp_all add: setclass_def)
paulson@13503
   916
done
paulson@13503
   917
paulson@13503
   918
lemma iterates_MH_iff_sats:
paulson@13503
   919
  assumes is_F_iff_sats:
paulson@13503
   920
      "!!a b c d. [| a \<in> A; b \<in> A; c \<in> A; d \<in> A|]
paulson@13503
   921
              ==> is_F(a,b) <->
paulson@13503
   922
                  sats(A, p, Cons(b, Cons(a, Cons(c, Cons(d,env)))))"
paulson@13503
   923
  shows 
paulson@13503
   924
  "[| nth(i',env) = v; nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
paulson@13503
   925
      i' \<in> nat; i \<in> nat; j \<in> nat; k < length(env); env \<in> list(A)|]
paulson@13807
   926
   ==> iterates_MH(##A, is_F, v, x, y, z) <->
paulson@13503
   927
       sats(A, iterates_MH_fm(p,i',i,j,k), env)"
paulson@13503
   928
by (simp add: sats_iterates_MH_fm [OF is_F_iff_sats]) 
paulson@13503
   929
paulson@13503
   930
text{*The second argument of @{term p} gives it direct access to @{term x},
paulson@13503
   931
  which is essential for handling free variable references.  Without this
paulson@13503
   932
  argument, we cannot prove reflection for @{term list_N}.*}
paulson@13503
   933
theorem iterates_MH_reflection:
paulson@13503
   934
  assumes p_reflection:
paulson@13503
   935
    "!!f g h. REFLECTS[\<lambda>x. p(L, h(x), f(x), g(x)),
paulson@13807
   936
                     \<lambda>i x. p(##Lset(i), h(x), f(x), g(x))]"
paulson@13503
   937
 shows "REFLECTS[\<lambda>x. iterates_MH(L, p(L,x), e(x), f(x), g(x), h(x)),
paulson@13807
   938
               \<lambda>i x. iterates_MH(##Lset(i), p(##Lset(i),x), e(x), f(x), g(x), h(x))]"
paulson@13503
   939
apply (simp (no_asm_use) only: iterates_MH_def)
paulson@13503
   940
apply (intro FOL_reflections function_reflections is_nat_case_reflection
paulson@13503
   941
             restriction_reflection p_reflection)
paulson@13503
   942
done
paulson@13503
   943
paulson@13503
   944
paulson@13655
   945
subsubsection{*The Operator @{term is_iterates}*}
paulson@13655
   946
paulson@13655
   947
text{*The three arguments of @{term p} are always 2, 1, 0;
paulson@13655
   948
      @{term p} is enclosed by 9 (??) quantifiers.*}
paulson@13655
   949
paulson@13655
   950
(*    "is_iterates(M,isF,v,n,Z) == 
paulson@13655
   951
      \<exists>sn[M]. \<exists>msn[M]. successor(M,n,sn) & membership(M,sn,msn) &
paulson@13655
   952
       1       0       is_wfrec(M, iterates_MH(M,isF,v), msn, n, Z)"*)
paulson@13655
   953
wenzelm@21404
   954
definition
wenzelm@21404
   955
  is_iterates_fm :: "[i, i, i, i]=>i" where
wenzelm@21404
   956
  "is_iterates_fm(p,v,n,Z) == 
paulson@13655
   957
     Exists(Exists(
paulson@13655
   958
      And(succ_fm(n#+2,1),
paulson@13655
   959
       And(Memrel_fm(1,0),
paulson@13655
   960
              is_wfrec_fm(iterates_MH_fm(p, v#+7, 2, 1, 0), 
paulson@13655
   961
                          0, n#+2, Z#+2)))))"
paulson@13655
   962
paulson@13655
   963
text{*We call @{term p} with arguments a, f, z by equating them with 
paulson@13655
   964
  the corresponding quantified variables with de Bruijn indices 2, 1, 0.*}
paulson@13655
   965
paulson@13655
   966
paulson@13655
   967
lemma is_iterates_type [TC]:
paulson@13655
   968
     "[| p \<in> formula; x \<in> nat; y \<in> nat; z \<in> nat |] 
paulson@13655
   969
      ==> is_iterates_fm(p,x,y,z) \<in> formula"
paulson@13655
   970
by (simp add: is_iterates_fm_def) 
paulson@13655
   971
paulson@13655
   972
lemma sats_is_iterates_fm:
paulson@13655
   973
  assumes is_F_iff_sats:
paulson@13655
   974
      "!!a b c d e f g h i j k. 
paulson@13655
   975
              [| a \<in> A; b \<in> A; c \<in> A; d \<in> A; e \<in> A; f \<in> A; 
paulson@13655
   976
                 g \<in> A; h \<in> A; i \<in> A; j \<in> A; k \<in> A|]
paulson@13655
   977
              ==> is_F(a,b) <->
paulson@13655
   978
                  sats(A, p, Cons(b, Cons(a, Cons(c, Cons(d, Cons(e, Cons(f, 
paulson@13655
   979
                      Cons(g, Cons(h, Cons(i, Cons(j, Cons(k, env))))))))))))"
paulson@13655
   980
  shows 
paulson@13655
   981
      "[|x \<in> nat; y < length(env); z < length(env); env \<in> list(A)|]
paulson@13655
   982
       ==> sats(A, is_iterates_fm(p,x,y,z), env) <->
paulson@13807
   983
           is_iterates(##A, is_F, nth(x,env), nth(y,env), nth(z,env))"
paulson@13655
   984
apply (frule_tac x=z in lt_length_in_nat, assumption)  
paulson@13655
   985
apply (frule lt_length_in_nat, assumption)  
paulson@13655
   986
apply (simp add: is_iterates_fm_def is_iterates_def sats_is_nat_case_fm 
paulson@13655
   987
              is_F_iff_sats [symmetric] sats_is_wfrec_fm sats_iterates_MH_fm)
paulson@13655
   988
done
paulson@13655
   989
paulson@13655
   990
paulson@13655
   991
lemma is_iterates_iff_sats:
paulson@13655
   992
  assumes is_F_iff_sats:
paulson@13655
   993
      "!!a b c d e f g h i j k. 
paulson@13655
   994
              [| a \<in> A; b \<in> A; c \<in> A; d \<in> A; e \<in> A; f \<in> A; 
paulson@13655
   995
                 g \<in> A; h \<in> A; i \<in> A; j \<in> A; k \<in> A|]
paulson@13655
   996
              ==> is_F(a,b) <->
paulson@13655
   997
                  sats(A, p, Cons(b, Cons(a, Cons(c, Cons(d, Cons(e, Cons(f, 
paulson@13655
   998
                      Cons(g, Cons(h, Cons(i, Cons(j, Cons(k, env))))))))))))"
paulson@13655
   999
  shows 
paulson@13655
  1000
  "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
paulson@13655
  1001
      i \<in> nat; j < length(env); k < length(env); env \<in> list(A)|]
paulson@13807
  1002
   ==> is_iterates(##A, is_F, x, y, z) <->
paulson@13655
  1003
       sats(A, is_iterates_fm(p,i,j,k), env)"
paulson@13655
  1004
by (simp add: sats_is_iterates_fm [OF is_F_iff_sats]) 
paulson@13655
  1005
paulson@13655
  1006
text{*The second argument of @{term p} gives it direct access to @{term x},
paulson@13655
  1007
  which is essential for handling free variable references.  Without this
paulson@13655
  1008
  argument, we cannot prove reflection for @{term list_N}.*}
paulson@13655
  1009
theorem is_iterates_reflection:
paulson@13655
  1010
  assumes p_reflection:
paulson@13655
  1011
    "!!f g h. REFLECTS[\<lambda>x. p(L, h(x), f(x), g(x)),
paulson@13807
  1012
                     \<lambda>i x. p(##Lset(i), h(x), f(x), g(x))]"
paulson@13655
  1013
 shows "REFLECTS[\<lambda>x. is_iterates(L, p(L,x), f(x), g(x), h(x)),
paulson@13807
  1014
               \<lambda>i x. is_iterates(##Lset(i), p(##Lset(i),x), f(x), g(x), h(x))]"
paulson@13655
  1015
apply (simp (no_asm_use) only: is_iterates_def)
paulson@13655
  1016
apply (intro FOL_reflections function_reflections p_reflection
paulson@13655
  1017
             is_wfrec_reflection iterates_MH_reflection)
paulson@13655
  1018
done
paulson@13655
  1019
paulson@13503
  1020
paulson@13503
  1021
subsubsection{*The Formula @{term is_eclose_n}, Internalized*}
paulson@13503
  1022
paulson@13655
  1023
(* is_eclose_n(M,A,n,Z) == is_iterates(M, big_union(M), A, n, Z) *)
paulson@13503
  1024
wenzelm@21404
  1025
definition
wenzelm@21404
  1026
  eclose_n_fm :: "[i,i,i]=>i" where
paulson@13655
  1027
  "eclose_n_fm(A,n,Z) == is_iterates_fm(big_union_fm(1,0), A, n, Z)"
paulson@13503
  1028
paulson@13503
  1029
lemma eclose_n_fm_type [TC]:
paulson@13503
  1030
 "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> eclose_n_fm(x,y,z) \<in> formula"
paulson@13503
  1031
by (simp add: eclose_n_fm_def)
paulson@13503
  1032
paulson@13503
  1033
lemma sats_eclose_n_fm [simp]:
paulson@13503
  1034
   "[| x \<in> nat; y < length(env); z < length(env); env \<in> list(A)|]
paulson@13503
  1035
    ==> sats(A, eclose_n_fm(x,y,z), env) <->
paulson@13807
  1036
        is_eclose_n(##A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13503
  1037
apply (frule_tac x=z in lt_length_in_nat, assumption)  
paulson@13503
  1038
apply (frule_tac x=y in lt_length_in_nat, assumption)  
paulson@13655
  1039
apply (simp add: eclose_n_fm_def is_eclose_n_def 
paulson@13655
  1040
                 sats_is_iterates_fm) 
paulson@13503
  1041
done
paulson@13503
  1042
paulson@13503
  1043
lemma eclose_n_iff_sats:
paulson@13503
  1044
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13503
  1045
          i \<in> nat; j < length(env); k < length(env); env \<in> list(A)|]
paulson@13807
  1046
       ==> is_eclose_n(##A, x, y, z) <-> sats(A, eclose_n_fm(i,j,k), env)"
paulson@13503
  1047
by (simp add: sats_eclose_n_fm)
paulson@13503
  1048
paulson@13503
  1049
theorem eclose_n_reflection:
paulson@13503
  1050
     "REFLECTS[\<lambda>x. is_eclose_n(L, f(x), g(x), h(x)),  
paulson@13807
  1051
               \<lambda>i x. is_eclose_n(##Lset(i), f(x), g(x), h(x))]"
paulson@13655
  1052
apply (simp only: is_eclose_n_def)
paulson@13655
  1053
apply (intro FOL_reflections function_reflections is_iterates_reflection) 
paulson@13503
  1054
done
paulson@13503
  1055
paulson@13503
  1056
paulson@13503
  1057
subsubsection{*Membership in @{term "eclose(A)"}*}
paulson@13503
  1058
paulson@13503
  1059
(* mem_eclose(M,A,l) == 
paulson@13503
  1060
      \<exists>n[M]. \<exists>eclosen[M]. 
paulson@13503
  1061
       finite_ordinal(M,n) & is_eclose_n(M,A,n,eclosen) & l \<in> eclosen *)
wenzelm@21404
  1062
definition
wenzelm@21404
  1063
  mem_eclose_fm :: "[i,i]=>i" where
paulson@13503
  1064
    "mem_eclose_fm(x,y) ==
paulson@13503
  1065
       Exists(Exists(
paulson@13503
  1066
         And(finite_ordinal_fm(1),
paulson@13503
  1067
           And(eclose_n_fm(x#+2,1,0), Member(y#+2,0)))))"
paulson@13503
  1068
paulson@13503
  1069
lemma mem_eclose_type [TC]:
paulson@13503
  1070
     "[| x \<in> nat; y \<in> nat |] ==> mem_eclose_fm(x,y) \<in> formula"
paulson@13503
  1071
by (simp add: mem_eclose_fm_def)
paulson@13503
  1072
paulson@13503
  1073
lemma sats_mem_eclose_fm [simp]:
paulson@13503
  1074
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
paulson@13807
  1075
    ==> sats(A, mem_eclose_fm(x,y), env) <-> mem_eclose(##A, nth(x,env), nth(y,env))"
paulson@13503
  1076
by (simp add: mem_eclose_fm_def mem_eclose_def)
paulson@13503
  1077
paulson@13503
  1078
lemma mem_eclose_iff_sats:
paulson@13503
  1079
      "[| nth(i,env) = x; nth(j,env) = y;
paulson@13503
  1080
          i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@13807
  1081
       ==> mem_eclose(##A, x, y) <-> sats(A, mem_eclose_fm(i,j), env)"
paulson@13503
  1082
by simp
paulson@13503
  1083
paulson@13503
  1084
theorem mem_eclose_reflection:
paulson@13503
  1085
     "REFLECTS[\<lambda>x. mem_eclose(L,f(x),g(x)),
paulson@13807
  1086
               \<lambda>i x. mem_eclose(##Lset(i),f(x),g(x))]"
paulson@13655
  1087
apply (simp only: mem_eclose_def)
paulson@13503
  1088
apply (intro FOL_reflections finite_ordinal_reflection eclose_n_reflection)
paulson@13503
  1089
done
paulson@13503
  1090
paulson@13503
  1091
paulson@13503
  1092
subsubsection{*The Predicate ``Is @{term "eclose(A)"}''*}
paulson@13503
  1093
paulson@13503
  1094
(* is_eclose(M,A,Z) == \<forall>l[M]. l \<in> Z <-> mem_eclose(M,A,l) *)
wenzelm@21404
  1095
definition
wenzelm@21404
  1096
  is_eclose_fm :: "[i,i]=>i" where
paulson@13503
  1097
    "is_eclose_fm(A,Z) ==
paulson@13503
  1098
       Forall(Iff(Member(0,succ(Z)), mem_eclose_fm(succ(A),0)))"
paulson@13503
  1099
paulson@13503
  1100
lemma is_eclose_type [TC]:
paulson@13503
  1101
     "[| x \<in> nat; y \<in> nat |] ==> is_eclose_fm(x,y) \<in> formula"
paulson@13503
  1102
by (simp add: is_eclose_fm_def)
paulson@13503
  1103
paulson@13503
  1104
lemma sats_is_eclose_fm [simp]:
paulson@13503
  1105
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
paulson@13807
  1106
    ==> sats(A, is_eclose_fm(x,y), env) <-> is_eclose(##A, nth(x,env), nth(y,env))"
paulson@13503
  1107
by (simp add: is_eclose_fm_def is_eclose_def)
paulson@13503
  1108
paulson@13503
  1109
lemma is_eclose_iff_sats:
paulson@13503
  1110
      "[| nth(i,env) = x; nth(j,env) = y;
paulson@13503
  1111
          i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@13807
  1112
       ==> is_eclose(##A, x, y) <-> sats(A, is_eclose_fm(i,j), env)"
paulson@13503
  1113
by simp
paulson@13503
  1114
paulson@13503
  1115
theorem is_eclose_reflection:
paulson@13503
  1116
     "REFLECTS[\<lambda>x. is_eclose(L,f(x),g(x)),
paulson@13807
  1117
               \<lambda>i x. is_eclose(##Lset(i),f(x),g(x))]"
paulson@13655
  1118
apply (simp only: is_eclose_def)
paulson@13503
  1119
apply (intro FOL_reflections mem_eclose_reflection)
paulson@13503
  1120
done
paulson@13503
  1121
paulson@13503
  1122
paulson@13503
  1123
subsubsection{*The List Functor, Internalized*}
paulson@13503
  1124
wenzelm@21404
  1125
definition
wenzelm@21404
  1126
  list_functor_fm :: "[i,i,i]=>i" where
paulson@13503
  1127
(* "is_list_functor(M,A,X,Z) ==
paulson@13503
  1128
        \<exists>n1[M]. \<exists>AX[M].
paulson@13503
  1129
         number1(M,n1) & cartprod(M,A,X,AX) & is_sum(M,n1,AX,Z)" *)
paulson@13503
  1130
    "list_functor_fm(A,X,Z) ==
paulson@13503
  1131
       Exists(Exists(
paulson@13503
  1132
        And(number1_fm(1),
paulson@13503
  1133
            And(cartprod_fm(A#+2,X#+2,0), sum_fm(1,0,Z#+2)))))"
paulson@13503
  1134
paulson@13503
  1135
lemma list_functor_type [TC]:
paulson@13503
  1136
     "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> list_functor_fm(x,y,z) \<in> formula"
paulson@13503
  1137
by (simp add: list_functor_fm_def)
paulson@13503
  1138
paulson@13503
  1139
lemma sats_list_functor_fm [simp]:
paulson@13503
  1140
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13503
  1141
    ==> sats(A, list_functor_fm(x,y,z), env) <->
paulson@13807
  1142
        is_list_functor(##A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13503
  1143
by (simp add: list_functor_fm_def is_list_functor_def)
paulson@13503
  1144
paulson@13503
  1145
lemma list_functor_iff_sats:
paulson@13503
  1146
  "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13503
  1147
      i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13807
  1148
   ==> is_list_functor(##A, x, y, z) <-> sats(A, list_functor_fm(i,j,k), env)"
paulson@13503
  1149
by simp
paulson@13503
  1150
paulson@13503
  1151
theorem list_functor_reflection:
paulson@13503
  1152
     "REFLECTS[\<lambda>x. is_list_functor(L,f(x),g(x),h(x)),
paulson@13807
  1153
               \<lambda>i x. is_list_functor(##Lset(i),f(x),g(x),h(x))]"
paulson@13655
  1154
apply (simp only: is_list_functor_def)
paulson@13503
  1155
apply (intro FOL_reflections number1_reflection
paulson@13503
  1156
             cartprod_reflection sum_reflection)
paulson@13503
  1157
done
paulson@13503
  1158
paulson@13503
  1159
paulson@13503
  1160
subsubsection{*The Formula @{term is_list_N}, Internalized*}
paulson@13503
  1161
paulson@13503
  1162
(* "is_list_N(M,A,n,Z) == 
paulson@13655
  1163
      \<exists>zero[M]. empty(M,zero) & 
paulson@13655
  1164
                is_iterates(M, is_list_functor(M,A), zero, n, Z)" *)
paulson@13655
  1165
wenzelm@21404
  1166
definition
wenzelm@21404
  1167
  list_N_fm :: "[i,i,i]=>i" where
paulson@13503
  1168
  "list_N_fm(A,n,Z) == 
paulson@13655
  1169
     Exists(
paulson@13655
  1170
       And(empty_fm(0),
paulson@13655
  1171
           is_iterates_fm(list_functor_fm(A#+9#+3,1,0), 0, n#+1, Z#+1)))"
paulson@13503
  1172
paulson@13503
  1173
lemma list_N_fm_type [TC]:
paulson@13503
  1174
 "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> list_N_fm(x,y,z) \<in> formula"
paulson@13503
  1175
by (simp add: list_N_fm_def)
paulson@13503
  1176
paulson@13503
  1177
lemma sats_list_N_fm [simp]:
paulson@13503
  1178
   "[| x \<in> nat; y < length(env); z < length(env); env \<in> list(A)|]
paulson@13503
  1179
    ==> sats(A, list_N_fm(x,y,z), env) <->
paulson@13807
  1180
        is_list_N(##A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13503
  1181
apply (frule_tac x=z in lt_length_in_nat, assumption)  
paulson@13503
  1182
apply (frule_tac x=y in lt_length_in_nat, assumption)  
paulson@13655
  1183
apply (simp add: list_N_fm_def is_list_N_def sats_is_iterates_fm) 
paulson@13503
  1184
done
paulson@13503
  1185
paulson@13503
  1186
lemma list_N_iff_sats:
paulson@13503
  1187
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13503
  1188
          i \<in> nat; j < length(env); k < length(env); env \<in> list(A)|]
paulson@13807
  1189
       ==> is_list_N(##A, x, y, z) <-> sats(A, list_N_fm(i,j,k), env)"
paulson@13503
  1190
by (simp add: sats_list_N_fm)
paulson@13503
  1191
paulson@13503
  1192
theorem list_N_reflection:
paulson@13503
  1193
     "REFLECTS[\<lambda>x. is_list_N(L, f(x), g(x), h(x)),  
paulson@13807
  1194
               \<lambda>i x. is_list_N(##Lset(i), f(x), g(x), h(x))]"
paulson@13655
  1195
apply (simp only: is_list_N_def)
paulson@13655
  1196
apply (intro FOL_reflections function_reflections 
paulson@13655
  1197
             is_iterates_reflection list_functor_reflection) 
paulson@13503
  1198
done
paulson@13503
  1199
paulson@13503
  1200
paulson@13503
  1201
paulson@13503
  1202
subsubsection{*The Predicate ``Is A List''*}
paulson@13503
  1203
paulson@13503
  1204
(* mem_list(M,A,l) == 
paulson@13503
  1205
      \<exists>n[M]. \<exists>listn[M]. 
paulson@13503
  1206
       finite_ordinal(M,n) & is_list_N(M,A,n,listn) & l \<in> listn *)
wenzelm@21404
  1207
definition
wenzelm@21404
  1208
  mem_list_fm :: "[i,i]=>i" where
paulson@13503
  1209
    "mem_list_fm(x,y) ==
paulson@13503
  1210
       Exists(Exists(
paulson@13503
  1211
         And(finite_ordinal_fm(1),
paulson@13503
  1212
           And(list_N_fm(x#+2,1,0), Member(y#+2,0)))))"
paulson@13503
  1213
paulson@13503
  1214
lemma mem_list_type [TC]:
paulson@13503
  1215
     "[| x \<in> nat; y \<in> nat |] ==> mem_list_fm(x,y) \<in> formula"
paulson@13503
  1216
by (simp add: mem_list_fm_def)
paulson@13503
  1217
paulson@13503
  1218
lemma sats_mem_list_fm [simp]:
paulson@13503
  1219
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
paulson@13807
  1220
    ==> sats(A, mem_list_fm(x,y), env) <-> mem_list(##A, nth(x,env), nth(y,env))"
paulson@13503
  1221
by (simp add: mem_list_fm_def mem_list_def)
paulson@13503
  1222
paulson@13503
  1223
lemma mem_list_iff_sats:
paulson@13503
  1224
      "[| nth(i,env) = x; nth(j,env) = y;
paulson@13503
  1225
          i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@13807
  1226
       ==> mem_list(##A, x, y) <-> sats(A, mem_list_fm(i,j), env)"
paulson@13503
  1227
by simp
paulson@13503
  1228
paulson@13503
  1229
theorem mem_list_reflection:
paulson@13503
  1230
     "REFLECTS[\<lambda>x. mem_list(L,f(x),g(x)),
paulson@13807
  1231
               \<lambda>i x. mem_list(##Lset(i),f(x),g(x))]"
paulson@13655
  1232
apply (simp only: mem_list_def)
paulson@13503
  1233
apply (intro FOL_reflections finite_ordinal_reflection list_N_reflection)
paulson@13503
  1234
done
paulson@13503
  1235
paulson@13503
  1236
paulson@13503
  1237
subsubsection{*The Predicate ``Is @{term "list(A)"}''*}
paulson@13503
  1238
paulson@13503
  1239
(* is_list(M,A,Z) == \<forall>l[M]. l \<in> Z <-> mem_list(M,A,l) *)
wenzelm@21404
  1240
definition
wenzelm@21404
  1241
  is_list_fm :: "[i,i]=>i" where
paulson@13503
  1242
    "is_list_fm(A,Z) ==
paulson@13503
  1243
       Forall(Iff(Member(0,succ(Z)), mem_list_fm(succ(A),0)))"
paulson@13503
  1244
paulson@13503
  1245
lemma is_list_type [TC]:
paulson@13503
  1246
     "[| x \<in> nat; y \<in> nat |] ==> is_list_fm(x,y) \<in> formula"
paulson@13503
  1247
by (simp add: is_list_fm_def)
paulson@13503
  1248
paulson@13503
  1249
lemma sats_is_list_fm [simp]:
paulson@13503
  1250
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
paulson@13807
  1251
    ==> sats(A, is_list_fm(x,y), env) <-> is_list(##A, nth(x,env), nth(y,env))"
paulson@13503
  1252
by (simp add: is_list_fm_def is_list_def)
paulson@13503
  1253
paulson@13503
  1254
lemma is_list_iff_sats:
paulson@13503
  1255
      "[| nth(i,env) = x; nth(j,env) = y;
paulson@13503
  1256
          i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@13807
  1257
       ==> is_list(##A, x, y) <-> sats(A, is_list_fm(i,j), env)"
paulson@13503
  1258
by simp
paulson@13503
  1259
paulson@13503
  1260
theorem is_list_reflection:
paulson@13503
  1261
     "REFLECTS[\<lambda>x. is_list(L,f(x),g(x)),
paulson@13807
  1262
               \<lambda>i x. is_list(##Lset(i),f(x),g(x))]"
paulson@13655
  1263
apply (simp only: is_list_def)
paulson@13503
  1264
apply (intro FOL_reflections mem_list_reflection)
paulson@13503
  1265
done
paulson@13503
  1266
paulson@13503
  1267
paulson@13503
  1268
subsubsection{*The Formula Functor, Internalized*}
paulson@13503
  1269
wenzelm@21404
  1270
definition formula_functor_fm :: "[i,i]=>i" where
paulson@13503
  1271
(*     "is_formula_functor(M,X,Z) ==
paulson@13503
  1272
        \<exists>nat'[M]. \<exists>natnat[M]. \<exists>natnatsum[M]. \<exists>XX[M]. \<exists>X3[M].
paulson@13503
  1273
           4           3               2       1       0
paulson@13503
  1274
          omega(M,nat') & cartprod(M,nat',nat',natnat) &
paulson@13503
  1275
          is_sum(M,natnat,natnat,natnatsum) &
paulson@13503
  1276
          cartprod(M,X,X,XX) & is_sum(M,XX,X,X3) &
paulson@13503
  1277
          is_sum(M,natnatsum,X3,Z)" *)
paulson@13503
  1278
    "formula_functor_fm(X,Z) ==
paulson@13503
  1279
       Exists(Exists(Exists(Exists(Exists(
paulson@13503
  1280
        And(omega_fm(4),
paulson@13503
  1281
         And(cartprod_fm(4,4,3),
paulson@13503
  1282
          And(sum_fm(3,3,2),
paulson@13503
  1283
           And(cartprod_fm(X#+5,X#+5,1),
paulson@13503
  1284
            And(sum_fm(1,X#+5,0), sum_fm(2,0,Z#+5)))))))))))"
paulson@13503
  1285
paulson@13503
  1286
lemma formula_functor_type [TC]:
paulson@13503
  1287
     "[| x \<in> nat; y \<in> nat |] ==> formula_functor_fm(x,y) \<in> formula"
paulson@13503
  1288
by (simp add: formula_functor_fm_def)
paulson@13503
  1289
paulson@13503
  1290
lemma sats_formula_functor_fm [simp]:
paulson@13503
  1291
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
paulson@13503
  1292
    ==> sats(A, formula_functor_fm(x,y), env) <->
paulson@13807
  1293
        is_formula_functor(##A, nth(x,env), nth(y,env))"
paulson@13503
  1294
by (simp add: formula_functor_fm_def is_formula_functor_def)
paulson@13503
  1295
paulson@13503
  1296
lemma formula_functor_iff_sats:
paulson@13503
  1297
  "[| nth(i,env) = x; nth(j,env) = y;
paulson@13503
  1298
      i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@13807
  1299
   ==> is_formula_functor(##A, x, y) <-> sats(A, formula_functor_fm(i,j), env)"
paulson@13503
  1300
by simp
paulson@13503
  1301
paulson@13503
  1302
theorem formula_functor_reflection:
paulson@13503
  1303
     "REFLECTS[\<lambda>x. is_formula_functor(L,f(x),g(x)),
paulson@13807
  1304
               \<lambda>i x. is_formula_functor(##Lset(i),f(x),g(x))]"
paulson@13655
  1305
apply (simp only: is_formula_functor_def)
paulson@13503
  1306
apply (intro FOL_reflections omega_reflection
paulson@13503
  1307
             cartprod_reflection sum_reflection)
paulson@13503
  1308
done
paulson@13503
  1309
paulson@13503
  1310
paulson@13503
  1311
subsubsection{*The Formula @{term is_formula_N}, Internalized*}
paulson@13503
  1312
paulson@13655
  1313
(*  "is_formula_N(M,n,Z) == 
paulson@13655
  1314
      \<exists>zero[M]. empty(M,zero) & 
paulson@13655
  1315
                is_iterates(M, is_formula_functor(M), zero, n, Z)" *) 
wenzelm@21404
  1316
definition
wenzelm@21404
  1317
  formula_N_fm :: "[i,i]=>i" where
paulson@13503
  1318
  "formula_N_fm(n,Z) == 
paulson@13655
  1319
     Exists(
paulson@13655
  1320
       And(empty_fm(0),
paulson@13655
  1321
           is_iterates_fm(formula_functor_fm(1,0), 0, n#+1, Z#+1)))"
paulson@13503
  1322
paulson@13503
  1323
lemma formula_N_fm_type [TC]:
paulson@13503
  1324
 "[| x \<in> nat; y \<in> nat |] ==> formula_N_fm(x,y) \<in> formula"
paulson@13503
  1325
by (simp add: formula_N_fm_def)
paulson@13503
  1326
paulson@13503
  1327
lemma sats_formula_N_fm [simp]:
paulson@13503
  1328
   "[| x < length(env); y < length(env); env \<in> list(A)|]
paulson@13503
  1329
    ==> sats(A, formula_N_fm(x,y), env) <->
paulson@13807
  1330
        is_formula_N(##A, nth(x,env), nth(y,env))"
paulson@13503
  1331
apply (frule_tac x=y in lt_length_in_nat, assumption)  
paulson@13503
  1332
apply (frule lt_length_in_nat, assumption)  
paulson@13655
  1333
apply (simp add: formula_N_fm_def is_formula_N_def sats_is_iterates_fm) 
paulson@13503
  1334
done
paulson@13503
  1335
paulson@13503
  1336
lemma formula_N_iff_sats:
paulson@13503
  1337
      "[| nth(i,env) = x; nth(j,env) = y; 
paulson@13503
  1338
          i < length(env); j < length(env); env \<in> list(A)|]
paulson@13807
  1339
       ==> is_formula_N(##A, x, y) <-> sats(A, formula_N_fm(i,j), env)"
paulson@13503
  1340
by (simp add: sats_formula_N_fm)
paulson@13503
  1341
paulson@13503
  1342
theorem formula_N_reflection:
paulson@13503
  1343
     "REFLECTS[\<lambda>x. is_formula_N(L, f(x), g(x)),  
paulson@13807
  1344
               \<lambda>i x. is_formula_N(##Lset(i), f(x), g(x))]"
paulson@13655
  1345
apply (simp only: is_formula_N_def)
paulson@13655
  1346
apply (intro FOL_reflections function_reflections 
paulson@13655
  1347
             is_iterates_reflection formula_functor_reflection) 
paulson@13503
  1348
done
paulson@13503
  1349
paulson@13503
  1350
paulson@13503
  1351
paulson@13503
  1352
subsubsection{*The Predicate ``Is A Formula''*}
paulson@13503
  1353
paulson@13503
  1354
(*  mem_formula(M,p) == 
paulson@13503
  1355
      \<exists>n[M]. \<exists>formn[M]. 
paulson@13503
  1356
       finite_ordinal(M,n) & is_formula_N(M,n,formn) & p \<in> formn *)
wenzelm@21404
  1357
definition
wenzelm@21404
  1358
  mem_formula_fm :: "i=>i" where
paulson@13503
  1359
    "mem_formula_fm(x) ==
paulson@13503
  1360
       Exists(Exists(
paulson@13503
  1361
         And(finite_ordinal_fm(1),
paulson@13503
  1362
           And(formula_N_fm(1,0), Member(x#+2,0)))))"
paulson@13503
  1363
paulson@13503
  1364
lemma mem_formula_type [TC]:
paulson@13503
  1365
     "x \<in> nat ==> mem_formula_fm(x) \<in> formula"
paulson@13503
  1366
by (simp add: mem_formula_fm_def)
paulson@13503
  1367
paulson@13503
  1368
lemma sats_mem_formula_fm [simp]:
paulson@13503
  1369
   "[| x \<in> nat; env \<in> list(A)|]
paulson@13807
  1370
    ==> sats(A, mem_formula_fm(x), env) <-> mem_formula(##A, nth(x,env))"
paulson@13503
  1371
by (simp add: mem_formula_fm_def mem_formula_def)
paulson@13503
  1372
paulson@13503
  1373
lemma mem_formula_iff_sats:
paulson@13503
  1374
      "[| nth(i,env) = x; i \<in> nat; env \<in> list(A)|]
paulson@13807
  1375
       ==> mem_formula(##A, x) <-> sats(A, mem_formula_fm(i), env)"
paulson@13503
  1376
by simp
paulson@13503
  1377
paulson@13503
  1378
theorem mem_formula_reflection:
paulson@13503
  1379
     "REFLECTS[\<lambda>x. mem_formula(L,f(x)),
paulson@13807
  1380
               \<lambda>i x. mem_formula(##Lset(i),f(x))]"
paulson@13655
  1381
apply (simp only: mem_formula_def)
paulson@13503
  1382
apply (intro FOL_reflections finite_ordinal_reflection formula_N_reflection)
paulson@13503
  1383
done
paulson@13503
  1384
paulson@13503
  1385
paulson@13503
  1386
paulson@13503
  1387
subsubsection{*The Predicate ``Is @{term "formula"}''*}
paulson@13503
  1388
paulson@13503
  1389
(* is_formula(M,Z) == \<forall>p[M]. p \<in> Z <-> mem_formula(M,p) *)
wenzelm@21404
  1390
definition
wenzelm@21404
  1391
  is_formula_fm :: "i=>i" where
paulson@13503
  1392
    "is_formula_fm(Z) == Forall(Iff(Member(0,succ(Z)), mem_formula_fm(0)))"
paulson@13503
  1393
paulson@13503
  1394
lemma is_formula_type [TC]:
paulson@13503
  1395
     "x \<in> nat ==> is_formula_fm(x) \<in> formula"
paulson@13503
  1396
by (simp add: is_formula_fm_def)
paulson@13503
  1397
paulson@13503
  1398
lemma sats_is_formula_fm [simp]:
paulson@13503
  1399
   "[| x \<in> nat; env \<in> list(A)|]
paulson@13807
  1400
    ==> sats(A, is_formula_fm(x), env) <-> is_formula(##A, nth(x,env))"
paulson@13503
  1401
by (simp add: is_formula_fm_def is_formula_def)
paulson@13503
  1402
paulson@13503
  1403
lemma is_formula_iff_sats:
paulson@13503
  1404
      "[| nth(i,env) = x; i \<in> nat; env \<in> list(A)|]
paulson@13807
  1405
       ==> is_formula(##A, x) <-> sats(A, is_formula_fm(i), env)"
paulson@13503
  1406
by simp
paulson@13503
  1407
paulson@13503
  1408
theorem is_formula_reflection:
paulson@13503
  1409
     "REFLECTS[\<lambda>x. is_formula(L,f(x)),
paulson@13807
  1410
               \<lambda>i x. is_formula(##Lset(i),f(x))]"
paulson@13655
  1411
apply (simp only: is_formula_def)
paulson@13503
  1412
apply (intro FOL_reflections mem_formula_reflection)
paulson@13503
  1413
done
paulson@13503
  1414
paulson@13503
  1415
paulson@13503
  1416
subsubsection{*The Operator @{term is_transrec}*}
paulson@13503
  1417
paulson@13503
  1418
text{*The three arguments of @{term p} are always 2, 1, 0.  It is buried
paulson@13503
  1419
   within eight quantifiers!
paulson@13503
  1420
   We call @{term p} with arguments a, f, z by equating them with 
paulson@13503
  1421
  the corresponding quantified variables with de Bruijn indices 2, 1, 0.*}
paulson@13503
  1422
paulson@13503
  1423
(* is_transrec :: "[i=>o, [i,i,i]=>o, i, i] => o"
paulson@13503
  1424
   "is_transrec(M,MH,a,z) == 
paulson@13503
  1425
      \<exists>sa[M]. \<exists>esa[M]. \<exists>mesa[M]. 
paulson@13503
  1426
       2       1         0
paulson@13503
  1427
       upair(M,a,a,sa) & is_eclose(M,sa,esa) & membership(M,esa,mesa) &
paulson@13503
  1428
       is_wfrec(M,MH,mesa,a,z)" *)
wenzelm@21404
  1429
definition
wenzelm@21404
  1430
  is_transrec_fm :: "[i, i, i]=>i" where
paulson@13503
  1431
 "is_transrec_fm(p,a,z) == 
paulson@13503
  1432
    Exists(Exists(Exists(
paulson@13503
  1433
      And(upair_fm(a#+3,a#+3,2),
paulson@13503
  1434
       And(is_eclose_fm(2,1),
paulson@13503
  1435
        And(Memrel_fm(1,0), is_wfrec_fm(p,0,a#+3,z#+3)))))))"
paulson@13503
  1436
paulson@13503
  1437
paulson@13503
  1438
lemma is_transrec_type [TC]:
paulson@13503
  1439
     "[| p \<in> formula; x \<in> nat; z \<in> nat |] 
paulson@13503
  1440
      ==> is_transrec_fm(p,x,z) \<in> formula"
paulson@13503
  1441
by (simp add: is_transrec_fm_def) 
paulson@13503
  1442
paulson@13503
  1443
lemma sats_is_transrec_fm:
paulson@13503
  1444
  assumes MH_iff_sats: 
paulson@13503
  1445
      "!!a0 a1 a2 a3 a4 a5 a6 a7. 
paulson@13503
  1446
        [|a0\<in>A; a1\<in>A; a2\<in>A; a3\<in>A; a4\<in>A; a5\<in>A; a6\<in>A; a7\<in>A|] 
paulson@13503
  1447
        ==> MH(a2, a1, a0) <-> 
paulson@13503
  1448
            sats(A, p, Cons(a0,Cons(a1,Cons(a2,Cons(a3,
paulson@13503
  1449
                          Cons(a4,Cons(a5,Cons(a6,Cons(a7,env)))))))))"
paulson@13503
  1450
  shows 
paulson@13503
  1451
      "[|x < length(env); z < length(env); env \<in> list(A)|]
paulson@13503
  1452
       ==> sats(A, is_transrec_fm(p,x,z), env) <-> 
paulson@13807
  1453
           is_transrec(##A, MH, nth(x,env), nth(z,env))"
paulson@13503
  1454
apply (frule_tac x=z in lt_length_in_nat, assumption)  
paulson@13503
  1455
apply (frule_tac x=x in lt_length_in_nat, assumption)  
paulson@13503
  1456
apply (simp add: is_transrec_fm_def sats_is_wfrec_fm is_transrec_def MH_iff_sats [THEN iff_sym]) 
paulson@13503
  1457
done
paulson@13503
  1458
paulson@13503
  1459
paulson@13503
  1460
lemma is_transrec_iff_sats:
paulson@13503
  1461
  assumes MH_iff_sats: 
paulson@13503
  1462
      "!!a0 a1 a2 a3 a4 a5 a6 a7. 
paulson@13503
  1463
        [|a0\<in>A; a1\<in>A; a2\<in>A; a3\<in>A; a4\<in>A; a5\<in>A; a6\<in>A; a7\<in>A|] 
paulson@13503
  1464
        ==> MH(a2, a1, a0) <-> 
paulson@13503
  1465
            sats(A, p, Cons(a0,Cons(a1,Cons(a2,Cons(a3,
paulson@13503
  1466
                          Cons(a4,Cons(a5,Cons(a6,Cons(a7,env)))))))))"
paulson@13503
  1467
  shows
paulson@13503
  1468
  "[|nth(i,env) = x; nth(k,env) = z; 
paulson@13503
  1469
      i < length(env); k < length(env); env \<in> list(A)|]
paulson@13807
  1470
   ==> is_transrec(##A, MH, x, z) <-> sats(A, is_transrec_fm(p,i,k), env)" 
paulson@13503
  1471
by (simp add: sats_is_transrec_fm [OF MH_iff_sats])
paulson@13503
  1472
paulson@13503
  1473
theorem is_transrec_reflection:
paulson@13503
  1474
  assumes MH_reflection:
paulson@13503
  1475
    "!!f' f g h. REFLECTS[\<lambda>x. MH(L, f'(x), f(x), g(x), h(x)), 
paulson@13807
  1476
                     \<lambda>i x. MH(##Lset(i), f'(x), f(x), g(x), h(x))]"
paulson@13503
  1477
  shows "REFLECTS[\<lambda>x. is_transrec(L, MH(L,x), f(x), h(x)), 
paulson@13807
  1478
               \<lambda>i x. is_transrec(##Lset(i), MH(##Lset(i),x), f(x), h(x))]"
paulson@13655
  1479
apply (simp (no_asm_use) only: is_transrec_def)
paulson@13503
  1480
apply (intro FOL_reflections function_reflections MH_reflection 
paulson@13503
  1481
             is_wfrec_reflection is_eclose_reflection)
paulson@13503
  1482
done
paulson@13503
  1483
paulson@13496
  1484
end