src/HOL/List.ML
author paulson
Mon Oct 07 10:28:44 1996 +0200 (1996-10-07)
changeset 2056 93c093620c28
parent 1985 84cf16192e03
child 2512 0231e4f467f2
permissions -rw-r--r--
Removed commands made redundant by new one-point rules
     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 AddIffs list.distinct;
    12 AddIffs list.inject;
    13 
    14 bind_thm("Cons_inject", (hd list.inject) RS iffD1 RS conjE);
    15 
    16 goal List.thy "!x. xs ~= x#xs";
    17 by (list.induct_tac "xs" 1);
    18 by (ALLGOALS Asm_simp_tac);
    19 qed "not_Cons_self";
    20 
    21 goal List.thy "(xs ~= []) = (? y ys. xs = y#ys)";
    22 by (list.induct_tac "xs" 1);
    23 by (Simp_tac 1);
    24 by (Asm_simp_tac 1);
    25 by (REPEAT(resolve_tac [exI,refl,conjI] 1));
    26 qed "neq_Nil_conv";
    27 
    28 
    29 (** @ - append **)
    30 
    31 goal List.thy "(xs@ys)@zs = xs@(ys@zs)";
    32 by (list.induct_tac "xs" 1);
    33 by (ALLGOALS Asm_simp_tac);
    34 qed "append_assoc";
    35 
    36 goal List.thy "xs @ [] = xs";
    37 by (list.induct_tac "xs" 1);
    38 by (ALLGOALS Asm_simp_tac);
    39 qed "append_Nil2";
    40 
    41 goal List.thy "(xs@ys = []) = (xs=[] & ys=[])";
    42 by (list.induct_tac "xs" 1);
    43 by (ALLGOALS Asm_simp_tac);
    44 qed "append_is_Nil";
    45 
    46 goal List.thy "(xs @ ys = xs @ zs) = (ys=zs)";
    47 by (list.induct_tac "xs" 1);
    48 by (ALLGOALS Asm_simp_tac);
    49 qed "same_append_eq";
    50 
    51 goal List.thy "hd(xs@ys) = (if xs=[] then hd ys else hd xs)";
    52 by (list.induct_tac "xs" 1);
    53 by (ALLGOALS Asm_simp_tac);
    54 qed "hd_append";
    55 
    56 (** rev **)
    57 
    58 goal List.thy "rev(xs@ys) = rev(ys) @ rev(xs)";
    59 by (list.induct_tac "xs" 1);
    60 by (ALLGOALS (asm_simp_tac (!simpset addsimps [append_Nil2,append_assoc])));
    61 qed "rev_append";
    62 
    63 goal List.thy "rev(rev l) = l";
    64 by (list.induct_tac "l" 1);
    65 by (ALLGOALS (asm_simp_tac (!simpset addsimps [rev_append])));
    66 qed "rev_rev_ident";
    67 
    68 
    69 (** mem **)
    70 
    71 goal List.thy "x mem (xs@ys) = (x mem xs | x mem ys)";
    72 by (list.induct_tac "xs" 1);
    73 by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
    74 qed "mem_append";
    75 
    76 goal List.thy "x mem [x:xs.P(x)] = (x mem xs & P(x))";
    77 by (list.induct_tac "xs" 1);
    78 by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
    79 qed "mem_filter";
    80 
    81 (** set_of_list **)
    82 
    83 goal thy "set_of_list (xs@ys) = (set_of_list xs Un set_of_list ys)";
    84 by (list.induct_tac "xs" 1);
    85 by (ALLGOALS Asm_simp_tac);
    86 by (Fast_tac 1);
    87 qed "set_of_list_append";
    88 
    89 goal thy "(x mem xs) = (x: set_of_list xs)";
    90 by (list.induct_tac "xs" 1);
    91 by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
    92 by (Fast_tac 1);
    93 qed "set_of_list_mem_eq";
    94 
    95 goal List.thy "set_of_list l <= set_of_list (x#l)";
    96 by (Simp_tac 1);
    97 by (Fast_tac 1);
    98 qed "set_of_list_subset_Cons";
    99 
   100 
   101 (** list_all **)
   102 
   103 goal List.thy "(Alls x:xs.True) = True";
   104 by (list.induct_tac "xs" 1);
   105 by (ALLGOALS Asm_simp_tac);
   106 qed "list_all_True";
   107 
   108 goal List.thy "list_all p (xs@ys) = (list_all p xs & list_all p ys)";
   109 by (list.induct_tac "xs" 1);
   110 by (ALLGOALS Asm_simp_tac);
   111 qed "list_all_conj";
   112 
   113 goal List.thy "(Alls x:xs.P(x)) = (!x. x mem xs --> P(x))";
   114 by (list.induct_tac "xs" 1);
   115 by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
   116 by (Fast_tac 1);
   117 qed "list_all_mem_conv";
   118 
   119 
   120 (** list_case **)
   121 
   122 goal List.thy
   123  "P(list_case a f xs) = ((xs=[] --> P(a)) & \
   124 \                         (!y ys. xs=y#ys --> P(f y ys)))";
   125 by (list.induct_tac "xs" 1);
   126 by (ALLGOALS Asm_simp_tac);
   127 by (Fast_tac 1);
   128 qed "expand_list_case";
   129 
   130 goal List.thy  "(xs=[] --> P([])) & (!y ys. xs=y#ys --> P(y#ys)) --> P(xs)";
   131 by (list.induct_tac "xs" 1);
   132 by (Fast_tac 1);
   133 by (Fast_tac 1);
   134 bind_thm("list_eq_cases",
   135   impI RSN (2,allI RSN (2,allI RSN (2,impI RS (conjI RS (result() RS mp))))));
   136 
   137 (** flat **)
   138 
   139 goal List.thy  "flat(xs@ys) = flat(xs)@flat(ys)";
   140 by (list.induct_tac "xs" 1);
   141 by (ALLGOALS (asm_simp_tac (!simpset addsimps [append_assoc])));
   142 qed"flat_append";
   143 
   144 (** length **)
   145 
   146 goal List.thy "length(xs@ys) = length(xs)+length(ys)";
   147 by (list.induct_tac "xs" 1);
   148 by (ALLGOALS Asm_simp_tac);
   149 qed"length_append";
   150 Addsimps [length_append];
   151 
   152 goal List.thy "length (map f l) = length l";
   153 by (list.induct_tac "l" 1);
   154 by (ALLGOALS Simp_tac);
   155 qed "length_map";
   156 Addsimps [length_map];
   157 
   158 goal List.thy "length(rev xs) = length(xs)";
   159 by (list.induct_tac "xs" 1);
   160 by (ALLGOALS Asm_simp_tac);
   161 qed "length_rev";
   162 Addsimps [length_rev];
   163 
   164 (** nth **)
   165 
   166 val [nth_0,nth_Suc] = nat_recs nth_def; 
   167 store_thm("nth_0",nth_0);
   168 store_thm("nth_Suc",nth_Suc);
   169 Addsimps [nth_0,nth_Suc];
   170 
   171 goal List.thy "!n. n < length xs --> nth n (map f xs) = f (nth n xs)";
   172 by (list.induct_tac "xs" 1);
   173 (* case [] *)
   174 by (Asm_full_simp_tac 1);
   175 (* case x#xl *)
   176 by (rtac allI 1);
   177 by (nat_ind_tac "n" 1);
   178 by (ALLGOALS Asm_full_simp_tac);
   179 qed_spec_mp "nth_map";
   180 Addsimps [nth_map];
   181 
   182 goal List.thy "!n. n < length xs --> list_all P xs --> P(nth n xs)";
   183 by (list.induct_tac "xs" 1);
   184 (* case [] *)
   185 by (Simp_tac 1);
   186 (* case x#xl *)
   187 by (rtac allI 1);
   188 by (nat_ind_tac "n" 1);
   189 by (ALLGOALS Asm_full_simp_tac);
   190 qed_spec_mp "list_all_nth";
   191 
   192 goal List.thy "!n. n < length xs --> (nth n xs) mem xs";
   193 by (list.induct_tac "xs" 1);
   194 (* case [] *)
   195 by (Simp_tac 1);
   196 (* case x#xl *)
   197 by (rtac allI 1);
   198 by (nat_ind_tac "n" 1);
   199 (* case 0 *)
   200 by (Asm_full_simp_tac 1);
   201 (* case Suc x *)
   202 by (asm_full_simp_tac (!simpset setloop (split_tac [expand_if])) 1);
   203 qed_spec_mp "nth_mem";
   204 Addsimps [nth_mem];
   205 
   206 (** drop **)
   207 
   208 goal thy "drop 0 xs = xs";
   209 by (list.induct_tac "xs" 1);
   210 by (ALLGOALS Asm_simp_tac);
   211 qed "drop_0";
   212 
   213 goal thy "drop (Suc n) (x#xs) = drop n xs";
   214 by (Simp_tac 1);
   215 qed "drop_Suc_Cons";
   216 
   217 Delsimps [drop_Cons];
   218 Addsimps [drop_0,drop_Suc_Cons];
   219 
   220 (** take **)
   221 
   222 goal thy "take 0 xs = []";
   223 by (list.induct_tac "xs" 1);
   224 by (ALLGOALS Asm_simp_tac);
   225 qed "take_0";
   226 
   227 goal thy "take (Suc n) (x#xs) = x # take n xs";
   228 by (Simp_tac 1);
   229 qed "take_Suc_Cons";
   230 
   231 Delsimps [take_Cons];
   232 Addsimps [take_0,take_Suc_Cons];
   233 
   234 (** Additional mapping lemmas **)
   235 
   236 goal List.thy "map (%x.x) = (%xs.xs)";
   237 by (rtac ext 1);
   238 by (list.induct_tac "xs" 1);
   239 by (ALLGOALS Asm_simp_tac);
   240 qed "map_ident";
   241 
   242 goal List.thy "map f (xs@ys) = map f xs @ map f ys";
   243 by (list.induct_tac "xs" 1);
   244 by (ALLGOALS Asm_simp_tac);
   245 qed "map_append";
   246 
   247 goalw List.thy [o_def] "map (f o g) xs = map f (map g xs)";
   248 by (list.induct_tac "xs" 1);
   249 by (ALLGOALS Asm_simp_tac);
   250 qed "map_compose";
   251 
   252 goal List.thy "rev(map f l) = map f (rev l)";
   253 by (list.induct_tac "l" 1);
   254 by (ALLGOALS (asm_simp_tac (!simpset addsimps [map_append])));
   255 qed "rev_map_distrib";
   256 
   257 goal List.thy "rev(flat ls) = flat (map rev (rev ls))";
   258 by (list.induct_tac "ls" 1);
   259 by (ALLGOALS (asm_simp_tac (!simpset addsimps 
   260        [map_append, flat_append, rev_append, append_Nil2])));
   261 qed "rev_flat";
   262 
   263 Addsimps
   264   [not_Cons_self, append_assoc, append_Nil2, append_is_Nil, same_append_eq,
   265    mem_append, mem_filter,
   266    rev_append, rev_rev_ident,
   267    map_ident, map_append, map_compose,
   268    flat_append, list_all_True, list_all_conj];
   269