src/HOL/List.ML
changeset 5318 72bf8039b53f
parent 5316 7a8975451a89
child 5355 a9f71e87f53e
equal deleted inserted replaced
5317:3a9214482762 5318:72bf8039b53f
   230 Addsimps [tl_append2];
   230 Addsimps [tl_append2];
   231 
   231 
   232 (* trivial rules for solving @-equations automatically *)
   232 (* trivial rules for solving @-equations automatically *)
   233 
   233 
   234 Goal "xs = ys ==> xs = [] @ ys";
   234 Goal "xs = ys ==> xs = [] @ ys";
   235 by(Asm_simp_tac 1);
   235 by (Asm_simp_tac 1);
   236 qed "eq_Nil_appendI";
   236 qed "eq_Nil_appendI";
   237 
   237 
   238 Goal "[| x#xs1 = ys; xs = xs1 @ zs |] ==> x#xs = ys@zs";
   238 Goal "[| x#xs1 = ys; xs = xs1 @ zs |] ==> x#xs = ys@zs";
   239 bd sym 1;
   239 by (dtac sym 1);
   240 by(Asm_simp_tac 1);
   240 by (Asm_simp_tac 1);
   241 qed "Cons_eq_appendI";
   241 qed "Cons_eq_appendI";
   242 
   242 
   243 Goal "[| xs@xs1 = zs; ys = xs1 @ us |] ==> xs@ys = zs@us";
   243 Goal "[| xs@xs1 = zs; ys = xs1 @ us |] ==> xs@ys = zs@us";
   244 bd sym 1;
   244 by (dtac sym 1);
   245 by(Asm_simp_tac 1);
   245 by (Asm_simp_tac 1);
   246 qed "append_eq_appendI";
   246 qed "append_eq_appendI";
   247 
   247 
   248 
   248 
   249 (** map **)
   249 (** map **)
   250 
   250 
   409 by Auto_tac;
   409 by Auto_tac;
   410 qed "in_set_filter";
   410 qed "in_set_filter";
   411 Addsimps [in_set_filter];
   411 Addsimps [in_set_filter];
   412 
   412 
   413 Goal "(x : set xs) = (? ys zs. xs = ys@x#zs)";
   413 Goal "(x : set xs) = (? ys zs. xs = ys@x#zs)";
   414 by(induct_tac "xs" 1);
   414 by (induct_tac "xs" 1);
   415  by(Simp_tac 1);
   415  by (Simp_tac 1);
   416 by(Asm_simp_tac 1);
   416 by (Asm_simp_tac 1);
   417 br iffI 1;
   417 by (rtac iffI 1);
   418 by(blast_tac (claset() addIs [eq_Nil_appendI,Cons_eq_appendI]) 1);
   418 by (blast_tac (claset() addIs [eq_Nil_appendI,Cons_eq_appendI]) 1);
   419 by(REPEAT(etac exE 1));
   419 by (REPEAT(etac exE 1));
   420 by(exhaust_tac "ys" 1);
   420 by (exhaust_tac "ys" 1);
   421 by Auto_tac;
   421 by Auto_tac;
   422 qed "in_set_conv_decomp";
   422 qed "in_set_conv_decomp";
   423 
   423 
   424 (* eliminate `lists' in favour of `set' *)
   424 (* eliminate `lists' in favour of `set' *)
   425 
   425 
   426 Goal "(xs : lists A) = (!x : set xs. x : A)";
   426 Goal "(xs : lists A) = (!x : set xs. x : A)";
   427 by(induct_tac "xs" 1);
   427 by (induct_tac "xs" 1);
   428 by Auto_tac;
   428 by Auto_tac;
   429 qed "in_lists_conv_set";
   429 qed "in_lists_conv_set";
   430 
   430 
   431 bind_thm("in_listsD",in_lists_conv_set RS iffD1);
   431 bind_thm("in_listsD",in_lists_conv_set RS iffD1);
   432 AddSDs [in_listsD];
   432 AddSDs [in_listsD];
   797 
   797 
   798 (** foldl **)
   798 (** foldl **)
   799 section "foldl";
   799 section "foldl";
   800 
   800 
   801 Goal "!a. foldl f a (xs @ ys) = foldl f (foldl f a xs) ys";
   801 Goal "!a. foldl f a (xs @ ys) = foldl f (foldl f a xs) ys";
   802 by(induct_tac "xs" 1);
   802 by (induct_tac "xs" 1);
   803 by Auto_tac;
   803 by Auto_tac;
   804 qed_spec_mp "foldl_append";
   804 qed_spec_mp "foldl_append";
   805 Addsimps [foldl_append];
   805 Addsimps [foldl_append];
   806 
   806 
   807 (* Note: `n <= foldl op+ n ns' looks simpler, but is more difficult to use
   807 (* Note: `n <= foldl op+ n ns' looks simpler, but is more difficult to use
   808    because it requires an additional transitivity step
   808    because it requires an additional transitivity step
   809 *)
   809 *)
   810 Goal "!n::nat. m <= n --> m <= foldl op+ n ns";
   810 Goal "!n::nat. m <= n --> m <= foldl op+ n ns";
   811 by(induct_tac "ns" 1);
   811 by (induct_tac "ns" 1);
   812  by(Simp_tac 1);
   812  by (Simp_tac 1);
   813 by(Asm_full_simp_tac 1);
   813 by (Asm_full_simp_tac 1);
   814 by(blast_tac (claset() addIs [trans_le_add1]) 1);
   814 by (blast_tac (claset() addIs [trans_le_add1]) 1);
   815 qed_spec_mp "start_le_sum";
   815 qed_spec_mp "start_le_sum";
   816 
   816 
   817 Goal "n : set ns ==> n <= foldl op+ 0 ns";
   817 Goal "n : set ns ==> n <= foldl op+ 0 ns";
   818 by(auto_tac (claset() addIs [start_le_sum],
   818 by (auto_tac (claset() addIs [start_le_sum],
   819              simpset() addsimps [in_set_conv_decomp]));
   819              simpset() addsimps [in_set_conv_decomp]));
   820 qed "elem_le_sum";
   820 qed "elem_le_sum";
   821 
   821 
   822 Goal "!m. (foldl op+ m ns = 0) = (m=0 & (!n : set ns. n=0))";
   822 Goal "!m. (foldl op+ m ns = 0) = (m=0 & (!n : set ns. n=0))";
   823 by(induct_tac "ns" 1);
   823 by (induct_tac "ns" 1);
   824 by Auto_tac;
   824 by Auto_tac;
   825 qed_spec_mp "sum_eq_0_conv";
   825 qed_spec_mp "sum_eq_0_conv";
   826 AddIffs [sum_eq_0_conv];
   826 AddIffs [sum_eq_0_conv];
   827 
   827 
   828 
   828 
   862 
   862 
   863 (*** Lexcicographic orderings on lists ***)
   863 (*** Lexcicographic orderings on lists ***)
   864 section"Lexcicographic orderings on lists";
   864 section"Lexcicographic orderings on lists";
   865 
   865 
   866 Goal "wf r ==> wf(lexn r n)";
   866 Goal "wf r ==> wf(lexn r n)";
   867 by(induct_tac "n" 1);
   867 by (induct_tac "n" 1);
   868 by(Simp_tac 1);
   868 by (Simp_tac 1);
   869 by(Simp_tac 1);
   869 by (Simp_tac 1);
   870 br wf_subset 1;
   870 by (rtac wf_subset 1);
   871 br Int_lower1 2;
   871 by (rtac Int_lower1 2);
   872 br wf_prod_fun_image 1;
   872 by (rtac wf_prod_fun_image 1);
   873 br injI 2;
   873 by (rtac injI 2);
   874 by(Auto_tac);
   874 by (Auto_tac);
   875 qed "wf_lexn";
   875 qed "wf_lexn";
   876 
   876 
   877 Goal "!xs ys. (xs,ys) : lexn r n --> length xs = n & length ys = n";
   877 Goal "!xs ys. (xs,ys) : lexn r n --> length xs = n & length ys = n";
   878 by(induct_tac "n" 1);
   878 by (induct_tac "n" 1);
   879 by(Auto_tac);
   879 by (Auto_tac);
   880 qed_spec_mp "lexn_length";
   880 qed_spec_mp "lexn_length";
   881 
   881 
   882 Goalw [lex_def] "wf r ==> wf(lex r)";
   882 Goalw [lex_def] "wf r ==> wf(lex r)";
   883 br wf_UN 1;
   883 by (rtac wf_UN 1);
   884 by(blast_tac (claset() addIs [wf_lexn]) 1);
   884 by (blast_tac (claset() addIs [wf_lexn]) 1);
   885 by(Clarify_tac 1);
   885 by (Clarify_tac 1);
   886 by(rename_tac "m n" 1);
   886 by (rename_tac "m n" 1);
   887 by(subgoal_tac "m ~= n" 1);
   887 by (subgoal_tac "m ~= n" 1);
   888  by(Blast_tac 2);
   888  by (Blast_tac 2);
   889 by(blast_tac (claset() addDs [lexn_length,not_sym]) 1);
   889 by (blast_tac (claset() addDs [lexn_length,not_sym]) 1);
   890 qed "wf_lex";
   890 qed "wf_lex";
   891 AddSIs [wf_lex];
   891 AddSIs [wf_lex];
   892 
   892 
   893 Goal
   893 Goal
   894  "lexn r n = \
   894  "lexn r n = \
   895 \ {(xs,ys). length xs = n & length ys = n & \
   895 \ {(xs,ys). length xs = n & length ys = n & \
   896 \           (? xys x y xs' ys'. xs= xys @ x#xs' & ys= xys @ y#ys' & (x,y):r)}";
   896 \           (? xys x y xs' ys'. xs= xys @ x#xs' & ys= xys @ y#ys' & (x,y):r)}";
   897 by(induct_tac "n" 1);
   897 by (induct_tac "n" 1);
   898  by(Simp_tac 1);
   898  by (Simp_tac 1);
   899  by(Blast_tac 1);
   899  by (Blast_tac 1);
   900 by(asm_full_simp_tac (simpset() delsimps [length_Suc_conv] 
   900 by (asm_full_simp_tac (simpset() delsimps [length_Suc_conv] 
   901 				addsimps [lex_prod_def]) 1);
   901 				addsimps [lex_prod_def]) 1);
   902 by(auto_tac (claset(), simpset() delsimps [length_Suc_conv]));
   902 by (auto_tac (claset(), simpset() delsimps [length_Suc_conv]));
   903   by(Blast_tac 1);
   903   by (Blast_tac 1);
   904  by(rename_tac "a xys x xs' y ys'" 1);
   904  by (rename_tac "a xys x xs' y ys'" 1);
   905  by(res_inst_tac [("x","a#xys")] exI 1);
   905  by (res_inst_tac [("x","a#xys")] exI 1);
   906  by(Simp_tac 1);
   906  by (Simp_tac 1);
   907 by(exhaust_tac "xys" 1);
   907 by (exhaust_tac "xys" 1);
   908  by(ALLGOALS (asm_full_simp_tac (simpset() delsimps [length_Suc_conv])));
   908  by (ALLGOALS (asm_full_simp_tac (simpset() delsimps [length_Suc_conv])));
   909 by(Blast_tac 1);
   909 by (Blast_tac 1);
   910 qed "lexn_conv";
   910 qed "lexn_conv";
   911 
   911 
   912 Goalw [lex_def]
   912 Goalw [lex_def]
   913  "lex r = \
   913  "lex r = \
   914 \ {(xs,ys). length xs = length ys & \
   914 \ {(xs,ys). length xs = length ys & \
   915 \           (? xys x y xs' ys'. xs= xys @ x#xs' & ys= xys @ y#ys' & (x,y):r)}";
   915 \           (? xys x y xs' ys'. xs= xys @ x#xs' & ys= xys @ y#ys' & (x,y):r)}";
   916 by(force_tac (claset(), simpset() delsimps [length_Suc_conv] addsimps [lexn_conv]) 1);
   916 by (force_tac (claset(), simpset() delsimps [length_Suc_conv] addsimps [lexn_conv]) 1);
   917 qed "lex_conv";
   917 qed "lex_conv";
   918 
   918 
   919 Goalw [lexico_def] "wf r ==> wf(lexico r)";
   919 Goalw [lexico_def] "wf r ==> wf(lexico r)";
   920 by(Blast_tac 1);
   920 by (Blast_tac 1);
   921 qed "wf_lexico";
   921 qed "wf_lexico";
   922 AddSIs [wf_lexico];
   922 AddSIs [wf_lexico];
   923 
   923 
   924 Goalw
   924 Goalw
   925  [lexico_def,diag_def,lex_prod_def,measure_def,inv_image_def]
   925  [lexico_def,diag_def,lex_prod_def,measure_def,inv_image_def]
   926 "lexico r = {(xs,ys). length xs < length ys | \
   926 "lexico r = {(xs,ys). length xs < length ys | \
   927 \                     length xs = length ys & (xs,ys) : lex r}";
   927 \                     length xs = length ys & (xs,ys) : lex r}";
   928 by(Simp_tac 1);
   928 by (Simp_tac 1);
   929 qed "lexico_conv";
   929 qed "lexico_conv";
   930 
   930 
   931 Goal "([],ys) ~: lex r";
   931 Goal "([],ys) ~: lex r";
   932 by(simp_tac (simpset() addsimps [lex_conv]) 1);
   932 by (simp_tac (simpset() addsimps [lex_conv]) 1);
   933 qed "Nil_notin_lex";
   933 qed "Nil_notin_lex";
   934 
   934 
   935 Goal "(xs,[]) ~: lex r";
   935 Goal "(xs,[]) ~: lex r";
   936 by(simp_tac (simpset() addsimps [lex_conv]) 1);
   936 by (simp_tac (simpset() addsimps [lex_conv]) 1);
   937 qed "Nil2_notin_lex";
   937 qed "Nil2_notin_lex";
   938 
   938 
   939 AddIffs [Nil_notin_lex,Nil2_notin_lex];
   939 AddIffs [Nil_notin_lex,Nil2_notin_lex];
   940 
   940 
   941 Goal "((x#xs,y#ys) : lex r) = \
   941 Goal "((x#xs,y#ys) : lex r) = \
   942 \     ((x,y) : r & length xs = length ys | x=y & (xs,ys) : lex r)";
   942 \     ((x,y) : r & length xs = length ys | x=y & (xs,ys) : lex r)";
   943 by(simp_tac (simpset() addsimps [lex_conv]) 1);
   943 by (simp_tac (simpset() addsimps [lex_conv]) 1);
   944 br iffI 1;
   944 by (rtac iffI 1);
   945  by(blast_tac (claset() addIs [Cons_eq_appendI]) 2);
   945  by (blast_tac (claset() addIs [Cons_eq_appendI]) 2);
   946 by(REPEAT(eresolve_tac [conjE, exE] 1));
   946 by (REPEAT(eresolve_tac [conjE, exE] 1));
   947 by(exhaust_tac "xys" 1);
   947 by (exhaust_tac "xys" 1);
   948 by(Asm_full_simp_tac 1);
   948 by (Asm_full_simp_tac 1);
   949 by(Asm_full_simp_tac 1);
   949 by (Asm_full_simp_tac 1);
   950 by(Blast_tac 1);
   950 by (Blast_tac 1);
   951 qed "Cons_in_lex";
   951 qed "Cons_in_lex";
   952 AddIffs [Cons_in_lex];
   952 AddIffs [Cons_in_lex];
   953 
   953 
   954 
   954 
   955 (***
   955 (***