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