ktsk
https://ktsk.xyz
Personal web of Tomas KoutskyZolaenMon, 23 Aug 2021 00:00:00 +0000MU123 Unit 14 NotesMon, 23 Aug 2021 00:00:00 +0000
https://ktsk.xyz/posts/mu123unit14/
https://ktsk.xyz/posts/mu123unit14/<h1 id="1communicatingclearly">1 Communicating clearly</h1>
<h2 id="11interpretinginformationaboutrisk">1.1 Interpreting information about risk</h2>
<p><strong>Probability</strong>, <strong>chance</strong> or <strong>risk</strong> defines how likely is something to occur.</p>
<p>Probabilities can be expressed as fractions, decimals or percentages, or in the form of an $x$ in $y$ chance.</p>
<h2 id="12interpretinggraphsandcharts">1.2 Interpreting graphs and charts</h2>
<p><strong>Comparative bar chart</strong> is a bar chart with tow or more bars for each data item.
<strong>Pictogram</strong> is a chart that conveys numerical information by means of pictures.</p>
<h1 id="2extendingyourmathematicalskills">2 Extending your mathematical skills</h1>
<h2 id="21developingyourequationsolvingskills">2.1 Developing your equationsolving skills</h2>
<h3 id="usingshortcuts">Using shortcuts</h3>
<h4 id="crossmultiplying">Crossmultiplying</h4>
<p>$$
\frac{A}{B} = \frac{C}{D} \\[1em]
BD \times \frac{A}{B} = BD \times \frac{C}{D} \\[1em]
AD = BC
$$</p>
<h2 id="22solvingtrigonometricequations">2.2 Solving trigonometric equations</h2>
<h3 id="sinescosinesandtangentsofrelatedangles">Sines, cosines and tangents of related angles</h3>
<p>In general, for any acute angle $\theta$ the for angles</p>
<p>$\theta$, $180^\circ\theta$, $180^\circ+\theta$, $360^\circ\theta$</p>
<p>all have the same sine, cosine and tangent, except for the signs.
The signs are determined by the sings that th $x$ and $y$coordinates take in the different quadrats:</p>
<ul>
<li>In the first quadrant, $x$ and $y$ are both positive, so sine, cosine and tangent are all positive.</li>
<li>In the second quadrant, $x$ is negative and $y$ is positive, so sine is positive and cosine is negative, and hence tangent is negative.</li>
<li>In the third quadrant, $x$ and $y$ are both negative, so sine and cosine are both negative, and hence tangent is positive.</li>
<li>In the fourth quadrant, $x$ is positive and $y$ is negative, so sine is negative and cosine is positive, and hence tangent is negative.</li>
</ul>
<p>The sings can be remembered using <strong>CAST</strong>:</p>
<table><thead><tr><th>S (Sin positive)</th><th>A (All positive)</th></tr></thead><tbody>
<tr><td>T (Tan positive)</td><td>C (Cos positive)</td></tr>
</tbody></table>
<h2 id="23findingtheangleofinclinationofaline">2.3 Finding the angle of inclination of a line</h2>
<p><strong>Angle of inclination</strong> of a line is its angle measured anticlockwise from the positive direction of the $x$axis, when the line is drawn on a pair of axes with equal scales.</p>
<h3 id="gradientandangleofinclinationofastraightline">Gradient and angle of inclination of a straight line</h3>
<p>For any straight line with angle of inclination $\theta$,
$$
\text{gradient} = \tan \theta
$$
Remember that the angle of inclination is measured when the line is drawn on axes <em>with equal scales</em>.</p>
<h2 id="24solvingtrigonometricequationsinradians">2.4 Solving trigonometric equations in radians</h2>
<p>The quadrants</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;"> pi/2

pi  0 and 2pi

3pi/2
</span></code></pre><h2 id="42exploringsinusoidalfunctions">4.2 Exploring sinusoidal functions</h2>
<p>A curve that can be obtained from the graph of the sine function by shifting, stretching or compressing it horizontally or vertically is called a <strong>sinusoidal curve</strong>.
A function whose graph is sinusoidal curve is called a <strong>sinusoidal function</strong>.</p>
<p><strong>General sine functions</strong> and <strong>general cosine functions</strong> are functions with roles of following forms:
$$
y = a \sin(b(x  c)) + d
$$
and
$$
y = a \cos (b(x + c)) + d
$$
where $a$, $b$, $c$ and $d$ are constants.</p>
<p>The $y$values of any sinusoidal function <em>oscillates</em> between a minimum value and a maximum value and the shape of the graph is continually repeated.
<strong>Period</strong> of the graph is the length on the $x$axis that it takes for the graph to repeat. Any section of the graph covering this length on the $x$axis is referred to as an <strong>oscillation</strong>.</p>
<h3 id="theperiodofgeneralsineorcosinefunction">The period of general sine or cosine function</h3>
<p>The period of $y = a \sin(b(x  c)) + d$ or $y = a \cos (b(x + c)) + d$ is:
$$
\frac{2\pi}{b}
$$</p>
<h3 id="thegraphofageneralsinefunction">The graph of a general sine function</h3>
<p>The graph of the equation
$$
y = a \sin(b(x  c)) + d
$$
where $a$ and $b$ are positive, and $c$ and $d$ can take any values, has the following features.</p>
<ul>
<li>$a$ is the <strong>amplitude</strong>: the distance between the center line and the maximum (or minimum) value.</li>
<li>$b$ determines the <em>period</em>, which is equal to $2\pi/b$.</li>
<li>$c$ is the <strong>horizontal displacement</strong>: the amount that the graph of $y = a \sin (bx) + d$ is shifhted to the right to obtain the graph of $y = a \sin (b(x  c)) + d$. (The shift is to the left if $c$ is negative.)</li>
<li>$d$ is the <strong>vertical displacement</strong>: the amount that the center line is shifted up from the $x$axis. (The shift is down if $d$ is negative.)</li>
<li>The minimum value is $d  a$ (the vertical displacement minus the amplitude)</li>
<li>The maximum value is $d + a$ (the vertical displacement plus the amplitude)</li>
</ul>
MU123 Unit 13 NotesThu, 05 Aug 2021 00:00:00 +0000
https://ktsk.xyz/posts/mu123unit13/
https://ktsk.xyz/posts/mu123unit13/<h1 id="introduction">Introduction</h1>
<p>Exponential growth or decay happens when the numbers increase or decrease by the same factor at each stage.</p>
<h1 id="1exponentialgrowthanddecay">1 Exponential growth and decay</h1>
<h2 id="11doublingandhalving">1.1 Doubling and halving</h2>
<p>Exponential growth is growth that arises by repeated multiplication by the same number.
<strong>Starting number</strong> is a number that is started with.
<strong>Scale factor</strong> is a multiplier.
For exponential growth, the scale factor must be greater than 1.</p>
<p>In general, if the starting value is $a$ and the scale factor $b$ then:</p>
<ul>
<li>The initial value is $a$</li>
<li>After 1 step, the value is $a \times b = ab$</li>
<li>After 2 steps, the value is $a \times b \times b = ab^2$</li>
<li>After 3 steps, the value is $a \times b \times b \times b = ab^3$</li>
</ul>
<p>Hence after $n$ steps, the value is $ab^n$.</p>
<h2 id="12multiplyingbyascalefactor">1.2 Multiplying by a scale factor</h2>
<h2 id="13discreeteandcontinuousexponentialgrowthanddecay">1.3 Discreete and continuous exponential growth and decay</h2>
<p>A variable $y$ is said to <strong>change exponentially</strong> with respect to a variable $x$ if the relationship between $x$ and $y$ is given by an equation of the form
$$
y = ab^x
$$
where $a$ and $b$ are positive constants, with $b$ not equal to $1$.</p>
<p>If $b > 1$, then $y$ <strong>grows exponentially</strong>.
If $0 < b < 1$, then $y$ <strong>decays exponentially</strong>.</p>
<p>If the change happens in steps ($x$ takes values from a range of equally spaced numbers, such as the nonnegative integers), then it is <strong>discreete exponential change</strong> (also called <strong>geometric change</strong>).</p>
<p>If the change happens continuosly ($x$ takes values from an interval of real numbers, such as the nonnegative real numbers), then it is <strong>continuous exponential change</strong>.</p>
<p>The curve formed by exponential equation $y = ab^x$ is called an <strong>exponential curve</strong>.</p>
<h2 id="14usingcontinuosexponentialmodels">1.4 Using continuos exponential models</h2>
<h2 id="15exponentialmodelsfromdata">1.5 Exponential models from data</h2>
<p><strong>Linear regression</strong> is the process of fitting the best straight line to a set of data points.
<strong>Exponential regression</strong> is similar process used to fit the best exponential curve to a set of data points.</p>
<h1 id="2workingwithexponentialgrowthanddecay">2 Working with exponential growth and decay</h1>
<h2 id="21growthanddecaytoparticularsizes">2.1 Growth and decay to particular sizes</h2>
<h2 id="22growthanddecayoverdifferentlengthsoftime">2.2 Growth and decay over different lengths of time</h2>
<p><strong>Discrete exponential change over different numbers of steps.</strong>
Suppose that a quantity changes by the scale factor $b$ at each step.
Then every $i$ steps it changes by the scale factor $b^i$.</p>
<p><strong>Continuous exponential change over different time periods</strong>
Suppose that a qunatity is subject to continuous exponential change by the scale factor $b$ every year.</p>
<p>Then over any time interval of length $i$ years, it changes by the scale factor $b^i$.</p>
<p>(The same is true if time is measured in any other unit, such as weeks, days or minutes.)</p>
<h1 id="3exponentialcurves">3 Exponential curves</h1>
<p>TODO(p24): Check Unit 3</p>
<h2 id="graphsofequationsoftheformyabx">Graphs of equations of the form $y = ab^x$</h2>
<ul>
<li>If $a > 0$ then the graph lies entirely above the $x$axis. If also
<ul>
<li>$b > 1$, then the graph is an exponential growth curve</li>
<li>$0 < b < 1$, then the graph is an exponential decay curve</li>
<li>$b = 1$, then the graph is a horizontal line</li>
</ul>
</li>
<li>If $a < 0$ then the graph lies entirely below the $x$axis and is neither an exponential growth curve nor an exponential decay curve</li>
<li>The $x$axis is an asymptote (except when $a = 0$ or $b = 1$)</li>
<li>The $y$intercept is $a$</li>
<li>The closer the value of $b$ is to $1$ (and the closer the value of $a$ is to $0$) the flatter is the graph</li>
</ul>
<h2 id="33eulersnumbere">3.3 Euler's number $e$</h2>
<p>Irrational number usually denoted by letter $e$, approximately $2.71828...$.
When $e$ is a value on of $b$ in exponential function then the gradient of $1$ is given at $(0, 1)$.</p>
<h1 id="4logarithms">4 Logarithms</h1>
<p>Equations like
$$
170 \times 1.23^t = 7~000~000~000
$$
where the unknown is in an exponent, are known as <strong>exponential equations</strong>.
Solving such an equation involves the use of <em>logarithms</em>, (<em>logs</em> for short).</p>
<h2 id="41abriefhistoryoflogarithms">4.1 A brief history of logarithms</h2>
<p>Logarithms were invented by John Napier in 16th century to solve the problem of multiplication and division of large numbers in astronavigation.</p>
<p>He used the $a^m \times a^n = a^{m + n}$ law to turn multiplication problem into addition one. </p>
<p>So, in ordert to multipy e.g. 287 and 37 the numbers need to be rewritten as a common base to a power of something:
$$
287 \times 37 \approx 10^{2.4579} \times 10^{1.5682} \\
= 10^{2.4579 + 1.5682} \\
= 10^{4.0261} \\
\approx 10619
$$</p>
<p>However, there is still problem of finding the correct powers of ten for the numbers to be multiplied, and of turning the power of ten obtained as the answer back into an ordinary number.</p>
<p>The problem was solved by drawing up sets of tables to be used whenever such calculation arised. The tables gave the power of ten corresponding to each number that might need to be multiplied  called the <strong>logarithms</strong> of the numbers.</p>
<p>The tables were also used to find the ordinary number corresponding to each ower  <strong>antilogarithms</strong> of the powers.</p>
<h2 id="42logarithmstobase10">4.2 Logarithms to base 10</h2>
<p>As mentioned, the logarithm of a number is the power to which 10 must be raised to give the number. Such logarithms are called <strong>logarithms to base</strong> since 10 has been chosen as the base.</p>
<p>Logarithms to base 10 are also called <strong>common logarithms</strong>.</p>
<p>Following common logarithm (in mathematical notation):
$$
\log_{10}100 = 2
$$
is described as "the logarithm to base 10 of 100 equals 2".</p>
<p>It also applies that following statements
$10^2 = 100$ and $\log_{10}100 = 2$
are equivalent.</p>
<p>In summary, <strong>logarithms to base 10</strong> of a number $x$, denoted by $\log_{10}x$, is the power to which you have to raise $10$ to get the answer $x$. </p>
<p>The subscript 10 can be omitted when</p>
<ul>
<li>it is understood that a logarithm is a common logarithm.</li>
<li>When the notation is used in an equation involing logarithms that is true no matter what the base is.</li>
</ul>
<p>Raising 10 to a number and finding the logarithm of a number to base 10 are <strong>inverse operations</strong>.</p>
<h2 id="44logarithmstootherbases">4.4 Logarithms to other bases</h2>
<p>The <strong>logarithm to base</strong> $b$ of a number $x$, denoted by $\log_bx$, is the power to which you have to raise the base $b$ to get the anser $x$. So the two equations
$x = b^y$ and $y = log_bx$
are equivalent.</p>
<p>Given that</p>
<ul>
<li>The base $b$ must be positive and not equal to 1.</li>
<li>Only positive numbers have logarithms, but logarithsm themselves can be any number</li>
</ul>
<p>Euler's number $e$ is often used as a base for logarithms, called <strong>natural logarithms</strong>. The notation $\ln$ is usually used in place of $\log_e$, hence, e.g. the natural logarithm of 5 is written as
$$
\ln5
$$</p>
<p>Hence the <strong>natural logarithm</strong> of a number $x$, denoted by $\ln x$, is the power to which you have to rase the base $e$ to get the answer $x$. So the two equations
$x = e^y$ and $y = \ln x$
are equivalent.</p>
<h3 id="logarithmofthenumberoneandlogarithmofthebase">Logarithm of the number one and logarithm of the base</h3>
<p>For any base $b$,
$\log_b1=0$ and $\log_bb=1$</p>
<h1 id="5workingwithlogarithms">5 Working with logarithms</h1>
<h2 id="51threelogarithmlaws">5.1 Three logarithm laws</h2>
<h3 id="ruleforadditionoflogarithms">Rule for addition of logarithms</h3>
<p>$$
\log x + \log y = \log(xy)
$$</p>
<h4 id="formalproof">Formal proof</h4>
<p>Suppose that the numbers $x$ and $y$ can be written as $b^m$ and $b^n$, that is
$x = b^m$ and $y = b^n$
Then
$m = \log_bx$ and $n = \log_by$
The product $xy$ can be written as
$xy = b^m \times b^n = b^{m + n}$
This means that the power to which $b$ must be raised to give $xy$ is $m + n$, that is
$\log_b(xy) = m + n = \log_bx + \log_by$
which is the logarithm law above.</p>
<h3 id="ruleforsubtractionoflogarithms">Rule for subtraction of logarithms</h3>
<p>$$
\log x  \log y = log (\frac{x}{y})
$$</p>
<h4 id="formalproof1">Formal proof</h4>
<p>$$
x = b^m ~~~ y = b^n \\[1em]
m = \log_bx ~~~ n = \log_by \\[1em]
\frac{x}{y} = \frac{b^m}{b^n} = b^{m  n} \\[1em]
\log_b(\frac{x}{y}) = m  n = \log_bx  \log_by \\
$$</p>
<h3 id="ruleforamultipleofalogarithm">Rule for a multiple of a logarithm</h3>
<p>$$
n \log x = \log (x^n)
$$</p>
<h4 id="formalproof2">Formal proof</h4>
<p>Suppose that
$$
x = b^m \\[1em]
m = \log_bx \\[1em]
$$
The power $x^n$ can be written as
$$
x^n = (b^m)^n = b^{m + n} \\[1em]
$$
Hence the power to which $b$ must be raised to give $x^n$ is $mn$, that is
$$
\log_b(x^n) = mn = n\log_bx
$$
Which is the logarithm law above.</p>
<h2 id="52solvingexponentialequationsbytakinglogs">5.2 Solving exponential equations by taking logs</h2>
<p>Exponential equations is an equation where the unknown is in an exponent, e.g.
$$
170 \times 1.23^t = 7 000 000 000
$$</p>
<p>Basic procedure for solving such equations is to take the logarithm of both sides and then applying the logarithm law $\log(x^n) = n\log x$.</p>
<p>This method works the best when one side of the equation consists only of a number raised to an exponent containing unknown. An equation of different form shoud be rearranged.</p>
<h3 id="logarithmicidentity">Logarithmic identity</h3>
<p>$$
\ln(e^x) = x
$$
and
$$
e^{\ln x} = x
$$
These hold for bases other than $e$.</p>
<h2 id="53doublingandhalvingtimes">5.3 Doubling and halving times</h2>
<p>For any quantity that is subject to continuous exponential growth over time, there will be a particular length of time in which its size always doubles. This length of time is called its <strong>doubling time</strong>.</p>
<p>A quantity that is subject to continous exponential decay has <strong>halving time</strong>.</p>
<h3 id="summarized">Summarized</h3>
<p>Suppose that a quantity is subject to continuous exponential change by scale factor $b$ every year.
If the quantity grows (that is, if $b > 1$), then its doubling time in years is the solution $i$ of the equation
$$
b^i = 2
$$
If the quantity decays (that is, if $0 < b < 1$), then its halving time (halflife) in years is the solution $i$ of the equation
$$
b^i = \frac{1}{2}
$$</p>
<h2 id="54graphsoflogarithmicfunctions">5.4 Graphs of logarithmic functions</h2>
<p>A function with a rule of the form $y = \log_bx$ is called a <strong>logarithmic function</strong>.
A graph of the function $y = \log_bx$ is the inverse of $y = b^x$</p>
MU123 Unit 12 NotesTue, 13 Jul 2021 00:00:00 +0000
https://ktsk.xyz/posts/mu123unit12/
https://ktsk.xyz/posts/mu123unit12/<h1 id="introduction">Introduction</h1>
<p><strong>Trigonometry</strong> is branch of mathematics that is concerned with methods of using triangles to find unknown lengths and unknown angles.</p>
<h1 id="1rightangledtriangles">1 Rightangled triangles</h1>
<p>Introduction of trigonometric rations sine, cosine and tanget.</p>
<h2 id="11sinecosineandtangent">1.1 Sine, cosine and tangent</h2>
<p>Suppose that $\theta$ is an acute angle in a rightangled triangle in which the lengths of the hypotenuse, opposite and adjacent sides are represented by hyp, opp and adj, respectively.</p>
<p>The <strong>sine</strong> of the angle $\theta$ is
$$
\text{sin}~\theta = \frac{\text{opp}}{\text{hyp}}
$$
The <strong>cosine</strong> of the angle $\theta$ is
$$
\text{cos}~\theta = \frac{\text{adj}}{\text{hyp}}
$$
The <strong>tangent</strong> of the angle $\theta$ is
$$
\text{tan}~\theta = \frac{\text{opp}}{\text{adj}}
$$</p>
<p>Hence the acronym: <strong>SOH CAH TOA</strong></p>
<h2 id="12findingunknownangles">1.2 Finding unknown angles</h2>
<p>$$
\arcsin(x) = \sin^{1}(x)
$$</p>
<h2 id="14usefultrigonometricratiosandidentities">1.4 Useful trigonometric ratios and identities</h2>
<p>It's possible to deduct ratios of certain triangles.
E.g. in an equilateral triangle (interior angles of $60^\circ$) with each side of 2 units in which a vertical line divides the base of the triangle into two equal parts following can be deducted:
$$
\cos 60^\circ = \frac{1}{2}
$$
The length $x$ of the third side of this rightangled triangle can be calculated:
$$
1^2 + x^2 = 2^2 \
x^2 = 4  1 = 3 \\
x = \sqrt{3}
$$
Hence:
$$
\sin60^\circ = \frac{\sqrt{3}}{2} \\
\tan60^\circ = \frac{\sqrt{3}}{1} = \sqrt{3} \\
$$</p>
<p>Following table can be devised</p>
<table><thead><tr><th>$\theta$</th><th>$\sin\theta$</th><th>$\cos\theta$</th><th>$\tan\theta$</th></tr></thead><tbody>
<tr><td>$30^\circ$</td><td>$\frac{1}{2}$</td><td>$\frac{\sqrt{3}}{2}$</td><td>$\frac{1}{\sqrt{3}}$</td></tr>
<tr><td>$45^\circ$</td><td>$\frac{1}{\sqrt{2}}$</td><td>$\frac{1}{\sqrt{2}}$</td><td>$1$</td></tr>
<tr><td>$60^\circ$</td><td>$\frac{\sqrt{3}}{2}$</td><td>$\frac{1}{2}$</td><td>$\sqrt{3}$</td></tr>
</tbody></table>
<h3 id="identities">Identities</h3>
<p>$$
\cos\theta = \sin(90^\circ  \theta) \\
\sin\theta = \cos(90^\circ  \theta) \\
\tan\theta = \frac{\sin\theta}{\cos\theta} \\
\sin^2\theta + \cos^2\theta = 1
$$</p>
<h1 id="2solvinggeneraltriangles">2 Solving general triangles</h1>
<h2 id="21thesinerule">2.1 The Sine Rule</h2>
<p>$$
\frac{a}{\sin A} = \frac{b}{\sin B} = \frac{c}{\sin C}
$$
or
$$
\frac{\sin A}{a} = \frac{\sin B}{b} = \frac{\sin C}{c}
$$</p>
<h2 id="22thecosinerule">2.2 The Cosine Rule</h2>
<p>$$
a^2 = b^2 + c^2  2bc\cos A \\
b^2 = c^2 + a^2  2ca \cos B \\
c^2 = a^2 + b^2  2ab \cos C
$$</p>
<h3 id="themethodsofsolvingatriangle">The methods of solving a triangle</h3>
<div class="mermaid isflex isjustifycontentcenter isalignitemscenter">graph TD
l1(Does the triangle contain a right angle?)
l2a(Does the problem only involve lengths?)
l2b(Do you know a length and the angle opposite?)
l3a(Pythagoras' theorem)
l3b(Trigonometric ratios)
l3c(Sine rule)
l3d(Cosine rule)
l1  Y > l2a
l1  N > l2b
l2a  Y > l3a
l2a  N > l3b
l2b  Y > l3c
l2b  N > l3d</div>
<h2 id="24aformulafortheareaofatriangle">2.4 A formula for the area of a triangle</h2>
<p>The area of a triangle with two sides of lengths $a$ and $b$, and included angle $\theta$ , is
$$
\text{area} = \frac{1}{2}ab\sin\theta
$$</p>
<h1 id="3trigonometricfunctions">3 Trigonometric functions</h1>
<h3 id="signofanangle">Sign of an angle</h3>
<p>A general angle is a measure of rotation around a point, measured in degrees. Positive angles give anticlockwise rotations, and negative angles give clockwise rotations.</p>
<h3 id="sineandcosineofageneralangle">Sine and cosine of a general angle</h3>
<p>For a general angle $\theta$, let $P$ be the point on the unit circle obtained by a rotation of $\theta$ around the origin from the positive $x$axis, and suppose that $P$ has coordinates $(x, y)$. Then
$$
\cos \theta = x <del>\text{and}</del> \sin \theta = y
$$</p>
<h3 id="tangentofageneralangle">Tangent of a general angle</h3>
<p>For a general angle $\theta$,
$$
\tan \theta = \frac{\sin \theta}{\cos \theta}
$$
provided that $\cos \theta \ne 0$.</p>
<h1 id="4radians">4 Radians</h1>
<p>One <strong>radian</strong> is the angle subtended at the centre of a circle by an arc that is the same length as the radius.</p>
<p>So the number of radians in a full turn is
$$
\frac{2\pi r}{r} = 2\pi
$$
Hence
$$
2\pi ~\text{radians} = 360^\circ
$$
This gives
$$
1~\text{radian} = \frac{360^\circ}{2\pi} = \frac{180^\circ}{\pi} \approx 57^\circ
$$</p>
<h3 id="convertingbetweendegreesandradians">Converting between degrees and radians</h3>
<p>Angle in radians $= \frac{\pi}{180} \times$ angle in degrees.
Angle in degrees $= \frac{180}{\pi} \times$ angle in radians.</p>
MU123 Unit 10 NotesWed, 30 Jun 2021 00:00:00 +0000
https://ktsk.xyz/posts/mu123unit10/
https://ktsk.xyz/posts/mu123unit10/<h1 id="introduction">Introduction</h1>
<p>Equation of the form:
$$
y = ax^2 +bx + c
$$
where $a$, $b$ and $c$ are constants with $a \ne 0$, are examined in this unit.
The <em>RHS</em> is a quadratic expression and graphs of these equations have a curved shape called <em>parabola</em>.</p>
<h1 id="1introducingparabolas">1 Introducing parabolas</h1>
<h2 id="11parabolaseverywhere">1.1 Parabolas everywhere</h2>
<h3 id="thefreefallequation">The freefall equation</h3>
<p>The relationship between the distance $d$ fallen by an object and the time $t$ that it has been falling is given by
$$
d = \frac{1}{2}gt^2
$$
where the constant $g$ is the acceleration due to gravity, which is about $9.8 \text{m/s}^2$.
Or more compactly:
$$
d = 4.9t^2
$$</p>
<p><strong>Parabola</strong>  a part of a parabola is formed by curved shape in the freefall equation.
<strong>Parabolic curve</strong>  a curve whose shape is all or part of a parabola.</p>
<h4 id="definitionsofaparabola">Definitions of a parabola</h4>
<ul>
<li>A shape obtained when a plane "parallel" to the side of a cone intersects the cone.</li>
<li>A shape of the graph of any equation of the form:
$$
y = ax^2 +bx + c
$$
where $a$, $b$ and $c$ are constants with $a \ne 0$. The freefall equation has this form with $b = c = 0$.</li>
</ul>
<p>The freefall equation is only a <strong>model</strong> for the motion of a falling object. It's accurate when there are no other forces than gravity acting on the object.
In real life there actually are other forces, notably <em>air resistance</em> (<em>drag</em>) which slows down the falling object. After great enough distance the air resistance will cause the speed of falling object to stop increasing  to become constant. This is known as the <em>terminal velocity</em>.</p>
<p><strong>Quadratic model</strong>
Any model based on an equation of form $y = ax^2 +bx + c$.</p>
<h2 id="12projectiles">1.2 Projectiles</h2>
<p>An object that is propelled through space by a force that ceases after launch.
<strong>Trajectory</strong> is the path a projectile follows.
<strong>Ballistics</strong> is the science of projectiles.</p>
<h2 id="13stoppingdistances">1.3 Stopping distances</h2>
<h1 id="2graphsofquadraticfunctions">2 Graphs of quadratic functions</h1>
<p>Every parabola has an <strong>axis of symmetry</strong> cutting the parabola at exactly one point  the <strong>vertex</strong>.
A rule that takes input values and produces output values is called a <strong>function</strong>.</p>
<p>A function of the form $y = ax^2 + bx + c$ is called a <strong>quadratic function</strong>.</p>
<h2 id="21graphsofequationsoftheformyax2">2.1 Graphs of equations of the form $y = ax^2$</h2>
<p>The <strong>magnitude</strong> of $a$ affects how narrow the graph is. The larther the magnitude of $a$, the narrower the parabola becomes.</p>
<ul>
<li><strong>ushaped</strong> parabola is same way up as the graph of $y = x^2$.</li>
<li><strong>nshaped</strong> parabola is the another way up, e.g. $y = x^2$.</li>
</ul>
<p>The vertex is $(0, 0)$.</p>
<h2 id="22graphsofequationsoftheformyax2bxc">2.2 Graphs of equations of the form $y = ax^2 + bx + c$</h2>
<p>The graph has the same shape as the graph of $y = ax^2$, but shifted and crosses the $y$axis at $(0, c)$.</p>
<h2 id="23theinterceptsofaparabola">2.3 The intercepts of a parabola</h2>
<p>The graph of $y = ax^2 + box + c$ can have two, one or zero $x$intercepts. There is always exactly one $y$intercept.</p>
<h2 id="24sketchgraphsofquadraticfunctions">2.4 Sketch graphs of quadratic functions</h2>
<ol>
<li>Find whether the parabola is ushaped or nshaped.</li>
<li>Find its intercepts, axis of symmetry and vertex.</li>
<li>Plot the features found, and hence sketch the parabola.</li>
<li>Lable the parabola with its equation, and make sure that the values of the intercepts and the coordinates of the vertex are indicated.</li>
</ol>
<p>A formula for the axis of symmetry of a parabola with equation $y = ax^2 + bx + c$ is:
$$
x =  \frac{b}{2a}
$$</p>
<h1 id="3solvingquadraticequations">3 Solving quadratic equations</h1>
<h2 id="32thequadraticformula">3.2 The quadratic formula</h2>
<p>The solutions of the quadratic equation
$$
ax^2 + bx + c = 0
$$
are given by
$$
x = \frac{b \pm \sqrt{b^2  4ac}}{2a}
$$</p>
<h3 id="simplifyingaquadraticequation">Simplifying a quadratic equation</h3>
<ul>
<li>If the coeficient of $x^2$ is negative, then multiply the equation through by $1$ to make this coefficient positive.</li>
<li>If the coefficients have a common factor, then divide the equation through by this factor.</li>
<li>If any of the coefficients are fractions, then multiply the equation through by a suitable number to clear them.</li>
</ul>
<h2 id="33thenumberofsolutionsofaquadraticequation">3.3 The number of solutions of a quadratic equation</h2>
<p>The value $b^2  4ac$ is called the <strong>discriminant</strong> of the quadratic expression $ax^2 + bx + c$. Such an equation has:</p>
<ul>
<li>two solutions if $b^2  4ac > 0$ (the discriminant is positive).</li>
<li>one solution if $b^2  4ac = 0$ (the discriminant is zero).</li>
<li>no solutions if $b^2  4ac < 0$ (the discriminant is negative).</li>
</ul>
<h2 id="34verticallylaunchedprojectiles">3.4 Verticallylaunched projectiles</h2>
<p>If an object is launched upwards from an initial height $h_0$ with an initial speed $v_0$, then after time $t$ its height $h$ is given by
$$
h = \frac{1}{2}gt^2 + v_0t + h_0
$$
where $g$ is the acceleration due to gravity, which is about $9.8\text{m}/\text{s}^2$.</p>
<h1 id="4completingthesquare">4 Completing the square</h1>
<p>Is a way to rearrange a quadratic expression.</p>
<h2 id="41shiftingparabolas">4.1 Shifting parabolas</h2>
<p>If a parabola with equation $y = ax^2$ is shifted right by $h$ units and up by $k$ units, then each point $(x, y)$ on the second parabola is a shift of the point $(x  h, y  k)$ on the first parabola. Hence the formula for second parabola is:
$$
y  k = a(x  h)^2
$$
Or equivalently:
$$
y = a(x  h)^2 + k
$$
Which can be further multiplied out to give the usual form $y = ax^2 + bx + c$.
Importantly the process works viceversa too. Any equation of the form $y = ax^2 + bx + c$ where $a$, $b$ and $c$ are constants with $a \ne 0$, can be rearranged into the form $y = a(x  h)^2 + k$.</p>
<p>Every expression of the form $ax^2 + bx + c$, where $a \ne 0$, can be rearranged into the form
$$
a (x + \text{a number})^2 + \text{a number}
$$
where each of the two numbers in this expression can be positive, negative or zero.
This is called the <strong>completedsquare form</strong>.</p>
<p>The parabola with equation
$$
y = a(x  h)^2 + k
$$
has vertex $(h, k)$.</p>
<h2 id="42completingthesquareinquadraticsoftheformx2bxc">4.2 Completing the square in quadratics of the form $x^2 + bx + c$</h2>
<p>Where the coefficient of $x^2$ is 1  the completedsquare form looks like:
$$
( x + \text{a number} ) ^2 + \text{a number}
$$</p>
<h3 id="completingthesquareinquadraticsoftheformx2bx">Completing the square in quadratics of the form $x^2 + bx$</h3>
<p>In general:
$$
(x + p)^2 = x^2 + 2px + p^2
$$
The RHS expression is of the form $x^2 + bx$ plus an extra number. If I subtract this extra number from both sides and swap the sides, then I obtain:
$$
x^2 + 2px = (x + p)^2  p^2
$$
The RHS expression is the completedsquare form of the LHS expression with following properties:</p>
<ul>
<li>Constant term in the RHS bracket is half of the coefficient of the term in $x$ on LHS.</li>
<li>The number that is subtracted on the RHS is the square of the constant term in the brackets.</li>
</ul>
<h3 id="completingthesquareinquadraticsoftheformx2bxc">Completing the square in quadratics of the form $x^2 + bx + c$</h3>
<ol>
<li>Complete the square for the $x^2$ and $x$ terms as before.</li>
<li>Collect the constant terms.</li>
</ol>
<p>E.g.:
$$
x^2 + 8x + 10 = \\[0.6em]
(x + 4)^2  16 + 10 = \\[0.6em]
(x + 4)^2  6
$$</p>
<p>Hence the general strategy:</p>
<ol>
<li>Rewrite the expression with the $x^2 + bx$ part changed to $(x + p)^2  p^2$, where the number $p$ is half of $b$.</li>
<li>Collect the constant terms.</li>
</ol>
<h2 id="43solvingquadraticequationsbycompletingthesquare">4.3 Solving quadratic equations by completing the square</h2>
<ol>
<li>Equations, where the coefficient of $x^2$ is greated than 1, should be divided through by given coefficient.</li>
<li>Complete the square.</li>
<li>Rearrange the equation so the square term and the constant are on different sides.</li>
<li>Take the square root of both sides.</li>
<li>Rearrange the equation to obtain $x$ by itself on one side.</li>
</ol>
<h3 id="thederivationofthequadraticformula">The derivation of the quadratic formula</h3>
<p>The general quadratic equation $ax^2 + bx + c = 0$ can be rearranged to obtain $x$ by itself on the LHS by following the steps:</p>
<p>Divide through by the coefficient of $x^2$:
$$
x^2 + \frac{b}{a}x + \frac{c}{a} = 0
$$
Complete the square:
$$
(x + \frac{b}{2a})^2  \frac{b^2}{4a^2} + \frac{c}{a} = 0 \\[1em]
$$
Get the constant terms on the right, combine them into a single fraction:
$$
\begin{aligned}
(x + \frac{b}{2a})^2 &= \frac{b^2}{4a^2}  \frac{c}{a} \\[1em]
&= \frac{b^2}{4a^2}  \frac{4ac}{4a^2} \\[1em]
&= \frac{b^2  4ac}{4a^2}
\end{aligned}
$$
Take the square root of both sides:
$$
\begin{aligned}
x + \frac{b}{2a} &= \pm \sqrt{\frac{b^2  4ac}{4a^2}} \\[1em]
&= \pm \frac{\sqrt{b^2  4ac}}{2a}
\end{aligned}
$$
Get $x$ by itself on the LHS:
$$
\begin{aligned}
x &= \frac{b}{2a} \pm \frac{\sqrt{b^2  4ac}}{2a} \\[1em]
&= \frac{b \pm \sqrt{b^2  4ac}}{2a}
\end{aligned}
$$
This is the quadratic formula!</p>
<h2 id="44completingthesquareinquadraticsoftheformax2bxc">4.4 Completing the square in quadratics of the form $ax^2 + bx + c$</h2>
<p>The common factor of $x^2$ and $x$ can be taken out of present, e.g.:</p>
<p>$$
2x^2 + 8x 7 = 2(x^2 +4x)  7
$$</p>
<p>Then the square in the qudratic <em>inside the brackets</em> can be completed as usual.</p>
<p>When there is no common factor, the coefficient of $x^2$ can still be taken out, the process will create fractions though:</p>
<p>$$
2x^2 + 5x + 1 = 2(x^2 + \frac{5}{2}x) + 1
$$</p>
<h3 id="strategytocompletethesquareinaqudraticoftheformaxbxc">Strategy to complete the square in a qudratic of the form $ax + bx + c$</h3>
<ol>
<li>Rewrite the expression with the coefficient $a$ of $x^2$ taken out of the $ax^2 + bx$ part as a factor. This generates a pair of brackets.</li>
<li>Complete the square in the simple quadratic inside the brackets, remembering to keep it enclosed within its brackets. This generates a second pair of brackets, inside the first pair.</li>
<li>Multiply out the <em>outer</em> brackets.</li>
<li>Collect the constant terms.</li>
</ol>
<h1 id="5maximisationproblems">5 Maximisation problems</h1>
<p>Is the problem of finding the maximum value of a quantity and the circumstances under which it is obtained.</p>
<p>This section focuses on problems that can be modelled with a quadratic function, hence the solution is to find a vertex.</p>
<h3 id="methodstofindthevertexofaparabolafromitsequation">Methods to find the vertex of a parabola from its equation</h3>
<ul>
<li>Use the formula $x = b / (2a)$ to find the $x$coordinate, then substitute into the equation of the parabola to find the $y$coordinate</li>
<li>Find the $x$intercepts (if there are any); then the value halfway between them is the $x$coordinate of the vertex. Find the $y$coordinate by substituting into the equation of the parabola.</li>
<li>Complete the square: the parabola with equation $y = a(x  h)^2 + k$ has vertex $(h, k)$.</li>
<li>Plot the parabola and read off the approximate coordinates of the vertex.</li>
</ul>
<h3 id="strategytosolveamaximisationproblem">Strategy to solve a maximisation problem</h3>
<ol>
<li>Identify the quantity to be maximised and the quantity that it depends on, and denote each quantity by a variable.</li>
<li>Find a formula for the variable to be maximised in terms of the variable that it depends on.</li>
<li>If this gives a quadratic function, then find the vertex of its graph.</li>
</ol>
MU123 Unit 9 NotesMon, 14 Jun 2021 00:00:00 +0000
https://ktsk.xyz/posts/mu123unit9/
https://ktsk.xyz/posts/mu123unit9/<h1 id="1numberpatternsandalgebra">1 Number patterns and algebra</h1>
<h2 id="11arithmeticsequences">1.1 Arithmetic sequences</h2>
<p>Sum of a sequence of natural numbers can be rewritten as a sum of pairs of numbers:
$$
1 + 2 + ... + 99 + 100 = (1 + 100) + (2 + 99) + ... + (50 + 51)
$$
There are 50 pairs, each of them having a sum of $101$, so:
$$
1 + 2 + ... + 99 + 100 = 50 \times 101 = 5050
$$</p>
<p>In case of a sum of successive odd numbers the sum is always the square of how many odd numbers I add, e.g. $1 + 3 + 5 + 7 = 16 = 4^2$ . For $n$ numbers the formula is $n^2$.</p>
<p>Formula for $n$ successive natural numbers is:
$$
1 + 2 + ... + n = \frac{1}{2}n(n + 1)
$$
The numbers given by the formula are called <strong>triangular numbers</strong>.</p>
<p>Any list of numbers is called a <strong>sequence</strong></p>
<ul>
<li>$1, 2, 3, ..., 100$ is <strong>finite</strong> sequence</li>
<li>$1, 2, 3, ...$ is <strong>infinite</strong> sequence</li>
</ul>
<p>The numbers in a sequence are called the <strong>terms</strong> of the sequence.
<strong>Arithmetic</strong> sequence is a sequence where the <strong>difference</strong> between consequtive terms is constant, e.g.: $1, 2, 3, ...$ is a arithmetic sequence with difference of 1,
To specify an arithemtic sequence we can give the first term denoted by $a$, the difference denoted by $d$. If the sequence is finite the number of terms is denoted by $n$.</p>
<p>The $n$th term of an arithmetic sequence with first term $a$ and difference $d$ is given by the formula
$$
n\text{th term} = a + (n  1)d
$$</p>
<p>The number of terms $n$ of a finite arithmetic sequence with first term $a$, last term $L$ and nonzero difference $d$ is given by the formula:
$$
n = \frac{L  a}{d} + 1
$$</p>
<p>The sum of the finite arithmetic sequence with first term $a$, difference $d$ and numbers of term $n$ is given by the formula:
$$
S = \frac{1}{2}n(2a + (n  1)d)
$$
An alternative formula involving the last term $L$:
$$
S = \frac{1}{2}n(a + L)
$$</p>
<h1 id="2multiplyingoutpairsofbrackets">2 Multiplying out pairs of brackets</h1>
<h2 id="21pairsofbrackets">2.1 Pairs of brackets</h2>
<blockquote>
<p>Strategy to multiply out two brackets</p>
<p>Multiply each term inside the first bracket by each term inside the second bracket, and add the resulting terms.</p>
</blockquote>
<h2 id="22squaringbrackets">2.2 Squaring brackets</h2>
<p>$$
(x + p)^2 = (x + p)(x + p) \\
= x^2 + xp + px + p^2 \\
= x^2 + 2px + p^2
$$</p>
<p>Hence the general formula:
$$
(x + p)^2 = x^2 + 2px + p^2
$$
and
$$
(x  p)^2 = x^2  2px + p^2
$$</p>
<h2 id="23differencesoftwosquares">2.3 Differences of two squares</h2>
<p>$$
(x  p)(x + p) = x^2 + xp  px  p^2
$$
Hence:
$$
(x  p)(x + p) = x^2  p^2
$$</p>
<h1 id="3quadraticexpressionsandequations">3 Quadratic expressions and equations</h1>
<h2 id="31quadraticexpressions">3.1 Quadratic expressions</h2>
<p>An expression of the form $ax^2 + bx + c$, where $a, b, c$ are numbers and $a \ne 0$ is called a <strong>quadratic expression</strong> in $x$. $a, b, c$ are called the <strong>coefficients</strong> of the quadratic.</p>
<h2 id="32quadraticequations">3.2 Quadratic equations</h2>
<p>An equation that can be expressed in the form:
$$
ax^2 + bx + c = 0
$$
is called a <strong>quadratic equation</strong> in $x$.</p>
<h2 id="33solvingsimplequadraticequations">3.3 Solving simple quadratic equations</h2>
<p>An equation of the form $x^2 = d$, where $d > 0$ has two solutions $x = \pm \sqrt{d}$.</p>
<p>Equations as $x^2 + 1 = 0$ have no solution among the real numbers.</p>
<h2 id="34factorisingquadraticsoftheformx2bxc">3.4 Factorising quadratics of the form $x^2 + bx + c$</h2>
<p>Fill in the gaps in the brackets on the righthand side of the equation
$$
x^2 + bx + c = (x...)(x...)
$$
with two numbers whose product is $c$ and whose sum is $b$.
I can search systematically by writing down all the factor pairs of $c$ and choosing (if possible) a pair whose sum is $b$.</p>
<h2 id="35solvingquadraticequationsbyfactorisation">3.5 Solving quadratic equations by factorisation</h2>
<p>If the product of two or more numbers is 0, then at least one of the numbers must be 0.
Hence in an equation as $(x  2)(x  3) = 0$ either $x  2$ or $x  3$ is 0. If $x  2 = 0$ then $x = 2$, if $x  3 = 0$ then $x  3$ so the equation has two solutions.</p>
<h3 id="strategytosolvex2bxc0byfactorisation">Strategy to solve $x^2 + bx + c = 0$ by factorisation</h3>
<ol>
<li>Find a factorisation: $x^2 + bx + c = (x + p)(x + p)$</li>
<li>Then $(x + p)(x + p) = 0$, so $x + p = 0$ or $x + q = 0$
and hence the solutions are $x = p$ and $x = q$.</li>
</ol>
<p>When the two solutions are same it's said that equation has a <strong>repeated solution</strong>.</p>
<h2 id="36factorisingquadraticsoftheformax2bxc">3.6 Factorising quadratics of the form $ax^2 + bx + c$</h2>
<p>E.g. following quadratic expression;
$$
2x^2  x  6
$$
Where:
$$
a = 2\\
b = 1\\
c = 6
$$</p>
<blockquote>
<p>Find two numbers whose product is $ac$ and whose sum is $b$.</p>
</blockquote>
<p>The numbers are $3$ and $4$.</p>
<blockquote>
<p>Rewrite the quadratic expression, splitting the term in $x$ using the above factor pair.</p>
</blockquote>
<p>$$
2x^2  x  6 = 2x^2 +3x 4x  6
$$</p>
<blockquote>
<p>Group the four terms in pairs and take out common factors to give the required factorisation.</p>
</blockquote>
<p>$$
2x^2  x  6 = 2x^2 +3x 4x  6 \\
= x(2x + 3) 2(2x + 3) \\
= (x  2)(2x + 3)
$$</p>
<h3 id="simplifyaquadraticequation">Simplify a quadratic equation</h3>
<ul>
<li>If the coefficient of $x^2$ is negative, then multiply the equation through by $1$ to make this coefficient positive.</li>
<li>If the coefficients have a common factor, then divide the equation through by this factor.</li>
<li>If any of the coefficients are fractions, then multiply the equation through by a suitable number to clear them.</li>
</ul>
<h1 id="4manipulatingalgebraicfractions">4 Manipulating algebraic fractions</h1>
<p>$\frac{a}{b}$ is equivalent to $\frac{a(a + 1)}{b(b + 1)}$ and common factor can be cancelled out as usual.</p>
Complex numbers notesSun, 02 May 2021 00:00:00 +0000
https://ktsk.xyz/posts/complexnumbersnotes/
https://ktsk.xyz/posts/complexnumbersnotes/<h1 id="imaginarynumbers">Imaginary numbers</h1>
<p>Quadratic equations as $x^2 = 1$ don't have any <em>real number</em> solution.
The solution exists in the <strong>complex</strong> number system.</p>
<p>Backbone of which is the <strong>imaginary unit</strong> $i$. For which following is true:</p>
<ul>
<li>$i = \sqrt{1}$</li>
<li>$i^2 = 1$</li>
</ul>
<p>By taking multiples of $i$, I can create infinitely many <strong>pure imaginary numbers</strong>, e.g. $3i$, $i\sqrt{5}$, $12i$.</p>
<p>By squaring an imaginary number I can explore how those relate to the real numbers:
$$
(3i)^2 = 3^2i^2 = 9i^2
$$</p>
<p>Now I can apply the fact that $i^2 = 1$:</p>
<p>$$
9i^2 = 9(1) = 9
$$</p>
<p>Meaning $3i$ is square root of $9$</p>
<h2 id="simplifyingpureimaginarynumbers">Simplifying pure imaginary numbers</h2>
<p>As proved $\sqrt{9}$ simplifies to $3i$ and following though process can be applied:
The square root of $9$ is an imaginary number. The square root of $9$ is $3$, so the square root of <em>negative</em> $9$ is $3$ <em>imaginary units</em>, or $3i$</p>
<p>More formally:
$$
\text{For}~ a > 0, \sqrt{a} = i\sqrt{a}
$$</p>
<h2 id="powersofi">Powers of $i$</h2>
<p>Basic power line can be devised:
$$
\begin{aligned}
i^0 &= 1 \\
i^1 &= i \\
i^2 &= 1 \\
i^3 &= i^2 \times i = (1)(i) = i \\
i^4 &= i^3 \times i = (i)(i) = (1)(i)(i) = (1)(1) = 1 \\
i^5 &= i^4 \times i = 1 \times i = i \\
i^6 &= i^5 \times i = 1 \\
i^7 &= i^6 \times i = i \\
i^8 &= i^7 \times i = 1 \\
\end{aligned}
$$</p>
<p>Results can be summarised in following table:</p>
<table><thead><tr><th>$i^1$</th><th>$i^2$</th><th>$i^3$</th><th>$i^4$</th><th>$i^5$</th><th>$i^6$</th><th>$i^7$</th><th>$i^8$</th></tr></thead><tbody>
<tr><td>$i$</td><td>$1$</td><td>$i$</td><td>$1$</td><td>$i$</td><td>$1$</td><td>$i$</td><td>1</td></tr>
</tbody></table>
<p>Hence it appearst that powers of $i$ cycle through the sequence of $i, 1, i, 1$.</p>
<p>Properties of exponents can be used to devise larger powers of $i$, e.g.:
$$
i^{20} = i^{4\times5} = (i^4)^5 = 1^5 = 1
$$
Hence:
$$
i^{20} = 1
$$</p>
<p>The fact that $i$ raised to a multiple of $4$ is $1$ (along with properties of exponents) can be used to find large powers of $i$.</p>
<h2 id="rootsofnegativenumbers">Roots of negative numbers</h2>
<p>Square roots of negative numbers can be simplified followingly:
$$
\sqrt{20} = \sqrt{1 \times 4 \times 5} = i\sqrt{4 \times 5} = 2i\sqrt{5}
$$</p>
<h2 id="iastheprincipalrootof1">$i$ as the principal root of $1$</h2>
<p>Consider following application of the $\sqrt{ab} = \sqrt{a} \times \sqrt{b}$ rule on the $i$:</p>
<p>GIven $i = \sqrt{1}$ I can state:
$$
1 = i \times i = \sqrt{1} \times \sqrt{1} = \sqrt{1 \times 1} = \sqrt{1} = 1
$$
Which is obviosly not truthy. In reality the $\sqrt{ab} = \sqrt{a} \times \sqrt{b}$ rule <strong>cannot be applied</strong> when both $a$ and $b$ are negative.</p>
<h1 id="complexnumbers">Complex numbers</h1>
<p>Combination of real and imaginary numbers, e.g. $z = 5 + 3i$ which has following parts:
Real:
$$
Re(z) = 5
$$
Imaginary:
$$
Im(z) = 3
$$</p>
<p>The number can be plotted with $Re$ on $x$ axis and $Im$ on $y$ axis:
<img src=":/e0e4b2bfff13476988e5e745801aeb66" alt="complex_plot.png" /></p>
<p>More formally a complex number is any number that can be written as $a + bi$.</p>
<h2 id="classifyingcomplexnumbers">Classifying complex numbers</h2>
<p>An imaginary number is a complex nuimber $a + bi$ where $a = 0$.
A real number is a complex number $a + bi$ where $b = 0$.</p>
<p>Hence following hiearchy:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">
 Complex numbers 
 
  
  Real numbers  
  
 
  
  Imaginary numbers  
  

</span></code></pre><h2 id="simplifyingcomplexnumbers">Simplifying complex numbers</h2>
<p>Let's consider:
$$
2 + 3i + 7i^2 + 5i^3 + 9i^4
$$</p>
<p>I already know that:
$$
i^2 = 1 \\
i^3 = i \\
i^4 = 1
$$ </p>
<p>Hence:
$$
2 + 3i + 7(1) + 5(i)+ 9(1) = \\
2 + 3i  7 5i + 9 = \\
4  2i
$$</p>
<h2 id="addingcomplexnumbers">Adding complex numbers</h2>
<p>E.g.:
$$
(5 + 2i) + (3  7i) = \\
5 + 3 + 2i  7i = \\
8  5i
$$</p>
<h2 id="subtractingcomplexnumbers">Subtracting complex numbers</h2>
<p>E.g.:
$$
(2  3i)  (6  18i) = \\
2  3i  6 + 18i = \\
4 + 15i
$$</p>
<h2 id="distanceofcomplexnumbers">Distance of complex numbers</h2>
<p>E.g. distance between:
$$
z = 2 + 3i \\
w = 5 i
$$</p>
<p>Can be calculated using Pythagoras theorem:
<img src=":/3c8cf700b648464283597c0ffe920c0e" alt="complex_distance.png" /></p>
<h2 id="midpointofcomplexnumbers">Midpoint of complex numbers</h2>
<p>Is the half of real and complex parts separately:
$$
z = 2 + 3i \\
w = 5 i \\
$$</p>
<p>$$
a = (\frac{2 + (5)}{2}) + (\frac{3 + ( 1)}{2})i \\
a = \frac{3}{2} + i
$$</p>
<h2 id="multiplyingcomplexnumbers">Multiplying complex numbers</h2>
<h3 id="arealnumberbyacomplexnumber">A real number by a complex number</h3>
<p>Use a distributive property:
$$
4(13 + 5i) = 4(13) + (4)(5i) = 52  20i
$$</p>
<h3 id="apureimaginarynumberbyacomplexnumber">A pure imaginary number by a complex number</h3>
<p>$$
2i(3  8i) = 2i(3)  2i(8i) = 6i  16i^2
$$</p>
<p>Use the fact that $i^2 = 1$:
$$
6i  16i^2 = 6i  16(1) = 6i + 16 = 16 + 6i
$$</p>
<h3 id="twocomplexnumbers">Two complex numbers</h3>
<p>Multiply each term in the first number by each term in the second number:</p>
<p>$$
(1 + 4i)(5 + i) = \\
(1)(5) + (1)(i) + (4i)(5) + (4i)(i) = \\
5 + i + 20i + 4i^2 = \\
5 + 21i + 4i^2 = \\
5 + 21i + 4(1) = \\
5 + 21i  4 = \\
1 + 21i
$$</p>
MU123 Unit 6 NotesSun, 25 Apr 2021 00:00:00 +0000
https://ktsk.xyz/posts/mu123unit6/
https://ktsk.xyz/posts/mu123unit6/<h1 id="introduction">Introduction</h1>
<ul>
<li>Extends Unit 2 with connections between algebra and graphs.</li>
<li>Explores relationships between two quantities.</li>
<li>Relationships corresponding to straight lines only</li>
</ul>
<h1 id="1plottinggraphs">1 Plotting graphs</h1>
<ul>
<li>Useful to illustrate an equation or formula with two variables
<ul>
<li>Formula is an equation with a subject  a variable that appears by itself on one side of the equals sign and not at all on the other side.</li>
</ul>
</li>
</ul>
<h2 id="11graphaxesandcoordinates">1.1 Graph axes and coordinates</h2>
<ul>
<li>Two axes  x and y.</li>
<li>Aeach axis has scale markings and arrows.</li>
<li>Distance between two consecutive integers on an axis is reffered to as 1 unit.</li>
<li>Axis are often extended to include negative numbers.</li>
<li>Each point plottend on a graph is represented by the <strong>coordinates</strong>.
<ul>
<li>First number represents position along the xaxis from 0</li>
<li>Second number position along the yaxis from 0</li>
<li>The two numbers are called <em>x</em> and <em>y</em>coordinates</li>
<li>Also known as the <strong>Cartesian coordinate system</strong></li>
<li>Alternatives labels (and units) can be used too</li>
</ul>
</li>
</ul>
<h2 id="12graphsofequations">1.2 Graphs of equations</h2>
<p>When an equation, e.g.: $y = \frac{1}{2}x + 3$ is plotted into a line we say it's the <strong>equation</strong> of the line.
Checking whether some coordinates lie on the line $y = \frac{1}{2}x + 3$ is checking whether whether the coordinates of the point <strong>satisfy</strong> the equation.</p>
<p>In practical formulas, where variables are letters other than <em>x</em> and <em>y</em> the subject is known as the <strong>dependent variable</strong>. Its value depends on the value of th other, <strong>independent variable</strong>.
Indpendent variable should be on the horizontal axis and the depenedent on the vertical  <strong>against</strong> the independent variable.
In the table of values, the indendent variable should be in the first line.</p>
<p>Relationships plotted on straight line are called <strong>linear relationships</strong>.</p>
<h2 id="13scatterplots">1.3 Scatterplots</h2>
<p>Is a graph plotted for two quantities for which I don't know an equation relating them. Plotted points are reffered to as <strong>data points</strong>.
When data points approximatelly form a straight line it can be modelled into it. For which an equation can be devised.</p>
<h1 id="2characteristicsofstraightlinegraphs">2 Characteristics of straightline graphs</h1>
<h2 id="21gradient">2.1 Gradient</h2>
<p>Measures the steepnes of a line. Gradient of the line is the number of units it moves vertically as it moves 1 unit horizontally to the right.
Gradient is often not obvious to find. One approach is to pick two points on the line and consider what happens when "cursor" is moved from lefthand point to the righthand point.
The increase in the:</p>
<ul>
<li><em>x</em>coordinate is called <strong>run</strong>.</li>
<li><em>y</em>coordinate is called <strong>rise</strong>.</li>
</ul>
<p>The gradient of the line can be calculated by dividing the rise by the run:
$$
\text{gradient} = \frac{\text{increase in y}}{\text{increase in x}} = \frac{\text{rise}}{\text{run}}
$$</p>
<blockquote>
<p><strong>The sign of the gradient</strong>
Lines that slope up from left to right have a <em>positive</em> gradient.
Lines that slope down from left to right have a <em>negative</em> gradient.</p>
</blockquote>
<p>Run (<em>x</em> increase) and rise (<em>y</em> increase) can be calculated by subtracting the respective coordinate of the lefthand point from the respective coordinate of the righthand point.</p>
<p>Steepnes of a line depends not only on its gradient but also on the scales used on the axes.</p>
<h3 id="horizontalandverticallines">Horizontal and vertical lines</h3>
<p>The gradient of every horizontal line is <strong>zero</strong> since the rise between any two points on a horizontal line is zero.
The gradient of every vertical line is <strong>undefined</strong> since the run is zero and it's not possible to divide any rise number by zero.</p>
<h2 id="22aformulaforgradient">2.2 A formula for gradient</h2>
<p>First point on the line can be represented as $(x_1, y_1)$ and second as $(x_2, y_2)$. 1, 2 are <strong>subscripts</strong>. Hence the gradient calculation can be generalised as:
$$
\text{gradient} = \frac{\text{rise}}{\text{run}} = \frac{y_2  y_1}{x_2  x_1}
$$
It doesn't matter which point I take to be $(x_1, y_1)$ and which $(x_2, y_2)$</p>
<p><strong>Paralel</strong> are such lines that never cross, even when extended infinitely. Hence those lines have to have the same gradient (except for vertical lines with undefined gradient).</p>
<h2 id="23interpretinggradients">2.3 Interpreting gradients</h2>
<p>Gradients for graphs that illustrate a relationship between reallife quantities should contain units in a form of <em>y</em>unit / <em>x</em>unit. When units are the same they cancel out so the gradient has no units.</p>
<p>The gradient can be thought of as the <strong>rate of change</strong> of <em>y</em> with respect to <em>x</em>.</p>
<p>To save time the units can be quoted in calculations e.g.:
$$
\frac{150}{6} = 25~\text{cm/day}
$$
That is not strictly correct though.</p>
<blockquote>
<p><strong>Interpreting the sign of the gradient of a graph</strong></p>
<ul>
<li>A <em>positive</em> indicates that the quantity on the vertical axis <em>increases</em> as the quantity on the horizontal axis increases.</li>
<li>A <em>negative</em> indicates that the quantity on the vertical axis <em>decreases</em> as the quantity on the horizontal axis increases.</li>
<li>A <em>zero</em> indicates that the quantity on the vertical axis <em>remains constant</em> as the quantity on the horizontal axis increases.</li>
</ul>
</blockquote>
<h2 id="24intercepts">2.4 Intercepts</h2>
<p>The value on the axis scale where a straightline graph one of the graph axes.
<em>x</em>intercept is the value of <em>x</em> when <em>y = 0</em> and the <em>y</em>intercept is the value of <em>y</em> when <em>x = 0</em>.</p>
<h1 id="3equationsofstraightlines">3 Equations of straight lines</h1>
<h2 id="31linesthatpassthroughtheorigin">3.1 Lines that pass through the origin</h2>
<p>In general, each line that passes through the origin has the equation:
$$
y = \text{gradient} \times x
$$
With the exception of the vertical lines since it doesn't have a gradient.</p>
<p>The statement can be generalised as:
The straight line that passes through the origin and has gradient $m$ has equation $y = mx$.</p>
<h2 id="32directproportion">3.2 Direct proportion</h2>
<p>The relationship between two quantities when, if one quantity is multiplied or divided by a number then the second quantity is also multiplied or divided by same number.
E.g. number of miles is directly proportional to the equivalent number of kilometers.</p>
<p>If two quantities $x$ and $y$ are directly proportional to each other, then the relationship between them is described by an equation of the form
$$
y = kx
$$
where $k$ is a nonzero number, known as the <strong>constant of proportionality</strong>.
The statement '$y$ is directly proportional to $x$' is sometimes written as
$$
y \propto x
$$</p>
<p><strong>Constant</strong> in an equation or expression is a quantity that doesn't change when the values of the variables change.</p>
<p>A graph represents directly proportional quantities when it's a <strong>straight line through the origin</strong>. That means the constant of proprtionality is a gradient.</p>
<h2 id="33thegeneralequationofastraightline">3.3 The general equation of a straight line</h2>
<p>Nearly every straight line graph can be described by an equation of the form
$$
y = mx + c
$$
where gradient $m$ and $y$intercept $c$ are constants. The exeception being vertical lines.</p>
<p><strong>Equations of horizontal and vertical lines</strong>
The horizontal line with $y$intercept $a$ has equation $y = a$.
The vertical line with $x$interceept $a$ has equation $x = a$.</p>
<h2 id="34drawinglinesfromtheirequations">3.4 Drawing lines from their equations</h2>
<p>When a graph illustrates an equation it should label the line.</p>
<h2 id="35findingtheequationsoflines">3.5 Finding the equations of lines</h2>
<ol>
<li>Find the gradient $m$ of the line and substitute it into the general equation $y = mx + c$.</li>
<li>Substitute the coordinates of a point on the line into the equation of the line from step 1 and solve it fo find the value of the $y$intercept $c$.</li>
<li>Use the values of $m$ and $c$ to write down the equation of the line.</li>
</ol>
<h1 id="4linearmodelsfromdata">4 Linear models from data</h1>
<h2 id="41regressionlines">4.1 Regression lines</h2>
<p>Collected data can be plotted on the graph and possibly modelled by straight line.
The way how a line fits the data can be meassured followingly:</p>
<ul>
<li>Measure the vertical distances from the points to the line</li>
<li>Square each of these distances</li>
<li>Add up the squared distances</li>
</ul>
<p>The smaller the sum the better the fit of the line. There is always just one line for which the sum is the smallest  the <strong>regression line</strong>.</p>
<p>The process of estimating a value within the <em>range</em> of the data is called <strong>interpolation</strong>.
Estimating a value outside of the data <em>range</em> is called <strong>extrapolation</strong> and it can be unreliable. In general it is unwise to extrapolate too far from the range of dataset.</p>
<h2 id="42correlationcoefficients">4.2 Correlation coefficients</h2>
<p>Measures how accurate a prediction provided by a regression line is likely to be. It's calcluated from data pair and denoted by $r$.
It indicates how well the regression line fits the data pairs.
The coefficient is always between 1 and 1, inclusive.
When it's possitive the regression line has a positive gradient and it's called <strong>possitive correlation</strong>. Negative has a negative gradient and is called <strong>negative correlation</strong>.</p>
<p>The correlation coefficient is exactly 1 or exactly 1 when all the data points lie exactly on the regression line, it's called <strong>perfect correlation</strong>.
Strong correlation is when the data points are close to the regression line.
The closer the coefficient is to zero the <strong>weaker</strong> is the correlation.</p>
Git cheatsheetMon, 12 Apr 2021 00:00:00 +0000
https://ktsk.xyz/posts/gitcheatsheet/
https://ktsk.xyz/posts/gitcheatsheet/<h1 id="breakacommit">Break a commit</h1>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">git</span><span style="color:#abb2bf;"> rebase</span><span style="color:#eb6772;"> i </span><span style="color:#adb7c9;"><</span><span style="color:#abb2bf;">id</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;">^
</span></code></pre>
<blockquote>
<p>edit a commit</p>
</blockquote>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">git</span><span style="color:#abb2bf;"> reset HEAD</span><span style="color:#eb6772;">~
</span></code></pre>
<blockquote>
<p>add + commit files selectively</p>
</blockquote>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">git</span><span style="color:#abb2bf;"> rebase</span><span style="color:#eb6772;"> continue
</span></code></pre><h1 id="changetheauthorofacommit">Change the author of a commit</h1>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">git</span><span style="color:#abb2bf;"> rebase</span><span style="color:#eb6772;"> i </span><span style="color:#adb7c9;"><</span><span style="color:#abb2bf;">id</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;">^
</span></code></pre>
<blockquote>
<p>edit a commit</p>
</blockquote>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">git</span><span style="color:#abb2bf;"> commit</span><span style="color:#eb6772;"> amend author</span><span style="color:#adb7c9;">=</span><span style="color:#9acc76;">"First Last <email@email>"</span><span style="color:#eb6772;"> noedit
git</span><span style="color:#abb2bf;"> rebase</span><span style="color:#eb6772;"> continue
</span></code></pre><h1 id="renameabranch">Rename a branch</h1>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">git checkout <old name>
</span></code></pre>
<p>Rename the local branch:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">git branch m <new name>
</span></code></pre>
<p>Perform following if pushed to remote:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">git push origin u <new name>
git push origin delete <old name>
</span></code></pre>MU123 Unit 5 NotesMon, 05 Apr 2021 00:00:00 +0000
https://ktsk.xyz/posts/mu123unit5/
https://ktsk.xyz/posts/mu123unit5/<h1 id="2expressions">2 Expressions</h1>
<h2 id="21whatisanexpression">2.1 What is an expression?</h2>
<p>A collection of letters, numbers and/or mathematical symbols arranged in such a way that if numbers are substituted for the letters, then I can work out hte value of the expression.</p>
<blockquote>
<p>Letters represent numbers, so the normal rules of arithmetic apply to them.
In exactly the same way as they apply to numbers.</p>
</blockquote>
<p>In particular <strong>BIDMAS</strong> rules apply to the letters.</p>
<p><strong>Evaluation</strong> is the process of substituting numbers for the letters.
<strong>Equivalent</strong> expresions are those that are same, just written differently</p>
<ul>
<li>e.g.: $x + x = 2x$</li>
</ul>
<p><strong>Rearranging</strong> is writing an expression in a different way.
<strong>Simplifying</strong> is rearranging in order to make the expression simpler.</p>
<p>Expressions <em>don't</em> contain equals sings. E.g.: $x + x = 2$ is an <strong>equation</strong></p>
<blockquote>
<p><em>bicause noe 2 thynges can be moare equalle.</em>
 Robert Recorde, the inventor of $=$</p>
</blockquote>
<p><strong>Identities</strong> are equations that are true for all values of the variables</p>
<ul>
<li>$\frac{3}{10}N = 150$ is not identity, it's currect for only one value of $N$.</li>
<li>$x + x = 2x$ is an identity.</li>
</ul>
<p><strong>unknown</strong> is a letter representing a particular number I don't know yet</p>
<ul>
<li>In $\frac{3}{10}N = 150$ the $N$ is unknown.</li>
</ul>
<p><strong>variable</strong> is a letter that represents <em>any</em> number</p>
<ul>
<li>In $x + x = 2x$ the $x$ is variable. </li>
</ul>
<h2 id="22whatisaterm">2.2 What is a term?</h2>
<p>The things that are added or subtracted in an expression.
E.g. in following expression:
$$
2xy + 3z  y^2
$$
The $2xy$, $+3z$, $y^2$ are terms. Plus / minus signs are part of the term.
There's implicit plus in the front of an expression, e.g. $4a + c$ has following terms: $+4a$ and $+c$. When dicussing the terms the plus sign can be omitted alltogether.</p>
<blockquote>
<p>An expression is equivalent to the sum of its terms.</p>
</blockquote>
<p>Order of terms can be changed since it doesn't matter when adding numbers.</p>
<p><strong>Constant</strong> term is a number only, e.g. in $3a  2$ the term $2$ is constant.
<strong>Coefficient</strong> of a term is a number in a term of the $\text{a number} \times \text{a combination of letters}$ form, e.g. $2xy$ has coefficient $2$ and $2$ is a term in $xy$.</p>
<h2 id="23collectingliketerms">2.3 Collecting like terms</h2>
<p><strong>Like terms</strong> are terms that are 'batches of same thing'. Same thing means the letters and the powers of the letters in each term must be the same. E.g. $7\sqrt{A}$ and $3\sqrt{A}$ are like terms.
The lower and uppercase versions of the same letter are <em>different</em> symbols.
Terms <strong>cancel</strong> each other out when the result of collecting those is zero.</p>
<h1 id="3simplifyingterms">3 Simplifying terms</h1>
<h2 id="31simplifyingsingleterms">3.1 Simplifying single terms.</h2>
<p>Index notation should be used when simplifying a term with samel letters, e.g. $p \times p$ simplifies to $p^2$.</p>
<blockquote>
<p>Strategy</p>
<ol>
<li>Find the overall sign.</li>
<li>Simplify the rest of the coefficient.</li>
<li>Write the letters in alphabetical order, use index notation.</li>
</ol>
</blockquote>
<h2 id="32simplifyingtwoormoreterms">3.2 Simplifying two or more terms</h2>
<blockquote>
<p><strong>Strategy</strong></p>
<ol>
<li>Identify the terms. Each term after the first starts with a plus or minus sign that isn't inside brackets.</li>
<li>Simplify each term. Include the sign (plus or minus) at the start of each term.</li>
<li>Collect any like terms</li>
</ol>
</blockquote>
<h1 id="4brackets">4 Brackets</h1>
<h2 id="41multiplyingoutbrackets">4.1 Multiplying out brackets</h2>
<p>Any expression containing brackets like:
$$
8a + 3b(b  2a)
$$
can be rewritten without brackets by multiplying each term inside the brackets by the <strong>multiplier</strong>  $3b$ in the example:
$$
8a + 3b \times b  3b \times 2a
$$</p>
<blockquote>
<p><strong>Strategy</strong>
To multiply out brackets in an expression with more than one term</p>
<ol>
<li>Identify the terms. Each term after the first starts with a plus or minus sign that isn't inside brackets.</li>
<li>Multiply out the brackets in each term. Include the sign (plus or minus) at the start of each resulting term.</li>
<li>Collect any like terms.</li>
</ol>
</blockquote>
<blockquote>
<p><strong>Strategy</strong>
To remove brackets with a plus or minus sign in front</p>
<ul>
<li>Inf the sign is plus, keep the sign of each term inside the brackets the same.</li>
<li>If the sign is minus, change the sign of each term inside the brackets.</li>
</ul>
</blockquote>
<h2 id="42algebraicfractions">4.2 Algebraic fractions</h2>
<p>Are algebraic expressions written using fraction notation, e.g.: $a + \frac{b}{c}$. Fractions are preffered over divisin sign.</p>
<p><strong>Expanding</strong> the algebraic fraction is useful technique when there is more terms in th numerator. such as:
$$
\frac{2a  5b + c}{3d}
$$
The expresion can be rewritten as multiplication by the reciprocal of the denominator:
$$
\frac{1}{3d}(2a  5b + c)
$$
Then I can multiply out the brackets:
$$
\frac{2a}{3d}  \frac{5b}{3d} + \frac{c}{3d}
$$</p>
<p>Once the algebraic fraction is expanded it may be possible to simplify some of the resulting terms.</p>
<h1 id="5linearequations">5 Linear equations</h1>
<p>Particularly <em>linear equations in one unknown</em></p>
<p>Linear because those equations doesn't include powers, e.g.: $x^2$, thus form straigh lines on a graph.</p>
<p>An equation consists of two expressions:</p>
<ul>
<li>lefthand side (LHS)</li>
<li>righhand side (RHS)</li>
</ul>
<p><strong>Solving the equation</strong> is the process of finding the value of the unknown. Found value is <em>solution</em>  <em>solution</em> <strong>satisfies</strong> the equation.</p>
<p>An equation can have more than one solution, e.g.: $a^2 = 4$ has two solutions  $a = 2$ and $a = 2$. Also an equation can have no solution at all, e.g.: $a^2 = 1$</p>
<h2 id="52howtosolvelinearequation">5.2 How to solve linear equation</h2>
<blockquote>
<p><strong>Strategy</strong></p>
<ul>
<li>do the same thing to both sides</li>
<li>simplify one side or both sides</li>
<li>swap the sides</li>
<li>clear any fraction and multiply out any brackets. To clear a fraction, multiply both sides by a suitable number.</li>
<li>Add or subtract terms on both sides to obtain an equation of the form $\text{a number} \times \text{the unknown} = \text{a number}$</li>
</ul>
</blockquote>
Building Git NotesWed, 31 Mar 2021 00:00:00 +0000
https://ktsk.xyz/posts/buildinggitnotes/
https://ktsk.xyz/posts/buildinggitnotes/<blockquote>
<p>These are my notes taken while reading the <strong>Building Git</strong> book (<a href="https://shop.jcoglan.com/buildinggit/">https://shop.jcoglan.com/buildinggit/</a>).</p>
</blockquote>
<h1 id="2gettingtoknowgit">2. Getting to know <code>.git</code></h1>
<h2 id="21thegitdirectory">2.1 The <code>.git</code> directory</h2>
<p>is called a <strong>repository</strong></p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">.git
├──</span><span style="color:#abb2bf;"> branches
</span><span style="color:#eb6772;">├──</span><span style="color:#abb2bf;"> config
</span><span style="color:#eb6772;">├──</span><span style="color:#abb2bf;"> description
</span><span style="color:#eb6772;">├──</span><span style="color:#abb2bf;"> HEAD
</span><span style="color:#eb6772;">├──</span><span style="color:#abb2bf;"> hooks
</span><span style="color:#eb6772;">│</span><span style="color:#abb2bf;"> ├── ...
</span><span style="color:#eb6772;">├──</span><span style="color:#abb2bf;"> info
</span><span style="color:#eb6772;">│</span><span style="color:#abb2bf;"> └── exclude
</span><span style="color:#eb6772;">├──</span><span style="color:#abb2bf;"> objects
</span><span style="color:#eb6772;">│</span><span style="color:#abb2bf;"> ├── info
</span><span style="color:#eb6772;">│</span><span style="color:#abb2bf;"> └── pack
</span><span style="color:#eb6772;">└──</span><span style="color:#abb2bf;"> refs
</span><span style="color:#eb6772;">├──</span><span style="color:#abb2bf;"> heads
</span><span style="color:#eb6772;">└──</span><span style="color:#abb2bf;"> tags
</span></code></pre>
<p><a href="https://shop.jcoglan.com/buildinggit/%5D">https://gitscm.com/docs/gitrepositorylayout</a></p>
<h3 id="gitconfig"><code>.git/config</code></h3>
<p>A configuration settings that apply only to this directory.</p>
<h3 id="gitdescription"><code>.git/description</code></h3>
<p>A name of the repository, used by gitweb.</p>
<h3 id="githead"><code>.git/HEAD</code></h3>
<p>A reference to the <em>current commit</em>, either using that commit's ID or a <em>symbolic reference</em> (<em>symref</em>).
<code>HEAD</code> is used as a parent reference for new commit.
<code>HEAD</code> is changed when checking out a branch or specific comit.
When merging, the requested branch is merged with whatever <code>HEAD</code> points at.</p>
<h3 id="gitinfo"><code>.git/info</code></h3>
<p>Various pieces of metadata about the repository.</p>
<h3 id="githooks"><code>.git/hooks</code></h3>
<p>Scripts that Git will execute as part of certain core commands.</p>
<h3 id="gitobjects"><code>.git/objects</code></h3>
<p>Forms Git's <em>database</em>, place where Git stores all the content it tracks. Initial subdirectories are:</p>
<ul>
<li><code>.git/objects/pack</code>  for storing objects in an optimised format. Every object added to the database is stored in its own file at first, such an object is called <em>loose object</em>. On certain events many individual files are rolled up into a pack  a single file containing many objects in a compressed format. It needs an index describing where to find each object in a pack.</li>
<li><code>.git/objects/info</code> stores metadata about the packs for use by some of the remote protocols. Also stores links to other object stores.</li>
</ul>
<h3 id="gitrefs"><code>.git/refs</code></h3>
<p>Stores various kind of pointers into the <code>.git/objects</code> database. Usually just files that contain the ID of a commit, e.g.:</p>
<ul>
<li><code>.git/refs/heads</code> store the latest commit on each local branch.</li>
<li><code>.git/refs/stash</code> references to stashed changes in <code>.git/objects</code></li>
</ul>
<h2 id="22asimplecommit">2.2 A simple commit</h2>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">git commit message "First commit."
[master (rootcommit) 65b1d93] First commit.
2 files changed, 2 insertions(+)
create mode 100644 hello.txt
create mode 100644 world.txt
</span></code></pre>
<p><code>rootcommit</code> is a commit without any parent.</p>
<p>Newly added files after running a commit:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">├── COMMIT_EDITMSG
├── index
├── logs
│ ├── HEAD
│ └── refs
│ └── heads
│ └── master
├── objects
│ ├── 65
│ │ └── b1d9312836b1e84233b209d8d066038aead925
│ ├── 88
│ │ └── e38705fdbd3608cddbe904b67c731f3234c45b
│ ├── cc
│ │ └── 628ccd10742baea8241c5924df992b5c019f71
│ ├── ce
│ │ └── 013625030ba8dba906f756967f9e9ca394464a
│ ├── info
│ └── pack
└── refs
├── heads
│ └── master
└── tags
</span></code></pre><h3 id="gitcommiteditmsg"><code>.git/COMMIT_EDITMSG</code></h3>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">cat .git/COMMIT_EDITMSG
First commit.
</span></code></pre>
<p>Used by Git to compose commit messages. When <code>message</code> is not passed Git opens an editor to compose the commit message. <code>.git/COMMIT_EDITMSG</code> is asked to editor to open. After closing GIt will read this file. When <code>message</code> is passed Git still saves it in the file.</p>
<h3 id="gitindex"><code>.git/index</code></h3>
<p>Binary cache that that stores information about each file in the current commit and which version of each file should be present. Updated when <code>git add</code> is run. Is used to build next commit.</p>
<h3 id="gitlogs"><code>.git/logs</code></h3>
<p>Text files containing a log of every time a <em>ref</em> (<em>reference</em>, something that points to a commit, like <code>HEAD</code> or branch name) changes its value, e.g. when:</p>
<ul>
<li>making a commit</li>
<li>checking out a branch</li>
<li>merging</li>
<li>rebasing</li>
<li>...</li>
</ul>
<p>A log record for the First commit:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">0000000000000000000000000000000000000000 65b1d9312836b1e84233b209d8d066038aead925 \
Tomas Koutsky <tomas@stepnivlk.net> 1616955235 +0200 \
commit (initial): First commit.
</span></code></pre>
<p>This event changes refs from pointing at nothing (<code>0000...</code>) to a commit (<code>65b1...</code>). Used by <code>reflog</code> command.</p>
<h3 id="gitrefsheadsmaster"><code>.git/refs/heads/master</code></h3>
<p>Records which commit is at the tip of the <code>master</code> branch, which <code>HEAD</code> is currently reffering to:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">65b1d9312836b1e84233b209d8d066038aead925
</span></code></pre><h2 id="23storingobjects">2.3 Storing objects</h2>
<p>Files in:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">├── objects
│ ├── 65
│ │ └── b1d9312836b1e84233b209d8d066038aead925
│ ├── 88
│ │ └── e38705fdbd3608cddbe904b67c731f3234c45b
│ ├── cc
│ │ └── 628ccd10742baea8241c5924df992b5c019f71
│ ├── ce
│ │ └── 013625030ba8dba906f756967f9e9ca394464a
</span></code></pre>
<p>are where Git stores all the objects that make up the content including commits.</p>
<p>The object from a database can be printed using <code>git catfile p <hash></code>, e.g.:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">~> git catfile p 65b1d9312836b1e84233b209d8d066038aead925
tree 88e38705fdbd3608cddbe904b67c731f3234c45b
author Tomas Koutsky <tomas@stepnivlk.net> 1616955235 +0200
committer Tomas Koutsky <tomas@stepnivlk.net> 1616955235 +0200
First commit.
</span></code></pre>
<p>A <em>tree</em> represenets whole tree of files as they were when given commit was made:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">~> git catfile p 88e38705fdbd3608cddbe904b67c731f3234c45b
100644 blob ce013625030ba8dba906f756967f9e9ca394464a hello.txt
100644 blob cc628ccd10742baea8241c5924df992b5c019f71 world.txt
</span></code></pre>
<p>Tree has one tree for every directory. Each entry in a tree is either another tree or a <em>blob</em>  regular file. Each entry in a tree lists:</p>
<ul>
<li>mode  type + permissions, 100644 is a regular, readable, nonexecutable file</li>
<li>type  <em>blob</em> or <em>tree</em></li>
<li>ID</li>
<li>filename</li>
</ul>
<p>For blobs, Git just stores their literal contents:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">~> git catfile p ce013625030ba8dba906f756967f9e9ca394464a
hello
</span></code></pre>
<p>Git stores objects with first two characters forming directory in order to cope with restrictions of some operating systems when the amount of objects grows. Also it allows for faster lookup.</p>
<p>Objects are compressed:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">~> cat .git/objects/ce/013625030ba8dba906f756967f9e9ca394464a
xK��OR0c�H�����⏎
</span></code></pre>
<p>using DEFLATE (zlib).</p>
<p>Object can be easilly decompressed using ruby:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">~> cat .git/objects/ce/01..  ruby r zlib e "puts Zlib::Inflate.inflate(STDIN.read)"
blob 6hello
</span></code></pre>
<p>The file can be inspected further using hexdump:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">cat .git/objects/ce/01..  ruby r ...  hexdump C
00000000 62 6c 6f 62 20 36 00 68 65 6c 6c 6f 0a blob 6.hello.
0000000d
</span></code></pre>
<ul>
<li><code>62 6c 6f 62</code>  <code>blob</code> in ASCII</li>
<li><code>20</code>  space</li>
<li><code>36</code> <code>6</code> in ASCII</li>
<li><code>00</code>  null byte; separates the header from actual content</li>
</ul>
<p>So the blobs are stored as zlib compressed:</p>
<ul>
<li>the word <code>blob</code></li>
<li>a space</li>
<li>the lenght of the blob</li>
<li>null byte</li>
<li>the actual data</li>
</ul>
<p>Trees are different though:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">~> cat .git/objects/88/e38705fdbd3608cddbe904b67c731f3234c45b  ./inflate.sh  hexdump C
00000000 74 72 65 65 20 37 34 00 31 30 30 36 34 34 20 68 tree 74.100644 h
00000010 65 6c 6c 6f 2e 74 78 74 00 ce 01 36 25 03 0b a8 ello.txt...6%...
00000020 db a9 06 f7 56 96 7f 9e 9c a3 94 46 4a 31 30 30 ....V......FJ100
00000030 36 34 34 20 77 6f 72 6c 64 2e 74 78 74 00 cc 62 644 world.txt..b
00000040 8c cd 10 74 2b ae a8 24 1c 59 24 df 99 2b 5c 01 ...t+..$.Y$..+\.
00000050 9f 71 0a .q.
00000053
</span></code></pre>
<p>The knowns:</p>
<ul>
<li><code>tree 74.</code>  header</li>
<li><code>100644 hello.txt</code>  a filename with mode</li>
<li><code>100644 world.txt</code>  a filename with mode</li>
</ul>
<p>Then there are IDs in packed, 20B format:</p>
<ul>
<li><code>ce 01 36 25 03 0b a8 db a9 06 f7 56 96 7f 9e 9c a3 94 46 4a</code></li>
<li><code>cc 62 8c cd 10 74 2b ae a8 24 1c 59 24 df 99 2b 5c 01 9f 71</code>
The end of filename is separated using null byte.</li>
</ul>
<p>The type of an object is implied by its mode  <code>10</code> at the beggining of <code>100644</code> indicates its a regular file, not a directory.</p>
<p>Commits are simpler:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">~> cat .git/objects/65/b1d9312836b1e84233b209d8d066038aead925  ./inflate.sh
commit 184tree 88e38705fdbd3608cddbe904b67c731f3234c45b
author Tomas Koutsky <tomas@stepnivlk.net> 1616955235 +0200
committer Tomas Koutsky <tomas@stepnivlk.net> 1616955235 +0200
First commit.
</span></code></pre>
<p>It's simply a series of headers followed by the message. In this commit the headers are:</p>
<ul>
<li><code>commit 184</code>  its own header</li>
<li><code>tree</code>  reference to a single tree representing the state of files at that point in the history.</li>
<li><code>author</code>  simple metadata</li>
<li><code>committer</code>  simple metadata</li>
</ul>
<h3 id="computingobjectids">Computing object IDs</h3>
<p>Objects are named by taking SHA1 hash of their content prepended with a header before compressing them.
SHA1 is a <em>cryptographic hash function</em>, it takes input of arbitrary sized string and outputs a fixedsize 20B number.
It's designed in such a way that it should be effectivelly impossible to find two inputs that has to the same output.
There are $2^{160}$ of possible object IDs so its <em>computationally infeasible</em> to find a collision.
This is property is a key to the distributed nature of Git  no two distinct objects in any repository will be given the same ID.
Also comparition becomes simple  if two objects have same ID they are same.</p>
<h3 id="problemswithsha1">Problems with SHA1</h3>
<p>A hash is considered broken when there is an attack requiring less than $2^\frac{n}{2}$ ($n$ being the size of the output in bits) inputs to find a collision. For SHA1 tht means an attack requiring fewer than $2^{80}$ steps.</p>
<p>In 2005 an attack requiring $5.9 \times 10^{20}$ steps was reported (<a href="https://www.schneier.com/blog/archives/2005/02/cryptanalysis_o.html">https://www.schneier.com/blog/archives/2005/02/cryptanalysis_o.html</a>).
In 2017 Google announced an attach requiring $9.2 \times 10^{18}$ (<a href="https://shattered.io/">https://shattered.io/</a>)</p>
<p>The migration to SHA256 is possible however Git doesn't rely on SHA1 as proof of trust, it's an integrity check against accidental damage. From this perspective SHA1 is good enough.</p>
<p>Moreover for an attacker to replace an object it's not enough to find a collision, he needs to find collision with concrete blob.</p>
<h1 id="3thefirstcommit">3. The first commit</h1>
<h2 id="init"><code>init</code></h2>
<p>The very first step is <code>git init</code> the bare essentials for it are <code>objects</code> and <code>refs</code> folder and <code>HEAD</code> file. With those Git will consider the directory valid.</p>
<h2 id="commit"><code>commit</code></h2>
<ul>
<li><code>Workspace</code> is responsible for the files in the working tree  all the files that are edited directly, rather than those stored in <code>.git</code>.</li>
</ul>
<h1 id="4makinghistory">4. Making history</h1>
<p>When adding second commit via Git I get:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git commit</span><span style="color:#eb6772;"> m </span><span style="color:#9acc76;">'Second commit.'
</span><span style="color:#eb6772;">[master</span><span style="color:#abb2bf;"> 2d719c9] Second commit.
</span><span style="color:#eb6772;">1</span><span style="color:#abb2bf;"> file changed, 1 insertion(+)</span><span style="color:#eb6772;">,</span><span style="color:#abb2bf;"> 1 deletion()
</span></code></pre>
<p>There's no <code>rootcommit</code> now since it follows on from the previous commit.</p>
<p>The ID of the second commit is stored in master ref:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> cat .git/refs/heads/master
</span><span style="color:#eb6772;">2d719c90a3c181782e6e07e2fd027f90ab5de0b5
</span></code></pre>
<p>There's a parent field in the object representing second commit:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git catfile</span><span style="color:#eb6772;"> p</span><span style="color:#abb2bf;"> 2d719c90a3c181782e6e07e2fd027f90ab5de0b5
</span><span style="color:#eb6772;">tree</span><span style="color:#abb2bf;"> 040c6f3e807f0d433870584bc91e06b6046b955d
</span><span style="color:#eb6772;">parent</span><span style="color:#abb2bf;"> 65b1d9312836b1e84233b209d8d066038aead925
</span><span style="color:#eb6772;">author</span><span style="color:#abb2bf;"> Tomas Koutsky </span><span style="color:#adb7c9;"><</span><span style="color:#abb2bf;">tomas@stepnivlk.net</span><span style="color:#adb7c9;">> </span><span style="color:#db9d63;">1617213880</span><span style="color:#abb2bf;"> +0200
</span><span style="color:#eb6772;">committer</span><span style="color:#abb2bf;"> Tomas Koutsky </span><span style="color:#adb7c9;"><</span><span style="color:#abb2bf;">tomas@stepnivlk.net</span><span style="color:#adb7c9;">> </span><span style="color:#db9d63;">1617213880</span><span style="color:#abb2bf;"> +0200
</span><span style="color:#eb6772;">Second</span><span style="color:#abb2bf;"> commit.
</span></code></pre>
<p>The ID behind parent points to the first commit:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git catfile</span><span style="color:#eb6772;"> p</span><span style="color:#abb2bf;"> 65b1d9312836b1e84233b209d8d066038aead925
</span><span style="color:#eb6772;">tree</span><span style="color:#abb2bf;"> 88e38705fdbd3608cddbe904b67c731f3234c45b
</span><span style="color:#eb6772;">author</span><span style="color:#abb2bf;"> Tomas Koutsky </span><span style="color:#adb7c9;"><</span><span style="color:#abb2bf;">tomas@stepnivlk.net</span><span style="color:#adb7c9;">> </span><span style="color:#db9d63;">1616955235</span><span style="color:#abb2bf;"> +0200
</span><span style="color:#eb6772;">committer</span><span style="color:#abb2bf;"> Tomas Koutsky </span><span style="color:#adb7c9;"><</span><span style="color:#abb2bf;">tomas@stepnivlk.net</span><span style="color:#adb7c9;">> </span><span style="color:#db9d63;">1616955235</span><span style="color:#abb2bf;"> +0200
</span><span style="color:#eb6772;">First</span><span style="color:#abb2bf;"> commit.
</span></code></pre>
<p>So each commit made after the root one has parent field pointing to previous commit. This allows for understanding of how commits are <em>causually connected</em>.</p>
<p>Each tree contains the snapshot of all the files.
First tree:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git catfile</span><span style="color:#eb6772;"> p</span><span style="color:#abb2bf;"> 88e38705fdbd3608cddbe904b67c731f3234c45b
</span><span style="color:#eb6772;">100644</span><span style="color:#abb2bf;"> blob ce013625030ba8dba906f756967f9e9ca394464a hello.txt
</span><span style="color:#eb6772;">100644</span><span style="color:#abb2bf;"> blob cc628ccd10742baea8241c5924df992b5c019f71 world.txt
</span></code></pre>
<p>Second tree:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git catfile</span><span style="color:#eb6772;"> p</span><span style="color:#abb2bf;"> 040c6f3e807f0d433870584bc91e06b6046b955d
</span><span style="color:#eb6772;">100644</span><span style="color:#abb2bf;"> blob e019be006cf33489e2d0177a3837a2384eddebc5 hello.txt
</span><span style="color:#eb6772;">100644</span><span style="color:#abb2bf;"> blob cc628ccd10742baea8241c5924df992b5c019f71 world.txt
</span></code></pre>
<p><code>world.txt</code> is same object with same ID as its content didn't change and IDs of objects are derived from their contents.</p>
<p>Thus Git only creates new blobs when files have their content changed. Files with same content will point to same blob even when those files appear in many trees across many commits.</p>
<h2 id="42implementingtheparentchain">4.2 Implementing the <code>parent</code> chain</h2>
<p><code>.git/HEAD</code> needs to be updated when storing commits however it has to be done in safe, atomic way as there may be multiple readers. Multiple writers are considered as an error. This can be tackled using a lockfile.</p>
<h1 id="5growingtrees">5 Growing trees</h1>
<h2 id="51executablefiles">5.1 Executable files</h2>
<p>When commiting executable file:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> touch cruel.txt
</span><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> chmod +x cruel.txt
</span><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git add cruel.txt
</span><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git commit</span><span style="color:#eb6772;"> m </span><span style="color:#9acc76;">'Third commit.'
</span><span style="color:#eb6772;">[master</span><span style="color:#abb2bf;"> 91c525a] Third commit.
</span><span style="color:#eb6772;">1</span><span style="color:#abb2bf;"> file changed, 0 insertions(+)</span><span style="color:#eb6772;">,</span><span style="color:#abb2bf;"> 0 deletions()
</span><span style="color:#eb6772;">create</span><span style="color:#abb2bf;"> mode 100755 cruel.txt
</span></code></pre>
<p>The mode is <code>100755</code> instead of <code>100644</code> and it's stored in the tree:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git catfile</span><span style="color:#eb6772;"> p</span><span style="color:#abb2bf;"> HEAD^{tree}
</span><span style="color:#eb6772;">100755</span><span style="color:#abb2bf;"> blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 cruel.txt
</span><span style="color:#eb6772;">100644</span><span style="color:#abb2bf;"> blob e019be006cf33489e2d0177a3837a2384eddebc5 hello.txt
</span><span style="color:#eb6772;">100644</span><span style="color:#abb2bf;"> blob cc628ccd10742baea8241c5924df992b5c019f71 world.txt
</span></code></pre>
<p>The mode is in base 8, it makes it easier to read in the compact format. First 4 bits are file type related, others are permissions (special, user, group other).
E.g. in <code>100644</code>:</p>
<ul>
<li><code>10</code>  regular file</li>
<li><code>0</code>  no special permissions</li>
<li><code>6</code>  owner can rw</li>
<li><code>4</code>  members of the group can read</li>
<li><code>4</code>  others can read
In <code>100755</code>:</li>
<li><code>7</code>  owner can rw + execute</li>
<li><code>5</code>  members of the group can r + execute</li>
<li><code>5</code>  others can r + execute</li>
</ul>
<p>Git only uses very restricted permissions  whether owner can execute, rest is thrown out:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> touch out.txt
</span><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> chmod 655 out.txt
</span><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git add out.txt
</span><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git commit</span><span style="color:#eb6772;"> m </span><span style="color:#9acc76;">'Forth commit.'
</span><span style="color:#eb6772;">[master</span><span style="color:#abb2bf;"> 27df932] Forth commit.
</span><span style="color:#eb6772;">1</span><span style="color:#abb2bf;"> file changed, 0 insertions(+)</span><span style="color:#eb6772;">,</span><span style="color:#abb2bf;"> 0 deletions()
</span><span style="color:#eb6772;">create</span><span style="color:#abb2bf;"> mode 100644 out.txt
</span></code></pre>
<p>Thus Git only has two modes  <code>100644</code> and <code>100755</code>.</p>
<h2 id="52nestedtrees">5.2 Nested trees</h2>
<p>Trees can be arbitrarily nested:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> mkdir</span><span style="color:#eb6772;"> p</span><span style="color:#abb2bf;"> a/b
</span><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> touch a/b/c.txt
</span><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git add .
</span><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git commit</span><span style="color:#eb6772;"> m </span><span style="color:#9acc76;">'First commit.'
</span><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git catfile</span><span style="color:#eb6772;"> p</span><span style="color:#abb2bf;"> HEAD^{tree}
</span><span style="color:#eb6772;">040000</span><span style="color:#abb2bf;"> tree c4a644afb090a8303bdb28306a2f803017551f25 a
</span></code></pre>
<p>Hexdump:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> cat .git/objects/c4/a644afb090a8303bdb28306a2f803017551f25 </span><span style="color:#adb7c9;"> </span><span style="color:#eb6772;">./inflate.sh </span><span style="color:#adb7c9;"> </span><span style="color:#eb6772;">hexdump C
00000000</span><span style="color:#abb2bf;"> 74 72 65 65 20 32 38 00 34 30 30 30 30 20 62 00 </span><span style="color:#adb7c9;"></span><span style="color:#eb6772;">tree</span><span style="color:#abb2bf;"> 28.40000 b.</span><span style="color:#adb7c9;">
</span><span style="color:#eb6772;">00000010</span><span style="color:#abb2bf;"> 17 21 a7 a9 1e 87 f5 41 3c 84 2a 9c 5c e7 3f 67 </span><span style="color:#adb7c9;"></span><span style="color:#eb6772;">.!.....A</span><span style="color:#adb7c9;"><</span><span style="color:#abb2bf;">.</span><span style="color:#adb7c9;">*</span><span style="color:#abb2bf;">.</span><span style="color:#5ebfcc;">\.</span><span style="color:#adb7c9;">?</span><span style="color:#abb2bf;">g</span><span style="color:#adb7c9;">
</span><span style="color:#eb6772;">00000020</span><span style="color:#abb2bf;"> 44 59 e9 2b 0a </span><span style="color:#adb7c9;"></span><span style="color:#eb6772;">DY.+.</span><span style="color:#adb7c9;">
</span><span style="color:#eb6772;">00000025
</span></code></pre>
<p>The mode is <code>40000</code>. In Unix, directories have file type bits set to <code>4</code> and permissions to <code>755</code>. Git ingones all the permissions and just stores <code>40000</code> to indicate it's a directory.
<code>a</code> of course points to <code>b</code>  another tree.</p>
<p>The content of a tree is just a list of IDs and names of this contents and SHA1 hashes the content. Thus when two trees have same IDs it means all their contents are same, recursively.
This method of storing a tree of information where each tree is labelled with the has of its children is called a Merkle tree.</p>
<p>Entries in trees have to be sorted in order to compare those effectively. Git sorts the file list for the entire project before building trees, thus it sorts following entries:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">foo </span><span style="fontstyle:italic;color:#5f697a;"># dir with bar.txt entry
</span><span style="color:#eb6772;">foo.txt
</span></code></pre>
<p>as:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">foo.txt
foo
</span></code></pre>
<p>It sees <code>foo</code> as <code>foo/bar.txt</code>.</p>
<p>In Git, the <code>add</code> command reads the working tree, stores blobs in the database and adds them to the index. <code>commit</code> reads the index to create trees. The index is stored as flat list of paths.</p>
<h1 id="6theindex">6. The index</h1>
<p>Current <code>commit</code> implementation reads and hashes every file in the project in order to store blobs, that's ineffective. Usually, in larger projects, only small subset of files is changed in commit. Moreover, the current implementation is cumbersome to use. The user should control what goes in a commit.</p>
<p>The <code>add</code> command and the index solve the problem by providing a cache of all the blobs representing the current state of the project. It contains the object IDs of the blobs corresponding the the current files plus a lot of information from the filesystem (size of files, timestamps).</p>
<h2 id="62inspectinggitindex">6.2 Inspecting <code>.git/index</code></h2>
<p>Let's consider following scenario:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> touch file.txt
</span><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git status
</span><span style="color:#eb6772;">On</span><span style="color:#abb2bf;"> branch master
</span><span style="color:#eb6772;">No</span><span style="color:#abb2bf;"> commits yet
</span><span style="color:#eb6772;">Untracked</span><span style="color:#abb2bf;"> files:
(</span><span style="color:#eb6772;">use </span><span style="color:#9acc76;">"git add <file>..."</span><span style="color:#abb2bf;"> to include in what will be committed)
</span><span style="color:#eb6772;">file.txt
nothing</span><span style="color:#abb2bf;"> added to commit but untracked files present (use </span><span style="color:#9acc76;">"git add"</span><span style="color:#abb2bf;"> to track)
</span><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git add file.txt
</span><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git status
</span><span style="color:#eb6772;">On</span><span style="color:#abb2bf;"> branch master
</span><span style="color:#eb6772;">No</span><span style="color:#abb2bf;"> commits yet
</span><span style="color:#eb6772;">Changes</span><span style="color:#abb2bf;"> to be committed:
(</span><span style="color:#eb6772;">use </span><span style="color:#9acc76;">"git rm cached <file>..."</span><span style="color:#abb2bf;"> to unstage)
</span><span style="color:#eb6772;">new</span><span style="color:#abb2bf;"> file: file.txt
</span><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> echo </span><span style="color:#9acc76;">"new content" </span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> file.txt
</span><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git status
</span><span style="color:#eb6772;">On</span><span style="color:#abb2bf;"> branch master
</span><span style="color:#eb6772;">No</span><span style="color:#abb2bf;"> commits yet
</span><span style="color:#eb6772;">Changes</span><span style="color:#abb2bf;"> to be committed:
(</span><span style="color:#eb6772;">use </span><span style="color:#9acc76;">"git rm cached <file>..."</span><span style="color:#abb2bf;"> to unstage)
</span><span style="color:#eb6772;">new</span><span style="color:#abb2bf;"> file: file.txt
</span><span style="color:#eb6772;">Changes</span><span style="color:#abb2bf;"> not staged for commit:
(</span><span style="color:#eb6772;">use </span><span style="color:#9acc76;">"git add <file>..."</span><span style="color:#abb2bf;"> to update what will be committed)
(</span><span style="color:#eb6772;">use </span><span style="color:#9acc76;">"git restore <file>..."</span><span style="color:#abb2bf;"> to discard changes in working directory)
</span><span style="color:#eb6772;">modified:</span><span style="color:#abb2bf;"> file.txt
</span></code></pre>
<p>What does it mean for change to be <em>staged</em>?</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> hexdump</span><span style="color:#eb6772;"> C</span><span style="color:#abb2bf;"> .git/index
</span><span style="color:#eb6772;">00000000</span><span style="color:#abb2bf;"> 44 49 52 43 00 00 00 02 00 00 00 01 60 66 e1 3d </span><span style="color:#adb7c9;"></span><span style="color:#eb6772;">DIRC........</span><span style="color:#9acc76;">`</span><span style="color:#eb6772;">f.</span><span style="color:#adb7c9;">=
</span><span style="color:#eb6772;">00000010</span><span style="color:#9acc76;"> 15 7d 40 fe 60 66 e1 3d 15 7d 40 fe 00 00 00 1a </span><span style="color:#adb7c9;"></span><span style="color:#eb6772;">.</span><span style="color:#9acc76;">}</span><span style="color:#eb6772;">@.</span><span style="color:#9acc76;">`f.=.}@.....</span><span style="color:#adb7c9;">
</span><span style="color:#eb6772;">00000020</span><span style="color:#abb2bf;"> 00 1f 40 63 00 00 81 a4 00 00 03 e8 00 00 03 e8 </span><span style="color:#adb7c9;"></span><span style="color:#eb6772;">..@c............</span><span style="color:#adb7c9;">
</span><span style="color:#eb6772;">00000030</span><span style="color:#abb2bf;"> 00 00 00 00 e6 9d e2 9b b2 d1 d6 43 4b 8b 29 ae </span><span style="color:#adb7c9;"></span><span style="color:#eb6772;">...........CK.</span><span style="color:#abb2bf;">)</span><span style="color:#5ebfcc;">.</span><span style="color:#adb7c9;">
</span><span style="color:#eb6772;">00000040</span><span style="color:#abb2bf;"> 77 5a d8 c2 e4 8c 53 91 00 08 66 69 6c 65 2e 74 </span><span style="color:#adb7c9;"></span><span style="color:#eb6772;">wZ....S...file.t</span><span style="color:#adb7c9;">
</span><span style="color:#eb6772;">00000050</span><span style="color:#abb2bf;"> 78 74 00 00 4a a4 ed 90 d2 ca 32 07 52 b6 39 d3 </span><span style="color:#adb7c9;"></span><span style="color:#eb6772;">xt..J.....2.R.9.</span><span style="color:#adb7c9;">
</span><span style="color:#eb6772;">00000060</span><span style="color:#abb2bf;"> e4 31 4b bb fc 72 8e 2d </span><span style="color:#adb7c9;"></span><span style="color:#eb6772;">.1K..r.</span><span style="color:#adb7c9;">
</span><span style="color:#eb6772;">00000068
</span></code></pre>
<p>By checking <a href="https://gitscm.com/docs/indexformat">https://gitscm.com/docs/indexformat</a> I ca see that the index starts with:</p>
<ul>
<li>A 12byte header consisting of
<ul>
<li>4byte signature:
<ul>
<li>The signature is { 'D', 'I', 'R', 'C' } (stands for "dircache")</li>
</ul>
</li>
<li>4byte version number:
<ul>
<li>The current supported versions are 2, 3 and 4.</li>
</ul>
</li>
<li>32bit number of index entries.</li>
</ul>
</li>
</ul>
<p>Thus the header part of the dump is:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">44</span><span style="color:#abb2bf;"> 49 52 43 00 00 00 02 00 00 00 01
</span><span style="color:#eb6772;"></span><span style="color:#adb7c9;"></span><span style="color:#eb6772;"></span><span style="color:#adb7c9;"></span><span style="color:#eb6772;">
DIRC </span><span style="color:#adb7c9;"> </span><span style="color:#eb6772;">v2 </span><span style="color:#adb7c9;"> </span><span style="color:#eb6772;">1</span><span style="color:#abb2bf;"> entry
</span></code></pre>
<p>The header is followed by entries themselves, each entry starts with ten 4byte <code>stat</code> numbers:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">ctime</span><span style="color:#abb2bf;"> seconds, the last time a file</span><span style="color:#9acc76;">'s metadata changed
ctime nanosecond fractions
mtime seconds, the last time a file'</span><span style="color:#abb2bf;">s data changed
</span><span style="color:#eb6772;">mtime</span><span style="color:#abb2bf;"> nanosecond fractions
</span><span style="color:#eb6772;">dev
ino
mode
uid
gid
file</span><span style="color:#abb2bf;"> size
</span></code></pre>
<ul>
<li><em>ctame</em>  time when content or metadata was changed</li>
<li><em>mtame</em>  time when content was changed</li>
<li><em>dev</em>  ID of hardware storage</li>
<li><em>non</em>  number of inode</li>
</ul>
<p>To list all the files in the index:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagesh" datalang="sh"><span style="color:#eb6772;">~</span><span style="color:#adb7c9;">></span><span style="color:#abb2bf;"> git lsfiles</span><span style="color:#eb6772;"> stage
100644</span><span style="color:#abb2bf;"> e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 file.txt
</span></code></pre>MU123 Unit 4 NotesSun, 14 Mar 2021 00:00:00 +0000
https://ktsk.xyz/posts/mu123unit4/
https://ktsk.xyz/posts/mu123unit4/<h1 id="1questionsquestions">1 Questions, questions</h1>
<ul>
<li>Quantitative view  uses numbers > measurments, counts</li>
<li>Qualitative view  describes what something is like in words</li>
</ul>
<p>Statistics is about quantitative view</p>
<h2 id="11typesofstatisticalquestion">1.1 Types of statistical question</h2>
<ul>
<li>Summarising: how can the information be reduced?
<ul>
<li>Reduction of many numbers to few representatives, e.g. average</li>
<li>Statistical charts or plots</li>
</ul>
</li>
<li>Comparing: is there a difference?
<ul>
<li>Depends on various factors
<ul>
<li>Sizes of the samples on which averages are based</li>
<li>The degree of variation</li>
<li>Whether the size of the observed difference is sufficiently large to act upon</li>
</ul>
</li>
</ul>
</li>
<li>Seeking a relationship: what sort of relationship is there?
<ul>
<li>Finding a possible relationship between quite separate things</li>
<li>Statistical relation doesn't prove a causeandeffect relationship</li>
<li>Useful to determine the kind of relationship
<ul>
<li>How much does one factor change relative to the other?</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="12thestatisticalinvestigationcycle">1.2 The statistical investigation cycle</h2>
<p>The stages of statistical investigation</p>
<ol>
<li><strong>P</strong>ose a question</li>
<li><strong>C</strong>ollect relevant data</li>
<li><strong>A</strong>nalyse the data</li>
<li><strong>I</strong>nterpret the data</li>
</ol>
<p>Forming <strong>PCAI</strong> cycle:</p>
<div class="mermaid isflex isjustifycontentcenter isalignitemscenter">stateDiagramv2
P: P Real world
A: A Statistical world
P > A : C
A > P : I</div>
<p>The question has to be as focused as possible.</p>
<h1 id="2dealingwithdata">2 Dealing with data</h1>
<ul>
<li>Issues to do with collecting data (<strong>C</strong>)</li>
<li>Important distinctions between different types of data (<strong>A</strong>)</li>
</ul>
<h2 id="21primaryandsecondarydata">2.1 Primary and secondary data</h2>
<ul>
<li>Primary data  data that I collect by myself (a research unit)</li>
<li>Secondary data  data that already exist and can be used or adapted</li>
<li>Dataset  a collection of data (e.g. in tabular form)
<ul>
<li>Reference should be provided</li>
</ul>
</li>
</ul>
<h2 id="22discreteandcontinuousdata">2.2 Discrete and continuous data</h2>
<ul>
<li>Discrete  counting
<ul>
<li>Can take one of a particular set of values, typically integers</li>
<li>Nonnumerical data can be coded to discrete values
<ul>
<li>e.g. binary yes/no > 1/0</li>
</ul>
</li>
<li>Exact answer can be given</li>
</ul>
</li>
<li>Continuous  measuring
<ul>
<li>Can take all the inbetween values on the number scale</li>
<li>All the real numbers, can be constrained to e.g. finite interval </li>
<li>Never possible to get an exact answer
<ul>
<li>Measurements can be only approximated with some degree of precision</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>The approximation given by measuring of continuous data implies that its a dicrete representation of continous data</p>
<h2 id="23checkingandcleaningdata">2.3 Checking and cleaning data</h2>
<p>One or more data values that are considerably smaller or larger than the other values in the same dataset are called <strong>outliers</strong>.
Outliers sometimes correspond to errors. Sometimes its just unusual observation (e.g. woman 1.92m tall).
Therea are various statistical techniques to deal with outliers.</p>
<h2 id="24spuriousprecision">2.4 Spurious precision</h2>
<p>Can arise in various ways, e.g.:</p>
<ul>
<li>Conversion of units
<ul>
<li>E.g.: age given as $29.91666$ that is a result of monthstoyears conversion $=29\text{years} + 11\text{months}/12$</li>
</ul>
</li>
<li>Implying that a quantity can be measured to a greater level of precision than is possible with the measuring instrumet used. </li>
<li>Quoting figures to a greater number of significant figures than is warranted in the context. </li>
</ul>
<p>Generally, displayed data should be just precise enough to reveal the key features.</p>
<h2 id="26singleandpaireddata">2.6 Single and paired data</h2>
<ul>
<li><strong>Sigle data</strong>  can be analysed in isolation, e.g. in weights of persons I can:
<ul>
<li>Find average</li>
<li>Find dispersion of values</li>
<li>Plot it to discren the overall pattern visually</li>
</ul>
</li>
<li><strong>Twosample data</strong>  second dataset is added, e.g. weights of old persons
<ul>
<li>Interest now is in comparing features</li>
</ul>
</li>
<li><strong>Paired data</strong>  e.g. statistical interest being in comparing weight of babies to the weights of their mothers at the start of pregnancy.
<ul>
<li>Essentially seeking a relationship</li>
<li>Two data lists must contain the same number of values</li>
<li>For each item in one list there's a corresponding item in the other</li>
</ul>
</li>
</ul>
<h1 id="3summarisingdatalocation">3. Summarising data: location</h1>
<p>Stage <strong>A</strong> of the PCAI cycle  analysing data that have been collected.
<strong>Location</strong> of a dataset is:</p>
<ul>
<li>Single number that represents
<ul>
<li>average value</li>
<li>typical value</li>
<li>central value</li>
</ul>
</li>
<li>Sets of data can be compared by their locations </li>
</ul>
<h2 id="32measuringlocation">3.2 Measuring location</h2>
<p>There's no single and universally most appropriate measure of location. Measures can be chosen mased on the situation and the nature of the data.
The three most common measures of location are:</p>
<ul>
<li>Mean</li>
<li>Mode
<ul>
<li>A value that occurs most frequently in the dataset
<ul>
<li>Won't be used in MU123</li>
</ul>
</li>
</ul>
</li>
<li>Median</li>
</ul>
<h3 id="mean">Mean</h3>
<p>(also arithmetic average)</p>
<blockquote>
<p>Strategy</p>
<ul>
<li>Add all the numbers together</li>
<li>Divide by however many numbers there are in the set.</li>
</ul>
</blockquote>
<h3 id="median">Median</h3>
<p>Data value that is in the middle when the data are arranged in order</p>
<blockquote>
<p>Strategy</p>
<ul>
<li>Sort the data into increasing or decreasing order</li>
<li>If there is an odd number of data values, the median is the middle value</li>
<li>If there is an even number of data values, the median is defined as the mean of the middle two values</li>
</ul>
</blockquote>
<h2 id="33meanversusmedian">3.3 Mean versus median</h2>
<p>When the values are highly symmetrical the values of mean and the median are very similar. Outlier on one side has big impact on mean but none on median, e.g.:
$$
[3,4,5,6,7,8,99] => \text{mean}: 18.9 ~\text{median}: 6
$$</p>
<h1 id="3summarisingdataspread">3. Summarising data: spread</h1>
<p>How widely <strong>spread</strong> the values are.</p>
<p>E.g. following data set is relatively widely spread from 42 to 92:
$$
[42, 58, 60, 68, 78, 92]
$$</p>
<p>And following set is narrower, ranging from 60 to 80:
$$
[60, 65, 72, 74, 75, 80]
$$</p>
<h2 id="41range">4.1 Range</h2>
<p>The difference between the smallest and largest value in the set.
$$
\text{range} = \text{max}  \text{min}
$$</p>
<p>Not adequate when there are extreme outliers in the dataset.</p>
<h2 id="42quartilesandtheinterquartilerange">4.2 Quartiles and the interquartile range</h2>
<p>Exclude top and bottom quarters of the values and create a new measure of spread that measures the range of the middle 50%.
Cutoff points are called <strong>quartiles</strong></p>
<ul>
<li><strong>lower quartile</strong> (Q1)</li>
<li><strong>upper quartile</strong> (Q1)</li>
</ul>
<p><strong>Interquartile range</strong> (IQR) is the difference between the upper and lower quartiles (Q3  Q1)</p>
<blockquote>
<p>Strategy</p>
<ul>
<li>Arrange the dataset in increasing order.</li>
<li>Next
<ul>
<li>When even
<ul>
<li>Q1 is the median of the lower half of dataset</li>
<li>Q3 is the median of the upper half of dataset</li>
</ul>
</li>
<li>When odd
<ul>
<li>Throw out the middle value, median (one of the conventions)</li>
<li>Q1 is the median of the lower half of new dataset</li>
<li>Q3 is the median of the upper half of new dataset</li>
</ul>
</li>
</ul>
</li>
<li>IQR is Q3  Q1</li>
</ul>
</blockquote>
<h2 id="43standarddeviation">4.3 Standard deviation</h2>
<blockquote>
<p>Strategy</p>
<ul>
<li>Find the mean of the dataset</li>
<li>Find the difference of each value from the mean  'deviations', labelled as $d$ values</li>
<li>Square each deviation  $d^2$ values</li>
<li>Find the mean of these squared deviations  'mean squared deviation'  <strong>variance</strong></li>
<li>Find the square root of the variance  'root mean squared deviation'  standard deviation</li>
</ul>
</blockquote>
<h2 id="summariesofdata">Summaries of data</h2>
<div class="mermaid isflex isjustifycontentcenter isalignitemscenter">graph LR
id[Summaries of data]
id>Location
id>Spread
Location>Mean
Location>Median
Spread>Range
Spread>iqr[Interquartile range]
Spread>std[Standard deviation]</div>
<h1 id="5measuringwithaccuracyandprecision">5 Measuring with accuracy and precision</h1>
<p>Repeated measurements to asses the quality of dataset.</p>
<h2 id="52accuracyandprecision">5.2 Accuracy and precision</h2>
<ul>
<li><strong>Accuracy</strong> describes how close the average is to the true value</li>
<li><strong>Precision</strong> describes how close the measurements are to each other</li>
</ul>
Math cheatsheetSun, 07 Mar 2021 00:00:00 +0000
https://ktsk.xyz/posts/mathcheatsheet/
https://ktsk.xyz/posts/mathcheatsheet/<h1 id="rearrangingformulasbyclearingalgebraicfractions">Rearranging formulas by clearing algebraic fractions</h1>
<p>Carry out a sequence of steps. In each step, do one of the following:</p>
<ul>
<li>do the same thing to both sides</li>
<li>simplify one side or both sides</li>
<li>swap the sides</li>
</ul>
<p>Aim to the the following, in order.</p>
<ol>
<li>Clear any fractions and multiply out any brackets. To clear fractions, multiply both sides by a suitable expression.</li>
<li>Add or subtract terms on both sides to get all the terms containing the required subject on one side, and all the other terms on the other side.</li>
<li>If more than one term contains the required subject, then take it out as a common factor. This gives an equation of the form
$$
\text{an expression} \times \text{the required subject} = \text{an expression}
$$</li>
<li>Divide both sides by the expression that multiplies the required subject.</li>
</ol>
<h1 id="indexlaws">Index laws</h1>
<p>$$
a^m \times a^n = a^{m + n} \qquad \frac{a^m}{a^n} = a^{mn} \\[1em]
(a^m)^n = a^{mn} \\[1em]
(a \times b)^n = a^n \times b^n \qquad (\frac{a}{b})^n = \frac{a^n}{b^n} \\[1em]
a^0 = 1 \qquad a^{n} = \frac{1}{a^n} \\[1em]
a^\frac{1}{n} = \sqrt[n]{a} \qquad a^\frac{m}{n} = (\sqrt[n]{a})^m
$$</p>
<h1 id="squaringbrackets">Squaring brackets</h1>
<p>$$
(x + p)^2 = x^2 + 2px + p^2
$$</p>
<p>$$
(x  p)^2 = x^2  2px + p^2
$$</p>
<h1 id="shapesofyax2parabola">Shapes of $y = ax^2$ parabola</h1>
<ul>
<li><strong>ushaped</strong> when the coefficient $a$ is positive</li>
<li><strong>nshaped</strong> when the coefficient $a$ is negative</li>
</ul>
<h1 id="methodstofindthevertexofaparabolafromitsequation">Methods to find the vertex of a parabola from its equation</h1>
<ul>
<li>Use the formula $x = b / (2a)$ to find the $x$coordinate, then substitute into the equation of the parabola to find the $y$coordinate</li>
<li>Find the $x$intercepts (if there are any); then the value halfway between them is the $x$coordinate of the vertex. Find the $y$coordinate by substituting into the equation of the parabola.</li>
<li>Complete the square: the parabola with equation $y = a(x  h)^2 + k$ has vertex $(h, k)$.</li>
<li>Plot the parabola and read off the approximate coordinates of the vertex.</li>
</ul>
<h1 id="thenumberofsolutionsofaquadraticequation">The number of solutions of a quadratic equation</h1>
<p>The value $b^2  4ac$ is called the <strong>discriminant</strong> of the quadratic expression $ax^2 + bx + c$. Such an equation has:</p>
<ul>
<li>two solutions if $b^2  4ac > 0$ (the discriminant is positive).</li>
<li>one solution if $b^2  4ac = 0$ (the discriminant is zero).</li>
<li>no solutions if $b^2  4ac < 0$ (the discriminant is negative).</li>
</ul>
<h1 id="asymptoteofacurve">Asymptote of a curve</h1>
<p>Is a line such that the distance between the curve and the line approaches zero as one or both of the x or y coordinates tends to infinity.</p>
<h1 id="evenandoddfunctions">Even and odd functions</h1>
<p>$f(x) = x^n$ is an even function if $n$ is an even integer and odd if $n$ is an odd integer.</p>
MU123 Unit 3 NotesSun, 21 Feb 2021 00:00:00 +0000
https://ktsk.xyz/posts/mu123unit3/
https://ktsk.xyz/posts/mu123unit3/<h1 id="1naturalnumbers">1 Natural numbers</h1>
<p>Positive integers <code>1, 2, 3, 4...</code>
<a href="https://en.wikipedia.org/wiki/Natural_number">Some include zero, some not</a>.</p>
<h2 id="11multiples">1.1 Multiples</h2>
<p>A result of multiplying a natural number by natural number. E.g. multiples of 8 are $8, 16, 24, 32$</p>
<p>Thus multiples are numbers into which 8 divides exactly.</p>
<h3 id="commonmultiple">Common multiple</h3>
<p>is a multiple of all the numbers in question. Lowest common multiple (LCM) is the smallest number that is a multiple of numbers in question</p>
<h2 id="12factors">1.2 Factors</h2>
<p>A natural number that divides a number exactly into a second natural number, e.g. 2 is factor of 10.
Alternatively we can say 10 is divisible by 2.</p>
<p>Related to multiples since 2 is a factor of 10 is same as 10 is a multiple of 2.</p>
<p>All natural numbers > 1 have at least two factors  itself and 1.</p>
<p>Factors can be arranged into factor pairs  $1,10$; $2,5$.</p>
<blockquote>
<p><strong>Strategy to find factors of a number</strong></p>
<ul>
<li>Try 1,2,3,4... in turn. When factor is found, write it down with the other factor in the pair</li>
<li>Stop when you reach already found factor pair</li>
</ul>
</blockquote>
<h3 id="commonfactors">Common factors</h3>
<p>is a factor of all the numbers in question. The highest common factor (HCF) is the largest number that is a factor of numbers in question.</p>
<h2 id="13primenumbers">1.3 Prime numbers</h2>
<p>Natural numbers that have <strong>exactly</strong> two factors  1 and itself, e.g. $2, 3, 5, 7, 11, 13, \ldots$.</p>
<h3 id="sieveoferatosthenes">Sieve of Eratosthenes</h3>
<p>An algorithm for finding all the prime numbers up to a certain number.
<img src="https://upload.wikimedia.org/wikipedia/commons/b/b9/Sieve_of_Eratosthenes_animation.gif" alt="sieveofera" /></p>
<ul>
<li>Create a range of $2..n$ where $n$ is a certain number</li>
<li>Mark all the numbers that are multiples of 2 and are $>= 2^2$</li>
<li>Move to next unmarked number  3 and mark its multiples that are $>= 3^2$</li>
<li>...</li>
<li>All the unmarked numbers are primes</li>
</ul>
<p>Python impelementation <a href="https://www.geeksforgeeks.org/sieveoferatosthenes/">src</a>:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagepython" datalang="python"><span style="color:#cd74e8;">def </span><span style="color:#5cb3fa;">SieveOfEratosthenes</span><span style="color:#abb2bf;">(</span><span style="color:#eb6772;">n</span><span style="color:#abb2bf;">):
</span><span style="fontstyle:italic;color:#5f697a;"># Create a boolean array
# "prime[0..n]" and initialize
# all entries it as true.
# A value in prime[i] will
# finally be false if i is
# Not a prime, else true.
</span><span style="color:#abb2bf;">prime </span><span style="color:#adb7c9;">= </span><span style="color:#abb2bf;">[</span><span style="color:#db9d63;">True </span><span style="color:#cd74e8;">for </span><span style="color:#abb2bf;">i </span><span style="color:#cd74e8;">in </span><span style="color:#5ebfcc;">range</span><span style="color:#abb2bf;">(n</span><span style="color:#adb7c9;">+</span><span style="color:#db9d63;">1</span><span style="color:#abb2bf;">)]
p </span><span style="color:#adb7c9;">= </span><span style="color:#db9d63;">2
</span><span style="color:#cd74e8;">while </span><span style="color:#abb2bf;">(p </span><span style="color:#adb7c9;">* </span><span style="color:#abb2bf;">p </span><span style="color:#adb7c9;"><= </span><span style="color:#abb2bf;">n):
</span><span style="fontstyle:italic;color:#5f697a;"># If prime[p] is not
# changed, then it is a prime
</span><span style="color:#cd74e8;">if </span><span style="color:#abb2bf;">(prime[p] </span><span style="color:#adb7c9;">== </span><span style="color:#db9d63;">True</span><span style="color:#abb2bf;">):
</span><span style="fontstyle:italic;color:#5f697a;"># Update all multiples of p
</span><span style="color:#cd74e8;">for </span><span style="color:#abb2bf;">i </span><span style="color:#cd74e8;">in </span><span style="color:#5ebfcc;">range</span><span style="color:#abb2bf;">(p </span><span style="color:#adb7c9;">* </span><span style="color:#abb2bf;">p, n</span><span style="color:#adb7c9;">+</span><span style="color:#db9d63;">1</span><span style="color:#abb2bf;">, p):
prime[i] </span><span style="color:#adb7c9;">= </span><span style="color:#db9d63;">False
</span><span style="color:#abb2bf;">p </span><span style="color:#adb7c9;">+= </span><span style="color:#db9d63;">1
</span><span style="fontstyle:italic;color:#5f697a;"># Print all prime numbers
</span><span style="color:#cd74e8;">for </span><span style="color:#abb2bf;">p </span><span style="color:#cd74e8;">in </span><span style="color:#5ebfcc;">range</span><span style="color:#abb2bf;">(</span><span style="color:#db9d63;">2</span><span style="color:#abb2bf;">, n</span><span style="color:#adb7c9;">+</span><span style="color:#db9d63;">1</span><span style="color:#abb2bf;">):
</span><span style="color:#cd74e8;">if </span><span style="color:#abb2bf;">prime[p]:
</span><span style="color:#cd74e8;">print </span><span style="color:#abb2bf;">p,
</span></code></pre>
<p>Resources</p>
<ul>
<li><a href="https://www.geeksforgeeks.org/sieveoferatosthenes/">https://www.geeksforgeeks.org/sieveoferatosthenes/</a></li>
<li><a href="https://cpalgorithms.com/algebra/sieveoferatosthenes.html">https://cpalgorithms.com/algebra/sieveoferatosthenes.html</a></li>
<li><a href="https://www.baeldung.com/cs/sieveoferatosthenes">https://www.baeldung.com/cs/sieveoferatosthenes</a></li>
</ul>
<h3 id="mersenneprimes">Mersenne primes</h3>
<p>$$
2^n  1 ~\text{for natural number} ~n
$$
It can be proven that if $2^n  1$ is prime then $n$ must be a prime.</p>
<p>Resources</p>
<ul>
<li><a href="https://en.wikipedia.org/wiki/Mersenne_prime">https://en.wikipedia.org/wiki/Mersenne_prime</a></li>
<li><a href="https://www.mersenne.org/">https://www.mersenne.org/</a></li>
<li><a href="https://primes.utm.edu/mersenne/">https://primes.utm.edu/mersenne/</a></li>
</ul>
<h2 id="14primefactors">1.4 Prime factors</h2>
<p>A natural number > 1 that is not prime is called a <strong>composite number</strong>, e.g.: $4, 6, 8, 9, 10\ldots$.
A composite number can often be written as a product of even more factors forming a <strong>factor tree</strong>:</p>
<div class="mermaid isflex isjustifycontentcenter isalignitemscenter">graph TD;
two1((2))
two2((2))
two3((2))
three1((3))
three2((3))
five1((5))
360>20;
360>18;
20>4;
20>five1;
18>three1;
18>6;
4>two1;
4>two2;
6>two3;
6>three2;</div>
<p>Hence we can say $360 = 2^3 \times 3^2 \times 5$. All of the factors here are primes.</p>
<p>I could've started with different nodes, e.g. $360 = 10 \times 36$, but the result would've been the same.</p>
<p>The process of writing a natural number as a product of factors > 1 is called <strong>factorisation</strong>.</p>
<blockquote>
<p><strong>The fundamental theorem of arithmetic</strong></p>
<p>Every natural number > 1 can be written as product of prime numbers in <strong>just one way</strong>.</p>
</blockquote>
<p>The <strong>prime factorisation</strong> of a natural number is the product of prime factors that is equal to it, e.g.:
$$
2 = 2 \qquad 3 = 3 \qquad 4 = 2^2 \\
5 = 5 \qquad 6 = 2 \times 3 \qquad 7 = 7 \\
8 = 2^3 \qquad 9 = 3^2 \qquad 10 = 2 \times 5
$$</p>
<p>Because of the fundamental theorem of aithmetic we can say that prime numbers are the <strong>building blocks of natural numbers</strong>.</p>
<p>For prime factorisation it may be helpful to be systematic and follow:
$$
\text{the smallest possible prime} \times \text{a number}
$$
And iterate for each composite number in the factor tree, e.g.:</p>
<div class="mermaid isflex isjustifycontentcenter isalignitemscenter">graph TD;
two1((2))
two2((2))
three1((3))
three2((3))
seven1((5))
252>two1;
252>126;
126>two2;
126>63;
63>three1;
63>21;
21>three2;
21>seven1;</div>
<p>There's no other way to find prime factors of a number $n$ then trying all the primes < $n$.
So multiplying two large primes is a quick process but expensive to reverse.
This fact is a base to secure encryption systems.</p>
<h3 id="findinglcmandhcfusingprimefactors">Finding LCM and HCF using prime factors</h3>
<ul>
<li>Find the prime factorisation of the numbers.</li>
<li>To find the LCM, multiply together the highest ower of each prime factor occuring in any of the numbers.</li>
<li>To find the HCF, multiply together the lowest power of each prime factor common to all the numbers.</li>
</ul>
<h2 id="15powers">1.5 Powers</h2>
<h3 id="indexlaws">Index laws</h3>
<p>So far I've used these
$$
\begin{aligned}
a^m \times a^n &= a^{m+n} \qquad \frac{a^m}{a^n} = a^{mn} \\
(a^m)^n &= a^{mn} \\
(a \times b)^n &= a^n \times b^n \qquad (\frac{a}{b})^n = \frac{a^n}{b^n}
\end{aligned}
$$</p>
<h1 id="2rationalnumbers">2 Rational numbers</h1>
<p>Include natural numbers among others.</p>
<p>Is a number that can be written as a fraction of two integers: $\frac{integer}{integer}$.</p>
<p>Following numbers can be written in this form:</p>
<ul>
<li>Fraction as $\frac{3}{4}$</li>
<li>Mixed number as $5\frac{3}{4}$ since it can be converted to topheavy fraction: $\frac{23}{4}$</li>
<li>Whole number: $7 = \frac{7}{1}$</li>
<li>Decimal number with finite number of digits after decimal points: $0.42 = \frac{42}{100}$</li>
<li>Some decimal numbers with infinite numbers after decimal point: $0.333\ldots = \frac{1}{3}$</li>
<li>The negative of any above: $4 = \frac{4}{1}$</li>
</ul>
<h3 id="irrationalnumbers">Irrational numbers</h3>
<ul>
<li>$\pi$</li>
<li>$\sqrt{2}$</li>
</ul>
<h3 id="rationalnumbersasdecimals">Rational numbers as decimals</h3>
<p>Every rational number can be converted to decimal, e.g.: $\frac{5}{8} = 5 \div 8 = 0.625$
There are two possible outcomes of the division:</p>
<ul>
<li>decimal number with finite digits after d.p.  <strong>terminating decimal</strong>
<ul>
<li>$0.625$ is terminating</li>
</ul>
</li>
<li>decimal with block of indefinitely repeating digits after d.p  <strong>recurring decimal</strong>
<ul>
<li>$\frac{2}{3} = 0.6666\ldots$ is recurring</li>
<li>Can be denoted with $0.1\overline{23}$.</li>
</ul>
</li>
</ul>
<p><strong>Thus rational numbers can be redefined as</strong></p>
<blockquote>
<p>Decimal numbers that are terminating or recurring.</p>
</blockquote>
<p>I can convert terminating to fraction so I can prove first part of the statement but I can't prove the second yet.</p>
<h2 id="22addingandsubtractingfractions">2.2 Adding and subtracting fractions</h2>
<ul>
<li>Only when there's a same denominator  fractions are of a same type.</li>
<li>When there's different denominator  find common one (LCM).</li>
<li>Always simplify.</li>
</ul>
<h2 id="23multiplyinganddividingfractions">2.3 Multiplying and dividing fractions</h2>
<h3 id="multiplying">Multiplying</h3>
<ul>
<li>Multiply the numerators together and multiply the denominators together.</li>
</ul>
<h3 id="dividing">Dividing</h3>
<ul>
<li>Multiple the fraction by its reciprocal </li>
</ul>
<h4 id="reciprocal">Reciprocal</h4>
<p>A number and its reciprocal multiply together to give 1.
E.g.:
$0.25 ~\text{is rec of} ~4$,since $0.25 \times 4 = 1$
$\frac{3}{2} ~\text{is rec of} ~\frac{2}{3}$,since $\frac{3}{2} \times \frac{2}{3} = 1$</p>
<p>Alternatively, it is 1 divided by given number. </p>
<p>To find a reciprocal of fraction turn it upside down.
E.g.:
$\text{rec of}~\frac{3}{4}~\text{is}~\frac{4}{3}$</p>
<h2 id="24negativeindices">2.4 Negative indices</h2>
<p>The previous positive power of a number $n$ is equal to current positive power divided by $n$, e.g.:
$4^3 = \frac{4^4}{4}$</p>
<p>Thus $4^0$ has to be a number I get when dividing $\frac{4^1}{4} = 1$.
Similarly $4^{1}$ has to be a number I get when dividing $\frac{4^0}{4} = \frac{1}{4}$.</p>
<p>We can build whole scale of the pattern</p>
<table><thead><tr><th>$4^{3}$</th><th>$4^{2}$</th><th>$4^{1}$</th><th>$4^0$</th><th>$4^1$</th><th>$4^2$</th><th>$4^3$</th></tr></thead><tbody>
<tr><td>$\frac{1}{4^3}$</td><td>$\frac{1}{4^2}$</td><td>$\frac{1}{4}$</td><td>$1$</td><td>$4$</td><td>$16$</td><td>$64$</td></tr>
</tbody></table>
<p>The meaning of negative and zero indices works with all the index laws I've seen so far.</p>
<p>Index laws can be expand by following rules based on previous observations:</p>
<ul>
<li>A nonzero number raised to the power zero is 1:
$$
a^0 = 1
$$</li>
<li>A nonzero number raised to a negative power is the reciprocal of the number raised to the corresponding positive power:
$$
a^{n  1} = \frac{1}{a^n}
$$</li>
</ul>
<p>Interestingly:
$$
a^{1} = \frac{1}{a}
$$
Hence, raising a number to the power of $1$ is the same as finding its reciprocal.</p>
<p>E.g.:
$$
(\frac{2}{3})^{1} = 1 \times \frac{3}{2} = \frac{3}{2}
$$</p>
<h2 id="25scientificnotation">2.5 Scientific notation</h2>
<ul>
<li>Also called <strong>standard form</strong>.</li>
<li>A number between 1 and 10 (excluded) multiplied by a power of 10.</li>
</ul>
<h1 id="3irrationalnumbersandrealnumbers">3 Irrational numbers and real numbers</h1>
<h2 id="31whatisanirrationalnumber">3.1 What is an irrational number?</h2>
<p>Decimals with infinite number of digits afterthe decimal point but no repeating block of digits.</p>
<p>Following number is not terminating nor recurring:
$$
0.010,010,001,000,010,000,01\ldots
$$</p>
<p><em>TODO: What if the repeating block is just really big?</em></p>
<p>Here $x$ is not rational:</p>
<p>$$
x^2 = 2 \\
\sqrt{2} = x
$$</p>
<hr />
<p>The fact that $\sqrt{2}$ is irrational can be proven by <strong>contradiction</strong> followingly.</p>
<p>Suppose there's a rational number whose square is $2$. Hence it can be written as
$$
\frac{\text{integer}}{\text{integer}}
$$
Consider it being cancelled down to the simplest form as:
$$
\frac{m}{n}
$$
So $m$ and $n$ don't have any common factor.
The square of $\frac{m}{n}$ is 2, so:
$$
(\frac{m}{n})^2 = 2 \\
\frac{m^2}{n^2} = 2
$$
It follow that
$$
\frac{m^2}{n^2} \times n^2 = 2 \times n^2 \\
m^2 = 2n^2
$$
$2n^2$ has to be even since it's a product of 2 and whole number. Meaning $m^2$ has to be even too, that means $m$ has to be even as well.
That means that $m = 2r$ for some integer $r$.
When substituting to the original equation we get:
$$
(2r)^2 = 2n^2 \\
4r^2 = 2n^2 \\
$$
It follow that
$$
\frac{4r^2}{2} = \frac{2n^2}{2} \\
2r^2 = n^2
$$</p>
<p>The integer $n^2$ is even hence $n$ has to be even too.
So both $m$ and $n$ are even. But that's <strong>impossible</strong> since $m$ and $n$ don't have any common factor.</p>
<hr />
<p>The irrational numbers together with the rational numbers form the <strong>real numbers</strong>.</p>
<p>I can think about various categories of numbers as layers:</p>
<pre style="backgroundcolor:#2b303b;">
<code><span style="color:#abb2bf;">Real(
Irrational,
Rational(
Integers(
Natural
)
)
)
</span></code></pre>
<p>plus complex, that will come later on.</p>
<h2 id="32rootsofnumbers">3.2 Roots of numbers</h2>
<p>A number that when multiplied by itself gives the original number.
Every positive number has two square roots  a positive one and a negative one.</p>
<p>Square roots of two numbers can be used to find the square root of the product or a quotient.</p>
<p>For example, numbers 16 and 49 have square roots of 4 and 7.
I can apply index law $(a \times b)^n = a^n \times b^n$ to those:
$$
(4 \times 7)^2 = 4^2 \times 7^2 \\
(4 \times 7)^2 = 16 \times 49
$$
That implies:
$$
\sqrt{16 \times 49} = \sqrt{16} \times \sqrt{49}
$$</p>
<p>This can be generalized into following laws:
$$
\sqrt{a \times b} = \sqrt{a} \times \sqrt{b} \qquad \sqrt{\frac{a}{b}} = \frac{\sqrt{a}}{\sqrt{b}}
$$</p>
<p>Obviously, these laws apply to any root.</p>
<h2 id="33surds">3.3 Surds</h2>
<p>Numbers that are not perfect square have irrational roots. Hence following roots are irrational:
$$
\sqrt{7}, \sqrt{8}, \sqrt{10}, \sqrt{11}
$$
Since such number can be only approximated as a decimal it should be left as is in calculations, e.g.:
$$
x = 2 \times \sqrt{5}
$$
such expressions are called <strong>surds</strong>  it contains one or more irrational roots of numbers.
Surds are usually written concisely as formulas, number before surd when multiplied:
$$
y = 2\sqrt{5}
$$
In the simplest form:
$$
\sqrt{12} = \sqrt{4 \times 3} = \sqrt{4} \times \sqrt{3} = 2\sqrt{3}
$$
This is obviously possible when some of a numbers under the root are perfect squares. Thus the goal when simplifying is to find some perfect square multiplied some other number giving the original number bellow the root.</p>
<h3 id="multiplyingroots">Multiplying roots</h3>
<ul>
<li>Multiply numbers together</li>
<li>Multiply roots together</li>
<li>Simplify the root</li>
</ul>
<h3 id="dividingroots">Dividing roots</h3>
<p>Use following laws
$$
\sqrt{a \times b} = \sqrt{a} \times \sqrt{b} \qquad \sqrt{\frac{a}{b}} = \frac{\sqrt{a}}{\sqrt{b}}
$$</p>
<p>Sometimes, I should expand an integer to a multiplication of surds in order to simplify the quotient:
$$
\frac{2}{\sqrt{2}} = \frac{\sqrt{2} \times \sqrt{2}}{\sqrt{2}} = \frac{1 \times \sqrt{2}}{1} = \sqrt{2}
$$</p>
<h3 id="addingandsubstractingroots">Adding and substracting roots</h3>
<p>It's usually not possible to add or substract different roots, thus
$$
\sqrt{a} + \sqrt{b} \not= \sqrt{a + b}
$$</p>
<p>I can only add or substract roots that are the same.</p>
<blockquote>
<p><strong>To simplify surds</strong></p>
<ul>
<li>Simplify roots of integers with square factors.</li>
<li>Simplify products and quotients of roots.</li>
<li>Add or subtract roots that are the same.</li>
</ul>
</blockquote>
<h2 id="34fractionalindices">3.4 Fractional indices</h2>
<p>Index laws can be applied to fractional indices too, e.g. let's consider the power $5^\frac{1}{2}$</p>
<p>By applying
$$
a^m \times a^n = a ^{m + n}
$$
I get
$$
5^\frac{1}{2} \times 5^\frac{1}{2} = 5^{\frac{1}{2} + \frac{1}{2}} = 5^1 = 5
$$
Hence
$$
5^\frac{1}{2} = \sqrt{5}
$$</p>
<p>It can be generalized in the following index law
$$
a^\frac{1}{n} = \sqrt[n]{a}
$$</p>
<p>This rule toegher with other index laws can be used to give a meaning to any fractional index.</p>
<p>E.g. in combination with
$$
(a^m)^n = a^{mn}
$$</p>
<p>I can do following operation
$$
5^\frac{4}{3} = 5^{\frac{1}{3} \times 4} = (5^{\frac{1}{3}})^4 = (\sqrt[3]{5})^4
$$</p>
<p>This combination can be generalized to yet another index law
$$
a^\frac{m}{n} = (\sqrt[n]{a})^m
$$</p>
<p>Interestingly the square root laws I saw before:
$$
\sqrt{a \times b} = \sqrt{a} \times \sqrt{b} \qquad \sqrt{\frac{a}{b}} = \frac{\sqrt{a}}{\sqrt{b}}
$$
Can be deduced by applying $n = \frac{1}{2}$ to following index laws:
$$
(a \times b)^n = a^n \times b^n \qquad (\frac{a}{b})^n = \frac{a^n}{b^n}
$$</p>
<blockquote>
<p>Irrational indices are also valid but I will encounter those later on.</p>
</blockquote>
<h1 id="4ratios">4 Ratios</h1>
<h2 id="41whatisaratio">4.1 What is a ratio?</h2>
<p>Comparition of multiple ordered quantities, e.g.: $3:5 ~ 2:10:7$</p>
<p>Sometimes it's useful to convert a ratio to a $number:1$ form to e.g.</p>
<ul>
<li>Compare multiple ratios.</li>
<li>Find approximate ratios.
To reach such a form I can divide both numbers by second number, e.g.:
$$
7 : 11 = \frac{7}{11} : \frac{11}{11} = 0.636 : 1 ~\text{(3 d.p.)}
$$</li>
</ul>
How I hiked GR20 through the mountains of CorsicaSat, 10 Oct 2020 00:00:00 +0000
https://ktsk.xyz/posts/hikinggr20/
https://ktsk.xyz/posts/hikinggr20/<h1 id="day0arrival">Day 0  Arrival</h1>
<p><img src="https://live.staticflickr.com/65535/50329726063_2ae5b97922_c.jpg" alt="d0" /></p>
<p>My plane landed at the <a href="https://en.mapy.cz/s/jecazulapa">Calvi</a>  a rather rural airport; there were herds of goats and small fields everywhere. Horizon was filled with mountains; thick clouds were forming over them. It was hot and damp in a very tropical way.</p>
<p>I got some money out of ATM and unwrapped a massively wrapped backpack; the scrap plastic was like a football.</p>
<p><img src="https://live.staticflickr.com/65535/50330572627_30f7faa5a9_c.jpg" alt="img" /></p>
<p>Took a short cab ride to a camp in <a href="https://en.mapy.cz/s/gurahosude">Calenzana</a>, the starting town of GR20.
There were tens of hikers preparing or finishing their own hikes. GR20 is rather a popular trail.</p>
<p>I settled in, pitched my tent, had chats with others, mostly about gear.</p>
<p>Later, I brushed my teeth with a pimpedup halftoothbrush and superconcentrated outdoor paste.
After that, I threw the paste into the tent to deal with it later.
Then more chats with fellow hikers, but my eyes started to close.
So I sat into the tent to organize my stuff before sleep.
Suddenly there was a fire ... on my ass? I got up just to find I sat to the most concentrated toothpaste, which I smudged everywhere. It was all over my only one pair of shorts, an expensive cubenfiber tent floor...</p>
<p>Fortunately, the tent seemed ok; 30mins in shover sorted out the shots. The ass was still burning, though.
It was like 30*C outside, and as a true ultra lighter, I didn't even have any spare underwear, just those shorts (with liner). So I got to sleep halfnaked.</p>
<p>A big thunderstorm awoke the whole camp at 2 A.M. It got me up sometime before; I was listening to this rumbling over the sea with a massive soundstage slowly closing on the land.
Flashes of lightning blink every second; it rained like crazy. There were streams of water forming below me.
There was solid condensation on my tent's walls given it was damp even before the storm and I was all wet from my toothpaste party. And in combination with raindrops bashing the tent on the outside, it created rain on the inside too.</p>
<h1 id="day1calenzanarefugedecarozzu1988km2300mup1298mdown">Day 1  Calenzana > Refuge de Carozzu  19.88 km; 2,300m up; 1,298m down</h1>
<iframe height='405' width='590' frameborder='0' allowtransparency='true' scrolling='no' src='https://www.strava.com/activities/3997444075/embed/f7685261e7efdee4fe833e1c16c78dbc157da113'></iframe>
<p><img src="https://live.staticflickr.com/65535/50330573247_6460537b29_c.jpg" alt="img" /></p>
<p>Storm got over us around 7 A.M. Obviously, I didn't sleep much. Slowly packed the stuff; everything I had was wet. There was mud inside of my shoes.</p>
<p>At 9, after some wasted efforts to dry out the gear, I finally started walking... To the shop.
But after that, I found myself at the official start. Plenty of people starting, everyone was, of course, taking photos. But after this ritual, we quickly broke up, and I got some alonetime.</p>
<p>It was windy.
<img src="https://live.staticflickr.com/65535/50330574057_e3c6982e2e_c.jpg" alt="img" /></p>
<p>Locally rainy.
<img src="https://live.staticflickr.com/65535/50330573572_ec9948de29_c.jpg" alt="img" /></p>
<p>The trail constantly went uphill, had to climb around 1600m to the first refuge.
During the morning, the weather improved
<img src="https://live.staticflickr.com/65535/50330573792_d579ea7690_c.jpg" alt="img" /></p>
<p>And clouds gave space to views
<img src="https://live.staticflickr.com/65535/50330574752_2b1040520c_c.jpg" alt="img" /></p>
<p>Around lunchtime, I arrived at <a href="https://en.mapy.cz/s/popevejaje">Refuge de l'Ortu di u Piobbu</a>, got Coke with some muesli to the system and started to think about what next. Other hikers were already pitching their tents  way too early. I asked the hut manager what the next stage was like; he didn't understand much, had to use hands and some other hiker. I think the answer was: more or less the same as the previous one.</p>
<p><img src="https://live.staticflickr.com/65535/50330402281_c6aa9a4118_c.jpg" alt="img" /></p>
<p>I didn't believe that, it seemed like a short climb to saddle and a bit of a fall to the next hut from the map. So I drank 1.5l of water from the spring and got up the hill.</p>
<p>The trail indeed started with the climb to the saddle.
<img src="https://live.staticflickr.com/65535/50329730533_112fbcfc04_c.jpg" alt="img" /></p>
<p>However, then it continued with a long, technical ridge walk with endless ups and downs.
<img src="https://live.staticflickr.com/65535/50329731218_e8645ddab4_c.jpg" alt="img" /></p>
<p>With some loose rocks and scrambling.
<img src="https://live.staticflickr.com/65535/50329731963_6369942e3f_c.jpg" alt="img" />
Somewhere around here, I met this older guy with a much younger couple. I guessed maybe father taking kids on hike or uncle. So I dabbed them Uncle and the Kids(TM). They hiked at my pace. I got to talk with the uncle but the kids didn't speak a word in English, and they mostly ignored me. Found out they aren't related, just random people on the trail.</p>
<p>In one of those more technical sections, we met another guy who looked like he's gonna have a total breakdown every second. He was just standing there, kept telling us he's ok but refused to move. We didn't know what to do, so we left him there.
<img src="https://live.staticflickr.com/65535/50330405141_37427f1975_c.jpg" alt="img" /></p>
<p>The hike down out of the ridge was very long, steep, and energytaking  a lot of loose rocks with scrambling sections. Down in the valley, streams started to pop up; I filtered some, uncle just leaned over and drank it directly.
<img src="https://live.staticflickr.com/65535/50330405496_c983baf5b4_c.jpg" alt="img" /></p>
<p>We arrived at the refuge rather exhausted, first thing first  beer.
Uncle and the Kids didn't have a tent nor any booking; the hut manager looked like he's gonna send them out to the wild. Then he told me there's only one spot left for my little tent  next to the trash bins.</p>
<p>Then usual rituals, I cooked on the alcohol stove for the first time; really hoped I won't burn the place to the ground.</p>
<h1 id="day2refugedecarozzuascu501km816mup668mdown">Day 2  Refuge de Carozzu > Ascu  5.01km; 816m up; 668m down</h1>
<iframe height='405' width='590' frameborder='0' allowtransparency='true' scrolling='no' src='https://www.strava.com/activities/3997455202/embed/7a1082315cee05ef15f95f9033073b437d37870c'></iframe>
<p>I got up in the middle of the night, and I was freezing. Found out my mattress was totally deflated, so I inflated it, got to sleep ... and this repeated 3 more times. So I got a puncture probably even before the first night on the trail. Plus, a second night without good sleep and counting.</p>
<p><img src="https://live.staticflickr.com/65535/50329731588_e698ced49c_c.jpg" alt="img" /></p>
<p>In the morning I got somehow going but obviously didn't feel well; the plan was to get to the next refuge, sort out the mat, get sleep and be good & happy. And that's really an overthehill hike.</p>
<p>As I approached the saddle, it got cold, and I had to take the long sleeve for the first (and last) time. There was thick mist on the other side of the ridge; visibility was to the nearest rock.
So I was just mindlessly dropping down... through the technical terrain thus I broke my knee. Some blood was pumping out; I rubbed it off with Buff every couple of minutes.</p>
<p>At 2 (P.M.) I reached <a href="https://en.mapy.cz/s/dudapetopa">Asco</a>, broke gypsystyle camp, just to dry out everything in the sun.
Met the Uncle and the Kids, they, of course, continued. Wished them luck; I had a mat to fix.
The only problem was I didn't have a repair kit, but at first, I had to find the puncture.
Tried to put it into the brook, but the water was too restless.</p>
<p>At the Thermarest site, I read the best approach is to smudge the mat with soup water.
Damn, who they think I am, some sort of Hollywood supermodel? I didn't have such an item in my inventory.
So I went around the camp asking for soup, got one, smudged the hell out of it but didn't find the puncture.
What now? I didn't want to go shopping for a mat in the city. I bought a beer instead, then a second one.
Then I invented this sort of a nest, pulled out padded back from the backpack, got together all the clothes (packed, not naked this time) I had, placed it bellow the mat. With an experiment, I figured ~2hrs of good sleep on nest + mat and Nhrs of bad sleep in the bare nest, hopefully limiting reinflate operations during the night. That could work.</p>
<p>I still felt quite out of my skin. Also, I had really high resting HR, around 100BPM, essentially the same as when walking.</p>
<p>Later I simply hung out and had some chats with fellow hikers.
Cooked some meal, left packed stove in the vestibule of the tent, and fell asleep.</p>
<h1 id="day3192020ascucasteldevergio2351km2021mup1298m">Day 3  1.9. 2020  Ascu > Castel de Vergio  23.51 km; 2,021m up; 1,298m</h1>
<iframe height='405' width='590' frameborder='0' allowtransparency='true' scrolling='no' src='https://www.strava.com/activities/3997492271/embed/c781ac26142e5109136dd0d5a4d72cc28dc10c06'></iframe>
<p>It was around 3:30 when the cold awoke me, it means the nest was working, but the cold was still bitter as well as fragmented sleep. HR was at 100BPM. I inflated the mat and fell asleep.</p>
<p>I got awake again at 4:30, this time not because of the mat. There was an attack on my tent. I heard this quick, sneaky sound followed by a sad jingle of my stove moving away. So probably a fox took it away, but why? I cleaned it precisely after lunch. Suddenly I remembered I kept a pack of outdoor coffee stuffed in it, and the fox was probably up to some caffeine.
That was like the last bit for me; I was lying there, in the nest, relatively exhausted, thinking if I should pack my stuff and go sit on some beach instead of this chain of failures. Well, anyway, I got up to chase the thief.
After a bit of uphill walk in the bushes, I found the stove! The stuff sack was on pieces; there was just a single bite in the coffee. It wasn't good enough or what?</p>
<p>So I cleaned up the mess, got back to nest but wasn't able to fall asleep; this was my very bottom of the whole trail. I wanted to give up.</p>
<p>Somewhat mechanically, I packed the gear and hit the trail as usual. I thought, screw it, what other disaster can possibly happen.
This stage was no joke though, there was a climb to the ridges of Mt. Cinto, the highest peak of Corsica, ahead of me. Basically 1188m of ascent in one go. HR was, of course, at 100BPM.</p>
<iframe style="border:none" src="https://en.frame.mapy.cz/s/jorojenuru" width="400" height="280" frameborder="0"></iframe>
<p>So I put some music in my ears and got going. Sun was shining behind the ridge. The air was crisp and crystal clear  the promise of a nice day in the mountains.</p>
<p><img src="https://live.staticflickr.com/65535/50330579892_0ee75b6029_c.jpg" alt="img" /></p>
<p>The landscape was pleasantly mountainous, sparkled with Mediterrane vegetation here and there.
<img src="https://live.staticflickr.com/65535/50330406826_086efc3e77_c.jpg" alt="img" /></p>
<p>At this point, I started to feel like I'm in the best place I could possibly be and started to fully enjoy the hike. Very opposite of how I felt just a couple of hours before.
<img src="https://live.staticflickr.com/65535/50330581152_bed440396d_c.jpg" alt="img" /></p>
<p>Got in a serious flow, flew up the hill like nothing (well, I felt like that).
<img src="https://live.staticflickr.com/65535/50330581547_1935208abe_c.jpg" alt="img" /></p>
<p>On the top, I hung out a bit and continued with quite a technical scramble on the ridge.
<img src="https://live.staticflickr.com/65535/50330582072_965805f5b1_c.jpg" alt="img" /></p>
<p>Then free fall through a massive slope of loose scree.
<img src="https://live.staticflickr.com/65535/50330582902_3f37d9fa91_c.jpg" alt="img" /></p>
<p>When I was getting ahead of one colleague, I told him I don't feel comfortable on those loose rocks after my recent armbraking incident.</p>
<p>Later we met this group of guys racing downhill against each other, and again I was like screw it and joined them. We mostly ran, and I totally forgot about what I was saying a couple of moments ago.</p>
<p><img src="https://live.staticflickr.com/65535/50330583317_647b798b9d_c.jpg" alt="img" /></p>
<p>Down in the valley, we had to scramble all the time.
<img src="https://live.staticflickr.com/65535/50330583702_3664e94939_c.jpg" alt="img" /></p>
<p>I only had tiny moments to decide which limb goes where. Really enjoyed this livinginthepresent sensation brought by it.
<img src="https://live.staticflickr.com/65535/50330583702_3664e94939_c.jpg" alt="img" /></p>
<p>And I finished first. Had to cool down my legs in a lagoon.
<img src="https://live.staticflickr.com/65535/50330410116_f22f4750de_c.jpg" alt="img" /></p>
<p>I ate lunch of champions on the <a href="https://en.mapy.cz/s/fadujuvose">first refuge</a> in the valley.
<img src="https://live.staticflickr.com/65535/50329737458_3e2aa96435_c.jpg" alt="img" /></p>
<p>On <a href="https://en.mapy.cz/s/kovacalare">the second</a>, I bought 400g of cheese, on both combined I drank 3l of water, the sun was starting to show its power.</p>
<p>The plan was to get over one more ridge and combine two official stages.
First, it was an easy flat walk, but then the climb began. The sun was burning everything around. Other hikers were climbing up too. I often caught up with some of them; usually, they were pretty polite and wanted to let me go ahead. But that's like an obligation to move faster and lose them a bit together with remaining energy.</p>
<p>At least clouds were pushing from the other side of the ridge.
<img src="https://live.staticflickr.com/65535/50329737768_1a26509b46_c.jpg" alt="img" /></p>
<p>The way slowly fell down into this amazing remote valley.
<img src="https://live.staticflickr.com/65535/50330585272_257703f57e_c.jpg" alt="img" /></p>
<p>Down.
<img src="https://live.staticflickr.com/65535/50330585817_8f4d6ea650_c.jpg" alt="img" /></p>
<p>To the Forrest.
<img src="https://live.staticflickr.com/65535/50330586252_3994af4feb_c.jpg" alt="img" /></p>
<p>Where I broke a pole in between some roots like nothing. Damn these ultralight tinfoils...
I needed at least one pole to pitch the tent, and by this experiment, I figured it's not very hard to break one. So I decided to carry a broken one for spare parts, like an antenna on the backpack.</p>
<p>However, it made me realized that I was exhausted, didn't sleep properly for god knows how long, and just hiked over the most demanding section of GR20. I sat down and ate the whole cheese I bought before, simply like that, without anything else. Suddenly the walk went much better.</p>
<p>I arrived very much wretched to the refuge but with a feeling of a day fully lived through. Falling asleep was a matter of seconds; the nest wasn't a problem this time.</p>
<h1 id="day4292020casteldevergiopetrapiana2632km1577mup1140m">Day 4  2.9. 2020  Castel de Vergio > Petra Piana  26.32 km; 1,577m up; 1,140m</h1>
<iframe height='405' width='590' frameborder='0' allowtransparency='true' scrolling='no' src='https://www.strava.com/activities/4001619813/embed/42439deb5b83108789358cec1d922ed9169aebd7'></iframe>
<p>I had to reinflate only two times over the night. But still, I desperately needed to improve my quality of sleep. And for that, I hatched a plan  on the next refuge, I will try to panhandle some of their spare mats. For this purpose, my amazing girlfriend sent me a manual full of french phrases including "I broke my matters, can I borrow one of yours?".</p>
<p>Today it all started with a grassy, mushy landscape; it was so restorative against beaten feet.
<img src="https://live.staticflickr.com/65535/50329740243_b248c42e34_c.jpg" alt="img" /></p>
<p>It looked like from Lord of the Rings dashed with a bit of Death Stranding.
<img src="https://live.staticflickr.com/65535/50329740588_644b7fab41_c.jpg" alt="img" /></p>
<p>So I put on its soundtrack and felt like Sam Porter Bridges. My load of 7kg felt a bit pathetic, though.
<img src="https://live.staticflickr.com/65535/50330587642_8cee07ae78_c.jpg" alt="img" /></p>
<p>I had lunch at the refuge Manganu  coke and a piece of chocolate. Checked the weather with hut manager, all good, so I had no excuse to continue.
<img src="https://live.staticflickr.com/65535/50330588532_9d186af062_c.jpg" alt="img" /></p>
<p><img src="https://live.staticflickr.com/65535/50329742238_2c9d01fe88_c.jpg" alt="img" /></p>
<p>This stage was amazing but tough. You basically scramble around glacial lakes 500m above them, all very airy. I got together with two guys here, french; hence we talked with hands. But we were a good team, like some elite hiking unit flying over the trail. And the trail was beautifully demanding, climbing sections everywhere, moraine fields...</p>
<p><img src="https://live.staticflickr.com/65535/50330589387_dce43a492f_c.jpg" alt="img" /></p>
<p>Broke the other knee here, cured it with buff again.</p>
<p>When we arrived at the refuge, I interestingly felt quite good. Went to the hut manager to try to borrow the mat, and it went the followingly:</p>
<ul>
<li>"Hi, sorry I don't speak French, is English ok?"</li>
<li>"Meh."</li>
<li>"Can I pitch my tent in here?"</li>
<li>"You want to rent a tent?"</li>
<li>"No, I have my tent," I point to myself.</li>
<li>"Ok, 8E."</li>
<li>"And can I ask you, I punctured my mattress, would it be possible to borrow one of yours?"</li>
<li>"You broke your tent?"</li>
<li>"No, my mattress was broken" I showed cross with my hands.</li>
<li>"Eh?"</li>
<li>"My tapi de mus broken," I showed the manual my girlfriend sent me.</li>
<li>"Oh, your tapidemu, no problem, see that guy? Ask him."</li>
</ul>
<p>So I had to repeat the same conversation, but in the end, I got a mat! Hooray.</p>
<p>I also picked a convenient spot to pitch a tent near this big rock I called workbench; in a minute, my whole backpack exploded there.
<img src="https://live.staticflickr.com/65535/50329747273_a92aacd46d_c.jpg" alt="img" /></p>
<p>Since we had a new month, I washed my self and some of the clothes.</p>
<p>And again I fell asleep totally exhausted & happy.</p>
<h1 id="day5392020petrapianavizzavona1815km1058mup1979m">Day 5  3.9. 2020  Petra Piana > Vizzavona  18.15 km; 1,058m up; 1,979m</h1>
<iframe height='405' width='590' frameborder='0' allowtransparency='true' scrolling='no' src='https://www.strava.com/activities/4022470711/embed/9bc7d582f0701c3253576153782fb7d6f5efe6e8'></iframe>
<p>It got freezing in the night, but I regenerated much better on a real mat than a nest. I was ready to go at 8:30. Actually, that's my superpower here; I'm usually glad when I start cooking sometime after 7.</p>
<p>Today, it all started with nice ridge walk; sometimes, there was a bit of scramble but nothing serious as yesterday. It reminded me of Carpathians.
<img src="https://live.staticflickr.com/65535/50330594687_a80ed1a641_c.jpg" alt="img" /></p>
<p>Had lunch above the refuge <a href="https://en.mapy.cz/s/poperosobo">Onda</a>  snickers followed by another big climb in the prime sun. Which made me soo slow and dizzy. I got to the saddle like a winner just to realize I had to fall 1000m down to the town of Vizzavona.
<img src="https://live.staticflickr.com/65535/50329749043_c1a6479c08_c.jpg" alt="img" /></p>
<p><img src="https://live.staticflickr.com/65535/50330597037_b300dcbe2c_c.jpg" alt="img" /></p>
<p>Originally I didn't even want to stop there and go to the next stage right away. However, there was gossip going on on the trail that they cook pizza down there.
So in the town, I indeed got pizza (and some beers, of course), had some chats with fellow hikers. And started planning how much time it'll get to finish the whole trail. I estimated 4 more days.
Vizzavona divides the northern part of GR20 I just did and the southern part. Which is supposed to be less technical and more walkable.
<img src="https://live.staticflickr.com/65535/50329751083_0155e76c33_c.jpg" alt="img" /></p>
<h1 id="day6492020vizzavonarefugedeprati3484km2064mup1172mdown">Day 6  4.9. 2020  Vizzavona > Refuge de Prati  34.84km; 2,064m up; 1,172m down</h1>
<iframe height='405' width='590' frameborder='0' allowtransparency='true' scrolling='no' src='https://www.strava.com/activities/4022496565/embed/ca00f13cd46acfdb493de4d8fc52b54b98ddf1c8'></iframe>
<p>Today was indeed a fast day. It all started with 1000m of a very gentle climb on dirt roads through forests. Around lunchtime, I arrived at a <a href="https://en.mapy.cz/s/damonacobu">refuge</a>; had coke & omelet. There were some Czech guys, so I had an opportunity to chat in my native language. They had huge ~20kg backpacks; I wished them my condolences and got going.
<img src="https://live.staticflickr.com/65535/50330424596_5f001e3fe1_c.jpg" alt="img" /></p>
<p>Then I met the uncle from the uncle and the kids' team, but he lost the kids. We exchanged trail stories and split after a while but agreed on the common refuge (and beer) of the day.
<img src="https://live.staticflickr.com/65535/50330600687_26ec89d073_c.jpg" alt="img" /></p>
<p><img src="https://live.staticflickr.com/65535/50329756138_7a1a04e2c3_c.jpg" alt="img" /></p>
<p>Next, I had an opportunity to enjoy a flat walk before the final climb to a ridge.
Suddenly, the mountains were different; everything was more open, grassy with big white rocks here and there. Lord of the Rings: chapter 2?
<img src="https://live.staticflickr.com/65535/50330605527_b61f020eb9_c.jpg" alt="img" /></p>
<p>When I arrived to <a href="https://en.mapy.cz/s/besalumese">refuge</a>, it got even better. It was on top of a high plateau, with those new, fresh and romantic mountains all around, fluffy clouds flitted around peaks. Golden hour was about to start. And there was a panoramic view of a see 2km below us. It took my breath away.
<img src="https://live.staticflickr.com/65535/50330434386_99ca58deee_c.jpg" alt="img" /></p>
<p>Had a nice chat with the hut manager; borrowing a mat was an easy job.
<img src="https://live.staticflickr.com/65535/50330608567_769de6d28e_c.jpg" alt="img" /></p>
<p>I cooked the dinner almost as a native french man:
<img src="https://live.staticflickr.com/65535/50330607562_274c58e208_c.jpg" alt="img" /></p>
<p>Then some beers and chats followed by sleep in a million stars hotel.</p>
<h1 id="day7592020refugedepratirefugedasinau2895km1935mup2140mdown">Day 7  5.9. 2020  Refuge de Prati > Refuge d'Asinau  28.95km; 1,935m up; 2,140m down</h1>
<iframe height='405' width='590' frameborder='0' allowtransparency='true' scrolling='no' src='https://www.strava.com/activities/4022520158/embed/1b0efe626d7f5d3a6aaa28f27a5386b644170b08'></iframe>
<p>I had such a late start that even the staff had already cleaned everything and were merely chilling around.
The trail was playing with me this time, it was running just below the ridge, but I had to constantly switch sides of it. Sometimes there was a nice solid trail, sometimes serious scrambling.
<img src="https://live.staticflickr.com/65535/50330609502_01f2db86c4_c.jpg" alt="img" /></p>
<p>Sun wasn't that hard on me (yet). I was genuinely enjoying it.
Around noon I met the uncle, and together we've slowly moved to the next <a href="https://en.mapy.cz/s/pomobudumu">refuge</a> while dreaming what to order for lunch. When we got there, we found out that, actually, the hut manager had lunch. Thus he was closed for business. So we sat down, ate some of our provisions, and patiently waited.
<img src="https://live.staticflickr.com/65535/50330442856_059be62fb7_c.jpg" alt="img" /></p>
<p>With some more hikers, we started to plan what next. There were two variants ahead of us. One was direct, but 20km through a long valley followed by a big hill to the next refuge, marked as a daylong demanding hike in the guide.</p>
<p>The second one went rather around over a couple of intermediate refuges and was supposed to be easy. Others wanted to take it easy; I sought risks, pain and destruction, so I pushed them for the first one. Well, in the end, I went alone.</p>
<p><img src="https://live.staticflickr.com/65535/50330612307_21d6118363_c.jpg" alt="img" /></p>
<p>Before dropping to the valley, there was an extra ridge ahead of me, seemed short on the map. In reality, it was a technical and tedious scramble under the scorching sun.</p>
<p>The sun started to be a real problem down in the south. There was no wind; the rocks were all white; hence it acted as a reflector. Mirages everywhere around.</p>
<p>But in the end, the ridge spilled me out
<img src="https://live.staticflickr.com/65535/50330618717_1e616a28bc_c.jpg" alt="img" /></p>
<p>Suddenly, I found myself walking through very different terrain again. This time it was a steppe; Now I was a cowboy from some western. Completely alone in this wild, dusty landscape with exotic plants all around. There have been so many dramatic scenery changes on this hike, I wasn't able to believe I went through yet another one.
<img src="https://live.staticflickr.com/65535/50330445746_3a21fe6853_c.jpg" alt="img" /></p>
<p>After the steppe, I had to climb that big hill.
<img src="https://live.staticflickr.com/65535/50330447131_e53f942f6d_c.jpg" alt="img" /></p>
<p>It was that kind with 5 false peaks before the true one.
<img src="https://live.staticflickr.com/65535/50330621057_e917e3d7d6_c.jpg" alt="img" /></p>
<p>And whenever you triumphantly reach one of those, the next one pops behind.
<img src="https://live.staticflickr.com/65535/50330448926_4d798b0c45_c.jpg" alt="img" /></p>
<p>I enjoyed the silence on the top, then had to fall steeply down to the next refuge on the other side of the hill.
<img src="https://live.staticflickr.com/65535/50330623922_0fd634288a_c.jpg" alt="img" /></p>
<p>Constant scrambling on tired legs in the approaching dark.</p>
<p>I started to dislike the refuge almost instantly; it seemed like the fact that I was close to civilization had something to do with it.
There were fresh, clean people that tended to not say hi and overall be smug. At least in my head.
On top of that, there was basically no place to pitch a tent. After some struggle and checking with various managers, I had to take a bed in a dormitory with many other people.
Didn't imagine my last night on the trail to be like that. Especially after a heavenly experience the day before.
It was hot, sweaty during the night, sometimes someone farted, the guy next to me slept on plastic covers, so I could hear every move...</p>
<h1 id="day8692020refugedasinauconca3048km1133mup2378mdown">Day 8  6.9. 2020  Refuge d'Asinau > Conca  30.48km; 1,133m up; 2,378m down</h1>
<iframe height='405' width='590' frameborder='0' allowtransparency='true' scrolling='no' src='https://www.strava.com/activities/4022543592/embed/3a26981684c0deb31ed973c43ce2c177f95a7d64'></iframe>
<p>Last day on the trail, mostly downhil so I aimed to oversleep as much as possible. Ate breakfast as the very last nonstaff person in the camp.
At the water source, there was donkey drinking; I needed to drink too, so I came by, he moved a bit, and we simply drank together there, like some hippies.</p>
<p>Then I started hiking; it was quite an ordinary walk in an ordinary forest this time. Started to meet day hikers; they were very refined and smelled like washing powder.
Around lunchtime, I arrived at the <a href="https://en.mapy.cz/s/hurumuhako">Village de Bavella</a>, a popular spot for hikers; there's a nice road, restaurants, and a big parking spot.
To me it was like being in the middle of some circus there.
For lunch, I bought crepes with cheese and french fries and coke, of course.
Next, there was quite a climb on the menu, although I was in general slowly going down to 200 meters above the sea.
That meant the plants were getting more and more exotic and were absolutely stunning now  sort of greeny, spiky, thick stuff everywhere.
On the negative side, the sun was burning me alive.
<img src="https://live.staticflickr.com/65535/50330451146_6cdf1cdf97_c.jpg" alt="img" /></p>
<p>At this point, I started to feel the tension in my stomach; it felt like it's getting out of order. Started to think that the lunch was a big mistake.
There was literally no processing going on when I tried to drink water. It was just splashing as if there was some stopper in my belly.</p>
<p>The problem was, there was this massive fusion reactor above me reaching its peak performance. This time yesterday, I already had 6l of water in me.
I started to be sluggish, like I was about to pass out. Every 30mins, I had to sit down and just stare at nowhere. I was convincing myself the body only needed some time to process the food.
And always, after some serious time of staring, I started to feel a bit better, got up, walked a couple of meters, and got back to this abouttothrowupthenpassout state.
Sections without any shade were the worst, and there were many of those. It started to feel dangerous; I just kept telling myself  dude, you can't stop here.
When I reached some shade, I always felt down right away, sometimes to sleep, just like that on rocks. Sometimes I threw up some fluids.
<img src="https://live.staticflickr.com/65535/50329777853_6d8d0cc14d_c.jpg" alt="img" /></p>
<p>After what felt like infinity, I arrived at some <a href="https://en.mapy.cz/s/kelohoreju">waterfall with lagoons</a> and slowly got whole myself in. That helped a lot, stomach stopped cramping, and I finally managed to drink.
Then it was only over the hill down to <a href="https://en.mapy.cz/s/kocaduheso">Conca</a>  my destination. And as it was getting later, even the sun started to burn less.
So I simply walked and walked, now quite sure I was able to make it without dying. And indeed, after a couple of hours, I found myself at the end of GR20.
<img src="https://live.staticflickr.com/65535/50330625157_18a902db47_c.jpg" alt="img" /></p>
<p>It was funny how natives ignored me; they probably have their scoop of experiences with finishing hikers.
So I, a battered, dirty, smelly person, probably with some vomit on himself, sat down to a bar, ordered a coke, and watched football with them.</p>
<p>Then celebratory call with my girlfriend, camp, shower, stars, chats, sleep.
<img src="https://live.staticflickr.com/65535/50329725393_502e14563e_c.jpg" alt="img" /></p>
<p>And that was basically it.</p>
Hey Webpack, can you bust my cache?Sun, 02 Jul 2017 00:00:00 +0000
https://ktsk.xyz/posts/webpackcachebust/
https://ktsk.xyz/posts/webpackcachebust/<p>Most JavaScript developers are familiar with this problem. You have a bug in your system; you fix it, ship it… and your error monitoring still spams you with the problem, which was apparently fixed. How come? Your responses have cache headers set, and the client's browser caches static assets. But web development is very dynamic nowadays; we deploy multiple times per day. So how can we continue with aggressive deployment and still cache static assets?</p>
<p>You can use query string to version your assets:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagehtml" datalang="html"><span style="color:#abb2bf;"><</span><span style="color:#eb6772;">script </span><span style="color:#db9d63;">src</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">”/bundles/app.bundle.js?v=23” </span><span style="color:#db9d63;">type</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">”text/javascript”</span><span style="color:#abb2bf;">></</span><span style="color:#eb6772;">script</span><span style="color:#abb2bf;">>
</span></code></pre>
<p>Unfortunately, some CDNs and proxies don't cache assets with query strings at all. Moreover, versioning here is a very manual process, thus doomed to be forgotten.</p>
<p>What else? Of course, you can include your version in a path or in a file name:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagehtml" datalang="html"><span style="color:#abb2bf;"><</span><span style="color:#eb6772;">script </span><span style="color:#db9d63;">src</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">”/bundles/v23/app.bundle.js” </span><span style="color:#db9d63;">type</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">”text/javascript”</span><span style="color:#abb2bf;">></</span><span style="color:#eb6772;">script</span><span style="color:#abb2bf;">>
</span></code></pre>
<p>...</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagehtml" datalang="html"><span style="color:#abb2bf;"><</span><span style="color:#eb6772;">script </span><span style="color:#db9d63;">src</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">”/bundles/app.bundle.v23.js” </span><span style="color:#db9d63;">type</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">”text/javascript”</span><span style="color:#abb2bf;">></</span><span style="color:#eb6772;">script</span><span style="color:#abb2bf;">>
</span></code></pre>
<p>Better and valid for CDNs and proxies. But still too manual, we need something automatic and more sophisticated. So whenever someone builds an asset, the version will be automatically busted. Only then will the feature be handy (even managers will be able to invalidate a cache).</p>
<p>Let's try to automate it! Since the title of this post starts with Hey Webpack, we will focus on Webpack based solutions. We will build a very tiny example React application because React is cool. But it doesn't matter; you can use this solution with whatever library (or framework) you want as long as it will be built using Webpack.</p>
<p>We start with initializing the project and adding some libraries:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagebash" datalang="bash"><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> mkdir cachebusters </span><span style="color:#adb7c9;">&& </span><span style="color:#5ebfcc;">cd</span><span style="color:#abb2bf;"> cachebusters
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters yarn init
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters yarn add react reactdom
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters yarn add</span><span style="color:#eb6772;"> dev</span><span style="color:#abb2bf;"> webpack webpackdevserver babelcore babelloader babelpresetreact cssloader
</span></code></pre>
<p>Now let's create some basic directory structure:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagebash" datalang="bash"><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters mkdir config
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters mkdir config/webpack
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters mkdir src
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters touch src/index.jsx
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters mkdir src
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters mkdir src/components
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters mkdir src/assets
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters touch src/assets/style.css
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters mkdir public
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters touch public/index.html
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters mkdir public/bundles
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters touch .babelrc
</span></code></pre>
<p>Add Babel preset to .babelrc:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagejs" datalang="js"><span style="color:#abb2bf;">{
</span><span style="color:#9acc76;">"presets"</span><span style="color:#abb2bf;">: [</span><span style="color:#9acc76;">"react"</span><span style="color:#abb2bf;">]
}
</span></code></pre>
<p>Ok, time to get our hands dirty; now we start to configure the Webpack. We want to have one basic configuration file with just an entry point definition and some rules. Then we'll add two separate configurations for development and production environments, which would enhance basic configuration. Using this setup, we can define plugins for each environment separately:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagebash" datalang="bash"><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters touch config/webpack/config.js
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters touch config/webpack/config.production.js
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters touch config/webpack/config.development.js
</span></code></pre><pre style="backgroundcolor:#2b303b;">
<code class="languagejs" datalang="js"><span style="fontstyle:italic;color:#5f697a;">// config/webpack/config.js
</span><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">path </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'path'</span><span style="color:#abb2bf;">)
</span><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">ExtractTextPlugin </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'extracttextwebpackplugin'</span><span style="color:#abb2bf;">)
module.exports </span><span style="color:#adb7c9;">= </span><span style="color:#abb2bf;">{
entry: {
app: [
</span><span style="color:#eb6772;">path</span><span style="color:#abb2bf;">.</span><span style="color:#5ebfcc;">resolve</span><span style="color:#abb2bf;">(__dirname, </span><span style="color:#9acc76;">'../../src/index.jsx'</span><span style="color:#abb2bf;">),
],
},
module: {
rules: [
{
test: </span><span style="color:#5ebfcc;">/</span><span style="color:#db9d63;">.</span><span style="color:#5ebfcc;">jsx</span><span style="color:#adb7c9;">?</span><span style="color:#cd74e8;">$</span><span style="color:#5ebfcc;">/</span><span style="color:#abb2bf;">,
use: [</span><span style="color:#9acc76;">'babelloader'</span><span style="color:#abb2bf;">],
exclude: </span><span style="color:#5ebfcc;">/node_modules/</span><span style="color:#abb2bf;">,
},
{
test: </span><span style="color:#5ebfcc;">/\.css</span><span style="color:#cd74e8;">$</span><span style="color:#5ebfcc;">/</span><span style="color:#abb2bf;">,
use: </span><span style="color:#eb6772;">ExtractTextPlugin</span><span style="color:#abb2bf;">.</span><span style="color:#5cb3fa;">extract</span><span style="color:#abb2bf;">({
use: </span><span style="color:#9acc76;">'cssloader'</span><span style="color:#abb2bf;">,
}),
},
],
},
resolve: {
modules: [
</span><span style="color:#9acc76;">'node_modules'</span><span style="color:#abb2bf;">,
</span><span style="color:#eb6772;">path</span><span style="color:#abb2bf;">.</span><span style="color:#5ebfcc;">resolve</span><span style="color:#abb2bf;">(__dirname, </span><span style="color:#9acc76;">'../../src'</span><span style="color:#abb2bf;">),
],
extensions: [</span><span style="color:#9acc76;">'.js'</span><span style="color:#abb2bf;">, </span><span style="color:#9acc76;">'.jsx'</span><span style="color:#abb2bf;">],
alias: {
react: </span><span style="color:#eb6772;">path</span><span style="color:#abb2bf;">.</span><span style="color:#5ebfcc;">resolve</span><span style="color:#abb2bf;">(__dirname, </span><span style="color:#9acc76;">'../../node_modules'</span><span style="color:#abb2bf;">, </span><span style="color:#9acc76;">'react'</span><span style="color:#abb2bf;">),
},
},
plugins: [],
}
</span></code></pre>
<p>Webpack now knows our entry point and is instructed to use babelloader for js/jsx and cssloader for CSS files.</p>
<p>Now it's time to add basic development configuration, so we'll be able to actually build our application and run webpackdevserver:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagejs" datalang="js"><span style="fontstyle:italic;color:#5f697a;">// config/webpack.development.js
</span><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">webpack </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'webpack'</span><span style="color:#abb2bf;">)
</span><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">config </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'./config'</span><span style="color:#abb2bf;">)
</span><span style="color:#eb6772;">config</span><span style="color:#abb2bf;">.</span><span style="color:#eb6772;">output </span><span style="color:#adb7c9;">= </span><span style="color:#abb2bf;">{
path: </span><span style="color:#eb6772;">path</span><span style="color:#abb2bf;">.</span><span style="color:#5ebfcc;">resolve</span><span style="color:#abb2bf;">(__dirname, </span><span style="color:#9acc76;">'../../public/bundles'</span><span style="color:#abb2bf;">),
filename: </span><span style="color:#9acc76;">'[name].bundle.js'</span><span style="color:#abb2bf;">,
chunkFilename: </span><span style="color:#9acc76;">"[name].js"</span><span style="color:#abb2bf;">,
publicPath: </span><span style="color:#9acc76;">'/bundles/'</span><span style="color:#abb2bf;">,
}
module.exports </span><span style="color:#adb7c9;">= </span><span style="color:#eb6772;">config
</span></code></pre>
<p>Here we told Webpack where it should store output files and defined file names.</p>
<p>We're almost ready for our first development build! We need to just add index.html file, React component, and some basic styling:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagehtml" datalang="html"><span style="color:#abb2bf;">// public/index.html
<!</span><span style="color:#cd74e8;">DOCTYPE </span><span style="color:#db9d63;">html</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">html </span><span style="color:#db9d63;">lang</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"en"</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">head</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">meta </span><span style="color:#db9d63;">charset</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"UTF8"</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">meta </span><span style="color:#db9d63;">name</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"viewport" </span><span style="color:#db9d63;">content</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"width=devicewidth, initialscale=1.0"</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">meta </span><span style="color:#db9d63;">httpequiv</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"XUACompatible" </span><span style="color:#db9d63;">content</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"ie=edge"</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">title</span><span style="color:#abb2bf;">>Cache Busters</</span><span style="color:#eb6772;">title</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">link </span><span style="color:#db9d63;">rel</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"stylesheet" </span><span style="color:#db9d63;">href</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"/bundles/app.bundle.css"</span><span style="color:#abb2bf;">>
</</span><span style="color:#eb6772;">head</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">body</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">div </span><span style="color:#db9d63;">id</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"app"</span><span style="color:#abb2bf;">></</span><span style="color:#eb6772;">div</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">script </span><span style="color:#db9d63;">src</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"/bundles/app.bundle.js" </span><span style="color:#db9d63;">type</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"text/javascript"</span><span style="color:#abb2bf;">></</span><span style="color:#eb6772;">script</span><span style="color:#abb2bf;">>
</</span><span style="color:#eb6772;">body</span><span style="color:#abb2bf;">>
</</span><span style="color:#eb6772;">html</span><span style="color:#abb2bf;">>
</span></code></pre><pre style="backgroundcolor:#2b303b;">
<code class="languagejs" datalang="js"><span style="fontstyle:italic;color:#5f697a;">// src/index.jsx
</span><span style="color:#cd74e8;">import </span><span style="color:#eb6772;">React </span><span style="color:#cd74e8;">from </span><span style="color:#9acc76;">'react'
</span><span style="color:#cd74e8;">import </span><span style="color:#abb2bf;">{ </span><span style="color:#eb6772;">render </span><span style="color:#abb2bf;">} </span><span style="color:#cd74e8;">from </span><span style="color:#9acc76;">'reactdom'
</span><span style="color:#cd74e8;">const </span><span style="color:#5cb3fa;">CacheBusters </span><span style="color:#adb7c9;">= </span><span style="color:#abb2bf;">() </span><span style="color:#cd74e8;">=>
</span><span style="color:#abb2bf;"><div></span><span style="color:#eb6772;">Stays Puft</span><span style="color:#abb2bf;">, </span><span style="color:#eb6772;">Even</span><span style="color:#abb2bf;"> When Toasted</div>
</span><span style="color:#5cb3fa;">render</span><span style="color:#abb2bf;">(
<CacheBusters />,
document.</span><span style="color:#5ebfcc;">getElementById</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'app'</span><span style="color:#abb2bf;">),
)
</span></code></pre><pre style="backgroundcolor:#2b303b;">
<code class="languagecss" datalang="css"><span style="color:#abb2bf;">// </span><span style="color:#cd74e8;">src</span><span style="color:#abb2bf;">/</span><span style="color:#cd74e8;">assets</span><span style="color:#abb2bf;">/</span><span style="color:#eb6772;">style</span><span style="color:#db9d63;">.css
</span><span style="color:#eb6772;">body </span><span style="color:#abb2bf;">{
backgroundcolor: purple;
}
</span></code></pre>
<p>And finally, we can add the start script to package.json:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagejs" datalang="js"><span style="color:#abb2bf;">{
</span><span style="fontstyle:italic;color:#5f697a;">// …
</span><span style="color:#9acc76;">"scripts"</span><span style="color:#abb2bf;">: {
</span><span style="color:#9acc76;">"start"</span><span style="color:#abb2bf;">: </span><span style="color:#9acc76;">"webpackdevserver — config config/webpack/config.development.js — contentbase public/"</span><span style="color:#abb2bf;">,
},
</span><span style="fontstyle:italic;color:#5f697a;">// …
</span><span style="color:#abb2bf;">}
</span></code></pre>
<p>Now lets try to build & start webpackdevserver:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagebash" datalang="bash"><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters yarn start
</span><span style="color:#eb6772;">yarn</span><span style="color:#abb2bf;"> start v0.22.0
</span><span style="color:#eb6772;">$</span><span style="color:#abb2bf;"> webpackdevserver — config config/webpack/config.development.js — contentbase public/ — historyapifallback
</span><span style="color:#eb6772;">...
Version:</span><span style="color:#abb2bf;"> webpack 3.0.0
</span><span style="color:#eb6772;">Time:</span><span style="color:#abb2bf;"> 1681ms
</span><span style="color:#eb6772;">Asset</span><span style="color:#abb2bf;"> Size Chunks Chunk Names
</span><span style="color:#eb6772;">app.bundle.js</span><span style="color:#abb2bf;"> 1.06 MB 0 </span><span style="color:#cd74e8;">[</span><span style="color:#abb2bf;">emitted</span><span style="color:#cd74e8;">] [</span><span style="color:#abb2bf;">big</span><span style="color:#cd74e8;">]</span><span style="color:#abb2bf;"> app
</span><span style="color:#eb6772;">app.bundle.css</span><span style="color:#abb2bf;"> 40 bytes 0 </span><span style="color:#cd74e8;">[</span><span style="color:#abb2bf;">emitted</span><span style="color:#cd74e8;">]</span><span style="color:#abb2bf;"> app
</span><span style="color:#eb6772;">...
+</span><span style="color:#abb2bf;"> 252 hidden modules
</span><span style="color:#eb6772;">webpack:</span><span style="color:#abb2bf;"> Compiled successfully.
</span></code></pre>
<p>Nice 1MB hello world, our setup works, we can check webpackdevserver running at a given URL: <code>http://localhost:8080/</code>.</p>
<p>Time to move on to production configuration!</p>
<p>Let's repeat our goal once more. Upon each production build, we want our static assets to contain a hash (which would be different than the previous one only if the code was changed) and our index.html to be dynamically generated with correct assets names (containing a hash), e.g.:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagehtml" datalang="html"><span style="color:#abb2bf;"><</span><span style="color:#eb6772;">script </span><span style="color:#db9d63;">src</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">”/bundles/app.bundle.9f61f58dd1cc3bb82182.js” </span><span style="color:#db9d63;">type</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">”text/javascript”</span><span style="color:#abb2bf;">></</span><span style="color:#eb6772;">script</span><span style="color:#abb2bf;">>
</span></code></pre>
<p>Adding a hash is easy, Webpack gives us two options:</p>
<p><strong>[hash]</strong> — calculated for build and <strong>[chunkhash]</strong> — calculated for entry file. For our use case, chunkhash will be a better option. Since we can selectively bust only, e.g., <em>app.bundle.js</em> and no <em>app.bundle.css</em> if we changed code just in the javascript part of our application:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagejs" datalang="js"><span style="fontstyle:italic;color:#5f697a;">// config/webpack/config.production.js
</span><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">ExtractTextPlugin </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'extracttextwebpackplugin'</span><span style="color:#abb2bf;">)
</span><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">path </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'path'</span><span style="color:#abb2bf;">)
</span><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">config </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'./config'</span><span style="color:#abb2bf;">)
</span><span style="color:#eb6772;">config</span><span style="color:#abb2bf;">.plugins.</span><span style="color:#5ebfcc;">push</span><span style="color:#abb2bf;">(
</span><span style="color:#adb7c9;">new </span><span style="color:#abb2bf;">ExtractTextPlugin({
filename: </span><span style="color:#9acc76;">'app.bundle.[chunkhash].css'</span><span style="color:#abb2bf;">,
allChunks: </span><span style="color:#db9d63;">true
</span><span style="color:#abb2bf;">})
)
</span><span style="color:#eb6772;">config</span><span style="color:#abb2bf;">.</span><span style="color:#eb6772;">output </span><span style="color:#adb7c9;">= </span><span style="color:#abb2bf;">{
path: </span><span style="color:#eb6772;">path</span><span style="color:#abb2bf;">.</span><span style="color:#5ebfcc;">resolve</span><span style="color:#abb2bf;">(__dirname, </span><span style="color:#9acc76;">'../../public/bundles'</span><span style="color:#abb2bf;">),
filename: </span><span style="color:#9acc76;">'[name].bundle.[chunkhash].js'</span><span style="color:#abb2bf;">,
chunkFilename: </span><span style="color:#9acc76;">"[name].[chunkhash].js"</span><span style="color:#abb2bf;">,
publicPath: </span><span style="color:#9acc76;">'/bundles/'</span><span style="color:#abb2bf;">,
}
module.exports </span><span style="color:#adb7c9;">= </span><span style="color:#eb6772;">config
</span></code></pre>
<p>Let's add a build option to our package.json:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagejs" datalang="js"><span style="color:#abb2bf;">{
</span><span style="color:#adb7c9;">...
</span><span style="color:#9acc76;">"scripts"</span><span style="color:#abb2bf;">: {
</span><span style="color:#adb7c9;">...
</span><span style="color:#9acc76;">"build"</span><span style="color:#abb2bf;">: </span><span style="color:#9acc76;">"webpack bail p config config/webpack/config.production.js"</span><span style="color:#abb2bf;">,
</span><span style="color:#adb7c9;">...
</span><span style="color:#abb2bf;">},
</span><span style="color:#adb7c9;">...
</span><span style="color:#abb2bf;">}
</span></code></pre>
<p>And trigger a build:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagebash" datalang="bash"><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters yarn build
</span><span style="color:#eb6772;">yarn</span><span style="color:#abb2bf;"> build v0.22.0
</span><span style="color:#eb6772;">$</span><span style="color:#abb2bf;"> webpack — bail</span><span style="color:#eb6772;"> p</span><span style="color:#abb2bf;"> — config config/webpack/config.production.js
</span><span style="color:#eb6772;">Hash:</span><span style="color:#abb2bf;"> 01788dcc6a43c1f47e5c
</span><span style="color:#eb6772;">Version:</span><span style="color:#abb2bf;"> webpack 3.0.0
</span><span style="color:#eb6772;">Time:</span><span style="color:#abb2bf;"> 1786ms
</span><span style="color:#eb6772;">Asset</span><span style="color:#abb2bf;"> Size Chunks Chunk Names
</span><span style="color:#eb6772;">app.bundle.9f61f58dd1cc3bb82182.js</span><span style="color:#abb2bf;"> 688 kB 0 </span><span style="color:#cd74e8;">[</span><span style="color:#abb2bf;">emitted</span><span style="color:#cd74e8;">] [</span><span style="color:#abb2bf;">big</span><span style="color:#cd74e8;">]</span><span style="color:#abb2bf;"> app
</span><span style="color:#eb6772;">app.bundle.9f61f58dd1cc3bb82182.css</span><span style="color:#abb2bf;"> 29 bytes 0 </span><span style="color:#cd74e8;">[</span><span style="color:#abb2bf;">emitted</span><span style="color:#cd74e8;">]</span><span style="color:#abb2bf;"> app
</span></code></pre>
<p>We are getting there! Now our bundles have unique hashes. But we have a new problem now; our index.html contains old links to <em>/bundles/app.bundle.js</em> and <em>/bundles/app.bundle.css</em>.</p>
<p>We will use <a href="https://github.com/jantimon/htmlwebpackplugin">htmlwebpackplugin</a> to generate our <em>index.html</em> on demand from a template. You can use <em>htmlwebpackplugin</em> with various templating engines, so it should cover most of the use cases.</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagebash" datalang="bash"><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters yarn add</span><span style="color:#eb6772;"> dev</span><span style="color:#abb2bf;"> htmlwebpackplugin
</span><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters mv public/index.html ./src/assets/index.template.html
</span></code></pre>
<p>Remove bundle links from index.template.html:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagehtml" datalang="html"><span style="color:#abb2bf;">// src/assets/index.template.html
<!</span><span style="color:#cd74e8;">DOCTYPE </span><span style="color:#db9d63;">html</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">html </span><span style="color:#db9d63;">lang</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"en"</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">head</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">meta </span><span style="color:#db9d63;">charset</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"UTF8"</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">meta </span><span style="color:#db9d63;">name</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"viewport" </span><span style="color:#db9d63;">content</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"width=devicewidth, initialscale=1.0"</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">meta </span><span style="color:#db9d63;">httpequiv</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"XUACompatible" </span><span style="color:#db9d63;">content</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"ie=edge"</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">title</span><span style="color:#abb2bf;">>Cache Busters</</span><span style="color:#eb6772;">title</span><span style="color:#abb2bf;">>
</</span><span style="color:#eb6772;">head</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">body</span><span style="color:#abb2bf;">>
<</span><span style="color:#eb6772;">div </span><span style="color:#db9d63;">id</span><span style="color:#abb2bf;">=</span><span style="color:#9acc76;">"app"</span><span style="color:#abb2bf;">></</span><span style="color:#eb6772;">div</span><span style="color:#abb2bf;">>
</</span><span style="color:#eb6772;">body</span><span style="color:#abb2bf;">>
</</span><span style="color:#eb6772;">html</span><span style="color:#abb2bf;">>
</span></code></pre>
<p>Add <em>htmlwebpackplugin</em> to Webpack's <em>config.production.js</em>:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagejs" datalang="js"><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">path </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'path'</span><span style="color:#abb2bf;">)
</span><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">ExtractTextPlugin </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'extracttextwebpackplugin'</span><span style="color:#abb2bf;">)
</span><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">HtmlWebpackPlugin </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'htmlwebpackplugin'</span><span style="color:#abb2bf;">)
</span><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">config </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'./config'</span><span style="color:#abb2bf;">)
</span><span style="color:#eb6772;">config</span><span style="color:#abb2bf;">.</span><span style="color:#eb6772;">output </span><span style="color:#adb7c9;">= </span><span style="color:#abb2bf;">{
path: </span><span style="color:#eb6772;">path</span><span style="color:#abb2bf;">.</span><span style="color:#5ebfcc;">resolve</span><span style="color:#abb2bf;">(__dirname, </span><span style="color:#9acc76;">'../../public/bundles'</span><span style="color:#abb2bf;">),
filename: </span><span style="color:#9acc76;">'[name].bundle.[chunkhash].js'</span><span style="color:#abb2bf;">,
chunkFilename: </span><span style="color:#9acc76;">"[name].[chunkhash].js"</span><span style="color:#abb2bf;">,
publicPath: </span><span style="color:#9acc76;">'/bundles/'</span><span style="color:#abb2bf;">,
}
</span><span style="color:#eb6772;">config</span><span style="color:#abb2bf;">.plugins.</span><span style="color:#5ebfcc;">push</span><span style="color:#abb2bf;">(
</span><span style="color:#adb7c9;">new </span><span style="color:#abb2bf;">ExtractTextPlugin({
filename: </span><span style="color:#9acc76;">'app.bundle.[chunkhash].css'</span><span style="color:#abb2bf;">,
allChunks: </span><span style="color:#db9d63;">true
</span><span style="color:#abb2bf;">}),
</span><span style="color:#adb7c9;">new </span><span style="color:#abb2bf;">HtmlWebpackPlugin({
filename: </span><span style="color:#9acc76;">'../../public/index.html'</span><span style="color:#abb2bf;">,
template: </span><span style="color:#9acc76;">'src/assets/index.template.html'
</span><span style="color:#abb2bf;">})
)
module.exports </span><span style="color:#adb7c9;">= </span><span style="color:#eb6772;">config
</span></code></pre>
<p>And build:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagebash" datalang="bash"><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters yarn build
</span><span style="color:#eb6772;">yarn</span><span style="color:#abb2bf;"> build v0.22.0
</span><span style="color:#eb6772;">...
Asset</span><span style="color:#abb2bf;"> Size Chunks Chunk Names
</span><span style="color:#eb6772;">app.bundle.9f61f58dd1cc3bb82182.js</span><span style="color:#abb2bf;"> 688 kB 0 </span><span style="color:#cd74e8;">[</span><span style="color:#abb2bf;">emitted</span><span style="color:#cd74e8;">] [</span><span style="color:#abb2bf;">big</span><span style="color:#cd74e8;">]</span><span style="color:#abb2bf;"> app
</span><span style="color:#eb6772;">app.bundle.9f61f58dd1cc3bb82182.css</span><span style="color:#abb2bf;"> 29 bytes 0 </span><span style="color:#cd74e8;">[</span><span style="color:#abb2bf;">emitted</span><span style="color:#cd74e8;">]</span><span style="color:#abb2bf;"> app
</span><span style="color:#eb6772;">public/index.html</span><span style="color:#abb2bf;"> 462 bytes </span><span style="color:#cd74e8;">[</span><span style="color:#abb2bf;">emitted</span><span style="color:#cd74e8;">]
</span><span style="color:#eb6772;">...
➜</span><span style="color:#abb2bf;"> cachebusters cat public/index.html
</span><span style="color:#adb7c9;"><</span><span style="color:#abb2bf;">!DOCTYPE </span><span style="color:#eb6772;">html</span><span style="color:#adb7c9;">>
<</span><span style="color:#abb2bf;">html lang=”en”</span><span style="color:#adb7c9;">>
<</span><span style="color:#abb2bf;">head</span><span style="color:#adb7c9;">>
</span><span style="color:#abb2bf;"> ...
</span><span style="color:#adb7c9;"><</span><span style="color:#abb2bf;">link </span><span style="color:#eb6772;">href</span><span style="color:#adb7c9;">=</span><span style="color:#9acc76;">"/bundles/app.bundle.9f61f58dd1cc3bb82182.css" </span><span style="color:#eb6772;">rel</span><span style="color:#adb7c9;">=</span><span style="color:#9acc76;">" stylesheet"</span><span style="color:#adb7c9;">>
<</span><span style="color:#abb2bf;">/head</span><span style="color:#adb7c9;">>
<</span><span style="color:#abb2bf;">body</span><span style="color:#adb7c9;">>
<</span><span style="color:#abb2bf;">div </span><span style="color:#eb6772;">id</span><span style="color:#adb7c9;">=</span><span style="color:#9acc76;">”app”</span><span style="color:#adb7c9;">><</span><span style="color:#abb2bf;">/div</span><span style="color:#adb7c9;">>
<</span><span style="color:#abb2bf;">script </span><span style="color:#eb6772;">type</span><span style="color:#adb7c9;">=</span><span style="color:#9acc76;">”text/javascript” </span><span style="color:#eb6772;">src</span><span style="color:#adb7c9;">=</span><span style="color:#9acc76;">”/bundles/app.bundle.9f61f58dd1cc3bb82182.js”</span><span style="color:#adb7c9;">><</span><span style="color:#abb2bf;">/script</span><span style="color:#adb7c9;">>
<</span><span style="color:#abb2bf;">/body</span><span style="color:#adb7c9;">>
<</span><span style="color:#abb2bf;">/html</span><span style="color:#adb7c9;">>
</span></code></pre>
<p>Bingo! Our <em>index.html</em> now contains a dynamic chunk hash for both asset files.</p>
<p>It's a good idea to add those folders with dynamically generated files to <em>.gitignore</em> so that no one will commit it to git.</p>
<p>Now we have a new problem; our development build is broken. There's no <em>index.html</em> with our entry point anymore, and we don't want to use chunk hash during development since it's slower. One way to solve this issue would be to create a second public folder for development only with <em>index.html</em> referencing to static app.bundle.js/css assets, but it means we'd have to keep two versions of <em>index.html</em> with the same content.</p>
<p>But what if we'd use htmlwebpackplugin to generate index.html from the template with chunk hashfree assets? I'd work except for one small issue — using webpackdevserver, our <em>index.html</em> is not being written to a hard drive. What now? Of course, there is a webpack plugin to solve it: <a href="https://github.com/jantimon/htmlwebpackharddiskplugin">htmlwebpackharddiskplugin</a>!</p>
<p>Now we can add it to our development config:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagebash" datalang="bash"><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters yarn add</span><span style="color:#eb6772;"> dev</span><span style="color:#abb2bf;"> htmlwebpackharddiskplugin
</span></code></pre><pre style="backgroundcolor:#2b303b;">
<code class="languagejs" datalang="js"><span style="fontstyle:italic;color:#5f697a;">// config.development.js
</span><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">path </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'path'</span><span style="color:#abb2bf;">)
</span><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">ExtractTextPlugin </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'extracttextwebpackplugin'</span><span style="color:#abb2bf;">)
</span><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">HtmlWebpackPlugin </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'htmlwebpackplugin'</span><span style="color:#abb2bf;">)
</span><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">HtmlWebpackHarddiskPlugin </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'htmlwebpackharddiskplugin'</span><span style="color:#abb2bf;">)
</span><span style="color:#cd74e8;">const </span><span style="color:#eb6772;">config </span><span style="color:#adb7c9;">= </span><span style="color:#5ebfcc;">require</span><span style="color:#abb2bf;">(</span><span style="color:#9acc76;">'./config'</span><span style="color:#abb2bf;">)
</span><span style="color:#eb6772;">config</span><span style="color:#abb2bf;">.</span><span style="color:#eb6772;">output </span><span style="color:#adb7c9;">= </span><span style="color:#abb2bf;">{
path: </span><span style="color:#eb6772;">path</span><span style="color:#abb2bf;">.</span><span style="color:#5ebfcc;">resolve</span><span style="color:#abb2bf;">(__dirname, </span><span style="color:#9acc76;">'../../public/bundles'</span><span style="color:#abb2bf;">),
filename: </span><span style="color:#9acc76;">'[name].bundle.js'</span><span style="color:#abb2bf;">,
chunkFilename: </span><span style="color:#9acc76;">"[name].js"</span><span style="color:#abb2bf;">,
publicPath: </span><span style="color:#9acc76;">'/bundles/'</span><span style="color:#abb2bf;">,
}
</span><span style="color:#eb6772;">config</span><span style="color:#abb2bf;">.plugins.</span><span style="color:#5ebfcc;">push</span><span style="color:#abb2bf;">(
</span><span style="color:#adb7c9;">new </span><span style="color:#abb2bf;">ExtractTextPlugin({
filename: </span><span style="color:#9acc76;">'app.bundle.css'</span><span style="color:#abb2bf;">,
allChunks: </span><span style="color:#db9d63;">true
</span><span style="color:#abb2bf;">}),
</span><span style="color:#adb7c9;">new </span><span style="color:#abb2bf;">HtmlWebpackPlugin({
filename: </span><span style="color:#9acc76;">'../../public/index.html'</span><span style="color:#abb2bf;">,
template: </span><span style="color:#9acc76;">'src/assets/index.template.html'</span><span style="color:#abb2bf;">,
alwaysWriteToDisk: </span><span style="color:#db9d63;">true</span><span style="color:#abb2bf;">, </span><span style="fontstyle:italic;color:#5f697a;">// this option was added by htmlwebpackharddiskplugin
</span><span style="color:#abb2bf;">}),
</span><span style="color:#adb7c9;">new </span><span style="color:#abb2bf;">HtmlWebpackHarddiskPlugin()
)
module.exports </span><span style="color:#adb7c9;">= </span><span style="color:#eb6772;">config
</span></code></pre>
<p>Try to run webpackdevserver:</p>
<pre style="backgroundcolor:#2b303b;">
<code class="languagebash" datalang="bash"><span style="color:#eb6772;">➜</span><span style="color:#abb2bf;"> cachebusters yarn start
</span><span style="color:#eb6772;">...
Asset</span><span style="color:#abb2bf;"> Size Chunks Chunk Names
</span><span style="color:#eb6772;">app.bundle.js</span><span style="color:#abb2bf;"> 1.06 MB 0 </span><span style="color:#cd74e8;">[</span><span style="color:#abb2bf;">emitted</span><span style="color:#cd74e8;">] [</span><span style="color:#abb2bf;">big</span><span style="color:#cd74e8;">]</span><span style="color:#abb2bf;"> app
</span><span style="color:#eb6772;">app.bundle.css</span><span style="color:#abb2bf;"> 37 bytes 0 </span><span style="color:#cd74e8;">[</span><span style="color:#abb2bf;">emitted</span><span style="color:#cd74e8;">]</span><span style="color:#abb2bf;"> app
</span><span style="color:#eb6772;">../../public/index.html</span><span style="color:#abb2bf;"> 420 bytes </span><span style="color:#cd74e8;">[</span><span style="color:#abb2bf;">emitted</span><span style="color:#cd74e8;">]
</span></code></pre>
<p>That's it! Bundles don't have a hash, and index.html is being emitted.</p>
<p>Now we have working cachebusting as well as a solid Webpack setup ready to be extended.</p>
<p>I hope you enjoyed this tutorial & see you next time.</p>