src/HOL/SetInterval.thy
changeset 29667 53103fc8ffa3
parent 28853 69eb69659bf3
child 29709 cf8476cc440d
equal deleted inserted replaced
29549:7187373c6cb1 29667:53103fc8ffa3
   530   apply (simp add: inj_on_def)
   530   apply (simp add: inj_on_def)
   531   apply (rule image_add_int_atLeastLessThan)
   531   apply (rule image_add_int_atLeastLessThan)
   532   done
   532   done
   533 
   533 
   534 lemma card_atLeastAtMost_int [simp]: "card {l..u} = nat (u - l + 1)"
   534 lemma card_atLeastAtMost_int [simp]: "card {l..u} = nat (u - l + 1)"
   535   apply (subst atLeastLessThanPlusOne_atLeastAtMost_int [THEN sym])
   535 apply (subst atLeastLessThanPlusOne_atLeastAtMost_int [THEN sym])
   536   apply (auto simp add: compare_rls)
   536 apply (auto simp add: algebra_simps)
   537   done
   537 done
   538 
   538 
   539 lemma card_greaterThanAtMost_int [simp]: "card {l<..u} = nat (u - l)"
   539 lemma card_greaterThanAtMost_int [simp]: "card {l<..u} = nat (u - l)"
   540   by (subst atLeastPlusOneAtMost_greaterThanAtMost_int [THEN sym], simp)
   540 by (subst atLeastPlusOneAtMost_greaterThanAtMost_int [THEN sym], simp)
   541 
   541 
   542 lemma card_greaterThanLessThan_int [simp]: "card {l<..<u} = nat (u - (l + 1))"
   542 lemma card_greaterThanLessThan_int [simp]: "card {l<..<u} = nat (u - (l + 1))"
   543   by (subst atLeastPlusOneLessThan_greaterThanLessThan_int [THEN sym], simp)
   543 by (subst atLeastPlusOneLessThan_greaterThanLessThan_int [THEN sym], simp)
   544 
   544 
   545 lemma finite_M_bounded_by_nat: "finite {k. P k \<and> k < (i::nat)}"
   545 lemma finite_M_bounded_by_nat: "finite {k. P k \<and> k < (i::nat)}"
   546 proof -
   546 proof -
   547   have "{k. P k \<and> k < i} \<subseteq> {..<i}" by auto
   547   have "{k. P k \<and> k < i} \<subseteq> {..<i}" by auto
   548   with finite_lessThan[of "i"] show ?thesis by (simp add: finite_subset)
   548   with finite_lessThan[of "i"] show ?thesis by (simp add: finite_subset)
   804 by (simp add: setsum_head atLeastSucAtMost_greaterThanAtMost)
   804 by (simp add: setsum_head atLeastSucAtMost_greaterThanAtMost)
   805 
   805 
   806 lemma setsum_head_upt_Suc:
   806 lemma setsum_head_upt_Suc:
   807   "m < n \<Longrightarrow> setsum f {m..<n} = f m + setsum f {Suc m..<n}"
   807   "m < n \<Longrightarrow> setsum f {m..<n} = f m + setsum f {Suc m..<n}"
   808 apply(insert setsum_head_Suc[of m "n - 1" f])
   808 apply(insert setsum_head_Suc[of m "n - 1" f])
   809 apply (simp add: atLeastLessThanSuc_atLeastAtMost[symmetric] ring_simps)
   809 apply (simp add: atLeastLessThanSuc_atLeastAtMost[symmetric] algebra_simps)
   810 done
   810 done
   811 
   811 
   812 
   812 
   813 lemma setsum_add_nat_ivl: "\<lbrakk> m \<le> n; n \<le> p \<rbrakk> \<Longrightarrow>
   813 lemma setsum_add_nat_ivl: "\<lbrakk> m \<le> n; n \<le> p \<rbrakk> \<Longrightarrow>
   814   setsum f {m..<n} + setsum f {n..<p} = setsum f {m..<p::nat}"
   814   setsum f {m..<n} + setsum f {n..<p} = setsum f {m..<p::nat}"
   868 proof (induct n)
   868 proof (induct n)
   869   case 0
   869   case 0
   870   show ?case by simp
   870   show ?case by simp
   871 next
   871 next
   872   case (Suc n)
   872   case (Suc n)
   873   then show ?case by (simp add: ring_simps)
   873   then show ?case by (simp add: algebra_simps)
   874 qed
   874 qed
   875 
   875 
   876 theorem arith_series_general:
   876 theorem arith_series_general:
   877   "((1::'a::comm_semiring_1) + 1) * (\<Sum>i\<in>{..<n}. a + of_nat i * d) =
   877   "((1::'a::comm_semiring_1) + 1) * (\<Sum>i\<in>{..<n}. a + of_nat i * d) =
   878   of_nat n * (a + (a + of_nat(n - 1)*d))"
   878   of_nat n * (a + (a + of_nat(n - 1)*d))"
   892     by (cases n) (auto simp: atLeastLessThanSuc_atLeastAtMost)
   892     by (cases n) (auto simp: atLeastLessThanSuc_atLeastAtMost)
   893   also from ngt1
   893   also from ngt1
   894   have "(1+1)*?n*a + d*(1+1)*(\<Sum>i\<in>{1..n - 1}. ?I i) = ((1+1)*?n*a + d*?I (n - 1)*?I n)"
   894   have "(1+1)*?n*a + d*(1+1)*(\<Sum>i\<in>{1..n - 1}. ?I i) = ((1+1)*?n*a + d*?I (n - 1)*?I n)"
   895     by (simp only: mult_ac gauss_sum [of "n - 1"])
   895     by (simp only: mult_ac gauss_sum [of "n - 1"])
   896        (simp add:  mult_ac trans [OF add_commute of_nat_Suc [symmetric]])
   896        (simp add:  mult_ac trans [OF add_commute of_nat_Suc [symmetric]])
   897   finally show ?thesis by (simp add: mult_ac add_ac right_distrib)
   897   finally show ?thesis by (simp add: algebra_simps)
   898 next
   898 next
   899   assume "\<not>(n > 1)"
   899   assume "\<not>(n > 1)"
   900   hence "n = 1 \<or> n = 0" by auto
   900   hence "n = 1 \<or> n = 0" by auto
   901   thus ?thesis by (auto simp: mult_ac right_distrib)
   901   thus ?thesis by (auto simp: algebra_simps)
   902 qed
   902 qed
   903 
   903 
   904 lemma arith_series_nat:
   904 lemma arith_series_nat:
   905   "Suc (Suc 0) * (\<Sum>i\<in>{..<n}. a+i*d) = n * (a + (a+(n - 1)*d))"
   905   "Suc (Suc 0) * (\<Sum>i\<in>{..<n}. a+i*d) = n * (a + (a+(n - 1)*d))"
   906 proof -
   906 proof -