src/CCL/ex/Stream.ML
changeset 3837 d7f033c74b38
parent 2035 e329b36d9136
child 5062 fbdb0b541314
equal deleted inserted replaced
3836:f1a1817659e6 3837:d7f033c74b38
    14 
    14 
    15 (*** Map of composition is composition of maps ***)
    15 (*** Map of composition is composition of maps ***)
    16 
    16 
    17 val prems = goal Stream.thy "l:Lists(A) ==> map(f o g,l) = map(f,map(g,l))";
    17 val prems = goal Stream.thy "l:Lists(A) ==> map(f o g,l) = map(f,map(g,l))";
    18 by (eq_coinduct3_tac 
    18 by (eq_coinduct3_tac 
    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);
    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);
    20 by (fast_tac (ccl_cs addSIs prems) 1);
    20 by (fast_tac (ccl_cs addSIs prems) 1);
    21 by (safe_tac type_cs);
    21 by (safe_tac type_cs);
    22 by (etac (XH_to_E ListsXH) 1);
    22 by (etac (XH_to_E ListsXH) 1);
    23 by (EQgen_tac list_ss [] 1);
    23 by (EQgen_tac list_ss [] 1);
    24 by (simp_tac list_ss 1);
    24 by (simp_tac list_ss 1);
    25 by (fast_tac ccl_cs 1);
    25 by (fast_tac ccl_cs 1);
    26 qed "map_comp";
    26 qed "map_comp";
    27 
    27 
    28 (*** Mapping the identity function leaves a list unchanged ***)
    28 (*** Mapping the identity function leaves a list unchanged ***)
    29 
    29 
    30 val prems = goal Stream.thy "l:Lists(A) ==> map(%x.x,l) = l";
    30 val prems = goal Stream.thy "l:Lists(A) ==> map(%x. x,l) = l";
    31 by (eq_coinduct3_tac 
    31 by (eq_coinduct3_tac 
    32        "{p. EX x y.p=<x,y> & (EX l:Lists(A).x=map(%x.x,l) & y=l)}"  1);
    32        "{p. EX x y. p=<x,y> & (EX l:Lists(A).x=map(%x. x,l) & y=l)}"  1);
    33 by (fast_tac (ccl_cs addSIs prems) 1);
    33 by (fast_tac (ccl_cs addSIs prems) 1);
    34 by (safe_tac type_cs);
    34 by (safe_tac type_cs);
    35 by (etac (XH_to_E ListsXH) 1);
    35 by (etac (XH_to_E ListsXH) 1);
    36 by (EQgen_tac list_ss [] 1);
    36 by (EQgen_tac list_ss [] 1);
    37 by (fast_tac ccl_cs 1);
    37 by (fast_tac ccl_cs 1);
    39 
    39 
    40 (*** Mapping distributes over append ***)
    40 (*** Mapping distributes over append ***)
    41 
    41 
    42 val prems = goal Stream.thy 
    42 val prems = goal Stream.thy 
    43         "[| l:Lists(A); m:Lists(A) |] ==> map(f,l@m) = map(f,l) @ map(f,m)";
    43         "[| l:Lists(A); m:Lists(A) |] ==> map(f,l@m) = map(f,l) @ map(f,m)";
    44 by (eq_coinduct3_tac "{p. EX x y.p=<x,y> & (EX l:Lists(A).EX m:Lists(A). \
    44 by (eq_coinduct3_tac "{p. EX x y. p=<x,y> & (EX l:Lists(A).EX m:Lists(A). \
    45 \                                           x=map(f,l@m) & y=map(f,l) @ map(f,m))}"  1);
    45 \                                           x=map(f,l@m) & y=map(f,l) @ map(f,m))}"  1);
    46 by (fast_tac (ccl_cs addSIs prems) 1);
    46 by (fast_tac (ccl_cs addSIs prems) 1);
    47 by (safe_tac type_cs);
    47 by (safe_tac type_cs);
    48 by (etac (XH_to_E ListsXH) 1);
    48 by (etac (XH_to_E ListsXH) 1);
    49 by (EQgen_tac list_ss [] 1);
    49 by (EQgen_tac list_ss [] 1);
    55 (*** Append is associative ***)
    55 (*** Append is associative ***)
    56 
    56 
    57 val prems = goal Stream.thy 
    57 val prems = goal Stream.thy 
    58         "[| k:Lists(A); l:Lists(A); m:Lists(A) |] ==> k @ l @ m = (k @ l) @ m";
    58         "[| k:Lists(A); l:Lists(A); m:Lists(A) |] ==> k @ l @ m = (k @ l) @ m";
    59 by (eq_coinduct3_tac 
    59 by (eq_coinduct3_tac 
    60     "{p. EX x y.p=<x,y> & (EX k:Lists(A).EX l:Lists(A).EX m:Lists(A). \
    60     "{p. EX x y. p=<x,y> & (EX k:Lists(A).EX l:Lists(A).EX m:Lists(A). \
    61 \                          x=k @ l @ m & y=(k @ l) @ m)}"  1);
    61 \                          x=k @ l @ m & y=(k @ l) @ m)}"  1);
    62 by (fast_tac (ccl_cs addSIs prems) 1);
    62 by (fast_tac (ccl_cs addSIs prems) 1);
    63 by (safe_tac type_cs);
    63 by (safe_tac type_cs);
    64 by (etac (XH_to_E ListsXH) 1);
    64 by (etac (XH_to_E ListsXH) 1);
    65 by (EQgen_tac list_ss [] 1);
    65 by (EQgen_tac list_ss [] 1);
    69 
    69 
    70 (*** Appending anything to an infinite list doesn't alter it ****)
    70 (*** Appending anything to an infinite list doesn't alter it ****)
    71 
    71 
    72 val prems = goal Stream.thy "l:ILists(A) ==> l @ m = l";
    72 val prems = goal Stream.thy "l:ILists(A) ==> l @ m = l";
    73 by (eq_coinduct3_tac
    73 by (eq_coinduct3_tac
    74     "{p. EX x y.p=<x,y> & (EX l:ILists(A).EX m.x=l@m & y=l)}" 1);
    74     "{p. EX x y. p=<x,y> & (EX l:ILists(A).EX m. x=l@m & y=l)}" 1);
    75 by (fast_tac (ccl_cs addSIs prems) 1);
    75 by (fast_tac (ccl_cs addSIs prems) 1);
    76 by (safe_tac set_cs);
    76 by (safe_tac set_cs);
    77 by (etac (XH_to_E IListsXH) 1);
    77 by (etac (XH_to_E IListsXH) 1);
    78 by (EQgen_tac list_ss [] 1);
    78 by (EQgen_tac list_ss [] 1);
    79 by (fast_tac ccl_cs 1);
    79 by (fast_tac ccl_cs 1);
   101 by (simp_tac (list_ss addsimps [prem RS nmapBcons]) 1);
   101 by (simp_tac (list_ss addsimps [prem RS nmapBcons]) 1);
   102 qed "iter2Blemma";
   102 qed "iter2Blemma";
   103 
   103 
   104 goal Stream.thy "iter1(f,a) = iter2(f,a)";
   104 goal Stream.thy "iter1(f,a) = iter2(f,a)";
   105 by (eq_coinduct3_tac 
   105 by (eq_coinduct3_tac 
   106     "{p. EX x y.p=<x,y> & (EX n:Nat.x=iter1(f,f^n`a) & y=map(f)^n`iter2(f,a))}"
   106     "{p. EX x y. p=<x,y> & (EX n:Nat. x=iter1(f,f^n`a) & y=map(f)^n`iter2(f,a))}"
   107     1);
   107     1);
   108 by (fast_tac (type_cs addSIs [napplyBzero RS sym,
   108 by (fast_tac (type_cs addSIs [napplyBzero RS sym,
   109                               napplyBzero RS sym RS arg_cong]) 1);
   109                               napplyBzero RS sym RS arg_cong]) 1);
   110 by (EQgen_tac list_ss [iter1B,iter2Blemma] 1);
   110 by (EQgen_tac list_ss [iter1B,iter2Blemma] 1);
   111 by (stac napply_f 1 THEN atac 1);
   111 by (stac napply_f 1 THEN atac 1);