src/ZF/Constructible/Datatype_absolute.thy
author paulson
Fri Jul 12 11:24:40 2002 +0200 (2002-07-12)
changeset 13352 3cd767f8d78b
parent 13350 626b79677dfa
child 13353 1800e7134d2e
permissions -rw-r--r--
new definitions of fun_apply and M_is_recfun
paulson@13306
     1
header {*Absoluteness Properties for Recursive Datatypes*}
paulson@13306
     2
paulson@13269
     3
theory Datatype_absolute = Formula + WF_absolute:
paulson@13268
     4
paulson@13268
     5
paulson@13268
     6
subsection{*The lfp of a continuous function can be expressed as a union*}
paulson@13268
     7
paulson@13268
     8
constdefs
paulson@13268
     9
  contin :: "[i=>i]=>o"
paulson@13268
    10
   "contin(h) == (\<forall>A. A\<noteq>0 --> h(\<Union>A) = (\<Union>X\<in>A. h(X)))"
paulson@13268
    11
paulson@13268
    12
lemma bnd_mono_iterates_subset: "[|bnd_mono(D, h); n \<in> nat|] ==> h^n (0) <= D"
paulson@13268
    13
apply (induct_tac n) 
paulson@13268
    14
 apply (simp_all add: bnd_mono_def, blast) 
paulson@13268
    15
done
paulson@13268
    16
paulson@13268
    17
paulson@13268
    18
lemma contin_iterates_eq: 
paulson@13268
    19
    "contin(h) \<Longrightarrow> h(\<Union>n\<in>nat. h^n (0)) = (\<Union>n\<in>nat. h^n (0))"
paulson@13268
    20
apply (simp add: contin_def) 
paulson@13268
    21
apply (rule trans) 
paulson@13268
    22
apply (rule equalityI) 
paulson@13268
    23
 apply (simp_all add: UN_subset_iff) 
paulson@13268
    24
 apply safe
paulson@13268
    25
 apply (erule_tac [2] natE) 
paulson@13268
    26
  apply (rule_tac a="succ(x)" in UN_I) 
paulson@13268
    27
   apply simp_all 
paulson@13268
    28
apply blast 
paulson@13268
    29
done
paulson@13268
    30
paulson@13268
    31
lemma lfp_subset_Union:
paulson@13268
    32
     "[|bnd_mono(D, h); contin(h)|] ==> lfp(D,h) <= (\<Union>n\<in>nat. h^n(0))"
paulson@13268
    33
apply (rule lfp_lowerbound) 
paulson@13268
    34
 apply (simp add: contin_iterates_eq) 
paulson@13268
    35
apply (simp add: contin_def bnd_mono_iterates_subset UN_subset_iff) 
paulson@13268
    36
done
paulson@13268
    37
paulson@13268
    38
lemma Union_subset_lfp:
paulson@13268
    39
     "bnd_mono(D,h) ==> (\<Union>n\<in>nat. h^n(0)) <= lfp(D,h)"
paulson@13268
    40
apply (simp add: UN_subset_iff)
paulson@13268
    41
apply (rule ballI)  
paulson@13339
    42
apply (induct_tac n, simp_all) 
paulson@13268
    43
apply (rule subset_trans [of _ "h(lfp(D,h))"])
paulson@13268
    44
 apply (blast dest: bnd_monoD2 [OF _ _ lfp_subset] )  
paulson@13268
    45
apply (erule lfp_lemma2) 
paulson@13268
    46
done
paulson@13268
    47
paulson@13268
    48
lemma lfp_eq_Union:
paulson@13268
    49
     "[|bnd_mono(D, h); contin(h)|] ==> lfp(D,h) = (\<Union>n\<in>nat. h^n(0))"
paulson@13268
    50
by (blast del: subsetI 
paulson@13268
    51
          intro: lfp_subset_Union Union_subset_lfp)
paulson@13268
    52
paulson@13268
    53
paulson@13268
    54
subsection {*lists without univ*}
paulson@13268
    55
paulson@13268
    56
lemmas datatype_univs = A_into_univ Inl_in_univ Inr_in_univ 
paulson@13268
    57
                        Pair_in_univ zero_in_univ
paulson@13268
    58
paulson@13268
    59
lemma list_fun_bnd_mono: "bnd_mono(univ(A), \<lambda>X. {0} + A*X)"
paulson@13268
    60
apply (rule bnd_monoI)
paulson@13268
    61
 apply (intro subset_refl zero_subset_univ A_subset_univ 
paulson@13268
    62
	      sum_subset_univ Sigma_subset_univ) 
paulson@13268
    63
 apply (blast intro!: subset_refl sum_mono Sigma_mono del: subsetI)
paulson@13268
    64
done
paulson@13268
    65
paulson@13268
    66
lemma list_fun_contin: "contin(\<lambda>X. {0} + A*X)"
paulson@13268
    67
by (simp add: contin_def, blast)
paulson@13268
    68
paulson@13268
    69
text{*Re-expresses lists using sum and product*}
paulson@13268
    70
lemma list_eq_lfp2: "list(A) = lfp(univ(A), \<lambda>X. {0} + A*X)"
paulson@13268
    71
apply (simp add: list_def) 
paulson@13268
    72
apply (rule equalityI) 
paulson@13268
    73
 apply (rule lfp_lowerbound) 
paulson@13268
    74
  prefer 2 apply (rule lfp_subset)
paulson@13268
    75
 apply (clarify, subst lfp_unfold [OF list_fun_bnd_mono])
paulson@13268
    76
 apply (simp add: Nil_def Cons_def)
paulson@13268
    77
 apply blast 
paulson@13268
    78
txt{*Opposite inclusion*}
paulson@13268
    79
apply (rule lfp_lowerbound) 
paulson@13268
    80
 prefer 2 apply (rule lfp_subset) 
paulson@13268
    81
apply (clarify, subst lfp_unfold [OF list.bnd_mono]) 
paulson@13268
    82
apply (simp add: Nil_def Cons_def)
paulson@13268
    83
apply (blast intro: datatype_univs
paulson@13268
    84
             dest: lfp_subset [THEN subsetD])
paulson@13268
    85
done
paulson@13268
    86
paulson@13268
    87
text{*Re-expresses lists using "iterates", no univ.*}
paulson@13268
    88
lemma list_eq_Union:
paulson@13268
    89
     "list(A) = (\<Union>n\<in>nat. (\<lambda>X. {0} + A*X) ^ n (0))"
paulson@13268
    90
by (simp add: list_eq_lfp2 lfp_eq_Union list_fun_bnd_mono list_fun_contin)
paulson@13268
    91
paulson@13268
    92
paulson@13268
    93
subsection {*Absoluteness for "Iterates"*}
paulson@13268
    94
paulson@13268
    95
lemma (in M_trancl) iterates_relativize:
paulson@13268
    96
  "[|n \<in> nat; M(v); \<forall>x[M]. M(F(x));
paulson@13268
    97
     strong_replacement(M, 
paulson@13352
    98
       \<lambda>x z. \<exists>y[M]. \<exists>g[M]. pair(M,x,y,z) &
paulson@13352
    99
              M_is_recfun(M, \<lambda>n f z. z = nat_case(v, \<lambda>m. F(f`m), n), 
paulson@13352
   100
                          Memrel(succ(n)), x, g) &
paulson@13268
   101
              y = nat_case(v, \<lambda>m. F(g`m), x))|] 
paulson@13268
   102
   ==> iterates(F,n,v) = z <-> 
paulson@13268
   103
       (\<exists>g[M]. is_recfun(Memrel(succ(n)), n, 
paulson@13268
   104
                             \<lambda>n g. nat_case(v, \<lambda>m. F(g`m), n), g) &
paulson@13268
   105
            z = nat_case(v, \<lambda>m. F(g`m), n))"
paulson@13268
   106
by (simp add: iterates_nat_def recursor_def transrec_def 
paulson@13268
   107
              eclose_sing_Ord_eq trans_wfrec_relativize nat_into_M
paulson@13352
   108
              wf_Memrel trans_Memrel relation_Memrel
paulson@13352
   109
              is_recfun_abs [of "\<lambda>n g. nat_case(v, \<lambda>m. F(g`m), n)"])
paulson@13268
   110
paulson@13268
   111
lemma (in M_wfrank) iterates_closed [intro,simp]:
paulson@13268
   112
  "[|n \<in> nat; M(v); \<forall>x[M]. M(F(x));
paulson@13268
   113
     strong_replacement(M, 
paulson@13268
   114
       \<lambda>x z. \<exists>y[M]. \<exists>g[M]. pair(M, x, y, z) &
paulson@13268
   115
              is_recfun (Memrel(succ(n)), x,
paulson@13268
   116
                         \<lambda>n f. nat_case(v, \<lambda>m. F(f`m), n), g) &
paulson@13268
   117
              y = nat_case(v, \<lambda>m. F(g`m), x))|] 
paulson@13268
   118
   ==> M(iterates(F,n,v))"
paulson@13268
   119
by (simp add: iterates_nat_def recursor_def transrec_def 
paulson@13268
   120
              eclose_sing_Ord_eq trans_wfrec_closed nat_into_M
paulson@13268
   121
              wf_Memrel trans_Memrel relation_Memrel nat_case_closed)
paulson@13268
   122
paulson@13268
   123
paulson@13350
   124
constdefs
paulson@13350
   125
  is_list_functor :: "[i=>o,i,i,i] => o"
paulson@13350
   126
    "is_list_functor(M,A,X,Z) == 
paulson@13350
   127
        \<exists>n1[M]. \<exists>AX[M]. 
paulson@13350
   128
         number1(M,n1) & cartprod(M,A,X,AX) & is_sum(M,n1,AX,Z)"
paulson@13350
   129
paulson@13352
   130
  list_functor_case :: "[i=>o,i,i,i,i] => o"
paulson@13352
   131
    --{*Abbreviation for the definition of lists below*}
paulson@13352
   132
    "list_functor_case(M,A,g,x,y) == 
paulson@13350
   133
        is_nat_case(M, 0, 
paulson@13350
   134
             \<lambda>m u. \<exists>gm[M]. fun_apply(M,g,m,gm) & is_list_functor(M,A,gm,u),
paulson@13350
   135
             x, y)"
paulson@13350
   136
paulson@13350
   137
lemma (in M_axioms) list_functor_abs [simp]: 
paulson@13350
   138
     "[| M(A); M(X); M(Z) |] ==> is_list_functor(M,A,X,Z) <-> (Z = {0} + A*X)"
paulson@13350
   139
by (simp add: is_list_functor_def singleton_0 nat_into_M)
paulson@13350
   140
paulson@13352
   141
lemma (in M_axioms) list_functor_case_abs: 
paulson@13352
   142
     "[| M(A); M(n); M(y); M(g) |] 
paulson@13352
   143
      ==> list_functor_case(M,A,g,n,y) <-> 
paulson@13352
   144
          y = nat_case(0, \<lambda>m. {0} + A * g`m, n)"
paulson@13352
   145
by (simp add: list_functor_case_def nat_into_M)
paulson@13352
   146
paulson@13350
   147
paulson@13268
   148
locale M_datatypes = M_wfrank +
paulson@13268
   149
  assumes list_replacement1: 
paulson@13350
   150
       "[|M(A); n \<in> nat|] ==> 
paulson@13350
   151
	strong_replacement(M, 
paulson@13350
   152
	  \<lambda>x z. \<exists>y[M]. \<exists>g[M]. \<exists>sucn[M]. \<exists>memr[M]. 
paulson@13350
   153
		 pair(M,x,y,z) & successor(M,n,sucn) & 
paulson@13350
   154
		 membership(M,sucn,memr) &
paulson@13352
   155
		 M_is_recfun(M, \<lambda>n f z. list_functor_case(M,A,f,n,z), 
paulson@13352
   156
                             memr, x, g) &
paulson@13352
   157
                 list_functor_case(M,A,g,x,y))"
paulson@13350
   158
(*THEY NEED RELATIVIZATION*)
paulson@13348
   159
      and list_replacement2: 
paulson@13350
   160
           "M(A) ==> strong_replacement(M, \<lambda>x y. y = (\<lambda>X. {0} + A * X)^x (0))"
paulson@13350
   161
paulson@13268
   162
paulson@13268
   163
paulson@13268
   164
lemma (in M_datatypes) list_replacement1':
paulson@13268
   165
  "[|M(A); n \<in> nat|]
paulson@13268
   166
   ==> strong_replacement
paulson@13350
   167
	  (M, \<lambda>x z. \<exists>y[M]. z = \<langle>x,y\<rangle> &
paulson@13293
   168
               (\<exists>g[M]. is_recfun (Memrel(succ(n)), x,
paulson@13350
   169
		          \<lambda>n f. nat_case(0, \<lambda>m. {0} + A * f`m, n), g) &
paulson@13350
   170
 	       y = nat_case(0, \<lambda>m. {0} + A * g ` m, x)))"
paulson@13350
   171
apply (insert list_replacement1 [of A n], simp add: nat_into_M)
paulson@13352
   172
apply (simp add: nat_into_M list_functor_case_abs
paulson@13350
   173
                 is_recfun_abs [of "\<lambda>n f. nat_case(0, \<lambda>m. {0} + A * f`m, n)"])
paulson@13350
   174
done
paulson@13268
   175
paulson@13348
   176
lemma (in M_datatypes) list_replacement2': 
paulson@13350
   177
  "M(A) ==> strong_replacement(M, \<lambda>x y. y = (\<lambda>X. {0} + A * X)^x (0))"
paulson@13348
   178
by (insert list_replacement2, simp add: nat_into_M) 
paulson@13348
   179
paulson@13268
   180
paulson@13268
   181
lemma (in M_datatypes) list_closed [intro,simp]:
paulson@13268
   182
     "M(A) ==> M(list(A))"
paulson@13268
   183
by (simp add: list_eq_Union list_replacement1' list_replacement2')
paulson@13268
   184
paulson@13293
   185
paulson@13268
   186
end