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