Reference
Math Toolkit
Every tool the course uses, sharpened in five minutes or less.
Relativity needs less math than its reputation suggests: algebra, square roots, Pythagoras and a few friendly functions. This page has all of it.
How to use this page
This is a reference page, not a chapter. You don’t need to read it from top to bottom. Each section refreshes one piece of math, with one picture and four practice items.
- Jump in. A chapter’s “Need a refresher?” link opens the one section you need. You can also pick one from the list below.
- Read, then try. Read the refresher, look at the picture, then try the practice items. Answers can be fractions or roots: type
5/4orsqrt(2). - Head back. If you came from a chapter, use the “Back to …” link at the top of the page, or your browser’s Back button.
Each practice item shows how hard it is:
- Back of the envelope: quick, in your head.
- Pencil and paper: a few written steps.
- Head-scratcher: harder, so take your time.
Pythagoras
In a right triangle, the squares on the two short sides (the legs) add up to the square on the long side (the hypotenuse). Legs 3 and 4: \(9 + 16 = 25\), so the long side is \(\sqrt{25} = 5\).
\[ \begin{aligned} a^2 + b^2 &= c^2, \\[4pt] c &= \sqrt{a^2 + b^2}, \\[4pt] b &= \sqrt{c^2 - a^2}. \end{aligned} \]
The same rule measures the straight-line distance between two points on a map: the east offset and the north offset are the legs.
Practice
A right triangle has legs 6 and 8. How long is the hypotenuse?
That’s 6 + 8. Add the squares, not the sides.
Hint
\(36 + 64 = 100\).
Solution
\(\sqrt{36 + 64} = \sqrt{100} = 10\). It’s the 3-4-5 triangle, doubled.
The hypotenuse is 25 and one leg is 7. How long is the other leg?
That’s 25 − 7. Subtract the squares instead.
Hint
\(b^2 = 25^2 - 7^2 = 625 - 49\).
Solution
\(\sqrt{625 - 49} = \sqrt{576} = 24\): the 7-24-25 triangle.
How far is it from the point (1, 2) to the point (4, 6)?
Hint
The offsets are \(4 - 1 = 3\) and \(6 - 2 = 4\).
Solution
\(\sqrt{3^2 + 4^2} = 5\). Only the differences matter, not where you start.
How long is the diagonal of a square with sides of length 1? (Type sqrt(2) or a decimal.)
That’s 1 + 1. The diagonal is a shortcut, so it’s shorter than going around.
Hint
Both legs are 1, so \(c^2 = 1 + 1\).
Solution
\(\sqrt{1 + 1} = \sqrt{2} \approx 1.414\).
Sine, cosine and angles
In a right triangle, pick one of the two sharp angles and call it \(\theta\). The side that touches it (other than the hypotenuse) is the adjacent side; the side across from it is the opposite side. Their ratios to the hypotenuse depend only on the angle, not on how big the triangle is:
\[ \begin{aligned} \cos\theta &= \frac{\text{adjacent}}{\text{hypotenuse}}, \\[6pt] \sin\theta &= \frac{\text{opposite}}{\text{hypotenuse}}, \\[6pt] \tan\theta &= \frac{\text{opposite}}{\text{adjacent}}. \end{aligned} \]
Some people remember this as SOH-CAH-TOA. In the 3-4-5 triangle, the angle next to the side of length 4 has \(\cos\theta = 4/5 = 0.8\) and \(\sin\theta = 3/5 = 0.6\). That angle is about 36.87°. Because the two legs are \(\cos\theta\) and \(\sin\theta\) times the hypotenuse, Pythagoras gives \(\cos^2\theta + \sin^2\theta = 1\) for every angle.
Degrees, radians and your calculator
Angles come in two units. In degrees a full turn is 360°; in radians it is \(2\pi \approx 6.283\). This course uses degrees. If your calculator says \(\cos 60 = -0.952\) instead of 0.5, it is set to radians: switch it to degrees (look for a DRG or MODE key). Code uses radians too: see Code basics.
Going backwards: inverse cosine
If you know the ratio and want the angle, use the inverse cosine, \(\arccos\). Calculators label it \(\cos^{-1}\); it means "the angle whose cosine is", not \(1/\cos\). So \(\arccos 0.8 = 36.87°\) and \(\arccos 0.6 = 53.13°\). Inverse sine, \(\arcsin\), works the same way.
Practice
A right triangle has a hypotenuse of 10 and an angle of 30°. How long is the side opposite that angle? (\(\sin 30° = 0.5\).)
That’s the adjacent side, \(10\cos 30°\). The opposite side uses sine.
Hint
Opposite = hypotenuse × \(\sin\theta\).
Solution
\(10 \times \sin 30° = 10 \times 0.5 = 5\).
Set your calculator to degrees. What is \(\cos 60°\)?
That’s the cosine of 60 radians. Switch your calculator to degrees.
Hint
An equilateral triangle cut in half has angles 30°, 60° and 90°, and its short side is half the hypotenuse.
Solution
\(\cos 60° = 0.5\): in the half equilateral triangle, the side next to the 60° angle is half the hypotenuse.
A surveyor walks 100 m in a straight line, heading 10° north of east. How far north of her starting point does she end up, in meters?
That’s how far east she went, \(100\cos 10°\). North is the side opposite the 10° angle.
Hint
Her path is the hypotenuse. North is opposite the 10° angle, so use sine.
Solution
\(100 \times \sin 10° = 100 \times 0.1736 = 17.36\) m north (and \(100 \cos 10° = 98.48\) m east).
An angle has \(\cos\theta = 0.6\). What is the angle, in degrees?
That’s the angle in radians. Multiply by 180/π, or switch your calculator to degrees.
Hint
Use the inverse cosine, \(\cos^{-1}\) on a calculator.
Solution
\(\arccos 0.6 = 53.13°\). It’s the other sharp angle of the 3-4-5 triangle: \(53.13° + 36.87° = 90°\).
Squares and square roots
Squaring a number multiplies it by itself: \(7^2 = 49\). The square root undoes that: \(\sqrt{49} = 7\). Picture a square made of unit tiles. Its area is the square; its side is the square root.
Two rules carry most of the course. Roots of products split: \(\sqrt{4 \times 9} = \sqrt{4}\,\sqrt{9} = 6\). Roots of sums don’t: \(\sqrt{9 + 16} = 5\), not \(3 + 4 = 7\). And a negative number has no square root among ordinary numbers, which is why \(\sqrt{1 - v^2}\) needs \(v\) between −1 and 1 (that is, \(v^2\) below 1).
Practice
What is \(\sqrt{144}\)?
Hint
Which number times itself makes 144?
Solution
\(12 \times 12 = 144\), so \(\sqrt{144} = 12\).
What is \(\sqrt{0.36}\)?
Check it: \(0.06 \times 0.06 = 0.0036\). Square roots of numbers below 1 are bigger than the number.
Hint
\(0.36 = 36/100\), and you can take the root of the top and the bottom separately.
Solution
\(\sqrt{36/100} = 6/10 = 0.6\). You’ll meet it as \(\sqrt{1 - 0.8^2}\).
What is \(\sqrt{9 + 16}\)?
That’s \(\sqrt{9} + \sqrt{16}\). The root of a sum is not the sum of the roots. Add first.
Hint
Add first: \(9 + 16 = 25\).
Solution
\(\sqrt{25} = 5\), not 7.
Estimate \(\sqrt{50}\) to two decimal places. (A calculator is fine, but try first: \(7^2 = 49\).)
Hint
50 is a little more than 49, so the root is a little more than 7. Try \(7.07^2\).
Solution
\(7.07^2 = 49.98\), very close to 50, so \(\sqrt{50} \approx 7.07\). (Exactly, \(\sqrt{50} = 5\sqrt{2} = 7.0710\ldots\))
Slopes and graphs
The slope of a straight line is how much it rises for each step it runs: rise ÷ run. A line through (0, 0) and (4, 2) rises 2 while it runs 4, so its slope is \(2/4 = 0.5\). A line written \(y = m x + b\) has slope \(m\) and crosses the vertical axis at \(b\).
In a physics class, distance–time graphs put time along the bottom. A spacetime diagram puts time \(t\) pointing up, and distance \(x\) pointing right. A point on the diagram is an event, a time and a place, and the course writes it with time first: \((t, x)\). The path an object traces on the diagram is its worldline.
Because time points up, a moving object’s speed is how far it goes sideways for each step up: \(v = \Delta x / \Delta t\). That is run ÷ rise, the flip of the usual slope. So a steep line is slow, a vertical line is standing still, and a 45° line is light, which goes one step sideways for each step up.
Practice
What is the slope of the line through (0, 0) and (4, 2)?
That’s run ÷ rise. Slope is rise ÷ run.
Hint
Rise 2, run 4.
Solution
\(2 / 4 = 0.5\).
What is the slope of the line through (1, 1) and (4, 7)?
Hint
Rise \(7 - 1 = 6\), run \(4 - 1 = 3\).
Solution
\(6 / 3 = 2\).
On a spacetime diagram, a worldline passes the events \((t, x) = (0, 0)\) and \((10, 6)\). What is its speed \(v\)?
You divided up ÷ sideways. Speed is sideways ÷ up: \(x \div t\).
Hint
Speed is sideways ÷ up: \(x \div t\), not \(t \div x\).
Solution
\(v = 6 / 10 = 0.6\): 60% of light’s speed.
On the line \(t = 0.6\,x + 4\), what is \(t\) when \(x = 3\)?
Hint
Substitute: \(0.6 \times 3 + 4\).
Solution
\(1.8 + 4 = 5.8\).
Units as ratios
“60 minutes per hour” is a fraction equal to 1: \(\frac{60\ \text{min}}{1\ \text{h}} = 1\). Multiplying by 1 never changes a quantity, only its units. So to convert, multiply by fractions like that, arranged so the unit you don’t want cancels top against bottom. The top row of Toolkit 5 turns 3 hours into seconds this way.
Light’s speed is a conversion factor
The course’s most important conversion factor is light’s speed. Light covers exactly 299 792 458 meters every second. That lets the course measure time in meters. One meter of time is the time light takes to go one meter: 1 ÷ 299 792 458 of a second, about 3.3 nanoseconds (billionths of a second).
So 1 second and 299 792 458 meters of time are two names for the same amount of time, like 1 hour and 60 minutes. So this fraction equals 1, the same way \(\frac{60\ \text{min}}{1\ \text{h}}\) does:
\[ \frac{299\,792\,458\ \text{m of time}}{1\ \text{s}} = 1. \]
Multiplying by it turns seconds into meters of time without changing how much time you have.
In 1 meter of time, light goes 1 meter. So light’s speed is 1 m (of distance) ÷ 1 m (of time) = 1, with no units left over. Slower things get smaller numbers: a car covers only a tiny part of a meter in each meter of time.
Measure time in meters and every speed becomes a plain number, the fraction of light’s speed. The course calls it \(v\). Here is the move in both directions:
- \(v = 0.6\) means 0.6 × 299 792 458, about 180 000 000 meters per second.
- A car at 30 m/s has \(v\) = 30 ÷ 299 792 458, about 0.000 000 1. The bottom row of Toolkit 5 shows every unit cancelling.
Practice
How many seconds are there in 3 hours?
Hint
\(3 \times 60 \times 60\).
Solution
\(3\ \text{h} \times 60\ \tfrac{\text{min}}{\text{h}} \times 60\ \tfrac{\text{s}}{\text{min}} = 10\,800\ \text{s}\).
Convert 72 km/h into meters per second.
That multiplies by 3.6 instead of dividing. Is a meter per second faster or slower than a kilometer per hour?
Hint
Multiply by \(\frac{1000\ \text{m}}{1\ \text{km}}\) and by \(\frac{1\ \text{h}}{3600\ \text{s}}\).
Solution
\(72 \times 1000 / 3600 = 20\) m/s.
How many meters of time is one nanosecond (\(10^{-9}\) s)?
That’s how many nanoseconds make one meter of time. Go the other way: multiply by light’s speed.
Hint
One second is 299 792 458 m of time. Multiply by \(10^{-9}\).
Solution
\(299\,792\,458 \times 10^{-9} \approx\) 0.2998 m: roughly a foot. A nanosecond is “a foot of light”.
A rocket moves at \(v = 0.8\). What is that in meters per second? (Type big numbers without spaces, or like 3e8 for \(3 \times 10^8\).)
That divides by light’s speed. \(v\) is already a fraction of light’s speed, so multiply.
Hint
\(v = 0.8\) means 0.8 of light’s speed, and light’s speed is 299 792 458 m/s.
Solution
\(0.8 \times 299\,792\,458 \approx 240\,000\,000\) m/s, or \(2.4 \times 10^{8}\) m/s. In meters of time the rocket’s story is simpler: it goes 0.8 m for every meter of time.
Rearranging equations
An equation is a balance. Do the same thing to both sides and it stays balanced. To get a letter alone, undo whatever was done to it, in reverse order: if it was multiplied by 2 and then had 1 added, subtract 1 first, then divide by 2.
The course’s favorite rearrangement involves \(\gamma\) (gamma), the stretch factor: the number that says how big relativity’s effects are at a speed \(v\) (\(\gamma = 1\) means no effect at all). Its formula, \(\gamma = 1/\sqrt{1 - v^2}\), run backward gives the speed, \(v = \sqrt{1 - 1/\gamma^2}\). Each step is something you already know: flip both sides, square both sides, move a term across, take a root.
Show me the four steps
Suppose \(\gamma = 5/3\), so \(1/\sqrt{1 - v^2} = 5/3\). Find \(v\).
- Flip both sides: \(\sqrt{1 - v^2} = 3/5\).
- Square both sides: \(1 - v^2 = 9/25\).
- Move a term across: \(v^2 = 1 - 9/25 = 16/25\).
- Take a root: \(v = 4/5 = 0.8\).
Check: \(1 - 0.8^2 = 0.36\), \(\sqrt{0.36} = 0.6\), and \(1 \div 0.6 = 5/3\). The ★ item below uses the same four steps.
Practice
Distance = speed × time: \(d = v\,t\). If \(d = 12\) and \(v = 0.6\), what is \(t\)?
That multiplies 12 by 0.6. To undo “times \(v\)”, divide by \(v\).
Hint
Divide both sides by \(v\): \(t = d / v\).
Solution
\(t = 12 / 0.6 = 20\).
Solve \(2x + 1 = 5\) for \(x\).
Hint
Subtract 1 from both sides first.
Solution
\(2x = 4\), so \(x = 2\).
If \(y^2 = 25 - 9\) and \(y\) is positive, what is \(y\)?
That’s \(y^2\). One more step: take the square root.
Hint
\(y^2 = 16\).
Solution
\(y = \sqrt{16} = 4\).
If \(\dfrac{1}{\sqrt{1 - v^2}} = 1.25\), what is \(v\) (positive)?
That’s \(\sqrt{1 - v^2}\), not \(v\). Keep going: square it and subtract from 1.
Hint
Flip both sides: \(\sqrt{1 - v^2} = 1/1.25 = 0.8\).
Hint
Square both sides: \(1 - v^2 = 0.64\).
Solution
\(\sqrt{1 - v^2} = 0.8\), so \(1 - v^2 = 0.64\), so \(v^2 = 0.36\) and \(v = 0.6\). That’s the friendliest speed in the course: \(\gamma = 5/4\) at \(v = 3/5\).
Fractions
The course’s friendliest speeds are fractions: 3/5, 4/5, 5/13, 12/13. Working with them exactly keeps the answers clean. Three moves cover almost everything. To add, use a common bottom: \(\tfrac{3}{5} + \tfrac{4}{5} = \tfrac{7}{5}\). To divide by a fraction, multiply by its flip: \(1 \div \tfrac{4}{5} = \tfrac{5}{4}\). To square, square the top and the bottom: \(\left(\tfrac{3}{5}\right)^2 = \tfrac{9}{25}\).
Practice
\(\tfrac{3}{5} + \tfrac{4}{5} = \;?\) (A fraction like 7/5 is fine.)
That adds the bottoms too. With a common bottom, add only the tops.
Hint
Same bottom, so add the tops.
Solution
\(\tfrac{7}{5} = 1.4\).
\(1 \div \tfrac{4}{5} = \;?\)
Dividing by a number below 1 gives something bigger than you started with. Flip the fraction.
Hint
Multiply by the flip, \(\tfrac{5}{4}\).
Solution
\(\tfrac{5}{4} = 1.25\).
\(\left(\tfrac{3}{5}\right)^2 = \;?\)
That doubles instead of squaring. Square the top and the bottom.
Hint
\(3^2 = 9\) and \(5^2 = 25\).
Solution
\(\tfrac{9}{25} = 0.36\).
\(1 - \left(\tfrac{3}{5}\right)^2 = \;?\)
Hint
Write 1 as \(\tfrac{25}{25}\).
Solution
\(\tfrac{25}{25} - \tfrac{9}{25} = \tfrac{16}{25}\), which is \(\left(\tfrac{4}{5}\right)^2\). Its square root is \(\tfrac45\), and one over that is \(\tfrac54\).
Exponentials and logarithms
The number \(e \approx 2.718\) is the natural base for growth and decay. \(e^x\) means \(e\) multiplied by itself \(x\) times (and it makes sense for any \(x\), not only whole numbers). The natural logarithm \(\ln\) undoes it: \(\ln(e^x) = x\), and \(e^{\ln y} = y\).
The rule that makes logarithms useful: they turn multiplying into adding, \(\ln(a\,b) = \ln a + \ln b\). Decay uses \(e\) too: for muons sitting still in a lab, the fraction still alive after a time \(t\) is \(e^{-t/\tau}\), where \(\tau\) is the average lifetime, 2.2 μs. For fast muons, the key question is: whose clock measures \(t\)? A later chapter answers it.
Practice
What is \(\ln\!\left(e^3\right)\)?
Hint
\(\ln\) undoes \(e^{(\ )}\).
Solution
3: the logarithm hands back the power.
What is \(e^0\)?
Any number to the power 0 is 1, not 0. (Check the graph: where does \(e^x\) cross the vertical axis?)
Hint
Look at where the blue curve crosses \(x = 0\).
Solution
\(e^0 = 1\).
\(\ln 2 + \ln 3 = \ln N\). What is \(N\)?
Logarithms turn multiplying into adding, so adding logarithms means multiplying the numbers.
Hint
\(\ln a + \ln b = \ln(a\,b)\).
Solution
\(\ln(2 \times 3) = \ln 6\), so \(N = 6\).
A batch of muons sits still in a lab for two average lifetimes. What fraction is still alive? (It’s \(e^{-2}\); give a decimal.)
Hint
\(e^{-2} = 1/e^2 \approx 1/7.39\).
Solution
\(e^{-2} \approx 0.135\): about 13.5%, roughly one in seven.
Approximations for small numbers
When a number is tiny, some awkward formulas shrink to arithmetic you can do in your head. Take \(x\) = 0.01. Then 1 − \(x\) = 0.99, and 1 ÷ 0.99 = 1.0101…, very nearly 1 + \(x\) = 1.01. And 1 ÷ √0.99 = 1.00504…, very nearly 1 + \(x\)/2 = 1.005. The pattern holds for any tiny number \(x\):
\[ \begin{aligned} \frac{1}{1 - x} &\approx 1 + x, \\[8pt] \frac{1}{\sqrt{1 - x}} &\approx 1 + \frac{x}{2}. \end{aligned} \]
Two cousins work the same way. Flip the sign: \(1/(1 + x) \approx 1 - x\) (1 ÷ 1.01 = 0.990…). Square: \((1 + x)^2 \approx 1 + 2x\) (1.01² = 1.0201).
Why do they work?
Tiny times tiny is tinier still. 0.99 × 1.01 = 0.9999, which misses 1 by only 0.01². Ignore it, and 1.01 is the flip of 0.99. Likewise, 1.005² = 1.010 025, which is 1.01 once you ignore the tiny 0.000 025. So 1.005 is very nearly 1 ÷ √0.99.
What it means for speeds
The stretch factor \(\gamma\) (the Greek letter gamma) is the number that says how big relativity’s effects are at a speed \(v\) (\(\gamma = 1\) means no effect at all). Its formula is \(\gamma = 1/\sqrt{1 - v^2}\), and Chapter 5 builds it from a clock made of light. Put \(x = v^2\) into the second shortcut and you get the course’s most useful one:
\[ \gamma \approx 1 + \tfrac12 v^2. \]
Watch the units
Here \(v\) is not in meters per second. It is the speed as a fraction of light’s speed, so light has \(v = 1\) (see Units as ratios). A car at 30 m/s has \(v\) = 30 ÷ 299 792 458, about 0.000 000 1. Half of its square is about 0.000 000 000 000 005. Put in 30 for \(v\) and you get ½ × 30² = 450, which means nothing here.
So the car’s \(\gamma\) is 1.000 000 000 000 005, and a 10-digit calculator shows 1. A jet airliner at 250 m/s has \(v\) of about 0.000 000 83, and half its square is about 0.000 000 000 000 35. That is why relativity hides at the speed of a car or a plane: it is there, 13 or more places after the decimal point. The shortcut works only for small \(v\): at \(v = 0.995\) it gives 1.5, but the true \(\gamma\) is 10.
Practice
Use the shortcut to estimate \(\dfrac{1}{1 - 0.01}\).
Hint
\(1/(1 - x) \approx 1 + x\) with \(x = 0.01\).
Solution
\(1 + 0.01 = 1.01\). The exact value is 1.0101…, so the shortcut is off by about one part in ten thousand.
Use the shortcut to estimate \(\dfrac{1}{\sqrt{1 - 0.02}}\).
That’s the shortcut for \(1/(1 - x)\). With a square root, use half of \(x\).
Hint
\(1/\sqrt{1 - x} \approx 1 + x/2\) with \(x = 0.02\).
Solution
\(1 + 0.01 = 1.01\) (exact: 1.01015…).
Estimate the stretch factor \(\gamma\) at \(v = 0.1\) using \(\gamma \approx 1 + \tfrac12 v^2\).
That’s \(1 + v^2\), the shortcut without a square root. \(\gamma\) has a square root, so add only half of \(v^2\).
That adds half of \(v\). Square \(v\) first: \(0.1^2 = 0.01\), then take half.
Hint
\(v^2 = 0.01\), and half of that is 0.005.
Solution
\(1 + 0.005 = 1.005\). The exact value is \(1/\sqrt{0.99} = 1.00504\ldots\)
A satellite moves at 3 km/s. As a fraction of light’s speed, that is about \(v = 10^{-5}\) (0.000 01). By how much does \(\gamma\) exceed 1? Give \(\gamma - 1\). (Type tiny numbers like 2e-9 for \(2 \times 10^{-9}\).)
That’s \(v^2\). The shortcut adds only half of it: \(\tfrac12 v^2\).
Hint
\(\gamma - 1 \approx \tfrac12 v^2\), and \(v^2 = 10^{-10}\).
Solution
\(\tfrac12 \times 10^{-10} = 5 \times 10^{-11}\), or 0.000 000 000 05. Most calculators can’t even show \(\gamma\) itself to that many digits; the shortcut gets the tiny difference directly.
cosh, sinh and tanh
Chapter 13 builds these functions and uses them for speeds. If no chapter has sent you here yet, it is fine to skip this section for now.
These three functions sound exotic, but they are built from \(e^x\) with plain arithmetic:
\[ \begin{aligned} \cosh\theta &= \frac{e^{\theta} + e^{-\theta}}{2}, \\[6pt] \sinh\theta &= \frac{e^{\theta} - e^{-\theta}}{2}, \\[6pt] \tanh\theta &= \frac{\sinh\theta}{\cosh\theta}. \end{aligned} \]
Try \(\theta = \ln 2\), so \(e^{\theta} = 2\) and \(e^{-\theta} = \tfrac12\). Then \(\cosh\theta = (2 + 0.5)/2 = 1.25\), \(\sinh\theta = (2 - 0.5)/2 = 0.75\), and \(\tanh\theta = 0.75/1.25 = 0.6\). All three belong to the speed \(v = 0.6\) (3/5): 0.6 is \(v\) itself, 1.25 is its stretch factor \(\gamma\), and 0.75 is \(\gamma v\), a number a later chapter puts to work.
Now check: \(1.25^2 - 0.75^2 = 1.5625 - 0.5625 = 1\). That is no coincidence: \(\cosh^2\theta - \sinh^2\theta = 1\) for every \(\theta\). So the point \((\cosh\theta, \sinh\theta)\) always lies on the hyperbola \(x^2 - y^2 = 1\), the same way \((\cos\phi, \sin\phi)\) always lies on the circle \(x^2 + y^2 = 1\).
Why is cosh² − sinh² always 1?
Write \(p = e^{\theta}\) and \(q = e^{-\theta}\). Their product is \(e^{0} = 1\). Also \(\cosh\theta = (p + q)/2\) and \(\sinh\theta = (p - q)/2\). So:
\[ \begin{aligned} &\cosh^2\theta - \sinh^2\theta \\[4pt] &\quad = \frac{(p + q)^2 - (p - q)^2}{4} \\[6pt] &\quad = \frac{4pq}{4} = 1. \end{aligned} \]
Expand both squares to see the middle step: everything cancels except \(4pq\).
Practice
What is \(\cosh 0\)?
That’s \(\sinh 0\). For cosh, add: \((e^0 + e^0)/2\).
Hint
\(e^0 = 1\).
Solution
\((1 + 1)/2 = 1\): the point where the hyperbola touches the circle.
With \(e^{\theta} = 2\), what is \(\cosh\theta\)?
\(e^{-\theta}\) is \(1/e^{\theta} = 0.5\), not 0. Add it to 2 and halve.
Hint
\(e^{-\theta} = 1/2\).
Solution
\((2 + 0.5)/2 = 1.25\).
With \(e^{\theta} = 2\), what is \(\sinh\theta\)?
Hint
Subtract instead of adding: \((2 - 0.5)/2\).
Solution
\(1.5/2 = 0.75\).
With \(e^{\theta} = 2\), what is \(\tanh\theta\)?
That’s cosh ÷ sinh, upside down. tanh is sinh ÷ cosh.
Hint
\(\tanh = \sinh / \cosh = 0.75 / 1.25\).
Solution
\(0.6\), the speed 3/5. A later chapter calls this \(\theta\) the rapidity of that speed.
Code basics
Every “Build it” section asks for one small JavaScript function. Here is everything the first one needs, for reference. Later chapters add a little more, and each addition is explained right where it’s first used.
- A function has a name, inputs in brackets (parameters), and a body in braces.
returnsends back the answer. - Arithmetic:
+ - * /. Powers:3 ** 2is 9. Brackets work as in algebra:(1 + 2) * 3is 9. - Square roots:
Math.sqrt(49)is 7. Pythagoras in one call:Math.hypot(3, 4)is 5. - Scientific notation:
3e8is \(3 \times 10^8\) and2.2e-6is \(2.2 \times 10^{-6}\). - Angles:
Math.cosandMath.sinuse radians, not degrees, so convert first:Math.cos(60 * Math.PI / 180)gives 0.5 (to 15 decimal places). Going backwards,Math.acos(0.8)gives radians (0.6435); multiply by180 / Math.PIto get degrees (36.87). - The test table lists each test’s name (what it checks), the Input it tried, the Expected answer, what your function returned (Got) and the Result. Fix the first failing row first. For that row, compare Got with Expected for the same Input.
Here is a made-up table for double(x), written by mistake as return x + 2;.
| Test | Input | Expected | Got | Result |
|---|---|---|---|---|
| doubles 2 | double(2) | 4 | 4 | pass |
| doubles 21 | double(21) | 42 | 23 | fail |
The first row passes by luck: 2 + 2 and 2 × 2 are both 4. The second row fails. For the input 21, Expected says 42 but Got says 23, which is 21 + 2. So the function adds 2 where it should multiply by 2.
double(21) runs the body with x = 21 and returns 42.Practice
What is 3 ** 2?
Hint
** raises to a power.
Solution
\(3^2 = 9\).
Given function triple(x) { return 3 * x + 1; }, what does triple(4) return?
That computes \(3 \times (4 + 1)\). Multiplication happens before addition.
That’s \(3 \times 4\). Don’t forget the \(+ 1\).
Hint
Put 4 in place of x.
Solution
\(3 \times 4 + 1 = 13\).
Which line correctly returns the long side of a right triangle with legs a and b?
Hint
Try each with \(a = 3, b = 4\). Which gives 5?
Solution
Math.sqrt(a * a + b * b) gives \(\sqrt{25} = 5\).
In the test table, which column shows what your function actually returned?
Hint
Which column would change if you changed your code?
Solution
Got. When it differs from Expected, that row fails.
Ready to use it? The prologue’s Build it section has a one-line warm-up and your first function.