# HG changeset patch # User kleing # Date 1144372834 -7200 # Node ID c33563c7c14cc0c4873e4e4c16a52bccc806a962 # Parent 2e1c7ca05ee0d81a1940d84d8e6b1d1494c97d2a renamed ASeries to Arithmetic_Series, removed the ^M diff -r 2e1c7ca05ee0 -r c33563c7c14c src/HOL/Library/ASeries.thy --- a/src/HOL/Library/ASeries.thy Thu Apr 06 17:29:40 2006 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -(* Title: HOL/Library/ASeries.thy - ID: $Id$ - Author: Benjamin Porter, 2006 -*) - - -header {* Arithmetic Series *} - -theory ASeries -imports Main -begin - -section {* Abstract *} - -text {* The following document presents a proof of the Arithmetic -Series Sum formalised in Isabelle/Isar. - -{\em Theorem:} The series $\sum_{i=1}^{n} a_i$ where $a_{i+1} = a_i + -d$ for some constant $d$ has the sum $\frac{n}{2} (a_1 + a_n)$ -(i.e. $n$ multiplied by the arithmetic mean of the first and last -element). - -{\em Informal Proof:} (from -"http://mathworld.wolfram.com/ArithmeticSeries.html") - The proof is a simple forward proof. Let $S$ equal the sum above and - $a$ the first element, then we have -\begin{tabular}{ll} - $S$ &$= a + (a+d) + (a+2d) + ... a_n$ \\ - &$= n*a + d (0 + 1 + 2 + ... n-1)$ \\ - &$= n*a + d (\frac{1}{2} * (n-1) * n)$ ..using a simple sum identity \\ - &$= \frac{n}{2} (2a + d(n-1))$ \\ - & ..but $(a+a_n = a + (a + d(n-1)) = 2a + d(n-1))$ so \\ - $S$ &$= \frac{n}{2} (a + a_n)$ -\end{tabular} -*} - -section {* Formal Proof *} - -text {* We present a proof for the abstract case of a commutative ring, -we then instantiate for three common types nats, ints and reals. The -function @{text "of_nat"} maps the natural numbers into any -commutative ring. -*} - -lemmas comm_simp [simp] = left_distrib right_distrib add_assoc mult_ac - -text {* Next we prove the following simple summation law $\sum_{i=1}^n -i = \frac {n * (n+1)}{2}$. *} - -lemma sum_ident: - "((1::'a::comm_semiring_1_cancel) + 1)*(\i\{1..n}. of_nat i) = - of_nat n*((of_nat n)+1)" -proof (induct n) - case 0 - show ?case by simp -next - case (Suc n) - then show ?case by simp -qed - -text {* The abstract theorem follows. Note that $2$ is displayed as -$1+1$ to keep the structure as abstract as possible. *} - -theorem arith_series_general: - "((1::'a::comm_semiring_1_cancel) + 1) * (\i\{.. 1" - let ?I = "\i. of_nat i" and ?n = "of_nat n" - have - "(\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)" - by (simp only: mult_ac sum_ident [of "n - 1"]) (simp add: of_nat_Suc [symmetric]) - finally show ?thesis by simp -next - assume "\(n > 1)" - hence "n = 1 \ n = 0" by auto - thus ?thesis by auto -qed - -subsection {* Instantiation *} - -lemma arith_series_nat: - "(2::nat) * (\i\{..i\{..i\{..i\{..i\{1..n}. of_nat i) = + of_nat n*((of_nat n)+1)" +proof (induct n) + case 0 + show ?case by simp +next + case (Suc n) + then show ?case by simp +qed + +text {* The abstract theorem follows. Note that $2$ is displayed as +$1+1$ to keep the structure as abstract as possible. *} + +theorem arith_series_general: + "((1::'a::comm_semiring_1_cancel) + 1) * (\i\{.. 1" + let ?I = "\i. of_nat i" and ?n = "of_nat n" + have + "(\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)" + by (simp only: mult_ac sum_ident [of "n - 1"]) (simp add: of_nat_Suc [symmetric]) + finally show ?thesis by simp +next + assume "\(n > 1)" + hence "n = 1 \ n = 0" by auto + thus ?thesis by auto +qed + +subsection {* Instantiation *} + +lemma arith_series_nat: + "(2::nat) * (\i\{..i\{..i\{..i\{..