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