src/ZF/ex/LListFn.ML
author lcp
Tue, 30 Nov 1993 11:08:18 +0100
changeset 173 85071e6ad295
parent 128 b0ec0c1bddb7
permissions -rw-r--r--
ZF/ex/llist_eq/lleq_Int_Vset_subset_lemma, ZF/ex/counit/counit2_Int_Vset_subset_lemma: now uses QPair_Int_Vset_subset_UN ZF/ex/llistfn/flip_llist_quniv_lemma: now uses transfinite induction and QPair_Int_Vset_subset_UN ZF/ex/llist/llist_quniv_lemma: now uses transfinite induction and QPair_Int_Vset_subset_UN
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     1
(*  Title: 	ZF/ex/llist-fn.ML
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
Functions for Lazy Lists in Zermelo-Fraenkel Set Theory 
120
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
     7
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
     8
Examples of coinduction for type-checking and to prove llist equations
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     9
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
open LListFn;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
(*** lconst -- defined directly using lfp, but equivalent to a LList_corec ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
goalw LListFn.thy LList.con_defs "bnd_mono(univ(a), %l. LCons(a,l))";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
by (rtac bnd_monoI 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
by (REPEAT (ares_tac [subset_refl, QInr_mono, QPair_mono] 2));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
by (REPEAT (ares_tac [subset_refl, A_subset_univ, 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
		      QInr_subset_univ, QPair_subset_univ] 1));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
val lconst_fun_bnd_mono = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    22
(* lconst(a) = LCons(a,lconst(a)) *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
val lconst = standard 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
    ([lconst_def, lconst_fun_bnd_mono] MRS def_lfp_Tarski);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    26
val lconst_subset = lconst_def RS def_lfp_subset;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    28
val member_subset_Union_eclose = standard (arg_into_eclose RS Union_upper);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    30
goal LListFn.thy "!!a A. a : A ==> lconst(a) : quniv(A)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
by (rtac (lconst_subset RS subset_trans RS qunivI) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
by (etac (arg_into_eclose RS eclose_subset RS univ_mono) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
val lconst_in_quniv = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    34
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    35
goal LListFn.thy "!!a A. a:A ==> lconst(a): llist(A)";
120
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    36
by (rtac (singletonI RS LList.coinduct) 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
by (fast_tac (ZF_cs addSIs [lconst_in_quniv]) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
by (fast_tac (ZF_cs addSIs [lconst]) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    39
val lconst_type = result();
120
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    40
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    41
(*** flip --- equations merely assumed; certain consequences proved ***)
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    42
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    43
val flip_ss = ZF_ss addsimps [flip_LNil, flip_LCons, not_type];
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    44
173
85071e6ad295 ZF/ex/llist_eq/lleq_Int_Vset_subset_lemma,
lcp
parents: 128
diff changeset
    45
goal QUniv.thy "!!b. b:bool ==> b Int X <= univ(eclose(A))";
85071e6ad295 ZF/ex/llist_eq/lleq_Int_Vset_subset_lemma,
lcp
parents: 128
diff changeset
    46
by (fast_tac (quniv_cs addSEs [boolE]) 1);
85071e6ad295 ZF/ex/llist_eq/lleq_Int_Vset_subset_lemma,
lcp
parents: 128
diff changeset
    47
val bool_Int_subset_univ = result();
120
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    48
173
85071e6ad295 ZF/ex/llist_eq/lleq_Int_Vset_subset_lemma,
lcp
parents: 128
diff changeset
    49
val flip_cs = quniv_cs addSIs [not_type]
85071e6ad295 ZF/ex/llist_eq/lleq_Int_Vset_subset_lemma,
lcp
parents: 128
diff changeset
    50
                       addIs  [bool_Int_subset_univ];
120
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    51
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    52
(*Reasoning borrowed from llist_eq.ML; a similar proof works for all
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    53
  "productive" functions -- cf Coquand's "Infinite Objects in Type Theory".*)
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    54
goal LListFn.thy
173
85071e6ad295 ZF/ex/llist_eq/lleq_Int_Vset_subset_lemma,
lcp
parents: 128
diff changeset
    55
   "!!i. Ord(i) ==> ALL l: llist(bool). flip(l) Int Vset(i) <= \
85071e6ad295 ZF/ex/llist_eq/lleq_Int_Vset_subset_lemma,
lcp
parents: 128
diff changeset
    56
\                   univ(eclose(bool))";
120
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    57
by (etac trans_induct 1);
173
85071e6ad295 ZF/ex/llist_eq/lleq_Int_Vset_subset_lemma,
lcp
parents: 128
diff changeset
    58
by (rtac ballI 1);
120
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    59
by (etac LList.elim 1);
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    60
by (asm_simp_tac flip_ss 1);
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    61
by (asm_simp_tac flip_ss 2);
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    62
by (rewrite_goals_tac ([QInl_def,QInr_def]@LList.con_defs));
173
85071e6ad295 ZF/ex/llist_eq/lleq_Int_Vset_subset_lemma,
lcp
parents: 128
diff changeset
    63
(*LNil case*)
120
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    64
by (fast_tac flip_cs 1);
173
85071e6ad295 ZF/ex/llist_eq/lleq_Int_Vset_subset_lemma,
lcp
parents: 128
diff changeset
    65
(*LCons case*)
85071e6ad295 ZF/ex/llist_eq/lleq_Int_Vset_subset_lemma,
lcp
parents: 128
diff changeset
    66
by (safe_tac flip_cs);
85071e6ad295 ZF/ex/llist_eq/lleq_Int_Vset_subset_lemma,
lcp
parents: 128
diff changeset
    67
by (ALLGOALS (fast_tac (flip_cs addSEs [Ord_trans, make_elim bspec])));
120
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    68
val flip_llist_quniv_lemma = result();
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    69
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    70
goal LListFn.thy "!!l. l: llist(bool) ==> flip(l) : quniv(bool)";
173
85071e6ad295 ZF/ex/llist_eq/lleq_Int_Vset_subset_lemma,
lcp
parents: 128
diff changeset
    71
by (rtac (flip_llist_quniv_lemma RS bspec RS Int_Vset_subset RS qunivI) 1);
120
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    72
by (REPEAT (assume_tac 1));
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    73
val flip_in_quniv = result();
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    74
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    75
val [prem] = goal LListFn.thy "l : llist(bool) ==> flip(l): llist(bool)";
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    76
by (res_inst_tac [("X", "{flip(l) . l:llist(bool)}")]
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    77
       LList.coinduct 1);
128
b0ec0c1bddb7 expandshort
lcp
parents: 120
diff changeset
    78
by (rtac (prem RS RepFunI) 1);
120
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    79
by (fast_tac (ZF_cs addSIs [flip_in_quniv]) 1);
128
b0ec0c1bddb7 expandshort
lcp
parents: 120
diff changeset
    80
by (etac RepFunE 1);
120
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    81
by (etac LList.elim 1);
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    82
by (asm_simp_tac flip_ss 1);
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    83
by (asm_simp_tac flip_ss 1);
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    84
by (fast_tac (ZF_cs addSIs [not_type]) 1);
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    85
val flip_type = result();
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    86
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    87
val [prem] = goal LListFn.thy
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    88
    "l : llist(bool) ==> flip(flip(l)) = l";
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    89
by (res_inst_tac [("X1", "{<flip(flip(l)),l> . l:llist(bool)}")]
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    90
       (LList_Eq.coinduct RS lleq_implies_equal) 1);
128
b0ec0c1bddb7 expandshort
lcp
parents: 120
diff changeset
    91
by (rtac (prem RS RepFunI) 1);
120
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    92
by (fast_tac (ZF_cs addSIs [flip_type]) 1);
128
b0ec0c1bddb7 expandshort
lcp
parents: 120
diff changeset
    93
by (etac RepFunE 1);
120
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    94
by (etac LList.elim 1);
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    95
by (asm_simp_tac flip_ss 1);
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    96
by (asm_simp_tac (flip_ss addsimps [flip_type, not_not]) 1);
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    97
by (fast_tac (ZF_cs addSIs [not_type]) 1);
09287f26bfb8 changed all co- and co_ to co
lcp
parents: 0
diff changeset
    98
val flip_flip = result();