diff --git a/tex/TheLuaChameleonBook.cls b/tex/TheLuaChameleonBook.cls index 0a35738..1882f07 100755 --- a/tex/TheLuaChameleonBook.cls +++ b/tex/TheLuaChameleonBook.cls @@ -76,6 +76,7 @@ %---------------------------------------------------------------------------------------- \usepackage{fontspec} +\usepackage{lmodern} \usepackage{ulem} %---------------------------------------------------------------------------------------- @@ -126,7 +127,7 @@ \node[anchor=north east, inner sep=0pt, xshift=-\Gm@rmargin, yshift=-\Gm@tmargin] at (current page.north east) {\fontsize{30pt}{30pt}\selectfont\sffamily\bfseries\textcolor{primarycolor}{\strut #2}}; % Part title \node[anchor=south east, inner sep=0pt, xshift=-\Gm@rmargin, yshift=\Gm@bmargin] at (current page.south east) { % Mini table of contents \parbox[t][][t]{8.5cm}{ % Width of box holding the mini ToC - \printcontents[part]{l}{0}{\setcounter{tocdepth}{1}} % Display the mini table of contents showing chapters and sections, change tocdepth to 2 to also show subsections or 0 to only show chapters + \printcontents[part]{l}{0}{\setcounter{tocdepth}{3}} % Display the mini table of contents showing chapters and sections, change tocdepth to 2 to also show subsections or 0 to only show chapters } }; \end{tikzpicture} diff --git a/tex/content/chapters/include.tex b/tex/content/chapters/include.tex index 224a891..4e5425e 100755 --- a/tex/content/chapters/include.tex +++ b/tex/content/chapters/include.tex @@ -15,4 +15,4 @@ \includechapters{part01}{2} -\includechapters{part02}{2} \ No newline at end of file +% \includechapters{part02}{2} \ No newline at end of file diff --git a/tex/content/chapters/part01/0.tex b/tex/content/chapters/part01/0.tex index e69de29..ebca180 100755 --- a/tex/content/chapters/part01/0.tex +++ b/tex/content/chapters/part01/0.tex @@ -0,0 +1 @@ +\part{} \ No newline at end of file diff --git a/tex/content/chapters/part01/1.tex b/tex/content/chapters/part01/1.tex index e69de29..6e1cf9f 100755 --- a/tex/content/chapters/part01/1.tex +++ b/tex/content/chapters/part01/1.tex @@ -0,0 +1,270 @@ +\chapter{Basic concepts} + +\section{Algorithms} + +\section{Mathematical Preliminaries} + +\subsection{Mathematical induction} + +\begin{myexercise}{4}{18} + + 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} +\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} + + 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. + +\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 +\[ +T_n = \sum_{i=0}^n (-1)^i (n-i)^2 +\] + +With little help from formal computation, we get +\begin{equation} +T_n = \frac{1}{2} n (n + 1) +\label{eq:ex7_half_factor_n_n+1} +\end{equation} + +\begin{proof} + Let us prove the formula. + + Let $P(n)$ be the proposition that Eq. \ref{eq:ex7_half_factor_n_n+1} is correct for $T_n$. + + By recursion on $n$ + + \emph{Initiation} + + For $n = 1$, $1^2 = 1$ and $\frac{1}{2} 1 \times (1+1) = 1$, so $P(n)$ is true. + + \emph{Heredity} + + 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 +\end{proof} + +\end{myanswer} +\end{myexercise} + +\begin{myexercise}{8}{19} + (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 + 2i|$''. + + \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} +\end{myexercise} + +\begin{myexercise}{9}{19} + Prove by induction that if $0 < a < 1$ then $(1 - a)^n \geq 1 - na$. + \begin{myanswer} + We proceed by recursion on $n$. + + Let $P(n)$ be the proposition ``$(1 - a)^n \geq 1 - na$''. + + \emph{Initiation} For $n = 0$, + + $(1 - a)^n = 1 = 1 - na$, so $P(0)$ is true. + + \emph{Heredity} Suppose $P(n)$ true, let us prove that $P(n+1)$ is also true. + + We want to prove that $(1 - a)^{n+1} \geq 1 - (n+1)a$. + + \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*} + + \emph{Conclusion} + $P(1)$ is true. + + $P(n)$ true implies $P(n+1)$ true, so $P(n)$ is true for all $n \in \mathbb{N}_+$. + \end{myanswer} +\end{myexercise} + +% \begin{myexercise}{10}{19} +% Prove by induction that if $n \geq 10$ then $2^n > n^3$. + +% \begin{myanswer} +% We proceed by recursion on $n$. + +% Let $P(n)$ be the proposition ``$2^n > n^3$''. + +% \emph{Initiation} For $n = 10$, + +% $2^{10} = 1024 > 1000 = 10^3$, so $P(10)$ is true. + +% \emph{Heredity} Suppose $P(n)$ true, let us prove that $P(n+1)$ is also true. + +% We want to prove that $2^{n+1} > (n+1)^3$. + +% \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*} + +% $n^3 = n^2 \times n$ + +% \emph{Conclusion} +% $P(10)$ is true. + +% $P(n)$ true implies $P(n+1)$ true, so $P(n)$ is true for all integer $n \geq 10$. +% \end{myanswer} +% \end{myexercise} +% Dirty false proof... To be continued + diff --git a/tex/content/introduction.tex b/tex/content/introduction.tex index 4ecda9a..0dc24e4 100755 --- a/tex/content/introduction.tex +++ b/tex/content/introduction.tex @@ -1,8 +1 @@ -\chapter{Introduction} - -Here we go - -\part{Hello, world} - - -\section{What did you expect ?} \ No newline at end of file +\chapter*{Introduction} diff --git a/tex/main.ist b/tex/main.ist index 069525b..888482b 100755 --- a/tex/main.ist +++ b/tex/main.ist @@ -1,5 +1,5 @@ % makeindex style file created by the glossaries package -% for document 'main' on 2022-12-31 +% for document 'main' on 2023-1-3 actual '?' encap '|' level '!' diff --git a/tex/main.pdf b/tex/main.pdf index add47c5..34a7463 100755 Binary files a/tex/main.pdf and b/tex/main.pdf differ diff --git a/tex/main.tex b/tex/main.tex index 2ac95d3..da63548 100755 --- a/tex/main.tex +++ b/tex/main.tex @@ -47,6 +47,9 @@ \makeglossaries \makeindex +\input{preamble.tex} +\setcounter{tocdepth}{2} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % DOCUMENT %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -61,11 +64,11 @@ {\includegraphics[width=\paperwidth]{background.pdf}} % Code to output the background image, which should be the same dimensions as the paper to fill the page entirely; leave empty for no background image { % Title(s) and author(s) \centering\sffamily % Font styling - {\Huge\bfseries Exploring the Physical Manifestation of Humanity's Subconscious Desires\par} % Book title + {\Huge\bfseries The Art of Computer Programming Vol. 1 - Some Exercises \par} % Book title \vspace{16pt} % Vertical whitespace - {\LARGE A Practical Guide\par} % Subtitle + {\LARGE An Attempt to solve some of the exercises\\ from the Book of Donald E. KNUTH\par} % Subtitle \vspace{24pt} % Vertical whitespace - {\huge\bfseries Goro Akechi\par} % Author name + {\huge\bfseries Samuel ORTION\par} % Author name } diff --git a/tex/preamble.tex b/tex/preamble.tex index e69de29..52f58e2 100755 --- a/tex/preamble.tex +++ b/tex/preamble.tex @@ -0,0 +1,66 @@ + +\usepackage{xstring} + +\newcommand{\unfinished}{ + \textbf{\textcolor{orange!90}{to be continued...}} +} + +\newcommand{\unresolved}{ + \textbf{\textcolor{red!90}{unresolved}} +} + +% Create a new environment {exercise} to refer to exercises from the KNUTH book. +% Add a TODO switch option to show unresolved exercises +\newenvironment{myexercise}[2] +{ + \addcontentsline{toc}{subsubsection}{Exercise #1} + \begin{minipage}{\textwidth} + \begin{flushleft} + { + \Huge + \textbf{Exercise #1.} (p. #2) + } + \end{flushleft} +} +{ + \end{minipage} +} + +% Create a new environment for big quote with `primarycolor' coloured quote sign +\newenvironment{myquote} +{ + \begin{minipage}{\textwidth} + \begin{flushleft} + { + + \fontsize{75pt}{3pt}\selectfont + \textcolor{primarycolor}{\textquotedblleft} + } +} +{ + \begin{flushright} + { + \textcolor{primarycolor}{\textquotedblright} + } + + \end{flushright} + \end{flushleft} + \end{minipage} +} + +\newenvironment{myanswer} +{ + \begin{minipage}{\textwidth} + \begin{itshape} + \begin{flushleft} + { + \Large + \textbf{My Answer}: + } +} +{ + \end{flushleft} + \end{itshape} + \end{minipage} +} +