src/HOL/SetInterval.thy
 author nipkow Thu Sep 29 15:31:34 2005 +0200 (2005-09-29) changeset 17719 2e75155c5ed5 parent 17149 e2b19c92ef51 child 19022 0e6ec4fd204c permissions -rw-r--r--
Added a few lemmas
 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  "{.. '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 '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<.. 'a set" ("(1{_..<_})")  nipkow@15045  33  "{l.. '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  51  "{)m..n(}" => "{m<.. "{m.. "{m<..n}"  nipkow@15045  54 nipkow@15048  55 nipkow@15048  56 text{* A note of warning when using @{term"{.. 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\ _\_./ _)" 10)  kleing@14418  68  "@UNION_less" :: "nat => nat => 'b set => 'b set" ("(3\ _<_./ _)" 10)  kleing@14418  69  "@INTER_le" :: "nat => nat => 'b set => 'b set" ("(3\ _\_./ _)" 10)  kleing@14418  70  "@INTER_less" :: "nat => nat => 'b set => 'b set" ("(3\ _<_./ _)" 10)  kleing@14418  71 kleing@14418  72 syntax (xsymbols)  wenzelm@14846  73  "@UNION_le" :: "nat \ nat => 'b set => 'b set" ("(3\(00\<^bsub>_ \ _\<^esub>)/ _)" 10)  wenzelm@14846  74  "@UNION_less" :: "nat \ nat => 'b set => 'b set" ("(3\(00\<^bsub>_ < _\<^esub>)/ _)" 10)  wenzelm@14846  75  "@INTER_le" :: "nat \ nat => 'b set => 'b set" ("(3\(00\<^bsub>_ \ _\<^esub>)/ _)" 10)  wenzelm@14846  76  "@INTER_less" :: "nat \ nat => 'b set => 'b set" ("(3\(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 atLeast y) = (y \ (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 \ greaterThan y) = (y \ (x::'a::linorder))"  paulson@15418  138 apply (auto simp add: greaterThan_def)  paulson@15418  139  apply (subst linorder_not_less [symmetric], blast)  paulson@13850  140 done  paulson@13850  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  paulson@13850  148 paulson@15418  149 lemma atMost_subset_iff [iff]: "(atMost x \ atMost y) = (x \ (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 \ lessThan y) = (x \ (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)  ballarin@13735  166 done  ballarin@13735  167 ballarin@13735  168 paulson@13850  169 subsection {*Two-sided intervals*}  ballarin@13735  170 ballarin@13735  171 lemma greaterThanLessThan_iff [simp]:  nipkow@15045  172  "(i : {l<.. {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 \ m ==> {m.. k ==> {k<..(l::'a::order)} = {}"  nipkow@17719  200 by(auto simp:greaterThanAtMost_def greaterThan_def atMost_def)  nipkow@17719  201 nipkow@17719  202 lemma greaterThanLessThan_empty[simp]:"l \ k ==> {k<..(l::'a::order)} = {}"  nipkow@17719  203 by(auto simp:greaterThanLessThan_def greaterThan_def lessThan_def)  nipkow@17719  204 nipkow@15554  205 lemma atLeastAtMost_singleton [simp]: "{a::'a::order..a} = {a}";  nipkow@17719  206 by (auto simp add: atLeastAtMost_def atMost_def atLeast_def);  paulson@14485  207 paulson@14485  208 subsection {* Intervals of natural numbers *}  paulson@14485  209 paulson@15047  210 subsubsection {* The Constant @{term lessThan} *}  paulson@15047  211 paulson@14485  212 lemma lessThan_0 [simp]: "lessThan (0::nat) = {}"  paulson@14485  213 by (simp add: lessThan_def)  paulson@14485  214 paulson@14485  215 lemma lessThan_Suc: "lessThan (Suc k) = insert k (lessThan k)"  paulson@14485  216 by (simp add: lessThan_def less_Suc_eq, blast)  paulson@14485  217 paulson@14485  218 lemma lessThan_Suc_atMost: "lessThan (Suc k) = atMost k"  paulson@14485  219 by (simp add: lessThan_def atMost_def less_Suc_eq_le)  paulson@14485  220 paulson@14485  221 lemma UN_lessThan_UNIV: "(UN m::nat. lessThan m) = UNIV"  paulson@14485  222 by blast  paulson@14485  223 paulson@15047  224 subsubsection {* The Constant @{term greaterThan} *}  paulson@15047  225 paulson@14485  226 lemma greaterThan_0 [simp]: "greaterThan 0 = range Suc"  paulson@14485  227 apply (simp add: greaterThan_def)  paulson@14485  228 apply (blast dest: gr0_conv_Suc [THEN iffD1])  paulson@14485  229 done  paulson@14485  230 paulson@14485  231 lemma greaterThan_Suc: "greaterThan (Suc k) = greaterThan k - {Suc k}"  paulson@14485  232 apply (simp add: greaterThan_def)  paulson@14485  233 apply (auto elim: linorder_neqE)  paulson@14485  234 done  paulson@14485  235 paulson@14485  236 lemma INT_greaterThan_UNIV: "(INT m::nat. greaterThan m) = {}"  paulson@14485  237 by blast  paulson@14485  238 paulson@15047  239 subsubsection {* The Constant @{term atLeast} *}  paulson@15047  240 paulson@14485  241 lemma atLeast_0 [simp]: "atLeast (0::nat) = UNIV"  paulson@14485  242 by (unfold atLeast_def UNIV_def, simp)  paulson@14485  243 paulson@14485  244 lemma atLeast_Suc: "atLeast (Suc k) = atLeast k - {k}"  paulson@14485  245 apply (simp add: atLeast_def)  paulson@14485  246 apply (simp add: Suc_le_eq)  paulson@14485  247 apply (simp add: order_le_less, blast)  paulson@14485  248 done  paulson@14485  249 paulson@14485  250 lemma atLeast_Suc_greaterThan: "atLeast (Suc k) = greaterThan k"  paulson@14485  251  by (auto simp add: greaterThan_def atLeast_def less_Suc_eq_le)  paulson@14485  252 paulson@14485  253 lemma UN_atLeast_UNIV: "(UN m::nat. atLeast m) = UNIV"  paulson@14485  254 by blast  paulson@14485  255 paulson@15047  256 subsubsection {* The Constant @{term atMost} *}  paulson@15047  257 paulson@14485  258 lemma atMost_0 [simp]: "atMost (0::nat) = {0}"  paulson@14485  259 by (simp add: atMost_def)  paulson@14485  260 paulson@14485  261 lemma atMost_Suc: "atMost (Suc k) = insert (Suc k) (atMost k)"  paulson@14485  262 apply (simp add: atMost_def)  paulson@14485  263 apply (simp add: less_Suc_eq order_le_less, blast)  paulson@14485  264 done  paulson@14485  265 paulson@14485  266 lemma UN_atMost_UNIV: "(UN m::nat. atMost m) = UNIV"  paulson@14485  267 by blast  paulson@14485  268 paulson@15047  269 subsubsection {* The Constant @{term atLeastLessThan} *}  paulson@15047  270 paulson@15047  271 text{*But not a simprule because some concepts are better left in terms  paulson@15047  272  of @{term atLeastLessThan}*}  paulson@15047  273 lemma atLeast0LessThan: "{0::nat.. n then insert n {m.. Suc n \ {m..Suc n} = insert (Suc n) {m..n}"  nipkow@15554  307 by (auto simp add: atLeastAtMost_def)  nipkow@15554  308 nipkow@16733  309 subsubsection {* Image *}  nipkow@16733  310 nipkow@16733  311 lemma image_add_atLeastAtMost:  nipkow@16733  312  "(%n::nat. n+k)  {i..j} = {i+k..j+k}" (is "?A = ?B")  nipkow@16733  313 proof  nipkow@16733  314  show "?A \ ?B" by auto  nipkow@16733  315 next  nipkow@16733  316  show "?B \ ?A"  nipkow@16733  317  proof  nipkow@16733  318  fix n assume a: "n : ?B"  nipkow@16733  319  hence "n - k : {i..j}" by auto arith+  nipkow@16733  320  moreover have "n = (n - k) + k" using a by auto  nipkow@16733  321  ultimately show "n : ?A" by blast  nipkow@16733  322  qed  nipkow@16733  323 qed  nipkow@16733  324 nipkow@16733  325 lemma image_add_atLeastLessThan:  nipkow@16733  326  "(%n::nat. n+k)  {i.. ?B" by auto  nipkow@16733  329 next  nipkow@16733  330  show "?B \ ?A"  nipkow@16733  331  proof  nipkow@16733  332  fix n assume a: "n : ?B"  nipkow@16733  333  hence "n - k : {i.. finite N"  paulson@14485  381  -- {* A bounded set of natural numbers is finite. *}  paulson@14485  382  apply (rule finite_subset)  paulson@14485  383  apply (rule_tac [2] finite_lessThan, auto)  paulson@14485  384  done  paulson@14485  385 paulson@14485  386 subsubsection {* Cardinality *}  paulson@14485  387 nipkow@15045  388 lemma card_lessThan [simp]: "card {.. u ==>  nipkow@15045  431  {(0::int).. u")  paulson@14485  440  apply (subst image_atLeastZeroLessThan_int, assumption)  paulson@14485  441  apply (rule finite_imageI)  paulson@14485  442  apply auto  paulson@14485  443  done  paulson@14485  444 nipkow@15045  445 lemma finite_atLeastLessThan_int [iff]: "finite {l.. u")  paulson@14485  466  apply (subst image_atLeastZeroLessThan_int, assumption)  paulson@14485  467  apply (subst card_image)  paulson@14485  468  apply (auto simp add: inj_on_def)  paulson@14485  469  done  paulson@14485  470 nipkow@15045  471 lemma card_atLeastLessThan_int [simp]: "card {l.. {l} Un {l<.. {l<.. {l} Un {l<..u} = {l..u}"  nipkow@15045  507  "(l::'a::linorder) <= u ==> {l.. {..l} Un {l<.. {.. {..l} Un {l<..u} = {..u}"  nipkow@15045  516  "(l::'a::linorder) <= u ==> {.. {l<..u} Un {u<..} = {l<..}"  nipkow@15045  518  "(l::'a::linorder) < u ==> {l<.. {l..u} Un {u<..} = {l..}"  nipkow@15045  520  "(l::'a::linorder) <= u ==> {l.. {l<.. {l<..m} Un {m<.. {l.. {l..m} Un {m<.. {l<.. {l<..m} Un {m<..u} = {l<..u}"  nipkow@15045  532  "[| (l::'a::linorder) <= m; m <= u |] ==> {l.. {l..m} Un {m<..u} = {l..u}"  ballarin@14398  534 by auto  ballarin@13735  535 ballarin@13735  536 lemmas ivl_disj_un = ivl_disj_un_singleton ivl_disj_un_one ivl_disj_un_two  ballarin@13735  537 wenzelm@14577  538 subsubsection {* Disjoint Intersections *}  ballarin@13735  539 wenzelm@14577  540 text {* Singletons and open intervals *}  ballarin@13735  541 ballarin@13735  542 lemma ivl_disj_int_singleton:  nipkow@15045  543  "{l::'a::order} Int {l<..} = {}"  nipkow@15045  544  "{.. n \ {i.. {m.. i | m \ i & j \ (n::'a::linorder))"  nipkow@15542  590 apply(auto simp:linorder_not_le)  nipkow@15542  591 apply(rule ccontr)  nipkow@15542  592 apply(insert linorder_le_less_linear[of i n])  nipkow@15542  593 apply(clarsimp simp:linorder_not_le)  nipkow@15542  594 apply(fastsimp)  nipkow@15542  595 done  nipkow@15542  596 nipkow@15041  597 nipkow@15042  598 subsection {* Summation indexed over intervals *}  nipkow@15042  599 nipkow@15042  600 syntax  nipkow@15042  601  "_from_to_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b" ("(SUM _ = _.._./ _)" [0,0,0,10] 10)  nipkow@15048  602  "_from_upto_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b" ("(SUM _ = _..<_./ _)" [0,0,0,10] 10)  nipkow@16052  603  "_upt_setsum" :: "idt \ 'a \ 'b \ 'b" ("(SUM _<_./ _)" [0,0,10] 10)  nipkow@16052  604  "_upto_setsum" :: "idt \ 'a \ 'b \ 'b" ("(SUM _<=_./ _)" [0,0,10] 10)  nipkow@15042  605 syntax (xsymbols)  nipkow@15042  606  "_from_to_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b" ("(3\_ = _.._./ _)" [0,0,0,10] 10)  nipkow@15048  607  "_from_upto_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b" ("(3\_ = _..<_./ _)" [0,0,0,10] 10)  nipkow@16052  608  "_upt_setsum" :: "idt \ 'a \ 'b \ 'b" ("(3\_<_./ _)" [0,0,10] 10)  nipkow@16052  609  "_upto_setsum" :: "idt \ 'a \ 'b \ 'b" ("(3\_\_./ _)" [0,0,10] 10)  nipkow@15042  610 syntax (HTML output)  nipkow@15042  611  "_from_to_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b" ("(3\_ = _.._./ _)" [0,0,0,10] 10)  nipkow@15048  612  "_from_upto_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b" ("(3\_ = _..<_./ _)" [0,0,0,10] 10)  nipkow@16052  613  "_upt_setsum" :: "idt \ 'a \ 'b \ 'b" ("(3\_<_./ _)" [0,0,10] 10)  nipkow@16052  614  "_upto_setsum" :: "idt \ 'a \ 'b \ 'b" ("(3\_\_./ _)" [0,0,10] 10)  nipkow@15056  615 syntax (latex_sum output)  nipkow@15052  616  "_from_to_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b"  nipkow@15052  617  ("(3\<^raw:$\sum_{>_ = _\<^raw:}^{>_\<^raw:}$> _)" [0,0,0,10] 10)  nipkow@15052  618  "_from_upto_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b"  nipkow@15052  619  ("(3\<^raw:$\sum_{>_ = _\<^raw:}^{<>_\<^raw:}$> _)" [0,0,0,10] 10)  nipkow@16052  620  "_upt_setsum" :: "idt \ 'a \ 'b \ 'b"  nipkow@16052  621  ("(3\<^raw:$\sum_{>_ < _\<^raw:}$> _)" [0,0,10] 10)  nipkow@15052  622  "_upto_setsum" :: "idt \ 'a \ 'b \ 'b"  nipkow@16052  623  ("(3\<^raw:$\sum_{>_ \ _\<^raw:}$> _)" [0,0,10] 10)  nipkow@15041  624 nipkow@15048  625 translations  nipkow@15048  626  "\x=a..b. t" == "setsum (%x. t) {a..b}"  nipkow@15048  627  "\x=a..i\n. t" == "setsum (\i. t) {..n}"  nipkow@15048  629  "\ii. t) {..x\{a..b}. e"} & @{term"\x=a..b. e"} & @{term[mode=latex_sum]"\x=a..b. e"}\\  nipkow@15056  637 @{term[source]"\x\{a..x=a..x=a..x\{..b}. e"} & @{term"\x\b. e"} & @{term[mode=latex_sum]"\x\b. e"}\\  nipkow@15056  639 @{term[source]"\x\{..xxx::nat=0..xa = c; b = d; !!x. \ c \ x; x < d \ \ f x = g x \ \  nipkow@15542  662  setsum f {a..i \ Suc n. f i) = (\i \ n. f i) + f(Suc n)"  nipkow@16052  669 by (simp add:atMost_Suc add_ac)  nipkow@16052  670 nipkow@16041  671 lemma setsum_lessThan_Suc[simp]: "(\i < Suc n. f i) = (\i < n. f i) + f n"  nipkow@16041  672 by (simp add:lessThan_Suc add_ac)  nipkow@15041  673 nipkow@15911  674 lemma setsum_cl_ivl_Suc[simp]:  nipkow@15561  675  "setsum f {m..Suc n} = (if Suc n < m then 0 else setsum f {m..n} + f(Suc n))"  nipkow@15561  676 by (auto simp:add_ac atLeastAtMostSuc_conv)  nipkow@15561  677 nipkow@15911  678 lemma setsum_op_ivl_Suc[simp]:  nipkow@15561  679  "setsum f {m..  nipkow@15561  683  (\i=n..m+1. f i) = (\i=n..m. f i) + f(m + 1)"  nipkow@15561  684 by (auto simp:add_ac atLeastAtMostSuc_conv)  nipkow@16041  685 *)  nipkow@15539  686 lemma setsum_add_nat_ivl: "\ m \ n; n \ p \ \  nipkow@15539  687  setsum f {m.. 'a::ab_group_add"  nipkow@15539  692 shows "\ m \ n; n \ p \ \  nipkow@15539  693 ` setsum f {m.. (\i=0..