Sequences & Series — Exercises

énoncés

By Pr. El Hadiq Zouhair

Contents

  1. Generate finite sequences easy
  2. Sum & product of a list easy
  3. Arithmetic progression easy
  4. Geometric progression medium
  5. Sum of $1..n$ and $1^2..n^2$ medium
  6. $\sum (2k-1) = n^2$ medium
  7. Infinite geometric series medium
  8. Recurrence — Fibonacci medium
  9. Convergence — p-series hard
  10. Catalan numbers hard
  11. Factorial as a product medium
  12. Symbolic recurrence with rsolve hard

1Generate finite sequences easy

Produce the first 10 terms of each:

  1. Squares $a_k = k^2$ for $k = 1..10$.
  2. Odd numbers $a_k = 2k - 1$ for $k = 1..10$.
  3. Powers of 2 $a_k = 2^k$ for $k = 0..9$.
Your answer…

2Sum & product of a list easy

Given L = [3, 1, 4, 1, 5, 9, 2, 6], compute its sum and its product.

Your answer…

3Arithmetic progression easy

For $c = 2,\, d = 3,\, n = 10$, list $\{c + kd\}_{k=0}^{n}$ and compute its sum. Then verify the closed-form $\dfrac{(n+1)(2c + nd)}{2}$.

Your answer…

4Geometric progression medium

For $d = 2,\, r = 3,\, n = 8$, list $\{d \cdot r^k\}_{k=0}^{n}$ and compute its sum. Verify the closed-form $\dfrac{d\,(r^{\,n+1} - 1)}{r - 1}$.

Your answer…

5Sum of $1..n$ and $1^2..n^2$ medium

For $n = 100$, compute:

  1. $\displaystyle \sum_{k=1}^{n} k$ and check $= n(n+1)/2$.
  2. $\displaystyle \sum_{k=1}^{n} k^2$ and check $= n(n+1)(2n+1)/6$.
Your answer…

6$\displaystyle\sum_{k=1}^{n}(2k-1) = n^2$ medium

Verify for $n = 1..1000$. Then prove it symbolically with SymPy.

Your answer…

7Infinite geometric series medium

Compute $\displaystyle \sum_{k=0}^{\infty} \left(\tfrac{3}{10}\right)^{k}$ and $\displaystyle \sum_{k=1}^{\infty} \left(\tfrac{1}{2}\right)^{k}$ both numerically and with SymPy.

Your answer…

8Recurrence — Fibonacci medium

The Fibonacci sequence is $F_0 = 0,\ F_1 = 1,\ F_n = F_{n-1} + F_{n-2}$. Print $F_0..F_{15}$ using:

  1. Recursive function with memoization.
  2. Iterative loop.
  3. SymPy's rsolve to obtain the closed-form (Binet's formula).
Your answer…

9Convergence — p-series hard

Compute $\displaystyle\sum_{k=1}^{\infty} \frac{1}{k^p}$ for $p = 1, 2, 3$. Which converge? Compare partial sums to known exact values (Basel problem: $\pi^2/6$ for $p=2$).

Your answer…

10Catalan numbers hard

Compute $C_0..C_{10}$ from $C_n = \frac{1}{n+1}\binom{2n}{n}$ in two ways:

  1. Direct formula using math.comb.
  2. sympy.catalan.
Your answer…

11Factorial as a product medium

Express $n! = \displaystyle\prod_{k=1}^{n} k$ in three ways: math.prod, functools.reduce, and SymPy's Product. Compute $10!$.

Your answer…

12Symbolic recurrence with rsolve hard

Solve each recurrence symbolically.

  1. $a_k = a_{k-1} + 3,\;a_0 = 2$
  2. $g_k = 3\,g_{k-1},\;g_0 = 2$
  3. $t_k = 2\,t_{k-1} + 1,\;t_0 = 0$  (Hanoi)
Your answer…

Going further

Open the main lesson for the matching theory.