src/CCL/ex/Stream.ML
author wenzelm
Mon, 09 Nov 1998 15:32:43 +0100
changeset 5824 91113aa09371
parent 5062 fbdb0b541314
child 17456 bcf7544875b2
permissions -rw-r--r--
Proof methods.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1459
d12da312eff4 expanded tabs
clasohm
parents: 1001
diff changeset
     1
(*  Title:      CCL/ex/stream
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1459
d12da312eff4 expanded tabs
clasohm
parents: 1001
diff changeset
     3
    Author:     Martin Coen, Cambridge University Computer Laboratory
0
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
For stream.thy.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
Proving properties about infinite lists using coinduction:
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     9
    Lists(A)  is the set of all finite and infinite lists of elements of A.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
    ILists(A) is the set of infinite lists of elements of A.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
open Stream;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
(*** Map of composition is composition of maps ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
val prems = goal Stream.thy "l:Lists(A) ==> map(f o g,l) = map(f,map(g,l))";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
by (eq_coinduct3_tac 
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 2035
diff changeset
    19
       "{p. EX x y. p=<x,y> & (EX l:Lists(A).x=map(f o g,l) & y=map(f,map(g,l)))}"  1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
by (fast_tac (ccl_cs addSIs prems) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
by (safe_tac type_cs);
1459
d12da312eff4 expanded tabs
clasohm
parents: 1001
diff changeset
    22
by (etac (XH_to_E ListsXH) 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
by (EQgen_tac list_ss [] 1);
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
    24
by (simp_tac list_ss 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
by (fast_tac ccl_cs 1);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 290
diff changeset
    26
qed "map_comp";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    28
(*** Mapping the identity function leaves a list unchanged ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 2035
diff changeset
    30
val prems = goal Stream.thy "l:Lists(A) ==> map(%x. x,l) = l";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
by (eq_coinduct3_tac 
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 2035
diff changeset
    32
       "{p. EX x y. p=<x,y> & (EX l:Lists(A).x=map(%x. x,l) & y=l)}"  1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
by (fast_tac (ccl_cs addSIs prems) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    34
by (safe_tac type_cs);
1459
d12da312eff4 expanded tabs
clasohm
parents: 1001
diff changeset
    35
by (etac (XH_to_E ListsXH) 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    36
by (EQgen_tac list_ss [] 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
by (fast_tac ccl_cs 1);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 290
diff changeset
    38
qed "map_id";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    39
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    40
(*** Mapping distributes over append ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    41
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    42
val prems = goal Stream.thy 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
        "[| l:Lists(A); m:Lists(A) |] ==> map(f,l@m) = map(f,l) @ map(f,m)";
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 2035
diff changeset
    44
by (eq_coinduct3_tac "{p. EX x y. p=<x,y> & (EX l:Lists(A).EX m:Lists(A). \
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    45
\                                           x=map(f,l@m) & y=map(f,l) @ map(f,m))}"  1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    46
by (fast_tac (ccl_cs addSIs prems) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    47
by (safe_tac type_cs);
1459
d12da312eff4 expanded tabs
clasohm
parents: 1001
diff changeset
    48
by (etac (XH_to_E ListsXH) 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
by (EQgen_tac list_ss [] 1);
1459
d12da312eff4 expanded tabs
clasohm
parents: 1001
diff changeset
    50
by (etac (XH_to_E ListsXH) 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    51
by (EQgen_tac list_ss [] 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    52
by (fast_tac ccl_cs 1);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 290
diff changeset
    53
qed "map_append";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    54
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    55
(*** Append is associative ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    56
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
val prems = goal Stream.thy 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    58
        "[| k:Lists(A); l:Lists(A); m:Lists(A) |] ==> k @ l @ m = (k @ l) @ m";
1001
1f416fb5de91 Simplified some proofs and made them work for new hyp_subst_tac.
lcp
parents: 757
diff changeset
    59
by (eq_coinduct3_tac 
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 2035
diff changeset
    60
    "{p. EX x y. p=<x,y> & (EX k:Lists(A).EX l:Lists(A).EX m:Lists(A). \
1001
1f416fb5de91 Simplified some proofs and made them work for new hyp_subst_tac.
lcp
parents: 757
diff changeset
    61
\                          x=k @ l @ m & y=(k @ l) @ m)}"  1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    62
by (fast_tac (ccl_cs addSIs prems) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    63
by (safe_tac type_cs);
1459
d12da312eff4 expanded tabs
clasohm
parents: 1001
diff changeset
    64
by (etac (XH_to_E ListsXH) 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    65
by (EQgen_tac list_ss [] 1);
1001
1f416fb5de91 Simplified some proofs and made them work for new hyp_subst_tac.
lcp
parents: 757
diff changeset
    66
by (fast_tac ccl_cs 2);
1f416fb5de91 Simplified some proofs and made them work for new hyp_subst_tac.
lcp
parents: 757
diff changeset
    67
by (DEPTH_SOLVE (etac (XH_to_E ListsXH) 1 THEN EQgen_tac list_ss [] 1));
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 290
diff changeset
    68
qed "append_assoc";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    69
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    70
(*** Appending anything to an infinite list doesn't alter it ****)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    72
val prems = goal Stream.thy "l:ILists(A) ==> l @ m = l";
1001
1f416fb5de91 Simplified some proofs and made them work for new hyp_subst_tac.
lcp
parents: 757
diff changeset
    73
by (eq_coinduct3_tac
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 2035
diff changeset
    74
    "{p. EX x y. p=<x,y> & (EX l:ILists(A).EX m. x=l@m & y=l)}" 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
by (fast_tac (ccl_cs addSIs prems) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
by (safe_tac set_cs);
1459
d12da312eff4 expanded tabs
clasohm
parents: 1001
diff changeset
    77
by (etac (XH_to_E IListsXH) 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    78
by (EQgen_tac list_ss [] 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    79
by (fast_tac ccl_cs 1);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 290
diff changeset
    80
qed "ilist_append";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    81
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    82
(*** The equivalance of two versions of an iteration function       ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    83
(*                                                                    *)
290
37d580c16af5 changed "." to "$" and added parentheses to eliminate ambiguity
clasohm
parents: 216
diff changeset
    84
(*        fun iter1(f,a) = a$iter1(f,f(a))                            *)
37d580c16af5 changed "." to "$" and added parentheses to eliminate ambiguity
clasohm
parents: 216
diff changeset
    85
(*        fun iter2(f,a) = a$map(f,iter2(f,a))                        *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    86
5062
fbdb0b541314 isatool fixgoal;
wenzelm
parents: 3837
diff changeset
    87
Goalw [iter1_def] "iter1(f,a) = a$iter1(f,f(a))";
1459
d12da312eff4 expanded tabs
clasohm
parents: 1001
diff changeset
    88
by (rtac (letrecB RS trans) 1);
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
    89
by (simp_tac term_ss 1);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 290
diff changeset
    90
qed "iter1B";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    91
5062
fbdb0b541314 isatool fixgoal;
wenzelm
parents: 3837
diff changeset
    92
Goalw [iter2_def] "iter2(f,a) = a $ map(f,iter2(f,a))";
1459
d12da312eff4 expanded tabs
clasohm
parents: 1001
diff changeset
    93
by (rtac (letrecB RS trans) 1);
d12da312eff4 expanded tabs
clasohm
parents: 1001
diff changeset
    94
by (rtac refl 1);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 290
diff changeset
    95
qed "iter2B";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    96
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    97
val [prem] =goal Stream.thy
1001
1f416fb5de91 Simplified some proofs and made them work for new hyp_subst_tac.
lcp
parents: 757
diff changeset
    98
   "n:Nat ==> \
1f416fb5de91 Simplified some proofs and made them work for new hyp_subst_tac.
lcp
parents: 757
diff changeset
    99
\   map(f) ^ n ` iter2(f,a) = (f ^ n ` a) $ (map(f) ^ n ` map(f,iter2(f,a)))";
1f416fb5de91 Simplified some proofs and made them work for new hyp_subst_tac.
lcp
parents: 757
diff changeset
   100
by (res_inst_tac [("P", "%x. ?lhs(x) = ?rhs")] (iter2B RS ssubst) 1);
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
   101
by (simp_tac (list_ss addsimps [prem RS nmapBcons]) 1);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 290
diff changeset
   102
qed "iter2Blemma";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   103
5062
fbdb0b541314 isatool fixgoal;
wenzelm
parents: 3837
diff changeset
   104
Goal "iter1(f,a) = iter2(f,a)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   105
by (eq_coinduct3_tac 
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 2035
diff changeset
   106
    "{p. EX x y. p=<x,y> & (EX n:Nat. x=iter1(f,f^n`a) & y=map(f)^n`iter2(f,a))}"
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
   107
    1);
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
   108
by (fast_tac (type_cs addSIs [napplyBzero RS sym,
1459
d12da312eff4 expanded tabs
clasohm
parents: 1001
diff changeset
   109
                              napplyBzero RS sym RS arg_cong]) 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   110
by (EQgen_tac list_ss [iter1B,iter2Blemma] 1);
2035
e329b36d9136 Ran expandshort; used stac instead of ssubst
paulson
parents: 1459
diff changeset
   111
by (stac napply_f 1 THEN atac 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   112
by (res_inst_tac [("f1","f")] (napplyBsucc RS subst) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   113
by (fast_tac type_cs 1);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 290
diff changeset
   114
qed "iter1_iter2_eq";