2023-01-03 08:42:54 +01:00
\chapter { Basic concepts}
\section { Algorithms}
\section { Mathematical Preliminaries}
\subsection { Mathematical induction}
\begin { myexercise} { 4} { 18}
2023-02-27 11:07:49 +01:00
Let $ F _ n $ be the $ n $ -th Fibonacci number, defined by the recursion relation
\[
\begin { cases}
F_ 0 = 1, \\
F_ 1 = 1, \\
F_ n = F_ { n-1} + F_ { n-2} , \quad n \geq 2.
\end { cases}
\]
Let $ \phi = \frac { 1 + \sqrt { 5 } } { 2 } $ be the golden ratio.
We have
\begin { equation}
F_ n \leq \phi ^ { n-1}
\label { eq:fibo_ leq_ golden_ ratio}
\end { equation}
$ \forall n \in \mathbb { N } $ .
Prove that, in addition to Eq. \ref { eq:fibo_ leq_ golden_ ratio} , $ F _ n \geq \phi ^ { n - 2 } $ .
\begin { myanswer}
Let $ P ( n ) $ be the assertion that $ F _ n \geq \phi ^ { n - 2 } $ .
We proceed by recursion on $ n $ .
\begin { equation}
1 + \phi = \phi ^ 2
\label { eq:golden_ ratio_ squared}
\end { equation}
\emph { Initiation} For $ n = 0 $ : $ \phi ^ { 0 - 2 } = \phi ^ { - 2 } = \frac { 1 } { \phi ^ 2 } $ . As $ \phi ^ 2 > 1 $ . $ \frac { 1 } { \phi ^ 2 } < 1 $ , so $ P ( 0 ) $ is true.
For $ n = 1 $ :
$ \phi ^ { 1 - 2 } = \phi ^ { - 1 } = \frac { 1 } { \phi } $ . As $ \phi > 1 $ , $ \frac { 1 } { \phi } < 1 $ , so $ P ( 1 ) $ is true.
\emph { Heredity}
Let $ P ( n ) $ and $ P ( n - 1 ) $ be true. We have to prove $ P ( n + 1 ) $ .
\begin { align*}
P(n) \wedge P(n-1) & \Leftrightarrow F_ n \geq \phi ^ { n-2} \wedge F_ { n-1} \geq \phi ^ { n-1-2} \\
& \Leftrightarrow F_ { n} + F_ { n-1} \geq \phi ^ { n-2} + \phi ^ { n-3} \\
& \Leftrightarrow F_ n + F_ { n-1} \geq \phi ^ { n-3} (1 + \phi ) \\
& \Leftrightarrow F_ n + F_ { n-1} \geq \phi ^ { n-3} \phi ^ 2 \qquad \text { using Eq. \ref { eq:golden_ ratio_ squared} } \\
& \Leftrightarrow F_ n + F_ { n-1} \geq \phi ^ { n-1} \\
& \Leftrightarrow F_ { n+1} \geq \phi ^ { n+1-2} \\
& \Leftrightarrow P(n+1)
\end { align*}
\emph { Conclusion} $ P ( 0 ) $ and $ P ( 1 ) $ are true. $ P ( n ) \wedge P ( n - 1 ) $ true implies $ P ( n + 1 ) $ true. So $ P ( n ) $ is true for all $ n \in \mathbb { N } $ .
\end { myanswer}
2023-01-03 08:42:54 +01:00
\end { myexercise}
\begin { myexercise} { 5} { 19}
A prime number is an integer $ > 1 $ that has no exact divisors other than $ 1 $ and itself.
Using this definition and mathematical induction, prove that every integer $ > 1 $ can be written as a product of prime numbers or is a prime itself.
\begin { myanswer}
Let $ P ( n ) $ be the assertion that $ n $ can be written as a product of prime numbers or is a prime.
\begin { proof}
2023-02-27 11:07:49 +01:00
Let $ N > 1 $ be the smallest integer such that $ P ( N ) $ is false.
As $ \forall N' < N $ , $ N' > 1 $ , $ P ( N' ) $ is true.
We have either of the following assertions:
\begin { itemize}
\item $ N $ is a prime number;
\item there exists $ m $ and $ n $ below $ N $ such that, $ m \times n = N $ .
As $ m $ and $ n $ are below $ N $ , they satisfies $ P $ , so they are either primes or a product of primes. So $ mn = N $ is also a product of primes.
\end { itemize}
We have a contradiction, and $ P ( N ) $ must be true.
2023-01-03 08:42:54 +01:00
\end { proof}
\end { myanswer}
\end { myexercise}
\begin { myexercise} { 7} { 19}
Formulate and prove by induction a rule for the sums $ 1 ^ 2 $ , $ 2 ^ 2 - 1 ^ 2 $ , $ 3 ^ 2 - 2 ^ 2 + 1 ^ 2 $ , $ 4 ^ 2 - 3 ^ 2 + 2 ^ 2 - 1 ^ 2 $ , $ 5 ^ 2 - 4 ^ 2 + 3 ^ 2 - 2 ^ 2 + 1 ^ 2 $ , etc.
\begin { myanswer}
$ 1 ^ 2 = 1 $
$ 2 ^ 2 - 1 ^ 2 = 3 $
$ 3 ^ 2 - 2 ^ 2 + 1 ^ 2 = 6 $
$ 4 ^ 2 - 3 ^ 2 + 2 ^ 2 - 1 ^ 2 = 10 $
$ 5 ^ 2 - 4 ^ 2 + 3 ^ 2 - 2 ^ 2 + 1 ^ 2 = 15 $
We can rewrite the computed sequence with
\[
2023-02-27 11:07:49 +01:00
T_ n = \sum _ { i=0} ^ n (-1)^ i (n-i)^ 2
2023-01-03 08:42:54 +01:00
\]
With little help from formal computation, we get
\begin { equation}
T_ n = \frac { 1} { 2} n (n + 1)
2023-02-27 11:07:49 +01:00
\label { eq:ex7_ half_ factor_ n_ n+1}
2023-01-03 08:42:54 +01:00
\end { equation}
\begin { proof}
2023-02-27 11:07:49 +01:00
Let us prove the formula.
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
Let $ P ( n ) $ be the proposition that Eq. \ref { eq:ex7_ half_ factor_ n_ n+1} is correct for $ T _ n $ .
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
By recursion on $ n $
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
\emph { Initiation}
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
For $ n = 1 $ , $ 1 ^ 2 = 1 $ and $ \frac { 1 } { 2 } 1 \times ( 1 + 1 ) = 1 $ , so $ P ( n ) $ is true.
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
\emph { Heredity}
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
Suppose $ P ( n ) $ true, let us prove that $ P ( n + 1 ) $ is also true.
\begin { align*}
P(n) & \Leftrightarrow T_ n = \frac { 1} { 2} n(n+1) \\
& \Leftrightarrow \sum _ { i=0} ^ n (-1)^ i (n-i)^ 2 = \frac { 1} { 2} n(n+1)
\end { align*}
\unfinished
2023-01-03 08:42:54 +01:00
\end { proof}
\end { myanswer}
\end { myexercise}
\begin { myexercise} { 8} { 19}
2023-02-27 11:07:49 +01:00
(a) Prove the following theorem of Nicomachus by induction:
$ 1 ^ 3 = 1 $ , $ 2 ^ 3 = 3 + 5 $ , $ 3 ^ 3 = 7 + 9 + 11 $ , $ 4 ^ 3 = 13 + 15 + 17 + 19 $ , etc.
(b) Use this result to prove the remarkable formula $ 1 ^ 3 + 2 ^ 3 + \dots + n ^ 3 = ( 1 + 2 + \dots + n ) ^ 2 $
\begin { myanswer}
(a) The theorem states the following:
For all $ n \in \mathbb { N } $ we have
\[
n^ 3 = \sum _ { i = 1} ^ n | n (n - 1) - 1 + 2i|
\]
\begin { proof}
We proceed by recursion on $ n $ .
Let $ P ( n ) $ be the proposition ``$ n ^ 3 = \sum _ { i = 1 } ^ n | n ( n - 1 ) - 1 + 2 i| $ ''.
\emph { Initiation} For $ n = 1 $ , $ 1 ^ 3 = 1 ^ 2 $ , so $ P ( 1 ) $ is true.
\emph { Heredity} Suppose $ P ( n ) $ true, let us prove that $ P ( n + 1 ) $ is also true.
\begin { align*}
P(n) \Leftrightarrow n^ 3 & = \sum _ { i = 1} ^ n n (n - 1) - 1 + 2i \\
% &\Leftrightarrow (n+1)^3 &= \sum_{i = 1}^n n^2 - n - 1 + 2i \\
\end { align*}
\end { proof}
\unfinished
(b)
\begin { theorem} [Formula of Nicomachus]
The sum of the cubes of the first $ n $ natural numbers is equal to the square of the sum of the first $ n $ natural numbers.
\end { theorem}
\begin { equation}
\sum _ { k=1} ^ n k^ 3 = \left (\sum _ { k=1} ^ n k \right )^ 2
\end { equation}
\begin { proof}
Let $ P ( n ) $ be the proposition ``$ \sum _ { k = 1 } ^ n k ^ 3 = \left ( \sum _ { k = 1 } ^ n k \right ) ^ 2 $ ''.
$ P ( n ) \Longleftrightarrow \sum _ { k = 1 } ^ n k ^ 3 = \left ( \frac { n ( n + 1 ) } { 2 } \right ) ^ 2 $
because $ \sum _ { i = 1 } ^ n i = \frac { n ( n + 1 ) } { 2 } $ .
We want to prove that: $ \sum _ { k = 1 } ^ { n + 1 } k ^ 3 = \left ( \frac { ( n + 1 ) ( n + 2 ) } { 2 } \right ) ^ 2 $
\begin { align*}
\sum _ { k=1} ^ { n+1} k^ 3 & = \frac { n^ 2 (n+1)^ 2} { 2^ 2} + (n+1)^ 3 \\
& = (n+1)^ 2 \left (\frac { n^ 2} { 4} + n + 1\right ) \\
& = (n+1)^ 2 \cdot \frac { n^ 2 + 4n + 4} { 4} \\
& = \frac { (n+1)^ 2(n+2)^ 2} { 2^ 2} \\
& \Updownarrow \\
& P(n+1)
\end { align*}
\emph { Conclusion}
$ P ( 1 ) $ is true because $ 1 ^ 3 = 1 $ and $ \left ( \frac { 1 ( 1 + 1 ) } { 2 } \right ) ^ 2 = 1 $ .
$ P ( n ) $ true implies $ P ( n + 1 ) $ true, so $ P ( n ) $ is true for all $ n \in \mathbb { N } _ + $ .
\end { proof}
\end { myanswer}
2023-01-03 08:42:54 +01:00
\end { myexercise}
\begin { myexercise} { 9} { 19}
2023-02-27 11:07:49 +01:00
Prove by induction that if $ 0 < a < 1 $ then $ ( 1 - a ) ^ n \geq 1 - na $ .
\begin { myanswer}
We proceed by recursion on $ n $ .
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
Let $ P ( n ) $ be the proposition ``$ ( 1 - a ) ^ n \geq 1 - na $ ''.
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
\emph { Initiation} For $ n = 0 $ ,
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
$ ( 1 - a ) ^ n = 1 = 1 - na $ , so $ P ( 0 ) $ is true.
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
\emph { Heredity} Suppose $ P ( n ) $ true, let us prove that $ P ( n + 1 ) $ is also true.
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
We want to prove that $ ( 1 - a ) ^ { n + 1 } \geq 1 - ( n + 1 ) a $ .
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
\begin { align*}
P(n) \Leftrightarrow (1-a)^ n & \geq 1-na \\
(1-a)^ n (1-a) & \geq (1 - na) (1-a) \qquad \text { $ 1 - a > 0 $ } \\
(1-a)^ { n+1} & \geq 1 - na - a + na \\
& \geq 1 - (n+1)a - a \\
& \geq 1 - (n+1)a \qquad \text { because $ a > 0 $ }
& \Rightarrow P(n+1)
\end { align*}
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
\emph { Conclusion}
$ P ( 1 ) $ is true.
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
$ P ( n ) $ true implies $ P ( n + 1 ) $ true, so $ P ( n ) $ is true for all $ n \in \mathbb { N } _ + $ .
\end { myanswer}
2023-01-03 08:42:54 +01:00
\end { myexercise}
% \begin{myexercise}{10}{19}
2023-02-27 11:07:49 +01:00
% Prove by induction that if $n \geq 10$ then $2^n > n^3$.
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
% \begin{myanswer}
% We proceed by recursion on $n$.
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
% Let $P(n)$ be the proposition ``$2^n > n^3$''.
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
% \emph{Initiation} For $n = 10$,
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
% $2^{10} = 1024 > 1000 = 10^3$, so $P(10)$ is true.
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
% \emph{Heredity} Suppose $P(n)$ true, let us prove that $P(n+1)$ is also true.
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
% We want to prove that $2^{n+1} > (n+1)^3$.
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
% \begin{align*}
% P(n) \Leftrightarrow 2^n &> n^3 \\
% 2^n \times 2 &> n^3 \times 2 \qquad \text{because $2 > 0$} \\
% 2^{n+1} &> n^3 + n^3 \\
% \end{align*}
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
% $n^3 = n^2 \times n$
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
% \emph{Conclusion}
% $P(10)$ is true.
2023-01-03 08:42:54 +01:00
2023-02-27 11:07:49 +01:00
% $P(n)$ true implies $P(n+1)$ true, so $P(n)$ is true for all integer $n \geq 10$.
% \end{myanswer}
2023-01-03 08:42:54 +01:00
% \end{myexercise}
% Dirty false proof... To be continued
2023-02-27 11:07:49 +01:00
\subsection { Numbers, Powers and Logarithms}
\begin { myexercise} { 1} { 25}
What is the smallest positive rational number?
\begin { myanswer}
The smallest positive rational number is 0.
\end { myanswer}
\end { myexercise}
\begin { myexercise} { 2} { 25}
Is $ 1 + 0 . 23999999999 ... $ a decimal expansion?
\begin { myanswer}
0.23999999999... is not a decimal number as it has an infinite decimal expansion.
The decimal expansion of $ 1 + 0 . 23999999999 ... $ is in the form
\[
1 \cdot 10^ 0 + 2 \cdot 10^ { -1} + 3 \cdot 10^ { -2} + 9 \cdot 10^ { -3} + \sum _ { i=1} ^ { \infty } 9 \cdot 10^ { -3-i}
\]
\textit { Nota bene} : This surely does not answer the question...
\end { myanswer}
\end { myexercise}
\begin { myexercise} { 3} { 25}
What is $ ( - 3 ) ^ { - 3 } $ ?
\begin { myanswer}
\[
(-3)^ { -3} = \frac { 1} { (-3)^ 3} = \frac { 1} { (-3)(-3)(-3)} = -\frac { 1} { 27}
\]
\end { myanswer}
\end { myexercise}
\begin { myexercise} { 4} { 25}
What is $ ( 0 . 125 ) ^ { - 2 / 3 } $ ?
\begin { equation}
b^ { p/q} = \sqrt [q] { b^ p}
\end { equation}
\begin { myanswer}
\begin { align*}
0.125^ { -2/3} & = \left (\frac { 1} { 8} \right )^ { -2/3} \\
& = 8^ { 2/3} \\
& = \sqrt [3] { 8^ 2} \\
& = \sqrt [3] { 64} \\
& = 4
\end { align*}
\end { myanswer}
\end { myexercise}
\begin { myexercise} { 5} { 25}
Defining real numbers in terms of binary expansion.
\begin { myanswer}
\[
x = \sum _ { i=0} ^ { \infty } a_ i \cdot 2^ { -i}
\]
\end { myanswer}
\end { myexercise}
\begin { myexercise} { 6} { 25}
Let $ x = m + 0 .d _ 1 d _ 2 \dots $ and $ y = n + 0 .e _ 1 e _ 2 \dots $ .
Give a rule for determining whether $ x = y $ , $ x < y $ , $ x > y $ based on the decimal representation.
\begin { myanswer}
\begin { algorithm} [H]
\begin { algorithmic} [1]
\Procedure { LowerGreaterEqual} { $ X $ , $ Y $ }
\Comment { $ X $ and $ Y $ are arrays of decimal of numbers $ x $ and $ y $ respectively.}
\State $ i \gets 0 $
\While { $ i < X.length $ and $ i < Y.length $ }
\If { $ X [ i ] = = Y [ i ] $ }
\State $ i \gets i + 1 $
\ElsIf { $ X [ i ] > Y [ i ] $ }
\State \Return \texttt { GREATER}
\Else
\State \Return \texttt { LOWER}
\EndIf
\EndWhile
\If { $ X.length > Y.length $ }
\State \Return \texttt { GREATER}
\ElsIf { $ X.length < Y.length $ }
\State \Return \texttt { LOWER}
\Else
\State \Return \texttt { EQUALS}
\EndIf
\EndProcedure
\end { algorithmic}
\caption { Greater, Lower or Equal Decimal representation}
\end { algorithm}
\end { myanswer}
\end { myexercise}
\begin { myexercise} { 7} { 25}
Given that $ x $ and $ y $ are integers. \textit { Prove} the laws of exponents, from definition given by Eq. \ref { eq:rule-of-exponents-2} from Eq. \ref { eq:rule-of-exponents} .
\begin { eqnarray}
b^ 0 = 1, & b^ n = b^ { n-1} b \quad \text { if $ n > 0 $ } , & b^ n = b^ { n+1} / b \quad \text { if $ n < 0 $ } .
\label { eq:rule-of-exponents}
\end { eqnarray}
\begin { eqnarray}
b^ { x+y} = b^ x b^ y, & (b^ x)^ y = b^ { xy} ,
\label { eq:rule-of-exponents-2}
\end { eqnarray}
\begin { myanswer}
We will prove this in $ \Reals $
Let us recall the following formula:
\begin { equation}
b^ x = e^ { x \ln b}
\end { equation}
and
\begin { equation}
\exp (x + y) = \exp (x) \exp (y)
\end { equation}
Thus it comes:
\begin { align*}
b^ { x + y} & = e^ { (x + y) \ln b} \\
& = e^ { x \ln b + y \ln b} \\
& = e^ { x \ln b} e^ { y \ln b} \\
& = b^ x b^ y
\end { align*}
Similarly for $ ( a ^ x ) ^ y $ :
\begin { align*}
(a^ x)^ y & = e^ { y \ln (a^ x)} \\
& = e^ { xy \ln a} \\
& = a^ { xy}
\end { align*}
\end { myanswer}
\end { myexercise}