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