nipkow@8924
|
1 |
(* Title: HOL/SetInterval.thy
|
nipkow@8924
|
2 |
ID: $Id$
|
ballarin@13735
|
3 |
Author: Tobias Nipkow and Clemens Ballarin
|
paulson@14485
|
4 |
Additions by Jeremy Avigad in March 2004
|
paulson@8957
|
5 |
Copyright 2000 TU Muenchen
|
nipkow@8924
|
6 |
|
ballarin@13735
|
7 |
lessThan, greaterThan, atLeast, atMost and two-sided intervals
|
nipkow@8924
|
8 |
*)
|
nipkow@8924
|
9 |
|
wenzelm@14577
|
10 |
header {* Set intervals *}
|
wenzelm@14577
|
11 |
|
nipkow@15131
|
12 |
theory SetInterval
|
nipkow@15140
|
13 |
imports IntArith
|
nipkow@15131
|
14 |
begin
|
nipkow@8924
|
15 |
|
nipkow@8924
|
16 |
constdefs
|
nipkow@15045
|
17 |
lessThan :: "('a::ord) => 'a set" ("(1{..<_})")
|
nipkow@15045
|
18 |
"{..<u} == {x. x<u}"
|
nipkow@8924
|
19 |
|
wenzelm@11609
|
20 |
atMost :: "('a::ord) => 'a set" ("(1{.._})")
|
wenzelm@11609
|
21 |
"{..u} == {x. x<=u}"
|
nipkow@8924
|
22 |
|
nipkow@15045
|
23 |
greaterThan :: "('a::ord) => 'a set" ("(1{_<..})")
|
nipkow@15045
|
24 |
"{l<..} == {x. l<x}"
|
nipkow@8924
|
25 |
|
wenzelm@11609
|
26 |
atLeast :: "('a::ord) => 'a set" ("(1{_..})")
|
wenzelm@11609
|
27 |
"{l..} == {x. l<=x}"
|
nipkow@8924
|
28 |
|
nipkow@15045
|
29 |
greaterThanLessThan :: "['a::ord, 'a] => 'a set" ("(1{_<..<_})")
|
nipkow@15045
|
30 |
"{l<..<u} == {l<..} Int {..<u}"
|
ballarin@13735
|
31 |
|
nipkow@15045
|
32 |
atLeastLessThan :: "['a::ord, 'a] => 'a set" ("(1{_..<_})")
|
nipkow@15045
|
33 |
"{l..<u} == {l..} Int {..<u}"
|
ballarin@13735
|
34 |
|
nipkow@15045
|
35 |
greaterThanAtMost :: "['a::ord, 'a] => 'a set" ("(1{_<.._})")
|
nipkow@15045
|
36 |
"{l<..u} == {l<..} Int {..u}"
|
ballarin@13735
|
37 |
|
ballarin@13735
|
38 |
atLeastAtMost :: "['a::ord, 'a] => 'a set" ("(1{_.._})")
|
ballarin@13735
|
39 |
"{l..u} == {l..} Int {..u}"
|
ballarin@13735
|
40 |
|
nipkow@15045
|
41 |
(* Old syntax, will disappear! *)
|
nipkow@15045
|
42 |
syntax
|
nipkow@15045
|
43 |
"_lessThan" :: "('a::ord) => 'a set" ("(1{.._'(})")
|
nipkow@15045
|
44 |
"_greaterThan" :: "('a::ord) => 'a set" ("(1{')_..})")
|
nipkow@15045
|
45 |
"_greaterThanLessThan" :: "['a::ord, 'a] => 'a set" ("(1{')_.._'(})")
|
nipkow@15045
|
46 |
"_atLeastLessThan" :: "['a::ord, 'a] => 'a set" ("(1{_.._'(})")
|
nipkow@15045
|
47 |
"_greaterThanAtMost" :: "['a::ord, 'a] => 'a set" ("(1{')_.._})")
|
nipkow@15045
|
48 |
translations
|
nipkow@15045
|
49 |
"{..m(}" => "{..<m}"
|
nipkow@15045
|
50 |
"{)m..}" => "{m<..}"
|
nipkow@15045
|
51 |
"{)m..n(}" => "{m<..<n}"
|
nipkow@15045
|
52 |
"{m..n(}" => "{m..<n}"
|
nipkow@15045
|
53 |
"{)m..n}" => "{m<..n}"
|
nipkow@15045
|
54 |
|
nipkow@15048
|
55 |
|
nipkow@15048
|
56 |
text{* A note of warning when using @{term"{..<n}"} on type @{typ
|
nipkow@15048
|
57 |
nat}: it is equivalent to @{term"{0::nat..<n}"} but some lemmas involving
|
nipkow@15052
|
58 |
@{term"{m..<n}"} may not exist in @{term"{..<n}"}-form as well. *}
|
nipkow@15048
|
59 |
|
kleing@14418
|
60 |
syntax
|
kleing@14418
|
61 |
"@UNION_le" :: "nat => nat => 'b set => 'b set" ("(3UN _<=_./ _)" 10)
|
kleing@14418
|
62 |
"@UNION_less" :: "nat => nat => 'b set => 'b set" ("(3UN _<_./ _)" 10)
|
kleing@14418
|
63 |
"@INTER_le" :: "nat => nat => 'b set => 'b set" ("(3INT _<=_./ _)" 10)
|
kleing@14418
|
64 |
"@INTER_less" :: "nat => nat => 'b set => 'b set" ("(3INT _<_./ _)" 10)
|
kleing@14418
|
65 |
|
kleing@14418
|
66 |
syntax (input)
|
kleing@14418
|
67 |
"@UNION_le" :: "nat => nat => 'b set => 'b set" ("(3\<Union> _\<le>_./ _)" 10)
|
kleing@14418
|
68 |
"@UNION_less" :: "nat => nat => 'b set => 'b set" ("(3\<Union> _<_./ _)" 10)
|
kleing@14418
|
69 |
"@INTER_le" :: "nat => nat => 'b set => 'b set" ("(3\<Inter> _\<le>_./ _)" 10)
|
kleing@14418
|
70 |
"@INTER_less" :: "nat => nat => 'b set => 'b set" ("(3\<Inter> _<_./ _)" 10)
|
kleing@14418
|
71 |
|
kleing@14418
|
72 |
syntax (xsymbols)
|
wenzelm@14846
|
73 |
"@UNION_le" :: "nat \<Rightarrow> nat => 'b set => 'b set" ("(3\<Union>(00\<^bsub>_ \<le> _\<^esub>)/ _)" 10)
|
wenzelm@14846
|
74 |
"@UNION_less" :: "nat \<Rightarrow> nat => 'b set => 'b set" ("(3\<Union>(00\<^bsub>_ < _\<^esub>)/ _)" 10)
|
wenzelm@14846
|
75 |
"@INTER_le" :: "nat \<Rightarrow> nat => 'b set => 'b set" ("(3\<Inter>(00\<^bsub>_ \<le> _\<^esub>)/ _)" 10)
|
wenzelm@14846
|
76 |
"@INTER_less" :: "nat \<Rightarrow> nat => 'b set => 'b set" ("(3\<Inter>(00\<^bsub>_ < _\<^esub>)/ _)" 10)
|
kleing@14418
|
77 |
|
kleing@14418
|
78 |
translations
|
kleing@14418
|
79 |
"UN i<=n. A" == "UN i:{..n}. A"
|
nipkow@15045
|
80 |
"UN i<n. A" == "UN i:{..<n}. A"
|
kleing@14418
|
81 |
"INT i<=n. A" == "INT i:{..n}. A"
|
nipkow@15045
|
82 |
"INT i<n. A" == "INT i:{..<n}. A"
|
kleing@14418
|
83 |
|
kleing@14418
|
84 |
|
paulson@14485
|
85 |
subsection {* Various equivalences *}
|
ballarin@13735
|
86 |
|
paulson@13850
|
87 |
lemma lessThan_iff [iff]: "(i: lessThan k) = (i<k)"
|
paulson@13850
|
88 |
by (simp add: lessThan_def)
|
ballarin@13735
|
89 |
|
paulson@15418
|
90 |
lemma Compl_lessThan [simp]:
|
paulson@13850
|
91 |
"!!k:: 'a::linorder. -lessThan k = atLeast k"
|
paulson@13850
|
92 |
apply (auto simp add: lessThan_def atLeast_def)
|
ballarin@13735
|
93 |
done
|
ballarin@13735
|
94 |
|
paulson@13850
|
95 |
lemma single_Diff_lessThan [simp]: "!!k:: 'a::order. {k} - lessThan k = {k}"
|
paulson@13850
|
96 |
by auto
|
paulson@13850
|
97 |
|
paulson@13850
|
98 |
lemma greaterThan_iff [iff]: "(i: greaterThan k) = (k<i)"
|
paulson@13850
|
99 |
by (simp add: greaterThan_def)
|
paulson@13850
|
100 |
|
paulson@15418
|
101 |
lemma Compl_greaterThan [simp]:
|
paulson@13850
|
102 |
"!!k:: 'a::linorder. -greaterThan k = atMost k"
|
paulson@13850
|
103 |
apply (simp add: greaterThan_def atMost_def le_def, auto)
|
ballarin@13735
|
104 |
done
|
ballarin@13735
|
105 |
|
paulson@13850
|
106 |
lemma Compl_atMost [simp]: "!!k:: 'a::linorder. -atMost k = greaterThan k"
|
paulson@13850
|
107 |
apply (subst Compl_greaterThan [symmetric])
|
paulson@15418
|
108 |
apply (rule double_complement)
|
ballarin@13735
|
109 |
done
|
ballarin@13735
|
110 |
|
paulson@13850
|
111 |
lemma atLeast_iff [iff]: "(i: atLeast k) = (k<=i)"
|
paulson@13850
|
112 |
by (simp add: atLeast_def)
|
paulson@13850
|
113 |
|
paulson@15418
|
114 |
lemma Compl_atLeast [simp]:
|
paulson@13850
|
115 |
"!!k:: 'a::linorder. -atLeast k = lessThan k"
|
paulson@13850
|
116 |
apply (simp add: lessThan_def atLeast_def le_def, auto)
|
ballarin@13735
|
117 |
done
|
ballarin@13735
|
118 |
|
paulson@13850
|
119 |
lemma atMost_iff [iff]: "(i: atMost k) = (i<=k)"
|
paulson@13850
|
120 |
by (simp add: atMost_def)
|
ballarin@13735
|
121 |
|
paulson@14485
|
122 |
lemma atMost_Int_atLeast: "!!n:: 'a::order. atMost n Int atLeast n = {n}"
|
paulson@14485
|
123 |
by (blast intro: order_antisym)
|
ballarin@13735
|
124 |
|
ballarin@13735
|
125 |
|
paulson@14485
|
126 |
subsection {* Logical Equivalences for Set Inclusion and Equality *}
|
paulson@13850
|
127 |
|
paulson@13850
|
128 |
lemma atLeast_subset_iff [iff]:
|
paulson@15418
|
129 |
"(atLeast x \<subseteq> atLeast y) = (y \<le> (x::'a::order))"
|
paulson@15418
|
130 |
by (blast intro: order_trans)
|
paulson@13850
|
131 |
|
paulson@13850
|
132 |
lemma atLeast_eq_iff [iff]:
|
paulson@15418
|
133 |
"(atLeast x = atLeast y) = (x = (y::'a::linorder))"
|
paulson@13850
|
134 |
by (blast intro: order_antisym order_trans)
|
paulson@13850
|
135 |
|
paulson@13850
|
136 |
lemma greaterThan_subset_iff [iff]:
|
paulson@15418
|
137 |
"(greaterThan x \<subseteq> greaterThan y) = (y \<le> (x::'a::linorder))"
|
paulson@15418
|
138 |
apply (auto simp add: greaterThan_def)
|
paulson@15418
|
139 |
apply (subst linorder_not_less [symmetric], blast)
|
ballarin@13735
|
140 |
done
|
ballarin@13735
|
141 |
|
paulson@13850
|
142 |
lemma greaterThan_eq_iff [iff]:
|
paulson@15418
|
143 |
"(greaterThan x = greaterThan y) = (x = (y::'a::linorder))"
|
paulson@15418
|
144 |
apply (rule iffI)
|
paulson@15418
|
145 |
apply (erule equalityE)
|
paulson@15418
|
146 |
apply (simp_all add: greaterThan_subset_iff)
|
paulson@13850
|
147 |
done
|
ballarin@13735
|
148 |
|
paulson@15418
|
149 |
lemma atMost_subset_iff [iff]: "(atMost x \<subseteq> atMost y) = (x \<le> (y::'a::order))"
|
paulson@13850
|
150 |
by (blast intro: order_trans)
|
paulson@13850
|
151 |
|
paulson@15418
|
152 |
lemma atMost_eq_iff [iff]: "(atMost x = atMost y) = (x = (y::'a::linorder))"
|
paulson@13850
|
153 |
by (blast intro: order_antisym order_trans)
|
paulson@13850
|
154 |
|
paulson@13850
|
155 |
lemma lessThan_subset_iff [iff]:
|
paulson@15418
|
156 |
"(lessThan x \<subseteq> lessThan y) = (x \<le> (y::'a::linorder))"
|
paulson@15418
|
157 |
apply (auto simp add: lessThan_def)
|
paulson@15418
|
158 |
apply (subst linorder_not_less [symmetric], blast)
|
paulson@13850
|
159 |
done
|
paulson@13850
|
160 |
|
paulson@13850
|
161 |
lemma lessThan_eq_iff [iff]:
|
paulson@15418
|
162 |
"(lessThan x = lessThan y) = (x = (y::'a::linorder))"
|
paulson@15418
|
163 |
apply (rule iffI)
|
paulson@15418
|
164 |
apply (erule equalityE)
|
paulson@15418
|
165 |
apply (simp_all add: lessThan_subset_iff)
|
paulson@13850
|
166 |
done
|
paulson@13850
|
167 |
|
paulson@13850
|
168 |
|
paulson@13850
|
169 |
subsection {*Two-sided intervals*}
|
ballarin@13735
|
170 |
|
ballarin@13735
|
171 |
lemma greaterThanLessThan_iff [simp]:
|
nipkow@15045
|
172 |
"(i : {l<..<u}) = (l < i & i < u)"
|
ballarin@13735
|
173 |
by (simp add: greaterThanLessThan_def)
|
ballarin@13735
|
174 |
|
ballarin@13735
|
175 |
lemma atLeastLessThan_iff [simp]:
|
nipkow@15045
|
176 |
"(i : {l..<u}) = (l <= i & i < u)"
|
ballarin@13735
|
177 |
by (simp add: atLeastLessThan_def)
|
ballarin@13735
|
178 |
|
ballarin@13735
|
179 |
lemma greaterThanAtMost_iff [simp]:
|
nipkow@15045
|
180 |
"(i : {l<..u}) = (l < i & i <= u)"
|
ballarin@13735
|
181 |
by (simp add: greaterThanAtMost_def)
|
ballarin@13735
|
182 |
|
ballarin@13735
|
183 |
lemma atLeastAtMost_iff [simp]:
|
ballarin@13735
|
184 |
"(i : {l..u}) = (l <= i & i <= u)"
|
ballarin@13735
|
185 |
by (simp add: atLeastAtMost_def)
|
ballarin@13735
|
186 |
|
wenzelm@14577
|
187 |
text {* The above four lemmas could be declared as iffs.
|
wenzelm@14577
|
188 |
If we do so, a call to blast in Hyperreal/Star.ML, lemma @{text STAR_Int}
|
wenzelm@14577
|
189 |
seems to take forever (more than one hour). *}
|
ballarin@13735
|
190 |
|
nipkow@15554
|
191 |
subsubsection{* Emptyness and singletons *}
|
nipkow@15554
|
192 |
|
nipkow@15554
|
193 |
lemma atLeastAtMost_empty [simp]: "n < m ==> {m::'a::order..n} = {}";
|
nipkow@15554
|
194 |
by (auto simp add: atLeastAtMost_def atMost_def atLeast_def);
|
nipkow@15554
|
195 |
|
nipkow@15554
|
196 |
lemma atLeastLessThan_empty[simp]: "n \<le> m ==> {m..<n::'a::order} = {}"
|
nipkow@15554
|
197 |
by (auto simp add: atLeastLessThan_def)
|
nipkow@15554
|
198 |
|
nipkow@15554
|
199 |
lemma atLeastAtMost_singleton [simp]: "{a::'a::order..a} = {a}";
|
nipkow@15554
|
200 |
by (auto simp add: atLeastAtMost_def atMost_def atLeast_def);
|
paulson@14485
|
201 |
|
paulson@14485
|
202 |
subsection {* Intervals of natural numbers *}
|
paulson@14485
|
203 |
|
paulson@15047
|
204 |
subsubsection {* The Constant @{term lessThan} *}
|
paulson@15047
|
205 |
|
paulson@14485
|
206 |
lemma lessThan_0 [simp]: "lessThan (0::nat) = {}"
|
paulson@14485
|
207 |
by (simp add: lessThan_def)
|
paulson@14485
|
208 |
|
paulson@14485
|
209 |
lemma lessThan_Suc: "lessThan (Suc k) = insert k (lessThan k)"
|
paulson@14485
|
210 |
by (simp add: lessThan_def less_Suc_eq, blast)
|
paulson@14485
|
211 |
|
paulson@14485
|
212 |
lemma lessThan_Suc_atMost: "lessThan (Suc k) = atMost k"
|
paulson@14485
|
213 |
by (simp add: lessThan_def atMost_def less_Suc_eq_le)
|
paulson@14485
|
214 |
|
paulson@14485
|
215 |
lemma UN_lessThan_UNIV: "(UN m::nat. lessThan m) = UNIV"
|
paulson@14485
|
216 |
by blast
|
paulson@14485
|
217 |
|
paulson@15047
|
218 |
subsubsection {* The Constant @{term greaterThan} *}
|
paulson@15047
|
219 |
|
paulson@14485
|
220 |
lemma greaterThan_0 [simp]: "greaterThan 0 = range Suc"
|
paulson@14485
|
221 |
apply (simp add: greaterThan_def)
|
paulson@14485
|
222 |
apply (blast dest: gr0_conv_Suc [THEN iffD1])
|
paulson@14485
|
223 |
done
|
paulson@14485
|
224 |
|
paulson@14485
|
225 |
lemma greaterThan_Suc: "greaterThan (Suc k) = greaterThan k - {Suc k}"
|
paulson@14485
|
226 |
apply (simp add: greaterThan_def)
|
paulson@14485
|
227 |
apply (auto elim: linorder_neqE)
|
paulson@14485
|
228 |
done
|
paulson@14485
|
229 |
|
paulson@14485
|
230 |
lemma INT_greaterThan_UNIV: "(INT m::nat. greaterThan m) = {}"
|
paulson@14485
|
231 |
by blast
|
paulson@14485
|
232 |
|
paulson@15047
|
233 |
subsubsection {* The Constant @{term atLeast} *}
|
paulson@15047
|
234 |
|
paulson@14485
|
235 |
lemma atLeast_0 [simp]: "atLeast (0::nat) = UNIV"
|
paulson@14485
|
236 |
by (unfold atLeast_def UNIV_def, simp)
|
paulson@14485
|
237 |
|
paulson@14485
|
238 |
lemma atLeast_Suc: "atLeast (Suc k) = atLeast k - {k}"
|
paulson@14485
|
239 |
apply (simp add: atLeast_def)
|
paulson@14485
|
240 |
apply (simp add: Suc_le_eq)
|
paulson@14485
|
241 |
apply (simp add: order_le_less, blast)
|
paulson@14485
|
242 |
done
|
paulson@14485
|
243 |
|
paulson@14485
|
244 |
lemma atLeast_Suc_greaterThan: "atLeast (Suc k) = greaterThan k"
|
paulson@14485
|
245 |
by (auto simp add: greaterThan_def atLeast_def less_Suc_eq_le)
|
paulson@14485
|
246 |
|
paulson@14485
|
247 |
lemma UN_atLeast_UNIV: "(UN m::nat. atLeast m) = UNIV"
|
paulson@14485
|
248 |
by blast
|
paulson@14485
|
249 |
|
paulson@15047
|
250 |
subsubsection {* The Constant @{term atMost} *}
|
paulson@15047
|
251 |
|
paulson@14485
|
252 |
lemma atMost_0 [simp]: "atMost (0::nat) = {0}"
|
paulson@14485
|
253 |
by (simp add: atMost_def)
|
paulson@14485
|
254 |
|
paulson@14485
|
255 |
lemma atMost_Suc: "atMost (Suc k) = insert (Suc k) (atMost k)"
|
paulson@14485
|
256 |
apply (simp add: atMost_def)
|
paulson@14485
|
257 |
apply (simp add: less_Suc_eq order_le_less, blast)
|
paulson@14485
|
258 |
done
|
paulson@14485
|
259 |
|
paulson@14485
|
260 |
lemma UN_atMost_UNIV: "(UN m::nat. atMost m) = UNIV"
|
paulson@14485
|
261 |
by blast
|
paulson@14485
|
262 |
|
paulson@15047
|
263 |
subsubsection {* The Constant @{term atLeastLessThan} *}
|
paulson@15047
|
264 |
|
paulson@15047
|
265 |
text{*But not a simprule because some concepts are better left in terms
|
paulson@15047
|
266 |
of @{term atLeastLessThan}*}
|
paulson@15047
|
267 |
lemma atLeast0LessThan: "{0::nat..<n} = {..<n}"
|
nipkow@15042
|
268 |
by(simp add:lessThan_def atLeastLessThan_def)
|
nipkow@16041
|
269 |
(*
|
paulson@15047
|
270 |
lemma atLeastLessThan0 [simp]: "{m..<0::nat} = {}"
|
paulson@15047
|
271 |
by (simp add: atLeastLessThan_def)
|
nipkow@16041
|
272 |
*)
|
paulson@15047
|
273 |
subsubsection {* Intervals of nats with @{term Suc} *}
|
paulson@15047
|
274 |
|
paulson@15047
|
275 |
text{*Not a simprule because the RHS is too messy.*}
|
paulson@15047
|
276 |
lemma atLeastLessThanSuc:
|
paulson@15047
|
277 |
"{m..<Suc n} = (if m \<le> n then insert n {m..<n} else {})"
|
paulson@15418
|
278 |
by (auto simp add: atLeastLessThan_def)
|
paulson@15047
|
279 |
|
paulson@15418
|
280 |
lemma atLeastLessThan_singleton [simp]: "{m..<Suc m} = {m}"
|
paulson@15047
|
281 |
by (auto simp add: atLeastLessThan_def)
|
nipkow@16041
|
282 |
(*
|
paulson@15047
|
283 |
lemma atLeast_sum_LessThan [simp]: "{m + k..<k::nat} = {}"
|
paulson@15047
|
284 |
by (induct k, simp_all add: atLeastLessThanSuc)
|
paulson@15047
|
285 |
|
paulson@15047
|
286 |
lemma atLeastSucLessThan [simp]: "{Suc n..<n} = {}"
|
paulson@15047
|
287 |
by (auto simp add: atLeastLessThan_def)
|
nipkow@16041
|
288 |
*)
|
nipkow@15045
|
289 |
lemma atLeastLessThanSuc_atLeastAtMost: "{l..<Suc u} = {l..u}"
|
paulson@14485
|
290 |
by (simp add: lessThan_Suc_atMost atLeastAtMost_def atLeastLessThan_def)
|
paulson@14485
|
291 |
|
paulson@15418
|
292 |
lemma atLeastSucAtMost_greaterThanAtMost: "{Suc l..u} = {l<..u}"
|
paulson@15418
|
293 |
by (simp add: atLeast_Suc_greaterThan atLeastAtMost_def
|
paulson@14485
|
294 |
greaterThanAtMost_def)
|
paulson@14485
|
295 |
|
paulson@15418
|
296 |
lemma atLeastSucLessThan_greaterThanLessThan: "{Suc l..<u} = {l<..<u}"
|
paulson@15418
|
297 |
by (simp add: atLeast_Suc_greaterThan atLeastLessThan_def
|
paulson@14485
|
298 |
greaterThanLessThan_def)
|
paulson@14485
|
299 |
|
nipkow@15554
|
300 |
lemma atLeastAtMostSuc_conv: "m \<le> Suc n \<Longrightarrow> {m..Suc n} = insert (Suc n) {m..n}"
|
nipkow@15554
|
301 |
by (auto simp add: atLeastAtMost_def)
|
nipkow@15554
|
302 |
|
paulson@14485
|
303 |
subsubsection {* Finiteness *}
|
paulson@14485
|
304 |
|
nipkow@15045
|
305 |
lemma finite_lessThan [iff]: fixes k :: nat shows "finite {..<k}"
|
paulson@14485
|
306 |
by (induct k) (simp_all add: lessThan_Suc)
|
paulson@14485
|
307 |
|
paulson@14485
|
308 |
lemma finite_atMost [iff]: fixes k :: nat shows "finite {..k}"
|
paulson@14485
|
309 |
by (induct k) (simp_all add: atMost_Suc)
|
paulson@14485
|
310 |
|
paulson@14485
|
311 |
lemma finite_greaterThanLessThan [iff]:
|
nipkow@15045
|
312 |
fixes l :: nat shows "finite {l<..<u}"
|
paulson@14485
|
313 |
by (simp add: greaterThanLessThan_def)
|
paulson@14485
|
314 |
|
paulson@14485
|
315 |
lemma finite_atLeastLessThan [iff]:
|
nipkow@15045
|
316 |
fixes l :: nat shows "finite {l..<u}"
|
paulson@14485
|
317 |
by (simp add: atLeastLessThan_def)
|
paulson@14485
|
318 |
|
paulson@14485
|
319 |
lemma finite_greaterThanAtMost [iff]:
|
nipkow@15045
|
320 |
fixes l :: nat shows "finite {l<..u}"
|
paulson@14485
|
321 |
by (simp add: greaterThanAtMost_def)
|
paulson@14485
|
322 |
|
paulson@14485
|
323 |
lemma finite_atLeastAtMost [iff]:
|
paulson@14485
|
324 |
fixes l :: nat shows "finite {l..u}"
|
paulson@14485
|
325 |
by (simp add: atLeastAtMost_def)
|
paulson@14485
|
326 |
|
paulson@14485
|
327 |
lemma bounded_nat_set_is_finite:
|
paulson@14485
|
328 |
"(ALL i:N. i < (n::nat)) ==> finite N"
|
paulson@14485
|
329 |
-- {* A bounded set of natural numbers is finite. *}
|
paulson@14485
|
330 |
apply (rule finite_subset)
|
paulson@14485
|
331 |
apply (rule_tac [2] finite_lessThan, auto)
|
paulson@14485
|
332 |
done
|
paulson@14485
|
333 |
|
paulson@14485
|
334 |
subsubsection {* Cardinality *}
|
paulson@14485
|
335 |
|
nipkow@15045
|
336 |
lemma card_lessThan [simp]: "card {..<u} = u"
|
paulson@15251
|
337 |
by (induct u, simp_all add: lessThan_Suc)
|
paulson@14485
|
338 |
|
paulson@14485
|
339 |
lemma card_atMost [simp]: "card {..u} = Suc u"
|
paulson@14485
|
340 |
by (simp add: lessThan_Suc_atMost [THEN sym])
|
paulson@14485
|
341 |
|
nipkow@15045
|
342 |
lemma card_atLeastLessThan [simp]: "card {l..<u} = u - l"
|
nipkow@15045
|
343 |
apply (subgoal_tac "card {l..<u} = card {..<u-l}")
|
paulson@14485
|
344 |
apply (erule ssubst, rule card_lessThan)
|
nipkow@15045
|
345 |
apply (subgoal_tac "(%x. x + l) ` {..<u-l} = {l..<u}")
|
paulson@14485
|
346 |
apply (erule subst)
|
paulson@14485
|
347 |
apply (rule card_image)
|
paulson@14485
|
348 |
apply (simp add: inj_on_def)
|
paulson@14485
|
349 |
apply (auto simp add: image_def atLeastLessThan_def lessThan_def)
|
paulson@14485
|
350 |
apply arith
|
paulson@14485
|
351 |
apply (rule_tac x = "x - l" in exI)
|
paulson@14485
|
352 |
apply arith
|
paulson@14485
|
353 |
done
|
paulson@14485
|
354 |
|
paulson@15418
|
355 |
lemma card_atLeastAtMost [simp]: "card {l..u} = Suc u - l"
|
paulson@14485
|
356 |
by (subst atLeastLessThanSuc_atLeastAtMost [THEN sym], simp)
|
paulson@14485
|
357 |
|
paulson@15418
|
358 |
lemma card_greaterThanAtMost [simp]: "card {l<..u} = u - l"
|
paulson@14485
|
359 |
by (subst atLeastSucAtMost_greaterThanAtMost [THEN sym], simp)
|
paulson@14485
|
360 |
|
nipkow@15045
|
361 |
lemma card_greaterThanLessThan [simp]: "card {l<..<u} = u - Suc l"
|
paulson@14485
|
362 |
by (subst atLeastSucLessThan_greaterThanLessThan [THEN sym], simp)
|
paulson@14485
|
363 |
|
paulson@14485
|
364 |
subsection {* Intervals of integers *}
|
paulson@14485
|
365 |
|
nipkow@15045
|
366 |
lemma atLeastLessThanPlusOne_atLeastAtMost_int: "{l..<u+1} = {l..(u::int)}"
|
paulson@14485
|
367 |
by (auto simp add: atLeastAtMost_def atLeastLessThan_def)
|
paulson@14485
|
368 |
|
paulson@15418
|
369 |
lemma atLeastPlusOneAtMost_greaterThanAtMost_int: "{l+1..u} = {l<..(u::int)}"
|
paulson@14485
|
370 |
by (auto simp add: atLeastAtMost_def greaterThanAtMost_def)
|
paulson@14485
|
371 |
|
paulson@15418
|
372 |
lemma atLeastPlusOneLessThan_greaterThanLessThan_int:
|
paulson@15418
|
373 |
"{l+1..<u} = {l<..<u::int}"
|
paulson@14485
|
374 |
by (auto simp add: atLeastLessThan_def greaterThanLessThan_def)
|
paulson@14485
|
375 |
|
paulson@14485
|
376 |
subsubsection {* Finiteness *}
|
paulson@14485
|
377 |
|
paulson@15418
|
378 |
lemma image_atLeastZeroLessThan_int: "0 \<le> u ==>
|
nipkow@15045
|
379 |
{(0::int)..<u} = int ` {..<nat u}"
|
paulson@14485
|
380 |
apply (unfold image_def lessThan_def)
|
paulson@14485
|
381 |
apply auto
|
paulson@14485
|
382 |
apply (rule_tac x = "nat x" in exI)
|
paulson@14485
|
383 |
apply (auto simp add: zless_nat_conj zless_nat_eq_int_zless [THEN sym])
|
paulson@14485
|
384 |
done
|
paulson@14485
|
385 |
|
nipkow@15045
|
386 |
lemma finite_atLeastZeroLessThan_int: "finite {(0::int)..<u}"
|
paulson@14485
|
387 |
apply (case_tac "0 \<le> u")
|
paulson@14485
|
388 |
apply (subst image_atLeastZeroLessThan_int, assumption)
|
paulson@14485
|
389 |
apply (rule finite_imageI)
|
paulson@14485
|
390 |
apply auto
|
paulson@14485
|
391 |
done
|
paulson@14485
|
392 |
|
paulson@15418
|
393 |
lemma image_atLeastLessThan_int_shift:
|
nipkow@15045
|
394 |
"(%x. x + (l::int)) ` {0..<u-l} = {l..<u}"
|
nipkow@15561
|
395 |
apply (auto simp add: image_def)
|
paulson@14485
|
396 |
apply (rule_tac x = "x - l" in bexI)
|
paulson@14485
|
397 |
apply auto
|
paulson@14485
|
398 |
done
|
paulson@14485
|
399 |
|
nipkow@15045
|
400 |
lemma finite_atLeastLessThan_int [iff]: "finite {l..<u::int}"
|
nipkow@15045
|
401 |
apply (subgoal_tac "(%x. x + l) ` {0..<u-l} = {l..<u}")
|
paulson@14485
|
402 |
apply (erule subst)
|
paulson@14485
|
403 |
apply (rule finite_imageI)
|
paulson@14485
|
404 |
apply (rule finite_atLeastZeroLessThan_int)
|
paulson@14485
|
405 |
apply (rule image_atLeastLessThan_int_shift)
|
paulson@14485
|
406 |
done
|
paulson@14485
|
407 |
|
paulson@15418
|
408 |
lemma finite_atLeastAtMost_int [iff]: "finite {l..(u::int)}"
|
paulson@14485
|
409 |
by (subst atLeastLessThanPlusOne_atLeastAtMost_int [THEN sym], simp)
|
paulson@14485
|
410 |
|
paulson@15418
|
411 |
lemma finite_greaterThanAtMost_int [iff]: "finite {l<..(u::int)}"
|
paulson@14485
|
412 |
by (subst atLeastPlusOneAtMost_greaterThanAtMost_int [THEN sym], simp)
|
paulson@14485
|
413 |
|
paulson@15418
|
414 |
lemma finite_greaterThanLessThan_int [iff]: "finite {l<..<u::int}"
|
paulson@14485
|
415 |
by (subst atLeastPlusOneLessThan_greaterThanLessThan_int [THEN sym], simp)
|
paulson@14485
|
416 |
|
paulson@14485
|
417 |
subsubsection {* Cardinality *}
|
paulson@14485
|
418 |
|
nipkow@15045
|
419 |
lemma card_atLeastZeroLessThan_int: "card {(0::int)..<u} = nat u"
|
paulson@14485
|
420 |
apply (case_tac "0 \<le> u")
|
paulson@14485
|
421 |
apply (subst image_atLeastZeroLessThan_int, assumption)
|
paulson@14485
|
422 |
apply (subst card_image)
|
paulson@14485
|
423 |
apply (auto simp add: inj_on_def)
|
paulson@14485
|
424 |
done
|
paulson@14485
|
425 |
|
nipkow@15045
|
426 |
lemma card_atLeastLessThan_int [simp]: "card {l..<u} = nat (u - l)"
|
nipkow@15045
|
427 |
apply (subgoal_tac "card {l..<u} = card {0..<u-l}")
|
paulson@14485
|
428 |
apply (erule ssubst, rule card_atLeastZeroLessThan_int)
|
nipkow@15045
|
429 |
apply (subgoal_tac "(%x. x + l) ` {0..<u-l} = {l..<u}")
|
paulson@14485
|
430 |
apply (erule subst)
|
paulson@14485
|
431 |
apply (rule card_image)
|
paulson@14485
|
432 |
apply (simp add: inj_on_def)
|
paulson@14485
|
433 |
apply (rule image_atLeastLessThan_int_shift)
|
paulson@14485
|
434 |
done
|
paulson@14485
|
435 |
|
paulson@14485
|
436 |
lemma card_atLeastAtMost_int [simp]: "card {l..u} = nat (u - l + 1)"
|
paulson@14485
|
437 |
apply (subst atLeastLessThanPlusOne_atLeastAtMost_int [THEN sym])
|
paulson@14485
|
438 |
apply (auto simp add: compare_rls)
|
paulson@14485
|
439 |
done
|
paulson@14485
|
440 |
|
paulson@15418
|
441 |
lemma card_greaterThanAtMost_int [simp]: "card {l<..u} = nat (u - l)"
|
paulson@14485
|
442 |
by (subst atLeastPlusOneAtMost_greaterThanAtMost_int [THEN sym], simp)
|
paulson@14485
|
443 |
|
nipkow@15045
|
444 |
lemma card_greaterThanLessThan_int [simp]: "card {l<..<u} = nat (u - (l + 1))"
|
paulson@14485
|
445 |
by (subst atLeastPlusOneLessThan_greaterThanLessThan_int [THEN sym], simp)
|
paulson@14485
|
446 |
|
paulson@14485
|
447 |
|
paulson@13850
|
448 |
subsection {*Lemmas useful with the summation operator setsum*}
|
paulson@13850
|
449 |
|
wenzelm@14577
|
450 |
text {* For examples, see Algebra/poly/UnivPoly.thy *}
|
ballarin@13735
|
451 |
|
wenzelm@14577
|
452 |
subsubsection {* Disjoint Unions *}
|
ballarin@13735
|
453 |
|
wenzelm@14577
|
454 |
text {* Singletons and open intervals *}
|
ballarin@13735
|
455 |
|
ballarin@13735
|
456 |
lemma ivl_disj_un_singleton:
|
nipkow@15045
|
457 |
"{l::'a::linorder} Un {l<..} = {l..}"
|
nipkow@15045
|
458 |
"{..<u} Un {u::'a::linorder} = {..u}"
|
nipkow@15045
|
459 |
"(l::'a::linorder) < u ==> {l} Un {l<..<u} = {l..<u}"
|
nipkow@15045
|
460 |
"(l::'a::linorder) < u ==> {l<..<u} Un {u} = {l<..u}"
|
nipkow@15045
|
461 |
"(l::'a::linorder) <= u ==> {l} Un {l<..u} = {l..u}"
|
nipkow@15045
|
462 |
"(l::'a::linorder) <= u ==> {l..<u} Un {u} = {l..u}"
|
ballarin@14398
|
463 |
by auto
|
ballarin@13735
|
464 |
|
wenzelm@14577
|
465 |
text {* One- and two-sided intervals *}
|
ballarin@13735
|
466 |
|
ballarin@13735
|
467 |
lemma ivl_disj_un_one:
|
nipkow@15045
|
468 |
"(l::'a::linorder) < u ==> {..l} Un {l<..<u} = {..<u}"
|
nipkow@15045
|
469 |
"(l::'a::linorder) <= u ==> {..<l} Un {l..<u} = {..<u}"
|
nipkow@15045
|
470 |
"(l::'a::linorder) <= u ==> {..l} Un {l<..u} = {..u}"
|
nipkow@15045
|
471 |
"(l::'a::linorder) <= u ==> {..<l} Un {l..u} = {..u}"
|
nipkow@15045
|
472 |
"(l::'a::linorder) <= u ==> {l<..u} Un {u<..} = {l<..}"
|
nipkow@15045
|
473 |
"(l::'a::linorder) < u ==> {l<..<u} Un {u..} = {l<..}"
|
nipkow@15045
|
474 |
"(l::'a::linorder) <= u ==> {l..u} Un {u<..} = {l..}"
|
nipkow@15045
|
475 |
"(l::'a::linorder) <= u ==> {l..<u} Un {u..} = {l..}"
|
ballarin@14398
|
476 |
by auto
|
ballarin@13735
|
477 |
|
wenzelm@14577
|
478 |
text {* Two- and two-sided intervals *}
|
ballarin@13735
|
479 |
|
ballarin@13735
|
480 |
lemma ivl_disj_un_two:
|
nipkow@15045
|
481 |
"[| (l::'a::linorder) < m; m <= u |] ==> {l<..<m} Un {m..<u} = {l<..<u}"
|
nipkow@15045
|
482 |
"[| (l::'a::linorder) <= m; m < u |] ==> {l<..m} Un {m<..<u} = {l<..<u}"
|
nipkow@15045
|
483 |
"[| (l::'a::linorder) <= m; m <= u |] ==> {l..<m} Un {m..<u} = {l..<u}"
|
nipkow@15045
|
484 |
"[| (l::'a::linorder) <= m; m < u |] ==> {l..m} Un {m<..<u} = {l..<u}"
|
nipkow@15045
|
485 |
"[| (l::'a::linorder) < m; m <= u |] ==> {l<..<m} Un {m..u} = {l<..u}"
|
nipkow@15045
|
486 |
"[| (l::'a::linorder) <= m; m <= u |] ==> {l<..m} Un {m<..u} = {l<..u}"
|
nipkow@15045
|
487 |
"[| (l::'a::linorder) <= m; m <= u |] ==> {l..<m} Un {m..u} = {l..u}"
|
nipkow@15045
|
488 |
"[| (l::'a::linorder) <= m; m <= u |] ==> {l..m} Un {m<..u} = {l..u}"
|
ballarin@14398
|
489 |
by auto
|
ballarin@13735
|
490 |
|
ballarin@13735
|
491 |
lemmas ivl_disj_un = ivl_disj_un_singleton ivl_disj_un_one ivl_disj_un_two
|
ballarin@13735
|
492 |
|
wenzelm@14577
|
493 |
subsubsection {* Disjoint Intersections *}
|
ballarin@13735
|
494 |
|
wenzelm@14577
|
495 |
text {* Singletons and open intervals *}
|
ballarin@13735
|
496 |
|
ballarin@13735
|
497 |
lemma ivl_disj_int_singleton:
|
nipkow@15045
|
498 |
"{l::'a::order} Int {l<..} = {}"
|
nipkow@15045
|
499 |
"{..<u} Int {u} = {}"
|
nipkow@15045
|
500 |
"{l} Int {l<..<u} = {}"
|
nipkow@15045
|
501 |
"{l<..<u} Int {u} = {}"
|
nipkow@15045
|
502 |
"{l} Int {l<..u} = {}"
|
nipkow@15045
|
503 |
"{l..<u} Int {u} = {}"
|
ballarin@13735
|
504 |
by simp+
|
ballarin@13735
|
505 |
|
wenzelm@14577
|
506 |
text {* One- and two-sided intervals *}
|
ballarin@13735
|
507 |
|
ballarin@13735
|
508 |
lemma ivl_disj_int_one:
|
nipkow@15045
|
509 |
"{..l::'a::order} Int {l<..<u} = {}"
|
nipkow@15045
|
510 |
"{..<l} Int {l..<u} = {}"
|
nipkow@15045
|
511 |
"{..l} Int {l<..u} = {}"
|
nipkow@15045
|
512 |
"{..<l} Int {l..u} = {}"
|
nipkow@15045
|
513 |
"{l<..u} Int {u<..} = {}"
|
nipkow@15045
|
514 |
"{l<..<u} Int {u..} = {}"
|
nipkow@15045
|
515 |
"{l..u} Int {u<..} = {}"
|
nipkow@15045
|
516 |
"{l..<u} Int {u..} = {}"
|
ballarin@14398
|
517 |
by auto
|
ballarin@13735
|
518 |
|
wenzelm@14577
|
519 |
text {* Two- and two-sided intervals *}
|
ballarin@13735
|
520 |
|
ballarin@13735
|
521 |
lemma ivl_disj_int_two:
|
nipkow@15045
|
522 |
"{l::'a::order<..<m} Int {m..<u} = {}"
|
nipkow@15045
|
523 |
"{l<..m} Int {m<..<u} = {}"
|
nipkow@15045
|
524 |
"{l..<m} Int {m..<u} = {}"
|
nipkow@15045
|
525 |
"{l..m} Int {m<..<u} = {}"
|
nipkow@15045
|
526 |
"{l<..<m} Int {m..u} = {}"
|
nipkow@15045
|
527 |
"{l<..m} Int {m<..u} = {}"
|
nipkow@15045
|
528 |
"{l..<m} Int {m..u} = {}"
|
nipkow@15045
|
529 |
"{l..m} Int {m<..u} = {}"
|
ballarin@14398
|
530 |
by auto
|
ballarin@13735
|
531 |
|
ballarin@13735
|
532 |
lemmas ivl_disj_int = ivl_disj_int_singleton ivl_disj_int_one ivl_disj_int_two
|
ballarin@13735
|
533 |
|
nipkow@15542
|
534 |
subsubsection {* Some Differences *}
|
nipkow@15542
|
535 |
|
nipkow@15542
|
536 |
lemma ivl_diff[simp]:
|
nipkow@15542
|
537 |
"i \<le> n \<Longrightarrow> {i..<m} - {i..<n} = {n..<(m::'a::linorder)}"
|
nipkow@15542
|
538 |
by(auto)
|
nipkow@15542
|
539 |
|
nipkow@15542
|
540 |
|
nipkow@15542
|
541 |
subsubsection {* Some Subset Conditions *}
|
nipkow@15542
|
542 |
|
nipkow@15542
|
543 |
lemma ivl_subset[simp]:
|
nipkow@15542
|
544 |
"({i..<j} \<subseteq> {m..<n}) = (j \<le> i | m \<le> i & j \<le> (n::'a::linorder))"
|
nipkow@15542
|
545 |
apply(auto simp:linorder_not_le)
|
nipkow@15542
|
546 |
apply(rule ccontr)
|
nipkow@15542
|
547 |
apply(insert linorder_le_less_linear[of i n])
|
nipkow@15542
|
548 |
apply(clarsimp simp:linorder_not_le)
|
nipkow@15542
|
549 |
apply(fastsimp)
|
nipkow@15542
|
550 |
done
|
nipkow@15542
|
551 |
|
nipkow@15041
|
552 |
|
nipkow@15042
|
553 |
subsection {* Summation indexed over intervals *}
|
nipkow@15042
|
554 |
|
nipkow@15042
|
555 |
syntax
|
nipkow@15042
|
556 |
"_from_to_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(SUM _ = _.._./ _)" [0,0,0,10] 10)
|
nipkow@15048
|
557 |
"_from_upto_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(SUM _ = _..<_./ _)" [0,0,0,10] 10)
|
nipkow@15048
|
558 |
"_upto_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(SUM _<_./ _)" [0,0,10] 10)
|
nipkow@15042
|
559 |
syntax (xsymbols)
|
nipkow@15042
|
560 |
"_from_to_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sum>_ = _.._./ _)" [0,0,0,10] 10)
|
nipkow@15048
|
561 |
"_from_upto_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sum>_ = _..<_./ _)" [0,0,0,10] 10)
|
nipkow@15048
|
562 |
"_upto_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sum>_<_./ _)" [0,0,10] 10)
|
nipkow@15042
|
563 |
syntax (HTML output)
|
nipkow@15042
|
564 |
"_from_to_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sum>_ = _.._./ _)" [0,0,0,10] 10)
|
nipkow@15048
|
565 |
"_from_upto_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sum>_ = _..<_./ _)" [0,0,0,10] 10)
|
nipkow@15048
|
566 |
"_upto_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sum>_<_./ _)" [0,0,10] 10)
|
nipkow@15056
|
567 |
syntax (latex_sum output)
|
nipkow@15052
|
568 |
"_from_to_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"
|
nipkow@15052
|
569 |
("(3\<^raw:$\sum_{>_ = _\<^raw:}^{>_\<^raw:}$> _)" [0,0,0,10] 10)
|
nipkow@15052
|
570 |
"_from_upto_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"
|
nipkow@15052
|
571 |
("(3\<^raw:$\sum_{>_ = _\<^raw:}^{<>_\<^raw:}$> _)" [0,0,0,10] 10)
|
nipkow@15052
|
572 |
"_upto_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"
|
nipkow@15052
|
573 |
("(3\<^raw:$\sum_{>_ < _\<^raw:}$> _)" [0,0,10] 10)
|
nipkow@15042
|
574 |
|
nipkow@15048
|
575 |
translations
|
nipkow@15048
|
576 |
"\<Sum>x=a..b. t" == "setsum (%x. t) {a..b}"
|
nipkow@15048
|
577 |
"\<Sum>x=a..<b. t" == "setsum (%x. t) {a..<b}"
|
nipkow@15048
|
578 |
"\<Sum>i<n. t" == "setsum (\<lambda>i. t) {..<n}"
|
nipkow@15042
|
579 |
|
nipkow@15052
|
580 |
text{* The above introduces some pretty alternative syntaxes for
|
nipkow@15056
|
581 |
summation over intervals:
|
nipkow@15052
|
582 |
\begin{center}
|
nipkow@15052
|
583 |
\begin{tabular}{lll}
|
nipkow@15056
|
584 |
Old & New & \LaTeX\\
|
nipkow@15056
|
585 |
@{term[source]"\<Sum>x\<in>{a..b}. e"} & @{term"\<Sum>x=a..b. e"} & @{term[mode=latex_sum]"\<Sum>x=a..b. e"}\\
|
nipkow@15056
|
586 |
@{term[source]"\<Sum>x\<in>{a..<b}. e"} & @{term"\<Sum>x=a..<b. e"} & @{term[mode=latex_sum]"\<Sum>x=a..<b. e"}\\
|
nipkow@15056
|
587 |
@{term[source]"\<Sum>x\<in>{..<b}. e"} & @{term"\<Sum>x<b. e"} & @{term[mode=latex_sum]"\<Sum>x<b. e"}
|
nipkow@15052
|
588 |
\end{tabular}
|
nipkow@15052
|
589 |
\end{center}
|
nipkow@15056
|
590 |
The left column shows the term before introduction of the new syntax,
|
nipkow@15056
|
591 |
the middle column shows the new (default) syntax, and the right column
|
nipkow@15056
|
592 |
shows a special syntax. The latter is only meaningful for latex output
|
nipkow@15056
|
593 |
and has to be activated explicitly by setting the print mode to
|
nipkow@15056
|
594 |
\texttt{latex\_sum} (e.g.\ via \texttt{mode=latex\_sum} in
|
nipkow@15056
|
595 |
antiquotations). It is not the default \LaTeX\ output because it only
|
nipkow@15056
|
596 |
works well with italic-style formulae, not tt-style.
|
nipkow@15052
|
597 |
|
nipkow@15052
|
598 |
Note that for uniformity on @{typ nat} it is better to use
|
nipkow@15052
|
599 |
@{term"\<Sum>x::nat=0..<n. e"} rather than @{text"\<Sum>x<n. e"}: @{text setsum} may
|
nipkow@15052
|
600 |
not provide all lemmas available for @{term"{m..<n}"} also in the
|
nipkow@15052
|
601 |
special form for @{term"{..<n}"}. *}
|
nipkow@15052
|
602 |
|
nipkow@15542
|
603 |
(* FIXME change the simplifier's treatment of congruence rules?? *)
|
nipkow@15542
|
604 |
|
nipkow@15542
|
605 |
text{* This congruence rule should be used for sums over intervals as
|
nipkow@15542
|
606 |
the standard theorem @{text[source]setsum_cong} does not work well
|
nipkow@15542
|
607 |
with the simplifier who adds the unsimplified premise @{term"x:B"} to
|
nipkow@15542
|
608 |
the context. *}
|
nipkow@15542
|
609 |
|
nipkow@15542
|
610 |
lemma setsum_ivl_cong:
|
nipkow@15542
|
611 |
"\<lbrakk>a = c; b = d; !!x. \<lbrakk> c \<le> x; x < d \<rbrakk> \<Longrightarrow> f x = g x \<rbrakk> \<Longrightarrow>
|
nipkow@15542
|
612 |
setsum f {a..<b} = setsum g {c..<d}"
|
nipkow@15542
|
613 |
by(rule setsum_cong, simp_all)
|
nipkow@15042
|
614 |
|
nipkow@16041
|
615 |
(* FIXME why are the following simp rules but the corresponding eqns
|
nipkow@16041
|
616 |
on intervals are not? *)
|
nipkow@16041
|
617 |
|
nipkow@16041
|
618 |
lemma setsum_lessThan_Suc[simp]: "(\<Sum>i < Suc n. f i) = (\<Sum>i < n. f i) + f n"
|
nipkow@16041
|
619 |
by (simp add:lessThan_Suc add_ac)
|
nipkow@15041
|
620 |
|
nipkow@15911
|
621 |
lemma setsum_cl_ivl_Suc[simp]:
|
nipkow@15561
|
622 |
"setsum f {m..Suc n} = (if Suc n < m then 0 else setsum f {m..n} + f(Suc n))"
|
nipkow@15561
|
623 |
by (auto simp:add_ac atLeastAtMostSuc_conv)
|
nipkow@15561
|
624 |
|
nipkow@15911
|
625 |
lemma setsum_op_ivl_Suc[simp]:
|
nipkow@15561
|
626 |
"setsum f {m..<Suc n} = (if n < m then 0 else setsum f {m..<n} + f(n))"
|
nipkow@15561
|
627 |
by (auto simp:add_ac atLeastLessThanSuc)
|
nipkow@16041
|
628 |
(*
|
nipkow@15561
|
629 |
lemma setsum_cl_ivl_add_one_nat: "(n::nat) <= m + 1 ==>
|
nipkow@15561
|
630 |
(\<Sum>i=n..m+1. f i) = (\<Sum>i=n..m. f i) + f(m + 1)"
|
nipkow@15561
|
631 |
by (auto simp:add_ac atLeastAtMostSuc_conv)
|
nipkow@16041
|
632 |
*)
|
nipkow@15539
|
633 |
lemma setsum_add_nat_ivl: "\<lbrakk> m \<le> n; n \<le> p \<rbrakk> \<Longrightarrow>
|
nipkow@15539
|
634 |
setsum f {m..<n} + setsum f {n..<p} = setsum f {m..<p::nat}"
|
nipkow@15539
|
635 |
by (simp add:setsum_Un_disjoint[symmetric] ivl_disj_int ivl_disj_un)
|
nipkow@15539
|
636 |
|
nipkow@15539
|
637 |
lemma setsum_diff_nat_ivl:
|
nipkow@15539
|
638 |
fixes f :: "nat \<Rightarrow> 'a::ab_group_add"
|
nipkow@15539
|
639 |
shows "\<lbrakk> m \<le> n; n \<le> p \<rbrakk> \<Longrightarrow>
|
nipkow@15539
|
640 |
setsum f {m..<p} - setsum f {m..<n} = setsum f {n..<p}"
|
nipkow@15539
|
641 |
using setsum_add_nat_ivl [of m n p f,symmetric]
|
nipkow@15539
|
642 |
apply (simp add: add_ac)
|
nipkow@15539
|
643 |
done
|
nipkow@15539
|
644 |
|
nipkow@15539
|
645 |
lemma setsum_shift_bounds_nat_ivl:
|
nipkow@15539
|
646 |
"setsum f {m+k..<n+k} = setsum (%i. f(i + k)){m..<n::nat}"
|
nipkow@15539
|
647 |
by (induct "n", auto simp:atLeastLessThanSuc)
|
nipkow@15539
|
648 |
|
paulson@15418
|
649 |
|
paulson@15418
|
650 |
ML
|
paulson@15418
|
651 |
{*
|
paulson@15418
|
652 |
val Compl_atLeast = thm "Compl_atLeast";
|
paulson@15418
|
653 |
val Compl_atMost = thm "Compl_atMost";
|
paulson@15418
|
654 |
val Compl_greaterThan = thm "Compl_greaterThan";
|
paulson@15418
|
655 |
val Compl_lessThan = thm "Compl_lessThan";
|
paulson@15418
|
656 |
val INT_greaterThan_UNIV = thm "INT_greaterThan_UNIV";
|
paulson@15418
|
657 |
val UN_atLeast_UNIV = thm "UN_atLeast_UNIV";
|
paulson@15418
|
658 |
val UN_atMost_UNIV = thm "UN_atMost_UNIV";
|
paulson@15418
|
659 |
val UN_lessThan_UNIV = thm "UN_lessThan_UNIV";
|
paulson@15418
|
660 |
val atLeastAtMost_def = thm "atLeastAtMost_def";
|
paulson@15418
|
661 |
val atLeastAtMost_iff = thm "atLeastAtMost_iff";
|
paulson@15418
|
662 |
val atLeastLessThan_def = thm "atLeastLessThan_def";
|
paulson@15418
|
663 |
val atLeastLessThan_iff = thm "atLeastLessThan_iff";
|
paulson@15418
|
664 |
val atLeast_0 = thm "atLeast_0";
|
paulson@15418
|
665 |
val atLeast_Suc = thm "atLeast_Suc";
|
paulson@15418
|
666 |
val atLeast_def = thm "atLeast_def";
|
paulson@15418
|
667 |
val atLeast_iff = thm "atLeast_iff";
|
paulson@15418
|
668 |
val atMost_0 = thm "atMost_0";
|
paulson@15418
|
669 |
val atMost_Int_atLeast = thm "atMost_Int_atLeast";
|
paulson@15418
|
670 |
val atMost_Suc = thm "atMost_Suc";
|
paulson@15418
|
671 |
val atMost_def = thm "atMost_def";
|
paulson@15418
|
672 |
val atMost_iff = thm "atMost_iff";
|
paulson@15418
|
673 |
val greaterThanAtMost_def = thm "greaterThanAtMost_def";
|
paulson@15418
|
674 |
val greaterThanAtMost_iff = thm "greaterThanAtMost_iff";
|
paulson@15418
|
675 |
val greaterThanLessThan_def = thm "greaterThanLessThan_def";
|
paulson@15418
|
676 |
val greaterThanLessThan_iff = thm "greaterThanLessThan_iff";
|
paulson@15418
|
677 |
val greaterThan_0 = thm "greaterThan_0";
|
paulson@15418
|
678 |
val greaterThan_Suc = thm "greaterThan_Suc";
|
paulson@15418
|
679 |
val greaterThan_def = thm "greaterThan_def";
|
paulson@15418
|
680 |
val greaterThan_iff = thm "greaterThan_iff";
|
paulson@15418
|
681 |
val ivl_disj_int = thms "ivl_disj_int";
|
paulson@15418
|
682 |
val ivl_disj_int_one = thms "ivl_disj_int_one";
|
paulson@15418
|
683 |
val ivl_disj_int_singleton = thms "ivl_disj_int_singleton";
|
paulson@15418
|
684 |
val ivl_disj_int_two = thms "ivl_disj_int_two";
|
paulson@15418
|
685 |
val ivl_disj_un = thms "ivl_disj_un";
|
paulson@15418
|
686 |
val ivl_disj_un_one = thms "ivl_disj_un_one";
|
paulson@15418
|
687 |
val ivl_disj_un_singleton = thms "ivl_disj_un_singleton";
|
paulson@15418
|
688 |
val ivl_disj_un_two = thms "ivl_disj_un_two";
|
paulson@15418
|
689 |
val lessThan_0 = thm "lessThan_0";
|
paulson@15418
|
690 |
val lessThan_Suc = thm "lessThan_Suc";
|
paulson@15418
|
691 |
val lessThan_Suc_atMost = thm "lessThan_Suc_atMost";
|
paulson@15418
|
692 |
val lessThan_def = thm "lessThan_def";
|
paulson@15418
|
693 |
val lessThan_iff = thm "lessThan_iff";
|
paulson@15418
|
694 |
val single_Diff_lessThan = thm "single_Diff_lessThan";
|
paulson@15418
|
695 |
|
paulson@15418
|
696 |
val bounded_nat_set_is_finite = thm "bounded_nat_set_is_finite";
|
paulson@15418
|
697 |
val finite_atMost = thm "finite_atMost";
|
paulson@15418
|
698 |
val finite_lessThan = thm "finite_lessThan";
|
paulson@15418
|
699 |
*}
|
paulson@15418
|
700 |
|
nipkow@8924
|
701 |
end
|