This type of exercise can be solved using the function : sequence
A numerical sequence or a numerical progression is any application of ℕ or a part of ℕ to ℝ
To say that a sequence (`u_(n)`) is arithmetic means that there is a real r such that for any natural number n, `u_(n+1)`=`u_(n)`+r.
The real r is called the common difference of the sequence (`u_(n)`).
If (`u_(n)`) is an arithmetic sequence of first term `u_(0)`, and common difference r. Then for any natural number n, `u_(n)=u_(0)+nr`
If S=a+...+k is the sum of p consecutive terms of an arithmetic sequence then `S = p(a+k)/2`. We deduce that `1+2+3+...+n=n(n+1)/2`
To say that a sequence (`u_(n)`) is geometric means that there is a real q such that for any natural n, `u_(n+1)`=`qu_(n)`.
The real q is called the common ratio for the sequence (`u_(n)`).
If (`u_(n)`) is a geometric sequence of first term `u_(0)`, and common ratio q. Then for any natural number n, `u_(n)=u_(0)*q^n`
If S=a+...+k is the sum of p consecutive terms of a geometric sequence of common ratio q (`q != 1`) then `S = (a-k*q)/(1-q)`.
We deduce that `1+q+q^2+...+q^n=(1-q^(n+1))/(1-q)`