1 (* Title: ZF/ex/counit.ML |
1 (* Title: ZF/ex/CoUnit.ML |
2 ID: $Id$ |
2 ID: $Id$ |
3 Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
3 Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
4 Copyright 1993 University of Cambridge |
4 Copyright 1994 University of Cambridge |
5 |
5 |
6 Trivial codatatype definitions, one of which goes wrong! |
6 Trivial codatatype definitions, one of which goes wrong! |
7 |
7 |
8 Need to find sufficient conditions for codatatypes to work correctly! |
8 See discussion in |
|
9 L C Paulson. A Concrete Final Coalgebra Theorem for ZF Set Theory. |
|
10 Report 334, Cambridge University Computer Laboratory. 1994. |
9 *) |
11 *) |
10 |
12 |
11 (*This degenerate definition does not work well because the one constructor's |
13 open CoUnit; |
12 definition is trivial! The same thing occurs with Aczel's Special Final |
|
13 Coalgebra Theorem |
|
14 *) |
|
15 structure CoUnit = CoDatatype_Fun |
|
16 (val thy = QUniv.thy; |
|
17 val thy_name = "CoUnit"; |
|
18 val rec_specs = |
|
19 [("counit", "quniv(0)", |
|
20 [(["Con"], "i=>i", NoSyn)])]; |
|
21 val rec_styp = "i"; |
|
22 val sintrs = ["x: counit ==> Con(x) : counit"]; |
|
23 val monos = []; |
|
24 val type_intrs = codatatype_intrs |
|
25 val type_elims = codatatype_elims); |
|
26 |
14 |
27 val [ConI] = CoUnit.intrs; |
|
28 |
|
29 (*USELESS because folding on Con(?xa) == ?xa fails*) |
15 (*USELESS because folding on Con(?xa) == ?xa fails*) |
30 val ConE = CoUnit.mk_cases CoUnit.con_defs "Con(x) : counit"; |
16 val ConE = counit.mk_cases counit.con_defs "Con(x) : counit"; |
31 |
17 |
32 (*Proving freeness results*) |
18 (*Proving freeness results*) |
33 val Con_iff = CoUnit.mk_free "Con(x)=Con(y) <-> x=y"; |
19 val Con_iff = counit.mk_free "Con(x)=Con(y) <-> x=y"; |
34 |
20 |
35 (*Should be a singleton, not everything!*) |
21 (*Should be a singleton, not everything!*) |
36 goal CoUnit.thy "counit = quniv(0)"; |
22 goal CoUnit.thy "counit = quniv(0)"; |
37 by (rtac (CoUnit.dom_subset RS equalityI) 1); |
23 by (rtac (counit.dom_subset RS equalityI) 1); |
38 by (rtac subsetI 1); |
24 by (rtac subsetI 1); |
39 by (etac CoUnit.coinduct 1); |
25 by (etac counit.coinduct 1); |
40 by (rtac subset_refl 1); |
26 by (rtac subset_refl 1); |
41 by (rewrite_goals_tac CoUnit.con_defs); |
27 by (rewrite_goals_tac counit.con_defs); |
42 by (fast_tac ZF_cs 1); |
28 by (fast_tac ZF_cs 1); |
43 val counit_eq_univ = result(); |
29 val counit_eq_univ = result(); |
44 |
30 |
45 |
|
46 (*****************************************************************) |
|
47 |
31 |
48 (*A similar example, but the constructor is non-degenerate and it works! |
32 (*A similar example, but the constructor is non-degenerate and it works! |
49 The resulting set is a singleton. |
33 The resulting set is a singleton. |
50 *) |
34 *) |
51 |
35 |
52 structure CoUnit2 = CoDatatype_Fun |
36 val Con2E = counit2.mk_cases counit2.con_defs "Con2(x,y) : counit2"; |
53 (val thy = QUniv.thy; |
|
54 val thy_name = "CoUnit2"; |
|
55 val rec_specs = |
|
56 [("counit2", "quniv(0)", |
|
57 [(["Con2"], "[i,i]=>i", NoSyn)])]; |
|
58 val rec_styp = "i"; |
|
59 val sintrs = ["[| x: counit2; y: counit2 |] ==> Con2(x,y) : counit2"]; |
|
60 val monos = []; |
|
61 val type_intrs = codatatype_intrs |
|
62 val type_elims = codatatype_elims); |
|
63 |
|
64 val [Con2I] = CoUnit2.intrs; |
|
65 |
|
66 val Con2E = CoUnit2.mk_cases CoUnit2.con_defs "Con2(x,y) : counit2"; |
|
67 |
37 |
68 (*Proving freeness results*) |
38 (*Proving freeness results*) |
69 val Con2_iff = CoUnit2.mk_free "Con2(x,y)=Con2(x',y') <-> x=x' & y=y'"; |
39 val Con2_iff = counit2.mk_free "Con2(x,y)=Con2(x',y') <-> x=x' & y=y'"; |
70 |
40 |
71 goalw CoUnit2.thy CoUnit2.con_defs "bnd_mono(univ(0), %x. Con2(x,x))"; |
41 goalw CoUnit.thy counit2.con_defs "bnd_mono(univ(0), %x. Con2(x,x))"; |
72 by (rtac bnd_monoI 1); |
42 by (rtac bnd_monoI 1); |
73 by (REPEAT (ares_tac [subset_refl, QPair_subset_univ, QPair_mono] 1)); |
43 by (REPEAT (ares_tac [subset_refl, QPair_subset_univ, QPair_mono] 1)); |
74 val Con2_bnd_mono = result(); |
44 val Con2_bnd_mono = result(); |
75 |
45 |
76 goal CoUnit2.thy "lfp(univ(0), %x. Con2(x,x)) : counit2"; |
46 goal CoUnit.thy "lfp(univ(0), %x. Con2(x,x)) : counit2"; |
77 by (rtac (singletonI RS CoUnit2.coinduct) 1); |
47 by (rtac (singletonI RS counit2.coinduct) 1); |
78 by (rtac (qunivI RS singleton_subsetI) 1); |
48 by (rtac (qunivI RS singleton_subsetI) 1); |
79 by (rtac ([lfp_subset, empty_subsetI RS univ_mono] MRS subset_trans) 1); |
49 by (rtac ([lfp_subset, empty_subsetI RS univ_mono] MRS subset_trans) 1); |
80 by (fast_tac (ZF_cs addSIs [Con2_bnd_mono RS lfp_Tarski]) 1); |
50 by (fast_tac (ZF_cs addSIs [Con2_bnd_mono RS lfp_Tarski]) 1); |
81 val lfp_Con2_in_counit2 = result(); |
51 val lfp_Con2_in_counit2 = result(); |
82 |
52 |
83 (*Lemma for proving finality. Borrowed from ex/llist_eq.ML!*) |
53 (*Lemma for proving finality. Borrowed from ex/llist_eq.ML!*) |
84 goal CoUnit2.thy |
54 goal CoUnit.thy |
85 "!!i. Ord(i) ==> ALL x y. x: counit2 & y: counit2 --> x Int Vset(i) <= y"; |
55 "!!i. Ord(i) ==> ALL x y. x: counit2 & y: counit2 --> x Int Vset(i) <= y"; |
86 by (etac trans_induct 1); |
56 by (etac trans_induct 1); |
87 by (safe_tac subset_cs); |
57 by (safe_tac subset_cs); |
88 by (etac CoUnit2.elim 1); |
58 by (etac counit2.elim 1); |
89 by (etac CoUnit2.elim 1); |
59 by (etac counit2.elim 1); |
90 by (rewrite_goals_tac CoUnit2.con_defs); |
60 by (rewrite_goals_tac counit2.con_defs); |
91 by (fast_tac lleq_cs 1); |
61 by (fast_tac lleq_cs 1); |
92 val counit2_Int_Vset_subset_lemma = result(); |
62 val counit2_Int_Vset_subset_lemma = result(); |
93 |
63 |
94 val counit2_Int_Vset_subset = standard |
64 val counit2_Int_Vset_subset = standard |
95 (counit2_Int_Vset_subset_lemma RS spec RS spec RS mp); |
65 (counit2_Int_Vset_subset_lemma RS spec RS spec RS mp); |
96 |
66 |
97 goal CoUnit2.thy "!!x y. [| x: counit2; y: counit2 |] ==> x=y"; |
67 goal CoUnit.thy "!!x y. [| x: counit2; y: counit2 |] ==> x=y"; |
98 by (rtac equalityI 1); |
68 by (rtac equalityI 1); |
99 by (REPEAT (ares_tac [conjI, counit2_Int_Vset_subset RS Int_Vset_subset] 1)); |
69 by (REPEAT (ares_tac [conjI, counit2_Int_Vset_subset RS Int_Vset_subset] 1)); |
100 val counit2_implies_equal = result(); |
70 val counit2_implies_equal = result(); |
101 |
71 |
102 goal CoUnit2.thy "counit2 = {lfp(univ(0), %x. Con2(x,x))}"; |
72 goal CoUnit.thy "counit2 = {lfp(univ(0), %x. Con2(x,x))}"; |
103 by (rtac equalityI 1); |
73 by (rtac equalityI 1); |
104 by (rtac (lfp_Con2_in_counit2 RS singleton_subsetI) 2); |
74 by (rtac (lfp_Con2_in_counit2 RS singleton_subsetI) 2); |
105 by (rtac subsetI 1); |
75 by (rtac subsetI 1); |
106 by (dtac (lfp_Con2_in_counit2 RS counit2_implies_equal) 1); |
76 by (dtac (lfp_Con2_in_counit2 RS counit2_implies_equal) 1); |
107 by (etac subst 1); |
77 by (etac subst 1); |