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