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