23 |
24 |
24 Goalw [mono_def] "mono tokens"; |
25 Goalw [mono_def] "mono tokens"; |
25 by (blast_tac (claset() addIs [tokens_mono_prefix]) 1); |
26 by (blast_tac (claset() addIs [tokens_mono_prefix]) 1); |
26 qed "mono_tokens"; |
27 qed "mono_tokens"; |
27 |
28 |
28 Goal "length xs <= k --> map fst [p:zip xs [0..length xs(] . snd p < k] = xs"; |
29 |
|
30 (*** sublist ***) |
|
31 |
|
32 Goalw [sublist_def] "sublist l {} = []"; |
|
33 by Auto_tac; |
|
34 qed "sublist_empty"; |
|
35 |
|
36 Goalw [sublist_def] "sublist [] A = []"; |
|
37 by Auto_tac; |
|
38 qed "sublist_nil"; |
|
39 |
|
40 Goal "map fst [p:zip xs [i..i + length xs(] . snd p : A] = \ |
|
41 \ map fst [p:zip xs [0..length xs(] . snd p + i : A]"; |
29 by (res_inst_tac [("xs","xs")] rev_induct 1); |
42 by (res_inst_tac [("xs","xs")] rev_induct 1); |
|
43 by (asm_simp_tac (simpset() addsimps [add_commute]) 2); |
|
44 by (Simp_tac 1); |
|
45 qed "sublist_shift_lemma"; |
|
46 |
|
47 Goalw [sublist_def] |
|
48 "sublist (l@l') A = sublist l A @ sublist l' {j. j + length l : A}"; |
|
49 by (res_inst_tac [("xs","l'")] rev_induct 1); |
|
50 by (Simp_tac 1); |
|
51 by (asm_simp_tac (simpset() addsimps [inst "i" "0" upt_add_eq_append, |
|
52 zip_append, sublist_shift_lemma]) 1); |
|
53 by (asm_simp_tac (simpset() addsimps [add_commute]) 1); |
|
54 qed "sublist_append"; |
|
55 |
|
56 Addsimps [sublist_empty, sublist_nil]; |
|
57 |
|
58 Goal "sublist (x#l) A = (if 0:A then [x] else []) @ sublist l {j. Suc j : A}"; |
|
59 by (res_inst_tac [("xs","l")] rev_induct 1); |
|
60 by (asm_simp_tac (simpset() delsimps [append_Cons] |
|
61 addsimps [append_Cons RS sym, sublist_append]) 2); |
|
62 by (simp_tac (simpset() addsimps [sublist_def]) 1); |
|
63 qed "sublist_Cons"; |
|
64 |
|
65 Goal "sublist [x] A = (if 0 : A then [x] else [])"; |
|
66 by (simp_tac (simpset() addsimps [sublist_Cons]) 1); |
|
67 qed "sublist_singleton"; |
|
68 Addsimps [sublist_singleton]; |
|
69 |
|
70 Goal "sublist l {..n(} = take n l"; |
|
71 by (res_inst_tac [("xs","l")] rev_induct 1); |
|
72 by (asm_simp_tac (simpset() addsplits [nat_diff_split] |
|
73 addsimps [sublist_append]) 2); |
|
74 by (Simp_tac 1); |
|
75 qed "sublist_upt_eq_take"; |
|
76 Addsimps [sublist_upt_eq_take]; |
|
77 |
|
78 |
|
79 (** bag_of **) |
|
80 |
|
81 Goal "bag_of (l@l') = bag_of l + bag_of l'"; |
|
82 by (induct_tac "l" 1); |
|
83 by (asm_simp_tac (simpset() addsimps (thms "plus_ac0")) 2); |
|
84 by (Simp_tac 1); |
|
85 qed "bag_of_append"; |
|
86 Addsimps [bag_of_append]; |
|
87 |
|
88 Goal "mono (bag_of :: 'a list => ('a::order) multiset)"; |
|
89 by (rtac monoI 1); |
|
90 by (rewtac prefix_def); |
|
91 by (etac genPrefix.induct 1); |
30 by Auto_tac; |
92 by Auto_tac; |
31 qed_spec_mp "sublist_length_lemma"; |
93 by (asm_full_simp_tac (simpset() addsimps [union_le_mono]) 1); |
|
94 by (etac order_trans 1); |
|
95 by (rtac union_upper1 1); |
|
96 qed "mono_bag_of"; |
32 |
97 |
33 Goalw [sublist_def] "sublist l {..length l(} = l"; |
98 Goal "finite A ==> \ |
34 by (simp_tac (simpset() addsimps [sublist_length_lemma]) 1); |
99 \ setsum (%i. if i < Suc(length zs) then {#(zs @ [z]) ! i#} else {#}) A = \ |
35 qed "sublist_length"; |
100 \ setsum (%i. if i < length zs then {#zs ! i#} else {#}) A + \ |
|
101 \ (if length zs : A then {#z#} else {#})"; |
|
102 by (etac finite_induct 1); |
|
103 by (Simp_tac 1); |
|
104 by (asm_simp_tac (simpset() addsimps (nth_append :: thms "plus_ac0")) 1); |
|
105 by (subgoal_tac "x < Suc (length zs) & ~ x < length zs --> length zs = x" 1); |
|
106 by Auto_tac; |
|
107 qed "bag_of_sublist_lemma"; |
|
108 |
|
109 |
|
110 Goal "finite A \ |
|
111 \ ==> bag_of (sublist l A) = \ |
|
112 \ setsum (%i. if i < length l then {# nth l i #} else {#}) A"; |
|
113 by (res_inst_tac [("xs","l")] rev_induct 1); |
|
114 by (Simp_tac 1); |
|
115 by (stac (symmetric Zero_def) 1); |
|
116 by (etac (setsum_0 RS sym) 1); |
|
117 by (asm_simp_tac (simpset() addsimps [sublist_append, |
|
118 bag_of_sublist_lemma]) 1); |
|
119 qed "bag_of_sublist"; |
|
120 |
|
121 |
|
122 Goal "[| finite A; finite B |] \ |
|
123 \ ==> bag_of (sublist l (A Un B)) + bag_of (sublist l (A Int B)) = \ |
|
124 \ bag_of (sublist l A) + bag_of (sublist l B)"; |
|
125 by (asm_simp_tac (simpset() addsimps [bag_of_sublist, setsum_Un_Int]) 1); |
|
126 qed "bag_of_sublist_Un_Int"; |