lcp@515: (* Title: ZF/ex/CoUnit.ML lcp@365: ID: \$Id\$ lcp@365: Author: Lawrence C Paulson, Cambridge University Computer Laboratory lcp@515: Copyright 1994 University of Cambridge lcp@365: lcp@365: Trivial codatatype definitions, one of which goes wrong! lcp@365: lcp@515: See discussion in lcp@515: L C Paulson. A Concrete Final Coalgebra Theorem for ZF Set Theory. lcp@515: Report 334, Cambridge University Computer Laboratory. 1994. lcp@365: *) lcp@365: lcp@515: open CoUnit; lcp@365: lcp@365: (*USELESS because folding on Con(?xa) == ?xa fails*) lcp@515: val ConE = counit.mk_cases counit.con_defs "Con(x) : counit"; lcp@365: lcp@365: (*Proving freeness results*) lcp@515: val Con_iff = counit.mk_free "Con(x)=Con(y) <-> x=y"; lcp@365: lcp@365: (*Should be a singleton, not everything!*) lcp@365: goal CoUnit.thy "counit = quniv(0)"; lcp@515: by (rtac (counit.dom_subset RS equalityI) 1); lcp@365: by (rtac subsetI 1); lcp@515: by (etac counit.coinduct 1); lcp@365: by (rtac subset_refl 1); lcp@515: by (rewrite_goals_tac counit.con_defs); lcp@365: by (fast_tac ZF_cs 1); lcp@365: val counit_eq_univ = result(); lcp@365: lcp@365: lcp@365: (*A similar example, but the constructor is non-degenerate and it works! lcp@365: The resulting set is a singleton. lcp@365: *) lcp@365: lcp@515: val Con2E = counit2.mk_cases counit2.con_defs "Con2(x,y) : counit2"; lcp@365: lcp@365: (*Proving freeness results*) lcp@515: val Con2_iff = counit2.mk_free "Con2(x,y)=Con2(x',y') <-> x=x' & y=y'"; lcp@365: lcp@515: goalw CoUnit.thy counit2.con_defs "bnd_mono(univ(0), %x. Con2(x,x))"; lcp@365: by (rtac bnd_monoI 1); lcp@365: by (REPEAT (ares_tac [subset_refl, QPair_subset_univ, QPair_mono] 1)); lcp@365: val Con2_bnd_mono = result(); lcp@365: lcp@515: goal CoUnit.thy "lfp(univ(0), %x. Con2(x,x)) : counit2"; lcp@515: by (rtac (singletonI RS counit2.coinduct) 1); lcp@365: by (rtac (qunivI RS singleton_subsetI) 1); lcp@365: by (rtac ([lfp_subset, empty_subsetI RS univ_mono] MRS subset_trans) 1); lcp@365: by (fast_tac (ZF_cs addSIs [Con2_bnd_mono RS lfp_Tarski]) 1); lcp@365: val lfp_Con2_in_counit2 = result(); lcp@365: lcp@365: (*Lemma for proving finality. Borrowed from ex/llist_eq.ML!*) lcp@515: goal CoUnit.thy lcp@365: "!!i. Ord(i) ==> ALL x y. x: counit2 & y: counit2 --> x Int Vset(i) <= y"; lcp@365: by (etac trans_induct 1); lcp@365: by (safe_tac subset_cs); lcp@515: by (etac counit2.elim 1); lcp@515: by (etac counit2.elim 1); lcp@515: by (rewrite_goals_tac counit2.con_defs); lcp@527: val lleq_cs = subset_cs lcp@527: addSIs [QPair_Int_Vset_subset_UN RS subset_trans, QPair_mono] lcp@527: addSEs [Ord_in_Ord, Pair_inject]; lcp@365: by (fast_tac lleq_cs 1); lcp@365: val counit2_Int_Vset_subset_lemma = result(); lcp@365: lcp@365: val counit2_Int_Vset_subset = standard lcp@365: (counit2_Int_Vset_subset_lemma RS spec RS spec RS mp); lcp@365: lcp@515: goal CoUnit.thy "!!x y. [| x: counit2; y: counit2 |] ==> x=y"; lcp@365: by (rtac equalityI 1); lcp@365: by (REPEAT (ares_tac [conjI, counit2_Int_Vset_subset RS Int_Vset_subset] 1)); lcp@365: val counit2_implies_equal = result(); lcp@365: lcp@515: goal CoUnit.thy "counit2 = {lfp(univ(0), %x. Con2(x,x))}"; lcp@365: by (rtac equalityI 1); lcp@365: by (rtac (lfp_Con2_in_counit2 RS singleton_subsetI) 2); lcp@365: by (rtac subsetI 1); lcp@365: by (dtac (lfp_Con2_in_counit2 RS counit2_implies_equal) 1); lcp@365: by (etac subst 1); lcp@365: by (rtac singletonI 1); lcp@365: val counit2_eq_univ = result();