| 1478 |      1 | (*  Title:      ZF/ex/CoUnit.ML
 | 
| 515 |      2 |     ID:         $Id$
 | 
| 1478 |      3 |     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
 | 
| 515 |      4 |     Copyright   1994  University of Cambridge
 | 
|  |      5 | *)
 | 
|  |      6 | 
 | 
| 12228 |      7 | header {* Trivial codatatype definitions, one of which goes wrong! *}
 | 
|  |      8 | 
 | 
| 16417 |      9 | theory CoUnit imports Main begin
 | 
| 515 |     10 | 
 | 
| 12228 |     11 | text {*
 | 
|  |     12 |   See discussion in: L C Paulson.  A Concrete Final Coalgebra Theorem
 | 
|  |     13 |   for ZF Set Theory.  Report 334, Cambridge University Computer
 | 
|  |     14 |   Laboratory.  1994.
 | 
|  |     15 | 
 | 
|  |     16 |   \bigskip
 | 
|  |     17 | 
 | 
|  |     18 |   This degenerate definition does not work well because the one
 | 
|  |     19 |   constructor's definition is trivial!  The same thing occurs with
 | 
|  |     20 |   Aczel's Special Final Coalgebra Theorem.
 | 
|  |     21 | *}
 | 
|  |     22 | 
 | 
| 515 |     23 | consts
 | 
| 1401 |     24 |   counit :: i
 | 
| 515 |     25 | codatatype
 | 
| 12228 |     26 |   "counit" = Con ("x \<in> counit")
 | 
|  |     27 | 
 | 
|  |     28 | inductive_cases ConE: "Con(x) \<in> counit"
 | 
|  |     29 |   -- {* USELESS because folding on @{term "Con(xa) == xa"} fails. *}
 | 
|  |     30 | 
 | 
|  |     31 | lemma Con_iff: "Con(x) = Con(y) <-> x = y"
 | 
|  |     32 |   -- {* Proving freeness results. *}
 | 
|  |     33 |   by (auto elim!: counit.free_elims)
 | 
|  |     34 | 
 | 
|  |     35 | lemma counit_eq_univ: "counit = quniv(0)"
 | 
|  |     36 |   -- {* Should be a singleton, not everything! *}
 | 
|  |     37 |   apply (rule counit.dom_subset [THEN equalityI])
 | 
|  |     38 |   apply (rule subsetI)
 | 
|  |     39 |   apply (erule counit.coinduct)
 | 
|  |     40 |    apply (rule subset_refl)
 | 
|  |     41 |   apply (unfold counit.con_defs)
 | 
|  |     42 |   apply fast
 | 
|  |     43 |   done
 | 
| 515 |     44 | 
 | 
|  |     45 | 
 | 
| 12228 |     46 | text {*
 | 
|  |     47 |   \medskip A similar example, but the constructor is non-degenerate
 | 
|  |     48 |   and it works!  The resulting set is a singleton.
 | 
|  |     49 | *}
 | 
| 515 |     50 | 
 | 
|  |     51 | consts
 | 
| 1401 |     52 |   counit2 :: i
 | 
| 515 |     53 | codatatype
 | 
| 12228 |     54 |   "counit2" = Con2 ("x \<in> counit2", "y \<in> counit2")
 | 
|  |     55 | 
 | 
|  |     56 | 
 | 
|  |     57 | inductive_cases Con2E: "Con2(x, y) \<in> counit2"
 | 
|  |     58 | 
 | 
|  |     59 | lemma Con2_iff: "Con2(x, y) = Con2(x', y') <-> x = x' & y = y'"
 | 
|  |     60 |   -- {* Proving freeness results. *}
 | 
|  |     61 |   by (fast elim!: counit2.free_elims)
 | 
|  |     62 | 
 | 
|  |     63 | lemma Con2_bnd_mono: "bnd_mono(univ(0), %x. Con2(x, x))"
 | 
|  |     64 |   apply (unfold counit2.con_defs)
 | 
|  |     65 |   apply (rule bnd_monoI)
 | 
|  |     66 |    apply (assumption | rule subset_refl QPair_subset_univ QPair_mono)+
 | 
|  |     67 |   done
 | 
|  |     68 | 
 | 
|  |     69 | lemma lfp_Con2_in_counit2: "lfp(univ(0), %x. Con2(x,x)) \<in> counit2"
 | 
|  |     70 |   apply (rule singletonI [THEN counit2.coinduct])
 | 
|  |     71 |   apply (rule qunivI [THEN singleton_subsetI])
 | 
|  |     72 |   apply (rule subset_trans [OF lfp_subset empty_subsetI [THEN univ_mono]])
 | 
|  |     73 |   apply (fast intro!: Con2_bnd_mono [THEN lfp_unfold])
 | 
|  |     74 |   done
 | 
|  |     75 | 
 | 
|  |     76 | lemma counit2_Int_Vset_subset [rule_format]:
 | 
|  |     77 |   "Ord(i) ==> \<forall>x y. x \<in> counit2 --> y \<in> counit2 --> x Int Vset(i) \<subseteq> y"
 | 
|  |     78 |   -- {* Lemma for proving finality. *}
 | 
|  |     79 |   apply (erule trans_induct)
 | 
|  |     80 |   apply (tactic "safe_tac subset_cs")
 | 
|  |     81 |   apply (erule counit2.cases)
 | 
|  |     82 |   apply (erule counit2.cases)
 | 
|  |     83 |   apply (unfold counit2.con_defs)
 | 
|  |     84 |   apply (tactic {* fast_tac (subset_cs
 | 
|  |     85 |     addSIs [QPair_Int_Vset_subset_UN RS subset_trans, QPair_mono]
 | 
|  |     86 |     addSEs [Ord_in_Ord, Pair_inject]) 1 *})
 | 
|  |     87 |   done
 | 
|  |     88 | 
 | 
|  |     89 | lemma counit2_implies_equal: "[| x \<in> counit2;  y \<in> counit2 |] ==> x = y"
 | 
|  |     90 |   apply (rule equalityI)
 | 
|  |     91 |   apply (assumption | rule conjI counit2_Int_Vset_subset [THEN Int_Vset_subset])+
 | 
|  |     92 |   done
 | 
|  |     93 | 
 | 
|  |     94 | lemma counit2_eq_univ: "counit2 = {lfp(univ(0), %x. Con2(x,x))}"
 | 
|  |     95 |   apply (rule equalityI)
 | 
|  |     96 |    apply (rule_tac [2] lfp_Con2_in_counit2 [THEN singleton_subsetI])
 | 
|  |     97 |   apply (rule subsetI)
 | 
|  |     98 |   apply (drule lfp_Con2_in_counit2 [THEN counit2_implies_equal])
 | 
|  |     99 |   apply (erule subst)
 | 
|  |    100 |   apply (rule singletonI)
 | 
|  |    101 |   done
 | 
| 515 |    102 | 
 | 
|  |    103 | end
 |