src/HOL/SetInterval.thy
 author wenzelm Fri Mar 28 19:43:54 2008 +0100 (2008-03-28) changeset 26462 dac4e2bce00d parent 26105 ae06618225ec child 27656 d4f6e64ee7cc permissions -rw-r--r--
avoid rebinding of existing facts;
 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  haftmann@25919  13 imports Int  nipkow@15131  14 begin  nipkow@8924  15 nipkow@24691  16 context ord  nipkow@24691  17 begin  nipkow@24691  18 definition  haftmann@25062  19  lessThan :: "'a => 'a set" ("(1{..<_})") where  haftmann@25062  20  "{.. 'a set" ("(1{.._})") where  haftmann@25062  24  "{..u} == {x. x \ u}"  nipkow@24691  25 nipkow@24691  26 definition  haftmann@25062  27  greaterThan :: "'a => 'a set" ("(1{_<..})") where  haftmann@25062  28  "{l<..} == {x. l 'a set" ("(1{_..})") where  haftmann@25062  32  "{l..} == {x. l\x}"  nipkow@24691  33 nipkow@24691  34 definition  haftmann@25062  35  greaterThanLessThan :: "'a => 'a => 'a set" ("(1{_<..<_})") where  haftmann@25062  36  "{l<.. 'a => 'a set" ("(1{_..<_})") where  haftmann@25062  40  "{l.. 'a => 'a set" ("(1{_<.._})") where  haftmann@25062  44  "{l<..u} == {l<..} Int {..u}"  nipkow@24691  45 nipkow@24691  46 definition  haftmann@25062  47  atLeastAtMost :: "'a => 'a => 'a set" ("(1{_.._})") where  haftmann@25062  48  "{l..u} == {l..} Int {..u}"  nipkow@24691  49 nipkow@24691  50 end  nipkow@24691  51 (*  nipkow@8924  52 constdefs  nipkow@15045  53  lessThan :: "('a::ord) => 'a set" ("(1{..<_})")  nipkow@15045  54  "{.. 'a set" ("(1{.._})")  wenzelm@11609  57  "{..u} == {x. x<=u}"  nipkow@8924  58 nipkow@15045  59  greaterThan :: "('a::ord) => 'a set" ("(1{_<..})")  nipkow@15045  60  "{l<..} == {x. l 'a set" ("(1{_..})")  wenzelm@11609  63  "{l..} == {x. l<=x}"  nipkow@8924  64 nipkow@15045  65  greaterThanLessThan :: "['a::ord, 'a] => 'a set" ("(1{_<..<_})")  nipkow@15045  66  "{l<.. 'a set" ("(1{_..<_})")  nipkow@15045  69  "{l.. 'a set" ("(1{_<.._})")  nipkow@15045  72  "{l<..u} == {l<..} Int {..u}"  ballarin@13735  73 ballarin@13735  74  atLeastAtMost :: "['a::ord, 'a] => 'a set" ("(1{_.._})")  ballarin@13735  75  "{l..u} == {l..} Int {..u}"  nipkow@24691  76 *)  ballarin@13735  77 nipkow@15048  78 text{* A note of warning when using @{term"{.. nat => 'b set => 'b set" ("(3UN _<=_./ _)" 10)  kleing@14418  84  "@UNION_less" :: "nat => nat => 'b set => 'b set" ("(3UN _<_./ _)" 10)  kleing@14418  85  "@INTER_le" :: "nat => nat => 'b set => 'b set" ("(3INT _<=_./ _)" 10)  kleing@14418  86  "@INTER_less" :: "nat => nat => 'b set => 'b set" ("(3INT _<_./ _)" 10)  kleing@14418  87 kleing@14418  88 syntax (input)  kleing@14418  89  "@UNION_le" :: "nat => nat => 'b set => 'b set" ("(3\ _\_./ _)" 10)  kleing@14418  90  "@UNION_less" :: "nat => nat => 'b set => 'b set" ("(3\ _<_./ _)" 10)  kleing@14418  91  "@INTER_le" :: "nat => nat => 'b set => 'b set" ("(3\ _\_./ _)" 10)  kleing@14418  92  "@INTER_less" :: "nat => nat => 'b set => 'b set" ("(3\ _<_./ _)" 10)  kleing@14418  93 kleing@14418  94 syntax (xsymbols)  wenzelm@14846  95  "@UNION_le" :: "nat \ nat => 'b set => 'b set" ("(3\(00\<^bsub>_ \ _\<^esub>)/ _)" 10)  wenzelm@14846  96  "@UNION_less" :: "nat \ nat => 'b set => 'b set" ("(3\(00\<^bsub>_ < _\<^esub>)/ _)" 10)  wenzelm@14846  97  "@INTER_le" :: "nat \ nat => 'b set => 'b set" ("(3\(00\<^bsub>_ \ _\<^esub>)/ _)" 10)  wenzelm@14846  98  "@INTER_less" :: "nat \ nat => 'b set => 'b set" ("(3\(00\<^bsub>_ < _\<^esub>)/ _)" 10)  kleing@14418  99 kleing@14418  100 translations  kleing@14418  101  "UN i<=n. A" == "UN i:{..n}. A"  nipkow@15045  102  "UN i atLeast y) = (y \ (x::'a::order))"  paulson@15418  150 by (blast intro: order_trans)  paulson@13850  151 paulson@13850  152 lemma atLeast_eq_iff [iff]:  paulson@15418  153  "(atLeast x = atLeast y) = (x = (y::'a::linorder))"  paulson@13850  154 by (blast intro: order_antisym order_trans)  paulson@13850  155 paulson@13850  156 lemma greaterThan_subset_iff [iff]:  paulson@15418  157  "(greaterThan x \ greaterThan y) = (y \ (x::'a::linorder))"  paulson@15418  158 apply (auto simp add: greaterThan_def)  paulson@15418  159  apply (subst linorder_not_less [symmetric], blast)  paulson@13850  160 done  paulson@13850  161 paulson@13850  162 lemma greaterThan_eq_iff [iff]:  paulson@15418  163  "(greaterThan x = greaterThan y) = (x = (y::'a::linorder))"  paulson@15418  164 apply (rule iffI)  paulson@15418  165  apply (erule equalityE)  paulson@15418  166  apply (simp_all add: greaterThan_subset_iff)  paulson@13850  167 done  paulson@13850  168 paulson@15418  169 lemma atMost_subset_iff [iff]: "(atMost x \ atMost y) = (x \ (y::'a::order))"  paulson@13850  170 by (blast intro: order_trans)  paulson@13850  171 paulson@15418  172 lemma atMost_eq_iff [iff]: "(atMost x = atMost y) = (x = (y::'a::linorder))"  paulson@13850  173 by (blast intro: order_antisym order_trans)  paulson@13850  174 paulson@13850  175 lemma lessThan_subset_iff [iff]:  paulson@15418  176  "(lessThan x \ lessThan y) = (x \ (y::'a::linorder))"  paulson@15418  177 apply (auto simp add: lessThan_def)  paulson@15418  178  apply (subst linorder_not_less [symmetric], blast)  paulson@13850  179 done  paulson@13850  180 paulson@13850  181 lemma lessThan_eq_iff [iff]:  paulson@15418  182  "(lessThan x = lessThan y) = (x = (y::'a::linorder))"  paulson@15418  183 apply (rule iffI)  paulson@15418  184  apply (erule equalityE)  paulson@15418  185  apply (simp_all add: lessThan_subset_iff)  ballarin@13735  186 done  ballarin@13735  187 ballarin@13735  188 paulson@13850  189 subsection {*Two-sided intervals*}  ballarin@13735  190 nipkow@24691  191 context ord  nipkow@24691  192 begin  nipkow@24691  193 paulson@24286  194 lemma greaterThanLessThan_iff [simp,noatp]:  haftmann@25062  195  "(i : {l<.. {m..n} = {}";  nipkow@24691  221 by (auto simp add: atLeastAtMost_def atMost_def atLeast_def)  nipkow@24691  222 haftmann@25062  223 lemma atLeastLessThan_empty[simp]: "n \ m ==> {m.. k ==> {k<..l} = {}"  nipkow@17719  227 by(auto simp:greaterThanAtMost_def greaterThan_def atMost_def)  nipkow@17719  228 haftmann@25062  229 lemma greaterThanLessThan_empty[simp]:"l \ k ==> {k<..l} = {}"  nipkow@17719  230 by(auto simp:greaterThanLessThan_def greaterThan_def lessThan_def)  nipkow@17719  231 haftmann@25062  232 lemma atLeastAtMost_singleton [simp]: "{a..a} = {a}"  nipkow@24691  233 by (auto simp add: atLeastAtMost_def atMost_def atLeast_def)  nipkow@24691  234 nipkow@24691  235 end  paulson@14485  236 paulson@14485  237 subsection {* Intervals of natural numbers *}  paulson@14485  238 paulson@15047  239 subsubsection {* The Constant @{term lessThan} *}  paulson@15047  240 paulson@14485  241 lemma lessThan_0 [simp]: "lessThan (0::nat) = {}"  paulson@14485  242 by (simp add: lessThan_def)  paulson@14485  243 paulson@14485  244 lemma lessThan_Suc: "lessThan (Suc k) = insert k (lessThan k)"  paulson@14485  245 by (simp add: lessThan_def less_Suc_eq, blast)  paulson@14485  246 paulson@14485  247 lemma lessThan_Suc_atMost: "lessThan (Suc k) = atMost k"  paulson@14485  248 by (simp add: lessThan_def atMost_def less_Suc_eq_le)  paulson@14485  249 paulson@14485  250 lemma UN_lessThan_UNIV: "(UN m::nat. lessThan m) = UNIV"  paulson@14485  251 by blast  paulson@14485  252 paulson@15047  253 subsubsection {* The Constant @{term greaterThan} *}  paulson@15047  254 paulson@14485  255 lemma greaterThan_0 [simp]: "greaterThan 0 = range Suc"  paulson@14485  256 apply (simp add: greaterThan_def)  paulson@14485  257 apply (blast dest: gr0_conv_Suc [THEN iffD1])  paulson@14485  258 done  paulson@14485  259 paulson@14485  260 lemma greaterThan_Suc: "greaterThan (Suc k) = greaterThan k - {Suc k}"  paulson@14485  261 apply (simp add: greaterThan_def)  paulson@14485  262 apply (auto elim: linorder_neqE)  paulson@14485  263 done  paulson@14485  264 paulson@14485  265 lemma INT_greaterThan_UNIV: "(INT m::nat. greaterThan m) = {}"  paulson@14485  266 by blast  paulson@14485  267 paulson@15047  268 subsubsection {* The Constant @{term atLeast} *}  paulson@15047  269 paulson@14485  270 lemma atLeast_0 [simp]: "atLeast (0::nat) = UNIV"  paulson@14485  271 by (unfold atLeast_def UNIV_def, simp)  paulson@14485  272 paulson@14485  273 lemma atLeast_Suc: "atLeast (Suc k) = atLeast k - {k}"  paulson@14485  274 apply (simp add: atLeast_def)  paulson@14485  275 apply (simp add: Suc_le_eq)  paulson@14485  276 apply (simp add: order_le_less, blast)  paulson@14485  277 done  paulson@14485  278 paulson@14485  279 lemma atLeast_Suc_greaterThan: "atLeast (Suc k) = greaterThan k"  paulson@14485  280  by (auto simp add: greaterThan_def atLeast_def less_Suc_eq_le)  paulson@14485  281 paulson@14485  282 lemma UN_atLeast_UNIV: "(UN m::nat. atLeast m) = UNIV"  paulson@14485  283 by blast  paulson@14485  284 paulson@15047  285 subsubsection {* The Constant @{term atMost} *}  paulson@15047  286 paulson@14485  287 lemma atMost_0 [simp]: "atMost (0::nat) = {0}"  paulson@14485  288 by (simp add: atMost_def)  paulson@14485  289 paulson@14485  290 lemma atMost_Suc: "atMost (Suc k) = insert (Suc k) (atMost k)"  paulson@14485  291 apply (simp add: atMost_def)  paulson@14485  292 apply (simp add: less_Suc_eq order_le_less, blast)  paulson@14485  293 done  paulson@14485  294 paulson@14485  295 lemma UN_atMost_UNIV: "(UN m::nat. atMost m) = UNIV"  paulson@14485  296 by blast  paulson@14485  297 paulson@15047  298 subsubsection {* The Constant @{term atLeastLessThan} *}  paulson@15047  299 nipkow@24449  300 text{*The orientation of the following rule is tricky. The lhs is  nipkow@24449  301 defined in terms of the rhs. Hence the chosen orientation makes sense  nipkow@24449  302 in this theory --- the reverse orientation complicates proofs (eg  nipkow@24449  303 nontermination). But outside, when the definition of the lhs is rarely  nipkow@24449  304 used, the opposite orientation seems preferable because it reduces a  nipkow@24449  305 specific concept to a more general one. *}  paulson@15047  306 lemma atLeast0LessThan: "{0::nat.. n then insert n {m.. Suc n \ {m..Suc n} = insert (Suc n) {m..n}"  nipkow@15554  342 by (auto simp add: atLeastAtMost_def)  nipkow@15554  343 nipkow@16733  344 subsubsection {* Image *}  nipkow@16733  345 nipkow@16733  346 lemma image_add_atLeastAtMost:  nipkow@16733  347  "(%n::nat. n+k)  {i..j} = {i+k..j+k}" (is "?A = ?B")  nipkow@16733  348 proof  nipkow@16733  349  show "?A \ ?B" by auto  nipkow@16733  350 next  nipkow@16733  351  show "?B \ ?A"  nipkow@16733  352  proof  nipkow@16733  353  fix n assume a: "n : ?B"  webertj@20217  354  hence "n - k : {i..j}" by auto  nipkow@16733  355  moreover have "n = (n - k) + k" using a by auto  nipkow@16733  356  ultimately show "n : ?A" by blast  nipkow@16733  357  qed  nipkow@16733  358 qed  nipkow@16733  359 nipkow@16733  360 lemma image_add_atLeastLessThan:  nipkow@16733  361  "(%n::nat. n+k)  {i.. ?B" by auto  nipkow@16733  364 next  nipkow@16733  365  show "?B \ ?A"  nipkow@16733  366  proof  nipkow@16733  367  fix n assume a: "n : ?B"  webertj@20217  368  hence "n - k : {i.. finite N"  paulson@14485  416  -- {* A bounded set of natural numbers is finite. *}  paulson@14485  417  apply (rule finite_subset)  paulson@14485  418  apply (rule_tac [2] finite_lessThan, auto)  paulson@14485  419  done  paulson@14485  420 nipkow@24853  421 text{* Any subset of an interval of natural numbers the size of the  nipkow@24853  422 subset is exactly that interval. *}  nipkow@24853  423 nipkow@24853  424 lemma subset_card_intvl_is_intvl:  nipkow@24853  425  "A <= {k.. A = {k.. \h. bij_betw h {0.. \h. bij_betw h M {0.. u ==>  nipkow@15045  499  {(0::int).. u")  paulson@14485  508  apply (subst image_atLeastZeroLessThan_int, assumption)  paulson@14485  509  apply (rule finite_imageI)  paulson@14485  510  apply auto  paulson@14485  511  done  paulson@14485  512 nipkow@15045  513 lemma finite_atLeastLessThan_int [iff]: "finite {l.. u")  paulson@14485  535  apply (subst image_atLeastZeroLessThan_int, assumption)  paulson@14485  536  apply (subst card_image)  paulson@14485  537  apply (auto simp add: inj_on_def)  paulson@14485  538  done  paulson@14485  539 nipkow@15045  540 lemma card_atLeastLessThan_int [simp]: "card {l.. {l} Un {l<.. {l<.. {l} Un {l<..u} = {l..u}"  nipkow@15045  576  "(l::'a::linorder) <= u ==> {l.. {..l} Un {l<.. {.. {..l} Un {l<..u} = {..u}"  nipkow@15045  585  "(l::'a::linorder) <= u ==> {.. {l<..u} Un {u<..} = {l<..}"  nipkow@15045  587  "(l::'a::linorder) < u ==> {l<.. {l..u} Un {u<..} = {l..}"  nipkow@15045  589  "(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  601  "[| (l::'a::linorder) <= m; m <= u |] ==> {l.. {l..m} Un {m<..u} = {l..u}"  ballarin@14398  603 by auto  ballarin@13735  604 ballarin@13735  605 lemmas ivl_disj_un = ivl_disj_un_singleton ivl_disj_un_one ivl_disj_un_two  ballarin@13735  606 wenzelm@14577  607 subsubsection {* Disjoint Intersections *}  ballarin@13735  608 wenzelm@14577  609 text {* Singletons and open intervals *}  ballarin@13735  610 ballarin@13735  611 lemma ivl_disj_int_singleton:  nipkow@15045  612  "{l::'a::order} Int {l<..} = {}"  nipkow@15045  613  "{.. n \ {i.. {m.. i | m \ i & j \ (n::'a::linorder))"  nipkow@15542  659 apply(auto simp:linorder_not_le)  nipkow@15542  660 apply(rule ccontr)  nipkow@15542  661 apply(insert linorder_le_less_linear[of i n])  nipkow@15542  662 apply(clarsimp simp:linorder_not_le)  nipkow@15542  663 apply(fastsimp)  nipkow@15542  664 done  nipkow@15542  665 nipkow@15041  666 nipkow@15042  667 subsection {* Summation indexed over intervals *}  nipkow@15042  668 nipkow@15042  669 syntax  nipkow@15042  670  "_from_to_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b" ("(SUM _ = _.._./ _)" [0,0,0,10] 10)  nipkow@15048  671  "_from_upto_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b" ("(SUM _ = _..<_./ _)" [0,0,0,10] 10)  nipkow@16052  672  "_upt_setsum" :: "idt \ 'a \ 'b \ 'b" ("(SUM _<_./ _)" [0,0,10] 10)  nipkow@16052  673  "_upto_setsum" :: "idt \ 'a \ 'b \ 'b" ("(SUM _<=_./ _)" [0,0,10] 10)  nipkow@15042  674 syntax (xsymbols)  nipkow@15042  675  "_from_to_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b" ("(3\_ = _.._./ _)" [0,0,0,10] 10)  nipkow@15048  676  "_from_upto_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b" ("(3\_ = _..<_./ _)" [0,0,0,10] 10)  nipkow@16052  677  "_upt_setsum" :: "idt \ 'a \ 'b \ 'b" ("(3\_<_./ _)" [0,0,10] 10)  nipkow@16052  678  "_upto_setsum" :: "idt \ 'a \ 'b \ 'b" ("(3\_\_./ _)" [0,0,10] 10)  nipkow@15042  679 syntax (HTML output)  nipkow@15042  680  "_from_to_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b" ("(3\_ = _.._./ _)" [0,0,0,10] 10)  nipkow@15048  681  "_from_upto_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b" ("(3\_ = _..<_./ _)" [0,0,0,10] 10)  nipkow@16052  682  "_upt_setsum" :: "idt \ 'a \ 'b \ 'b" ("(3\_<_./ _)" [0,0,10] 10)  nipkow@16052  683  "_upto_setsum" :: "idt \ 'a \ 'b \ 'b" ("(3\_\_./ _)" [0,0,10] 10)  nipkow@15056  684 syntax (latex_sum output)  nipkow@15052  685  "_from_to_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b"  nipkow@15052  686  ("(3\<^raw:$\sum_{>_ = _\<^raw:}^{>_\<^raw:}$> _)" [0,0,0,10] 10)  nipkow@15052  687  "_from_upto_setsum" :: "idt \ 'a \ 'a \ 'b \ 'b"  nipkow@15052  688  ("(3\<^raw:$\sum_{>_ = _\<^raw:}^{<>_\<^raw:}$> _)" [0,0,0,10] 10)  nipkow@16052  689  "_upt_setsum" :: "idt \ 'a \ 'b \ 'b"  nipkow@16052  690  ("(3\<^raw:$\sum_{>_ < _\<^raw:}$> _)" [0,0,10] 10)  nipkow@15052  691  "_upto_setsum" :: "idt \ 'a \ 'b \ 'b"  nipkow@16052  692  ("(3\<^raw:$\sum_{>_ \ _\<^raw:}$> _)" [0,0,10] 10)  nipkow@15041  693 nipkow@15048  694 translations  nipkow@15048  695  "\x=a..b. t" == "setsum (%x. t) {a..b}"  nipkow@15048  696  "\x=a..i\n. t" == "setsum (\i. t) {..n}"  nipkow@15048  698  "\ii. t) {..x\{a..b}. e"} & @{term"\x=a..b. e"} & @{term[mode=latex_sum]"\x=a..b. e"}\\  nipkow@15056  706 @{term[source]"\x\{a..x=a..x=a..x\{..b}. e"} & @{term"\x\b. e"} & @{term[mode=latex_sum]"\x\b. e"}\\  nipkow@15056  708 @{term[source]"\x\{..xxx::nat=0..xa = c; b = d; !!x. \ c \ x; x < d \ \ f x = g x \ \  nipkow@15542  731  setsum f {a..i \ Suc n. f i) = (\i \ n. f i) + f(Suc n)"  nipkow@16052  738 by (simp add:atMost_Suc add_ac)  nipkow@16052  739 nipkow@16041  740 lemma setsum_lessThan_Suc[simp]: "(\i < Suc n. f i) = (\i < n. f i) + f n"  nipkow@16041  741 by (simp add:lessThan_Suc add_ac)  nipkow@15041  742 nipkow@15911  743 lemma setsum_cl_ivl_Suc[simp]:  nipkow@15561  744  "setsum f {m..Suc n} = (if Suc n < m then 0 else setsum f {m..n} + f(Suc n))"  nipkow@15561  745 by (auto simp:add_ac atLeastAtMostSuc_conv)  nipkow@15561  746 nipkow@15911  747 lemma setsum_op_ivl_Suc[simp]:  nipkow@15561  748  "setsum f {m..  nipkow@15561  752  (\i=n..m+1. f i) = (\i=n..m. f i) + f(m + 1)"  nipkow@15561  753 by (auto simp:add_ac atLeastAtMostSuc_conv)  nipkow@16041  754 *)  nipkow@15539  755 lemma setsum_add_nat_ivl: "\ m \ n; n \ p \ \  nipkow@15539  756  setsum f {m.. 'a::ab_group_add"  nipkow@15539  761 shows "\ m \ n; n \ p \ \  nipkow@15539  762  setsum f {m..x\{m..n}. P x) = P m + (\x\{m<..n}. P x)" (is "?lhs = ?rhs")  kleing@19106  791 proof -  kleing@19106  792  from mn  kleing@19106  793  have "{m..n} = {m} \ {m<..n}"  kleing@19106  794  by (auto intro: ivl_disj_un_singleton)  kleing@19106  795  hence "?lhs = (\x\{m} \ {m<..n}. P x)"  kleing@19106  796  by (simp add: atLeast0LessThan)  kleing@19106  797  also have "\ = ?rhs" by simp  kleing@19106  798  finally show ?thesis .  kleing@19106  799 qed  kleing@19106  800 kleing@19106  801 lemma setsum_head_upt:  kleing@19022  802  fixes m::nat  kleing@19022  803  assumes m: "0 < m"  kleing@19106  804  shows "(\xx\{1..xx\{0.. = (\x\{0..m - 1}. P x)"  kleing@19106  811  by (cases m) (auto simp add: atLeastLessThanSuc_atLeastAtMost)  kleing@19106  812  also  kleing@19106  813  have "\ = P 0 + (\x\{0<..m - 1}. P x)"  kleing@19106  814  by (simp add: setsum_head)  kleing@19106  815  also  kleing@19106  816  from m  kleing@19106  817  have "{0<..m - 1} = {1.. (\i=0..i\{1..n}. of_nat i) =  kleing@19469  833  of_nat n*((of_nat n)+1)"  kleing@19469  834 proof (induct n)  kleing@19469  835  case 0  kleing@19469  836  show ?case by simp  kleing@19469  837 next  kleing@19469  838  case (Suc n)  nipkow@23477  839  then show ?case by (simp add: ring_simps)  kleing@19469  840 qed  kleing@19469  841 kleing@19469  842 theorem arith_series_general:  huffman@23277  843  "((1::'a::comm_semiring_1) + 1) * (\i\{.. 1"  kleing@19469  847  let ?I = "\i. of_nat i" and ?n = "of_nat n"  kleing@19469  848  have  kleing@19469  849  "(\i\{..i\{..i\{.. = ?n*a + (\i\{.. = (?n*a + d*(\i\{1.. = (1+1)*?n*a + d*(1+1)*(\i\{1..i\{1..n - 1}. ?I i) = ((1+1)*?n*a + d*?I (n - 1)*?I n)"  kleing@19469  861  by (simp only: mult_ac gauss_sum [of "n - 1"])  huffman@23431  862  (simp add: mult_ac trans [OF add_commute of_nat_Suc [symmetric]])  kleing@19469  863  finally show ?thesis by (simp add: mult_ac add_ac right_distrib)  kleing@19469  864 next  kleing@19469  865  assume "\(n > 1)"  kleing@19469  866  hence "n = 1 \ n = 0" by auto  kleing@19469  867  thus ?thesis by (auto simp: mult_ac right_distrib)  kleing@19469  868 qed  kleing@19469  869 kleing@19469  870 lemma arith_series_nat:  kleing@19469  871  "Suc (Suc 0) * (\i\{..i\{..i\{..i\{..nat"  kleing@19022  893  shows  kleing@19022  894  "\x. Q x \ P x \  kleing@19022  895 ` (\xxxxx