src/HOL/List.ML
changeset 923 ff1574a81019
child 962 136308504cd9
equal deleted inserted replaced
922:196ca0973a6d 923:ff1574a81019
       
     1 (*  Title: 	HOL/List
       
     2     ID:         $Id$
       
     3     Author: 	Tobias Nipkow
       
     4     Copyright   1994 TU Muenchen
       
     5 
       
     6 List lemmas
       
     7 *)
       
     8 
       
     9 open List;
       
    10 
       
    11 val [Nil_not_Cons,Cons_not_Nil] = list.distinct;
       
    12 
       
    13 bind_thm("Cons_neq_Nil", Cons_not_Nil RS notE);
       
    14 bind_thm("Nil_neq_Cons", sym RS Cons_neq_Nil);
       
    15 
       
    16 bind_thm("Cons_inject", (hd list.inject) RS iffD1 RS conjE);
       
    17 
       
    18 val list_ss = HOL_ss addsimps list.simps;
       
    19 
       
    20 goal List.thy "!x. xs ~= x#xs";
       
    21 by (list.induct_tac "xs" 1);
       
    22 by (ALLGOALS (asm_simp_tac list_ss));
       
    23 qed "not_Cons_self";
       
    24 
       
    25 goal List.thy "(xs ~= []) = (? y ys. xs = y#ys)";
       
    26 by (list.induct_tac "xs" 1);
       
    27 by(simp_tac list_ss 1);
       
    28 by(asm_simp_tac list_ss 1);
       
    29 by(REPEAT(resolve_tac [exI,refl,conjI] 1));
       
    30 qed "neq_Nil_conv";
       
    31 
       
    32 val list_ss = arith_ss addsimps list.simps @
       
    33   [null_Nil, null_Cons, hd_Cons, tl_Cons, ttl_Nil, ttl_Cons,
       
    34    mem_Nil, mem_Cons,
       
    35    append_Nil, append_Cons,
       
    36    map_Nil, map_Cons,
       
    37    flat_Nil, flat_Cons,
       
    38    list_all_Nil, list_all_Cons,
       
    39    filter_Nil, filter_Cons];
       
    40 
       
    41 
       
    42 (** @ - append **)
       
    43 
       
    44 goal List.thy "(xs@ys)@zs = xs@(ys@zs)";
       
    45 by (list.induct_tac "xs" 1);
       
    46 by(ALLGOALS(asm_simp_tac list_ss));
       
    47 qed "append_assoc";
       
    48 
       
    49 goal List.thy "xs @ [] = xs";
       
    50 by (list.induct_tac "xs" 1);
       
    51 by(ALLGOALS(asm_simp_tac list_ss));
       
    52 qed "append_Nil2";
       
    53 
       
    54 goal List.thy "(xs@ys = []) = (xs=[] & ys=[])";
       
    55 by (list.induct_tac "xs" 1);
       
    56 by(ALLGOALS(asm_simp_tac list_ss));
       
    57 qed "append_is_Nil";
       
    58 
       
    59 goal List.thy "(xs @ ys = xs @ zs) = (ys=zs)";
       
    60 by (list.induct_tac "xs" 1);
       
    61 by(ALLGOALS(asm_simp_tac list_ss));
       
    62 qed "same_append_eq";
       
    63 
       
    64 
       
    65 (** mem **)
       
    66 
       
    67 goal List.thy "x mem (xs@ys) = (x mem xs | x mem ys)";
       
    68 by (list.induct_tac "xs" 1);
       
    69 by(ALLGOALS(asm_simp_tac (list_ss setloop (split_tac [expand_if]))));
       
    70 qed "mem_append";
       
    71 
       
    72 goal List.thy "x mem [x:xs.P(x)] = (x mem xs & P(x))";
       
    73 by (list.induct_tac "xs" 1);
       
    74 by(ALLGOALS(asm_simp_tac (list_ss setloop (split_tac [expand_if]))));
       
    75 qed "mem_filter";
       
    76 
       
    77 (** list_all **)
       
    78 
       
    79 goal List.thy "(Alls x:xs.True) = True";
       
    80 by (list.induct_tac "xs" 1);
       
    81 by(ALLGOALS(asm_simp_tac list_ss));
       
    82 qed "list_all_True";
       
    83 
       
    84 goal List.thy "list_all p (xs@ys) = (list_all p xs & list_all p ys)";
       
    85 by (list.induct_tac "xs" 1);
       
    86 by(ALLGOALS(asm_simp_tac list_ss));
       
    87 qed "list_all_conj";
       
    88 
       
    89 goal List.thy "(Alls x:xs.P(x)) = (!x. x mem xs --> P(x))";
       
    90 by (list.induct_tac "xs" 1);
       
    91 by(ALLGOALS(asm_simp_tac (list_ss setloop (split_tac [expand_if]))));
       
    92 by(fast_tac HOL_cs 1);
       
    93 qed "list_all_mem_conv";
       
    94 
       
    95 
       
    96 (** list_case **)
       
    97 
       
    98 goal List.thy
       
    99  "P(list_case a f xs) = ((xs=[] --> P(a)) & \
       
   100 \                         (!y ys. xs=y#ys --> P(f y ys)))";
       
   101 by (list.induct_tac "xs" 1);
       
   102 by(ALLGOALS(asm_simp_tac list_ss));
       
   103 by(fast_tac HOL_cs 1);
       
   104 qed "expand_list_case";
       
   105 
       
   106 goal List.thy  "(xs=[] --> P([])) & (!y ys. xs=y#ys --> P(y#ys)) --> P(xs)";
       
   107 by(list.induct_tac "xs" 1);
       
   108 by(fast_tac HOL_cs 1);
       
   109 by(fast_tac HOL_cs 1);
       
   110 bind_thm("list_eq_cases",
       
   111   impI RSN (2,allI RSN (2,allI RSN (2,impI RS (conjI RS (result() RS mp))))));
       
   112 
       
   113 (** flat **)
       
   114 
       
   115 goal List.thy  "flat(xs@ys) = flat(xs)@flat(ys)";
       
   116 by (list.induct_tac "xs" 1);
       
   117 by(ALLGOALS(asm_simp_tac (list_ss addsimps [append_assoc])));
       
   118 qed"flat_append";
       
   119 
       
   120 (** nth **)
       
   121 
       
   122 val [nth_0,nth_Suc] = nat_recs nth_def; 
       
   123 store_thm("nth_0",nth_0);
       
   124 store_thm("nth_Suc",nth_Suc);
       
   125 
       
   126 (** Additional mapping lemmas **)
       
   127 
       
   128 goal List.thy "map (%x.x) xs = xs";
       
   129 by (list.induct_tac "xs" 1);
       
   130 by (ALLGOALS (asm_simp_tac list_ss));
       
   131 qed "map_ident";
       
   132 
       
   133 goal List.thy "map f (xs@ys) = map f xs @ map f ys";
       
   134 by (list.induct_tac "xs" 1);
       
   135 by (ALLGOALS (asm_simp_tac list_ss));
       
   136 qed "map_append";
       
   137 
       
   138 goalw List.thy [o_def] "map (f o g) xs = map f (map g xs)";
       
   139 by (list.induct_tac "xs" 1);
       
   140 by (ALLGOALS (asm_simp_tac list_ss));
       
   141 qed "map_compose";
       
   142 
       
   143 val list_ss = list_ss addsimps
       
   144   [not_Cons_self, append_assoc, append_Nil2, append_is_Nil, same_append_eq,
       
   145    mem_append, mem_filter,
       
   146    map_ident, map_append, map_compose,
       
   147    flat_append, list_all_True, list_all_conj, nth_0, nth_Suc];
       
   148