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