Chapter 1 first version ready
This commit is contained in:
parent
189dfcf070
commit
fb34683355
437
luku01.tex
437
luku01.tex
|
@ -77,7 +77,7 @@ is not an unfair advantage in the contest.
|
||||||
All examples in this book are written in C++,
|
All examples in this book are written in C++,
|
||||||
and the data structures and algorithms in
|
and the data structures and algorithms in
|
||||||
the standard library are often used.
|
the standard library are often used.
|
||||||
The book follows the C++11 standard
|
The book follows the C++11 standard,
|
||||||
that can be used in most contests nowadays.
|
that can be used in most contests nowadays.
|
||||||
If you can't program in C++ yet,
|
If you can't program in C++ yet,
|
||||||
now it is a good time to start learning.
|
now it is a good time to start learning.
|
||||||
|
@ -106,7 +106,8 @@ libraries such as \texttt{iostream},
|
||||||
but they are available automatically.
|
but they are available automatically.
|
||||||
|
|
||||||
The \texttt{using} line determines
|
The \texttt{using} line determines
|
||||||
that the standard library can be used directly
|
that the classes and functions
|
||||||
|
of the standard library can be used directly
|
||||||
in the code.
|
in the code.
|
||||||
Without the \texttt{using} line we should write,
|
Without the \texttt{using} line we should write,
|
||||||
for example, \texttt{std::cout},
|
for example, \texttt{std::cout},
|
||||||
|
@ -514,182 +515,184 @@ This section covers some important
|
||||||
mathematical concepts and formulas that
|
mathematical concepts and formulas that
|
||||||
are needed later in the book.
|
are needed later in the book.
|
||||||
|
|
||||||
\subsubsection{Summakaavat}
|
\subsubsection{Sum formulas}
|
||||||
|
|
||||||
Jokaiselle summalle muotoa
|
Each sum of the form
|
||||||
\[\sum_{x=1}^n x^k = 1^k+2^k+3^k+\ldots+n^k\]
|
\[\sum_{x=1}^n x^k = 1^k+2^k+3^k+\ldots+n^k\]
|
||||||
on olemassa laskukaava,
|
where $k$ is a positive integer,
|
||||||
kun $k$ on jokin positiivinen kokonaisluku.
|
has a closed-form formula that is a
|
||||||
Tällainen laskukaava on aina astetta $k+1$
|
polynomial of degree $k+1$.
|
||||||
oleva polynomi. Esimerkiksi
|
For example,
|
||||||
\[\sum_{x=1}^n x = 1+2+3+\ldots+n = \frac{n(n+1)}{2}\]
|
\[\sum_{x=1}^n x = 1+2+3+\ldots+n = \frac{n(n+1)}{2}\]
|
||||||
ja
|
and
|
||||||
\[\sum_{x=1}^n x^2 = 1^2+2^2+3^2+\ldots+n^2 = \frac{n(n+1)(2n+1)}{6}.\]
|
\[\sum_{x=1}^n x^2 = 1^2+2^2+3^2+\ldots+n^2 = \frac{n(n+1)(2n+1)}{6}.\]
|
||||||
|
|
||||||
\key{Aritmeettinen summa} on summa, \index{aritmeettinen summa@aritmeettinen summa}
|
An \key{arithmetic sum} is a sum \index{arithmetic sum}
|
||||||
jossa jokaisen vierekkäisen luvun erotus on vakio.
|
where the difference between any two consecutive
|
||||||
Esimerkiksi
|
numbers is constant.
|
||||||
|
For example,
|
||||||
\[3+7+11+15\]
|
\[3+7+11+15\]
|
||||||
on aritmeettinen summa,
|
is an arithmetic sum with constant 4.
|
||||||
jossa vakio on 4.
|
An arithmetic sum can be calculated
|
||||||
Aritmeettinen summa voidaan laskea kaavalla
|
using the formula
|
||||||
\[\frac{n(a+b)}{2},\]
|
\[\frac{n(a+b)}{2}\]
|
||||||
jossa summan ensimmäinen luku on $a$,
|
where $a$ is the first number,
|
||||||
viimeinen luku on $b$ ja lukujen määrä on $n$.
|
$b$ is the last number and
|
||||||
Esimerkiksi
|
$n$ is the amount of numbers.
|
||||||
|
For example,
|
||||||
\[3+7+11+15=\frac{4 \cdot (3+15)}{2} = 36.\]
|
\[3+7+11+15=\frac{4 \cdot (3+15)}{2} = 36.\]
|
||||||
Kaava perustuu siihen, että summa muodostuu $n$ luvusta
|
The formula is based on the fact
|
||||||
ja luvun suuruus on keskimäärin $(a+b)/2$.
|
that the sum consists of $n$ numbers and
|
||||||
|
the value of each number is $(a+b)/2$ on average.
|
||||||
|
|
||||||
\index{geometrinen summa@geometrinen summa}
|
\index{geometric sum}
|
||||||
\key{Geometrinen summa} on summa,
|
A \key{geometric sum} is a sum
|
||||||
jossa jokaisen vierekkäisen luvun suhde on vakio.
|
where the ratio between any two consecutive
|
||||||
Esimerkiksi
|
numbers is constant.
|
||||||
|
For example,
|
||||||
\[3+6+12+24\]
|
\[3+6+12+24\]
|
||||||
on geometrinen summa,
|
is a geometric sum with constant 2.
|
||||||
jossa vakio on 2.
|
A geometric sum can be calculated
|
||||||
Geometrinen summa voidaan laskea kaavalla
|
using the formula
|
||||||
\[\frac{bx-a}{x-1},\]
|
\[\frac{bx-a}{x-1}\]
|
||||||
jossa summan ensimmäinen luku on $a$,
|
where $a$ is the first number,
|
||||||
viimeinen luku on $b$ ja vierekkäisten lukujen suhde on $x$.
|
$b$ is the last number and the
|
||||||
Esimerkiksi
|
ratio between consecutive numbers is $x$.
|
||||||
|
For example,
|
||||||
\[3+6+12+24=\frac{24 \cdot 2 - 3}{2-1} = 45.\]
|
\[3+6+12+24=\frac{24 \cdot 2 - 3}{2-1} = 45.\]
|
||||||
|
|
||||||
Geometrisen summan kaavan voi johtaa merkitsemällä
|
This formula can be derived as follows. Let
|
||||||
\[ S = a + ax + ax^2 + \cdots + b .\]
|
\[ S = a + ax + ax^2 + \cdots + b .\]
|
||||||
Kertomalla molemmat puolet $x$:llä saadaan
|
By multiplying both sides by $x$, we get
|
||||||
\[ xS = ax + ax^2 + ax^3 + \cdots + bx,\]
|
\[ xS = ax + ax^2 + ax^3 + \cdots + bx,\]
|
||||||
josta kaava seuraa ratkaisemalla yhtälön
|
and solving the equation
|
||||||
\[ xS-S = bx-a.\]
|
\[ xS-S = bx-a.\]
|
||||||
|
yields the formula.
|
||||||
|
|
||||||
Geometrisen summan erikoistapaus on usein kätevä kaava
|
A special case of a geometric sum is the formula
|
||||||
\[1+2+4+8+\ldots+2^{n-1}=2^n-1.\]
|
\[1+2+4+8+\ldots+2^{n-1}=2^n-1.\]
|
||||||
|
|
||||||
% Geometrisen summan sukulainen on
|
\index{harmonic sum}
|
||||||
% \[x+2x^2+3x^3+\cdots+k x^k = \frac{kx^{k+2}-(k+1)x^{k+1}+x}{(x-1)^2}. \]
|
|
||||||
|
|
||||||
\index{harmoninen summa@harmoninen summa}
|
A \key{harmonic sum} is a sum of the form
|
||||||
|
|
||||||
\key{Harmoninen summa} on summa muotoa
|
|
||||||
\[ \sum_{x=1}^n \frac{1}{x} = 1+\frac{1}{2}+\frac{1}{3}+\ldots+\frac{1}{n}.\]
|
\[ \sum_{x=1}^n \frac{1}{x} = 1+\frac{1}{2}+\frac{1}{3}+\ldots+\frac{1}{n}.\]
|
||||||
|
|
||||||
Yläraja harmonisen summan suuruudelle on $\log_2(n)+1$.
|
An upper bound for the harmonic sum is $\log_2(n)+1$.
|
||||||
Summaa voi näet arvioida ylöspäin
|
The reason for this is that we can
|
||||||
muuttamalla jokaista termiä $1/k$ niin,
|
change each term $1/k$ so that $k$ becomes
|
||||||
että $k$:ksi tulee alempi 2:n potenssi.
|
a power of two that doesn't exceed $k$.
|
||||||
Esimerkiksi tapauksessa $n=6$ arvioksi tulee
|
For example, when $n=6$, we can estimate
|
||||||
|
the sum as follows:
|
||||||
\[ 1+\frac{1}{2}+\frac{1}{3}+\frac{1}{4}+\frac{1}{5}+\frac{1}{6} \le
|
\[ 1+\frac{1}{2}+\frac{1}{3}+\frac{1}{4}+\frac{1}{5}+\frac{1}{6} \le
|
||||||
1+\frac{1}{2}+\frac{1}{2}+\frac{1}{4}+\frac{1}{4}+\frac{1}{4}.\]
|
1+\frac{1}{2}+\frac{1}{2}+\frac{1}{4}+\frac{1}{4}+\frac{1}{4}.\]
|
||||||
Tämän seurauksena summa jakaantuu $\log_2(n)+1$ osaan
|
This upper bound consists of $\log_2(n)+1$ parts
|
||||||
($1$, $2 \cdot 1/2$, $4 \cdot 1/4$, jne.),
|
($1$, $2 \cdot 1/2$, $4 \cdot 1/4$, etc.),
|
||||||
joista jokaisen summa on enintään 1.
|
and the sum of each part is at most 1.
|
||||||
|
|
||||||
\subsubsection{Joukko-oppi}
|
\subsubsection{Set theory}
|
||||||
|
|
||||||
\index{joukko-oppi}
|
\index{set theory}
|
||||||
\index{joukko@joukko}
|
\index{set}
|
||||||
\index{leikkaus@leikkaus}
|
\index{intersection}
|
||||||
\index{yhdiste@yhdiste}
|
\index{union}
|
||||||
\index{erotus@erotus}
|
\index{difference}
|
||||||
\index{osajoukko@osajoukko}
|
\index{subset}
|
||||||
\index{perusjoukko}
|
\index{universal set}
|
||||||
|
\index{complement}
|
||||||
|
|
||||||
\key{Joukko} on kokoelma alkioita.
|
A \key{set} is a collection of elements.
|
||||||
Esimerkiksi joukko
|
For example, the set
|
||||||
\[X=\{2,4,7\}\]
|
\[X=\{2,4,7\}\]
|
||||||
sisältää alkiot 2, 4 ja 7.
|
contains elements 2, 4 and 7.
|
||||||
Merkintä $\emptyset$ tarkoittaa tyhjää joukkoa.
|
The symbol $\emptyset$ denotes an empty set,
|
||||||
Joukon $S$ koko eli alkoiden määrä on $|S|$.
|
and $|S|$ denotes the size of set $S$,
|
||||||
Esimerkiksi äskeisessä joukossa $|X|=3$.
|
i.e., the number of elements in the set.
|
||||||
|
For example, in the above set, $|X|=3$.
|
||||||
|
|
||||||
Merkintä $x \in S$ tarkoittaa,
|
If set $S$ contains element $x$,
|
||||||
että alkio $x$ on joukossa $S$,
|
we write $x \in S$,
|
||||||
ja merkintä $x \notin S$ tarkoittaa,
|
and otherwise we write $x \notin S$.
|
||||||
että alkio $x$ ei ole joukossa $S$.
|
For example, in the above set
|
||||||
Esimerkiksi äskeisessä joukossa
|
\[4 \in X \hspace{10px}\textrm{and}\hspace{10px} 5 \notin X.\]
|
||||||
\[4 \in X \hspace{10px}\textrm{ja}\hspace{10px} 5 \notin X.\]
|
|
||||||
|
|
||||||
\begin{samepage}
|
\begin{samepage}
|
||||||
Uusia joukkoja voidaan muodostaa joukko-operaatioilla
|
New sets can be constructed as follows using set operations:
|
||||||
seuraavasti:
|
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item \key{Leikkaus} $A \cap B$ sisältää alkiot,
|
\item The \key{intersection} $A \cap B$ consists of elements
|
||||||
jotka ovat molemmissa joukoista $A$ ja $B$.
|
that are both in $A$ and $B$.
|
||||||
Esimerkiksi jos $A=\{1,2,5\}$ ja $B=\{2,4\}$,
|
For example, if $A=\{1,2,5\}$ and $B=\{2,4\}$,
|
||||||
niin $A \cap B = \{2\}$.
|
then $A \cap B = \{2\}$.
|
||||||
\item \key{Yhdiste} $A \cup B$ sisältää alkiot,
|
\item The \key{union} $A \cup B$ consists of elements
|
||||||
jotka ovat ainakin toisessa joukoista $A$ ja $B$.
|
that are in $A$ or $B$ or both.
|
||||||
Esimerkiksi jos $A=\{3,7\}$ ja $B=\{2,3,8\}$,
|
For example, if $A=\{3,7\}$ and $B=\{2,3,8\}$,
|
||||||
niin $A \cup B = \{2,3,7,8\}$.
|
then $A \cup B = \{2,3,7,8\}$.
|
||||||
\item \key{Komplementti} $\bar A$ sisältää alkiot,
|
\item The \key{complement} $\bar A$ consists of elements
|
||||||
jotka eivät ole joukossa $A$.
|
that are not in $A$.
|
||||||
Komplementin tulkinta riippuu siitä, mikä on
|
The interpretation of a complement depends on
|
||||||
\key{perusjoukko} eli joukko, jossa on kaikki
|
the \key{universal set} that contains all possible elements.
|
||||||
mahdolliset alkiot. Esimerkiksi jos
|
For example, if $A=\{1,2,5,7\}$ and the universal set is
|
||||||
$A=\{1,2,5,7\}$ ja perusjoukko on $P=\{1,2,\ldots,10\}$,
|
$P=\{1,2,\ldots,10\}$, then $\bar A = \{3,4,6,8,9,10\}$.
|
||||||
niin $\bar A = \{3,4,6,8,9,10\}$.
|
\item The \key{difference} $A \setminus B = A \cap \bar B$
|
||||||
\item \key{Erotus} $A \setminus B = A \cap \bar B$ sisältää alkiot,
|
consists of elements that are in $A$ but not in $B$.
|
||||||
jotka ovat joukossa $A$ mutta eivät joukossa $B$.
|
Note that $B$ can contain elements that are not in $A$.
|
||||||
Huomaa, että $B$:ssä voi olla alkioita,
|
For example, if $A=\{2,3,7,8\}$ and $B=\{3,5,8\}$,
|
||||||
joita ei ole $A$:ssa.
|
then $A \setminus B = \{2,7\}$.
|
||||||
Esimerkiksi jos $A=\{2,3,7,8\}$ ja $B=\{3,5,8\}$,
|
|
||||||
niin $A \setminus B = \{2,7\}$.
|
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
\end{samepage}
|
\end{samepage}
|
||||||
|
|
||||||
|
If each element of $A$ also belongs to $S$,
|
||||||
Merkintä $A \subset S$ tarkoittaa,
|
we say that $A$ is a \key{subset} of $S$,
|
||||||
että $A$ on $S$:n \key{osajoukko}
|
denoted by $A \subset S$.
|
||||||
eli jokainen $A$:n alkio esiintyy $S$:ssä.
|
Set $S$ always has $2^{|S|}$ subsets,
|
||||||
Joukon $S$ osajoukkojen yhteismäärä on $2^{|S|}$.
|
including the empty set.
|
||||||
Esimerkiksi joukon $\{2,4,7\}$
|
For example, the subsets of the set $\{2,4,7\}$ are
|
||||||
osajoukot ovat
|
|
||||||
\begin{center}
|
\begin{center}
|
||||||
$\emptyset$,
|
$\emptyset$,
|
||||||
$\{2\}$, $\{4\}$, $\{7\}$, $\{2,4\}$, $\{2,7\}$, $\{4,7\}$ ja $\{2,4,7\}$.
|
$\{2\}$, $\{4\}$, $\{7\}$, $\{2,4\}$, $\{2,7\}$, $\{4,7\}$ ja $\{2,4,7\}$.
|
||||||
\end{center}
|
\end{center}
|
||||||
|
|
||||||
Usein esiintyviä joukkoja ovat
|
Often used sets are
|
||||||
|
|
||||||
\begin{itemize}[noitemsep]
|
\begin{itemize}[noitemsep]
|
||||||
\item $\mathbb{N}$ (luonnolliset luvut),
|
\item $\mathbb{N}$ (natural numbers),
|
||||||
\item $\mathbb{Z}$ (kokonaisluvut),
|
\item $\mathbb{Z}$ (integers),
|
||||||
\item $\mathbb{Q}$ (rationaaliluvut) ja
|
\item $\mathbb{Q}$ (rational numbers) and
|
||||||
\item $\mathbb{R}$ (reaaliluvut).
|
\item $\mathbb{R}$ (real numbers).
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
|
||||||
Luonnollisten lukujen joukko $\mathbb{N}$ voidaan määritellä
|
The set $\mathbb{N}$ of natural numbers
|
||||||
tilanteesta riippuen kahdella tavalla:
|
can be defined in two ways, depending
|
||||||
joko $\mathbb{N}=\{0,1,2,\ldots\}$
|
on the situation:
|
||||||
tai $\mathbb{N}=\{1,2,3,...\}$.
|
either $\mathbb{N}=\{0,1,2,\ldots\}$
|
||||||
|
or $\mathbb{N}=\{1,2,3,...\}$.
|
||||||
|
|
||||||
Joukon voi muodostaa myös säännöllä muotoa
|
We can also construct a set using a rule of the form
|
||||||
\[\{f(n) : n \in S\},\]
|
\[\{f(n) : n \in S\},\]
|
||||||
missä $f(n)$ on jokin funktio.
|
where $f(n)$ is some function.
|
||||||
Tällainen joukko sisältää kaikki alkiot
|
This set contains all elements $f(n)$
|
||||||
$f(n)$, jossa $n$ on valittu joukosta $S$.
|
where $n$ is an element in $S$.
|
||||||
Esimerkiksi joukko
|
For example, the set
|
||||||
\[X=\{2n : n \in \mathbb{Z}\}\]
|
\[X=\{2n : n \in \mathbb{Z}\}\]
|
||||||
sisältää kaikki parilliset kokonaisluvut.
|
contains all even integers.
|
||||||
|
|
||||||
\subsubsection{Logiikka}
|
\subsubsection{Logic}
|
||||||
|
|
||||||
\index{logiikka@logiikka}
|
\index{logic}
|
||||||
\index{negaatio@negaatio}
|
\index{negation}
|
||||||
\index{konjunktio@konjunktio}
|
\index{conjuction}
|
||||||
\index{disjunktio@disjunktio}
|
\index{disjunction}
|
||||||
\index{implikaatio@implikaatio}
|
\index{implication}
|
||||||
\index{ekvivalenssi@ekvivalenssi}
|
\index{equivalence}
|
||||||
|
|
||||||
Loogisen lausekkeen arvo on joko \key{tosi} (1) tai
|
The value of a logical expression is either
|
||||||
\key{epätosi} (0).
|
\key{true} (1) or \key{false} (0).
|
||||||
Tärkeimmät loogiset operaatiot ovat
|
The most important logical operators are
|
||||||
$\lnot$ (\key{negaatio}),
|
$\lnot$ (\key{negation}),
|
||||||
$\land$ (\key{konjunktio}),
|
$\land$ (\key{conjunction}),
|
||||||
$\lor$ (\key{disjunktio}),
|
$\lor$ (\key{disjunction}),
|
||||||
$\Rightarrow$ (\key{implikaatio}) sekä
|
$\Rightarrow$ (\key{implication}) and
|
||||||
$\Leftrightarrow$ (\key{ekvivalenssi}).
|
$\Leftrightarrow$ (\key{equivalence}).
|
||||||
Seuraava taulukko näyttää operaatioiden merkityksen:
|
The following table shows the meaning of the operators:
|
||||||
|
|
||||||
\begin{center}
|
\begin{center}
|
||||||
\begin{tabular}{rr|rrrrrrr}
|
\begin{tabular}{rr|rrrrrrr}
|
||||||
|
@ -702,67 +705,69 @@ $A$ & $B$ & $\lnot A$ & $\lnot B$ & $A \land B$ & $A \lor B$ & $A \Rightarrow B$
|
||||||
\end{tabular}
|
\end{tabular}
|
||||||
\end{center}
|
\end{center}
|
||||||
|
|
||||||
Negaatio $\lnot A$ muuttaa lausekkeen käänteiseksi.
|
The negation $\lnot A$ reverses the value of an expression.
|
||||||
Lauseke $A \land B$ on tosi, jos molemmat $A$ ja $B$ ovat tosia,
|
The expression $A \land B$ is true if both $A$ and $B$
|
||||||
ja lauseke $A \lor B$ on tosi, jos $A$ tai $B$ on tosi.
|
are true,
|
||||||
Lauseke $A \Rightarrow B$ on tosi,
|
and the expression $A \lor B$ is true if $A$ or $B$ or both
|
||||||
jos $A$:n ollessa tosi myös $B$ on aina tosi.
|
are true.
|
||||||
Lauseke $A \Leftrightarrow B$ on tosi,
|
The expression $A \Rightarrow B$ is true
|
||||||
jos $A$:n ja $B$:n totuusarvo on sama.
|
if whenever $A$ is true, also $B$ is true.
|
||||||
|
The expression $A \Leftrightarrow B$ is true
|
||||||
|
if $A$ and $B$ are both true or both false.
|
||||||
|
|
||||||
\index{predikaatti@predikaatti}
|
\index{predicate}
|
||||||
|
|
||||||
\key{Predikaatti} on lauseke, jonka arvo on tosi tai epätosi
|
A \key{predicate} is an expression that is true or false
|
||||||
riippuen sen parametreista.
|
depending on its parameters.
|
||||||
Yleensä predikaattia merkitään suurella kirjaimella.
|
Predicates are usually denoted by capital letters.
|
||||||
Esimerkiksi voimme määritellä predikaatin $P(x)$,
|
For example, we can define a predicate $P(x)$
|
||||||
joka on tosi tarkalleen silloin, kun $x$ on alkuluku.
|
that is true exactly when $x$ is a prime number.
|
||||||
Tällöin esimerkiksi $P(7)$ on tosi, kun taas $P(8)$ on epätosi.
|
Using this definition, $P(7)$ is true but $P(8)$ is false.
|
||||||
|
|
||||||
\index{kvanttori@kvanttori}
|
\index{quantifier}
|
||||||
|
|
||||||
\key{Kvanttori} ilmaisee, että looginen
|
A \key{quantifier} connects a logical expression
|
||||||
lauseke liittyy jollakin tavalla joukon alkioihin.
|
to elements in a set.
|
||||||
Tavalliset kvanttorit
|
The most important quantifiers are
|
||||||
ovat $\forall$ (\key{kaikille}) ja $\exists$ (\key{on olemassa}).
|
$\forall$ (\key{for all}) and $\exists$ (\key{there is}).
|
||||||
Esimerkiksi
|
For example,
|
||||||
\[\forall x (\exists y (y < x))\]
|
\[\forall x (\exists y (y < x))\]
|
||||||
tarkoittaa, että jokaiselle joukon
|
means that for each element $x$ in the set,
|
||||||
alkiolle $x$ on olemassa
|
there is an element $y$ in the set
|
||||||
jokin joukon alkio $y$ niin, että $y$ on $x$:ää pienempi.
|
such that $y$ is smaller than $x$.
|
||||||
Tämä pätee kokonaislukujen joukossa,
|
This is true in the set of integers,
|
||||||
mutta ei päde luonnollisten lukujen joukossa.
|
but false in the set of natural numbers.
|
||||||
|
|
||||||
Yllä esitettyjen merkintöjä avulla on mahdollista esittää
|
Using the notation described above,
|
||||||
monenlaisia loogisia väitteitä.
|
we can express many kinds of logical propositions.
|
||||||
Esimerkiksi
|
For example,
|
||||||
\[\forall x ((x>2 \land \lnot P(x)) \Rightarrow (\exists a (\exists b (x = ab \land a > 1 \land b > 1))))\]
|
\[\forall x ((x>2 \land \lnot P(x)) \Rightarrow (\exists a (\exists b (x = ab \land a > 1 \land b > 1))))\]
|
||||||
tarkoittaa, että jos luku $x$ on suurempi
|
means that if a number $x$ is larger than 2
|
||||||
kuin 2 eikä ole alkuluku,
|
and not a prime number,
|
||||||
niin on olemassa luvut $a$ ja $b$,
|
there are numbers $a$ and $b$
|
||||||
joiden tulo on $x$ ja jotka molemmat ovat suurempia kuin 1.
|
that are larger than $1$ and whose product is $x$.
|
||||||
Tämä väite pitää paikkansa kokonaislukujen joukossa.
|
This proposition is true in the set of integers.
|
||||||
|
|
||||||
\subsubsection{Funktioita}
|
\subsubsection{Functions}
|
||||||
|
|
||||||
Funktio $\lfloor x \rfloor$ pyöristää luvun $x$
|
The function $\lfloor x \rfloor$ rounds the number $x$
|
||||||
alaspäin kokonaisluvuksi ja
|
down to an integer, and the function
|
||||||
funktio $\lceil x \rceil$ pyöristää luvun $x$
|
$\lceil x \rceil$ rounds the number $x$
|
||||||
ylöspäin kokonaisluvuksi. Esimerkiksi
|
up to an integer. For example,
|
||||||
\[ \lfloor 3/2 \rfloor = 1 \hspace{10px} \textrm{ja} \hspace{10px} \lceil 3/2 \rceil = 2.\]
|
\[ \lfloor 3/2 \rfloor = 1 \hspace{10px} \textrm{and} \hspace{10px} \lceil 3/2 \rceil = 2.\]
|
||||||
|
|
||||||
Funktiot $\min(x_1,x_2,\ldots,x_n)$
|
The functions $\min(x_1,x_2,\ldots,x_n)$
|
||||||
ja $\max(x_1,x_2,\ldots,x_n)$
|
and $\max(x_1,x_2,\ldots,x_n)$
|
||||||
palauttavat pienimmän ja suurimman
|
return the smallest and the largest of values
|
||||||
arvoista $x_1,x_2,\ldots,x_n$.
|
$x_1,x_2,\ldots,x_n$.
|
||||||
Esimerkiksi
|
For example,
|
||||||
\[ \min(1,2,3)=1 \hspace{10px} \textrm{ja} \hspace{10px} \max(1,2,3)=3.\]
|
\[ \min(1,2,3)=1 \hspace{10px} \textrm{and} \hspace{10px} \max(1,2,3)=3.\]
|
||||||
|
|
||||||
\index{kertoma@kertoma}
|
\index{factorial}
|
||||||
|
|
||||||
\key{Kertoma} $n!$ määritellään
|
The \key{factorial} $n!$ is defined
|
||||||
\[\prod_{x=1}^n x = 1 \cdot 2 \cdot 3 \cdot \ldots \cdot n\]
|
\[\prod_{x=1}^n x = 1 \cdot 2 \cdot 3 \cdot \ldots \cdot n\]
|
||||||
tai vaihtoehtoisesti rekursiivisesti
|
or recursively
|
||||||
\[
|
\[
|
||||||
\begin{array}{lcl}
|
\begin{array}{lcl}
|
||||||
0! & = & 1 \\
|
0! & = & 1 \\
|
||||||
|
@ -770,10 +775,10 @@ n! & = & n \cdot (n-1)! \\
|
||||||
\end{array}
|
\end{array}
|
||||||
\]
|
\]
|
||||||
|
|
||||||
\index{Fibonaccin luku@Fibonaccin luku}
|
\index{Fibonacci number}
|
||||||
|
|
||||||
\key{Fibonaccin luvut} esiintyvät monissa erilaisissa yhteyksissä.
|
The \key{Fibonacci numbers} arise in several situations.
|
||||||
Ne määritellään seuraavasti rekursiivisesti:
|
They can be defined recursively as follows:
|
||||||
\[
|
\[
|
||||||
\begin{array}{lcl}
|
\begin{array}{lcl}
|
||||||
f(0) & = & 0 \\
|
f(0) & = & 0 \\
|
||||||
|
@ -781,56 +786,58 @@ f(1) & = & 1 \\
|
||||||
f(n) & = & f(n-1)+f(n-2) \\
|
f(n) & = & f(n-1)+f(n-2) \\
|
||||||
\end{array}
|
\end{array}
|
||||||
\]
|
\]
|
||||||
Ensimmäiset Fibonaccin luvut ovat
|
The first Fibonacci numbers are
|
||||||
\[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, \ldots\]
|
\[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, \ldots\]
|
||||||
Fibonaccin lukujen laskemiseen on olemassa myös
|
There is also a closed-form formula
|
||||||
suljetun muodon kaava
|
for calculating Fibonacci numbers:
|
||||||
\[f(n)=\frac{(1 + \sqrt{5})^n - (1-\sqrt{5})^n}{2^n \sqrt{5}}.\]
|
\[f(n)=\frac{(1 + \sqrt{5})^n - (1-\sqrt{5})^n}{2^n \sqrt{5}}.\]
|
||||||
|
|
||||||
\subsubsection{Logaritmi}
|
\subsubsection{Logarithm}
|
||||||
|
|
||||||
\index{logaritmi@logaritmi}
|
\index{logarithm}
|
||||||
|
|
||||||
Luvun $x$
|
The \key{logarithm} of a number $x$
|
||||||
\key{logaritmi} merkitään $\log_k(x)$, missä $k$ on logaritmin kantaluku.
|
is denoted $\log_k(x)$ where $k$ is the base
|
||||||
Logaritmin määritelmän mukaan
|
of the logarithm.
|
||||||
$\log_k(x)=a$ tarkalleen silloin, kun $k^a=x$.
|
The logarithm is defined so that
|
||||||
|
$\log_k(x)=a$ exactly when $k^a=x$.
|
||||||
|
|
||||||
Algoritmiikassa hyödyllinen tulkinta on,
|
A useful interpretation in algorithmics is
|
||||||
että logaritmi $\log_k(x)$ ilmaisee, montako kertaa lukua $x$
|
that $\log_k(x)$ equals the number of times
|
||||||
täytyy jakaa $k$:lla, ennen kuin tulos on 1.
|
we have to divide $x$ by $k$ before we reach
|
||||||
Esimerkiksi $\log_2(32)=5$,
|
the number 1.
|
||||||
koska lukua 32 täytyy jakaa 2:lla 5 kertaa:
|
For example, $\log_2(32)=5$
|
||||||
|
because 5 divisions are needed:
|
||||||
|
|
||||||
\[32 \rightarrow 16 \rightarrow 8 \rightarrow 4 \rightarrow 2 \rightarrow 1 \]
|
\[32 \rightarrow 16 \rightarrow 8 \rightarrow 4 \rightarrow 2 \rightarrow 1 \]
|
||||||
|
|
||||||
Logaritmi tulee usein vastaan algoritmien analyysissa,
|
Logarithms are often needed in the analysis of
|
||||||
koska monessa tehokkaassa algoritmissa jokin asia puolittuu
|
algorithms because many efficient algorithms
|
||||||
joka askeleella.
|
divide in half something at each step.
|
||||||
Niinpä logaritmin avulla voi arvioida algoritmin tehokkuutta.
|
Thus, we can estimate the efficiency of those algorithms
|
||||||
|
using the logarithm.
|
||||||
|
|
||||||
Logaritmille pätee kaava
|
The logarithm of a product is
|
||||||
\[\log_k(ab) = \log_k(a)+\log_k(b),\]
|
\[\log_k(ab) = \log_k(a)+\log_k(b),\]
|
||||||
josta seuraa edelleen
|
and consequently,
|
||||||
\[\log_k(x^n) = n \cdot \log_k(x).\]
|
\[\log_k(x^n) = n \cdot \log_k(x).\]
|
||||||
Samoin logaritmille pätee
|
In addition, the logarithm of a quotient is
|
||||||
\[\log_k\Big(\frac{a}{b}\Big) = \log_k(a)-\log_k(b).\]
|
\[\log_k\Big(\frac{a}{b}\Big) = \log_k(a)-\log_k(b).\]
|
||||||
Lisäksi on voimassa kaava
|
Another useful formula is
|
||||||
\[\log_u(x) = \frac{\log_k(x)}{\log_k(u)},\]
|
\[\log_u(x) = \frac{\log_k(x)}{\log_k(u)},\]
|
||||||
minkä ansiosta logaritmeja voi laskea mille tahansa kantaluvulle,
|
and using this, it is possible to calculate
|
||||||
jos on keino laskea logaritmeja jollekin kantaluvulle.
|
logarithms to any base if there is a way to
|
||||||
|
calculate logarithms to some fixed base.
|
||||||
|
|
||||||
\index{luonnollinen logaritmi@luonnollinen logaritmi}
|
\index{natural logarithm}
|
||||||
\index{Neperin luku@Neperin luku}
|
|
||||||
|
|
||||||
Luvun $x$ \key{luonnollinen logaritmi} $\ln(x)$ on logaritmi, jonka kantaluku on
|
The \key{natural logarithm} $\ln(x)$ of a number $x$
|
||||||
\key{Neperin luku} $e \approx 2{,}71828$.
|
is a logarithm whose base is $e \approx 2{,}71828$.
|
||||||
|
|
||||||
Vielä yksi logaritmin ominaisuus on, että
|
Another property of the logarithm is that
|
||||||
luvun $x$ numeroiden määrä $b$-kantaisessa
|
the number of digits of a number $x$ in base $b$ is
|
||||||
lukujärjestelmässä
|
$\lfloor \log_b(x)+1 \rfloor$.
|
||||||
on $\lfloor \log_b(x)+1 \rfloor$.
|
For example, the representation of
|
||||||
Esimerkiksi luvun $123$ esitys
|
the number $123$ in base $2$ is 1111011 and
|
||||||
2-järjestelmässä on 1111011 ja
|
|
||||||
$\lfloor \log_2(123)+1 \rfloor = 7$.
|
$\lfloor \log_2(123)+1 \rfloor = 7$.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue