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