src/ZF/Constructible/Rec_Separation.thy
 author paulson Fri Jul 19 18:06:31 2002 +0200 (2002-07-19) changeset 13398 1cadd412da48 parent 13395 4eb948d1eb4e child 13409 d4ea094c650e permissions -rw-r--r--
Towards relativization and absoluteness of formula_rec
 paulson@13363 ` 1` ```header{*Separation for Facts About Recursion*} ``` paulson@13348 ` 2` paulson@13363 ` 3` ```theory Rec_Separation = Separation + Datatype_absolute: ``` paulson@13348 ` 4` paulson@13348 ` 5` ```text{*This theory proves all instances needed for locales @{text ``` paulson@13348 ` 6` ```"M_trancl"}, @{text "M_wfrank"} and @{text "M_datatypes"}*} ``` paulson@13348 ` 7` paulson@13363 ` 8` ```lemma eq_succ_imp_lt: "[|i = succ(j); Ord(i)|] ==> jnnat[M]. \n[M]. \n'[M]. ``` paulson@13348 ` 19` ``` omega(M,nnat) & n\nnat & successor(M,n,n') & ``` paulson@13348 ` 20` ``` (\f[M]. typed_function(M,n',A,f) & ``` paulson@13348 ` 21` ``` (\x[M]. \y[M]. \zero[M]. pair(M,x,y,p) & empty(M,zero) & ``` paulson@13348 ` 22` ``` fun_apply(M,f,zero,x) & fun_apply(M,f,n,y)) & ``` paulson@13348 ` 23` ``` (\j[M]. j\n --> ``` paulson@13348 ` 24` ``` (\fj[M]. \sj[M]. \fsj[M]. \ffp[M]. ``` paulson@13348 ` 25` ``` fun_apply(M,f,j,fj) & successor(M,j,sj) & ``` paulson@13348 ` 26` ``` fun_apply(M,f,sj,fsj) & pair(M,fj,fsj,ffp) & ffp \ r)))"*) ``` paulson@13348 ` 27` ```constdefs rtran_closure_mem_fm :: "[i,i,i]=>i" ``` paulson@13348 ` 28` ``` "rtran_closure_mem_fm(A,r,p) == ``` paulson@13348 ` 29` ``` Exists(Exists(Exists( ``` paulson@13348 ` 30` ``` And(omega_fm(2), ``` paulson@13348 ` 31` ``` And(Member(1,2), ``` paulson@13348 ` 32` ``` And(succ_fm(1,0), ``` paulson@13348 ` 33` ``` Exists(And(typed_function_fm(1, A#+4, 0), ``` paulson@13348 ` 34` ``` And(Exists(Exists(Exists( ``` paulson@13348 ` 35` ``` And(pair_fm(2,1,p#+7), ``` paulson@13348 ` 36` ``` And(empty_fm(0), ``` paulson@13348 ` 37` ``` And(fun_apply_fm(3,0,2), fun_apply_fm(3,5,1))))))), ``` paulson@13348 ` 38` ``` Forall(Implies(Member(0,3), ``` paulson@13348 ` 39` ``` Exists(Exists(Exists(Exists( ``` paulson@13348 ` 40` ``` And(fun_apply_fm(5,4,3), ``` paulson@13348 ` 41` ``` And(succ_fm(4,2), ``` paulson@13348 ` 42` ``` And(fun_apply_fm(5,2,1), ``` paulson@13348 ` 43` ``` And(pair_fm(3,1,0), Member(0,r#+9))))))))))))))))))))" ``` paulson@13348 ` 44` paulson@13348 ` 45` paulson@13348 ` 46` ```lemma rtran_closure_mem_type [TC]: ``` paulson@13348 ` 47` ``` "[| x \ nat; y \ nat; z \ nat |] ==> rtran_closure_mem_fm(x,y,z) \ formula" ``` paulson@13348 ` 48` ```by (simp add: rtran_closure_mem_fm_def) ``` paulson@13348 ` 49` paulson@13348 ` 50` ```lemma arity_rtran_closure_mem_fm [simp]: ``` paulson@13348 ` 51` ``` "[| x \ nat; y \ nat; z \ nat |] ``` paulson@13348 ` 52` ``` ==> arity(rtran_closure_mem_fm(x,y,z)) = succ(x) \ succ(y) \ succ(z)" ``` paulson@13348 ` 53` ```by (simp add: rtran_closure_mem_fm_def succ_Un_distrib [symmetric] Un_ac) ``` paulson@13348 ` 54` paulson@13348 ` 55` ```lemma sats_rtran_closure_mem_fm [simp]: ``` paulson@13348 ` 56` ``` "[| x \ nat; y \ nat; z \ nat; env \ list(A)|] ``` paulson@13348 ` 57` ``` ==> sats(A, rtran_closure_mem_fm(x,y,z), env) <-> ``` paulson@13348 ` 58` ``` rtran_closure_mem(**A, nth(x,env), nth(y,env), nth(z,env))" ``` paulson@13348 ` 59` ```by (simp add: rtran_closure_mem_fm_def rtran_closure_mem_def) ``` paulson@13348 ` 60` paulson@13348 ` 61` ```lemma rtran_closure_mem_iff_sats: ``` paulson@13348 ` 62` ``` "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; ``` paulson@13348 ` 63` ``` i \ nat; j \ nat; k \ nat; env \ list(A)|] ``` paulson@13348 ` 64` ``` ==> rtran_closure_mem(**A, x, y, z) <-> sats(A, rtran_closure_mem_fm(i,j,k), env)" ``` paulson@13348 ` 65` ```by (simp add: sats_rtran_closure_mem_fm) ``` paulson@13348 ` 66` paulson@13348 ` 67` ```theorem rtran_closure_mem_reflection: ``` paulson@13348 ` 68` ``` "REFLECTS[\x. rtran_closure_mem(L,f(x),g(x),h(x)), ``` paulson@13348 ` 69` ``` \i x. rtran_closure_mem(**Lset(i),f(x),g(x),h(x))]" ``` paulson@13348 ` 70` ```apply (simp only: rtran_closure_mem_def setclass_simps) ``` paulson@13348 ` 71` ```apply (intro FOL_reflections function_reflections fun_plus_reflections) ``` paulson@13348 ` 72` ```done ``` paulson@13348 ` 73` paulson@13348 ` 74` ```text{*Separation for @{term "rtrancl(r)"}.*} ``` paulson@13348 ` 75` ```lemma rtrancl_separation: ``` paulson@13348 ` 76` ``` "[| L(r); L(A) |] ==> separation (L, rtran_closure_mem(L,A,r))" ``` paulson@13348 ` 77` ```apply (rule separation_CollectI) ``` paulson@13348 ` 78` ```apply (rule_tac A="{r,A,z}" in subset_LsetE, blast ) ``` paulson@13348 ` 79` ```apply (rule ReflectsE [OF rtran_closure_mem_reflection], assumption) ``` paulson@13348 ` 80` ```apply (drule subset_Lset_ltD, assumption) ``` paulson@13348 ` 81` ```apply (erule reflection_imp_L_separation) ``` paulson@13348 ` 82` ``` apply (simp_all add: lt_Ord2) ``` paulson@13385 ` 83` ```apply (rule DPow_LsetI) ``` paulson@13348 ` 84` ```apply (rename_tac u) ``` paulson@13348 ` 85` ```apply (rule_tac env = "[u,r,A]" in rtran_closure_mem_iff_sats) ``` paulson@13348 ` 86` ```apply (rule sep_rules | simp)+ ``` paulson@13348 ` 87` ```done ``` paulson@13348 ` 88` paulson@13348 ` 89` paulson@13348 ` 90` ```subsubsection{*Reflexive/Transitive Closure, Internalized*} ``` paulson@13348 ` 91` paulson@13348 ` 92` ```(* "rtran_closure(M,r,s) == ``` paulson@13348 ` 93` ``` \A[M]. is_field(M,r,A) --> ``` paulson@13348 ` 94` ``` (\p[M]. p \ s <-> rtran_closure_mem(M,A,r,p))" *) ``` paulson@13348 ` 95` ```constdefs rtran_closure_fm :: "[i,i]=>i" ``` paulson@13348 ` 96` ``` "rtran_closure_fm(r,s) == ``` paulson@13348 ` 97` ``` Forall(Implies(field_fm(succ(r),0), ``` paulson@13348 ` 98` ``` Forall(Iff(Member(0,succ(succ(s))), ``` paulson@13348 ` 99` ``` rtran_closure_mem_fm(1,succ(succ(r)),0)))))" ``` paulson@13348 ` 100` paulson@13348 ` 101` ```lemma rtran_closure_type [TC]: ``` paulson@13348 ` 102` ``` "[| x \ nat; y \ nat |] ==> rtran_closure_fm(x,y) \ formula" ``` paulson@13348 ` 103` ```by (simp add: rtran_closure_fm_def) ``` paulson@13348 ` 104` paulson@13348 ` 105` ```lemma arity_rtran_closure_fm [simp]: ``` paulson@13348 ` 106` ``` "[| x \ nat; y \ nat |] ``` paulson@13348 ` 107` ``` ==> arity(rtran_closure_fm(x,y)) = succ(x) \ succ(y)" ``` paulson@13348 ` 108` ```by (simp add: rtran_closure_fm_def succ_Un_distrib [symmetric] Un_ac) ``` paulson@13348 ` 109` paulson@13348 ` 110` ```lemma sats_rtran_closure_fm [simp]: ``` paulson@13348 ` 111` ``` "[| x \ nat; y \ nat; env \ list(A)|] ``` paulson@13348 ` 112` ``` ==> sats(A, rtran_closure_fm(x,y), env) <-> ``` paulson@13348 ` 113` ``` rtran_closure(**A, nth(x,env), nth(y,env))" ``` paulson@13348 ` 114` ```by (simp add: rtran_closure_fm_def rtran_closure_def) ``` paulson@13348 ` 115` paulson@13348 ` 116` ```lemma rtran_closure_iff_sats: ``` paulson@13348 ` 117` ``` "[| nth(i,env) = x; nth(j,env) = y; ``` paulson@13348 ` 118` ``` i \ nat; j \ nat; env \ list(A)|] ``` paulson@13348 ` 119` ``` ==> rtran_closure(**A, x, y) <-> sats(A, rtran_closure_fm(i,j), env)" ``` paulson@13348 ` 120` ```by simp ``` paulson@13348 ` 121` paulson@13348 ` 122` ```theorem rtran_closure_reflection: ``` paulson@13348 ` 123` ``` "REFLECTS[\x. rtran_closure(L,f(x),g(x)), ``` paulson@13348 ` 124` ``` \i x. rtran_closure(**Lset(i),f(x),g(x))]" ``` paulson@13348 ` 125` ```apply (simp only: rtran_closure_def setclass_simps) ``` paulson@13348 ` 126` ```apply (intro FOL_reflections function_reflections rtran_closure_mem_reflection) ``` paulson@13348 ` 127` ```done ``` paulson@13348 ` 128` paulson@13348 ` 129` paulson@13348 ` 130` ```subsubsection{*Transitive Closure of a Relation, Internalized*} ``` paulson@13348 ` 131` paulson@13348 ` 132` ```(* "tran_closure(M,r,t) == ``` paulson@13348 ` 133` ``` \s[M]. rtran_closure(M,r,s) & composition(M,r,s,t)" *) ``` paulson@13348 ` 134` ```constdefs tran_closure_fm :: "[i,i]=>i" ``` paulson@13348 ` 135` ``` "tran_closure_fm(r,s) == ``` paulson@13348 ` 136` ``` Exists(And(rtran_closure_fm(succ(r),0), composition_fm(succ(r),0,succ(s))))" ``` paulson@13348 ` 137` paulson@13348 ` 138` ```lemma tran_closure_type [TC]: ``` paulson@13348 ` 139` ``` "[| x \ nat; y \ nat |] ==> tran_closure_fm(x,y) \ formula" ``` paulson@13348 ` 140` ```by (simp add: tran_closure_fm_def) ``` paulson@13348 ` 141` paulson@13348 ` 142` ```lemma arity_tran_closure_fm [simp]: ``` paulson@13348 ` 143` ``` "[| x \ nat; y \ nat |] ``` paulson@13348 ` 144` ``` ==> arity(tran_closure_fm(x,y)) = succ(x) \ succ(y)" ``` paulson@13348 ` 145` ```by (simp add: tran_closure_fm_def succ_Un_distrib [symmetric] Un_ac) ``` paulson@13348 ` 146` paulson@13348 ` 147` ```lemma sats_tran_closure_fm [simp]: ``` paulson@13348 ` 148` ``` "[| x \ nat; y \ nat; env \ list(A)|] ``` paulson@13348 ` 149` ``` ==> sats(A, tran_closure_fm(x,y), env) <-> ``` paulson@13348 ` 150` ``` tran_closure(**A, nth(x,env), nth(y,env))" ``` paulson@13348 ` 151` ```by (simp add: tran_closure_fm_def tran_closure_def) ``` paulson@13348 ` 152` paulson@13348 ` 153` ```lemma tran_closure_iff_sats: ``` paulson@13348 ` 154` ``` "[| nth(i,env) = x; nth(j,env) = y; ``` paulson@13348 ` 155` ``` i \ nat; j \ nat; env \ list(A)|] ``` paulson@13348 ` 156` ``` ==> tran_closure(**A, x, y) <-> sats(A, tran_closure_fm(i,j), env)" ``` paulson@13348 ` 157` ```by simp ``` paulson@13348 ` 158` paulson@13348 ` 159` ```theorem tran_closure_reflection: ``` paulson@13348 ` 160` ``` "REFLECTS[\x. tran_closure(L,f(x),g(x)), ``` paulson@13348 ` 161` ``` \i x. tran_closure(**Lset(i),f(x),g(x))]" ``` paulson@13348 ` 162` ```apply (simp only: tran_closure_def setclass_simps) ``` paulson@13348 ` 163` ```apply (intro FOL_reflections function_reflections ``` paulson@13348 ` 164` ``` rtran_closure_reflection composition_reflection) ``` paulson@13348 ` 165` ```done ``` paulson@13348 ` 166` paulson@13348 ` 167` paulson@13348 ` 168` ```subsection{*Separation for the Proof of @{text "wellfounded_on_trancl"}*} ``` paulson@13348 ` 169` paulson@13348 ` 170` ```lemma wellfounded_trancl_reflects: ``` paulson@13348 ` 171` ``` "REFLECTS[\x. \w[L]. \wx[L]. \rp[L]. ``` paulson@13348 ` 172` ``` w \ Z & pair(L,w,x,wx) & tran_closure(L,r,rp) & wx \ rp, ``` paulson@13348 ` 173` ``` \i x. \w \ Lset(i). \wx \ Lset(i). \rp \ Lset(i). ``` paulson@13348 ` 174` ``` w \ Z & pair(**Lset(i),w,x,wx) & tran_closure(**Lset(i),r,rp) & ``` paulson@13348 ` 175` ``` wx \ rp]" ``` paulson@13348 ` 176` ```by (intro FOL_reflections function_reflections fun_plus_reflections ``` paulson@13348 ` 177` ``` tran_closure_reflection) ``` paulson@13348 ` 178` paulson@13348 ` 179` paulson@13348 ` 180` ```lemma wellfounded_trancl_separation: ``` paulson@13348 ` 181` ``` "[| L(r); L(Z) |] ==> ``` paulson@13348 ` 182` ``` separation (L, \x. ``` paulson@13348 ` 183` ``` \w[L]. \wx[L]. \rp[L]. ``` paulson@13348 ` 184` ``` w \ Z & pair(L,w,x,wx) & tran_closure(L,r,rp) & wx \ rp)" ``` paulson@13348 ` 185` ```apply (rule separation_CollectI) ``` paulson@13348 ` 186` ```apply (rule_tac A="{r,Z,z}" in subset_LsetE, blast ) ``` paulson@13348 ` 187` ```apply (rule ReflectsE [OF wellfounded_trancl_reflects], assumption) ``` paulson@13348 ` 188` ```apply (drule subset_Lset_ltD, assumption) ``` paulson@13348 ` 189` ```apply (erule reflection_imp_L_separation) ``` paulson@13348 ` 190` ``` apply (simp_all add: lt_Ord2) ``` paulson@13385 ` 191` ```apply (rule DPow_LsetI) ``` paulson@13348 ` 192` ```apply (rename_tac u) ``` paulson@13348 ` 193` ```apply (rule bex_iff_sats conj_iff_sats)+ ``` paulson@13348 ` 194` ```apply (rule_tac env = "[w,u,r,Z]" in mem_iff_sats) ``` paulson@13348 ` 195` ```apply (rule sep_rules tran_closure_iff_sats | simp)+ ``` paulson@13348 ` 196` ```done ``` paulson@13348 ` 197` paulson@13363 ` 198` paulson@13363 ` 199` ```subsubsection{*Instantiating the locale @{text M_trancl}*} ``` paulson@13363 ` 200` ```ML ``` paulson@13363 ` 201` ```{* ``` paulson@13363 ` 202` ```val rtrancl_separation = thm "rtrancl_separation"; ``` paulson@13363 ` 203` ```val wellfounded_trancl_separation = thm "wellfounded_trancl_separation"; ``` paulson@13363 ` 204` paulson@13363 ` 205` paulson@13363 ` 206` ```val m_trancl = [rtrancl_separation, wellfounded_trancl_separation]; ``` paulson@13363 ` 207` paulson@13363 ` 208` ```fun trancl_L th = ``` paulson@13363 ` 209` ``` kill_flex_triv_prems (m_trancl MRS (axioms_L th)); ``` paulson@13363 ` 210` paulson@13363 ` 211` ```bind_thm ("iterates_abs", trancl_L (thm "M_trancl.iterates_abs")); ``` paulson@13363 ` 212` ```bind_thm ("rtran_closure_rtrancl", trancl_L (thm "M_trancl.rtran_closure_rtrancl")); ``` paulson@13363 ` 213` ```bind_thm ("rtrancl_closed", trancl_L (thm "M_trancl.rtrancl_closed")); ``` paulson@13363 ` 214` ```bind_thm ("rtrancl_abs", trancl_L (thm "M_trancl.rtrancl_abs")); ``` paulson@13363 ` 215` ```bind_thm ("trancl_closed", trancl_L (thm "M_trancl.trancl_closed")); ``` paulson@13363 ` 216` ```bind_thm ("trancl_abs", trancl_L (thm "M_trancl.trancl_abs")); ``` paulson@13363 ` 217` ```bind_thm ("wellfounded_on_trancl", trancl_L (thm "M_trancl.wellfounded_on_trancl")); ``` paulson@13363 ` 218` ```bind_thm ("wellfounded_trancl", trancl_L (thm "M_trancl.wellfounded_trancl")); ``` paulson@13363 ` 219` ```bind_thm ("wfrec_relativize", trancl_L (thm "M_trancl.wfrec_relativize")); ``` paulson@13363 ` 220` ```bind_thm ("trans_wfrec_relativize", trancl_L (thm "M_trancl.trans_wfrec_relativize")); ``` paulson@13363 ` 221` ```bind_thm ("trans_wfrec_abs", trancl_L (thm "M_trancl.trans_wfrec_abs")); ``` paulson@13363 ` 222` ```bind_thm ("trans_eq_pair_wfrec_iff", trancl_L (thm "M_trancl.trans_eq_pair_wfrec_iff")); ``` paulson@13363 ` 223` ```bind_thm ("eq_pair_wfrec_iff", trancl_L (thm "M_trancl.eq_pair_wfrec_iff")); ``` paulson@13363 ` 224` ```*} ``` paulson@13363 ` 225` paulson@13363 ` 226` ```declare rtrancl_closed [intro,simp] ``` paulson@13363 ` 227` ```declare rtrancl_abs [simp] ``` paulson@13363 ` 228` ```declare trancl_closed [intro,simp] ``` paulson@13363 ` 229` ```declare trancl_abs [simp] ``` paulson@13363 ` 230` paulson@13363 ` 231` paulson@13348 ` 232` ```subsection{*Well-Founded Recursion!*} ``` paulson@13348 ` 233` paulson@13352 ` 234` ```(* M_is_recfun :: "[i=>o, [i,i,i]=>o, i, i, i] => o" ``` paulson@13352 ` 235` ``` "M_is_recfun(M,MH,r,a,f) == ``` paulson@13348 ` 236` ``` \z[M]. z \ f <-> ``` paulson@13348 ` 237` ``` 5 4 3 2 1 0 ``` paulson@13348 ` 238` ``` (\x[M]. \y[M]. \xa[M]. \sx[M]. \r_sx[M]. \f_r_sx[M]. ``` paulson@13348 ` 239` ``` pair(M,x,y,z) & pair(M,x,a,xa) & upair(M,x,x,sx) & ``` paulson@13348 ` 240` ``` pre_image(M,r,sx,r_sx) & restriction(M,f,r_sx,f_r_sx) & ``` paulson@13348 ` 241` ``` xa \ r & MH(x, f_r_sx, y))" ``` paulson@13348 ` 242` ```*) ``` paulson@13348 ` 243` paulson@13348 ` 244` ```constdefs is_recfun_fm :: "[[i,i,i]=>i, i, i, i]=>i" ``` paulson@13348 ` 245` ``` "is_recfun_fm(p,r,a,f) == ``` paulson@13348 ` 246` ``` Forall(Iff(Member(0,succ(f)), ``` paulson@13348 ` 247` ``` Exists(Exists(Exists(Exists(Exists(Exists( ``` paulson@13348 ` 248` ``` And(pair_fm(5,4,6), ``` paulson@13348 ` 249` ``` And(pair_fm(5,a#+7,3), ``` paulson@13348 ` 250` ``` And(upair_fm(5,5,2), ``` paulson@13348 ` 251` ``` And(pre_image_fm(r#+7,2,1), ``` paulson@13348 ` 252` ``` And(restriction_fm(f#+7,1,0), ``` paulson@13348 ` 253` ``` And(Member(3,r#+7), p(5,0,4)))))))))))))))" ``` paulson@13348 ` 254` paulson@13348 ` 255` paulson@13348 ` 256` ```lemma is_recfun_type_0: ``` paulson@13348 ` 257` ``` "[| !!x y z. [| x \ nat; y \ nat; z \ nat |] ==> p(x,y,z) \ formula; ``` paulson@13348 ` 258` ``` x \ nat; y \ nat; z \ nat |] ``` paulson@13348 ` 259` ``` ==> is_recfun_fm(p,x,y,z) \ formula" ``` paulson@13348 ` 260` ```apply (unfold is_recfun_fm_def) ``` paulson@13348 ` 261` ```(*FIXME: FIND OUT why simp loops!*) ``` paulson@13348 ` 262` ```apply typecheck ``` paulson@13348 ` 263` ```by simp ``` paulson@13348 ` 264` paulson@13348 ` 265` ```lemma is_recfun_type [TC]: ``` paulson@13348 ` 266` ``` "[| p(5,0,4) \ formula; ``` paulson@13348 ` 267` ``` x \ nat; y \ nat; z \ nat |] ``` paulson@13348 ` 268` ``` ==> is_recfun_fm(p,x,y,z) \ formula" ``` paulson@13348 ` 269` ```by (simp add: is_recfun_fm_def) ``` paulson@13348 ` 270` paulson@13348 ` 271` ```lemma arity_is_recfun_fm [simp]: ``` paulson@13348 ` 272` ``` "[| arity(p(5,0,4)) le 8; x \ nat; y \ nat; z \ nat |] ``` paulson@13348 ` 273` ``` ==> arity(is_recfun_fm(p,x,y,z)) = succ(x) \ succ(y) \ succ(z)" ``` paulson@13348 ` 274` ```apply (frule lt_nat_in_nat, simp) ``` paulson@13348 ` 275` ```apply (simp add: is_recfun_fm_def succ_Un_distrib [symmetric] ) ``` paulson@13348 ` 276` ```apply (subst subset_Un_iff2 [of "arity(p(5,0,4))", THEN iffD1]) ``` paulson@13348 ` 277` ```apply (rule le_imp_subset) ``` paulson@13348 ` 278` ```apply (erule le_trans, simp) ``` paulson@13348 ` 279` ```apply (simp add: succ_Un_distrib [symmetric] Un_ac) ``` paulson@13348 ` 280` ```done ``` paulson@13348 ` 281` paulson@13348 ` 282` ```lemma sats_is_recfun_fm: ``` paulson@13348 ` 283` ``` assumes MH_iff_sats: ``` paulson@13348 ` 284` ``` "!!x y z env. ``` paulson@13348 ` 285` ``` [| x \ nat; y \ nat; z \ nat; env \ list(A)|] ``` paulson@13348 ` 286` ``` ==> MH(nth(x,env), nth(y,env), nth(z,env)) <-> sats(A, p(x,y,z), env)" ``` paulson@13348 ` 287` ``` shows ``` paulson@13348 ` 288` ``` "[|x \ nat; y \ nat; z \ nat; env \ list(A)|] ``` paulson@13348 ` 289` ``` ==> sats(A, is_recfun_fm(p,x,y,z), env) <-> ``` paulson@13352 ` 290` ``` M_is_recfun(**A, MH, nth(x,env), nth(y,env), nth(z,env))" ``` paulson@13348 ` 291` ```by (simp add: is_recfun_fm_def M_is_recfun_def MH_iff_sats [THEN iff_sym]) ``` paulson@13348 ` 292` paulson@13348 ` 293` ```lemma is_recfun_iff_sats: ``` paulson@13348 ` 294` ``` "[| (!!x y z env. [| x \ nat; y \ nat; z \ nat; env \ list(A)|] ``` paulson@13348 ` 295` ``` ==> MH(nth(x,env), nth(y,env), nth(z,env)) <-> ``` paulson@13348 ` 296` ``` sats(A, p(x,y,z), env)); ``` paulson@13348 ` 297` ``` nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; ``` paulson@13348 ` 298` ``` i \ nat; j \ nat; k \ nat; env \ list(A)|] ``` paulson@13352 ` 299` ``` ==> M_is_recfun(**A, MH, x, y, z) <-> sats(A, is_recfun_fm(p,i,j,k), env)" ``` paulson@13348 ` 300` ```by (simp add: sats_is_recfun_fm [of A MH]) ``` paulson@13348 ` 301` paulson@13348 ` 302` ```theorem is_recfun_reflection: ``` paulson@13348 ` 303` ``` assumes MH_reflection: ``` paulson@13348 ` 304` ``` "!!f g h. REFLECTS[\x. MH(L, f(x), g(x), h(x)), ``` paulson@13348 ` 305` ``` \i x. MH(**Lset(i), f(x), g(x), h(x))]" ``` paulson@13352 ` 306` ``` shows "REFLECTS[\x. M_is_recfun(L, MH(L), f(x), g(x), h(x)), ``` paulson@13352 ` 307` ``` \i x. M_is_recfun(**Lset(i), MH(**Lset(i)), f(x), g(x), h(x))]" ``` paulson@13348 ` 308` ```apply (simp (no_asm_use) only: M_is_recfun_def setclass_simps) ``` paulson@13348 ` 309` ```apply (intro FOL_reflections function_reflections ``` paulson@13348 ` 310` ``` restriction_reflection MH_reflection) ``` paulson@13348 ` 311` ```done ``` paulson@13348 ` 312` paulson@13363 ` 313` ```text{*Currently, @{text sats}-theorems for higher-order operators don't seem ``` paulson@13363 ` 314` ```useful. Reflection theorems do work, though. This one avoids the repetition ``` paulson@13363 ` 315` ```of the @{text MH}-term.*} ``` paulson@13363 ` 316` ```theorem is_wfrec_reflection: ``` paulson@13363 ` 317` ``` assumes MH_reflection: ``` paulson@13363 ` 318` ``` "!!f g h. REFLECTS[\x. MH(L, f(x), g(x), h(x)), ``` paulson@13363 ` 319` ``` \i x. MH(**Lset(i), f(x), g(x), h(x))]" ``` paulson@13363 ` 320` ``` shows "REFLECTS[\x. is_wfrec(L, MH(L), f(x), g(x), h(x)), ``` paulson@13363 ` 321` ``` \i x. is_wfrec(**Lset(i), MH(**Lset(i)), f(x), g(x), h(x))]" ``` paulson@13363 ` 322` ```apply (simp (no_asm_use) only: is_wfrec_def setclass_simps) ``` paulson@13363 ` 323` ```apply (intro FOL_reflections MH_reflection is_recfun_reflection) ``` paulson@13363 ` 324` ```done ``` paulson@13363 ` 325` paulson@13363 ` 326` ```subsection{*The Locale @{text "M_wfrank"}*} ``` paulson@13363 ` 327` paulson@13363 ` 328` ```subsubsection{*Separation for @{term "wfrank"}*} ``` paulson@13348 ` 329` paulson@13348 ` 330` ```lemma wfrank_Reflects: ``` paulson@13348 ` 331` ``` "REFLECTS[\x. \rplus[L]. tran_closure(L,r,rplus) --> ``` paulson@13352 ` 332` ``` ~ (\f[L]. M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f)), ``` paulson@13348 ` 333` ``` \i x. \rplus \ Lset(i). tran_closure(**Lset(i),r,rplus) --> ``` paulson@13352 ` 334` ``` ~ (\f \ Lset(i). ``` paulson@13352 ` 335` ``` M_is_recfun(**Lset(i), %x f y. is_range(**Lset(i),f,y), ``` paulson@13352 ` 336` ``` rplus, x, f))]" ``` paulson@13348 ` 337` ```by (intro FOL_reflections function_reflections is_recfun_reflection tran_closure_reflection) ``` paulson@13348 ` 338` paulson@13348 ` 339` ```lemma wfrank_separation: ``` paulson@13348 ` 340` ``` "L(r) ==> ``` paulson@13348 ` 341` ``` separation (L, \x. \rplus[L]. tran_closure(L,r,rplus) --> ``` paulson@13352 ` 342` ``` ~ (\f[L]. M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f)))" ``` paulson@13348 ` 343` ```apply (rule separation_CollectI) ``` paulson@13348 ` 344` ```apply (rule_tac A="{r,z}" in subset_LsetE, blast ) ``` paulson@13348 ` 345` ```apply (rule ReflectsE [OF wfrank_Reflects], assumption) ``` paulson@13348 ` 346` ```apply (drule subset_Lset_ltD, assumption) ``` paulson@13348 ` 347` ```apply (erule reflection_imp_L_separation) ``` paulson@13348 ` 348` ``` apply (simp_all add: lt_Ord2, clarify) ``` paulson@13385 ` 349` ```apply (rule DPow_LsetI) ``` paulson@13348 ` 350` ```apply (rename_tac u) ``` paulson@13348 ` 351` ```apply (rule ball_iff_sats imp_iff_sats)+ ``` paulson@13348 ` 352` ```apply (rule_tac env="[rplus,u,r]" in tran_closure_iff_sats) ``` paulson@13348 ` 353` ```apply (rule sep_rules is_recfun_iff_sats | simp)+ ``` paulson@13348 ` 354` ```done ``` paulson@13348 ` 355` paulson@13348 ` 356` paulson@13363 ` 357` ```subsubsection{*Replacement for @{term "wfrank"}*} ``` paulson@13348 ` 358` paulson@13348 ` 359` ```lemma wfrank_replacement_Reflects: ``` paulson@13348 ` 360` ``` "REFLECTS[\z. \x[L]. x \ A & ``` paulson@13348 ` 361` ``` (\rplus[L]. tran_closure(L,r,rplus) --> ``` paulson@13348 ` 362` ``` (\y[L]. \f[L]. pair(L,x,y,z) & ``` paulson@13352 ` 363` ``` M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f) & ``` paulson@13348 ` 364` ``` is_range(L,f,y))), ``` paulson@13348 ` 365` ``` \i z. \x \ Lset(i). x \ A & ``` paulson@13348 ` 366` ``` (\rplus \ Lset(i). tran_closure(**Lset(i),r,rplus) --> ``` paulson@13348 ` 367` ``` (\y \ Lset(i). \f \ Lset(i). pair(**Lset(i),x,y,z) & ``` paulson@13352 ` 368` ``` M_is_recfun(**Lset(i), %x f y. is_range(**Lset(i),f,y), rplus, x, f) & ``` paulson@13348 ` 369` ``` is_range(**Lset(i),f,y)))]" ``` paulson@13348 ` 370` ```by (intro FOL_reflections function_reflections fun_plus_reflections ``` paulson@13348 ` 371` ``` is_recfun_reflection tran_closure_reflection) ``` paulson@13348 ` 372` paulson@13348 ` 373` paulson@13348 ` 374` ```lemma wfrank_strong_replacement: ``` paulson@13348 ` 375` ``` "L(r) ==> ``` paulson@13348 ` 376` ``` strong_replacement(L, \x z. ``` paulson@13348 ` 377` ``` \rplus[L]. tran_closure(L,r,rplus) --> ``` paulson@13348 ` 378` ``` (\y[L]. \f[L]. pair(L,x,y,z) & ``` paulson@13352 ` 379` ``` M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f) & ``` paulson@13348 ` 380` ``` is_range(L,f,y)))" ``` paulson@13348 ` 381` ```apply (rule strong_replacementI) ``` paulson@13348 ` 382` ```apply (rule rallI) ``` paulson@13348 ` 383` ```apply (rename_tac B) ``` paulson@13348 ` 384` ```apply (rule separation_CollectI) ``` paulson@13348 ` 385` ```apply (rule_tac A="{B,r,z}" in subset_LsetE, blast ) ``` paulson@13348 ` 386` ```apply (rule ReflectsE [OF wfrank_replacement_Reflects], assumption) ``` paulson@13348 ` 387` ```apply (drule subset_Lset_ltD, assumption) ``` paulson@13348 ` 388` ```apply (erule reflection_imp_L_separation) ``` paulson@13348 ` 389` ``` apply (simp_all add: lt_Ord2) ``` paulson@13385 ` 390` ```apply (rule DPow_LsetI) ``` paulson@13348 ` 391` ```apply (rename_tac u) ``` paulson@13348 ` 392` ```apply (rule bex_iff_sats ball_iff_sats conj_iff_sats)+ ``` paulson@13348 ` 393` ```apply (rule_tac env = "[x,u,B,r]" in mem_iff_sats) ``` paulson@13348 ` 394` ```apply (rule sep_rules tran_closure_iff_sats is_recfun_iff_sats | simp)+ ``` paulson@13348 ` 395` ```done ``` paulson@13348 ` 396` paulson@13348 ` 397` paulson@13363 ` 398` ```subsubsection{*Separation for Proving @{text Ord_wfrank_range}*} ``` paulson@13348 ` 399` paulson@13348 ` 400` ```lemma Ord_wfrank_Reflects: ``` paulson@13348 ` 401` ``` "REFLECTS[\x. \rplus[L]. tran_closure(L,r,rplus) --> ``` paulson@13348 ` 402` ``` ~ (\f[L]. \rangef[L]. ``` paulson@13348 ` 403` ``` is_range(L,f,rangef) --> ``` paulson@13352 ` 404` ``` M_is_recfun(L, \x f y. is_range(L,f,y), rplus, x, f) --> ``` paulson@13348 ` 405` ``` ordinal(L,rangef)), ``` paulson@13348 ` 406` ``` \i x. \rplus \ Lset(i). tran_closure(**Lset(i),r,rplus) --> ``` paulson@13348 ` 407` ``` ~ (\f \ Lset(i). \rangef \ Lset(i). ``` paulson@13348 ` 408` ``` is_range(**Lset(i),f,rangef) --> ``` paulson@13352 ` 409` ``` M_is_recfun(**Lset(i), \x f y. is_range(**Lset(i),f,y), ``` paulson@13352 ` 410` ``` rplus, x, f) --> ``` paulson@13348 ` 411` ``` ordinal(**Lset(i),rangef))]" ``` paulson@13348 ` 412` ```by (intro FOL_reflections function_reflections is_recfun_reflection ``` paulson@13348 ` 413` ``` tran_closure_reflection ordinal_reflection) ``` paulson@13348 ` 414` paulson@13348 ` 415` ```lemma Ord_wfrank_separation: ``` paulson@13348 ` 416` ``` "L(r) ==> ``` paulson@13348 ` 417` ``` separation (L, \x. ``` paulson@13348 ` 418` ``` \rplus[L]. tran_closure(L,r,rplus) --> ``` paulson@13348 ` 419` ``` ~ (\f[L]. \rangef[L]. ``` paulson@13348 ` 420` ``` is_range(L,f,rangef) --> ``` paulson@13352 ` 421` ``` M_is_recfun(L, \x f y. is_range(L,f,y), rplus, x, f) --> ``` paulson@13348 ` 422` ``` ordinal(L,rangef)))" ``` paulson@13348 ` 423` ```apply (rule separation_CollectI) ``` paulson@13348 ` 424` ```apply (rule_tac A="{r,z}" in subset_LsetE, blast ) ``` paulson@13348 ` 425` ```apply (rule ReflectsE [OF Ord_wfrank_Reflects], assumption) ``` paulson@13348 ` 426` ```apply (drule subset_Lset_ltD, assumption) ``` paulson@13348 ` 427` ```apply (erule reflection_imp_L_separation) ``` paulson@13348 ` 428` ``` apply (simp_all add: lt_Ord2, clarify) ``` paulson@13385 ` 429` ```apply (rule DPow_LsetI) ``` paulson@13348 ` 430` ```apply (rename_tac u) ``` paulson@13348 ` 431` ```apply (rule ball_iff_sats imp_iff_sats)+ ``` paulson@13348 ` 432` ```apply (rule_tac env="[rplus,u,r]" in tran_closure_iff_sats) ``` paulson@13348 ` 433` ```apply (rule sep_rules is_recfun_iff_sats | simp)+ ``` paulson@13348 ` 434` ```done ``` paulson@13348 ` 435` paulson@13348 ` 436` paulson@13363 ` 437` ```subsubsection{*Instantiating the locale @{text M_wfrank}*} ``` paulson@13363 ` 438` ```ML ``` paulson@13363 ` 439` ```{* ``` paulson@13363 ` 440` ```val wfrank_separation = thm "wfrank_separation"; ``` paulson@13363 ` 441` ```val wfrank_strong_replacement = thm "wfrank_strong_replacement"; ``` paulson@13363 ` 442` ```val Ord_wfrank_separation = thm "Ord_wfrank_separation"; ``` paulson@13363 ` 443` paulson@13363 ` 444` ```val m_wfrank = ``` paulson@13363 ` 445` ``` [wfrank_separation, wfrank_strong_replacement, Ord_wfrank_separation]; ``` paulson@13363 ` 446` paulson@13363 ` 447` ```fun wfrank_L th = ``` paulson@13363 ` 448` ``` kill_flex_triv_prems (m_wfrank MRS (trancl_L th)); ``` paulson@13363 ` 449` paulson@13363 ` 450` paulson@13363 ` 451` paulson@13363 ` 452` ```bind_thm ("iterates_closed", wfrank_L (thm "M_wfrank.iterates_closed")); ``` paulson@13363 ` 453` ```bind_thm ("exists_wfrank", wfrank_L (thm "M_wfrank.exists_wfrank")); ``` paulson@13363 ` 454` ```bind_thm ("M_wellfoundedrank", wfrank_L (thm "M_wfrank.M_wellfoundedrank")); ``` paulson@13363 ` 455` ```bind_thm ("Ord_wfrank_range", wfrank_L (thm "M_wfrank.Ord_wfrank_range")); ``` paulson@13363 ` 456` ```bind_thm ("Ord_range_wellfoundedrank", wfrank_L (thm "M_wfrank.Ord_range_wellfoundedrank")); ``` paulson@13363 ` 457` ```bind_thm ("function_wellfoundedrank", wfrank_L (thm "M_wfrank.function_wellfoundedrank")); ``` paulson@13363 ` 458` ```bind_thm ("domain_wellfoundedrank", wfrank_L (thm "M_wfrank.domain_wellfoundedrank")); ``` paulson@13363 ` 459` ```bind_thm ("wellfoundedrank_type", wfrank_L (thm "M_wfrank.wellfoundedrank_type")); ``` paulson@13363 ` 460` ```bind_thm ("Ord_wellfoundedrank", wfrank_L (thm "M_wfrank.Ord_wellfoundedrank")); ``` paulson@13363 ` 461` ```bind_thm ("wellfoundedrank_eq", wfrank_L (thm "M_wfrank.wellfoundedrank_eq")); ``` paulson@13363 ` 462` ```bind_thm ("wellfoundedrank_lt", wfrank_L (thm "M_wfrank.wellfoundedrank_lt")); ``` paulson@13363 ` 463` ```bind_thm ("wellfounded_imp_subset_rvimage", wfrank_L (thm "M_wfrank.wellfounded_imp_subset_rvimage")); ``` paulson@13363 ` 464` ```bind_thm ("wellfounded_imp_wf", wfrank_L (thm "M_wfrank.wellfounded_imp_wf")); ``` paulson@13363 ` 465` ```bind_thm ("wellfounded_on_imp_wf_on", wfrank_L (thm "M_wfrank.wellfounded_on_imp_wf_on")); ``` paulson@13363 ` 466` ```bind_thm ("wf_abs", wfrank_L (thm "M_wfrank.wf_abs")); ``` paulson@13363 ` 467` ```bind_thm ("wf_on_abs", wfrank_L (thm "M_wfrank.wf_on_abs")); ``` paulson@13363 ` 468` ```bind_thm ("wfrec_replacement_iff", wfrank_L (thm "M_wfrank.wfrec_replacement_iff")); ``` paulson@13363 ` 469` ```bind_thm ("trans_wfrec_closed", wfrank_L (thm "M_wfrank.trans_wfrec_closed")); ``` paulson@13363 ` 470` ```bind_thm ("wfrec_closed", wfrank_L (thm "M_wfrank.wfrec_closed")); ``` paulson@13363 ` 471` ```*} ``` paulson@13363 ` 472` paulson@13363 ` 473` ```declare iterates_closed [intro,simp] ``` paulson@13363 ` 474` ```declare Ord_wfrank_range [rule_format] ``` paulson@13363 ` 475` ```declare wf_abs [simp] ``` paulson@13363 ` 476` ```declare wf_on_abs [simp] ``` paulson@13363 ` 477` paulson@13363 ` 478` paulson@13363 ` 479` ```subsection{*For Datatypes*} ``` paulson@13363 ` 480` paulson@13363 ` 481` ```subsubsection{*Binary Products, Internalized*} ``` paulson@13363 ` 482` paulson@13363 ` 483` ```constdefs cartprod_fm :: "[i,i,i]=>i" ``` paulson@13363 ` 484` ```(* "cartprod(M,A,B,z) == ``` paulson@13363 ` 485` ``` \u[M]. u \ z <-> (\x[M]. x\A & (\y[M]. y\B & pair(M,x,y,u)))" *) ``` paulson@13363 ` 486` ``` "cartprod_fm(A,B,z) == ``` paulson@13363 ` 487` ``` Forall(Iff(Member(0,succ(z)), ``` paulson@13363 ` 488` ``` Exists(And(Member(0,succ(succ(A))), ``` paulson@13363 ` 489` ``` Exists(And(Member(0,succ(succ(succ(B)))), ``` paulson@13363 ` 490` ``` pair_fm(1,0,2)))))))" ``` paulson@13363 ` 491` paulson@13363 ` 492` ```lemma cartprod_type [TC]: ``` paulson@13363 ` 493` ``` "[| x \ nat; y \ nat; z \ nat |] ==> cartprod_fm(x,y,z) \ formula" ``` paulson@13363 ` 494` ```by (simp add: cartprod_fm_def) ``` paulson@13363 ` 495` paulson@13363 ` 496` ```lemma arity_cartprod_fm [simp]: ``` paulson@13363 ` 497` ``` "[| x \ nat; y \ nat; z \ nat |] ``` paulson@13363 ` 498` ``` ==> arity(cartprod_fm(x,y,z)) = succ(x) \ succ(y) \ succ(z)" ``` paulson@13363 ` 499` ```by (simp add: cartprod_fm_def succ_Un_distrib [symmetric] Un_ac) ``` paulson@13363 ` 500` paulson@13363 ` 501` ```lemma sats_cartprod_fm [simp]: ``` paulson@13363 ` 502` ``` "[| x \ nat; y \ nat; z \ nat; env \ list(A)|] ``` paulson@13363 ` 503` ``` ==> sats(A, cartprod_fm(x,y,z), env) <-> ``` paulson@13363 ` 504` ``` cartprod(**A, nth(x,env), nth(y,env), nth(z,env))" ``` paulson@13363 ` 505` ```by (simp add: cartprod_fm_def cartprod_def) ``` paulson@13363 ` 506` paulson@13363 ` 507` ```lemma cartprod_iff_sats: ``` paulson@13363 ` 508` ``` "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; ``` paulson@13363 ` 509` ``` i \ nat; j \ nat; k \ nat; env \ list(A)|] ``` paulson@13363 ` 510` ``` ==> cartprod(**A, x, y, z) <-> sats(A, cartprod_fm(i,j,k), env)" ``` paulson@13363 ` 511` ```by (simp add: sats_cartprod_fm) ``` paulson@13363 ` 512` paulson@13363 ` 513` ```theorem cartprod_reflection: ``` paulson@13363 ` 514` ``` "REFLECTS[\x. cartprod(L,f(x),g(x),h(x)), ``` paulson@13363 ` 515` ``` \i x. cartprod(**Lset(i),f(x),g(x),h(x))]" ``` paulson@13363 ` 516` ```apply (simp only: cartprod_def setclass_simps) ``` paulson@13363 ` 517` ```apply (intro FOL_reflections pair_reflection) ``` paulson@13363 ` 518` ```done ``` paulson@13363 ` 519` paulson@13363 ` 520` paulson@13363 ` 521` ```subsubsection{*Binary Sums, Internalized*} ``` paulson@13363 ` 522` paulson@13363 ` 523` ```(* "is_sum(M,A,B,Z) == ``` paulson@13363 ` 524` ``` \A0[M]. \n1[M]. \s1[M]. \B1[M]. ``` paulson@13363 ` 525` ``` 3 2 1 0 ``` paulson@13363 ` 526` ``` number1(M,n1) & cartprod(M,n1,A,A0) & upair(M,n1,n1,s1) & ``` paulson@13363 ` 527` ``` cartprod(M,s1,B,B1) & union(M,A0,B1,Z)" *) ``` paulson@13363 ` 528` ```constdefs sum_fm :: "[i,i,i]=>i" ``` paulson@13363 ` 529` ``` "sum_fm(A,B,Z) == ``` paulson@13363 ` 530` ``` Exists(Exists(Exists(Exists( ``` paulson@13363 ` 531` ``` And(number1_fm(2), ``` paulson@13363 ` 532` ``` And(cartprod_fm(2,A#+4,3), ``` paulson@13363 ` 533` ``` And(upair_fm(2,2,1), ``` paulson@13363 ` 534` ``` And(cartprod_fm(1,B#+4,0), union_fm(3,0,Z#+4)))))))))" ``` paulson@13363 ` 535` paulson@13363 ` 536` ```lemma sum_type [TC]: ``` paulson@13363 ` 537` ``` "[| x \ nat; y \ nat; z \ nat |] ==> sum_fm(x,y,z) \ formula" ``` paulson@13363 ` 538` ```by (simp add: sum_fm_def) ``` paulson@13363 ` 539` paulson@13363 ` 540` ```lemma arity_sum_fm [simp]: ``` paulson@13363 ` 541` ``` "[| x \ nat; y \ nat; z \ nat |] ``` paulson@13363 ` 542` ``` ==> arity(sum_fm(x,y,z)) = succ(x) \ succ(y) \ succ(z)" ``` paulson@13363 ` 543` ```by (simp add: sum_fm_def succ_Un_distrib [symmetric] Un_ac) ``` paulson@13363 ` 544` paulson@13363 ` 545` ```lemma sats_sum_fm [simp]: ``` paulson@13363 ` 546` ``` "[| x \ nat; y \ nat; z \ nat; env \ list(A)|] ``` paulson@13363 ` 547` ``` ==> sats(A, sum_fm(x,y,z), env) <-> ``` paulson@13363 ` 548` ``` is_sum(**A, nth(x,env), nth(y,env), nth(z,env))" ``` paulson@13363 ` 549` ```by (simp add: sum_fm_def is_sum_def) ``` paulson@13363 ` 550` paulson@13363 ` 551` ```lemma sum_iff_sats: ``` paulson@13363 ` 552` ``` "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; ``` paulson@13363 ` 553` ``` i \ nat; j \ nat; k \ nat; env \ list(A)|] ``` paulson@13363 ` 554` ``` ==> is_sum(**A, x, y, z) <-> sats(A, sum_fm(i,j,k), env)" ``` paulson@13363 ` 555` ```by simp ``` paulson@13363 ` 556` paulson@13363 ` 557` ```theorem sum_reflection: ``` paulson@13363 ` 558` ``` "REFLECTS[\x. is_sum(L,f(x),g(x),h(x)), ``` paulson@13363 ` 559` ``` \i x. is_sum(**Lset(i),f(x),g(x),h(x))]" ``` paulson@13363 ` 560` ```apply (simp only: is_sum_def setclass_simps) ``` paulson@13363 ` 561` ```apply (intro FOL_reflections function_reflections cartprod_reflection) ``` paulson@13363 ` 562` ```done ``` paulson@13363 ` 563` paulson@13363 ` 564` paulson@13363 ` 565` ```subsubsection{*The Operator @{term quasinat}*} ``` paulson@13363 ` 566` paulson@13363 ` 567` ```(* "is_quasinat(M,z) == empty(M,z) | (\m[M]. successor(M,m,z))" *) ``` paulson@13363 ` 568` ```constdefs quasinat_fm :: "i=>i" ``` paulson@13363 ` 569` ``` "quasinat_fm(z) == Or(empty_fm(z), Exists(succ_fm(0,succ(z))))" ``` paulson@13363 ` 570` paulson@13363 ` 571` ```lemma quasinat_type [TC]: ``` paulson@13363 ` 572` ``` "x \ nat ==> quasinat_fm(x) \ formula" ``` paulson@13363 ` 573` ```by (simp add: quasinat_fm_def) ``` paulson@13363 ` 574` paulson@13363 ` 575` ```lemma arity_quasinat_fm [simp]: ``` paulson@13363 ` 576` ``` "x \ nat ==> arity(quasinat_fm(x)) = succ(x)" ``` paulson@13363 ` 577` ```by (simp add: quasinat_fm_def succ_Un_distrib [symmetric] Un_ac) ``` paulson@13363 ` 578` paulson@13363 ` 579` ```lemma sats_quasinat_fm [simp]: ``` paulson@13363 ` 580` ``` "[| x \ nat; env \ list(A)|] ``` paulson@13363 ` 581` ``` ==> sats(A, quasinat_fm(x), env) <-> is_quasinat(**A, nth(x,env))" ``` paulson@13363 ` 582` ```by (simp add: quasinat_fm_def is_quasinat_def) ``` paulson@13363 ` 583` paulson@13363 ` 584` ```lemma quasinat_iff_sats: ``` paulson@13363 ` 585` ``` "[| nth(i,env) = x; nth(j,env) = y; ``` paulson@13363 ` 586` ``` i \ nat; env \ list(A)|] ``` paulson@13363 ` 587` ``` ==> is_quasinat(**A, x) <-> sats(A, quasinat_fm(i), env)" ``` paulson@13363 ` 588` ```by simp ``` paulson@13363 ` 589` paulson@13363 ` 590` ```theorem quasinat_reflection: ``` paulson@13363 ` 591` ``` "REFLECTS[\x. is_quasinat(L,f(x)), ``` paulson@13363 ` 592` ``` \i x. is_quasinat(**Lset(i),f(x))]" ``` paulson@13363 ` 593` ```apply (simp only: is_quasinat_def setclass_simps) ``` paulson@13363 ` 594` ```apply (intro FOL_reflections function_reflections) ``` paulson@13363 ` 595` ```done ``` paulson@13363 ` 596` paulson@13363 ` 597` paulson@13363 ` 598` ```subsubsection{*The Operator @{term is_nat_case}*} ``` paulson@13363 ` 599` paulson@13363 ` 600` ```(* is_nat_case :: "[i=>o, i, [i,i]=>o, i, i] => o" ``` paulson@13363 ` 601` ``` "is_nat_case(M, a, is_b, k, z) == ``` paulson@13363 ` 602` ``` (empty(M,k) --> z=a) & ``` paulson@13363 ` 603` ``` (\m[M]. successor(M,m,k) --> is_b(m,z)) & ``` paulson@13363 ` 604` ``` (is_quasinat(M,k) | empty(M,z))" *) ``` paulson@13363 ` 605` ```text{*The formula @{term is_b} has free variables 1 and 0.*} ``` paulson@13363 ` 606` ```constdefs is_nat_case_fm :: "[i, [i,i]=>i, i, i]=>i" ``` paulson@13363 ` 607` ``` "is_nat_case_fm(a,is_b,k,z) == ``` paulson@13363 ` 608` ``` And(Implies(empty_fm(k), Equal(z,a)), ``` paulson@13363 ` 609` ``` And(Forall(Implies(succ_fm(0,succ(k)), ``` paulson@13363 ` 610` ``` Forall(Implies(Equal(0,succ(succ(z))), is_b(1,0))))), ``` paulson@13363 ` 611` ``` Or(quasinat_fm(k), empty_fm(z))))" ``` paulson@13363 ` 612` paulson@13363 ` 613` ```lemma is_nat_case_type [TC]: ``` paulson@13363 ` 614` ``` "[| is_b(1,0) \ formula; ``` paulson@13363 ` 615` ``` x \ nat; y \ nat; z \ nat |] ``` paulson@13363 ` 616` ``` ==> is_nat_case_fm(x,is_b,y,z) \ formula" ``` paulson@13363 ` 617` ```by (simp add: is_nat_case_fm_def) ``` paulson@13363 ` 618` paulson@13363 ` 619` ```lemma arity_is_nat_case_fm [simp]: ``` paulson@13363 ` 620` ``` "[| is_b(1,0) \ formula; x \ nat; y \ nat; z \ nat |] ``` paulson@13363 ` 621` ``` ==> arity(is_nat_case_fm(x,is_b,y,z)) = ``` paulson@13363 ` 622` ``` succ(x) \ succ(y) \ succ(z) \ (arity(is_b(1,0)) #- 2)" ``` paulson@13363 ` 623` ```apply (subgoal_tac "arity(is_b(1,0)) \ nat") ``` paulson@13363 ` 624` ```apply typecheck ``` paulson@13363 ` 625` ```(*FIXME: could nat_diff_split work?*) ``` paulson@13363 ` 626` ```apply (auto simp add: diff_def raw_diff_succ is_nat_case_fm_def nat_imp_quasinat ``` paulson@13363 ` 627` ``` succ_Un_distrib [symmetric] Un_ac ``` paulson@13363 ` 628` ``` split: split_nat_case) ``` paulson@13363 ` 629` ```done ``` paulson@13363 ` 630` paulson@13363 ` 631` ```lemma sats_is_nat_case_fm: ``` paulson@13363 ` 632` ``` assumes is_b_iff_sats: ``` paulson@13363 ` 633` ``` "!!a b. [| a \ A; b \ A|] ``` paulson@13363 ` 634` ``` ==> is_b(a,b) <-> sats(A, p(1,0), Cons(b, Cons(a,env)))" ``` paulson@13363 ` 635` ``` shows ``` paulson@13363 ` 636` ``` "[|x \ nat; y \ nat; z < length(env); env \ list(A)|] ``` paulson@13363 ` 637` ``` ==> sats(A, is_nat_case_fm(x,p,y,z), env) <-> ``` paulson@13363 ` 638` ``` is_nat_case(**A, nth(x,env), is_b, nth(y,env), nth(z,env))" ``` paulson@13363 ` 639` ```apply (frule lt_length_in_nat, assumption) ``` paulson@13363 ` 640` ```apply (simp add: is_nat_case_fm_def is_nat_case_def is_b_iff_sats [THEN iff_sym]) ``` paulson@13363 ` 641` ```done ``` paulson@13363 ` 642` paulson@13363 ` 643` ```lemma is_nat_case_iff_sats: ``` paulson@13363 ` 644` ``` "[| (!!a b. [| a \ A; b \ A|] ``` paulson@13363 ` 645` ``` ==> is_b(a,b) <-> sats(A, p(1,0), Cons(b, Cons(a,env)))); ``` paulson@13363 ` 646` ``` nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; ``` paulson@13363 ` 647` ``` i \ nat; j \ nat; k < length(env); env \ list(A)|] ``` paulson@13363 ` 648` ``` ==> is_nat_case(**A, x, is_b, y, z) <-> sats(A, is_nat_case_fm(i,p,j,k), env)" ``` paulson@13363 ` 649` ```by (simp add: sats_is_nat_case_fm [of A is_b]) ``` paulson@13363 ` 650` paulson@13363 ` 651` paulson@13363 ` 652` ```text{*The second argument of @{term is_b} gives it direct access to @{term x}, ``` paulson@13363 ` 653` ``` which is essential for handling free variable references. Without this ``` paulson@13363 ` 654` ``` argument, we cannot prove reflection for @{term iterates_MH}.*} ``` paulson@13363 ` 655` ```theorem is_nat_case_reflection: ``` paulson@13363 ` 656` ``` assumes is_b_reflection: ``` paulson@13363 ` 657` ``` "!!h f g. REFLECTS[\x. is_b(L, h(x), f(x), g(x)), ``` paulson@13363 ` 658` ``` \i x. is_b(**Lset(i), h(x), f(x), g(x))]" ``` paulson@13363 ` 659` ``` shows "REFLECTS[\x. is_nat_case(L, f(x), is_b(L,x), g(x), h(x)), ``` paulson@13363 ` 660` ``` \i x. is_nat_case(**Lset(i), f(x), is_b(**Lset(i), x), g(x), h(x))]" ``` paulson@13363 ` 661` ```apply (simp (no_asm_use) only: is_nat_case_def setclass_simps) ``` paulson@13363 ` 662` ```apply (intro FOL_reflections function_reflections ``` paulson@13363 ` 663` ``` restriction_reflection is_b_reflection quasinat_reflection) ``` paulson@13363 ` 664` ```done ``` paulson@13363 ` 665` paulson@13363 ` 666` paulson@13363 ` 667` paulson@13363 ` 668` ```subsection{*The Operator @{term iterates_MH}, Needed for Iteration*} ``` paulson@13363 ` 669` paulson@13363 ` 670` ```(* iterates_MH :: "[i=>o, [i,i]=>o, i, i, i, i] => o" ``` paulson@13363 ` 671` ``` "iterates_MH(M,isF,v,n,g,z) == ``` paulson@13363 ` 672` ``` is_nat_case(M, v, \m u. \gm[M]. fun_apply(M,g,m,gm) & isF(gm,u), ``` paulson@13363 ` 673` ``` n, z)" *) ``` paulson@13363 ` 674` ```constdefs iterates_MH_fm :: "[[i,i]=>i, i, i, i, i]=>i" ``` paulson@13363 ` 675` ``` "iterates_MH_fm(isF,v,n,g,z) == ``` paulson@13363 ` 676` ``` is_nat_case_fm(v, ``` paulson@13363 ` 677` ``` \m u. Exists(And(fun_apply_fm(succ(succ(succ(g))),succ(m),0), ``` paulson@13363 ` 678` ``` Forall(Implies(Equal(0,succ(succ(u))), isF(1,0))))), ``` paulson@13363 ` 679` ``` n, z)" ``` paulson@13363 ` 680` paulson@13363 ` 681` ```lemma iterates_MH_type [TC]: ``` paulson@13363 ` 682` ``` "[| p(1,0) \ formula; ``` paulson@13363 ` 683` ``` v \ nat; x \ nat; y \ nat; z \ nat |] ``` paulson@13363 ` 684` ``` ==> iterates_MH_fm(p,v,x,y,z) \ formula" ``` paulson@13363 ` 685` ```by (simp add: iterates_MH_fm_def) ``` paulson@13363 ` 686` paulson@13363 ` 687` paulson@13363 ` 688` ```lemma arity_iterates_MH_fm [simp]: ``` paulson@13363 ` 689` ``` "[| p(1,0) \ formula; ``` paulson@13363 ` 690` ``` v \ nat; x \ nat; y \ nat; z \ nat |] ``` paulson@13363 ` 691` ``` ==> arity(iterates_MH_fm(p,v,x,y,z)) = ``` paulson@13363 ` 692` ``` succ(v) \ succ(x) \ succ(y) \ succ(z) \ (arity(p(1,0)) #- 4)" ``` paulson@13363 ` 693` ```apply (subgoal_tac "arity(p(1,0)) \ nat") ``` paulson@13363 ` 694` ```apply typecheck ``` paulson@13363 ` 695` ```apply (simp add: nat_imp_quasinat iterates_MH_fm_def Un_ac ``` paulson@13363 ` 696` ``` split: split_nat_case, clarify) ``` paulson@13363 ` 697` ```apply (rename_tac i j) ``` paulson@13363 ` 698` ```apply (drule eq_succ_imp_eq_m1, simp) ``` paulson@13363 ` 699` ```apply (drule eq_succ_imp_eq_m1, simp) ``` paulson@13363 ` 700` ```apply (simp add: diff_Un_distrib succ_Un_distrib Un_ac diff_diff_left) ``` paulson@13363 ` 701` ```done ``` paulson@13363 ` 702` paulson@13363 ` 703` ```lemma sats_iterates_MH_fm: ``` paulson@13363 ` 704` ``` assumes is_F_iff_sats: ``` paulson@13363 ` 705` ``` "!!a b c d. [| a \ A; b \ A; c \ A; d \ A|] ``` paulson@13363 ` 706` ``` ==> is_F(a,b) <-> ``` paulson@13363 ` 707` ``` sats(A, p(1,0), Cons(b, Cons(a, Cons(c, Cons(d,env)))))" ``` paulson@13363 ` 708` ``` shows ``` paulson@13363 ` 709` ``` "[|v \ nat; x \ nat; y \ nat; z < length(env); env \ list(A)|] ``` paulson@13363 ` 710` ``` ==> sats(A, iterates_MH_fm(p,v,x,y,z), env) <-> ``` paulson@13363 ` 711` ``` iterates_MH(**A, is_F, nth(v,env), nth(x,env), nth(y,env), nth(z,env))" ``` paulson@13363 ` 712` ```by (simp add: iterates_MH_fm_def iterates_MH_def sats_is_nat_case_fm ``` paulson@13363 ` 713` ``` is_F_iff_sats [symmetric]) ``` paulson@13363 ` 714` paulson@13363 ` 715` ```lemma iterates_MH_iff_sats: ``` paulson@13363 ` 716` ``` "[| (!!a b c d. [| a \ A; b \ A; c \ A; d \ A|] ``` paulson@13363 ` 717` ``` ==> is_F(a,b) <-> ``` paulson@13363 ` 718` ``` sats(A, p(1,0), Cons(b, Cons(a, Cons(c, Cons(d,env)))))); ``` paulson@13363 ` 719` ``` nth(i',env) = v; nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; ``` paulson@13363 ` 720` ``` i' \ nat; i \ nat; j \ nat; k < length(env); env \ list(A)|] ``` paulson@13363 ` 721` ``` ==> iterates_MH(**A, is_F, v, x, y, z) <-> ``` paulson@13363 ` 722` ``` sats(A, iterates_MH_fm(p,i',i,j,k), env)" ``` paulson@13363 ` 723` ```apply (rule iff_sym) ``` paulson@13363 ` 724` ```apply (rule iff_trans) ``` paulson@13363 ` 725` ```apply (rule sats_iterates_MH_fm [of A is_F], blast, simp_all) ``` paulson@13363 ` 726` ```done ``` paulson@13363 ` 727` paulson@13363 ` 728` ```theorem iterates_MH_reflection: ``` paulson@13363 ` 729` ``` assumes p_reflection: ``` paulson@13363 ` 730` ``` "!!f g h. REFLECTS[\x. p(L, f(x), g(x)), ``` paulson@13363 ` 731` ``` \i x. p(**Lset(i), f(x), g(x))]" ``` paulson@13363 ` 732` ``` shows "REFLECTS[\x. iterates_MH(L, p(L), e(x), f(x), g(x), h(x)), ``` paulson@13363 ` 733` ``` \i x. iterates_MH(**Lset(i), p(**Lset(i)), e(x), f(x), g(x), h(x))]" ``` paulson@13363 ` 734` ```apply (simp (no_asm_use) only: iterates_MH_def) ``` paulson@13363 ` 735` ```txt{*Must be careful: simplifying with @{text setclass_simps} above would ``` paulson@13363 ` 736` ``` change @{text "\gm[**Lset(i)]"} into @{text "\gm \ Lset(i)"}, when ``` paulson@13363 ` 737` ``` it would no longer match rule @{text is_nat_case_reflection}. *} ``` paulson@13363 ` 738` ```apply (rule is_nat_case_reflection) ``` paulson@13363 ` 739` ```apply (simp (no_asm_use) only: setclass_simps) ``` paulson@13363 ` 740` ```apply (intro FOL_reflections function_reflections is_nat_case_reflection ``` paulson@13363 ` 741` ``` restriction_reflection p_reflection) ``` paulson@13363 ` 742` ```done ``` paulson@13363 ` 743` paulson@13363 ` 744` paulson@13363 ` 745` paulson@13363 ` 746` ```subsection{*@{term L} is Closed Under the Operator @{term list}*} ``` paulson@13363 ` 747` paulson@13386 ` 748` ```subsubsection{*The List Functor, Internalized*} ``` paulson@13386 ` 749` paulson@13386 ` 750` ```constdefs list_functor_fm :: "[i,i,i]=>i" ``` paulson@13386 ` 751` ```(* "is_list_functor(M,A,X,Z) == ``` paulson@13386 ` 752` ``` \n1[M]. \AX[M]. ``` paulson@13386 ` 753` ``` number1(M,n1) & cartprod(M,A,X,AX) & is_sum(M,n1,AX,Z)" *) ``` paulson@13386 ` 754` ``` "list_functor_fm(A,X,Z) == ``` paulson@13386 ` 755` ``` Exists(Exists( ``` paulson@13386 ` 756` ``` And(number1_fm(1), ``` paulson@13386 ` 757` ``` And(cartprod_fm(A#+2,X#+2,0), sum_fm(1,0,Z#+2)))))" ``` paulson@13386 ` 758` paulson@13386 ` 759` ```lemma list_functor_type [TC]: ``` paulson@13386 ` 760` ``` "[| x \ nat; y \ nat; z \ nat |] ==> list_functor_fm(x,y,z) \ formula" ``` paulson@13386 ` 761` ```by (simp add: list_functor_fm_def) ``` paulson@13386 ` 762` paulson@13386 ` 763` ```lemma arity_list_functor_fm [simp]: ``` paulson@13386 ` 764` ``` "[| x \ nat; y \ nat; z \ nat |] ``` paulson@13386 ` 765` ``` ==> arity(list_functor_fm(x,y,z)) = succ(x) \ succ(y) \ succ(z)" ``` paulson@13386 ` 766` ```by (simp add: list_functor_fm_def succ_Un_distrib [symmetric] Un_ac) ``` paulson@13386 ` 767` paulson@13386 ` 768` ```lemma sats_list_functor_fm [simp]: ``` paulson@13386 ` 769` ``` "[| x \ nat; y \ nat; z \ nat; env \ list(A)|] ``` paulson@13386 ` 770` ``` ==> sats(A, list_functor_fm(x,y,z), env) <-> ``` paulson@13386 ` 771` ``` is_list_functor(**A, nth(x,env), nth(y,env), nth(z,env))" ``` paulson@13386 ` 772` ```by (simp add: list_functor_fm_def is_list_functor_def) ``` paulson@13386 ` 773` paulson@13386 ` 774` ```lemma list_functor_iff_sats: ``` paulson@13386 ` 775` ``` "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; ``` paulson@13386 ` 776` ``` i \ nat; j \ nat; k \ nat; env \ list(A)|] ``` paulson@13386 ` 777` ``` ==> is_list_functor(**A, x, y, z) <-> sats(A, list_functor_fm(i,j,k), env)" ``` paulson@13386 ` 778` ```by simp ``` paulson@13386 ` 779` paulson@13386 ` 780` ```theorem list_functor_reflection: ``` paulson@13386 ` 781` ``` "REFLECTS[\x. is_list_functor(L,f(x),g(x),h(x)), ``` paulson@13386 ` 782` ``` \i x. is_list_functor(**Lset(i),f(x),g(x),h(x))]" ``` paulson@13386 ` 783` ```apply (simp only: is_list_functor_def setclass_simps) ``` paulson@13386 ` 784` ```apply (intro FOL_reflections number1_reflection ``` paulson@13386 ` 785` ``` cartprod_reflection sum_reflection) ``` paulson@13386 ` 786` ```done ``` paulson@13386 ` 787` paulson@13386 ` 788` paulson@13386 ` 789` ```subsubsection{*Instances of Replacement for Lists*} ``` paulson@13386 ` 790` paulson@13363 ` 791` ```lemma list_replacement1_Reflects: ``` paulson@13363 ` 792` ``` "REFLECTS ``` paulson@13363 ` 793` ``` [\x. \u[L]. u \ B \ (\y[L]. pair(L,u,y,x) \ ``` paulson@13363 ` 794` ``` is_wfrec(L, iterates_MH(L, is_list_functor(L,A), 0), memsn, u, y)), ``` paulson@13363 ` 795` ``` \i x. \u \ Lset(i). u \ B \ (\y \ Lset(i). pair(**Lset(i), u, y, x) \ ``` paulson@13363 ` 796` ``` is_wfrec(**Lset(i), ``` paulson@13363 ` 797` ``` iterates_MH(**Lset(i), ``` paulson@13363 ` 798` ``` is_list_functor(**Lset(i), A), 0), memsn, u, y))]" ``` paulson@13363 ` 799` ```by (intro FOL_reflections function_reflections is_wfrec_reflection ``` paulson@13363 ` 800` ``` iterates_MH_reflection list_functor_reflection) ``` paulson@13363 ` 801` paulson@13363 ` 802` ```lemma list_replacement1: ``` paulson@13363 ` 803` ``` "L(A) ==> iterates_replacement(L, is_list_functor(L,A), 0)" ``` paulson@13363 ` 804` ```apply (unfold iterates_replacement_def wfrec_replacement_def, clarify) ``` paulson@13363 ` 805` ```apply (rule strong_replacementI) ``` paulson@13363 ` 806` ```apply (rule rallI) ``` paulson@13363 ` 807` ```apply (rename_tac B) ``` paulson@13363 ` 808` ```apply (rule separation_CollectI) ``` paulson@13363 ` 809` ```apply (insert nonempty) ``` paulson@13363 ` 810` ```apply (subgoal_tac "L(Memrel(succ(n)))") ``` paulson@13363 ` 811` ```apply (rule_tac A="{B,A,n,z,0,Memrel(succ(n))}" in subset_LsetE, blast ) ``` paulson@13363 ` 812` ```apply (rule ReflectsE [OF list_replacement1_Reflects], assumption) ``` paulson@13363 ` 813` ```apply (drule subset_Lset_ltD, assumption) ``` paulson@13363 ` 814` ```apply (erule reflection_imp_L_separation) ``` paulson@13386 ` 815` ``` apply (simp_all add: lt_Ord2 Memrel_closed) ``` paulson@13386 ` 816` ```apply (elim conjE) ``` paulson@13385 ` 817` ```apply (rule DPow_LsetI) ``` paulson@13363 ` 818` ```apply (rename_tac v) ``` paulson@13363 ` 819` ```apply (rule bex_iff_sats conj_iff_sats)+ ``` paulson@13363 ` 820` ```apply (rule_tac env = "[u,v,A,n,B,0,Memrel(succ(n))]" in mem_iff_sats) ``` paulson@13363 ` 821` ```apply (rule sep_rules | simp)+ ``` paulson@13363 ` 822` ```txt{*Can't get sat rules to work for higher-order operators, so just expand them!*} ``` paulson@13363 ` 823` ```apply (simp add: is_wfrec_def M_is_recfun_def iterates_MH_def is_nat_case_def) ``` paulson@13363 ` 824` ```apply (rule sep_rules list_functor_iff_sats quasinat_iff_sats | simp)+ ``` paulson@13363 ` 825` ```done ``` paulson@13363 ` 826` paulson@13363 ` 827` paulson@13363 ` 828` ```lemma list_replacement2_Reflects: ``` paulson@13363 ` 829` ``` "REFLECTS ``` paulson@13363 ` 830` ``` [\x. \u[L]. u \ B \ u \ nat \ ``` paulson@13363 ` 831` ``` (\sn[L]. \msn[L]. successor(L, u, sn) \ membership(L, sn, msn) \ ``` paulson@13363 ` 832` ``` is_wfrec (L, iterates_MH (L, is_list_functor(L, A), 0), ``` paulson@13363 ` 833` ``` msn, u, x)), ``` paulson@13363 ` 834` ``` \i x. \u \ Lset(i). u \ B \ u \ nat \ ``` paulson@13363 ` 835` ``` (\sn \ Lset(i). \msn \ Lset(i). ``` paulson@13363 ` 836` ``` successor(**Lset(i), u, sn) \ membership(**Lset(i), sn, msn) \ ``` paulson@13363 ` 837` ``` is_wfrec (**Lset(i), ``` paulson@13363 ` 838` ``` iterates_MH (**Lset(i), is_list_functor(**Lset(i), A), 0), ``` paulson@13363 ` 839` ``` msn, u, x))]" ``` paulson@13363 ` 840` ```by (intro FOL_reflections function_reflections is_wfrec_reflection ``` paulson@13363 ` 841` ``` iterates_MH_reflection list_functor_reflection) ``` paulson@13363 ` 842` paulson@13363 ` 843` paulson@13363 ` 844` ```lemma list_replacement2: ``` paulson@13363 ` 845` ``` "L(A) ==> strong_replacement(L, ``` paulson@13363 ` 846` ``` \n y. n\nat & ``` paulson@13363 ` 847` ``` (\sn[L]. \msn[L]. successor(L,n,sn) & membership(L,sn,msn) & ``` paulson@13363 ` 848` ``` is_wfrec(L, iterates_MH(L,is_list_functor(L,A), 0), ``` paulson@13363 ` 849` ``` msn, n, y)))" ``` paulson@13363 ` 850` ```apply (rule strong_replacementI) ``` paulson@13363 ` 851` ```apply (rule rallI) ``` paulson@13363 ` 852` ```apply (rename_tac B) ``` paulson@13363 ` 853` ```apply (rule separation_CollectI) ``` paulson@13363 ` 854` ```apply (insert nonempty) ``` paulson@13363 ` 855` ```apply (rule_tac A="{A,B,z,0,nat}" in subset_LsetE) ``` paulson@13363 ` 856` ```apply (blast intro: L_nat) ``` paulson@13363 ` 857` ```apply (rule ReflectsE [OF list_replacement2_Reflects], assumption) ``` paulson@13363 ` 858` ```apply (drule subset_Lset_ltD, assumption) ``` paulson@13363 ` 859` ```apply (erule reflection_imp_L_separation) ``` paulson@13363 ` 860` ``` apply (simp_all add: lt_Ord2) ``` paulson@13385 ` 861` ```apply (rule DPow_LsetI) ``` paulson@13363 ` 862` ```apply (rename_tac v) ``` paulson@13363 ` 863` ```apply (rule bex_iff_sats conj_iff_sats)+ ``` paulson@13363 ` 864` ```apply (rule_tac env = "[u,v,A,B,0,nat]" in mem_iff_sats) ``` paulson@13363 ` 865` ```apply (rule sep_rules | simp)+ ``` paulson@13363 ` 866` ```apply (simp add: is_wfrec_def M_is_recfun_def iterates_MH_def is_nat_case_def) ``` paulson@13363 ` 867` ```apply (rule sep_rules list_functor_iff_sats quasinat_iff_sats | simp)+ ``` paulson@13363 ` 868` ```done ``` paulson@13363 ` 869` paulson@13386 ` 870` paulson@13386 ` 871` ```subsection{*@{term L} is Closed Under the Operator @{term formula}*} ``` paulson@13386 ` 872` paulson@13386 ` 873` ```subsubsection{*The Formula Functor, Internalized*} ``` paulson@13386 ` 874` paulson@13386 ` 875` ```constdefs formula_functor_fm :: "[i,i]=>i" ``` paulson@13386 ` 876` ```(* "is_formula_functor(M,X,Z) == ``` paulson@13398 ` 877` ``` \nat'[M]. \natnat[M]. \natnatsum[M]. \XX[M]. \X3[M]. ``` paulson@13398 ` 878` ``` 4 3 2 1 0 ``` paulson@13386 ` 879` ``` omega(M,nat') & cartprod(M,nat',nat',natnat) & ``` paulson@13386 ` 880` ``` is_sum(M,natnat,natnat,natnatsum) & ``` paulson@13398 ` 881` ``` cartprod(M,X,X,XX) & is_sum(M,XX,X,X3) & ``` paulson@13398 ` 882` ``` is_sum(M,natnatsum,X3,Z)" *) ``` paulson@13386 ` 883` ``` "formula_functor_fm(X,Z) == ``` paulson@13398 ` 884` ``` Exists(Exists(Exists(Exists(Exists( ``` paulson@13398 ` 885` ``` And(omega_fm(4), ``` paulson@13398 ` 886` ``` And(cartprod_fm(4,4,3), ``` paulson@13398 ` 887` ``` And(sum_fm(3,3,2), ``` paulson@13398 ` 888` ``` And(cartprod_fm(X#+5,X#+5,1), ``` paulson@13398 ` 889` ``` And(sum_fm(1,X#+5,0), sum_fm(2,0,Z#+5)))))))))))" ``` paulson@13386 ` 890` paulson@13386 ` 891` ```lemma formula_functor_type [TC]: ``` paulson@13386 ` 892` ``` "[| x \ nat; y \ nat |] ==> formula_functor_fm(x,y) \ formula" ``` paulson@13386 ` 893` ```by (simp add: formula_functor_fm_def) ``` paulson@13386 ` 894` paulson@13386 ` 895` ```lemma sats_formula_functor_fm [simp]: ``` paulson@13386 ` 896` ``` "[| x \ nat; y \ nat; env \ list(A)|] ``` paulson@13386 ` 897` ``` ==> sats(A, formula_functor_fm(x,y), env) <-> ``` paulson@13386 ` 898` ``` is_formula_functor(**A, nth(x,env), nth(y,env))" ``` paulson@13386 ` 899` ```by (simp add: formula_functor_fm_def is_formula_functor_def) ``` paulson@13386 ` 900` paulson@13386 ` 901` ```lemma formula_functor_iff_sats: ``` paulson@13386 ` 902` ``` "[| nth(i,env) = x; nth(j,env) = y; ``` paulson@13386 ` 903` ``` i \ nat; j \ nat; env \ list(A)|] ``` paulson@13386 ` 904` ``` ==> is_formula_functor(**A, x, y) <-> sats(A, formula_functor_fm(i,j), env)" ``` paulson@13386 ` 905` ```by simp ``` paulson@13386 ` 906` paulson@13386 ` 907` ```theorem formula_functor_reflection: ``` paulson@13386 ` 908` ``` "REFLECTS[\x. is_formula_functor(L,f(x),g(x)), ``` paulson@13386 ` 909` ``` \i x. is_formula_functor(**Lset(i),f(x),g(x))]" ``` paulson@13386 ` 910` ```apply (simp only: is_formula_functor_def setclass_simps) ``` paulson@13386 ` 911` ```apply (intro FOL_reflections omega_reflection ``` paulson@13386 ` 912` ``` cartprod_reflection sum_reflection) ``` paulson@13386 ` 913` ```done ``` paulson@13386 ` 914` paulson@13386 ` 915` ```subsubsection{*Instances of Replacement for Formulas*} ``` paulson@13386 ` 916` paulson@13386 ` 917` ```lemma formula_replacement1_Reflects: ``` paulson@13386 ` 918` ``` "REFLECTS ``` paulson@13386 ` 919` ``` [\x. \u[L]. u \ B \ (\y[L]. pair(L,u,y,x) \ ``` paulson@13386 ` 920` ``` is_wfrec(L, iterates_MH(L, is_formula_functor(L), 0), memsn, u, y)), ``` paulson@13386 ` 921` ``` \i x. \u \ Lset(i). u \ B \ (\y \ Lset(i). pair(**Lset(i), u, y, x) \ ``` paulson@13386 ` 922` ``` is_wfrec(**Lset(i), ``` paulson@13386 ` 923` ``` iterates_MH(**Lset(i), ``` paulson@13386 ` 924` ``` is_formula_functor(**Lset(i)), 0), memsn, u, y))]" ``` paulson@13386 ` 925` ```by (intro FOL_reflections function_reflections is_wfrec_reflection ``` paulson@13386 ` 926` ``` iterates_MH_reflection formula_functor_reflection) ``` paulson@13386 ` 927` paulson@13386 ` 928` ```lemma formula_replacement1: ``` paulson@13386 ` 929` ``` "iterates_replacement(L, is_formula_functor(L), 0)" ``` paulson@13386 ` 930` ```apply (unfold iterates_replacement_def wfrec_replacement_def, clarify) ``` paulson@13386 ` 931` ```apply (rule strong_replacementI) ``` paulson@13386 ` 932` ```apply (rule rallI) ``` paulson@13386 ` 933` ```apply (rename_tac B) ``` paulson@13386 ` 934` ```apply (rule separation_CollectI) ``` paulson@13386 ` 935` ```apply (insert nonempty) ``` paulson@13386 ` 936` ```apply (subgoal_tac "L(Memrel(succ(n)))") ``` paulson@13386 ` 937` ```apply (rule_tac A="{B,n,z,0,Memrel(succ(n))}" in subset_LsetE, blast ) ``` paulson@13386 ` 938` ```apply (rule ReflectsE [OF formula_replacement1_Reflects], assumption) ``` paulson@13386 ` 939` ```apply (drule subset_Lset_ltD, assumption) ``` paulson@13386 ` 940` ```apply (erule reflection_imp_L_separation) ``` paulson@13386 ` 941` ``` apply (simp_all add: lt_Ord2 Memrel_closed) ``` paulson@13386 ` 942` ```apply (rule DPow_LsetI) ``` paulson@13386 ` 943` ```apply (rename_tac v) ``` paulson@13386 ` 944` ```apply (rule bex_iff_sats conj_iff_sats)+ ``` paulson@13386 ` 945` ```apply (rule_tac env = "[u,v,n,B,0,Memrel(succ(n))]" in mem_iff_sats) ``` paulson@13386 ` 946` ```apply (rule sep_rules | simp)+ ``` paulson@13386 ` 947` ```txt{*Can't get sat rules to work for higher-order operators, so just expand them!*} ``` paulson@13386 ` 948` ```apply (simp add: is_wfrec_def M_is_recfun_def iterates_MH_def is_nat_case_def) ``` paulson@13386 ` 949` ```apply (rule sep_rules formula_functor_iff_sats quasinat_iff_sats | simp)+ ``` paulson@13386 ` 950` ```txt{*SLOW: like 40 seconds!*} ``` paulson@13386 ` 951` ```done ``` paulson@13386 ` 952` paulson@13386 ` 953` ```lemma formula_replacement2_Reflects: ``` paulson@13386 ` 954` ``` "REFLECTS ``` paulson@13386 ` 955` ``` [\x. \u[L]. u \ B \ u \ nat \ ``` paulson@13386 ` 956` ``` (\sn[L]. \msn[L]. successor(L, u, sn) \ membership(L, sn, msn) \ ``` paulson@13386 ` 957` ``` is_wfrec (L, iterates_MH (L, is_formula_functor(L), 0), ``` paulson@13386 ` 958` ``` msn, u, x)), ``` paulson@13386 ` 959` ``` \i x. \u \ Lset(i). u \ B \ u \ nat \ ``` paulson@13386 ` 960` ``` (\sn \ Lset(i). \msn \ Lset(i). ``` paulson@13386 ` 961` ``` successor(**Lset(i), u, sn) \ membership(**Lset(i), sn, msn) \ ``` paulson@13386 ` 962` ``` is_wfrec (**Lset(i), ``` paulson@13386 ` 963` ``` iterates_MH (**Lset(i), is_formula_functor(**Lset(i)), 0), ``` paulson@13386 ` 964` ``` msn, u, x))]" ``` paulson@13386 ` 965` ```by (intro FOL_reflections function_reflections is_wfrec_reflection ``` paulson@13386 ` 966` ``` iterates_MH_reflection formula_functor_reflection) ``` paulson@13386 ` 967` paulson@13386 ` 968` paulson@13386 ` 969` ```lemma formula_replacement2: ``` paulson@13386 ` 970` ``` "strong_replacement(L, ``` paulson@13386 ` 971` ``` \n y. n\nat & ``` paulson@13386 ` 972` ``` (\sn[L]. \msn[L]. successor(L,n,sn) & membership(L,sn,msn) & ``` paulson@13386 ` 973` ``` is_wfrec(L, iterates_MH(L,is_formula_functor(L), 0), ``` paulson@13386 ` 974` ``` msn, n, y)))" ``` paulson@13386 ` 975` ```apply (rule strong_replacementI) ``` paulson@13386 ` 976` ```apply (rule rallI) ``` paulson@13386 ` 977` ```apply (rename_tac B) ``` paulson@13386 ` 978` ```apply (rule separation_CollectI) ``` paulson@13386 ` 979` ```apply (insert nonempty) ``` paulson@13386 ` 980` ```apply (rule_tac A="{B,z,0,nat}" in subset_LsetE) ``` paulson@13386 ` 981` ```apply (blast intro: L_nat) ``` paulson@13386 ` 982` ```apply (rule ReflectsE [OF formula_replacement2_Reflects], assumption) ``` paulson@13386 ` 983` ```apply (drule subset_Lset_ltD, assumption) ``` paulson@13386 ` 984` ```apply (erule reflection_imp_L_separation) ``` paulson@13386 ` 985` ``` apply (simp_all add: lt_Ord2) ``` paulson@13386 ` 986` ```apply (rule DPow_LsetI) ``` paulson@13386 ` 987` ```apply (rename_tac v) ``` paulson@13386 ` 988` ```apply (rule bex_iff_sats conj_iff_sats)+ ``` paulson@13386 ` 989` ```apply (rule_tac env = "[u,v,B,0,nat]" in mem_iff_sats) ``` paulson@13386 ` 990` ```apply (rule sep_rules | simp)+ ``` paulson@13386 ` 991` ```apply (simp add: is_wfrec_def M_is_recfun_def iterates_MH_def is_nat_case_def) ``` paulson@13386 ` 992` ```apply (rule sep_rules formula_functor_iff_sats quasinat_iff_sats | simp)+ ``` paulson@13386 ` 993` ```done ``` paulson@13386 ` 994` paulson@13386 ` 995` ```text{*NB The proofs for type @{term formula} are virtually identical to those ``` paulson@13386 ` 996` ```for @{term "list(A)"}. It was a cut-and-paste job! *} ``` paulson@13386 ` 997` paulson@13387 ` 998` paulson@13387 ` 999` ```subsubsection{*Instantiating the locale @{text M_datatypes}*} ``` paulson@13387 ` 1000` ```ML ``` paulson@13387 ` 1001` ```{* ``` paulson@13387 ` 1002` ```val list_replacement1 = thm "list_replacement1"; ``` paulson@13387 ` 1003` ```val list_replacement2 = thm "list_replacement2"; ``` paulson@13387 ` 1004` ```val formula_replacement1 = thm "formula_replacement1"; ``` paulson@13387 ` 1005` ```val formula_replacement2 = thm "formula_replacement2"; ``` paulson@13387 ` 1006` paulson@13387 ` 1007` ```val m_datatypes = [list_replacement1, list_replacement2, ``` paulson@13387 ` 1008` ``` formula_replacement1, formula_replacement2]; ``` paulson@13387 ` 1009` paulson@13387 ` 1010` ```fun datatypes_L th = ``` paulson@13387 ` 1011` ``` kill_flex_triv_prems (m_datatypes MRS (wfrank_L th)); ``` paulson@13387 ` 1012` paulson@13387 ` 1013` ```bind_thm ("list_closed", datatypes_L (thm "M_datatypes.list_closed")); ``` paulson@13387 ` 1014` ```bind_thm ("formula_closed", datatypes_L (thm "M_datatypes.formula_closed")); ``` paulson@13395 ` 1015` ```bind_thm ("list_abs", datatypes_L (thm "M_datatypes.list_abs")); ``` paulson@13395 ` 1016` ```bind_thm ("formula_abs", datatypes_L (thm "M_datatypes.formula_abs")); ``` paulson@13387 ` 1017` ```*} ``` paulson@13387 ` 1018` paulson@13387 ` 1019` ```declare list_closed [intro,simp] ``` paulson@13387 ` 1020` ```declare formula_closed [intro,simp] ``` paulson@13395 ` 1021` ```declare list_abs [intro,simp] ``` paulson@13395 ` 1022` ```declare formula_abs [intro,simp] ``` paulson@13395 ` 1023` paulson@13395 ` 1024` paulson@13395 ` 1025` paulson@13395 ` 1026` ```subsection{*@{term L} is Closed Under the Operator @{term eclose}*} ``` paulson@13395 ` 1027` paulson@13395 ` 1028` ```subsubsection{*Instances of Replacement for @{term eclose}*} ``` paulson@13395 ` 1029` paulson@13395 ` 1030` ```lemma eclose_replacement1_Reflects: ``` paulson@13395 ` 1031` ``` "REFLECTS ``` paulson@13395 ` 1032` ``` [\x. \u[L]. u \ B \ (\y[L]. pair(L,u,y,x) \ ``` paulson@13395 ` 1033` ``` is_wfrec(L, iterates_MH(L, big_union(L), A), memsn, u, y)), ``` paulson@13395 ` 1034` ``` \i x. \u \ Lset(i). u \ B \ (\y \ Lset(i). pair(**Lset(i), u, y, x) \ ``` paulson@13395 ` 1035` ``` is_wfrec(**Lset(i), ``` paulson@13395 ` 1036` ``` iterates_MH(**Lset(i), big_union(**Lset(i)), A), ``` paulson@13395 ` 1037` ``` memsn, u, y))]" ``` paulson@13395 ` 1038` ```by (intro FOL_reflections function_reflections is_wfrec_reflection ``` paulson@13395 ` 1039` ``` iterates_MH_reflection) ``` paulson@13395 ` 1040` paulson@13395 ` 1041` ```lemma eclose_replacement1: ``` paulson@13395 ` 1042` ``` "L(A) ==> iterates_replacement(L, big_union(L), A)" ``` paulson@13395 ` 1043` ```apply (unfold iterates_replacement_def wfrec_replacement_def, clarify) ``` paulson@13395 ` 1044` ```apply (rule strong_replacementI) ``` paulson@13395 ` 1045` ```apply (rule rallI) ``` paulson@13395 ` 1046` ```apply (rename_tac B) ``` paulson@13395 ` 1047` ```apply (rule separation_CollectI) ``` paulson@13395 ` 1048` ```apply (subgoal_tac "L(Memrel(succ(n)))") ``` paulson@13395 ` 1049` ```apply (rule_tac A="{B,A,n,z,Memrel(succ(n))}" in subset_LsetE, blast ) ``` paulson@13395 ` 1050` ```apply (rule ReflectsE [OF eclose_replacement1_Reflects], assumption) ``` paulson@13395 ` 1051` ```apply (drule subset_Lset_ltD, assumption) ``` paulson@13395 ` 1052` ```apply (erule reflection_imp_L_separation) ``` paulson@13395 ` 1053` ``` apply (simp_all add: lt_Ord2 Memrel_closed) ``` paulson@13395 ` 1054` ```apply (elim conjE) ``` paulson@13395 ` 1055` ```apply (rule DPow_LsetI) ``` paulson@13395 ` 1056` ```apply (rename_tac v) ``` paulson@13395 ` 1057` ```apply (rule bex_iff_sats conj_iff_sats)+ ``` paulson@13395 ` 1058` ```apply (rule_tac env = "[u,v,A,n,B,Memrel(succ(n))]" in mem_iff_sats) ``` paulson@13395 ` 1059` ```apply (rule sep_rules | simp)+ ``` paulson@13395 ` 1060` ```txt{*Can't get sat rules to work for higher-order operators, so just expand them!*} ``` paulson@13395 ` 1061` ```apply (simp add: is_wfrec_def M_is_recfun_def iterates_MH_def is_nat_case_def) ``` paulson@13395 ` 1062` ```apply (rule sep_rules big_union_iff_sats quasinat_iff_sats | simp)+ ``` paulson@13395 ` 1063` ```done ``` paulson@13395 ` 1064` paulson@13395 ` 1065` paulson@13395 ` 1066` ```lemma eclose_replacement2_Reflects: ``` paulson@13395 ` 1067` ``` "REFLECTS ``` paulson@13395 ` 1068` ``` [\x. \u[L]. u \ B \ u \ nat \ ``` paulson@13395 ` 1069` ``` (\sn[L]. \msn[L]. successor(L, u, sn) \ membership(L, sn, msn) \ ``` paulson@13395 ` 1070` ``` is_wfrec (L, iterates_MH (L, big_union(L), A), ``` paulson@13395 ` 1071` ``` msn, u, x)), ``` paulson@13395 ` 1072` ``` \i x. \u \ Lset(i). u \ B \ u \ nat \ ``` paulson@13395 ` 1073` ``` (\sn \ Lset(i). \msn \ Lset(i). ``` paulson@13395 ` 1074` ``` successor(**Lset(i), u, sn) \ membership(**Lset(i), sn, msn) \ ``` paulson@13395 ` 1075` ``` is_wfrec (**Lset(i), ``` paulson@13395 ` 1076` ``` iterates_MH (**Lset(i), big_union(**Lset(i)), A), ``` paulson@13395 ` 1077` ``` msn, u, x))]" ``` paulson@13395 ` 1078` ```by (intro FOL_reflections function_reflections is_wfrec_reflection ``` paulson@13395 ` 1079` ``` iterates_MH_reflection) ``` paulson@13395 ` 1080` paulson@13395 ` 1081` paulson@13395 ` 1082` ```lemma eclose_replacement2: ``` paulson@13395 ` 1083` ``` "L(A) ==> strong_replacement(L, ``` paulson@13395 ` 1084` ``` \n y. n\nat & ``` paulson@13395 ` 1085` ``` (\sn[L]. \msn[L]. successor(L,n,sn) & membership(L,sn,msn) & ``` paulson@13395 ` 1086` ``` is_wfrec(L, iterates_MH(L,big_union(L), A), ``` paulson@13395 ` 1087` ``` msn, n, y)))" ``` paulson@13395 ` 1088` ```apply (rule strong_replacementI) ``` paulson@13395 ` 1089` ```apply (rule rallI) ``` paulson@13395 ` 1090` ```apply (rename_tac B) ``` paulson@13395 ` 1091` ```apply (rule separation_CollectI) ``` paulson@13395 ` 1092` ```apply (rule_tac A="{A,B,z,nat}" in subset_LsetE) ``` paulson@13395 ` 1093` ```apply (blast intro: L_nat) ``` paulson@13395 ` 1094` ```apply (rule ReflectsE [OF eclose_replacement2_Reflects], assumption) ``` paulson@13395 ` 1095` ```apply (drule subset_Lset_ltD, assumption) ``` paulson@13395 ` 1096` ```apply (erule reflection_imp_L_separation) ``` paulson@13395 ` 1097` ``` apply (simp_all add: lt_Ord2) ``` paulson@13395 ` 1098` ```apply (rule DPow_LsetI) ``` paulson@13395 ` 1099` ```apply (rename_tac v) ``` paulson@13395 ` 1100` ```apply (rule bex_iff_sats conj_iff_sats)+ ``` paulson@13395 ` 1101` ```apply (rule_tac env = "[u,v,A,B,nat]" in mem_iff_sats) ``` paulson@13395 ` 1102` ```apply (rule sep_rules | simp)+ ``` paulson@13395 ` 1103` ```apply (simp add: is_wfrec_def M_is_recfun_def iterates_MH_def is_nat_case_def) ``` paulson@13395 ` 1104` ```apply (rule sep_rules big_union_iff_sats quasinat_iff_sats | simp)+ ``` paulson@13395 ` 1105` ```done ``` paulson@13395 ` 1106` paulson@13395 ` 1107` paulson@13395 ` 1108` ```subsubsection{*Instantiating the locale @{text M_eclose}*} ``` paulson@13395 ` 1109` ```ML ``` paulson@13395 ` 1110` ```{* ``` paulson@13395 ` 1111` ```val eclose_replacement1 = thm "eclose_replacement1"; ``` paulson@13395 ` 1112` ```val eclose_replacement2 = thm "eclose_replacement2"; ``` paulson@13395 ` 1113` paulson@13395 ` 1114` ```val m_eclose = [eclose_replacement1, eclose_replacement2]; ``` paulson@13395 ` 1115` paulson@13395 ` 1116` ```fun eclose_L th = ``` paulson@13395 ` 1117` ``` kill_flex_triv_prems (m_eclose MRS (wfrank_L th)); ``` paulson@13395 ` 1118` paulson@13395 ` 1119` ```bind_thm ("eclose_closed", eclose_L (thm "M_eclose.eclose_closed")); ``` paulson@13395 ` 1120` ```bind_thm ("eclose_abs", eclose_L (thm "M_eclose.eclose_abs")); ``` paulson@13395 ` 1121` ```*} ``` paulson@13395 ` 1122` paulson@13395 ` 1123` ```declare eclose_closed [intro,simp] ``` paulson@13395 ` 1124` ```declare eclose_abs [intro,simp] ``` paulson@13395 ` 1125` paulson@13395 ` 1126` paulson@13395 ` 1127` paulson@13387 ` 1128` paulson@13348 ` 1129` ```end ```