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