src/ZF/Constructible/Datatype_absolute.thy
author paulson
Tue Oct 01 13:26:10 2002 +0200 (2002-10-01)
changeset 13615 449a70d88b38
parent 13564 1500a2e48d44
child 13634 99a593b49b04
permissions -rw-r--r--
Numerous cosmetic changes, prompted by the new simplifier
paulson@13505
     1
(*  Title:      ZF/Constructible/Datatype_absolute.thy
paulson@13505
     2
    ID: $Id$
paulson@13505
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@13505
     4
    Copyright   2002  University of Cambridge
paulson@13505
     5
*)
paulson@13505
     6
paulson@13306
     7
header {*Absoluteness Properties for Recursive Datatypes*}
paulson@13306
     8
paulson@13269
     9
theory Datatype_absolute = Formula + WF_absolute:
paulson@13268
    10
paulson@13268
    11
paulson@13268
    12
subsection{*The lfp of a continuous function can be expressed as a union*}
paulson@13268
    13
paulson@13268
    14
constdefs
paulson@13385
    15
  directed :: "i=>o"
paulson@13385
    16
   "directed(A) == A\<noteq>0 & (\<forall>x\<in>A. \<forall>y\<in>A. x \<union> y \<in> A)"
paulson@13385
    17
paulson@13385
    18
  contin :: "(i=>i) => o"
paulson@13385
    19
   "contin(h) == (\<forall>A. directed(A) --> h(\<Union>A) = (\<Union>X\<in>A. h(X)))"
paulson@13268
    20
paulson@13268
    21
lemma bnd_mono_iterates_subset: "[|bnd_mono(D, h); n \<in> nat|] ==> h^n (0) <= D"
paulson@13268
    22
apply (induct_tac n) 
paulson@13268
    23
 apply (simp_all add: bnd_mono_def, blast) 
paulson@13268
    24
done
paulson@13268
    25
paulson@13385
    26
lemma bnd_mono_increasing [rule_format]:
paulson@13385
    27
     "[|i \<in> nat; j \<in> nat; bnd_mono(D,h)|] ==> i \<le> j --> h^i(0) \<subseteq> h^j(0)"
paulson@13385
    28
apply (rule_tac m=i and n=j in diff_induct, simp_all)
paulson@13385
    29
apply (blast del: subsetI
paulson@13398
    30
	     intro: bnd_mono_iterates_subset bnd_monoD2 [of concl: h]) 
paulson@13385
    31
done
paulson@13385
    32
paulson@13385
    33
lemma directed_iterates: "bnd_mono(D,h) ==> directed({h^n (0). n\<in>nat})"
paulson@13385
    34
apply (simp add: directed_def, clarify) 
paulson@13385
    35
apply (rename_tac i j)
paulson@13385
    36
apply (rule_tac x="i \<union> j" in bexI) 
paulson@13385
    37
apply (rule_tac i = i and j = j in Ord_linear_le)
paulson@13385
    38
apply (simp_all add: subset_Un_iff [THEN iffD1] le_imp_subset
paulson@13385
    39
                     subset_Un_iff2 [THEN iffD1])
paulson@13385
    40
apply (simp_all add: subset_Un_iff [THEN iff_sym] bnd_mono_increasing
paulson@13385
    41
                     subset_Un_iff2 [THEN iff_sym])
paulson@13385
    42
done
paulson@13385
    43
paulson@13268
    44
paulson@13268
    45
lemma contin_iterates_eq: 
paulson@13385
    46
    "[|bnd_mono(D, h); contin(h)|] 
paulson@13385
    47
     ==> h(\<Union>n\<in>nat. h^n (0)) = (\<Union>n\<in>nat. h^n (0))"
paulson@13385
    48
apply (simp add: contin_def directed_iterates) 
paulson@13268
    49
apply (rule trans) 
paulson@13268
    50
apply (rule equalityI) 
paulson@13385
    51
 apply (simp_all add: UN_subset_iff)
paulson@13268
    52
 apply safe
paulson@13268
    53
 apply (erule_tac [2] natE) 
paulson@13268
    54
  apply (rule_tac a="succ(x)" in UN_I) 
paulson@13268
    55
   apply simp_all 
paulson@13268
    56
apply blast 
paulson@13268
    57
done
paulson@13268
    58
paulson@13268
    59
lemma lfp_subset_Union:
paulson@13268
    60
     "[|bnd_mono(D, h); contin(h)|] ==> lfp(D,h) <= (\<Union>n\<in>nat. h^n(0))"
paulson@13268
    61
apply (rule lfp_lowerbound) 
paulson@13268
    62
 apply (simp add: contin_iterates_eq) 
paulson@13268
    63
apply (simp add: contin_def bnd_mono_iterates_subset UN_subset_iff) 
paulson@13268
    64
done
paulson@13268
    65
paulson@13268
    66
lemma Union_subset_lfp:
paulson@13268
    67
     "bnd_mono(D,h) ==> (\<Union>n\<in>nat. h^n(0)) <= lfp(D,h)"
paulson@13268
    68
apply (simp add: UN_subset_iff)
paulson@13268
    69
apply (rule ballI)  
paulson@13339
    70
apply (induct_tac n, simp_all) 
paulson@13268
    71
apply (rule subset_trans [of _ "h(lfp(D,h))"])
paulson@13398
    72
 apply (blast dest: bnd_monoD2 [OF _ _ lfp_subset])  
paulson@13268
    73
apply (erule lfp_lemma2) 
paulson@13268
    74
done
paulson@13268
    75
paulson@13268
    76
lemma lfp_eq_Union:
paulson@13268
    77
     "[|bnd_mono(D, h); contin(h)|] ==> lfp(D,h) = (\<Union>n\<in>nat. h^n(0))"
paulson@13268
    78
by (blast del: subsetI 
paulson@13268
    79
          intro: lfp_subset_Union Union_subset_lfp)
paulson@13268
    80
paulson@13268
    81
paulson@13385
    82
subsubsection{*Some Standard Datatype Constructions Preserve Continuity*}
paulson@13385
    83
paulson@13385
    84
lemma contin_imp_mono: "[|X\<subseteq>Y; contin(F)|] ==> F(X) \<subseteq> F(Y)"
paulson@13385
    85
apply (simp add: contin_def) 
paulson@13385
    86
apply (drule_tac x="{X,Y}" in spec) 
paulson@13385
    87
apply (simp add: directed_def subset_Un_iff2 Un_commute) 
paulson@13385
    88
done
paulson@13385
    89
paulson@13385
    90
lemma sum_contin: "[|contin(F); contin(G)|] ==> contin(\<lambda>X. F(X) + G(X))"
paulson@13385
    91
by (simp add: contin_def, blast)
paulson@13385
    92
paulson@13385
    93
lemma prod_contin: "[|contin(F); contin(G)|] ==> contin(\<lambda>X. F(X) * G(X))" 
paulson@13385
    94
apply (subgoal_tac "\<forall>B C. F(B) \<subseteq> F(B \<union> C)")
paulson@13385
    95
 prefer 2 apply (simp add: Un_upper1 contin_imp_mono) 
paulson@13385
    96
apply (subgoal_tac "\<forall>B C. G(C) \<subseteq> G(B \<union> C)")
paulson@13385
    97
 prefer 2 apply (simp add: Un_upper2 contin_imp_mono) 
paulson@13385
    98
apply (simp add: contin_def, clarify) 
paulson@13385
    99
apply (rule equalityI) 
paulson@13385
   100
 prefer 2 apply blast 
paulson@13385
   101
apply clarify 
paulson@13385
   102
apply (rename_tac B C) 
paulson@13385
   103
apply (rule_tac a="B \<union> C" in UN_I) 
paulson@13385
   104
 apply (simp add: directed_def, blast)  
paulson@13385
   105
done
paulson@13385
   106
paulson@13385
   107
lemma const_contin: "contin(\<lambda>X. A)"
paulson@13385
   108
by (simp add: contin_def directed_def)
paulson@13385
   109
paulson@13385
   110
lemma id_contin: "contin(\<lambda>X. X)"
paulson@13385
   111
by (simp add: contin_def)
paulson@13385
   112
paulson@13385
   113
paulson@13385
   114
paulson@13268
   115
subsection {*Absoluteness for "Iterates"*}
paulson@13268
   116
paulson@13353
   117
constdefs
paulson@13353
   118
paulson@13353
   119
  iterates_MH :: "[i=>o, [i,i]=>o, i, i, i, i] => o"
paulson@13353
   120
   "iterates_MH(M,isF,v,n,g,z) ==
paulson@13353
   121
        is_nat_case(M, v, \<lambda>m u. \<exists>gm[M]. fun_apply(M,g,m,gm) & isF(gm,u),
paulson@13353
   122
                    n, z)"
paulson@13353
   123
paulson@13353
   124
  iterates_replacement :: "[i=>o, [i,i]=>o, i] => o"
paulson@13353
   125
   "iterates_replacement(M,isF,v) ==
paulson@13363
   126
      \<forall>n[M]. n\<in>nat --> 
paulson@13353
   127
         wfrec_replacement(M, iterates_MH(M,isF,v), Memrel(succ(n)))"
paulson@13353
   128
paulson@13564
   129
lemma (in M_basic) iterates_MH_abs:
paulson@13353
   130
  "[| relativize1(M,isF,F); M(n); M(g); M(z) |] 
paulson@13353
   131
   ==> iterates_MH(M,isF,v,n,g,z) <-> z = nat_case(v, \<lambda>m. F(g`m), n)"
paulson@13363
   132
by (simp add: nat_case_abs [of _ "\<lambda>m. F(g ` m)"]
paulson@13363
   133
              relativize1_def iterates_MH_def)  
paulson@13353
   134
paulson@13564
   135
lemma (in M_basic) iterates_imp_wfrec_replacement:
paulson@13353
   136
  "[|relativize1(M,isF,F); n \<in> nat; iterates_replacement(M,isF,v)|] 
paulson@13353
   137
   ==> wfrec_replacement(M, \<lambda>n f z. z = nat_case(v, \<lambda>m. F(f`m), n), 
paulson@13353
   138
                       Memrel(succ(n)))" 
paulson@13353
   139
by (simp add: iterates_replacement_def iterates_MH_abs)
paulson@13353
   140
paulson@13353
   141
theorem (in M_trancl) iterates_abs:
paulson@13353
   142
  "[| iterates_replacement(M,isF,v); relativize1(M,isF,F);
paulson@13353
   143
      n \<in> nat; M(v); M(z); \<forall>x[M]. M(F(x)) |] 
paulson@13353
   144
   ==> is_wfrec(M, iterates_MH(M,isF,v), Memrel(succ(n)), n, z) <->
paulson@13353
   145
       z = iterates(F,n,v)" 
paulson@13353
   146
apply (frule iterates_imp_wfrec_replacement, assumption+)
paulson@13353
   147
apply (simp add: wf_Memrel trans_Memrel relation_Memrel nat_into_M
paulson@13353
   148
                 relativize2_def iterates_MH_abs 
paulson@13353
   149
                 iterates_nat_def recursor_def transrec_def 
paulson@13353
   150
                 eclose_sing_Ord_eq nat_into_M
paulson@13353
   151
         trans_wfrec_abs [of _ _ _ _ "\<lambda>n g. nat_case(v, \<lambda>m. F(g`m), n)"])
paulson@13353
   152
done
paulson@13353
   153
paulson@13268
   154
paulson@13268
   155
lemma (in M_wfrank) iterates_closed [intro,simp]:
paulson@13353
   156
  "[| iterates_replacement(M,isF,v); relativize1(M,isF,F);
paulson@13353
   157
      n \<in> nat; M(v); \<forall>x[M]. M(F(x)) |] 
paulson@13268
   158
   ==> M(iterates(F,n,v))"
paulson@13353
   159
apply (frule iterates_imp_wfrec_replacement, assumption+)
paulson@13353
   160
apply (simp add: wf_Memrel trans_Memrel relation_Memrel nat_into_M
paulson@13353
   161
                 relativize2_def iterates_MH_abs 
paulson@13353
   162
                 iterates_nat_def recursor_def transrec_def 
paulson@13353
   163
                 eclose_sing_Ord_eq nat_into_M
paulson@13353
   164
         trans_wfrec_closed [of _ _ _ "\<lambda>n g. nat_case(v, \<lambda>m. F(g`m), n)"])
paulson@13353
   165
done
paulson@13268
   166
paulson@13268
   167
paulson@13386
   168
subsection {*lists without univ*}
paulson@13386
   169
paulson@13386
   170
lemmas datatype_univs = Inl_in_univ Inr_in_univ 
paulson@13386
   171
                        Pair_in_univ nat_into_univ A_into_univ 
paulson@13386
   172
paulson@13386
   173
lemma list_fun_bnd_mono: "bnd_mono(univ(A), \<lambda>X. {0} + A*X)"
paulson@13386
   174
apply (rule bnd_monoI)
paulson@13386
   175
 apply (intro subset_refl zero_subset_univ A_subset_univ 
paulson@13386
   176
	      sum_subset_univ Sigma_subset_univ) 
paulson@13386
   177
apply (rule subset_refl sum_mono Sigma_mono | assumption)+
paulson@13386
   178
done
paulson@13386
   179
paulson@13386
   180
lemma list_fun_contin: "contin(\<lambda>X. {0} + A*X)"
paulson@13386
   181
by (intro sum_contin prod_contin id_contin const_contin) 
paulson@13386
   182
paulson@13386
   183
text{*Re-expresses lists using sum and product*}
paulson@13386
   184
lemma list_eq_lfp2: "list(A) = lfp(univ(A), \<lambda>X. {0} + A*X)"
paulson@13386
   185
apply (simp add: list_def) 
paulson@13386
   186
apply (rule equalityI) 
paulson@13386
   187
 apply (rule lfp_lowerbound) 
paulson@13386
   188
  prefer 2 apply (rule lfp_subset)
paulson@13386
   189
 apply (clarify, subst lfp_unfold [OF list_fun_bnd_mono])
paulson@13386
   190
 apply (simp add: Nil_def Cons_def)
paulson@13386
   191
 apply blast 
paulson@13386
   192
txt{*Opposite inclusion*}
paulson@13386
   193
apply (rule lfp_lowerbound) 
paulson@13386
   194
 prefer 2 apply (rule lfp_subset) 
paulson@13386
   195
apply (clarify, subst lfp_unfold [OF list.bnd_mono]) 
paulson@13386
   196
apply (simp add: Nil_def Cons_def)
paulson@13386
   197
apply (blast intro: datatype_univs
paulson@13386
   198
             dest: lfp_subset [THEN subsetD])
paulson@13386
   199
done
paulson@13386
   200
paulson@13386
   201
text{*Re-expresses lists using "iterates", no univ.*}
paulson@13386
   202
lemma list_eq_Union:
paulson@13386
   203
     "list(A) = (\<Union>n\<in>nat. (\<lambda>X. {0} + A*X) ^ n (0))"
paulson@13386
   204
by (simp add: list_eq_lfp2 lfp_eq_Union list_fun_bnd_mono list_fun_contin)
paulson@13386
   205
paulson@13386
   206
paulson@13350
   207
constdefs
paulson@13350
   208
  is_list_functor :: "[i=>o,i,i,i] => o"
paulson@13350
   209
    "is_list_functor(M,A,X,Z) == 
paulson@13350
   210
        \<exists>n1[M]. \<exists>AX[M]. 
paulson@13350
   211
         number1(M,n1) & cartprod(M,A,X,AX) & is_sum(M,n1,AX,Z)"
paulson@13350
   212
paulson@13564
   213
lemma (in M_basic) list_functor_abs [simp]: 
paulson@13350
   214
     "[| M(A); M(X); M(Z) |] ==> is_list_functor(M,A,X,Z) <-> (Z = {0} + A*X)"
paulson@13350
   215
by (simp add: is_list_functor_def singleton_0 nat_into_M)
paulson@13350
   216
paulson@13350
   217
paulson@13386
   218
subsection {*formulas without univ*}
paulson@13386
   219
paulson@13386
   220
lemma formula_fun_bnd_mono:
paulson@13398
   221
     "bnd_mono(univ(0), \<lambda>X. ((nat*nat) + (nat*nat)) + (X*X + X))"
paulson@13386
   222
apply (rule bnd_monoI)
paulson@13386
   223
 apply (intro subset_refl zero_subset_univ A_subset_univ 
paulson@13386
   224
	      sum_subset_univ Sigma_subset_univ nat_subset_univ) 
paulson@13386
   225
apply (rule subset_refl sum_mono Sigma_mono | assumption)+
paulson@13386
   226
done
paulson@13386
   227
paulson@13386
   228
lemma formula_fun_contin:
paulson@13398
   229
     "contin(\<lambda>X. ((nat*nat) + (nat*nat)) + (X*X + X))"
paulson@13386
   230
by (intro sum_contin prod_contin id_contin const_contin) 
paulson@13386
   231
paulson@13386
   232
paulson@13386
   233
text{*Re-expresses formulas using sum and product*}
paulson@13386
   234
lemma formula_eq_lfp2:
paulson@13398
   235
    "formula = lfp(univ(0), \<lambda>X. ((nat*nat) + (nat*nat)) + (X*X + X))"
paulson@13386
   236
apply (simp add: formula_def) 
paulson@13386
   237
apply (rule equalityI) 
paulson@13386
   238
 apply (rule lfp_lowerbound) 
paulson@13386
   239
  prefer 2 apply (rule lfp_subset)
paulson@13386
   240
 apply (clarify, subst lfp_unfold [OF formula_fun_bnd_mono])
paulson@13398
   241
 apply (simp add: Member_def Equal_def Nand_def Forall_def)
paulson@13386
   242
 apply blast 
paulson@13386
   243
txt{*Opposite inclusion*}
paulson@13386
   244
apply (rule lfp_lowerbound) 
paulson@13386
   245
 prefer 2 apply (rule lfp_subset, clarify) 
paulson@13386
   246
apply (subst lfp_unfold [OF formula.bnd_mono, simplified]) 
paulson@13398
   247
apply (simp add: Member_def Equal_def Nand_def Forall_def)  
paulson@13386
   248
apply (elim sumE SigmaE, simp_all) 
paulson@13386
   249
apply (blast intro: datatype_univs dest: lfp_subset [THEN subsetD])+  
paulson@13386
   250
done
paulson@13386
   251
paulson@13386
   252
text{*Re-expresses formulas using "iterates", no univ.*}
paulson@13386
   253
lemma formula_eq_Union:
paulson@13386
   254
     "formula = 
paulson@13398
   255
      (\<Union>n\<in>nat. (\<lambda>X. ((nat*nat) + (nat*nat)) + (X*X + X)) ^ n (0))"
paulson@13386
   256
by (simp add: formula_eq_lfp2 lfp_eq_Union formula_fun_bnd_mono 
paulson@13386
   257
              formula_fun_contin)
paulson@13386
   258
paulson@13386
   259
paulson@13386
   260
constdefs
paulson@13386
   261
  is_formula_functor :: "[i=>o,i,i] => o"
paulson@13386
   262
    "is_formula_functor(M,X,Z) == 
paulson@13398
   263
        \<exists>nat'[M]. \<exists>natnat[M]. \<exists>natnatsum[M]. \<exists>XX[M]. \<exists>X3[M]. 
paulson@13386
   264
          omega(M,nat') & cartprod(M,nat',nat',natnat) & 
paulson@13386
   265
          is_sum(M,natnat,natnat,natnatsum) &
paulson@13398
   266
          cartprod(M,X,X,XX) & is_sum(M,XX,X,X3) & 
paulson@13398
   267
          is_sum(M,natnatsum,X3,Z)"
paulson@13386
   268
paulson@13564
   269
lemma (in M_basic) formula_functor_abs [simp]: 
paulson@13386
   270
     "[| M(X); M(Z) |] 
paulson@13386
   271
      ==> is_formula_functor(M,X,Z) <-> 
paulson@13398
   272
          Z = ((nat*nat) + (nat*nat)) + (X*X + X)"
paulson@13386
   273
by (simp add: is_formula_functor_def) 
paulson@13386
   274
paulson@13386
   275
paulson@13386
   276
subsection{*@{term M} Contains the List and Formula Datatypes*}
paulson@13395
   277
paulson@13395
   278
constdefs
paulson@13397
   279
  list_N :: "[i,i] => i"
paulson@13397
   280
    "list_N(A,n) == (\<lambda>X. {0} + A * X)^n (0)"
paulson@13397
   281
paulson@13397
   282
lemma Nil_in_list_N [simp]: "[] \<in> list_N(A,succ(n))"
paulson@13397
   283
by (simp add: list_N_def Nil_def)
paulson@13397
   284
paulson@13397
   285
lemma Cons_in_list_N [simp]:
paulson@13397
   286
     "Cons(a,l) \<in> list_N(A,succ(n)) <-> a\<in>A & l \<in> list_N(A,n)"
paulson@13397
   287
by (simp add: list_N_def Cons_def) 
paulson@13397
   288
paulson@13397
   289
text{*These two aren't simprules because they reveal the underlying
paulson@13397
   290
list representation.*}
paulson@13397
   291
lemma list_N_0: "list_N(A,0) = 0"
paulson@13397
   292
by (simp add: list_N_def)
paulson@13397
   293
paulson@13397
   294
lemma list_N_succ: "list_N(A,succ(n)) = {0} + A * (list_N(A,n))"
paulson@13397
   295
by (simp add: list_N_def)
paulson@13397
   296
paulson@13397
   297
lemma list_N_imp_list:
paulson@13397
   298
  "[| l \<in> list_N(A,n); n \<in> nat |] ==> l \<in> list(A)"
paulson@13397
   299
by (force simp add: list_eq_Union list_N_def)
paulson@13397
   300
paulson@13397
   301
lemma list_N_imp_length_lt [rule_format]:
paulson@13397
   302
     "n \<in> nat ==> \<forall>l \<in> list_N(A,n). length(l) < n"
paulson@13397
   303
apply (induct_tac n)  
paulson@13397
   304
apply (auto simp add: list_N_0 list_N_succ 
paulson@13397
   305
                      Nil_def [symmetric] Cons_def [symmetric]) 
paulson@13397
   306
done
paulson@13397
   307
paulson@13397
   308
lemma list_imp_list_N [rule_format]:
paulson@13397
   309
     "l \<in> list(A) ==> \<forall>n\<in>nat. length(l) < n --> l \<in> list_N(A, n)"
paulson@13397
   310
apply (induct_tac l)
paulson@13397
   311
apply (force elim: natE)+
paulson@13397
   312
done
paulson@13397
   313
paulson@13397
   314
lemma list_N_imp_eq_length:
paulson@13397
   315
      "[|n \<in> nat; l \<notin> list_N(A, n); l \<in> list_N(A, succ(n))|] 
paulson@13397
   316
       ==> n = length(l)"
paulson@13397
   317
apply (rule le_anti_sym) 
paulson@13397
   318
 prefer 2 apply (simp add: list_N_imp_length_lt) 
paulson@13397
   319
apply (frule list_N_imp_list, simp)
paulson@13397
   320
apply (simp add: not_lt_iff_le [symmetric]) 
paulson@13397
   321
apply (blast intro: list_imp_list_N) 
paulson@13397
   322
done
paulson@13397
   323
  
paulson@13397
   324
text{*Express @{term list_rec} without using @{term rank} or @{term Vset},
paulson@13397
   325
neither of which is absolute.*}
paulson@13564
   326
lemma (in M_trivial) list_rec_eq:
paulson@13397
   327
  "l \<in> list(A) ==>
paulson@13397
   328
   list_rec(a,g,l) = 
paulson@13397
   329
   transrec (succ(length(l)),
paulson@13409
   330
      \<lambda>x h. Lambda (list(A),
paulson@13409
   331
                    list_case' (a, 
paulson@13409
   332
                           \<lambda>a l. g(a, l, h ` succ(length(l)) ` l)))) ` l"
paulson@13397
   333
apply (induct_tac l) 
paulson@13397
   334
apply (subst transrec, simp) 
paulson@13397
   335
apply (subst transrec) 
paulson@13397
   336
apply (simp add: list_imp_list_N) 
paulson@13397
   337
done
paulson@13397
   338
paulson@13397
   339
constdefs
paulson@13397
   340
  is_list_N :: "[i=>o,i,i,i] => o"
paulson@13397
   341
    "is_list_N(M,A,n,Z) == 
paulson@13395
   342
      \<exists>zero[M]. \<exists>sn[M]. \<exists>msn[M]. 
paulson@13395
   343
       empty(M,zero) & 
paulson@13395
   344
       successor(M,n,sn) & membership(M,sn,msn) &
paulson@13395
   345
       is_wfrec(M, iterates_MH(M, is_list_functor(M,A),zero), msn, n, Z)"
paulson@13395
   346
  
paulson@13395
   347
  mem_list :: "[i=>o,i,i] => o"
paulson@13395
   348
    "mem_list(M,A,l) == 
paulson@13395
   349
      \<exists>n[M]. \<exists>listn[M]. 
paulson@13397
   350
       finite_ordinal(M,n) & is_list_N(M,A,n,listn) & l \<in> listn"
paulson@13395
   351
paulson@13395
   352
  is_list :: "[i=>o,i,i] => o"
paulson@13395
   353
    "is_list(M,A,Z) == \<forall>l[M]. l \<in> Z <-> mem_list(M,A,l)"
paulson@13395
   354
paulson@13493
   355
subsubsection{*Towards Absoluteness of @{term formula_rec}*}
paulson@13493
   356
paulson@13493
   357
consts   depth :: "i=>i"
paulson@13493
   358
primrec
paulson@13493
   359
  "depth(Member(x,y)) = 0"
paulson@13493
   360
  "depth(Equal(x,y))  = 0"
paulson@13493
   361
  "depth(Nand(p,q)) = succ(depth(p) \<union> depth(q))"
paulson@13493
   362
  "depth(Forall(p)) = succ(depth(p))"
paulson@13493
   363
paulson@13493
   364
lemma depth_type [TC]: "p \<in> formula ==> depth(p) \<in> nat"
paulson@13493
   365
by (induct_tac p, simp_all) 
paulson@13493
   366
paulson@13493
   367
paulson@13395
   368
constdefs
paulson@13493
   369
  formula_N :: "i => i"
paulson@13493
   370
    "formula_N(n) == (\<lambda>X. ((nat*nat) + (nat*nat)) + (X*X + X)) ^ n (0)"
paulson@13493
   371
paulson@13493
   372
lemma Member_in_formula_N [simp]:
paulson@13493
   373
     "Member(x,y) \<in> formula_N(succ(n)) <-> x \<in> nat & y \<in> nat"
paulson@13493
   374
by (simp add: formula_N_def Member_def) 
paulson@13493
   375
paulson@13493
   376
lemma Equal_in_formula_N [simp]:
paulson@13493
   377
     "Equal(x,y) \<in> formula_N(succ(n)) <-> x \<in> nat & y \<in> nat"
paulson@13493
   378
by (simp add: formula_N_def Equal_def) 
paulson@13493
   379
paulson@13493
   380
lemma Nand_in_formula_N [simp]:
paulson@13493
   381
     "Nand(x,y) \<in> formula_N(succ(n)) <-> x \<in> formula_N(n) & y \<in> formula_N(n)"
paulson@13493
   382
by (simp add: formula_N_def Nand_def) 
paulson@13493
   383
paulson@13493
   384
lemma Forall_in_formula_N [simp]:
paulson@13493
   385
     "Forall(x) \<in> formula_N(succ(n)) <-> x \<in> formula_N(n)"
paulson@13493
   386
by (simp add: formula_N_def Forall_def) 
paulson@13493
   387
paulson@13493
   388
text{*These two aren't simprules because they reveal the underlying
paulson@13493
   389
formula representation.*}
paulson@13493
   390
lemma formula_N_0: "formula_N(0) = 0"
paulson@13493
   391
by (simp add: formula_N_def)
paulson@13493
   392
paulson@13493
   393
lemma formula_N_succ:
paulson@13493
   394
     "formula_N(succ(n)) = 
paulson@13493
   395
      ((nat*nat) + (nat*nat)) + (formula_N(n) * formula_N(n) + formula_N(n))"
paulson@13493
   396
by (simp add: formula_N_def)
paulson@13493
   397
paulson@13493
   398
lemma formula_N_imp_formula:
paulson@13493
   399
  "[| p \<in> formula_N(n); n \<in> nat |] ==> p \<in> formula"
paulson@13493
   400
by (force simp add: formula_eq_Union formula_N_def)
paulson@13493
   401
paulson@13493
   402
lemma formula_N_imp_depth_lt [rule_format]:
paulson@13493
   403
     "n \<in> nat ==> \<forall>p \<in> formula_N(n). depth(p) < n"
paulson@13493
   404
apply (induct_tac n)  
paulson@13493
   405
apply (auto simp add: formula_N_0 formula_N_succ 
paulson@13493
   406
                      depth_type formula_N_imp_formula Un_least_lt_iff
paulson@13493
   407
                      Member_def [symmetric] Equal_def [symmetric]
paulson@13493
   408
                      Nand_def [symmetric] Forall_def [symmetric]) 
paulson@13493
   409
done
paulson@13493
   410
paulson@13493
   411
lemma formula_imp_formula_N [rule_format]:
paulson@13493
   412
     "p \<in> formula ==> \<forall>n\<in>nat. depth(p) < n --> p \<in> formula_N(n)"
paulson@13493
   413
apply (induct_tac p)
paulson@13493
   414
apply (simp_all add: succ_Un_distrib Un_least_lt_iff) 
paulson@13493
   415
apply (force elim: natE)+
paulson@13493
   416
done
paulson@13493
   417
paulson@13493
   418
lemma formula_N_imp_eq_depth:
paulson@13493
   419
      "[|n \<in> nat; p \<notin> formula_N(n); p \<in> formula_N(succ(n))|] 
paulson@13493
   420
       ==> n = depth(p)"
paulson@13493
   421
apply (rule le_anti_sym) 
paulson@13493
   422
 prefer 2 apply (simp add: formula_N_imp_depth_lt) 
paulson@13493
   423
apply (frule formula_N_imp_formula, simp)
paulson@13493
   424
apply (simp add: not_lt_iff_le [symmetric]) 
paulson@13493
   425
apply (blast intro: formula_imp_formula_N) 
paulson@13493
   426
done
paulson@13493
   427
paulson@13493
   428
paulson@13493
   429
paulson@13493
   430
lemma formula_N_mono [rule_format]:
paulson@13493
   431
  "[| m \<in> nat; n \<in> nat |] ==> m\<le>n --> formula_N(m) \<subseteq> formula_N(n)"
paulson@13493
   432
apply (rule_tac m = m and n = n in diff_induct)
paulson@13493
   433
apply (simp_all add: formula_N_0 formula_N_succ, blast) 
paulson@13493
   434
done
paulson@13493
   435
paulson@13493
   436
lemma formula_N_distrib:
paulson@13493
   437
  "[| m \<in> nat; n \<in> nat |] ==> formula_N(m \<union> n) = formula_N(m) \<union> formula_N(n)"
paulson@13493
   438
apply (rule_tac i = m and j = n in Ord_linear_le, auto) 
paulson@13493
   439
apply (simp_all add: subset_Un_iff [THEN iffD1] subset_Un_iff2 [THEN iffD1] 
paulson@13493
   440
                     le_imp_subset formula_N_mono)
paulson@13493
   441
done
paulson@13493
   442
paulson@13493
   443
constdefs
paulson@13493
   444
  is_formula_N :: "[i=>o,i,i] => o"
paulson@13493
   445
    "is_formula_N(M,n,Z) == 
paulson@13395
   446
      \<exists>zero[M]. \<exists>sn[M]. \<exists>msn[M]. 
paulson@13395
   447
       empty(M,zero) & 
paulson@13395
   448
       successor(M,n,sn) & membership(M,sn,msn) &
paulson@13395
   449
       is_wfrec(M, iterates_MH(M, is_formula_functor(M),zero), msn, n, Z)"
paulson@13395
   450
  
paulson@13493
   451
paulson@13493
   452
constdefs
paulson@13493
   453
  
paulson@13395
   454
  mem_formula :: "[i=>o,i] => o"
paulson@13395
   455
    "mem_formula(M,p) == 
paulson@13395
   456
      \<exists>n[M]. \<exists>formn[M]. 
paulson@13493
   457
       finite_ordinal(M,n) & is_formula_N(M,n,formn) & p \<in> formn"
paulson@13395
   458
paulson@13395
   459
  is_formula :: "[i=>o,i] => o"
paulson@13395
   460
    "is_formula(M,Z) == \<forall>p[M]. p \<in> Z <-> mem_formula(M,p)"
paulson@13395
   461
wenzelm@13428
   462
locale M_datatypes = M_wfrank +
paulson@13353
   463
 assumes list_replacement1: 
paulson@13363
   464
   "M(A) ==> iterates_replacement(M, is_list_functor(M,A), 0)"
paulson@13353
   465
  and list_replacement2: 
paulson@13363
   466
   "M(A) ==> strong_replacement(M, 
paulson@13353
   467
         \<lambda>n y. n\<in>nat & 
paulson@13353
   468
               (\<exists>sn[M]. \<exists>msn[M]. successor(M,n,sn) & membership(M,sn,msn) &
paulson@13363
   469
               is_wfrec(M, iterates_MH(M,is_list_functor(M,A), 0), 
paulson@13353
   470
                        msn, n, y)))"
paulson@13386
   471
  and formula_replacement1: 
paulson@13386
   472
   "iterates_replacement(M, is_formula_functor(M), 0)"
paulson@13386
   473
  and formula_replacement2: 
paulson@13386
   474
   "strong_replacement(M, 
paulson@13386
   475
         \<lambda>n y. n\<in>nat & 
paulson@13386
   476
               (\<exists>sn[M]. \<exists>msn[M]. successor(M,n,sn) & membership(M,sn,msn) &
paulson@13386
   477
               is_wfrec(M, iterates_MH(M,is_formula_functor(M), 0), 
paulson@13386
   478
                        msn, n, y)))"
paulson@13422
   479
  and nth_replacement:
paulson@13422
   480
   "M(l) ==> iterates_replacement(M, %l t. is_tl(M,l,t), l)"
paulson@13422
   481
        
paulson@13395
   482
paulson@13395
   483
subsubsection{*Absoluteness of the List Construction*}
paulson@13395
   484
paulson@13348
   485
lemma (in M_datatypes) list_replacement2': 
paulson@13353
   486
  "M(A) ==> strong_replacement(M, \<lambda>n y. n\<in>nat & y = (\<lambda>X. {0} + A * X)^n (0))"
paulson@13353
   487
apply (insert list_replacement2 [of A]) 
paulson@13353
   488
apply (rule strong_replacement_cong [THEN iffD1])  
paulson@13353
   489
apply (rule conj_cong [OF iff_refl iterates_abs [of "is_list_functor(M,A)"]]) 
paulson@13363
   490
apply (simp_all add: list_replacement1 relativize1_def) 
paulson@13353
   491
done
paulson@13268
   492
paulson@13268
   493
lemma (in M_datatypes) list_closed [intro,simp]:
paulson@13268
   494
     "M(A) ==> M(list(A))"
paulson@13353
   495
apply (insert list_replacement1)
paulson@13353
   496
by  (simp add: RepFun_closed2 list_eq_Union 
paulson@13353
   497
               list_replacement2' relativize1_def
paulson@13353
   498
               iterates_closed [of "is_list_functor(M,A)"])
paulson@13397
   499
paulson@13423
   500
text{*WARNING: use only with @{text "dest:"} or with variables fixed!*}
paulson@13423
   501
lemmas (in M_datatypes) list_into_M = transM [OF _ list_closed]
paulson@13423
   502
paulson@13397
   503
lemma (in M_datatypes) list_N_abs [simp]:
paulson@13395
   504
     "[|M(A); n\<in>nat; M(Z)|] 
paulson@13397
   505
      ==> is_list_N(M,A,n,Z) <-> Z = list_N(A,n)"
paulson@13395
   506
apply (insert list_replacement1)
paulson@13397
   507
apply (simp add: is_list_N_def list_N_def relativize1_def nat_into_M
paulson@13395
   508
                 iterates_abs [of "is_list_functor(M,A)" _ "\<lambda>X. {0} + A*X"])
paulson@13395
   509
done
paulson@13268
   510
paulson@13397
   511
lemma (in M_datatypes) list_N_closed [intro,simp]:
paulson@13397
   512
     "[|M(A); n\<in>nat|] ==> M(list_N(A,n))"
paulson@13397
   513
apply (insert list_replacement1)
paulson@13397
   514
apply (simp add: is_list_N_def list_N_def relativize1_def nat_into_M
paulson@13397
   515
                 iterates_closed [of "is_list_functor(M,A)"])
paulson@13397
   516
done
paulson@13397
   517
paulson@13395
   518
lemma (in M_datatypes) mem_list_abs [simp]:
paulson@13395
   519
     "M(A) ==> mem_list(M,A,l) <-> l \<in> list(A)"
paulson@13395
   520
apply (insert list_replacement1)
paulson@13397
   521
apply (simp add: mem_list_def list_N_def relativize1_def list_eq_Union
paulson@13395
   522
                 iterates_closed [of "is_list_functor(M,A)"]) 
paulson@13395
   523
done
paulson@13395
   524
paulson@13395
   525
lemma (in M_datatypes) list_abs [simp]:
paulson@13395
   526
     "[|M(A); M(Z)|] ==> is_list(M,A,Z) <-> Z = list(A)"
paulson@13395
   527
apply (simp add: is_list_def, safe)
paulson@13395
   528
apply (rule M_equalityI, simp_all)
paulson@13395
   529
done
paulson@13395
   530
paulson@13395
   531
subsubsection{*Absoluteness of Formulas*}
paulson@13293
   532
paulson@13386
   533
lemma (in M_datatypes) formula_replacement2': 
paulson@13398
   534
  "strong_replacement(M, \<lambda>n y. n\<in>nat & y = (\<lambda>X. ((nat*nat) + (nat*nat)) + (X*X + X))^n (0))"
paulson@13386
   535
apply (insert formula_replacement2) 
paulson@13386
   536
apply (rule strong_replacement_cong [THEN iffD1])  
paulson@13386
   537
apply (rule conj_cong [OF iff_refl iterates_abs [of "is_formula_functor(M)"]]) 
paulson@13386
   538
apply (simp_all add: formula_replacement1 relativize1_def) 
paulson@13386
   539
done
paulson@13386
   540
paulson@13386
   541
lemma (in M_datatypes) formula_closed [intro,simp]:
paulson@13386
   542
     "M(formula)"
paulson@13386
   543
apply (insert formula_replacement1)
paulson@13386
   544
apply  (simp add: RepFun_closed2 formula_eq_Union 
paulson@13386
   545
                  formula_replacement2' relativize1_def
paulson@13386
   546
                  iterates_closed [of "is_formula_functor(M)"])
paulson@13386
   547
done
paulson@13386
   548
paulson@13423
   549
lemmas (in M_datatypes) formula_into_M = transM [OF _ formula_closed]
paulson@13423
   550
paulson@13493
   551
lemma (in M_datatypes) formula_N_abs [simp]:
paulson@13395
   552
     "[|n\<in>nat; M(Z)|] 
paulson@13493
   553
      ==> is_formula_N(M,n,Z) <-> Z = formula_N(n)"
paulson@13395
   554
apply (insert formula_replacement1)
paulson@13493
   555
apply (simp add: is_formula_N_def formula_N_def relativize1_def nat_into_M
paulson@13395
   556
                 iterates_abs [of "is_formula_functor(M)" _ 
paulson@13493
   557
                                  "\<lambda>X. ((nat*nat) + (nat*nat)) + (X*X + X)"])
paulson@13493
   558
done
paulson@13493
   559
paulson@13493
   560
lemma (in M_datatypes) formula_N_closed [intro,simp]:
paulson@13493
   561
     "n\<in>nat ==> M(formula_N(n))"
paulson@13493
   562
apply (insert formula_replacement1)
paulson@13493
   563
apply (simp add: is_formula_N_def formula_N_def relativize1_def nat_into_M
paulson@13493
   564
                 iterates_closed [of "is_formula_functor(M)"])
paulson@13395
   565
done
paulson@13395
   566
paulson@13395
   567
lemma (in M_datatypes) mem_formula_abs [simp]:
paulson@13395
   568
     "mem_formula(M,l) <-> l \<in> formula"
paulson@13395
   569
apply (insert formula_replacement1)
paulson@13493
   570
apply (simp add: mem_formula_def relativize1_def formula_eq_Union formula_N_def
paulson@13395
   571
                 iterates_closed [of "is_formula_functor(M)"]) 
paulson@13395
   572
done
paulson@13395
   573
paulson@13395
   574
lemma (in M_datatypes) formula_abs [simp]:
paulson@13395
   575
     "[|M(Z)|] ==> is_formula(M,Z) <-> Z = formula"
paulson@13395
   576
apply (simp add: is_formula_def, safe)
paulson@13395
   577
apply (rule M_equalityI, simp_all)
paulson@13395
   578
done
paulson@13395
   579
paulson@13395
   580
paulson@13397
   581
subsection{*Absoluteness for Some List Operators*}
paulson@13397
   582
paulson@13395
   583
subsection{*Absoluteness for @{text \<epsilon>}-Closure: the @{term eclose} Operator*}
paulson@13395
   584
paulson@13395
   585
text{*Re-expresses eclose using "iterates"*}
paulson@13395
   586
lemma eclose_eq_Union:
paulson@13395
   587
     "eclose(A) = (\<Union>n\<in>nat. Union^n (A))"
paulson@13395
   588
apply (simp add: eclose_def) 
paulson@13395
   589
apply (rule UN_cong) 
paulson@13395
   590
apply (rule refl)
paulson@13395
   591
apply (induct_tac n)
paulson@13395
   592
apply (simp add: nat_rec_0)  
paulson@13395
   593
apply (simp add: nat_rec_succ) 
paulson@13395
   594
done
paulson@13395
   595
paulson@13395
   596
constdefs
paulson@13395
   597
  is_eclose_n :: "[i=>o,i,i,i] => o"
paulson@13395
   598
    "is_eclose_n(M,A,n,Z) == 
paulson@13395
   599
      \<exists>sn[M]. \<exists>msn[M]. 
paulson@13395
   600
       successor(M,n,sn) & membership(M,sn,msn) &
paulson@13395
   601
       is_wfrec(M, iterates_MH(M, big_union(M), A), msn, n, Z)"
paulson@13395
   602
  
paulson@13395
   603
  mem_eclose :: "[i=>o,i,i] => o"
paulson@13395
   604
    "mem_eclose(M,A,l) == 
paulson@13395
   605
      \<exists>n[M]. \<exists>eclosen[M]. 
paulson@13395
   606
       finite_ordinal(M,n) & is_eclose_n(M,A,n,eclosen) & l \<in> eclosen"
paulson@13395
   607
paulson@13395
   608
  is_eclose :: "[i=>o,i,i] => o"
paulson@13395
   609
    "is_eclose(M,A,Z) == \<forall>u[M]. u \<in> Z <-> mem_eclose(M,A,u)"
paulson@13395
   610
paulson@13395
   611
wenzelm@13428
   612
locale M_eclose = M_datatypes +
paulson@13395
   613
 assumes eclose_replacement1: 
paulson@13395
   614
   "M(A) ==> iterates_replacement(M, big_union(M), A)"
paulson@13395
   615
  and eclose_replacement2: 
paulson@13395
   616
   "M(A) ==> strong_replacement(M, 
paulson@13395
   617
         \<lambda>n y. n\<in>nat & 
paulson@13395
   618
               (\<exists>sn[M]. \<exists>msn[M]. successor(M,n,sn) & membership(M,sn,msn) &
paulson@13395
   619
               is_wfrec(M, iterates_MH(M,big_union(M), A), 
paulson@13395
   620
                        msn, n, y)))"
paulson@13395
   621
paulson@13395
   622
lemma (in M_eclose) eclose_replacement2': 
paulson@13395
   623
  "M(A) ==> strong_replacement(M, \<lambda>n y. n\<in>nat & y = Union^n (A))"
paulson@13395
   624
apply (insert eclose_replacement2 [of A]) 
paulson@13395
   625
apply (rule strong_replacement_cong [THEN iffD1])  
paulson@13395
   626
apply (rule conj_cong [OF iff_refl iterates_abs [of "big_union(M)"]]) 
paulson@13395
   627
apply (simp_all add: eclose_replacement1 relativize1_def) 
paulson@13395
   628
done
paulson@13395
   629
paulson@13395
   630
lemma (in M_eclose) eclose_closed [intro,simp]:
paulson@13395
   631
     "M(A) ==> M(eclose(A))"
paulson@13395
   632
apply (insert eclose_replacement1)
paulson@13395
   633
by  (simp add: RepFun_closed2 eclose_eq_Union 
paulson@13395
   634
               eclose_replacement2' relativize1_def
paulson@13395
   635
               iterates_closed [of "big_union(M)"])
paulson@13395
   636
paulson@13395
   637
lemma (in M_eclose) is_eclose_n_abs [simp]:
paulson@13395
   638
     "[|M(A); n\<in>nat; M(Z)|] ==> is_eclose_n(M,A,n,Z) <-> Z = Union^n (A)"
paulson@13395
   639
apply (insert eclose_replacement1)
paulson@13395
   640
apply (simp add: is_eclose_n_def relativize1_def nat_into_M
paulson@13395
   641
                 iterates_abs [of "big_union(M)" _ "Union"])
paulson@13395
   642
done
paulson@13395
   643
paulson@13395
   644
lemma (in M_eclose) mem_eclose_abs [simp]:
paulson@13395
   645
     "M(A) ==> mem_eclose(M,A,l) <-> l \<in> eclose(A)"
paulson@13395
   646
apply (insert eclose_replacement1)
paulson@13395
   647
apply (simp add: mem_eclose_def relativize1_def eclose_eq_Union
paulson@13395
   648
                 iterates_closed [of "big_union(M)"]) 
paulson@13395
   649
done
paulson@13395
   650
paulson@13395
   651
lemma (in M_eclose) eclose_abs [simp]:
paulson@13395
   652
     "[|M(A); M(Z)|] ==> is_eclose(M,A,Z) <-> Z = eclose(A)"
paulson@13395
   653
apply (simp add: is_eclose_def, safe)
paulson@13395
   654
apply (rule M_equalityI, simp_all)
paulson@13395
   655
done
paulson@13395
   656
paulson@13395
   657
paulson@13395
   658
paulson@13395
   659
paulson@13395
   660
subsection {*Absoluteness for @{term transrec}*}
paulson@13395
   661
paulson@13395
   662
paulson@13395
   663
text{* @{term "transrec(a,H) \<equiv> wfrec(Memrel(eclose({a})), a, H)"} *}
paulson@13395
   664
constdefs
paulson@13395
   665
paulson@13395
   666
  is_transrec :: "[i=>o, [i,i,i]=>o, i, i] => o"
paulson@13395
   667
   "is_transrec(M,MH,a,z) == 
paulson@13395
   668
      \<exists>sa[M]. \<exists>esa[M]. \<exists>mesa[M]. 
paulson@13395
   669
       upair(M,a,a,sa) & is_eclose(M,sa,esa) & membership(M,esa,mesa) &
paulson@13395
   670
       is_wfrec(M,MH,mesa,a,z)"
paulson@13395
   671
paulson@13395
   672
  transrec_replacement :: "[i=>o, [i,i,i]=>o, i] => o"
paulson@13395
   673
   "transrec_replacement(M,MH,a) ==
paulson@13395
   674
      \<exists>sa[M]. \<exists>esa[M]. \<exists>mesa[M]. 
paulson@13395
   675
       upair(M,a,a,sa) & is_eclose(M,sa,esa) & membership(M,esa,mesa) &
paulson@13395
   676
       wfrec_replacement(M,MH,mesa)"
paulson@13395
   677
paulson@13395
   678
text{*The condition @{term "Ord(i)"} lets us use the simpler 
paulson@13395
   679
  @{text "trans_wfrec_abs"} rather than @{text "trans_wfrec_abs"},
paulson@13395
   680
  which I haven't even proved yet. *}
paulson@13395
   681
theorem (in M_eclose) transrec_abs:
paulson@13418
   682
  "[|transrec_replacement(M,MH,i);  relativize2(M,MH,H);
paulson@13418
   683
     Ord(i);  M(i);  M(z);
paulson@13395
   684
     \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
paulson@13395
   685
   ==> is_transrec(M,MH,i,z) <-> z = transrec(i,H)" 
paulson@13615
   686
by (simp add: trans_wfrec_abs transrec_replacement_def is_transrec_def
paulson@13395
   687
       transrec_def eclose_sing_Ord_eq wf_Memrel trans_Memrel relation_Memrel)
paulson@13395
   688
paulson@13395
   689
paulson@13395
   690
theorem (in M_eclose) transrec_closed:
paulson@13418
   691
     "[|transrec_replacement(M,MH,i);  relativize2(M,MH,H);
paulson@13418
   692
	Ord(i);  M(i);  
paulson@13395
   693
	\<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
paulson@13395
   694
      ==> M(transrec(i,H))"
paulson@13615
   695
by (simp add: trans_wfrec_closed transrec_replacement_def is_transrec_def
paulson@13615
   696
        transrec_def eclose_sing_Ord_eq wf_Memrel trans_Memrel relation_Memrel)
paulson@13615
   697
paulson@13395
   698
paulson@13440
   699
text{*Helps to prove instances of @{term transrec_replacement}*}
paulson@13440
   700
lemma (in M_eclose) transrec_replacementI: 
paulson@13440
   701
   "[|M(a);
paulson@13440
   702
    strong_replacement (M, 
paulson@13440
   703
                  \<lambda>x z. \<exists>y[M]. pair(M, x, y, z) \<and> is_wfrec(M,MH,Memrel(eclose({a})),x,y))|]
paulson@13440
   704
    ==> transrec_replacement(M,MH,a)"
paulson@13440
   705
by (simp add: transrec_replacement_def wfrec_replacement_def) 
paulson@13440
   706
paulson@13395
   707
paulson@13397
   708
subsection{*Absoluteness for the List Operator @{term length}*}
paulson@13397
   709
constdefs
paulson@13397
   710
paulson@13397
   711
  is_length :: "[i=>o,i,i,i] => o"
paulson@13397
   712
    "is_length(M,A,l,n) == 
paulson@13397
   713
       \<exists>sn[M]. \<exists>list_n[M]. \<exists>list_sn[M]. 
paulson@13397
   714
        is_list_N(M,A,n,list_n) & l \<notin> list_n &
paulson@13397
   715
        successor(M,n,sn) & is_list_N(M,A,sn,list_sn) & l \<in> list_sn"
paulson@13397
   716
paulson@13397
   717
paulson@13397
   718
lemma (in M_datatypes) length_abs [simp]:
paulson@13397
   719
     "[|M(A); l \<in> list(A); n \<in> nat|] ==> is_length(M,A,l,n) <-> n = length(l)"
paulson@13397
   720
apply (subgoal_tac "M(l) & M(n)")
paulson@13397
   721
 prefer 2 apply (blast dest: transM)  
paulson@13397
   722
apply (simp add: is_length_def)
paulson@13397
   723
apply (blast intro: list_imp_list_N nat_into_Ord list_N_imp_eq_length
paulson@13397
   724
             dest: list_N_imp_length_lt)
paulson@13397
   725
done
paulson@13397
   726
paulson@13397
   727
text{*Proof is trivial since @{term length} returns natural numbers.*}
paulson@13564
   728
lemma (in M_trivial) length_closed [intro,simp]:
paulson@13397
   729
     "l \<in> list(A) ==> M(length(l))"
paulson@13398
   730
by (simp add: nat_into_M) 
paulson@13397
   731
paulson@13397
   732
paulson@13397
   733
subsection {*Absoluteness for @{term nth}*}
paulson@13397
   734
paulson@13397
   735
lemma nth_eq_hd_iterates_tl [rule_format]:
paulson@13397
   736
     "xs \<in> list(A) ==> \<forall>n \<in> nat. nth(n,xs) = hd' (tl'^n (xs))"
paulson@13397
   737
apply (induct_tac xs) 
paulson@13397
   738
apply (simp add: iterates_tl_Nil hd'_Nil, clarify) 
paulson@13397
   739
apply (erule natE)
paulson@13397
   740
apply (simp add: hd'_Cons) 
paulson@13397
   741
apply (simp add: tl'_Cons iterates_commute) 
paulson@13397
   742
done
paulson@13397
   743
paulson@13564
   744
lemma (in M_basic) iterates_tl'_closed:
paulson@13397
   745
     "[|n \<in> nat; M(x)|] ==> M(tl'^n (x))"
paulson@13397
   746
apply (induct_tac n, simp) 
paulson@13397
   747
apply (simp add: tl'_Cons tl'_closed) 
paulson@13397
   748
done
paulson@13397
   749
paulson@13397
   750
text{*Immediate by type-checking*}
paulson@13397
   751
lemma (in M_datatypes) nth_closed [intro,simp]:
paulson@13397
   752
     "[|xs \<in> list(A); n \<in> nat; M(A)|] ==> M(nth(n,xs))" 
paulson@13397
   753
apply (case_tac "n < length(xs)")
paulson@13397
   754
 apply (blast intro: nth_type transM)
paulson@13397
   755
apply (simp add: not_lt_iff_le nth_eq_0)
paulson@13397
   756
done
paulson@13397
   757
paulson@13397
   758
constdefs
paulson@13397
   759
  is_nth :: "[i=>o,i,i,i] => o"
paulson@13397
   760
    "is_nth(M,n,l,Z) == 
paulson@13397
   761
      \<exists>X[M]. \<exists>sn[M]. \<exists>msn[M]. 
paulson@13397
   762
       successor(M,n,sn) & membership(M,sn,msn) &
paulson@13397
   763
       is_wfrec(M, iterates_MH(M, is_tl(M), l), msn, n, X) &
paulson@13397
   764
       is_hd(M,X,Z)"
paulson@13397
   765
 
paulson@13409
   766
lemma (in M_datatypes) nth_abs [simp]:
paulson@13422
   767
     "[|M(A); n \<in> nat; l \<in> list(A); M(Z)|] 
paulson@13397
   768
      ==> is_nth(M,n,l,Z) <-> Z = nth(n,l)"
paulson@13397
   769
apply (subgoal_tac "M(l)") 
paulson@13397
   770
 prefer 2 apply (blast intro: transM)
paulson@13397
   771
apply (simp add: is_nth_def nth_eq_hd_iterates_tl nat_into_M
paulson@13397
   772
                 tl'_closed iterates_tl'_closed 
paulson@13422
   773
                 iterates_abs [OF _ relativize1_tl] nth_replacement)
paulson@13397
   774
done
paulson@13397
   775
paulson@13395
   776
paulson@13398
   777
subsection{*Relativization and Absoluteness for the @{term formula} Constructors*}
paulson@13398
   778
paulson@13398
   779
constdefs
paulson@13398
   780
  is_Member :: "[i=>o,i,i,i] => o"
paulson@13398
   781
     --{* because @{term "Member(x,y) \<equiv> Inl(Inl(\<langle>x,y\<rangle>))"}*}
paulson@13398
   782
    "is_Member(M,x,y,Z) ==
paulson@13398
   783
	\<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inl(M,p,u) & is_Inl(M,u,Z)"
paulson@13398
   784
paulson@13564
   785
lemma (in M_trivial) Member_abs [simp]:
paulson@13398
   786
     "[|M(x); M(y); M(Z)|] ==> is_Member(M,x,y,Z) <-> (Z = Member(x,y))"
paulson@13398
   787
by (simp add: is_Member_def Member_def)
paulson@13398
   788
paulson@13564
   789
lemma (in M_trivial) Member_in_M_iff [iff]:
paulson@13398
   790
     "M(Member(x,y)) <-> M(x) & M(y)"
paulson@13398
   791
by (simp add: Member_def) 
paulson@13398
   792
paulson@13398
   793
constdefs
paulson@13398
   794
  is_Equal :: "[i=>o,i,i,i] => o"
paulson@13398
   795
     --{* because @{term "Equal(x,y) \<equiv> Inl(Inr(\<langle>x,y\<rangle>))"}*}
paulson@13398
   796
    "is_Equal(M,x,y,Z) ==
paulson@13398
   797
	\<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inr(M,p,u) & is_Inl(M,u,Z)"
paulson@13398
   798
paulson@13564
   799
lemma (in M_trivial) Equal_abs [simp]:
paulson@13398
   800
     "[|M(x); M(y); M(Z)|] ==> is_Equal(M,x,y,Z) <-> (Z = Equal(x,y))"
paulson@13398
   801
by (simp add: is_Equal_def Equal_def)
paulson@13398
   802
paulson@13564
   803
lemma (in M_trivial) Equal_in_M_iff [iff]: "M(Equal(x,y)) <-> M(x) & M(y)"
paulson@13398
   804
by (simp add: Equal_def) 
paulson@13398
   805
paulson@13398
   806
constdefs
paulson@13398
   807
  is_Nand :: "[i=>o,i,i,i] => o"
paulson@13398
   808
     --{* because @{term "Nand(x,y) \<equiv> Inr(Inl(\<langle>x,y\<rangle>))"}*}
paulson@13398
   809
    "is_Nand(M,x,y,Z) ==
paulson@13398
   810
	\<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inl(M,p,u) & is_Inr(M,u,Z)"
paulson@13398
   811
paulson@13564
   812
lemma (in M_trivial) Nand_abs [simp]:
paulson@13398
   813
     "[|M(x); M(y); M(Z)|] ==> is_Nand(M,x,y,Z) <-> (Z = Nand(x,y))"
paulson@13398
   814
by (simp add: is_Nand_def Nand_def)
paulson@13398
   815
paulson@13564
   816
lemma (in M_trivial) Nand_in_M_iff [iff]: "M(Nand(x,y)) <-> M(x) & M(y)"
paulson@13398
   817
by (simp add: Nand_def) 
paulson@13398
   818
paulson@13398
   819
constdefs
paulson@13398
   820
  is_Forall :: "[i=>o,i,i] => o"
paulson@13398
   821
     --{* because @{term "Forall(x) \<equiv> Inr(Inr(p))"}*}
paulson@13398
   822
    "is_Forall(M,p,Z) == \<exists>u[M]. is_Inr(M,p,u) & is_Inr(M,u,Z)"
paulson@13398
   823
paulson@13564
   824
lemma (in M_trivial) Forall_abs [simp]:
paulson@13398
   825
     "[|M(x); M(Z)|] ==> is_Forall(M,x,Z) <-> (Z = Forall(x))"
paulson@13398
   826
by (simp add: is_Forall_def Forall_def)
paulson@13398
   827
paulson@13564
   828
lemma (in M_trivial) Forall_in_M_iff [iff]: "M(Forall(x)) <-> M(x)"
paulson@13398
   829
by (simp add: Forall_def)
paulson@13398
   830
paulson@13398
   831
paulson@13398
   832
subsection {*Absoluteness for @{term formula_rec}*}
paulson@13398
   833
paulson@13423
   834
subsubsection{*@{term is_formula_case}: relativization of @{term formula_case}*}
paulson@13423
   835
paulson@13423
   836
constdefs
paulson@13423
   837
paulson@13423
   838
 is_formula_case :: 
paulson@13423
   839
    "[i=>o, [i,i,i]=>o, [i,i,i]=>o, [i,i,i]=>o, [i,i]=>o, i, i] => o"
paulson@13423
   840
  --{*no constraint on non-formulas*}
paulson@13423
   841
  "is_formula_case(M, is_a, is_b, is_c, is_d, p, z) == 
paulson@13493
   842
      (\<forall>x[M]. \<forall>y[M]. finite_ordinal(M,x) --> finite_ordinal(M,y) --> 
paulson@13493
   843
                      is_Member(M,x,y,p) --> is_a(x,y,z)) &
paulson@13493
   844
      (\<forall>x[M]. \<forall>y[M]. finite_ordinal(M,x) --> finite_ordinal(M,y) --> 
paulson@13493
   845
                      is_Equal(M,x,y,p) --> is_b(x,y,z)) &
paulson@13493
   846
      (\<forall>x[M]. \<forall>y[M]. mem_formula(M,x) --> mem_formula(M,y) --> 
paulson@13423
   847
                     is_Nand(M,x,y,p) --> is_c(x,y,z)) &
paulson@13493
   848
      (\<forall>x[M]. mem_formula(M,x) --> is_Forall(M,x,p) --> is_d(x,z))"
paulson@13423
   849
paulson@13423
   850
lemma (in M_datatypes) formula_case_abs [simp]: 
paulson@13423
   851
     "[| Relativize2(M,nat,nat,is_a,a); Relativize2(M,nat,nat,is_b,b); 
paulson@13423
   852
         Relativize2(M,formula,formula,is_c,c); Relativize1(M,formula,is_d,d); 
paulson@13423
   853
         p \<in> formula; M(z) |] 
paulson@13423
   854
      ==> is_formula_case(M,is_a,is_b,is_c,is_d,p,z) <-> 
paulson@13423
   855
          z = formula_case(a,b,c,d,p)"
paulson@13423
   856
apply (simp add: formula_into_M is_formula_case_def)
paulson@13423
   857
apply (erule formula.cases) 
paulson@13423
   858
   apply (simp_all add: Relativize1_def Relativize2_def) 
paulson@13423
   859
done
paulson@13423
   860
paulson@13418
   861
lemma (in M_datatypes) formula_case_closed [intro,simp]:
paulson@13418
   862
  "[|p \<in> formula; 
paulson@13418
   863
     \<forall>x[M]. \<forall>y[M]. x\<in>nat --> y\<in>nat --> M(a(x,y)); 
paulson@13418
   864
     \<forall>x[M]. \<forall>y[M]. x\<in>nat --> y\<in>nat --> M(b(x,y)); 
paulson@13418
   865
     \<forall>x[M]. \<forall>y[M]. x\<in>formula --> y\<in>formula --> M(c(x,y)); 
paulson@13418
   866
     \<forall>x[M]. x\<in>formula --> M(d(x))|] ==> M(formula_case(a,b,c,d,p))"
paulson@13418
   867
by (erule formula.cases, simp_all) 
paulson@13418
   868
paulson@13398
   869
paulson@13398
   870
subsection{*Absoluteness for the Formula Operator @{term depth}*}
paulson@13398
   871
constdefs
paulson@13398
   872
paulson@13398
   873
  is_depth :: "[i=>o,i,i] => o"
paulson@13398
   874
    "is_depth(M,p,n) == 
paulson@13398
   875
       \<exists>sn[M]. \<exists>formula_n[M]. \<exists>formula_sn[M]. 
paulson@13398
   876
        is_formula_N(M,n,formula_n) & p \<notin> formula_n &
paulson@13398
   877
        successor(M,n,sn) & is_formula_N(M,sn,formula_sn) & p \<in> formula_sn"
paulson@13398
   878
paulson@13398
   879
paulson@13398
   880
lemma (in M_datatypes) depth_abs [simp]:
paulson@13398
   881
     "[|p \<in> formula; n \<in> nat|] ==> is_depth(M,p,n) <-> n = depth(p)"
paulson@13398
   882
apply (subgoal_tac "M(p) & M(n)")
paulson@13398
   883
 prefer 2 apply (blast dest: transM)  
paulson@13398
   884
apply (simp add: is_depth_def)
paulson@13398
   885
apply (blast intro: formula_imp_formula_N nat_into_Ord formula_N_imp_eq_depth
paulson@13398
   886
             dest: formula_N_imp_depth_lt)
paulson@13398
   887
done
paulson@13398
   888
paulson@13398
   889
text{*Proof is trivial since @{term depth} returns natural numbers.*}
paulson@13564
   890
lemma (in M_trivial) depth_closed [intro,simp]:
paulson@13398
   891
     "p \<in> formula ==> M(depth(p))"
paulson@13398
   892
by (simp add: nat_into_M) 
paulson@13398
   893
paulson@13493
   894
paulson@13557
   895
subsection {*Absoluteness for @{term formula_rec}*}
paulson@13557
   896
paulson@13557
   897
constdefs
paulson@13557
   898
paulson@13557
   899
  formula_rec_case :: "[[i,i]=>i, [i,i]=>i, [i,i,i,i]=>i, [i,i]=>i, i, i] => i"
paulson@13557
   900
    --{* the instance of @{term formula_case} in @{term formula_rec}*}
paulson@13557
   901
   "formula_rec_case(a,b,c,d,h) ==
paulson@13557
   902
        formula_case (a, b,
paulson@13557
   903
                \<lambda>u v. c(u, v, h ` succ(depth(u)) ` u, 
paulson@13557
   904
                              h ` succ(depth(v)) ` v),
paulson@13557
   905
                \<lambda>u. d(u, h ` succ(depth(u)) ` u))"
paulson@13557
   906
paulson@13557
   907
  is_formula_rec :: "[i=>o, [i,i,i]=>o, i, i] => o"
paulson@13557
   908
    --{* predicate to relativize the functional @{term formula_rec}*}
paulson@13557
   909
   "is_formula_rec(M,MH,p,z)  ==
paulson@13557
   910
      \<exists>dp[M]. \<exists>i[M]. \<exists>f[M]. finite_ordinal(M,dp) & is_depth(M,p,dp) & 
paulson@13557
   911
             successor(M,dp,i) & fun_apply(M,f,p,z) & is_transrec(M,MH,i,f)"
paulson@13557
   912
paulson@13557
   913
text{*Unfold @{term formula_rec} to @{term formula_rec_case}.
paulson@13557
   914
     Express @{term formula_rec} without using @{term rank} or @{term Vset},
paulson@13557
   915
neither of which is absolute.*}
paulson@13564
   916
lemma (in M_trivial) formula_rec_eq:
paulson@13557
   917
  "p \<in> formula ==>
paulson@13557
   918
   formula_rec(a,b,c,d,p) = 
paulson@13557
   919
   transrec (succ(depth(p)),
paulson@13557
   920
             \<lambda>x h. Lambda (formula, formula_rec_case(a,b,c,d,h))) ` p"
paulson@13557
   921
apply (simp add: formula_rec_case_def)
paulson@13557
   922
apply (induct_tac p)
paulson@13557
   923
   txt{*Base case for @{term Member}*}
paulson@13557
   924
   apply (subst transrec, simp add: formula.intros) 
paulson@13557
   925
  txt{*Base case for @{term Equal}*}
paulson@13557
   926
  apply (subst transrec, simp add: formula.intros)
paulson@13557
   927
 txt{*Inductive step for @{term Nand}*}
paulson@13557
   928
 apply (subst transrec) 
paulson@13557
   929
 apply (simp add: succ_Un_distrib formula.intros)
paulson@13557
   930
txt{*Inductive step for @{term Forall}*}
paulson@13557
   931
apply (subst transrec) 
paulson@13557
   932
apply (simp add: formula_imp_formula_N formula.intros) 
paulson@13557
   933
done
paulson@13557
   934
paulson@13557
   935
paulson@13557
   936
text{*Sufficient conditions to relative the instance of @{term formula_case}
paulson@13557
   937
      in @{term formula_rec}*}
paulson@13557
   938
lemma (in M_datatypes) Relativize1_formula_rec_case:
paulson@13557
   939
     "[|Relativize2(M, nat, nat, is_a, a);
paulson@13557
   940
        Relativize2(M, nat, nat, is_b, b);
paulson@13557
   941
        Relativize2 (M, formula, formula, 
paulson@13557
   942
           is_c, \<lambda>u v. c(u, v, h`succ(depth(u))`u, h`succ(depth(v))`v));
paulson@13557
   943
        Relativize1(M, formula, 
paulson@13557
   944
           is_d, \<lambda>u. d(u, h ` succ(depth(u)) ` u));
paulson@13557
   945
 	M(h) |] 
paulson@13557
   946
      ==> Relativize1(M, formula,
paulson@13557
   947
                         is_formula_case (M, is_a, is_b, is_c, is_d),
paulson@13557
   948
                         formula_rec_case(a, b, c, d, h))"
paulson@13557
   949
apply (simp (no_asm) add: formula_rec_case_def Relativize1_def) 
paulson@13557
   950
apply (simp add: formula_case_abs) 
paulson@13557
   951
done
paulson@13557
   952
paulson@13557
   953
paulson@13557
   954
text{*This locale packages the premises of the following theorems,
paulson@13557
   955
      which is the normal purpose of locales.  It doesn't accumulate
paulson@13557
   956
      constraints on the class @{term M}, as in most of this deveopment.*}
paulson@13557
   957
locale Formula_Rec = M_eclose +
paulson@13557
   958
  fixes a and is_a and b and is_b and c and is_c and d and is_d and MH
paulson@13557
   959
  defines
paulson@13557
   960
      "MH(u::i,f,z) ==
paulson@13557
   961
	\<forall>fml[M]. is_formula(M,fml) -->
paulson@13557
   962
             is_lambda
paulson@13557
   963
	 (M, fml, is_formula_case (M, is_a, is_b, is_c(f), is_d(f)), z)"
paulson@13557
   964
paulson@13557
   965
  assumes a_closed: "[|x\<in>nat; y\<in>nat|] ==> M(a(x,y))"
paulson@13557
   966
      and a_rel:    "Relativize2(M, nat, nat, is_a, a)"
paulson@13557
   967
      and b_closed: "[|x\<in>nat; y\<in>nat|] ==> M(b(x,y))"
paulson@13557
   968
      and b_rel:    "Relativize2(M, nat, nat, is_b, b)"
paulson@13557
   969
      and c_closed: "[|x \<in> formula; y \<in> formula; M(gx); M(gy)|]
paulson@13557
   970
                     ==> M(c(x, y, gx, gy))"
paulson@13557
   971
      and c_rel:
paulson@13557
   972
         "M(f) ==> 
paulson@13557
   973
          Relativize2 (M, formula, formula, is_c(f),
paulson@13557
   974
             \<lambda>u v. c(u, v, f ` succ(depth(u)) ` u, f ` succ(depth(v)) ` v))"
paulson@13557
   975
      and d_closed: "[|x \<in> formula; M(gx)|] ==> M(d(x, gx))"
paulson@13557
   976
      and d_rel:
paulson@13557
   977
         "M(f) ==> 
paulson@13557
   978
          Relativize1(M, formula, is_d(f), \<lambda>u. d(u, f ` succ(depth(u)) ` u))"
paulson@13557
   979
      and fr_replace: "n \<in> nat ==> transrec_replacement(M,MH,n)"
paulson@13557
   980
      and fr_lam_replace:
paulson@13557
   981
           "M(g) ==>
paulson@13557
   982
            strong_replacement
paulson@13557
   983
	      (M, \<lambda>x y. x \<in> formula &
paulson@13557
   984
		  y = \<langle>x, formula_rec_case(a,b,c,d,g,x)\<rangle>)";
paulson@13557
   985
paulson@13557
   986
lemma (in Formula_Rec) formula_rec_case_closed:
paulson@13557
   987
    "[|M(g); p \<in> formula|] ==> M(formula_rec_case(a, b, c, d, g, p))"
paulson@13557
   988
by (simp add: formula_rec_case_def a_closed b_closed c_closed d_closed) 
paulson@13557
   989
paulson@13557
   990
lemma (in Formula_Rec) formula_rec_lam_closed:
paulson@13557
   991
    "M(g) ==> M(Lambda (formula, formula_rec_case(a,b,c,d,g)))"
paulson@13557
   992
by (simp add: lam_closed2 fr_lam_replace formula_rec_case_closed)
paulson@13557
   993
paulson@13557
   994
lemma (in Formula_Rec) MH_rel2:
paulson@13557
   995
     "relativize2 (M, MH,
paulson@13557
   996
             \<lambda>x h. Lambda (formula, formula_rec_case(a,b,c,d,h)))"
paulson@13557
   997
apply (simp add: relativize2_def MH_def, clarify) 
paulson@13557
   998
apply (rule lambda_abs2) 
paulson@13557
   999
apply (rule fr_lam_replace, assumption)
paulson@13557
  1000
apply (rule Relativize1_formula_rec_case)  
paulson@13557
  1001
apply (simp_all add: a_rel b_rel c_rel d_rel formula_rec_case_closed) 
paulson@13557
  1002
done
paulson@13557
  1003
paulson@13557
  1004
lemma (in Formula_Rec) fr_transrec_closed:
paulson@13557
  1005
    "n \<in> nat
paulson@13557
  1006
     ==> M(transrec
paulson@13557
  1007
          (n, \<lambda>x h. Lambda(formula, formula_rec_case(a, b, c, d, h))))"
paulson@13557
  1008
by (simp add: transrec_closed [OF fr_replace MH_rel2]  
paulson@13557
  1009
              nat_into_M formula_rec_lam_closed) 
paulson@13557
  1010
paulson@13557
  1011
text{*The main two results: @{term formula_rec} is absolute for @{term M}.*}
paulson@13557
  1012
theorem (in Formula_Rec) formula_rec_closed:
paulson@13557
  1013
    "p \<in> formula ==> M(formula_rec(a,b,c,d,p))"
paulson@13557
  1014
by (simp add: formula_rec_eq fr_transrec_closed 
paulson@13557
  1015
              transM [OF _ formula_closed])
paulson@13557
  1016
paulson@13557
  1017
theorem (in Formula_Rec) formula_rec_abs:
paulson@13557
  1018
  "[| p \<in> formula; M(z)|] 
paulson@13557
  1019
   ==> is_formula_rec(M,MH,p,z) <-> z = formula_rec(a,b,c,d,p)" 
paulson@13557
  1020
by (simp add: is_formula_rec_def formula_rec_eq transM [OF _ formula_closed]
paulson@13557
  1021
              transrec_abs [OF fr_replace MH_rel2] depth_type
paulson@13557
  1022
              fr_transrec_closed formula_rec_lam_closed eq_commute)
paulson@13557
  1023
paulson@13557
  1024
paulson@13268
  1025
end