The language of patterns: numbers, unknowns, functions and the rules they follow.
From counting and fractions to matrices, eigenvectors and the abstract algebra behind them. You start with numbers and the rules of arithmetic, learn to use letters for unknowns, solve equations and inequalities, and meet functions, graphs, polynomials, exponentials, logarithms, sequences and series. Then trigonometry, complex numbers, vectors and matrices, linear algebra and, last, groups, rings and fields. Every idea is explained in words, drawn on graphs you can drag, and practised with problems worked on paper, exercises and small programs that compute it.
What you’ll be able to do
Work confidently with integers, fractions, powers, roots and percentages, and estimate before you calculate.
Write, simplify and solve linear, quadratic, rational, radical, exponential and logarithmic equations, and systems of them.
Read and sketch functions and their graphs, and transform them: shift, stretch, reflect, compose and invert.
Use trigonometry, complex numbers and vectors to describe angles, rotations and directions.
Calculate with matrices, solve linear systems by elimination, and explain determinants, eigenvalues and eigenvectors.
Sum arithmetic and geometric series, read and write simple proofs (induction among them), and recognise the structures (groups, rings, fields) that algebra studies.
Modules
Numbers and what they count· 14 slides
Arithmetic, properly· 12 slides
Fractions, decimals, percentages and ratios· 14 slides
Powers, roots and scientific notation· 14 slides
Letters for numbers: variables and expressions· 11 slides
Solving linear equations· 13 slides
Inequalities and absolute value· 12 slides
Functions: a rule from inputs to outputs· 11 slides
Lines and slope· 12 slides
Systems of equations· 12 slides
Polynomials and factoring· 13 slides
Quadratic equations and parabolas· 13 slides
Rational and radical expressions· 12 slides
Exponentials and logarithms· 13 slides
Sequences, series and induction· 14 slides
Angles, triangles and trigonometry· 13 slides
Complex numbers· 13 slides
Vectors and matrices· 15 slides
Linear maps, determinants and eigenvectors· 15 slides
Abstract algebra and thinking like a mathematician· 14 slides
Interactive parts (exercises, code to run, walkthroughs, flashcards, checklists) are drawn still and marked “Interactive · disabled in the PDF”. Do them in the app; the answers are at the end.
Module 1: Numbers and what they count
Algebra1 / 260
Module 1 · Numbers and what they count
Numbers began as a way to count
Algebra is the study of numbers and the rules they follow, so it starts with the numbers themselves. The first ones anybody uses are the counting numbers: 1, 2, 3, and so on, as many as you like. Add zero, the number of things in an empty box, and you have the natural numbers. Mathematicians write the set of them with a doubled letter, .
The braces mean “the set of”; the dots mean “and so on, forever”.
Every natural number has a next one, so there is no largest. You can always add two of them and get another natural number. You cannot always subtract: has no answer among the naturals. Each new kind of number in this module exists to fill a gap like that one.
Natural number
A counting number or zero: 0, 1, 2, 3, …
Set
A collection of things, written in braces: .
Element
One of the things in a set. is an element of , written .
Going deeper
Does ℕ start at 0 or 1?. Books disagree. The international standard for mathematical notation (ISO 80000-2) and most of computer science start at 0; many number theory books start at 1. When it matters, writers say which, or write for the version with 0. In this course, includes 0.
Algebra2 / 260
Module 1 · Numbers and what they count
Ten digits write every natural number
We write numbers with ten digits, 0 to 9, and the place of a digit says what it is worth. In 3407 the 7 counts ones, the 0 counts tens, the 4 counts hundreds and the 3 counts thousands. Each place is worth ten times the one to its right, which is why this is called the decimal (base ten) system.
Thousands
Hundreds
Tens
Ones
3
4
0
7
Zero matters here: it holds the tens place open. Without it, 3407 and 347 would look the same. Roman numerals had no zero and no places, which is one reason long sums in them were so hard.
QuizInteractive · disabled in the PDF
In the number 52 816, what is the digit 2 worth?
In the number 52 816, what is the digit 2 worth?
ProblemInteractive · disabled in the PDF
In the number 47 305, what is the 7 worth, and what is the 3 worth? Then write as one number.
Algebra3 / 260
Module 1 · Numbers and what they count
Code in this course: your first C++ program
Some ideas in this course are worth computing, so its exercises include small programs, written in C++. You need no programming to start: this slide and the next teach the C++ they are built from, and anything more is explained where it first appears. You write C++ as text, a compiler turns it into instructions the machine runs, and then it runs. Here the compiler (Clang) works inside this page: press Run.
PlaygroundInteractive · disabled in the PDF
C++
1#include<cmath>2#include<iostream>34intmain(){5int apples =7; // a whole number6double price =0.35; // a number with a fraction7bool cheap = price <1; // true or false8 std::cout <<"Cost: "<< apples * price <<"\n";9 std::cout <<"Cheap? "<< cheap <<"\n";10 std::cout <<7/2<<" but "<<7.0/2<<"\n";11 std::cout << std::sqrt(2.0)<<" "<< std::pow(2,10)<<"\n";12return0;13}
Change the numbers and run it again. A bool prints as 1 (true) or 0 (false).
#include <iostream> brings in the part of the standard library (the code that comes with C++) that prints. #include <cmath> brings in the maths: std::sqrt, std::pow, std::abs, std::floor, std::round, and later std::exp, std::log and std::sin.
int main() is where the program starts. The { } braces hold its steps, each ending in ;, and return 0; says it finished well.
std::cout << x prints x, and "\n" starts a new line. std:: says the name comes from the standard library.
A variable is a named box with a type that never changes: int for whole numbers, double for numbers with a fraction, bool for true or false. Text after // is a comment, for people: the compiler skips it.
Two traps for a mathematician. Dividing two ints gives an int: the fraction is thrown away, so 7 / 2 is 3 and 1 / 2 is 0. Make one side a double (7.0 / 2) to get 3.5. And C++ has no power operator: is std::pow(2, 10). 2 ^ 10 compiles, but it is 8: ^ is a different operation (exclusive or, on the numbers’ binary digits).
Predict the outputInteractive · disabled in the PDF
What does this line print?
C++
1std::cout <<9/4<<" "<<9.0/4<<" "<<1/3;
What does this line print?
Algebra4 / 260
Module 1 · Numbers and what they count
Functions, decisions, loops and lists in C++
A function is named steps you can use again: the type of its answer, its name, then its parameters (the values it is given) in brackets. It hands its answer back with return. Here is one for the area of a circle, one for the mean of a list, and a loop that decides between odd and even.
PlaygroundInteractive · disabled in the PDF
C++
1#include<iostream>2#include<vector>34doublearea(double r){ // given a double, returns one5return3.14159* r * r;6}78doublemean(const std::vector<double>& xs){9double total =0;10for(double x : xs) total += x; // each x in the list, in turn11return total / xs.size();12}1314intmain(){15 std::cout <<area(2)<<"\n";16for(int i =1; i <=4; i++){ // i = 1, 2, 3, 417if(i %2==0){ // == compares; = would store18 std::cout << i <<" is even\n";19}else{20 std::cout << i <<" is odd\n";21}22}23 std::vector<double> marks ={12,15,9};24 marks.push_back(16); // add one at the end25 std::cout << marks[0]<<" of "<< marks.size()<<"\n";26 std::cout <<"mean "<<mean(marks)<<"\n";27}
Change the list, or the loop’s 4, and run it again.
double area(double r) is given a double called r and returns a double. area(2) calls it, with r as 2.
if (…) { … } else { … } runs one branch or the other. == compares (= stores), != is “not equal”, && is “and”, || is “or”, and % is the remainder: i % 2 == 0 means i is even.
for (int i = 1; i <= 4; i++) starts i at 1, runs while i <= 4, and adds one (i++) after each turn. while (n > 0) { … } repeats while its condition holds. total += x is short for total = total + x.
std::vector<double> (from <vector>) is a list of doubles: {12, 15, 9} makes one, marks[0] is the first (positions count from 0), marks.size() is how many, push_back adds one at the end, and for (double x : marks) visits each in turn.
const std::vector<double>& xs lets a function read the caller’s list without copying it or changing it.
How the code exercises work. A challenge asks for one function, with no main. You finish it, and tests call it and check what it returns: EXPECT_EQ(area(1), …) wants exactly that value, and EXPECT_NEAR(actual, expected, within) wants a decimal close to it, because computed decimals are rarely exact. “See the tests” shows them: they are the spec.
Fill the blanksInteractive · disabled in the PDF
Finish the function that adds up the squares of a list, so that gives 14.
C++
1#include<vector>23sumOfSquares(const std::vector<double>& xs){4double total =;5(double x : xs){6 total +=;7}8 total;9}
Algebra5 / 260
Module 1 · Numbers and what they count
Try it: split a number into its places
A computer finds the digits of a number with two operations. n % 10 is the remainder when you divide by 10, which is the ones digit. n / 10 drops that digit, because dividing one int by another throws the fraction away: the trap from two slides ago, put to work. Repeat until nothing is left, and each digit times its place value gives the pieces of the sum from before.
Code challengeInteractive · disabled in the PDF
Write placeValues(n): for a natural number n, return what each digit is worth, biggest place first. placeValues(3407) is {3000, 400, 0, 7}, and placeValues(0) is {0}. parts.insert(parts.begin(), x) puts x at the front of a vector.
C++
1#include<vector>23std::vector<int>placeValues(int n){4 std::vector<int> parts;5 // TODO: take off the ones digit, times its place,6 // until n is 07return parts;8}
Algebra6 / 260
Module 1 · Numbers and what they count
Negative numbers fill the gap below zero
To make have an answer, we add negative numbers: , written with a minus sign. You already use them: a temperature of degrees is 4 below zero, and a bank balance of is a debt of 20. The naturals and their negatives together are the integers, written (from the German Zahlen, “numbers”).
The number line is the picture to keep in your head: zero in the middle, positives to the right, negatives to the left, each integer one step from the next. Adding moves you right, subtracting moves you left. Drag the slider to move from 3, five steps left.
3 − k−2
Subtracting 5 from 3 walks five steps left and lands below zero, on −2.
QuizInteractive · disabled in the PDF
At 6 in the morning it was degrees. By noon it was 7 degrees warmer. What was the temperature at noon?
At 6 in the morning it was degrees. By noon it was 7 degrees warmer. What was the temperature at noon?
Algebra7 / 260
Module 1 · Numbers and what they count
Further right is bigger
On the number line, of two numbers the one further right is the bigger. We write for “ is less than ” and for “ is greater than ”; the open side of the sign faces the bigger number. For negatives this can feel backwards: , because is further left. Being 7 below zero is colder than being 2 below.
Symbol
Read as
Example
is less than
is greater than
is less than or equal to
is greater than or equal to
Put in orderInteractive · disabled in the PDF
Put these numbers in order, smallest first.
1.
2.
3.
4.
5.
6.
Algebra8 / 260
Module 1 · Numbers and what they count
Absolute value is distance from zero
The absolute value of a number is how far it is from zero, ignoring direction. It is written with two upright bars: and , because both are five steps from zero. A distance is never negative, so for every , and only when .
The distance between any two numbers and is . Subtracting finds the gap; the bars throw away which way you went. From to is steps. Drag both points and watch the readout.
|a − b|7
|a|3
The distance between a and b is the same whichever you start from.
Code challengeInteractive · disabled in the PDF
Write distance(a, b): how far apart a and b are on the number line. It must never be negative. std::abs(x), from <cmath>, gives the absolute value of x.
C++
1#include<cmath>23doubledistance(double a,double b){4return b - a;5}
ProblemInteractive · disabled in the PDF
Work out and . Then find the distance between and on the number line.
Algebra9 / 260
Module 1 · Numbers and what they count
Fractions fill the gaps between integers
Integers let you subtract freely, but not divide: is not an integer. So we add fractions: a number , where and are integers and is not zero. These are the rational numbers (from ratio), written for quotient. Every integer is one too: .
Read it as: all numbers p over q, where p and q are integers and q is not zero.
Rationals are dense: between any two of them there is another. Their average, , is always between them, and it is rational too. So there are no gaps you could point to between rationals. And yet, as the next slide shows, the line still has holes.
Written as decimals, rationals either stop, like , or settle into a block of digits that repeats for ever, like (Module 3 shows why). A bar over the block marks the repeat: .
QuizInteractive · disabled in the PDF
Which number lies between and ?
Which number lies between and ?
Algebra10 / 260
Module 1 · Numbers and what they count
Some lengths are not fractions
A square with sides of 1 metre has a diagonal with (Pythagoras’ theorem). So , the number whose square is 2. The ancient Greeks found, to their alarm, that no fraction squares to exactly 2. A number that is not rational is irrational. Its decimal goes on for ever without repeating:
Both p and q even means the fraction was not in lowest terms after all. The only way out: no such fraction exists.
This is a proof by contradiction: assume the opposite, follow the rules, and reach something impossible. It is the first proof most people meet, and it shows what algebra can do that trying examples cannot: it settles the question for every fraction at once, including ones too big to ever write down.
QuizInteractive · disabled in the PDF
Which of these are irrational? Choose all that are.
Which of these are irrational? Choose all that are.
Going deeper
The step “ even, so even” needs its own reason. If were odd, , then , which is odd. So an even square must come from an even number. The same argument with 3 in place of 2 shows is irrational; in fact is irrational for every natural that is not a perfect square.
Algebra11 / 260
Module 1 · Numbers and what they count
Fractions get close to the square root of 2, never there
The proof says no fraction works; a computer can show how close they get. For each bottom number , the program takes the nearest top number and measures how far is from . If were exactly , the gap would be 0. Run it: the best fractions miss by exactly 1, every time.
PlaygroundInteractive · disabled in the PDF
C++
1#include<cmath>2#include<iomanip>3#include<iostream>4#include<numbers>56intmain(){7 std::cout << std::setprecision(17); // all the digits8 // Look for p/q with p * p exactly 2 * q * q.9 // long long: an int that holds whole numbers up to 9.2e1810for(longlong q =1; q <=500; q++){11longlong p = std::llround(q * std::numbers::sqrt2);12longlong gap = p * p -2* q * q;13if(gap ==0) std::cout <<"A fraction for root 2!\n";14if(std::abs(gap)==1){15 std::cout << p <<"/"<< q <<" = "<<1.0* p / q;16 std::cout <<", gap "<< gap <<"\n";17}18}19 std::cout <<"sqrt2 = "<< std::numbers::sqrt2 <<"\n";20}
1/1, 3/2, 7/5, 17/12, 41/29… each a little closer. (7/5 prints as 1.3999999999999999: the double nearest 1.4, shown in full.) Raise 500 to 100000: the “A fraction” line never prints.
A computer stores no irrational numbers.std::numbers::sqrt2 (from <numbers>) is a fraction with a power of two underneath, the closest one a double, a 64-bit floating-point number, can hold. Every number a computer stores this way is rational. Irrationals exist in the maths, and the computer works with rationals close to them, which is why calculations on a computer pick up tiny rounding errors. (std::llround rounds to the nearest whole number, and 1.0 * p / q keeps the division from throwing the fraction away.)
Algebra12 / 260
Module 1 · Numbers and what they count
The real numbers fill the whole line
Put the rationals and the irrationals together and you get the real numbers, : every point on the number line, with no holes left. Each kind of number contains the one before it, so a number can belong to several sets at once. is an integer, a rational and a real.
⊂ means “is inside”: every natural is an integer, every integer is rational, every rational is real.
Real numbers ℝthe whole line; limits of rationals; √2, π
Rational numbers ℚp/q; division always works (except by 0)
Natural numbers ℕ0, 1, 2, …; addition and multiplication work
Each kind of number was added so an operation always has an answer.
QuizInteractive · disabled in the PDF
What is the smallest of the sets that contains ?
What is the smallest of the sets that contains ?
Going deeper
More irrationals than rationals. Both sets are infinite, but not equally so. The rationals can be listed one after another (Cantor did it in 1874), so they are countable. The reals cannot: any list of them misses one, which Cantor proved with his diagonal argument. So almost every real number is irrational, even though the ones we name every day are mostly rational.
Algebra13 / 260
Module 1 · Numbers and what they count
Practice problems
ProblemInteractive · disabled in the PDF
At 6 in the morning it was degrees. By 2 in the afternoon it had risen 13 degrees, and by midnight it had fallen 7 degrees from there. What was the temperature at 2 in the afternoon, and at midnight? How many degrees apart were the coldest and the warmest of these three readings?
degrees
degrees
degrees
ProblemInteractive · disabled in the PDF
Find the number exactly halfway between and on the number line. How far is it from each of them?
ProblemInteractive · disabled in the PDF
How many integers lie between and on the number line? How many of those are natural numbers?
ProblemInteractive · disabled in the PDF
A building’s floors are numbered from (the lowest car park) up to . A lift starts on floor , goes up to floor , and then down to floor . How many floors does it travel on each trip, and in all?
Place value: each digit is worth ten times the same digit one place to its right.
Integers add negatives, so subtraction always has an answer.
On the number line, further right is bigger: .
is the distance from to 0; is the distance between and .
Rationals are fractions ; their decimals stop or repeat.
Irrationals like and are not fractions; their decimals never repeat.
The reals are the whole line: .
FlashcardsInteractive · disabled in the PDF
Natural numbers
: the counting numbers and zero.
Integers
: the naturals and their negatives.
Rational number
A fraction of integers with .
Irrational number
A real number that is no fraction: , .
Absolute value
The distance from to 0. Never negative.
Distance between and
, whichever order you subtract in.
Proof by contradiction
Assume the opposite, reason correctly, reach something impossible.
Dense
Between any two, there is another: true of the rationals.
Module 2: Arithmetic, properly
Algebra15 / 260
Module 2 · Arithmetic, properly
An agreed order makes a sum mean one thing
What is ? Working left to right gives ; multiplying first gives . Both are fair readings, so everyone has agreed on one: the order of operations. It is a convention, a rule people chose, not a fact of nature, and its job is that a written sum means the same to everybody. The agreed answer is 14.
Brackets first, innermost first.
Powers (and roots), like .
Multiplication and division, left to right, as equals.
Addition and subtraction, left to right, as equals.
Left to right inside a level. Multiplication does not beat division, and addition does not beat subtraction. They share a level and go left to right. So , not . Memory aids like “BODMAS” or “PEMDAS” list them one by one, which is how this mistake is made.
QuizInteractive · disabled in the PDF
What is ?
What is ?
ProblemInteractive · disabled in the PDF
Work out and .
Algebra16 / 260
Module 2 · Arithmetic, properly
Programming languages use the same order
C++ follows the same convention: *, / and % before + and -, each level left to right, and brackets to override. It has no power operator: is std::pow(2, 3), a function call, worked out before anything around it. Beware 2 ^ 3: it compiles, but ^ is exclusive or on the numbers’ binary digits, and 2 ^ 3 is 1. When you are not sure, add brackets: they cost nothing and make your meaning plain to the next reader.
Predict the outputInteractive · disabled in the PDF
Powers stack from the top. A tower of powers is read from the top down: , not . With no power operator, C++ makes you write the order yourself: std::pow(2, std::pow(3, 2)) is 512. And means in maths; in C++ you choose with the call, -std::pow(3, 2) for −9 or std::pow(-3, 2) for 9. The trap is ^: -3 ^ 2 compiles and gives −1, which has nothing to do with powers.
Algebra17 / 260
Module 2 · Arithmetic, properly
Order and grouping do not matter for adding and multiplying
Two laws let you rearrange freely. Commutative: the order of two numbers does not change the answer. Associative: how you group three numbers does not change it either. Both hold for addition and for multiplication, for every real number. The letters stand for any numbers: that is what makes them laws, not examples.
Written next to each other, letters mean multiplied: ab is a × b.
They are what make mental arithmetic possible: . Subtraction and division have neither law: , and but .
QuizInteractive · disabled in the PDF
For which of these is true for all numbers, where is the operation?
For which of these is true for all numbers, where is the operation?
Algebra18 / 260
Module 2 · Arithmetic, properly
Multiplying spreads over a sum
The distributive law connects the two operations: multiplying a sum is the same as multiplying each part and adding. Picture a rectangle wide and long: its area is , and it is also the two smaller rectangles, and , side by side. It is the law behind almost every simplification in algebra, from Module 5 on.
Split an awkward number into a friendly one and a small correction.
Fill the blanksInteractive · disabled in the PDF
Fill the blanks so each comparison is true. Each uses the distributive law.
C++
1bool first =6*103==6*100+6*;2bool second =9*49==9*50-9*;3bool third =4*12+4*8==4*;
Algebra19 / 260
Module 2 · Arithmetic, properly
Zero and one change nothing
Adding 0 leaves a number alone, and so does multiplying by 1: they are the identity elements of addition and multiplication. Each number also has an inverse that brings you back to the identity. For addition it is the opposite, . For multiplication it is the reciprocal, .
Addition
Multiplication
Identity
Inverse
, if
Undoing
subtracting is adding the opposite
dividing is multiplying by the reciprocal
The last row is the useful one. is , and is . So subtraction and division are not new operations, just adding and multiplying by an inverse. Solving equations in Module 6 is nothing but applying inverses.
QuizInteractive · disabled in the PDF
Which number has no reciprocal?
Which number has no reciprocal?
Algebra20 / 260
Module 2 · Arithmetic, properly
Primes are the numbers with no smaller factors
A whole number divides , written , when leaves no remainder; then is a factor (or divisor) of and is a multiple of . A prime is a natural number with exactly two factors, 1 and itself: 2, 3, 5, 7, 11, 13, … A number above 1 that is not prime is composite. 1 is neither: it has only one factor.
Factors of each number from 1 to 20. The primes, highlighted, have exactly two.
Divisible by
When
2
the last digit is even
3
the sum of the digits is divisible by 3
5
the last digit is 0 or 5
9
the sum of the digits is divisible by 9
10
the last digit is 0
QuizInteractive · disabled in the PDF
Which of these are prime? Choose all that are.
Which of these are prime? Choose all that are.
Going deeper
Why stop testing at ? If with both factors bigger than , their product would be bigger than . So any composite has a factor at most . And there are infinitely many primes (Euclid, around 300 BC): multiply any finite list of primes and add 1; the result leaves remainder 1 when divided by each prime on the list, so its prime factors are new ones.
Algebra21 / 260
Module 2 · Arithmetic, properly
Every number is a product of primes in one way
Keep splitting a composite number into factors until every piece is prime. However you split, you end with the same primes: this is the fundamental theorem of arithmetic. Primes are the atoms that every natural number above 1 is built from, and the prime factorisation is its recipe.
360
36
6
2
3
6
2
3
10
2
5
A factor tree for 360. Splitting it as 4 × 90 instead gives the same primes in the end.
Code challengeInteractive · disabled in the PDF
Write primeFactors(n) for a natural number n ≥ 1: its prime factors, smallest first, each repeated as often as it divides. primeFactors(360) is {2, 2, 2, 3, 3, 5}; primeFactors(1) is empty, {}.
C++
1#include<vector>23std::vector<int>primeFactors(int n){4 std::vector<int> factors;5 // TODO: try 2, 3, 4, … and divide each out6 // for as long as it goes7return factors;8}
Algebra22 / 260
Module 2 · Arithmetic, properly
The gcd and the lcm
The greatest common divisor, , is the biggest number that divides both. The least common multiple, , is the smallest positive number both divide. You use the gcd to simplify fractions and the lcm to add them (Module 3). From the factorisations: the gcd takes each shared prime to the lower power, the lcm takes every prime to the higher power.
Notice . That always holds: , because between them they take every prime power from and exactly once. So once you have the gcd, the lcm is one division away.
QuizInteractive · disabled in the PDF
One bus leaves the station every 12 minutes and another every 20 minutes. They both leave at 9:00. When do they next leave together?
One bus leaves the station every 12 minutes and another every 20 minutes. They both leave at 9:00. When do they next leave together?
ProblemInteractive · disabled in the PDF
Factorise 84 and 120 into primes. Then find and .
Algebra23 / 260
Module 2 · Arithmetic, properly
Euclid’s algorithm finds the gcd fast
Factorising big numbers is slow. Euclid found a way around it, around 300 BC, which is still how computers do it. Any number that divides and also divides the remainder when is divided by . So : replace the pair with a smaller pair, and repeat until the remainder is 0. The last non-zero number is the gcd.
Write gcd(a, b) with Euclid’s algorithm, for natural numbers not both zero, and lcm(a, b) for positive ones, using gcd. a % b is the remainder of a divided by b.
C++
1intgcd(int a,int b){2 // TODO: replace (a, b) with (b, a % b) until b is 03return1;4}56intlcm(int a,int b){7return a * b;8}
Going deeper
Why it is fast. Every two steps, the bigger number at least halves (if then the next remainder is ). So the number of steps grows with the number of digits, not the size: about five times the digits of the smaller number at worst (Lamé, 1844). The slowest inputs are neighbouring Fibonacci numbers, like 89 and 55.
Algebra24 / 260
Module 2 · Arithmetic, properly
Estimate before you calculate
An estimate is a quick, rough answer, made by rounding each number to something easy. Rounding to the nearest hundred, 487 becomes 500 and 432 becomes 400: look at the tens digit, and round up from 5. Estimating first is how you catch a slip on a calculator: if you expected about 1000 and got 10 000, a key went wrong.
Nearest hundred500
Nearest ten490
Rounding picks the nearest marked point. Halfway, 450, rounds up.≈ means “is about”. Round one number up and the other down, and the errors partly cancel.
QuizInteractive · disabled in the PDF
Without calculating exactly, which is closest to ?
Without calculating exactly, which is closest to ?
Algebra25 / 260
Module 2 · Arithmetic, properly
Practice problems
ProblemInteractive · disabled in the PDF
Write 1176 as a product of primes, in the form . What are , and ?
ProblemInteractive · disabled in the PDF
Use Euclid’s algorithm to find . Then use the gcd to find .
ProblemInteractive · disabled in the PDF
A floor 360 cm long and 264 cm wide is to be covered with square tiles, all the same size, with no gaps and no cutting. What is the largest tile side that works, and how many tiles of that size are needed?
cm
ProblemInteractive · disabled in the PDF
Three lighthouses flash every 12, 18 and 30 seconds. They all flash together at midnight. How many seconds later do they next all flash together? How many times do they all flash together after midnight, up to and including 1 o’clock?
s
Algebra26 / 260
Module 2 · Arithmetic, properly
Recap
Order of operations: brackets, powers, then × and ÷ left to right, then + and − left to right.
Commutative and associative: order and grouping do not matter for + and ×. Not for − and ÷.
Distributive: . Run it backwards to factor.
Identities 0 and 1; inverses and . Zero has no reciprocal.
A prime has exactly two factors. Every number above 1 factorises into primes in one way.
gcd: shared primes at the lower power. lcm: all primes at the higher. .
Euclid: , until the remainder is 0.
Round and estimate first, so you know roughly what the answer should be.
FlashcardsInteractive · disabled in the PDF
Commutative
Order does not matter: , .
Associative
Grouping does not matter: .
Distributive
.
Identity element
Changes nothing: 0 for addition, 1 for multiplication.
Reciprocal of
, the number that multiplies with to give 1.
Prime
A natural number with exactly two factors, 1 and itself.
gcd
The greatest number that divides both.
lcm
The least positive number that both divide.
Euclid’s step
Replace with , where is the remainder of .
Module 3: Fractions, decimals, percentages and ratios
Algebra27 / 260
Module 3 · Fractions, decimals, percentages and ratios
A fraction is a division waiting to happen
Cut a cake into 4 equal slices and take 3: you have of the cake. The bottom number, the denominator, says how many equal parts the whole is cut into; the top, the numerator, how many you take. A fraction is also a division: , a point on the number line between 0 and 1.
p ÷ q0.75
Change the top and the bottom. When the top is bigger, the fraction is more than 1.
Numerator
The top number: how many parts you have.
Denominator
The bottom number: how many equal parts make a whole. Never 0.
Proper fraction
Top smaller than bottom, so less than 1: .
Improper fraction
Top at least the bottom: , which is also the mixed number .
Algebra28 / 260
Module 3 · Fractions, decimals, percentages and ratios
Many fractions name the same number
, and are the same amount: cutting each piece in two doubles both the number of pieces and the number you hold. Multiplying or dividing the top and bottom by the same non-zero number gives an equivalent fraction. To simplify, divide both by their gcd (Module 2); the result is in lowest terms.
QuizInteractive · disabled in the PDF
What is in lowest terms?
What is in lowest terms?
Algebra29 / 260
Module 3 · Fractions, decimals, percentages and ratios
Add fractions over a common denominator
You can only add pieces of the same size. Quarters and sixths are different sizes, so first rewrite both as twelfths: 12 is the lcm of 4 and 6, the least common denominator. Then add the tops and keep the bottom. Subtracting works the same way.
Using bd as the common denominator always works; you may need to simplify after.
QuizInteractive · disabled in the PDF
What is ?
What is ?
ProblemInteractive · disabled in the PDF
Work out and . Give each in lowest terms.
Algebra30 / 260
Module 3 · Fractions, decimals, percentages and ratios
Multiplying is easier than adding
To multiply, multiply the tops and multiply the bottoms: half of three quarters is . To divide, multiply by the reciprocal, the fraction flipped over (Module 2: dividing is multiplying by the inverse). asks “how many halves fit in three quarters?”, and the answer is one and a half.
QuizInteractive · disabled in the PDF
A ribbon is m long. How many pieces m long can you cut from it?
A ribbon is m long. How many pieces m long can you cut from it?
Algebra31 / 260
Module 3 · Fractions, decimals, percentages and ratios
Try it: add two fractions exactly
A computer’s 1.0 / 3 is a decimal that has been rounded (and in C++, 1 / 3 is worse: two ints divide to 0). To keep a fraction exact, store its top and bottom as two whole numbers. The starter does what many people do on paper: adds tops and bottoms. Fix it with the formula from two slides back, then simplify with the gcd that is already written.
Code challengeInteractive · disabled in the PDF
Finish addFractions(a, b, c, d): return as a pair {top, bottom} in lowest terms, with a positive bottom. b and d are positive. A std::pair<int, int> holds two ints: {5, 12} makes one.
C++
1#include<cmath>2#include<utility>34intgcd(int a,int b){5while(b !=0){6int r = a % b;7 a = b;8 b = r;9}10return std::abs(a);11}1213std::pair<int,int>addFractions(int a,int b,int c,int d){14return{a + c, b + d};15}
Algebra32 / 260
Module 3 · Fractions, decimals, percentages and ratios
Decimals are fractions over powers of ten
The places after the decimal point continue the pattern of Module 1: tenths, hundredths, thousandths. So , which simplifies to . Going the other way, divide: .
A fraction in lowest terms has a decimal that stops exactly when its denominator has no prime factors except 2 and 5, the factors of 10. stops because ; never does, because and no power of ten is a multiple of 3.
QuizInteractive · disabled in the PDF
Which of these have a decimal that stops? Choose all that do.
Which of these have a decimal that stops? Choose all that do.
Algebra33 / 260
Module 3 · Fractions, decimals, percentages and ratios
Recurring decimals turn back into fractions
Why must the decimal of a fraction repeat? In the long division , each step leaves a remainder, and a remainder on dividing by 7 can only be 0 to 6. If it ever is 0 the decimal stops; otherwise, within 6 steps a remainder comes back, and from then on the digits repeat. So , a block of six.
To turn a repeating decimal back into a fraction, give it a name, shift it by the length of the block, and subtract: the endless tails cancel.
The block has two digits, so multiply by 100. A block of three would need 1000.
QuizInteractive · disabled in the PDF
What fraction is ?
What fraction is ?
Going deeper
Apply the trick to : , so and . That is right: and are two ways of writing the same real number, just as and are. If they were different, some number would lie between them, and no decimal fits.
Algebra34 / 260
Module 3 · Fractions, decimals, percentages and ratios
A percentage is a fraction out of one hundred
Per cent means “for each hundred”: . To find of 80, multiply: . A percentage change compares the change with where you started, so the starting value goes on the bottom.
A change of multiplies by : up 20% is , down 20% is . That makes chains of changes easy, and shows a trap: up 20% then down 20% is , a 4% loss overall. The graph shows a price of 100 going up by % and then down by the same %.
Up p%, then down p%
Where you started
Price after both96
Up and down by the same percentage never brings you back: you lose p²/100 per cent.
ProblemInteractive · disabled in the PDF
A jacket costs 80 euros. Its price goes up by 15%, and then the new price is cut by 20% in a sale. What is the sale price? What is the overall percentage change from 80 euros (negative for a fall)?
euros
%
Algebra35 / 260
Module 3 · Fractions, decimals, percentages and ratios
Try it: percentage change
Code challengeInteractive · disabled in the PDF
Write percentChange(before, after), the change as a percentage of before, and afterChanges(value, percents), which applies each percentage change in turn. afterChanges(100, {10, -10}) is about 99.
C++
1#include<vector>23doublepercentChange(double before,double after){4return after - before;5}67doubleafterChanges(double value,8const std::vector<double>& percents){9 // TODO: multiply by 1 + p / 100 for each p10return value;11}
QuizInteractive · disabled in the PDF
A coat is reduced by 25% to 60 euros. What was the price before?
A coat is reduced by 25% to 60 euros. What was the price before?
Algebra36 / 260
Module 3 · Fractions, decimals, percentages and ratios
Ratios compare amounts; proportion keeps them fixed
A ratio says how much of one thing there is for each amount of another: a dressing of oil and vinegar in the ratio has 3 spoons of oil for every spoon of vinegar. Like fractions, ratios simplify: . To share 45 in the ratio , cut it into equal parts of 9: one share is , the other .
Two amounts are in direct proportion when their ratio never changes: double one and the other doubles. Then for a fixed constant of proportionality , and the graph is a straight line through the origin. Here is kilograms of apples and the price per kilogram.
cost = k × mass
Cost of 3 kg7.5
Proportional amounts lie on a line through (0, 0). The slope is k.
QuizInteractive · disabled in the PDF
A recipe for 4 people uses 300 g of flour. How much flour do you need for 6?
A recipe for 4 people uses 300 g of flour. How much flour do you need for 6?
Algebra37 / 260
Module 3 · Fractions, decimals, percentages and ratios
Rates and unit conversion are fractions too
A rate is a ratio of two different kinds of quantity: kilometres per hour, euros per kilogram. To convert units, multiply by fractions equal to 1, like , chosen so the units you do not want cancel, top against bottom, like factors.
km cancels km, h cancels h, and metres per second are left.
Fill the blanksInteractive · disabled in the PDF
Convert 72 km/h to metres per second. Fill in the two conversion numbers.
Module 3 · Fractions, decimals, percentages and ratios
Practice problems
ProblemInteractive · disabled in the PDF
Write and as fractions in lowest terms.
ProblemInteractive · disabled in the PDF
Work out , in lowest terms.
ProblemInteractive · disabled in the PDF
After a rise of 12%, the rent of a flat is 896 euros a month. What was it before the rise?
euros
Algebra39 / 260
Module 3 · Fractions, decimals, percentages and ratios
More practice problems
ProblemInteractive · disabled in the PDF
Three friends share 168 euros in the ratio . How much does each get?
euros
euros
euros
ProblemInteractive · disabled in the PDF
A car uses 6.5 litres of fuel per 100 km. How much fuel does it use on a 340 km trip? At 1.80 euros a litre, what does that fuel cost?
L
euros
Algebra40 / 260
Module 3 · Fractions, decimals, percentages and ratios
Recap
A fraction is ; equivalent fractions multiply top and bottom by the same number.
Simplify by dividing top and bottom by their gcd.
Add and subtract over a common denominator: .
Multiply straight across; divide by multiplying by the reciprocal.
A decimal stops when the bottom has only 2s and 5s; otherwise it repeats.
Shift and subtract turns a repeating decimal into a fraction: .
A change multiplies by ; changes chain by multiplying.
Proportion: . Convert units by multiplying by fractions equal to 1.
FlashcardsInteractive · disabled in the PDF
Numerator and denominator
Top: how many parts. Bottom: how many parts make a whole.
Lowest terms
Top and bottom have no common factor but 1.
Least common denominator
The lcm of the denominators.
Dividing by a fraction
Multiply by its reciprocal: is .
When does a decimal stop?
When the denominator, in lowest terms, has no prime factors but 2 and 5.
Percentage change
Direct proportion
: a fixed ratio, a line through the origin.
km/h to m/s
Divide by 3.6, since .
Module 4: Powers, roots and scientific notation
Algebra41 / 260
Module 4 · Powers, roots and scientific notation
A power is repeated multiplication
Just as is short for , the power is short for . The number multiplied, 4, is the base; the small raised number, 3, is the exponent (or index), and says how many times the base appears. is read “ squared” and “ cubed”, after the area of a square and the volume of a cube.
Powers of 2: each bar is double the one before. By 2¹⁰ it is over a thousand.
QuizInteractive · disabled in the PDF
What are and ?
What are and ?
Algebra42 / 260
Module 4 · Powers, roots and scientific notation
The laws of exponents follow from counting factors
Every law of exponents comes from counting how many times the base appears. Multiply by and you have three ’s and then two more: five in all. Divide and the common ones cancel. Raise a power to a power and you repeat the whole group.
Powers do not spread over sums. , but is not . Try : , while . Module 5 shows what really is.
QuizInteractive · disabled in the PDF
Simplify .
Simplify .
ProblemInteractive · disabled in the PDF
Simplify , for .
Algebra43 / 260
Module 4 · Powers, roots and scientific notation
Zero and negative exponents keep the pattern going
Count down the powers of 2 and each step divides by 2. Keep going past and the pattern decides what and must be. These are not new rules but the only values that keep the laws true: , and anything divided by itself is 1.
QuizInteractive · disabled in the PDF
What is ?
What is ?
Going deeper
What about 0⁰?. The rule would give , while for every positive suggests 0. In algebra, combinatorics and programming is the standard choice (it makes formulas like the binomial theorem work), and std::pow(0, 0) is 1 in C++. In calculus, an expression heading towards can head anywhere, so it is called indeterminate there.
Algebra44 / 260
Module 4 · Powers, roots and scientific notation
Try it: powers by repeated multiplication
Code challengeInteractive · disabled in the PDF
Write power(base, n) for a whole number n, which may be zero or negative, by multiplying in a loop. Do not use std::pow.
C++
1#include<cmath>23doublepower(double base,int n){4return base * n;5}
Going deeper
The loop does multiplications. Squaring does far fewer: is four multiplications, not sixteen. For any , square when is even, multiply once more when it is odd, and you need only about steps. Computers use this to raise numbers to huge powers in cryptography.
Algebra45 / 260
Module 4 · Powers, roots and scientific notation
A root undoes a power
The square root of , written , is the number that squares to : because . Both and square to 25, so by agreement means the one that is not negative, the principal root. The cube root cubes to , and the $n$th root gives when raised to the .
y = x²
y = √x
y = x
a²4
√(a²)2
Square a, then take the root, and you are back at a. The two curves are mirror images in the line y = x.
QuizInteractive · disabled in the PDF
Which of these are real numbers? Choose all that are.
Which of these are real numbers? Choose all that are.
Algebra46 / 260
Module 4 · Powers, roots and scientific notation
A fractional exponent is a root
What should mean? The laws decide again: . So squares to 9: it is . In general the bottom of the fraction is a root and the top is a power, in either order.
Take the root first: the numbers stay small.
QuizInteractive · disabled in the PDF
What is ?
What is ?
ProblemInteractive · disabled in the PDF
Work out , and , exactly.
Algebra47 / 260
Module 4 · Powers, roots and scientific notation
Simplify a root by taking out squares
A root that is irrational, like , is called a surd. Leaving it as a surd keeps it exact. Roots multiply, (for ), so you can simplify by finding the biggest square factor and taking its root out. To rationalise a denominator, multiply top and bottom by the root, so the bottom becomes whole.
QuizInteractive · disabled in the PDF
What is ?
What is ?
Algebra48 / 260
Module 4 · Powers, roots and scientific notation
Try it: a square root by halving the gap
How does a calculator find when no fraction is exact? One way is bisection: the root of lies between a low guess and a high guess. Try the middle. If its square is too small, the root is in the upper half; otherwise, the lower half. Each step halves the gap, so 60 steps narrow it by a factor of , about .
Code challengeInteractive · disabled in the PDF
Write squareRoot(a) for a ≥ 0 by bisection, without std::sqrt or std::pow. Start with low = 0 and high = std::max(1.0, a), and halve the gap 60 times. (std::max, from <algorithm>, wants two values of the same type: 1.0, not 1.)
C++
1#include<algorithm>23doublesquareRoot(double a){4double low =0;5double high = std::max(1.0, a);6 // TODO: try the middle; keep the half the root is in7return a /2;8}
Algebra49 / 260
Module 4 · Powers, roots and scientific notation
Scientific notation writes huge and tiny numbers
Light travels about metres every second; an electron has a mass of about kg. Counting zeros is hopeless, so scientists write a number between 1 and 10 times a power of ten: scientific notation (or standard form).
Quantity
Value
Speed of light in a vacuum
m/s (exactly 299 792 458 m/s)
Mass of an electron
kg
Mass of the Earth
kg
Diameter of a hydrogen atom
about m
Multiplying and dividing is easy with the laws of exponents: multiply the front numbers, add the powers. . C++ writes these as 3e8 and 2e3 (both doubles), and prints them that way too: 6e+11.
QuizInteractive · disabled in the PDF
What is in scientific notation?
What is in scientific notation?
PlaygroundInteractive · disabled in the PDF
C++
1#include<iomanip>2#include<iostream>34intmain(){5double c =2.998e8; // speed of light, m/s6double year =365.25*24*3600; // seconds in a year7double lightYear = c * year;8 std::cout << lightYear <<"\n"; // 6 figures, its own way9 std::cout << std::fixed << std::setprecision(0);10 std::cout << lightYear <<"\n"; // every digit, in metres11 std::cout << std::scientific << std::setprecision(3);12 std::cout << lightYear <<"\n"; // standard form13 std::cout << std::setprecision(2)<<9.109e-31<<"\n";14}
How far light goes in a year: about 9.46 × 10¹⁵ m (e+15 means × 10¹⁵). std::fixed and std::scientific choose the style, and std::setprecision (from <iomanip>) the digits after the point. Try the distance in a day.
Algebra50 / 260
Module 4 · Powers, roots and scientific notation
Orders of magnitude compare by powers of ten
The order of magnitude of a quantity is its power of ten, rounded: Mount Everest’s height, 8849 m, is about m. Two things that differ by one order of magnitude differ by a factor of about 10. It is the right tool for a first, rough comparison: how many atoms across is a bacterium? About .
Sizes in the universe, in metres, as powers of ten. Each step up the axis is ten times bigger.
QuizInteractive · disabled in the PDF
The Earth’s diameter is about m and the distance to the Sun about m. Roughly how many Earths would fit in a row from the Earth to the Sun?
The Earth’s diameter is about m and the distance to the Sun about m. Roughly how many Earths would fit in a row from the Earth to the Sun?
Algebra51 / 260
Module 4 · Powers, roots and scientific notation
Significant figures say how precise a number is
A measured number is only as good as the instrument. The significant figures are the digits that carry real information: all of them from the first non-zero digit on. Zeros in front only place the point, so has three: 4, 5 and the final 0, which says the measurement was precise to that place. Rounding to significant figures keeps the first and rounds the rest.
Number
Significant figures
To 2 s.f.
6
5
3
4
QuizInteractive · disabled in the PDF
What is to 3 significant figures?
What is to 3 significant figures?
Going deeper
Precision through a calculation. A result is no more precise than its least precise input. Multiply a length of m (2 s.f.) by and quote , not . Floating-point numbers in a computer carry about 15 to 17 significant decimal digits, which is why 0.1 + 0.2 == 0.3 is false in C++: printed with 17 figures (std::setprecision(17)), the sum is 0.30000000000000004, and the error is in the 17th figure.
Algebra52 / 260
Module 4 · Powers, roots and scientific notation
Practice problems
ProblemInteractive · disabled in the PDF
Simplify , and rationalise the denominator of .
ProblemInteractive · disabled in the PDF
Sunlight travels about m from the Sun to the Earth, at m/s. How many seconds does the trip take? How many minutes is that?
s
min
ProblemInteractive · disabled in the PDF
Work out and . You can type an answer like as 3e4 or 3*10^4.
Algebra53 / 260
Module 4 · Powers, roots and scientific notation
More practice problems
ProblemInteractive · disabled in the PDF
Round to 3 significant figures, and to 2 significant figures.
ProblemInteractive · disabled in the PDF
A colony of bacteria doubles every 20 minutes, starting from 1 cell. After 4 hours it has cells: what is , and how many cells is that? How many cells are there after 10 hours, in scientific notation to 3 significant figures?
cells
cells
Algebra54 / 260
Module 4 · Powers, roots and scientific notation
Recap
multiplies copies of . Brackets decide what the base is: .
Laws: , , , .
and , for .
Roots undo powers; is the non-negative one. .
Simplify surds by taking out squares: . Roots do not add.
Scientific notation: with .
Order of magnitude: the nearest power of ten.
Significant figures start at the first non-zero digit.
FlashcardsInteractive · disabled in the PDF
Base and exponent
In , is the base, the exponent: how many copies.
: multiplying adds exponents.
: a power of a power multiplies them.
, the $n$th root.
Surd
An irrational root left exact: , .
Rationalising
Multiplying top and bottom to clear a root from the denominator.
Scientific notation
, with .
Significant figures
The digits from the first non-zero one on.
Module 5: Letters for numbers: variables and expressions
Algebra55 / 260
Module 5 · Letters for numbers: variables and expressions
A letter stands for a number
A cinema ticket costs 9 euros. Two tickets cost , five cost , and tickets cost . The letter is a variable: a name for a number that can change, or that you do not know yet. With one line, , you have written down the price of every order at once. That is the step from arithmetic to algebra.
A number next to a letter is multiplied: means , and means .
The number comes first: write , not . And is just .
Division is usually a fraction: rather than .
Any letter works. , and are traditional for unknowns, others for what they name: for time, for radius.
Variable
A letter that stands for a number.
Constant
A number that does not change: the 4 in .
Coefficient
The number multiplying a variable: the 3 in .
Term
One piece of a sum: has the terms and .
Expression
Numbers, variables and operations put together: , .
Algebra56 / 260
Module 5 · Letters for numbers: variables and expressions
An expression names a value; an equation makes a claim
An expression like is a recipe for a number: give a value and you get one. It has no equals sign and is neither true nor false. An equation puts two expressions on either side of , and so makes a claim: says the two sides are the same number. That claim is true for some values of (here, only ) and false for the rest.
Expressions
You simplify or evaluate them.
Equations
You solve them: find when they are true.
QuizInteractive · disabled in the PDF
Which of these is an equation?
Which of these is an equation?
Algebra57 / 260
Module 5 · Letters for numbers: variables and expressions
Substitute to find an expression’s value
To evaluate an expression, substitute: replace each letter with its value, in brackets, and work it out with the order of operations. The brackets matter most with negatives. Here is when .
Square first: (−2)² = 4. Then minus 2 times −2 is plus 4.
3x² − 2x + 1
Value17
Every value of x gives one value of the expression. Drawn for all x, the values make a curve.
QuizInteractive · disabled in the PDF
What is when and ?
What is when and ?
ProblemInteractive · disabled in the PDF
Find the value of when and , and of when .
Algebra58 / 260
Module 5 · Letters for numbers: variables and expressions
An expression is a small function
In code, an expression with a variable is a function: you give it the value, it gives back the result. Substituting is calling it. Programming languages never let you leave out the multiplication sign, and C++ has no power operator: is written 3 * x * x (or 3 * std::pow(x, 2)).
PlaygroundInteractive · disabled in the PDF
C++
1#include<iostream>2#include<vector>34doublevalue(double x){5return3* x * x -2* x +1;6}78intmain(){9 std::vector<double> xs ={-2,-1,0,1,2};10for(double x : xs){11 std::cout <<"x = "<< x <<": "<<value(x)<<"\n";12}13}
A table of values, made by substituting each x in turn. Try other x, or change the expression.
Algebra59 / 260
Module 5 · Letters for numbers: variables and expressions
Only like terms can be added
Like terms have exactly the same letters raised to the same powers: and are alike, and are alike, but and are not. Adding like terms is the distributive law at work: . Unlike terms stay apart, just as 3 apples and 2 pears do not make 5 of anything.
QuizInteractive · disabled in the PDF
Simplify .
Simplify .
Code challengeInteractive · disabled in the PDF
Each term is a Term, a coefficient and its letters, so is {3, "x"}, is {2, "x²"} and a constant 5 is {5, ""}. Write collect(terms): add the coefficients of like terms, and return a std::map from letters to coefficient. Leave out any that come to 0. In a map, m[key] is the value kept for key (0 the first time), and for (const auto& [key, value] : m) visits each entry.
Module 5 · Letters for numbers: variables and expressions
Expanding brackets multiplies every term
To expand a bracket, multiply each term inside by what is outside: the distributive law of Module 2. Watch the signs: a negative outside changes every sign inside. Two brackets multiply every term of one by every term of the other, four products in all.
The last line is the one Module 4 promised: is plus the two cross terms . Drag and : the gap between the curves is always .
(a + b)²
a² + b²
Gap, 2ab6
The two curves meet only where a or b is 0. Everywhere else, (a + b)² is 2ab bigger or smaller.
Find the bugInteractive · disabled in the PDF
This simplification of goes wrong on one line. Which?
Text
ProblemInteractive · disabled in the PDF
Expand and simplify and .
Algebra61 / 260
Module 5 · Letters for numbers: variables and expressions
Factoring puts the brackets back
Factoring is expanding run backwards: find the highest common factor of every term, numbers and letters, and write it outside a bracket. What is left inside is each term divided by it. Check your answer by expanding again: you should get back where you started.
In the last one the common factor is a, and a ÷ a leaves 1, not 0.
Fill the blanksInteractive · disabled in the PDF
Factor completely. The two functions must agree for every x; the last line checks a few.
C++
1intbefore(int x){return12* x -18;}2intafter(int x){return*(* x -);}34bool same =before(0)==after(0)&&before(1)==after(1)&&5before(5)==after(5);
QuizInteractive · disabled in the PDF
Factor completely.
Factor completely.
Algebra62 / 260
Module 5 · Letters for numbers: variables and expressions
Turning words into expressions
Real problems come in words. Name the unknown with a letter, say exactly what it stands for (“let be the number of adults”), then translate phrase by phrase. Watch the order in phrases like “3 less than”, which reverses: “3 less than ” is .
In words
As an expression
5 more than twice a number
3 less than a number
A number decreased by 3, then tripled
The average of two numbers
12 euros per adult and 7 per child
QuizInteractive · disabled in the PDF
A garden is metres wide and 3 metres longer than it is wide. What is its perimeter, the distance all the way round?
A garden is metres wide and 3 metres longer than it is wide. What is its perimeter, the distance all the way round?
Code challengeInteractive · disabled in the PDF
Write two expressions as functions. ticketCost(adults, children): 12 euros per adult, 7 per child. gardenPerimeter(width): the perimeter of a garden 3 m longer than it is wide.
Module 5 · Letters for numbers: variables and expressions
An identity is true for every value
Some equations are true whatever the letters are: holds for every , because both sides are the same expression written two ways. These are identities, sometimes written with . Others, like , are true only for particular values (): those are the ones you solve, from the next module on.
To show an identity, simplify both sides until they match. To show something is not an identity, one value where the sides differ is enough: a counterexample. fails at , since . Checking a few values cannot prove an identity, but one failure disproves it.
QuizInteractive · disabled in the PDF
Which of these are identities, true for every ? Choose all that are.
Which of these are identities, true for every ? Choose all that are.
Algebra64 / 260
Module 5 · Letters for numbers: variables and expressions
Practice problems
ProblemInteractive · disabled in the PDF
Factor completely. What is the highest common factor you take out, and what is left in the bracket?
ProblemInteractive · disabled in the PDF
A rectangle is cm wide, and its length is 2 cm more than three times its width. Write its perimeter in terms of , simplified. Then find the perimeter when .
cm
cm
ProblemInteractive · disabled in the PDF
A family goes to the cinema: adults at 9 euros each, and children at 6 euros each, with 3 more children than adults. Write the total cost in terms of , simplified. What does it come to for 2 adults?
euros
euros
ProblemInteractive · disabled in the PDF
Expand and simplify . Then use your answer to work out without a calculator.
Algebra65 / 260
Module 5 · Letters for numbers: variables and expressions
Recap
A variable is a letter for a number. means .
An expression is a value; an equation says two values are equal.
Substitute values in brackets, then follow the order of operations.
Only like terms (same letters, same powers) can be added.
Expand by multiplying every term inside by what is outside; a negative flips every sign.
, never just .
Factor by taking out the highest common factor; check by expanding.
An identity holds for every value; one counterexample shows something is not one.
FlashcardsInteractive · disabled in the PDF
Variable
A letter that stands for a number.
Coefficient
The number in front of a variable: 7 in .
Like terms
Terms with the same letters to the same powers: and .
Substitute
Replace each letter with its value, in brackets.
Expand
Multiply out the brackets.
Factor
Write as a product: take a common factor outside a bracket.
Identity
An equation true for every value of its letters.
Counterexample
One value that shows a claim is false.
Module 6: Solving linear equations
Algebra66 / 260
Module 6 · Solving linear equations
An equation is a balance
Think of an equation as a pair of scales in balance: the left side weighs exactly what the right side weighs. You may change the scales, as long as you do the same thing to both sides: add 5 to each, take 2 from each, double each, halve each. They stay balanced, and each move can be undone, so the new equation has exactly the same solutions as the old one. (Multiplying both sides by 0 is not allowed: it turns any equation into , and cannot be undone.) Solving means making such moves until the unknown stands alone:
A linear equation is one where the unknown appears only to the first power: no , no , no . The name comes from its graph, a straight line (Module 9). Here are both sides of as graphs: the solution is the where they are equal.
left side, 3x + 5
right side, 17
Left side8
Left − right−9
Slide x until the left side, 3x + 5, weighs the same as the right side, 17.
Solution
A value of the unknown that makes the equation true. Also called a root.
Solve
Find every solution.
Linear equation
One whose unknown appears only to the power 1: .
Algebra67 / 260
Module 6 · Solving linear equations
Undo what was done to the unknown, in reverse order
Read as a recipe: take , multiply by 3, then add 5. To get back to , undo the steps with their inverse operations (Module 2) in reverse order, the way you take off shoes before socks: first subtract 5, then divide by 3. Each move is done to both sides.
Put in orderInteractive · disabled in the PDF
Put the steps for solving in order.
1.Add 3 to both sides:
2.Multiply both sides by 2:
3.Check: , as it should be
4.Start:
Algebra68 / 260
Module 6 · Solving linear equations
Gather the unknowns on one side
When appears on both sides, first move all the terms to one side and all the numbers to the other, by adding or subtracting them from both sides. Then collect like terms (Module 5) and divide. Moving the smaller term keeps the coefficient positive, which avoids sign slips.
QuizInteractive · disabled in the PDF
Solve .
Solve .
ProblemInteractive · disabled in the PDF
Solve .
Algebra69 / 260
Module 6 · Solving linear equations
Always check by substituting back
An answer is easy to check: put it back into the original equation (not one of your steps, which might already be wrong) and see whether both sides come out the same. It takes seconds and catches nearly every slip. A wrong answer never passes this check.
Find the bugInteractive · disabled in the PDF
This solution of gives , which fails the check. Which line has the mistake?
Text
PlaygroundInteractive · disabled in the PDF
C++
1#include<iostream>2#include<vector>34doubleleft(double x){return4* x +6;}5doubleright(double x){return2* x -10;}67intmain(){8 std::cout << std::boolalpha; // print true/false, not 1/09 std::vector<double> tries ={-2,-8};10for(double x : tries){11 std::cout << x <<" "<<left(x)<<" "<<right(x)<<" "12<<(left(x)==right(x))<<"\n";13}14}
A check in code: substitute into both sides and compare. Try your own equation.
Algebra70 / 260
Module 6 · Solving linear equations
Expand brackets first
With brackets, expand them first (Module 5), minding the signs, then solve as before. You could also divide both sides by a factor of a bracket when it is shared, but expanding always works.
QuizInteractive · disabled in the PDF
Solve .
Solve .
Algebra71 / 260
Module 6 · Solving linear equations
Clear fractions by multiplying through
Fractions are where slips multiply. Clear them first: multiply every term on both sides by the lcm of the denominators. Every fraction then cancels to a whole number, and the equation looks like the ones before.
12 × x/3 = 4x and 12 × x/4 = 3x. The 7 on the right is multiplied too.
QuizInteractive · disabled in the PDF
Solve .
Solve .
ProblemInteractive · disabled in the PDF
Solve .
Algebra72 / 260
Module 6 · Solving linear equations
Some equations have no solution, some have every number
Sometimes the terms cancel completely. What is left is a statement with no in it, and it decides everything. becomes , which is false whatever is: no solution. becomes , true whatever is: every number is a solution, because it is an identity (Module 5).
In pictures: the solution is where the two sides’ lines cross. Different slopes always cross once. The same slope with different starting heights gives parallel lines that never meet. Drag the slope of the right side to 2.
left: 2x + 3
right: mx + 5
Solution x = 2 ÷ (2 − m)2
At m = 2 the lines are parallel: 2x + 3 = 2x + 5 has no solution, and the readout goes to ∞.
QuizInteractive · disabled in the PDF
How many solutions does have?
How many solutions does have?
Algebra73 / 260
Module 6 · Solving linear equations
Try it: a solver for every linear equation
Any linear equation, once expanded and collected, looks like . Subtract and from both sides: . If , divide. If , the terms are gone and the last slide decides.
Code challengeInteractive · disabled in the PDF
Finish solveLinear(a, b, c, d), which solves . Return a Solution whose kind is "one" (with the solution in x), "none" when there is none, or "all" when every number is one.
C++
1#include<string>23structSolution{4 std::string kind; // "one", "none" or "all"5double x; // the solution, when kind is "one"6};78SolutionsolveLinear(double a,double b,double c,double d){9return{"one",(d - b)/(a - c)};10}
Algebra74 / 260
Module 6 · Solving linear equations
Rearranging a formula is solving for a letter
A formula relates several quantities, like for the speed of something that started at speed and sped up at a steady rate for a time . To make another letter the subject (alone on one side), treat the other letters as numbers and use exactly the same moves as before.
Fill the blanksInteractive · disabled in the PDF
Fahrenheit from Celsius is . Rearrange it to write celsius(f): subtract first, then undo the multiplication.
C++
1doublecelsius(double f){return(f -)*/;}23std::cout <<celsius(212)<<"\n"; // 100, water boils4std::cout <<celsius(32)<<"\n"; // 0, water freezes
QuizInteractive · disabled in the PDF
The area of a circle is . What is in terms of ?
The area of a circle is . What is in terms of ?
Algebra75 / 260
Module 6 · Solving linear equations
Word problems: name, write, solve, check
A word problem becomes an equation in four moves. Name the unknown and say what it means. Write the facts as an equation. Solve it. Check the answer against the words, not just the equation: a negative number of people means something went wrong.
The numbers are 16, 17 and 18, which do add up to 51.
QuizInteractive · disabled in the PDF
A taxi charges 3.50 euros to start plus 1.80 euros per kilometre. A ride costs 21.50 euros. How long was it?
A taxi charges 3.50 euros to start plus 1.80 euros per kilometre. A ride costs 21.50 euros. How long was it?
Units are a free check. In , the 1.80 is euros per kilometre, so is in euros only when is in kilometres. If the units on each side of an equation do not match, the equation is wrong before you even solve it.
Algebra76 / 260
Module 6 · Solving linear equations
Practice problems
ProblemInteractive · disabled in the PDF
Solve .
ProblemInteractive · disabled in the PDF
The perimeter of a rectangle is , where is its length and its width. Make the subject. Then find when cm and cm.
cm
ProblemInteractive · disabled in the PDF
A mother is 3 times as old as her son. In 12 years she will be twice as old as he will be. How old are they now?
years
years
Algebra77 / 260
Module 6 · Solving linear equations
More practice problems
ProblemInteractive · disabled in the PDF
Phone plan A costs 15 euros a month plus 0.10 euros a minute. Plan B costs 25 euros a month plus 0.05 euros a minute. For how many minutes a month do they cost the same, and what is that cost?
min
euros
ProblemInteractive · disabled in the PDF
Three consecutive odd numbers (odd numbers that follow each other, each 2 more than the last) add up to 159. What are the smallest and the largest?
Algebra78 / 260
Module 6 · Solving linear equations
Recap
Do the same thing to both sides (but never multiply by 0), and the solutions do not change.
Undo what was done to the unknown with inverse operations, in reverse order.
Gather terms on one side and numbers on the other, then divide.
Expand brackets first; clear fractions by multiplying every term by the lcm.
Check by substituting into the original equation.
If cancels: a false statement means no solution, a true one means every number.
Rearranging a formula is solving for one letter, treating the others as numbers.
Word problems: name the unknown, write the equation, solve, check against the words.
FlashcardsInteractive · disabled in the PDF
The one rule of solving
Whatever you do to one side, do to the other.
Linear equation
The unknown appears only to the power 1.
Inverse operations
Operations that undo each other: + and −, × and ÷.
Clearing fractions
Multiply every term on both sides by the lcm of the denominators.
cancels and leaves
No solution.
cancels and leaves
An identity: every number is a solution.
Subject of a formula
The letter alone on one side: in .
Checking
Substitute into the original equation; both sides must agree.
Module 7: Inequalities and absolute value
Algebra79 / 260
Module 7 · Inequalities and absolute value
An inequality has a range of solutions
A lift that carries at most 600 kg, a ride for people taller than 120 cm, a test you pass with at least 50 marks: these are not single numbers but ranges. An inequality compares two sides with , , or (Module 1), and its solution set is every number that makes it true. has infinitely many solutions: 3, 3.5, 10, a million.
On a number line, shade the solutions. The end point gets a closed (filled) dot when it is included, for and , and an open (hollow) dot when it is not, for and . Drag to move the boundary of .
x ≥ c
The solutions of x ≥ c: c itself and everything to its right.
QuizInteractive · disabled in the PDF
Which of these numbers satisfy ? Choose all that do.
Which of these numbers satisfy ? Choose all that do.
Algebra80 / 260
Module 7 · Inequalities and absolute value
Solve an inequality like an equation, with one exception
Adding or subtracting the same number on both sides keeps an inequality true: if you are shorter than your friend, you are both still in that order after you both stand on a 10 cm step. Multiplying or dividing both sides by a positive number keeps it true too. So most inequalities are solved exactly like equations.
Every number below 4 works; 4 itself does not, since 2 × 4 + 5 = 13 is not less than 13.
Check two numbers. Pick a number inside your answer and one outside, and try both in the original. For : gives , true; gives , false. If the inside one fails, the inequality points the wrong way.
Algebra81 / 260
Module 7 · Inequalities and absolute value
Multiplying by a negative flips the inequality
Here is the exception. , but multiply both by and you get and , and . Multiplying by a negative reflects the number line through zero, and a reflection swaps left and right. So whenever you multiply or divide both sides by a negative number, reverse the inequality sign. Drag below zero and watch the order swap.
k × 5 − k × 2 (positive: order kept)−6
Below the line: 2 and 5. Above: k × 2 and k × 5. For negative k, their order reverses.
QuizInteractive · disabled in the PDF
Solve .
Solve .
ProblemInteractive · disabled in the PDF
Solve . What is the largest number that satisfies it?
Algebra82 / 260
Module 7 · Inequalities and absolute value
Find the missing flip
Find the bugInteractive · disabled in the PDF
This solves , but the answer is wrong. Which line is the mistake?
Text
You cannot multiply by an unknown. Never multiply both sides of an inequality by an expression like or whose sign you do not know: you would not know whether to flip. For , the cases and must be handled separately.
Algebra83 / 260
Module 7 · Inequalities and absolute value
Interval notation writes a range in brackets
A range of real numbers is an interval, written with its two ends. A square bracket means the end is included, a round one that it is not, matching the closed and open dots. (infinity) is not a number but a way of saying “no end”, so it always gets a round bracket.
Inequality
Interval
Number line
open at , closed at 4
closed at both ends
open at 3, on for ever
closed at , on for ever left
every real number
the whole line
QuizInteractive · disabled in the PDF
Which interval is ?
Which interval is ?
Algebra84 / 260
Module 7 · Inequalities and absolute value
Compound inequalities: and, or
A compound inequality joins two. With and, a number must satisfy both: the overlap, like , a single stretch. With or, either will do: the two pieces together, like or . A double inequality like is an “and”, solved by doing each step to all three parts at once.
−3 < x ≤ 3
The solution (−3, 3]: open at −3, closed at 3.
Put in orderInteractive · disabled in the PDF
Put the steps for solving in order.
1.Subtract 7 from all three parts:
2.As an interval:
3.Divide all three by and flip both signs:
4.Rewrite smallest first:
Algebra85 / 260
Module 7 · Inequalities and absolute value
Try it: solve any linear inequality
Every linear inequality with a strict sign can be written . Subtract ; then dividing by keeps the sign if and flips it if . If , there is no left, and the statement is either always true or never.
Code challengeInteractive · disabled in the PDF
Write solveLess(a, b, c), which solves and returns the open interval of solutions as an Interval{lower, upper}, using -inf or inf (infinity, already defined) for no end. Return std::nullopt when nothing is a solution: a std::optional<Interval> holds an Interval or nothing, s.has_value() says which, and s->lower reads its member.
An absolute value equation usually has two answers
Module 1 showed that is the distance from to . So asks: which numbers are 5 away from 3? Two: and . In general, splits into or , when . If there is one answer, and if there is none, because a distance is never negative.
y = |x − 3|
y = r
x = 3 − r−2
x = 3 + r8
The V-shaped graph of |x − 3| meets the line y = r twice, once on each side of 3.
QuizInteractive · disabled in the PDF
Solve .
Solve .
Code challengeInteractive · disabled in the PDF
Write absSolutions(a, b, r): every solution of , smallest first, for . Return {} when there is none and one number when . std::min and std::max (from <algorithm>) give the smaller and bigger of two.
Read them as distances again. means “closer than to ”: one stretch, . means “further than from ”: two pieces, or . A machined bolt that must be mm long to within mm satisfies , so .
y = |x − a|
y = r
From−1
To3
The shaded stretch is where |x − a| ≤ r: the V is below the dashed line.
QuizInteractive · disabled in the PDF
Solve .
Solve .
Going deeper
The triangle inequality, , says a detour is never shorter than the direct path. It holds for every pair of real numbers, with equality exactly when and have the same sign (or one is 0). It is the most used inequality in higher mathematics, and it comes back with vectors, where it is about real triangles.
Algebra88 / 260
Module 7 · Inequalities and absolute value
Practice problems
ProblemInteractive · disabled in the PDF
Solve and write the answer as an interval. What are its left and right ends? How many integers are in it?
ProblemInteractive · disabled in the PDF
Solve . The answer is an interval : what are and ?
ProblemInteractive · disabled in the PDF
A phone plan costs 12 euros a month plus 0.08 euros for each text message. You want to spend at most 20 euros in a month. What is the largest number of texts you can send?
Algebra89 / 260
Module 7 · Inequalities and absolute value
More practice problems
ProblemInteractive · disabled in the PDF
A tank holds 500 litres when a tap at its bottom is opened at . It drains at 15 litres a minute. For which times , in minutes, does it hold between 200 and 380 litres (both included)?
min
min
ProblemInteractive · disabled in the PDF
A bag of flour is sold as 1000 g, and the law allows its weight to be off by at most 15 g: . What are the lightest and the heaviest weights allowed? A bag weighs 984 g: by how many grams is it outside the allowed range?
g
g
g
Algebra90 / 260
Module 7 · Inequalities and absolute value
Recap
An inequality’s solution set is a range; closed dots and include an end, open dots and do not.
Add, subtract, and multiply or divide by positives as with equations.
Multiplying or dividing by a negative flips the sign.
Check one number inside your answer and one outside.
“And” is an overlap, one stretch; “or” is the pieces together.
splits into or (none if ).
: within of , one interval. : further, two pieces.
FlashcardsInteractive · disabled in the PDF
When does an inequality flip?
When both sides are multiplied or divided by a negative number.
: 2 included, 7 not.
Why is always next to a round bracket?
It is not a number, so it cannot be included.
“And” compound inequality
Both must hold: the overlap of the two sets.
“Or” compound inequality
Either may hold: both sets together.
or : the two numbers 5 away from 3.
or
Module 8: Functions: a rule from inputs to outputs
Algebra91 / 260
Module 8 · Functions: a rule from inputs to outputs
A function gives exactly one output for each input
A function is a rule that takes an input and gives back exactly one output. Think of a machine: drop in a number, it does its rule, and one number comes out. The same input always gives the same output. A vending machine is a function from buttons to snacks; it would be broken if one button sometimes gave crisps and sometimes chocolate.
The input goes in: here .
The rule runs: .
Exactly one output comes out: .
The machine f(x) = 2x + 1: put in 3, get out 7.
Function
A rule that gives each allowed input exactly one output.
Input
The value you put in, often . Also called the argument.
Output
What comes out, : the value of at .
Algebra92 / 260
Module 8 · Functions: a rule from inputs to outputs
f(x) names the output
We name functions with letters, usually , , , and write : “ of is ”. The brackets here do not mean multiplication: is “the output of when the input is 3”. To evaluate, substitute the input everywhere appears (Module 5). The input can even be an expression.
QuizInteractive · disabled in the PDF
If , what is ?
If , what is ?
ProblemInteractive · disabled in the PDF
For , find and . Then find in terms of , expanded and simplified.
Going deeper
In programming, a “function” may print, change things or give different answers on different calls. A mathematical function does none of that: it is only the pairing of inputs with outputs. Programmers call functions like that pure, and they are the easiest kind to test, because the same input always gives the same output.
Algebra93 / 260
Module 8 · Functions: a rule from inputs to outputs
A graph draws every input–output pair
A table of values lists some inputs and their outputs. The graph of draws every pair as a point: across is the input, up is the output. So the height of the graph above is . Move the point along and read off its height.
f(x) = x² − 2x
f(a)3
The point (a, f(a)) is always on the graph. Its height is the output.
Algebra94 / 260
Module 8 · Functions: a rule from inputs to outputs
Domain is what goes in, range is what comes out
The domain of a function is the set of inputs it accepts. Unless told otherwise, it is every real number for which the rule makes sense: no dividing by zero, no square roots of negatives. The range is the set of outputs it actually produces. accepts every real number but only ever gives outputs .
Function
Domain
Range
all reals,
QuizInteractive · disabled in the PDF
What is the domain of ?
What is the domain of ?
Algebra95 / 260
Module 8 · Functions: a rule from inputs to outputs
The vertical line test
Not every curve is the graph of a function. A function gives each one output, so above each there is at most one point. That gives a quick test: if any vertical line crosses a curve more than once, the curve is not a function of . Slide the vertical line across the circle .
y = x²/2 − 3
x² + y² = 4
Crossings with the circle2
Inside −2 < v < 2, the line meets the circle twice: two outputs for one input. The parabola is crossed only once.
QuizInteractive · disabled in the PDF
Which of these give as a function of ? Choose all that do.
Which of these give as a function of ? Choose all that do.
Algebra96 / 260
Module 8 · Functions: a rule from inputs to outputs
Piecewise functions use different rules on different inputs
A piecewise function uses one rule on part of its domain and another elsewhere. Postage is one: up to 100 g costs 1.20 euros, over 100 g and up to 500 g costs 2.50, over 500 g and up to 2 kg costs 4.80. It is still a function, since each weight has one price; the conditions must not overlap. is piecewise too: for negative , otherwise.
p(w)
A step function: the price jumps at 100 g and 500 g, and stays flat between.
Code challengeInteractive · disabled in the PDF
Write postage(grams) from the rule above. Its domain is : for any weight outside it, return std::nullopt, no value at all. (A std::optional<double>, from <optional>, holds a double or nothing.)
Module 8 · Functions: a rule from inputs to outputs
Composition feeds one function into another
Two machines in a row: the output of goes straight into . That new function is the composition , read “ after ”, and . Work from the inside out: first. Order matters, because “double then add 3” is not “add 3 then double”.
QuizInteractive · disabled in the PDF
If and , what is ?
If and , what is ?
Code challengeInteractive · disabled in the PDF
Fix compose(f, g): it must return the function , which runs g first and then f. Fn is a function from double to double (a std::function, from <functional>), and [f, g](double x) { … } is a lambda, a function made on the spot that keeps f and g.
Module 8 · Functions: a rule from inputs to outputs
An inverse function runs the machine backwards
The inverse of , written , undoes it: if then , and . (The is not a power: is not .) To find it, write , solve for (Module 6), then rename. Its graph is the graph of reflected in the line , because every pair becomes .
f(x) = 2x + 3
f⁻¹(x) = (x − 3)/2
y = x
Each point (a, f(a)) has a mirror image (f(a), a) on the inverse.
Fill the blanksInteractive · disabled in the PDF
Write the inverse of , so that the check is true.
C++
1doublef(double x){return5* x -2;}2doublefInverse(double x){return(x +)/;}34bool undone =fInverse(f(0))==0&&fInverse(f(1))==1&&5fInverse(f(7))==7;
QuizInteractive · disabled in the PDF
Why does , on all real numbers, have no inverse?
Why does , on all real numbers, have no inverse?
ProblemInteractive · disabled in the PDF
Find the inverse of . Then work out .
Algebra99 / 260
Module 8 · Functions: a rule from inputs to outputs
Shift, stretch and reflect a graph
Small changes to the rule move the graph in predictable ways. Adding outside, , moves it up by . Changing the input, , moves it right by : right, not left, because the graph now reaches each height later. Multiplying, , stretches it upright by , and a negative reflects it in the axis. reflects it in the axis.
y = x²
y = a(x − h)² + k
y = a(x − h)² + k is y = x² moved right h, stretched by a, and moved up k. The turning point sits at (h, k).
QuizInteractive · disabled in the PDF
How is the graph of made from ?
How is the graph of made from ?
Algebra100 / 260
Module 8 · Functions: a rule from inputs to outputs
Practice problems
ProblemInteractive · disabled in the PDF
Let and . Find and , and write as one simplified expression.
ProblemInteractive · disabled in the PDF
Let . What is the largest number in its domain? Find , exactly. What is the smallest number in its range?
ProblemInteractive · disabled in the PDF
An electricity tariff charges 0.20 euros per kWh for the first 100 kWh used in a month, and 0.30 euros for each kWh after that. What does a month of 80 kWh cost? And of 250 kWh? A household’s bill is 50 euros: how many kWh did it use?
euros
euros
kWh
ProblemInteractive · disabled in the PDF
The graph of is moved 3 to the left, stretched upright by a factor of 2, and then moved 5 down. Write the equation of the new graph, and give its turning point.
Algebra101 / 260
Module 8 · Functions: a rule from inputs to outputs
Recap
A function gives each input exactly one output. is the output at .
Domain: the inputs allowed. Range: the outputs produced.
The graph is every point ; its height above is .
Vertical line test: a curve crossed twice by a vertical line is not a function.
Piecewise functions use different rules on non-overlapping pieces.
: first. Order matters.
undoes ; its graph is reflected in . Only one-to-one functions have one.
up, right, stretch, and reflect.
FlashcardsInteractive · disabled in the PDF
Function
A rule giving each input exactly one output.
Domain
The set of inputs a function accepts.
Range
The set of outputs a function produces.
Vertical line test
If a vertical line crosses a curve twice, it is not a function of .
: apply , then .
The inverse: . Not .
One-to-one
Different inputs always give different outputs.
The graph of moved right by .
The graph of reflected in the axis.
Module 9: Lines and slope
Algebra102 / 260
Module 9 · Lines and slope
Two number lines make a plane
Put one number line across (the axis) and another up (the axis), crossing at zero, the origin. Now every point has an address: a pair , how far across and then how far up. This is the coordinate plane, René Descartes’ idea (1637), and it is what lets algebra draw pictures and pictures be written as algebra. The axes cut the plane into four quadrants, numbered anticlockwise from the top right.
Move the point. The first number is always across, the second up.
QuizInteractive · disabled in the PDF
In which quadrant is the point ?
In which quadrant is the point ?
Algebra103 / 260
Module 9 · Lines and slope
Slope is rise over run
A straight line climbs at the same rate everywhere. That rate is its slope (or gradient), : how far it rises for each step across. Take any two points on it; the rise is the change in and the run the change in . The Greek letter (delta) means “change in”.
the line through both
Slope m = rise ÷ run1
Move either point. The slope is the same wherever the two points are on the same line.
Slope
The line…
positive
goes up from left to right
negative
goes down from left to right
0
is flat (horizontal)
undefined
is upright (vertical): the run is 0
QuizInteractive · disabled in the PDF
What is the slope of the line through and ?
What is the slope of the line through and ?
Algebra104 / 260
Module 9 · Lines and slope
Slope-intercept form: y = mx + c
Every non-vertical line can be written . is the slope, and is the -intercept, where the line crosses the axis: put and you get . So you can draw it at once: start at , then go 1 across and up. Where it crosses the axis, the -intercept, is where : , as long as (a flat line never crosses, unless it is the axis itself).
y = mx + c
x-intercept, −c ÷ m0.67
m tilts the line around (0, c); c slides it up and down without changing its tilt.
QuizInteractive · disabled in the PDF
A line crosses the axis at and goes down 2 for every 1 across. What is its equation?
A line crosses the axis at and goes down 2 for every 1 across. What is its equation?
Algebra105 / 260
Module 9 · Lines and slope
Try it: the line through two points
Two points fix a line. Find the slope from the two points, then from either one: since , it follows that . A vertical line has no slope, so it has no form at all.
Code challengeInteractive · disabled in the PDF
Finish lineThrough(x1, y1, x2, y2): return a Line{m, c} for the line through the two points, or std::nullopt when the line is vertical.
A line passes through and . Find its slope , its -intercept , and where it crosses the axis.
Algebra106 / 260
Module 9 · Lines and slope
Point-slope form starts from any point
If you know the slope and one point on the line, you can write the line straight away. Any other point on it must have the same slope back to : . Multiply up and you have the point-slope form.
QuizInteractive · disabled in the PDF
Which is the line with slope through ?
Which is the line with slope through ?
Algebra107 / 260
Module 9 · Lines and slope
Standard form handles every line, vertical ones too
The standard form is , with whole numbers when possible. It has no special place for the slope, but it has two advantages: the intercepts are easy (cover up one variable by setting it to 0), and it can write vertical lines, like , which is . Rearranging into gives the slope: .
QuizInteractive · disabled in the PDF
What is the slope of ?
What is the slope of ?
Algebra108 / 260
Module 9 · Lines and slope
Parallel lines share a slope; perpendicular slopes multiply to −1
Two lines with the same slope never meet: they are parallel, like and . Two lines that cross at a right angle are perpendicular, and their slopes are negative reciprocals: , or . Rotating a line a quarter turn swaps its run and rise and flips one of their signs.
y = mx
y = −x/m
Second slope, −1/m−2
Product of slopes−1
However you tilt the first line, the second stays at a right angle, and the slopes multiply to −1. (Equal scales on both axes keep the angle true.)
QuizInteractive · disabled in the PDF
What slope does a line perpendicular to have?
What slope does a line perpendicular to have?
ProblemInteractive · disabled in the PDF
Find the line through that is perpendicular to . Write it as : what are and ?
Algebra109 / 260
Module 9 · Lines and slope
Distance and midpoint between two points
The run and the rise between two points are the two shorter sides of a right-angled triangle; the straight line between them is the longest side. Pythagoras’ theorem gives its length: the distance formula. The midpoint, halfway between, has the average of the $x$s and the average of the $y$s.
Code challengeInteractive · disabled in the PDF
Write distance(x1, y1, x2, y2), the straight-line distance between two points, and midpoint(x1, y1, x2, y2), the point halfway, as a Point{x, y}.
When something changes by the same amount in each step of time, a line describes it, and both numbers mean something. A candle 20 cm tall that burns 1.6 cm every hour has height : the intercept, 20 cm, is where it started, and the slope, cm per hour, is its rate. Real measurements wobble a little. Fit a line by eye to the measured heights below: drag and to make the total miss small.
h = mt + c
Total squared miss7.94
Burns out at t =18
Measured heights each hour. The best line has m ≈ −1.6 and c ≈ 20, and predicts the candle runs out after about 12.5 hours.
QuizInteractive · disabled in the PDF
A phone plan costs euros a month for minutes of calls. What does the mean?
A phone plan costs euros a month for minutes of calls. What does the mean?
Going deeper
Least squares. The readout adds the squares of the vertical misses. The line that makes that sum as small as possible is the least-squares line, the standard way to fit a line to data (Legendre, 1805; Gauss). Here it is , with a total squared miss of about 0.019. There is a formula for it, , which a statistics course derives.
Algebra111 / 260
Module 9 · Lines and slope
Practice problems
ProblemInteractive · disabled in the PDF
For the points and , find the distance , exactly (as a simplified surd), and the midpoint of .
ProblemInteractive · disabled in the PDF
For the line , find where it crosses the axis and the axis, and its slope.
ProblemInteractive · disabled in the PDF
A plumber charges a fixed call-out fee plus a rate per hour. A 2-hour job costs 110 euros and a 5-hour job costs 215 euros. What is the hourly rate, what is the call-out fee, and what does a 3.5-hour job cost?
euros per hour
euros
euros
Algebra112 / 260
Module 9 · Lines and slope
More practice problems
ProblemInteractive · disabled in the PDF
The points , and lie on one straight line. Find .
ProblemInteractive · disabled in the PDF
Find the line parallel to that passes through . What is its -intercept, and where does it cross the axis?
Algebra113 / 260
Module 9 · Lines and slope
Recap
A point is : across, then up from the origin.
Slope : rise over run, the same anywhere on a line.
: slope , -intercept .
Point-slope: , when you know a point and the slope.
Standard form : easy intercepts, and vertical lines too.
Parallel: equal slopes. Perpendicular: .
Distance by Pythagoras; midpoint by averaging.
In a model, the slope is a rate (output units per input unit) and the intercept a starting value.
FlashcardsInteractive · disabled in the PDF
Slope
Rise over run: .
-intercept
Where a line crosses the axis: .
Slope-intercept form
Point-slope form
Standard form
; slope .
Slope of a vertical line
Undefined: the run is 0. Its equation is .
Perpendicular slopes
Negative reciprocals: .
Distance formula
Midpoint
Module 10: Systems of equations
Algebra114 / 260
Module 10 · Systems of equations
Two unknowns need two facts
Two numbers add up to 10. Which are they? 6 and 4, or 7 and 3, or 2.5 and 7.5: one equation in two unknowns, , has endless solutions. Add a second fact, “their difference is 2”, , and only one pair fits both. A set of equations that must all be true together is a system of equations, and its solution is the values that satisfy every one at once.
QuizInteractive · disabled in the PDF
Which pair solves both and ?
Which pair solves both and ?
Algebra115 / 260
Module 10 · Systems of equations
The solution is where the lines cross
Each linear equation in and is a line (Module 9): every point on it is a solution of that equation. A point that solves both must be on both lines, so the solution of the system is where they cross. Drawing them is a good way to see the answer, and a rough way to find it; algebra, on the next slides, finds it exactly.
y = 2x − 1
y = mx + c
x2
y3
The first line is y = 2x − 1. Move the second; the crossing point is the solution. At the start it is (2, 3).
Graphs are approximate. If two lines cross at , a graph shows “about 2.3”. Graphs tell you roughly where, and how many solutions there are; algebra gives the exact numbers. Use both: the graph is a check on the algebra.
Algebra116 / 260
Module 10 · Systems of equations
Substitution: solve one, put it into the other
Substitution turns two equations in two unknowns into one equation in one unknown. Solve one equation for one variable, then substitute that expression into the other equation. Solve it (Module 6), and put the answer back to find the second variable. It is easiest when one equation already says or .
The solution is (2, 3), the crossing point on the last slide. Check: 3(2) + 2(3) = 12.
Put in orderInteractive · disabled in the PDF
Put the steps for solving and in order.
1.Put back into :
2.Solve for : , so
3.Check in both: and
4.Replace in the second equation:
ProblemInteractive · disabled in the PDF
Solve by substitution: and .
Algebra117 / 260
Module 10 · Systems of equations
Elimination: add the equations to cancel a variable
Adding two true equations gives another true equation: equal amounts added to equal amounts. Elimination uses this to make one variable vanish. If the terms are and , adding the equations cancels them. If they do not match, first multiply each equation by a number that makes them match.
Multiplying each equation scales both sides, so it is still true. Then subtracting cancels the x terms.
QuizInteractive · disabled in the PDF
Solve and .
Solve and .
ProblemInteractive · disabled in the PDF
Solve by elimination: and .
Algebra118 / 260
Module 10 · Systems of equations
One solution, none, or infinitely many
Two lines can cross once, never (parallel: the same slope, different intercepts), or lie on top of each other (the same line). So a system of two linear equations has exactly one solution, none, or infinitely many, never two. Algebra shows it the way Module 6 did: eliminating leaves a false statement like for none, and for infinitely many.
y = 2x + 1
y = mx + c
Crossing at x =3
The first line is y = 2x + 1. Set m to 2: the lines are parallel. Then set c to 1 as well: they are one line.
QuizInteractive · disabled in the PDF
How many solutions does the system , have?
How many solutions does the system , have?
Algebra119 / 260
Module 10 · Systems of equations
Try it: solve any two-by-two system
Eliminate in general and you get a formula. For and , multiply the first by and the second by and subtract: . In the same way, . The number decides everything: if it is not 0, divide. If it is 0, the lines are parallel or the same.
Code challengeInteractive · disabled in the PDF
Finish solveTwo(a, b, c, d, e, f) for , . Return a Solution whose kind is "one" (with x and y), "none" or "infinite". When : if both tops, and , are 0 too, it is the same line.
C++
1#include<string>23structSolution{4 std::string kind; // "one", "none" or "infinite"5double x;6double y;7};89SolutionsolveTwo(double a,double b,double c,double d,10double e,double f){11double det = a * d - b * c;12 // TODO13return{"none",0,0};14}
Going deeper
Nearly parallel is nearly trouble. When is tiny but not 0, the lines are almost parallel, and a small change in or (a rounding error, a measurement off by a little) moves the crossing point a long way. Such a system is called ill-conditioned. In floating point, testing det == 0 is also fragile; real solvers compare against a tolerance scaled to the size of the numbers.
Algebra120 / 260
Module 10 · Systems of equations
Word problems with two unknowns
When a problem has two unknown amounts, name both, and look for two separate facts. A cinema sells adult tickets at 12 euros and child tickets at 7. One evening it sells 20 tickets for 215 euros. Let be the adult tickets and the child tickets: one fact counts tickets, the other counts money.
Check against the words: 15 + 5 = 20 tickets, and 180 + 35 = 215 euros.
QuizInteractive · disabled in the PDF
Two numbers add up to 30 and one is 8 more than the other. What are they?
Two numbers add up to 30 and one is 8 more than the other. What are they?
Algebra121 / 260
Module 10 · Systems of equations
Three unknowns need three equations
The same ideas work with more unknowns. With three, you need three independent equations. Use elimination to remove one variable from two different pairs of equations: that leaves two equations in two unknowns, which you already know how to solve. Then back-substitute. Each equation in , , is a flat plane in space, and the solution is the point where all three planes meet.
To solve a system in , and , you add equations (1) and (2) and get rid of . What do you need to do next, before you can find and ?
To solve a system in , and , you add equations (1) and (2) and get rid of . What do you need to do next, before you can find and ?
Algebra122 / 260
Module 10 · Systems of equations
Systems of inequalities mark out a region
One inequality like is a whole half of the plane: every point on or below the line. A system of inequalities asks for points that satisfy all of them, which is where the half-planes overlap: a feasible region. Here: , and , a triangle with corners , and . Move the test point in and out.
y = −x + 6
y = 2x − 3
Inside all three?1
The region is between the two lines, right of the y axis. Inside, the readout is 1; outside, 0.
Code challengeInteractive · disabled in the PDF
Each rule {a, b, c} means . Fix feasible(x, y, rules) so it is true only when the point satisfies every rule.
C++
1#include<vector>23structRule{4double a, b, c; // a x + b y <= c5};67boolfeasible(double x,double y,const std::vector<Rule>& rules){8for(constRule& r : rules){9if(r.a * x + r.b * y <= r.c)returntrue;10}11returnfalse;12}
Going deeper
Linear programming asks for the point in a feasible region that makes a linear quantity, like a profit , as big as possible. The best value is always at a corner. Here: , , , so the maximum is 15 at . With thousands of variables, the simplex method (Dantzig, 1947) walks from corner to corner, and it schedules airlines and factories to this day.
Algebra123 / 260
Module 10 · Systems of equations
Practice problems
ProblemInteractive · disabled in the PDF
A theatre sells 350 tickets for one show: adult tickets at 18 euros and child tickets at 11 euros. The takings are 5390 euros. How many of each kind were sold?
ProblemInteractive · disabled in the PDF
A drink that is 20% juice is mixed with a drink that is 50% juice, to make 30 litres of a drink that is 30% juice. How many litres of each are used?
L
L
ProblemInteractive · disabled in the PDF
Solve , and .
Algebra124 / 260
Module 10 · Systems of equations
More practice problems
ProblemInteractive · disabled in the PDF
For which number does the system , have no solution?
ProblemInteractive · disabled in the PDF
The region , , is a triangle. Two of its corners are on the axis. Find the third corner, where the two slanted lines meet, and the area of the triangle.
Algebra125 / 260
Module 10 · Systems of equations
Recap
A system’s solution satisfies every equation at once.
Graphically, it is where the lines cross; graphs show roughly where, algebra exactly.
Substitution: solve one equation for a variable and put it into the other.
Elimination: scale the equations so a variable cancels when you add or subtract.
Two linear equations have one solution, none () or infinitely many ().
For , : one solution exactly when .
Three unknowns: eliminate one variable from two pairs, then solve the two-by-two.
A system of inequalities is the overlap of half-planes: a feasible region.
FlashcardsInteractive · disabled in the PDF
System of equations
Equations that must all be true at the same time.
Substitution
Solve one equation for a variable, substitute into the other.
Elimination
Add or subtract (scaled) equations so a variable cancels.
Parallel lines in a system
No solution: elimination leaves something like .
The same line twice
Infinitely many solutions: elimination leaves .
Determinant of ,
; one solution exactly when it is not 0.
Feasible region
The points that satisfy every inequality in a system.
Linear programming
Finding the best corner of a feasible region.
Module 11: Polynomials and factoring
Algebra126 / 260
Module 11 · Polynomials and factoring
A polynomial is a sum of powers of one letter
A polynomial in is a sum of terms, each a number times a whole-number power of : is one. Each number in front is a coefficient; the term with no is the constant term. Written with the highest power first, it is in standard form, and that highest power is its degree.
The general shape: is the degree, the leading coefficient, the constant term.
Polynomial
Degree
Name
Leading coefficient
0
constant
7
1
linear
2
2
quadratic
1
3
cubic
−1
4
quartic
5
Term
One piece of the sum: a coefficient times a power of , such as .
Coefficient
The number multiplying a power of . In it is .
Degree
The highest power of with a coefficient that is not 0.
Like terms
Terms with the same power of , such as and .
QuizInteractive · disabled in the PDF
What is the degree of ?
What is the degree of ?
Going deeper
Powers must be whole numbers 0, 1, 2…: and are not polynomials. That restriction is what makes them so tame: a polynomial has a value for every , its graph has no breaks or corners, and it is built only from adding and multiplying, which is why computers and calculus lean on them so much.
Algebra127 / 260
Module 11 · Polynomials and factoring
Adding and subtracting means collecting like terms
To add two polynomials, add the coefficients of like terms: the terms together, the terms together, the constants together. Subtracting is adding the opposite: a minus sign in front of brackets flips the sign of every term inside.
The minus sign reaches every term. is , not . Forgetting to flip the later terms is the most common slip in this whole topic.
Fill the blanksInteractive · disabled in the PDF
Subtract: . Fill in the coefficients of the answer (a negative one with its minus sign).
To multiply two polynomials, multiply each term of the first by each term of the second, then collect like terms. Powers add when you multiply: . A grid keeps track: the first polynomial down the side, the second along the top, each cell a product.
×
The degrees add too: degree 1 times degree 1 gives degree 2.
In code, a polynomial is a list of its coefficients, a std::vector. Here the list starts with the constant: {a0, a1, a2} is , so the index of a coefficient is its power. Then multiplying is a double loop: the product of the term at index i and the term at index j lands at index i + j.
Code challengeInteractive · disabled in the PDF
Write multiply(p, q): the coefficients of the product of two polynomials with whole-number coefficients, both given constant first. The result has p.size() + q.size() - 1 coefficients; std::vector<int> out(n, 0) makes a vector of n zeros.
C++
1#include<vector>23std::vector<int>multiply(const std::vector<int>& p,4const std::vector<int>& q){5 // TODO: every term of p times every term of q6return{};7}
Algebra129 / 260
Module 11 · Polynomials and factoring
Three products worth knowing by heart
Some products come up so often that it pays to recognise them on sight. Each is just the grid from the last slide, done once in general.
The first two are perfect squares: the middle term is the one people forget, writing . Try : the left is , the right would be . In the third, the middle terms and cancel, leaving the difference of two squares.
Find the bugInteractive · disabled in the PDF
This expansion of goes wrong on one line. Which?
Text
ProblemInteractive · disabled in the PDF
Use the special products to work out and without a calculator.
Going deeper
These make mental arithmetic fast. , and . The general version of , for any power, is the binomial theorem, which comes with Pascal’s triangle in the module on sequences and series.
Algebra130 / 260
Module 11 · Polynomials and factoring
Evaluate a polynomial the fast way
To find for , you could work out each power and add. Horner’s method is quicker and is what computers do: pull out again and again, so only multiplications by and additions are left.
Start from the leading coefficient; then, for each lower one, multiply by and add it.
PlaygroundInteractive · disabled in the PDF
C++
1#include<iostream>2#include<vector>34intmain(){5 // p(x) = x^3 - 2x^2 - 5x + 6, constant first6 std::vector<double> p ={6,-5,-2,1};7int n = p.size();89double result =0;10for(int k = n -1; k >=0; k--){11 result = result *2+ p[k];12 std::cout <<"after coefficient "<< p[k];13 std::cout <<" result is "<< result <<"\n";14}15}
Run it to watch Horner’s method find one coefficient at a time. Change the 2 to 1 or 3.
Code challengeInteractive · disabled in the PDF
Write evaluate(p, x): the value of the polynomial with coefficients p (constant first) at x, using Horner’s method. An empty list is the zero polynomial.
Factoring writes a polynomial as a product: . It is multiplying run backwards, and it is how you solve equations, simplify fractions and find where a graph crosses the axis. Always try the easy moves first.
Take out a common factor. : every term has and in it.
Group in pairs. : each pair shares a factor, and then the pairs share .
Look for a pattern: a difference of squares or a trinomial, on the next slide.
Grouping: the keeps the second pair visible, so you can see both share .
Put in orderInteractive · disabled in the PDF
Put the steps for factoring by grouping in order.
1.Take it out:
2.Take a common factor out of each pair:
3.Check by multiplying back:
4.Split it into two pairs:
5.Notice both pairs share the factor
Algebra132 / 260
Module 11 · Polynomials and factoring
Differences of squares and trinomials
Read the special products backwards. A difference of two squares factors at once: and . A sum of squares, such as , does not factor with real numbers.
A trinomial factors as when you can find two numbers with and . For : two numbers that multiply to and add to are and , so it is .
When the leading coefficient is not 1, look for two numbers with product and sum , split the middle term with them, and group.
QuizInteractive · disabled in the PDF
Which is the factored form of ?
Which is the factored form of ?
Fill the blanksInteractive · disabled in the PDF
Factor completely: . It is a difference of squares twice.
Dividing polynomials works like long division of numbers: divide the leading terms, multiply back, subtract, bring down, repeat. You end with a quotient and a remainder whose degree is less than the divisor’s. Here is .
Dividend = divisor × quotient + remainder, exactly as .
Dividing by is so common it has a shortcut, synthetic division: work with the coefficients only. Bring down the leading one; then each next one is the coefficient above plus times the last result. The final number is the remainder. With and coefficients : , then , then , then .
Code challengeInteractive · disabled in the PDF
Write divideByLinear(p, r): divide the polynomial p (whole-number coefficients, constant first) by , returning a Division: a struct holding the quotient, also constant first, and the remainder.
C++
1#include<vector>23structDivision{4 std::vector<int> quotient;5int remainder;6};78DivisiondivideByLinear(const std::vector<int>& p,int r){9 std::vector<int> quotient;10 // TODO: synthetic division, from the leading coefficient down11return Division{quotient,0};12}
Algebra134 / 260
Module 11 · Polynomials and factoring
The remainder and factor theorems
Put into : the first part becomes , leaving . That is the remainder theorem: dividing by leaves remainder . And so the factor theorem: is a factor exactly when , that is, when is a root.
p(x) = x³ − 2x² − 5x + 6
Remainder p(r)−4
Drag r along the axis. The height of the curve at r is the remainder of dividing by x − r; it is 0 at the three roots.
So : knowing the roots is knowing the factors. To find a first root of a polynomial with whole-number coefficients, try small divisors of the constant term, here .
QuizInteractive · disabled in the PDF
What is the remainder when is divided by ?
What is the remainder when is divided by ?
QuizInteractive · disabled in the PDF
Which of these is a factor of ?
Which of these is a factor of ?
ProblemInteractive · disabled in the PDF
Let . Find the remainder when is divided by . Then show that is a factor, and find all three roots of .
Going deeper
The rational root theorem makes the guessing systematic: if in lowest terms is a root of a polynomial with integer coefficients, then divides the constant term and divides the leading coefficient. For the only candidates are , and all work.
Algebra135 / 260
Module 11 · Polynomials and factoring
Roots, touching and the ends of the graph
A polynomial of degree has at most real roots: each root gives a factor of degree 1, and there is only room for of them. A factor that appears twice, as in , is a double root: the graph touches the axis there and turns back instead of crossing. In general, a root of even multiplicity touches; odd crosses.
Far from the origin, the leading term outgrows all the others, so it decides the end behaviour. Even degree: both ends go the same way, up if the leading coefficient is positive. Odd degree: the ends go opposite ways.
y = a(x + 1)ᵐ(x − 2)
Degree3
Change m, how many times the factor (x + 1) appears, and the sign and size of a. Even m touches at −1; odd m crosses.
QuizInteractive · disabled in the PDF
As grows large and positive, what does do?
As grows large and positive, what does do?
Algebra136 / 260
Module 11 · Polynomials and factoring
Practice problems
ProblemInteractive · disabled in the PDF
Multiply out and collect like terms. Give each coefficient of the result.
ProblemInteractive · disabled in the PDF
Divide by . Give the quotient and the remainder.
ProblemInteractive · disabled in the PDF
Find the number for which is a factor of . With that , find the other two roots.
Algebra137 / 260
Module 11 · Polynomials and factoring
More practice problems
ProblemInteractive · disabled in the PDF
Find all three roots of . One of them is a fraction.
ProblemInteractive · disabled in the PDF
An open box is made from a by sheet of card: cut a square of side from each corner and fold up the sides. Its volume is . Find the volume when , and write in standard form.
cm³
Algebra138 / 260
Module 11 · Polynomials and factoring
Recap
A polynomial is a sum of coefficients times whole-number powers of ; its degree is the highest power.
Add by collecting like terms; a minus before brackets flips every sign inside.
Multiply every term by every term; powers and degrees add.
Know and .
Factor in order: common factor, grouping, then patterns. Check by multiplying back.
Dividing by leaves remainder ; is a factor exactly when .
Degree means at most real roots; the leading term decides the ends of the graph.
FlashcardsInteractive · disabled in the PDF
The degree of a polynomial
Its highest power of with a non-zero coefficient.
, the difference of two squares.
The remainder theorem
Dividing by leaves remainder .
The factor theorem
is a factor of exactly when .
Horner’s method
Evaluate from the leading coefficient down: multiply by , add the next coefficient.
A double root
A root whose factor appears twice; the graph touches the axis there instead of crossing.
Module 12: Quadratic equations and parabolas
Algebra139 / 260
Module 12 · Quadratic equations and parabolas
A quadratic draws a parabola
A quadratic is a polynomial of degree 2: with . Its graph is a parabola, a U shape. If it opens upwards and has a lowest point; if it opens downwards and has a highest point. That turning point is the vertex, and the parabola is mirror-symmetric about the vertical line through it, the axis of symmetry.
y = ax² + bx + c
Axis of symmetry x1
Vertex height−4
Drag a, b and c. a sets the width and which way it opens, c is where it crosses the y axis, and b slides the vertex along a curve.
The vertex sits at ; this module shows why. A quadratic equation asks where the parabola meets a height, usually : the solutions of are the roots, the points where the graph crosses the axis.
QuizInteractive · disabled in the PDF
Which of these is a quadratic equation?
Which of these is a quadratic equation?
Algebra140 / 260
Module 12 · Quadratic equations and parabolas
Vertex form shows the turning point
The same parabola can be written in vertex form, . Since is never negative and is only at , the lowest (or highest) value is , reached at . So the vertex is , read straight off. It is the graph of shifted right by , up by , and stretched by .
y = x²
y = a(x − h)² + k
Move h and k: the vertex follows them. Note the minus sign: shifts right.Expanding vertex form gives standard form. Check the vertex formula: , matching .
QuizInteractive · disabled in the PDF
Where is the vertex of , and does it open up or down?
Where is the vertex of , and does it open up or down?
Algebra141 / 260
Module 12 · Quadratic equations and parabolas
Solving by factoring
The key fact is the zero product property: if , then or . No other number has this power; tells you nothing so simple. So move everything to one side, factor, and set each factor to zero.
Check both in the original equation: and . A quadratic equation can have two solutions, and losing one is the usual mistake.
Find the bugInteractive · disabled in the PDF
This solution of finds only one of its two solutions. Which line loses the other?
Text
Algebra142 / 260
Module 12 · Quadratic equations and parabolas
A square has two square roots
When the equation is just “something squared equals a number”, take square roots, and keep both signs: means or , written . The symbol means only the positive root, 3; the is your job.
When there is no real solution. has no real solution: no real number squared is negative. The module on complex numbers builds numbers that do solve it.
QuizInteractive · disabled in the PDF
Solve .
Solve .
Algebra143 / 260
Module 12 · Quadratic equations and parabolas
Completing the square
Not every quadratic factors nicely. Completing the square works for all of them: it turns into a perfect square by adding the right number. Picture as an by square plus two strips by along its sides. The shape is almost a square of side ; only the corner is missing. Add and it is complete.
So or . Neither is a whole number, which is why factoring would not find them.
Put in orderInteractive · disabled in the PDF
Put the steps for solving by completing the square in order.
1.Move the constant across:
2.Take square roots, both signs:
3.Halve the coefficient of and square it:
4.Add 16 to both sides:
5.Write the left as a square:
ProblemInteractive · disabled in the PDF
Write in vertex form , then solve exactly.
Going deeper
Completing the square also converts standard form to vertex form: , so the vertex is . Done with letters, , which is where comes from.
Algebra144 / 260
Module 12 · Quadratic equations and parabolas
The quadratic formula, derived
Complete the square once, on with letters, and you get a formula that solves every quadratic. Divide by first so the term is alone.
The two roots sit symmetrically either side of , the axis of symmetry, at a distance . In code, work out the part under the root first.
Fill the blanksInteractive · disabled in the PDF
Finish the larger root, for .
C++
1doublelargerRoot(double a,double b,double c){2double d = b * b -* a * c;3return(-b + std::(d))/();4}
Algebra145 / 260
Module 12 · Quadratic equations and parabolas
Using the formula, step by step
Solve . Read off , , , signs included, then substitute carefully.
Check : .
Code challengeInteractive · disabled in the PDF
Write solveQuadratic(a, b, c): the real roots of () in increasing order. Return two roots, one when , or none (an empty vector, {}).
Solve with the quadratic formula. Give the discriminant, and the two roots exactly.
Algebra146 / 260
Module 12 · Quadratic equations and parabolas
The discriminant counts the roots
The number under the root, , is the discriminant. It tells you how many real roots there are without solving anything, and on the graph it tells you whether the parabola crosses the axis, touches it, or misses it.
Discriminant
Real roots
The parabola
two
crosses the axis twice
one (a double root)
touches the axis at its vertex
none
stays on one side of the axis
y = x² − 2x + c
Discriminant 4 − 4c12
Raise c and watch the discriminant fall through 0 as the parabola lifts off the axis at c = 1.
QuizInteractive · disabled in the PDF
How many real solutions does have?
How many real solutions does have?
Going deeper
The roots also obey Vieta’s formulas: their sum is and their product is , because . They hold even when the roots are complex, and they give a quick check: for , and .
Algebra147 / 260
Module 12 · Quadratic equations and parabolas
When the textbook formula fails a computer
A double, a floating-point number, keeps about 16 significant digits. When is huge compared with and , is almost exactly , and subtracts two nearly equal numbers: most digits cancel and what is left is rounding noise. This is catastrophic cancellation. For , the small root is about , but the formula, run in doubles, gives , wrong by 25%.
The fix: compute the root that adds two numbers of the same sign, which loses nothing, then get the other from Vieta’s product .
Code challengeInteractive · disabled in the PDF
The starter uses the textbook formula. Rewrite stableRoots(a, b, c) with the stable version above, returning both roots in increasing order. Assume and ; take as 1. b >= 0 ? d : -d is d when b >= 0, and -d otherwise.
C++
1#include<algorithm>2#include<cmath>3#include<vector>45std::vector<double>stableRoots(double a,double b,double c){6double d = std::sqrt(b * b -4* a * c);7double r1 =(-b - d)/(2* a);8double r2 =(-b + d)/(2* a);9return{std::min(r1, r2), std::max(r1, r2)};10}
Algebra148 / 260
Module 12 · Quadratic equations and parabolas
The vertex answers biggest and smallest
Many real questions ask for the most or the least of something, and when the quantity is a quadratic, the answer is its vertex. You have 40 metres of fencing for a rectangular pen. If one side is metres, the other is , and the area is square metres. That parabola opens down, so its vertex is the maximum: , a 10 m by 10 m square with area .
A = w(20 − w)
Length (m)14
Area (m²)84
Drag the width. The area peaks at w = 10 m, and widths the same distance either side give the same area.
QuizInteractive · disabled in the PDF
A ball thrown straight up at has height metres after seconds. What is its greatest height, to one decimal place?
A ball thrown straight up at has height metres after seconds. What is its greatest height, to one decimal place?
Algebra149 / 260
Module 12 · Quadratic equations and parabolas
Practice problems
ProblemInteractive · disabled in the PDF
For which positive number does have exactly one real solution? What is that solution?
ProblemInteractive · disabled in the PDF
A rectangle is longer than it is wide, and its area is . Find its width and its length.
cm
cm
ProblemInteractive · disabled in the PDF
One solution of is . Find and the other solution.
Algebra150 / 260
Module 12 · Quadratic equations and parabolas
More practice problems
ProblemInteractive · disabled in the PDF
A ball is thrown upwards from above the ground. Its height after seconds is metres. When is it highest, how high is that, and when does it hit the ground?
s
m
s
ProblemInteractive · disabled in the PDF
A shop sells 200 mugs a week at 8 euros each. For every 1 euro it adds to the price, it sells 10 fewer mugs a week. Which price brings in the most money, and how much is that a week?
euros
euros
Algebra151 / 260
Module 12 · Quadratic equations and parabolas
Recap
draws a parabola, opening up when , with its vertex at .
Vertex form shows the vertex directly.
Solve by factoring with the zero product property; never divide by something that might be 0.
Taking a square root gives two answers, .
Completing the square solves every quadratic, and done in general it gives the formula .
The discriminant says two, one or no real roots.
In floating point, compute one root without cancellation and the other from .
FlashcardsInteractive · disabled in the PDF
The quadratic formula
The vertex of
At ; its height is .
Vertex form
, with vertex .
The discriminant
: positive, two roots; zero, one; negative, none (real).
Zero product property
If then or .
Vieta’s formulas
Roots sum to and multiply to .
Completing the square on
Add : .
Module 13: Rational and radical expressions
Algebra152 / 260
Module 13 · Rational and radical expressions
A rational expression is a fraction of polynomials
A rational number is one integer over another, like . A rational expression is the same idea one level up: one polynomial over another, like or . It works like a fraction in every way, with one new worry: the bottom can be zero for some values of , and dividing by zero has no meaning.
So every rational expression comes with a domain: the values of it is allowed to take. To find what is left out, set the denominator to zero and solve. Here gives or , so those two are excluded.
Write the excluded values next to the expression, and keep them through every step.
Rational expression
A polynomial divided by a polynomial that is not zero everywhere: .
Domain
The values the variable may take: here, every with .
Excluded value
A value of that makes a denominator zero, so the expression has no value there.
QuizInteractive · disabled in the PDF
What is the domain of ?
What is the domain of ?
Algebra153 / 260
Module 13 · Rational and radical expressions
Simplify by cancelling factors, never terms
You simplify by spotting the common factor 2: . Rational expressions are the same: factor the top and the bottom fully (the factoring module showed how), then cancel any factor that appears in both. A factor is something multiplied; only those cancel.
is a factor of both, so it cancels. stays excluded, as the quiz before said.
Don't
Cancel the in to get .
Try : the original is , not .
Do
Factor first: .
Now is a factor of both, so it is .
QuizInteractive · disabled in the PDF
Which simplification is right?
Which simplification is right?
ProblemInteractive · disabled in the PDF
Simplify , and give the two values of it excludes.
Going deeper
Strictly, and are different functions: the first has no value at , the second has . They agree everywhere else. That is why the excluded values are written next to the simplified form: with them, the two really are equal.
Algebra154 / 260
Module 13 · Rational and radical expressions
Excluded values are holes or walls
An excluded value shows on the graph in one of two ways. If its factor cancels, the graph is the simpler curve with a single point missing: a hole. If the factor stays in the denominator, the values grow without bound as comes near it: the graph shoots up or down along a vertical asymptote, a line it gets ever closer to and never touches.
y = (x² − 1)/(x − 1)
for every : a straight line with one point, , missing.
y = k/(x − 1) + b
Horizontal asymptote
Value at x = 21
Value at x = 0−1
Drag k and b: the wall at never moves, because the factor stays in the denominator.
Code challengeInteractive · disabled in the PDF
Finish evalRational(num, den, x). Each polynomial is a list of coefficients, highest power first ({1, 0, -1} is ). Return its value at x, or std::nullopt where the denominator is zero: a std::optional<double> (from <optional>) holds a double or nothing, so return value; fills it and return std::nullopt; leaves it empty.
C++
1#include<optional>2#include<vector>34std::optional<double>evalRational(const std::vector<double>& num,5const std::vector<double>& den,6double x){7 // TODO: evaluate both polynomials at x8return0;9}
Algebra155 / 260
Module 13 · Rational and radical expressions
Multiply and divide as you would fractions
Multiply tops together and bottoms together, then cancel common factors. It is easiest to factor everything before multiplying out, so the common factors are in plain sight. To divide, multiply by the second expression flipped over (its reciprocal).
Dividing excludes one more kind of value: where the divisor is zero. Here at .
QuizInteractive · disabled in the PDF
Which values are excluded from ?
Which values are excluded from ?
Algebra156 / 260
Module 13 · Rational and radical expressions
Add and subtract over a common denominator
As with , you can only add fractions with the same denominator. Find the least common denominator (the product of every factor that appears, each as often as it does in any one denominator), rewrite each fraction over it, then add the tops.
Bottoms are never added. is not . Try : the left is , the right is . And when you subtract, the minus applies to the whole second numerator: put it in brackets before you expand.
QuizInteractive · disabled in the PDF
What is ?
What is ?
PlaygroundInteractive · disabled in the PDF
C++
1#include<iomanip>2#include<iostream>34doubleleft(double x){return3/(x -2)-1/(x +2);}5doubleright(double x){return(2* x +8)/(x * x -4);}67intmain(){8 std::cout << std::fixed << std::setprecision(6); // 6 decimals9for(int x : {-3,0,1,5,10}){10 std::cout << x <<" "<<left(x)<<" "<<right(x)<<"\n";11}12}
A numeric check: both sides agree at every tried. Change right to the wrong answer, with 2 * x + 4, and run it again.
Algebra157 / 260
Module 13 · Rational and radical expressions
Solve rational equations by clearing the denominators
To solve an equation with fractions, multiply both sides by the common denominator. The fractions disappear and you are left with a polynomial equation you already know how to solve. The catch: you multiplied by something that is zero at the excluded values, and multiplying both sides by zero makes any equation true. So a solution of the new equation may not solve the old one. Such a fake solution is called extraneous, and the only defence is to check every answer against the domain.
Check : both sides are .
Sometimes nothing survives. In , multiplying by gives , so , which is excluded: the equation has no solution.
Put in orderInteractive · disabled in the PDF
Put the steps for solving a rational equation in order.
1.Write down the excluded values
2.Throw out any answer that is an excluded value
3.Multiply both sides by the least common denominator
4.Solve the polynomial equation that is left
5.Factor every denominator
Code challengeInteractive · disabled in the PDF
Finish checkSolutions(candidates, lhs, rhs): keep only the candidates where lhs(x) and rhs(x) are both finite numbers (std::isfinite) and differ by less than 1e-9. The two sides are functions passed in, as std::function<double(double)> (from <functional>): something you call with a double that returns a double. The tests write them in place as lambdas, [](double x) { return x + 1; }.
C++
1#include<cmath>2#include<functional>3#include<vector>45std::vector<double>checkSolutions(6const std::vector<double>& candidates,7 std::function<double(double)> lhs,8 std::function<double(double)> rhs){9 // TODO: keep only the real solutions10return candidates;11}
Algebra158 / 260
Module 13 · Rational and radical expressions
Simplify radicals and rationalise the denominator
A radical is a root: , . For , roots split over products, , so you can take out any square factor: . They do not split over sums: , not .
By habit, a final answer has no root in its denominator. To rationalise it, multiply top and bottom by the same thing. For a single root, use the root itself: . For , use its conjugate , because has no root left.
QuizInteractive · disabled in the PDF
Which is in simplest form?
Which is in simplest form?
Going deeper
is , not : the square root sign means the root that is not negative, so . Roots are also powers, , so every rule for exponents applies to them: .
Algebra159 / 260
Module 13 · Rational and radical expressions
Radical equations: isolate, square, check
To solve an equation with a square root, get the root alone on one side, then square both sides. Squaring is not reversible: and are both , so the squared equation also solves the case where the two sides are opposites. That adds extraneous roots, and again the only defence is checking each one in the original equation.
Check: at , . At , but . Only solves it.
y = √(x + 7)
y = −√(x + 7)
y = x + 1
Squaring also solves , the dashed curve. That is where the extra root came from.
Find the bugInteractive · disabled in the PDF
This solves by squaring, then tries to drop the extraneous roots. It still returns for , . Which line is wrong?
C++
ProblemInteractive · disabled in the PDF
Solve . Squaring gives two candidates: which one is the solution, and which is extraneous?
Algebra160 / 260
Module 13 · Rational and radical expressions
Far from zero, the leading terms decide
When is huge, the highest powers swamp everything else: at , is , almost exactly . So far out, a rational function behaves like the ratio of its leading terms, and that ratio says whether the graph settles toward a horizontal asymptote.
Degrees
Far out it behaves like
Example
Top lower than bottom
Equal
The ratio of leading coefficients
Top one higher
A slanted line (found by long division)
Top two or more higher
No line: it grows like a polynomial
y = (2x² + 1)/(x² − 4)
y = 2
Walls at , where the bottom is zero; far out, the curve hugs .
QuizInteractive · disabled in the PDF
Which line does approach as grows?
Which line does approach as grows?
Going deeper
Unlike a vertical asymptote, a horizontal one may be crossed: it only describes the far ends. crosses at the origin, then settles back toward it on both sides. Calculus makes “approaches” exact with limits: .
Algebra161 / 260
Module 13 · Rational and radical expressions
Practice problems
ProblemInteractive · disabled in the PDF
Write as one fraction over the common denominator . What is its numerator, and what is the expression’s value at ?
ProblemInteractive · disabled in the PDF
Solve .
ProblemInteractive · disabled in the PDF
Solve .
ProblemInteractive · disabled in the PDF
For , find the vertical asymptote, the horizontal asymptote, and the hole in the graph.
Algebra162 / 260
Module 13 · Rational and radical expressions
More practice problems
ProblemInteractive · disabled in the PDF
Rationalise the denominator of , and write the result as .
ProblemInteractive · disabled in the PDF
Two pipes together fill a tank in 4 hours. Alone, the larger pipe would fill it 6 hours faster than the smaller one. How long does each take alone?
hours
hours
Algebra163 / 260
Module 13 · Rational and radical expressions
Recap
A rational expression is a polynomial over a polynomial; it has no value where the bottom is zero.
Simplify by factoring and cancelling factors, never terms; the excluded values stay excluded.
Multiply, divide, add and subtract as with number fractions; adding needs a common denominator.
A cancelled factor leaves a hole; one that stays leaves a vertical asymptote.
Clearing denominators and squaring both can add extraneous solutions: check every answer in the original.
Take square factors out of roots, and rationalise denominators with the conjugate.
Far out, the ratio of leading terms decides the horizontal or slanted asymptote.
FlashcardsInteractive · disabled in the PDF
What is excluded from a rational expression’s domain?
Every value that makes a denominator zero.
What can you cancel in a fraction?
Common factors, things multiplied on top and bottom. Never terms that are added.
Extraneous solution
An answer of a transformed equation that does not solve the original one.
Hole or vertical asymptote?
A hole if the factor cancels; an asymptote if it stays in the denominator.
Conjugate of
: their product has no root.
Horizontal asymptote when the degrees are equal
The ratio of the leading coefficients.
Module 14: Exponentials and logarithms
Algebra164 / 260
Module 14 · Exponentials and logarithms
Exponential growth multiplies by the same factor
A linear quantity adds the same amount each step: 10, 20, 30, 40. An exponential one multiplies by the same factor each step: 1, 2, 4, 8, 16. A colony of bacteria that doubles every hour is exponential. At first it looks slow, then it overtakes any linear growth you name.
is the value at ; is what it is multiplied by for each step of 1 in .One bacterium doubling every hour: . After 8 hours, 256; after 24, over 16 million.
Exponential function
A function : the variable is in the exponent.
Initial value
, the value when .
Growth factor
, what the value is multiplied by per step.
Growth rate
, the percentage change per step, with : growing 3% means .
QuizInteractive · disabled in the PDF
Savings grow by 3% each year. What is the growth factor ?
Savings grow by 3% each year. What is the growth factor ?
Algebra165 / 260
Module 14 · Exponentials and logarithms
The base decides growth or decay
If the function grows; if it decays, losing the same fraction each step. Either way it stays above zero, passes through , and on one side flattens toward the -axis, a horizontal asymptote, without ever reaching it.
y = a·bˣ
f(1)1.5
f(4)5.063
Drag b below 1 and the curve turns from growth into decay. a only stretches it.
QuizInteractive · disabled in the PDF
A car worth 20 000 euros loses 15% of its value each year. Which models its value after years?
A car worth 20 000 euros loses 15% of its value each year. Which models its value after years?
Algebra166 / 260
Module 14 · Exponentials and logarithms
Compound interest is exponential growth
A bank pays a yearly rate , but adds the interest times a year, each time of what is there. Interest then earns interest: that is compounding. After years there have been steps, each multiplying by .
is the starting amount (the principal) and the amount at the end.1000 euros at 5% for 10 years. Compounding more often helps, but less and less.
Code challengeInteractive · disabled in the PDF
Write compound(P, r, n, t): the amount after t years when P earns the yearly rate r (0.05 for 5%), compounded n times a year.
C++
1#include<cmath>23doublecompound(double P,double r,double n,double t){4 // TODO: n*t steps, each multiplying by 1 + r/n5return P;6}
ProblemInteractive · disabled in the PDF
You put 2500 euros in an account paying 4% a year, compounded quarterly. How much is there after 6 years, and how much of that is interest?
euros
euros
Going deeper
Banks quote an annual equivalent rate so different compounding schemes can be compared: the single yearly rate that gives the same result. For 5% compounded monthly it is .
Algebra167 / 260
Module 14 · Exponentials and logarithms
The number e is compounding without end
Push compounding to the limit: a rate of 100% for one year, paid times. Each step multiplies by , so one euro becomes . As grows, this does not run off to infinity: it settles on a number called .
Paid
One euro becomes
Yearly
1
2
Twice a year
2
2.25
Monthly
12
2.61304
Daily
365
2.71457
About twice a minute
1 000 000
2.71828
Compounded continuously, at rate grows to . is often called the exponential function.
PlaygroundInteractive · disabled in the PDF
C++
1#include<cmath>2#include<iomanip>3#include<iostream>4#include<numbers>5#include<vector>67intmain(){8 std::cout << std::setprecision(16);9 std::vector<double> ns ={1,2,12,365,1e6,1e9};10for(double n : ns){11 std::cout << n <<" "<< std::pow(1+1/ n, n)<<"\n";12}13 std::cout <<"e "<< std::numbers::e <<"\n";14}
Run it, then try 1e16: past a point, 1 + 1 / n rounds to exactly 1 and the answer collapses.
QuizInteractive · disabled in the PDF
About how much do 1000 euros become at 5% compounded continuously for 10 years?
About how much do 1000 euros become at 5% compounded continuously for 10 years?
Algebra168 / 260
Module 14 · Exponentials and logarithms
A logarithm asks which power
Exponentials answer “what is ?”. The reverse question, “2 to which power is 32?”, is answered by a logarithm: . A logarithm is an exponent. is often written just , and is the natural logarithm, .
Logarithm
Because
y = 2ˣ
y = log₂ x
y = x
undoes , so its graph is the mirror image across .
QuizInteractive · disabled in the PDF
What is ?
What is ?
Going deeper
Since is always positive, of zero or of a negative number has no real value: the graph lives only at , with the -axis as a vertical asymptote. That is another domain restriction to check when solving equations with logarithms.
Algebra169 / 260
Module 14 · Exponentials and logarithms
The laws of logarithms come from the laws of exponents
Exponents add when powers multiply: . Since logarithms are exponents, they turn multiplication into addition. Write and ; then , so . The other two laws follow the same way.
Not laws
Laws
QuizInteractive · disabled in the PDF
What is ?
What is ?
Going deeper
Turning products into sums is why logarithms were invented. Before calculators, astronomers multiplied long numbers by looking up their logs in printed tables, adding, and looking the sum up again. A slide rule is the same trick in wood: its scales are spaced by logarithm, so sliding lengths together adds logs and multiplies numbers.
Algebra170 / 260
Module 14 · Exponentials and logarithms
Change of base: any logarithm from one you have
Calculators and programming languages give you and , rarely . You do not need more: any logarithm is a ratio of two logarithms in a base you have.
Take of both sides, bring the power down, and divide.
Fill the blanksInteractive · disabled in the PDF
In C++, std::log (from <cmath>) is the natural logarithm. Finish logBase with the change-of-base rule.
C++
1doublelogBase(double x,double b){2return std::(x)/ std::log();3}45double four =logBase(81,); // 4
QuizInteractive · disabled in the PDF
What is , to three decimals?
What is , to three decimals?
Algebra171 / 260
Module 14 · Exponentials and logarithms
Solve exponential equations by taking logarithms
When the unknown is in an exponent, get the power alone, then take a logarithm of both sides: the power law brings the unknown down where you can reach it.
How long does money take to double at 5% a year? Solve : divide to get , so years. The starting amount cancels: the doubling time depends only on the rate. Bankers estimate it with the rule of 72: .
Code challengeInteractive · disabled in the PDF
The starter uses the rule of 72. Make doublingTime(r) exact: the number of years for an amount to double at the yearly rate r, compounded yearly.
C++
1#include<cmath>23doubledoublingTime(double r){4 // TODO: the rule of 72 is only a rough estimate5return72/(100* r);6}
ProblemInteractive · disabled in the PDF
Solve exactly, and to three significant figures.
Algebra172 / 260
Module 14 · Exponentials and logarithms
Half-life: decay measured in halvings
Radioactive atoms decay at random, but a large number of them decays exponentially. The half-life is the time for half of them to go. After one half-life, is left; after two, ; after half-lives, .
is the amount at the start, the amount after time .
N(t)
Left after 10 years (%)17.7
Drag T: the point at half the start always sits at .Carbon-14 has a half-life of 5730 years. A bone with 30% of its carbon-14 left died about 9950 years ago.
QuizInteractive · disabled in the PDF
What fraction of a sample is left after three half-lives?
What fraction of a sample is left after three half-lives?
Code challengeInteractive · disabled in the PDF
Write ageFromFraction(fraction, halfLife): how long ago a sample started decaying, if fraction of it is left now (0.25 for a quarter).
C++
1#include<cmath>23doubleageFromFraction(double fraction,double halfLife){4 // TODO: how many half-lives does it take to reach fraction?5return0;6}
Algebra173 / 260
Module 14 · Exponentials and logarithms
Log scales put huge ranges on one ruler
Some quantities span so many powers of ten that a normal scale is useless. A logarithmic scale gives each power of ten the same space, so a step of 1 means “multiply by 10”. Sound level in decibels is , where is the sound’s intensity and the faintest sound people hear: every 10 dB is ten times the intensity. Acidity is pH , the concentration of hydrogen ions in moles per litre.
Equal steps on this chart are equal factors: the concert is 50 dB above the conversation, times the intensity.
QuizInteractive · disabled in the PDF
A drink has pH 3 and water pH 5. How do their hydrogen ion concentrations compare?
A drink has pH 3 and water pH 5. How do their hydrogen ion concentrations compare?
Going deeper
Take logs of : , a straight line in with slope . So data that grows exponentially looks straight when its -axis is logarithmic, and scientists test for exponential growth exactly this way. Likewise a power law becomes the line on log-log axes, with slope .
Algebra174 / 260
Module 14 · Exponentials and logarithms
Practice problems
ProblemInteractive · disabled in the PDF
Without a calculator, find and .
ProblemInteractive · disabled in the PDF
Solve .
ProblemInteractive · disabled in the PDF
A medicine has a half-life of 6 hours in the body. After a dose of 400 mg, how much is left after 15 hours, and how long until only 50 mg is left?
mg
hours
Algebra175 / 260
Module 14 · Exponentials and logarithms
More practice problems
ProblemInteractive · disabled in the PDF
A town had 12 000 people in 2020 and 13 500 in 2025. If it grows exponentially, what is its yearly growth factor, and how many years after 2020 does it reach 20 000?
years
ProblemInteractive · disabled in the PDF
Sound level is decibels. How many times more intense is a 70 dB sound than a 40 dB one? And if one speaker plays at 80 dB, what level do two identical speakers make together (twice the intensity)?
dB
Algebra176 / 260
Module 14 · Exponentials and logarithms
Recap
multiplies by each step: growth for , decay for ; .
Compound interest is ; compounding without end gives .
is the limit of ; is the logarithm in base .
means : a logarithm is an exponent, and only positive numbers have one.
Logs turn products into sums, quotients into differences and powers into factors, and nothing else.
Change of base: . Solve for an exponent by taking logs of both sides.
Half-life: . Log scales such as decibels and pH count factors of ten.
FlashcardsInteractive · disabled in the PDF
Growth factor for a 4% rise
Growth factor for a 4% fall
means
Change of base
Doubling time at rate
, roughly the percentage.
Left after half-lives
of the start.
Module 15: Sequences, series and induction
Algebra177 / 260
Module 15 · Sequences, series and induction
A sequence is a list that follows a rule
A sequence is an ordered list of numbers: 3, 7, 11, 15, … Each number is a term, and its place in the list is its index. You write the terms , so and here. A sequence is really a function whose inputs are the whole numbers 1, 2, 3, …: give it an index , and it gives back the term .
The sequence 3, 7, 11, 15, … as bars: each one is 4 taller than the one before.
Sequence
An ordered list of numbers, usually following a rule.
Term
One number in the list. is the term at index .
Explicit rule
A formula that gives straight from , such as .
Recursive rule
A rule that gives each term from the ones before it, such as .
QuizInteractive · disabled in the PDF
Which explicit rule gives 3, 7, 11, 15, …?
Which explicit rule gives 3, 7, 11, 15, …?
Algebra178 / 260
Module 15 · Sequences, series and induction
Arithmetic sequences add the same amount each time
An arithmetic sequence adds a fixed number, the common difference , to get from one term to the next. To reach term from the first, you take steps of (not : from to is one step).
The -th term of an arithmetic sequence.The 20th term of 5, 2, −1, −4, …: the difference can be negative.
QuizInteractive · disabled in the PDF
The sequence 7, 12, 17, … has which term equal to 102?
The sequence 7, 12, 17, … has which term equal to 102?
Going deeper
Drawn as points , an arithmetic sequence lies on a straight line with slope : it is a linear function, looked at only on the whole numbers.
Algebra179 / 260
Module 15 · Sequences, series and induction
Geometric sequences multiply by the same amount
A geometric sequence multiplies by a fixed number, the common ratio , each time: 2, 6, 18, 54, … has . After steps you have multiplied by that many times. When the terms grow faster and faster; when they shrink toward 0.
The -th term of a geometric sequence.
aₙ = rⁿ⁻¹
a₈6.275
Drag r: above 1 the terms run away, below 1 they fade toward 0, at 1 they stay put.
QuizInteractive · disabled in the PDF
What is the 5th term of 3, 6, 12, …?
What is the 5th term of 3, 6, 12, …?
Algebra180 / 260
Module 15 · Sequences, series and induction
Recursive rules build each term from the last
A recursive rule says where to start and how to get the next term from the ones before it. is the arithmetic sequence from before; is a geometric one. Some sequences are easiest to describe this way: the Fibonacci numbers start 1, 1 and add the last two to get the next.
Fibonacci: 1, 1, 2, 3, 5, 8, 13, 21, …
QuizInteractive · disabled in the PDF
With and , what is ?
With and , what is ?
Code challengeInteractive · disabled in the PDF
Write arithmeticTerm(first, d, n) and geometricTerm(first, r, n): the -th term (counting from 1) of each kind of sequence.
A series is what you get when you add up the terms of a sequence. The Greek capital sigma, , is shorthand for “add these up”. Below and above it you write where the index starts and stops; to its right, the term, written using the index.
Read it as “the sum of , for from 1 to 4”.
Sigma is a loop, written in maths: the index is the loop variable, the bounds are where it starts and stops (both included), and the term is what gets added each time.
Fill the blanksInteractive · disabled in the PDF
Turn into a loop.
C++
1intsumOfSquares(int n){2int total =0;3for(int k =; k <=; k++){4 total +=;5}6return total;7}
Going deeper
Sums split and scale like ordinary addition: and . The index is a dummy: and are the same number.
Algebra182 / 260
Module 15 · Sequences, series and induction
An arithmetic series is pairs that add to the same total
The story goes that a young Carl Friedrich Gauss was told to add 1 to 100 and answered at once. Write the sum forwards and backwards: each column adds to 101, and there are 100 columns, so twice the sum is . The same trick works for any arithmetic series: pair the first with the last.
The number of terms times the average of the first and the last.
QuizInteractive · disabled in the PDF
What is ?
What is ?
Find the bugInteractive · disabled in the PDF
This sums the first n terms of an arithmetic sequence, but arithmeticSum(3, 4, 10) gives 230 instead of 210. Which line is wrong?
C++
ProblemInteractive · disabled in the PDF
Find the sum .
Algebra183 / 260
Module 15 · Sequences, series and induction
A geometric series collapses when you multiply it by r
For a geometric series there is a different trick. Multiply the sum by : every term moves along one place. Subtract, and everything cancels except the first term and one new one at the end.
For example, has , and 10 terms: . When the formula divides by zero, but the series is just added times: .
Code challengeInteractive · disabled in the PDF
Write geometricSum(a, r, n): the sum of the first n terms of the geometric sequence that starts at a with ratio r. Remember the case .
C++
1#include<cmath>23doublegeometricSum(double a,double r,int n){4return a *(1- std::pow(r, n))/(1- r);5}
Algebra184 / 260
Module 15 · Sequences, series and induction
Some infinite sums have a finite total
Walk half-way to a wall, then half of what is left, then half again. You take infinitely many steps, but you never pass the wall: . When , the in the sum formula shrinks to 0 as grows, so the partial sums settle on a limit. The series converges. When the terms never shrink, and the sum has no finite total: it diverges.
Partial sum Sₙ
Limit 1/(1 − r)
Limit2
S₁₀1.998
Partial sums of : drag r toward 1 and they climb to a higher limit, more slowly.
QuizInteractive · disabled in the PDF
What is ?
What is ?
ProblemInteractive · disabled in the PDF
Write the recurring decimal as a fraction in lowest terms, by treating it as an infinite geometric series.
Going deeper
Terms shrinking to 0 is needed but not enough. The harmonic series diverges: group its terms as , , , … and you add more than infinitely often. And is the series exactly.
Algebra185 / 260
Module 15 · Sequences, series and induction
Induction proves a rule for every whole number
Checking a formula on 1, 2 and 3 doesn’t prove it for all . Proof by induction does, like a row of dominoes: show the first one falls (the base case), and show that whenever one falls, so does the next (the inductive step). Then every domino falls. In the step you assume the statement for some (the inductive hypothesis) and prove it for .
The last line is the claim with in place of : the next domino falls.
Put in orderInteractive · disabled in the PDF
Put the parts of a proof by induction in order.
1.Inductive hypothesis: assume is true for some
2.Base case: show is true
3.Inductive step: use it to show is true
4.State the claim for every whole number
5.Conclude that holds for every
Going deeper
Where proofs by induction go wrong. The famous false proof that “all horses are the same colour” has a step from to that quietly needs two groups of horses to overlap. They do for , but not from 1 to 2, so the chain breaks at the first link. When you check a step, check it at the smallest too. Strong induction assumes all at once: handy for Fibonacci-style rules that look two terms back.
Algebra186 / 260
Module 15 · Sequences, series and induction
Pascal’s triangle expands any power of a sum
Expand and every term is times a count: the number of ways to choose from of the brackets. That count is the binomial coefficient , “ choose ”. Written in rows, they make Pascal’s triangle, where each number is the sum of the two above it: .
Each row starts and ends with 1; inside, add the two numbers above.Row 6 of the triangle: the coefficients of , biggest in the middle.
QuizInteractive · disabled in the PDF
What is the coefficient of in ?
What is the coefficient of in ?
Algebra187 / 260
Module 15 · Sequences, series and induction
Compute the triangle, row by row
Factorials grow so fast that is already past , where a double stops holding every whole number exactly, and from on they are rounded. A long long holds whole numbers exactly, but only up to about : fits, does not, and past the limit the arithmetic overflows into nonsense (a negative ), with no error. Pascal’s rule only ever adds, so building rows is a safer way to get . Run this to see the first rows, and the sum of each row: always , because setting gives .
PlaygroundInteractive · disabled in the PDF
C++
1#include<iostream>2#include<vector>34intmain(){5 std::vector<longlong> row ={1};6for(int n =0; n <=6; n++){7longlong total =0;8for(longlong value : row){9 std::cout << value <<" ";10 total += value;11}12 std::cout <<" sum "<< total <<"\n";13 std::vector<longlong> next ={1};14for(std::size_t k =1; k < row.size(); k++){15 next.push_back(row[k -1]+ row[k]);16}17 next.push_back(1);18 row = next;19}20}
Change 6 to 12 and look at the middle numbers.
Code challengeInteractive · disabled in the PDF
Write choose(n, k): the binomial coefficient for whole numbers , as a long long. Pascal’s rule or the product both work.
C++
1#include<vector>23longlongchoose(int n,int k){4 // TODO: build Pascal's triangle down to row n5return0;6}
Algebra188 / 260
Module 15 · Sequences, series and induction
Practice problems
ProblemInteractive · disabled in the PDF
A geometric sequence has and . Find the common ratio, the first term and .
ProblemInteractive · disabled in the PDF
Find . Then use to find .
ProblemInteractive · disabled in the PDF
In the expansion of , find the coefficient of and the coefficient of .
Algebra189 / 260
Module 15 · Sequences, series and induction
More practice problems
ProblemInteractive · disabled in the PDF
A job pays 30 000 euros in its first year, with a 3% rise every year. What is the pay in year 10, and how much is earned over the first 10 years in all?
euros
euros
ProblemInteractive · disabled in the PDF
A ball is dropped from 10 m. After each bounce it rises to 60% of the height it fell from. How high does it rise after the third bounce, and how far does it travel, up and down, before it comes to rest?
m
m
Algebra190 / 260
Module 15 · Sequences, series and induction
Recap
Arithmetic: add each time, , and .
Geometric: multiply by , , and for .
An infinite geometric series converges to exactly when .
Sigma notation is a loop: the index runs from the bottom bound to the top, both included.
Induction: prove the base case, then that each case gives the next.
expands with the binomial coefficients , the rows of Pascal’s triangle.
FlashcardsInteractive · disabled in the PDF
Common difference
What an arithmetic sequence adds each step: .
Common ratio
What a geometric sequence multiplies by: .
Series
The sum of a sequence’s terms.
When does converge?
When ; its sum is .
The two parts of a proof by induction
The base case, and the inductive step from to .
Pascal’s rule
Module 16: Angles, triangles and trigonometry
Algebra191 / 260
Module 16 · Angles, triangles and trigonometry
An angle measures a turn
An angle says how far one line has turned away from another, about the point where they meet (the vertex). The everyday unit is the degree: a full turn is , a half turn , and a quarter turn, a right angle, . Angles under are acute, between and obtuse. The angles of any triangle add up to .
Vertex
The point where the two sides of an angle meet.
Degree
One 360th of a full turn, written .
Right angle
A quarter turn, : the corner of a square.
Trigonometry
The study of how angles and lengths in triangles depend on each other.
QuizInteractive · disabled in the PDF
Two angles of a triangle are and . What is the third?
Two angles of a triangle are and . What is the third?
Algebra192 / 260
Module 16 · Angles, triangles and trigonometry
Radians measure an angle by the arc it cuts
Mathematicians prefer a second unit. Draw a circle of radius 1 around the vertex: the radian measure of the angle is the length of the arc between its sides. A full turn is the whole circumference, , so radians is , and one radian is about . For a circle of radius , the arc is , with in radians.
Arc θ
Arc length1
Degrees57.3
Drag θ: the accent arc on the unit circle is θ long, so θ is the angle in radians.
QuizInteractive · disabled in the PDF
How many radians is ?
How many radians is ?
Code challengeInteractive · disabled in the PDF
Write toRadians(degrees) and toDegrees(radians). Use std::numbers::pi, from <numbers>, for .
Radians are not just a convention. Measured in radians, for small angles (), and in calculus the slope of is exactly . In degrees, a factor of would appear in every one of those formulas.
Algebra193 / 260
Module 16 · Angles, triangles and trigonometry
In a right triangle, the angle fixes the ratios of the sides
Pick one of the acute angles of a right triangle, . The longest side, across from the right angle, is the hypotenuse. The side across from is the opposite, and the other short side, touching , the adjacent. Every right triangle with the same has the same shape, just scaled, so the ratios of its sides depend only on . Those ratios have names.
SOH, CAH, TOA: Sine is Opposite over Hypotenuse, and so on.
QuizInteractive · disabled in the PDF
A right triangle has sides 3, 4 and 5. For the angle opposite the side of length 3, what is ?
A right triangle has sides 3, 4 and 5. For the angle opposite the side of length 3, what is ?
Fill the blanksInteractive · disabled in the PDF
Find the two short sides of a right triangle from its hypotenuse and an angle in radians.
C++
1double hypotenuse =5;2double angle = std::numbers::pi /6; // 30 degrees3double opposite = hypotenuse * std::(angle);4double adjacent = hypotenuse * std::(angle);5// their ratio is the tangent6std::cout << opposite / adjacent <<" "<< std::(angle);
Algebra194 / 260
Module 16 · Angles, triangles and trigonometry
Solve a right triangle step by step
A 5 m ladder leans on a wall, making with the ground. How high does it reach, and how far is its foot from the wall? The ladder is the hypotenuse; the height is opposite the angle and the distance along the ground is adjacent to it.
Pythagoras is a free check on any right-triangle answer.
Find the bugInteractive · disabled in the PDF
heightOf(5, 70) should give about 4.70 but gives about 3.87. Which line is wrong?
C++
ProblemInteractive · disabled in the PDF
A kite flies on a straight string that makes with the ground. How high is the kite above the hand holding the string, and how far away is it horizontally?
m
m
Algebra195 / 260
Module 16 · Angles, triangles and trigonometry
The unit circle defines sine and cosine for any angle
A right triangle only has room for angles under . To go further, put the angle at the centre of a circle of radius 1, starting from the positive axis and turning anticlockwise. Where it meets the circle is the point . For acute angles this matches SOH-CAH-TOA (the hypotenuse is 1), and it works for any angle, even negative ones (turning clockwise) or ones past a full turn.
Unit circle
Degrees120.3
cos θ−0.505
sin θ0.863
Drag θ: cos θ is how far across the point is, sin θ how far up. Both turn negative in some quarters.
θ
(30°)
(45°)
(60°)
(90°)
QuizInteractive · disabled in the PDF
What is ?
What is ?
Algebra196 / 260
Module 16 · Angles, triangles and trigonometry
Sine and cosine are waves; tangent repeats with gaps
As goes round and round, goes up and down between and 1, repeating every : it is periodic, with period . Cosine is the same wave shifted left by . In , the amplitude stretches it up and down and squeezes it sideways, so the period becomes .
y = A sin(kx)
y = cos x
Period6.283
Drag A and k: the amplitude sets the height, k how many waves fit in 2π.
y = tan x
Tangent is sin/cos: it has no value where cos θ = 0, at ±π/2, ±3π/2, …, and repeats every π.
QuizInteractive · disabled in the PDF
What is the period of ?
What is the period of ?
Algebra197 / 260
Module 16 · Angles, triangles and trigonometry
Sine squared plus cosine squared is always 1
The point is on the circle of radius 1, so by Pythagoras its coordinates satisfy . That gives the most used identity in trigonometry, an equation true for every angle. Dividing by gives a second one.
means , not .
QuizInteractive · disabled in the PDF
If and is between and , what is ?
If and is between and , what is ?
Algebra198 / 260
Module 16 · Angles, triangles and trigonometry
Angle-sum identities split an angle in two
Sine is not linear: is not (that is against 1). The right rules mix sines and cosines. Setting gives the double-angle formulas.
An exact value from two angles you know.
PlaygroundInteractive · disabled in the PDF
C++
1#include<cmath>2#include<iostream>3#include<numbers>45doublerad(double deg){6return deg * std::numbers::pi /180;7}89intmain(){10double a =rad(45);11double b =rad(30);1213double direct = std::sin(a + b);14double split = std::sin(a)* std::cos(b)+ std::cos(a)* std::sin(b);15double wrong = std::sin(a)+ std::sin(b);1617 std::cout <<"sin 75 directly "<< direct <<"\n";18 std::cout <<"by the identity "<< split <<"\n";19 std::cout <<"sin 45 + sin 30 "<< wrong <<"\n";20}
Try other angles, and check the cosine rule the same way.
Going deeper
Two quick proofs of the sum rules use tools from later modules: with complex numbers, gives both at once; with matrices, rotating by then by is rotating by , and multiplying the two rotation matrices spells the identities out.
Algebra199 / 260
Module 16 · Angles, triangles and trigonometry
The laws of sines and cosines solve any triangle
For a triangle with no right angle, name the sides , , and the angles opposite them , , . The law of sines links each side to its opposite angle; the law of cosines is Pythagoras with a correction for when isn’t (then and it is Pythagoras).
Two sides and the angle between them: the law of cosines gives the third side.
Code challengeInteractive · disabled in the PDF
Write thirdSide(a, b, angleDegrees): the side across from the angle between sides a and b, by the law of cosines.
C++
1#include<cmath>2#include<numbers>34doublethirdSide(double a,double b,double angleDegrees){5return std::sqrt(a * a + b * b);6}
Put in orderInteractive · disabled in the PDF
You know sides , and the angle between them. Put the steps to find everything else in order.
1.Check: the longest side should face the largest angle
2.Find side with the law of cosines
3.Find the last angle: the three add up to
4.Find the angle opposite the shorter of and with the law of sines
ProblemInteractive · disabled in the PDF
A triangle has angles and , and the side opposite is . Find the third angle and the other two sides.
°
cm
cm
Algebra200 / 260
Module 16 · Angles, triangles and trigonometry
Inverse functions turn a ratio back into an angle
Given , which angle is it? Many: , , … To get one answer, the inverse functions use one stretch where the original goes through each value once. (also written ) gives an angle in , one in , and one in .
y = sin x
y = arcsin x
y = x
arcsin is sin on [−π/2, π/2] reflected in the line y = x: inputs and outputs swap.
QuizInteractive · disabled in the PDF
What is ?
What is ?
Code challengeInteractive · disabled in the PDF
Write angleOf(x, y): the angle in degrees, from 0 up to (not including) 360, from the positive axis to the point . std::atan2(y, x) gives an angle in radians between and that knows the quarter.
An angle lies between and , and . Find , and exactly.
ProblemInteractive · disabled in the PDF
For , with in radians, find the amplitude, the period, and the smallest positive where is at its maximum.
Algebra202 / 260
Module 16 · Angles, triangles and trigonometry
More practice problems
ProblemInteractive · disabled in the PDF
A ramp rises over a horizontal distance of . What angle does it make with the ground, in degrees, and how long is the ramp?
°
m
ProblemInteractive · disabled in the PDF
Find every angle from up to with , in degrees.
°
°
ProblemInteractive · disabled in the PDF
Two straight paths leave a point at an angle of to each other. One is long and the other . How far apart are their ends, and what angle does the straight line between the ends make with the path?
km
°
Algebra203 / 260
Module 16 · Angles, triangles and trigonometry
Recap
A full turn is or radians; a radian is the angle whose arc on a unit circle has length 1.
In a right triangle: , , .
On the unit circle, the point at angle is , for any angle.
has amplitude and period ; repeats every .
, and the angle-sum rules mix sines and cosines.
The laws of sines and cosines solve triangles without a right angle; inverse functions give back one angle, from a fixed range.
FlashcardsInteractive · disabled in the PDF
SOH-CAH-TOA
Sine = opposite/hypotenuse, cosine = adjacent/hypotenuse, tangent = opposite/adjacent.
Degrees to radians
Multiply by .
,
Both .
The Pythagorean identity
The law of cosines
The range of
, or .
Module 17: Complex numbers
Algebra204 / 260
Module 17 · Complex numbers
A number whose square is minus one
Every real number squared is 0 or more, so has no real solution. Mathematicians did what they did when they invented negative numbers: they added a new number that makes the equation solvable. It is called , the imaginary unit, and its only rule is . Everything else follows from the ordinary rules of algebra.
A complex number is , where and are real. is the real part, written , and is the imaginary part, . Real numbers are the complex numbers with , so nothing you knew is lost: the number line sits inside a bigger set, written .
Both and work, since .
Imaginary unit
The number , with .
Complex number
A number with and real.
Real part
in , written .
Imaginary part
in (a real number, without the ), written .
Going deeper
Why they were accepted. Complex numbers were first taken seriously in the 1500s, not for but for cubics. Cardano’s formula for a cubic with three real roots passes through square roots of negative numbers on the way, and the imaginary parts cancel at the end. The detour was the only road to real answers, which forced people to trust it.
Algebra205 / 260
Module 17 · Complex numbers
Adding and multiplying work as you expect
Treat as a letter, collect like terms, and replace by wherever it appears. Adding adds real parts and imaginary parts separately. Multiplying expands the brackets, as with .
In general .
Powers of go round in a cycle of four: , , , , and then it starts again. To find , only the remainder of divided by 4 matters.
QuizInteractive · disabled in the PDF
What is ?
What is ?
Algebra206 / 260
Module 17 · Complex numbers
The conjugate makes division possible
The conjugate of is : the same number with the sign of the imaginary part flipped. Multiplying a number by its conjugate gives a real number, which is what makes it useful.
To divide, multiply the top and the bottom by the conjugate of the bottom. The bottom becomes real, and dividing by a real number is easy. This is the same trick as rationalising .
Fill the blanksInteractive · disabled in the PDF
A complex number in code is a struct C holding two doubles, its real part re and its imaginary part im; C{a, b} makes . Finish divide(z, w), which works out . With and , .
One real number is a point on a line; a complex number needs two real numbers, so it is a point in a plane. The complex plane puts the real part across and the imaginary part up: is the point . Adding complex numbers is then adding arrows tip to tail, and the conjugate is the reflection in the real axis.
|z|3.606
arg z (radians)0.588
Drag the real and imaginary parts. The conjugate mirrors in the real axis; both are the same distance from 0.
No “bigger than”. Real numbers are ordered: one is always left of the other. Points in a plane are not, and no ordering of works with the rules of arithmetic. So means nothing; compare their sizes, , instead.
Algebra208 / 260
Module 17 · Complex numbers
Size and direction: modulus and argument
The arrow to has a length and a direction. The length is the modulus, , from Pythagoras. The direction is the argument, : the angle from the positive real axis, measured anticlockwise, in radians. The usual choice, the principal argument, lies in .
, but points into the fourth quadrant: wrong.
QuizInteractive · disabled in the PDF
What is the principal argument of ?
What is the principal argument of ?
Find the bugInteractive · disabled in the PDF
This gives the wrong argument for . Which line is wrong?
C++
ProblemInteractive · disabled in the PDF
Find the modulus and the principal argument, in radians, of .
Algebra209 / 260
Module 17 · Complex numbers
Polar form and Euler’s formula
Knowing the modulus and the argument is enough to find the point again: and . That gives the polar form. Euler’s formula gives it a short name: is the point on the unit circle at angle .
Unit circle
Real part cos θ0.697
Imaginary part sin θ0.717
Drag θ: walks round the unit circle. At θ = π it is −1.From polar to the form . And at : .
Going deeper
Why ? The series works for complex too. Put in and sort the terms by the powers of : the even ones give , and the odd ones give . Calculus gives a second proof: has derivative 0 and .
Algebra210 / 260
Module 17 · Complex numbers
Multiplying multiplies sizes and adds angles
Polar form shows what multiplication does. Powers of add their exponents, so multiplying two complex numbers multiplies their moduli and adds their arguments. Multiplying by scales the plane by and rotates it by . Multiplying by is a quarter turn anticlockwise.
|zw| = √5 · |w|2.236
arg zw2.034
Here . Drag the size and angle of : the product is turned by and stretched by .
QuizInteractive · disabled in the PDF
What is , and what happened to the point ?
What is , and what happened to the point ?
Algebra211 / 260
Module 17 · Complex numbers
Try it: complex arithmetic in code
C++ has a complex type ready-made: std::complex<double>, from <complex>, with std::abs and std::arg for the modulus and the argument. Building your own shows how it works, so here you make one: a struct, a type of your own that groups named values (its members), here a real part and an imaginary part. C{3, 2} makes , and z.re reads a member. Write multiplication from the rule , and the modulus from Pythagoras.
Code challengeInteractive · disabled in the PDF
Finish multiply(z, w), which returns the product of two complex numbers, and modulus(z), which returns its distance from 0.
Raising to a power multiplies the angle: . This is de Moivre’s theorem. Going backwards, the equation has solutions, the $n$th roots of unity, spaced evenly round the unit circle, because turning by a total of times is one full turn.
The six sixth roots of unity: a regular hexagon. Each is the one before turned by 60°.
Put in orderInteractive · disabled in the PDF
Put the steps for solving in order.
1.Convert back: , and
2.Write in polar form:
3.Divide the argument by 3:
4.Take the real cube root of the modulus:
5.Add twice for the other angles: and
Code challengeInteractive · disabled in the PDF
Finish rootsOfUnity(n): return the solutions of as a vector of C{re, im}, for to in order, where root has angle .
Every polynomial has all its roots in the complex numbers
You added to solve one equation, . The surprise is that you never need to add anything again. The fundamental theorem of algebra says every polynomial of degree , even one with complex coefficients, has exactly complex roots, counted with multiplicity, so it factors completely into linear factors.
A negative discriminant no longer means “no solution”: it means two complex roots, conjugates of each other.
Real coefficients, conjugate pairs. If a polynomial has real coefficients and is a root, so is : conjugating changes nothing but . So non-real roots of real polynomials come in pairs, and a real polynomial of odd degree always has at least one real root.
QuizInteractive · disabled in the PDF
A cubic with real coefficients has roots and . What is its third root?
A cubic with real coefficients has roots and . What is its third root?
QuizInteractive · disabled in the PDF
How many complex roots, counted with multiplicity, does have?
How many complex roots, counted with multiplicity, does have?
Going deeper
Algebraically closed. A field where every non-constant polynomial has a root is algebraically closed. is not (), is. Every proof of the theorem uses some analysis or topology (the completeness of the reals), which is why the “fundamental theorem of algebra” has no purely algebraic proof. Numerically, roots are found by iteration, for example by finding the eigenvalues of a companion matrix.
Algebra214 / 260
Module 17 · Complex numbers
Practice problems
ProblemInteractive · disabled in the PDF
Let and . Find , and the modulus of .
ProblemInteractive · disabled in the PDF
Solve . Give the real part of the roots, the positive imaginary part, and the product of the two roots.
ProblemInteractive · disabled in the PDF
Use polar form to find , and the imaginary part of .
Algebra215 / 260
Module 17 · Complex numbers
More practice problems
ProblemInteractive · disabled in the PDF
Find the three cube roots of : give the real one, and the one in the first quadrant as .
ProblemInteractive · disabled in the PDF
In a game, a sprite at the point is turned anticlockwise about the origin. Use complex multiplication to find where it lands.
Algebra216 / 260
Module 17 · Complex numbers
Recap
; a complex number is , a point in the complex plane.
Add part by part; multiply by expanding and replacing by .
The conjugate gives ; divide by multiplying top and bottom by the conjugate.
Modulus ; argument from atan2, checking the quadrant.
Polar form : multiplying multiplies moduli and adds angles, so it scales and rotates.
has roots evenly spaced on the unit circle; every degree- polynomial has complex roots.
FlashcardsInteractive · disabled in the PDF
What is ?
, because powers of cycle with period 4.
What is for ?
, a real number.
Euler’s formula
.
What does multiplying by do to the plane?
Scales it by and rotates it by .
De Moivre’s theorem
.
Fundamental theorem of algebra
A degree- polynomial has exactly complex roots, counted with multiplicity.
Module 18: Vectors and matrices
Algebra217 / 260
Module 18 · Vectors and matrices
A vector is a size and a direction
Some quantities are one number: a temperature, a mass. Others need a direction too: “walk 3 km north-east”, a wind, a force. A vector is such a quantity, drawn as an arrow. In the plane it is two numbers, its components: how far it goes across and how far up. means 3 right and 2 up, wherever the arrow starts.
Drag the components. The arrow from the origin ends at the point ; the dashed copy is the same vector, starting elsewhere.
Vectors can have any number of components: is an arrow in space, and a list of 100 prices is a vector in 100 dimensions. Everything on these slides works in any number of dimensions; the plane is just where you can see it. Vectors are often written as columns, , which will matter for matrices.
Vector
A quantity with a size and a direction; a list of numbers.
Component
One of its numbers: , , …
Scalar
An ordinary number, as opposed to a vector.
Zero vector
: no length, no direction.
Algebra218 / 260
Module 18 · Vectors and matrices
Adding vectors goes tip to tail
To add two vectors, add their components: . In a picture, walk along , then along : where you end is . Scalar multiplication multiplies every component: is stretched times, and turned round if is negative.
Drag both vectors. The sum is the diagonal of the parallelogram they make, whichever you walk first.
QuizInteractive · disabled in the PDF
What is ?
What is ?
Algebra219 / 260
Module 18 · Vectors and matrices
The length of a vector comes from Pythagoras
The components of are the two short sides of a right triangle, and the arrow is the long side. So its length, its norm , is the square root of the sum of the squares of the components. In more dimensions, add more squares.
Dividing by the length gives the unit vector : the same direction, length 1.
Fill the blanksInteractive · disabled in the PDF
Finish unit(v), which returns the vector in the same direction with length 1, for any number of components.
C++
1std::vector<double>unit(const std::vector<double>& v){2double sum =0;3for(double x : v) sum += x *;4double len = std::(sum);5 std::vector<double> u;6for(double x : v) u.push_back(x len);7return u;8}
Algebra220 / 260
Module 18 · Vectors and matrices
The dot product measures how much two vectors agree
The dot product multiplies matching components and adds: . The answer is a scalar. It also equals the two lengths times the cosine of the angle between the vectors, which turns it into a way to measure angles. It is positive when they point roughly the same way, 0 when they are perpendicular (at right angles), and negative when they point apart.
u · v2.72
Angle (degrees)63
Drag the directions. The dot product is 0 exactly when the angle is 90°.
QuizInteractive · disabled in the PDF
Which vector is perpendicular to ?
Which vector is perpendicular to ?
ProblemInteractive · disabled in the PDF
Find the dot product of and , and the angle between them in degrees.
°
Algebra221 / 260
Module 18 · Vectors and matrices
Try it: the angle between two vectors
Turn the formula around: , then take the inverse cosine. This is how search engines and recommendation systems compare documents: as vectors of word counts, close when the angle is small.
Code challengeInteractive · disabled in the PDF
Finish dot(u, v) and angleBetween(u, v), which returns the angle between two non-zero vectors in degrees. They work for any number of components. (using Vec = std::vector<double>; gives the type a short name.)
A matrix is a rectangle of numbers in rows and columns. An matrix (say “m by n”) has rows and columns, rows first. The entry in row and column is . Matrices of the same size add entry by entry, and a scalar multiplies every entry, just as with vectors.
A vector is a matrix with one column: as a column is . In code, a matrix is a vector of rows, std::vector<std::vector<double>>, which the code here names Matrix with using Matrix = std::vector<std::vector<double>>;. a[0][1] is row 1, column 2, because positions count from 0.
QuizInteractive · disabled in the PDF
In above, what is ?
In above, what is ?
Algebra223 / 260
Module 18 · Vectors and matrices
Matrix multiplication is rows times columns
The entry in row , column of is the dot product of row of with column of . So the rows of must be as long as the columns of : an matrix times an matrix is . The inner sizes must match and the outer ones are the result.
swaps the columns of ; swaps its rows. Order matters: in general .
QuizInteractive · disabled in the PDF
is and is . Which is true?
is and is . Which is true?
Code challengeInteractive · disabled in the PDF
Finish matMul(a, b): the product of an and an matrix, as a vector of rows. Entry [i][j] is row i of a dotted with column j of b.
C++
1#include<vector>23usingMatrix= std::vector<std::vector<double>>;45MatrixmatMul(constMatrix& a,constMatrix& b){6Matrix result;7 // TODO: one row of the result for each row of a8return result;9}
Find the bugInteractive · disabled in the PDF
matVec(a, v) should multiply a matrix by a column vector, but gives wrong answers for a matrix. Which line is wrong?
C++
ProblemInteractive · disabled in the PDF
Multiply by . Give each entry of .
Algebra224 / 260
Module 18 · Vectors and matrices
The identity matrix and the transpose
The identity matrix has 1s on its diagonal and 0s elsewhere. It is the 1 of matrices: for any square of its size. The transpose turns rows into columns: , so an matrix becomes . A matrix equal to its transpose is symmetric.
The rule reverses the order, like taking off socks and shoes. The dot product is a matrix product too: , a row times an column, which is .
QuizInteractive · disabled in the PDF
is . What size is , and is it symmetric?
is . What size is , and is it symmetric?
Algebra225 / 260
Module 18 · Vectors and matrices
A matrix moves every point of the plane
Multiplying by a matrix sends each vector to another one, so a matrix is a transformation of the plane. Where it sends the two unit vectors and tells you everything: is the first column of , the second, and every other vector goes to times the first column plus times the second.
Unit circle
Its image
The matrix is (a b; c d). Its columns are where the axes’ unit arrows land, and the dashed circle becomes the solid ellipse.
Matrix
What it does
Scales everything by
Rotates by anticlockwise
Reflects in the x axis
Shears: slides each row sideways by times its height
QuizInteractive · disabled in the PDF
What does do to the plane?
What does do to the plane?
Going deeper
Doing and then to a vector is : one matrix for both moves, read right to left. This is why matrix multiplication is defined the odd way it is, and why it isn’t commutative: rotating then shearing is not shearing then rotating. Graphics cards multiply millions of vectors by such matrices every frame. How much a transformation stretches areas, and which directions it leaves pointing the same way, come in the next module.
Algebra226 / 260
Module 18 · Vectors and matrices
A system of equations is one matrix equation
A system of linear equations is a matrix times a vector of unknowns equal to a vector of constants: . The coefficient matrix holds the numbers in front of the unknowns, one row per equation. Writing beside it gives the augmented matrix, the compact form you calculate with.
2x + y = 5
x − y = 1
Each equation is a line; the solution is where they cross.
QuizInteractive · disabled in the PDF
Read by columns. With , , which is true?
Read by columns. With , , which is true?
Algebra227 / 260
Module 18 · Vectors and matrices
Gaussian elimination solves any system step by step
Gaussian elimination uses three row operations, none of which changes the solutions: swap two rows, multiply a row by a non-zero number, and add a multiple of one row to another. Use them to make zeros below the diagonal, column by column (forward elimination), until the matrix is a triangle. Then solve the last equation and substitute upwards (back substitution).
Check in the original second equation: .
Put in orderInteractive · disabled in the PDF
Put the steps of Gaussian elimination in order.
1.Repeat for each next column until the matrix is triangular
2.Solve the last row, then substitute upwards
3.Subtract multiples of the pivot row to make zeros below the pivot
4.Pick a non-zero pivot in the first column, swapping rows if needed
5.Write the system as an augmented matrix
Going deeper
Partial pivoting. On a computer, a tiny pivot such as is as bad as 0: dividing by it multiplies rounding errors enormously. Partial pivoting swaps in the row with the largest pivot (in absolute value) at each column, which keeps the multipliers at most 1. Elimination on an system takes about operations, so doubling makes it eight times slower.
Algebra228 / 260
Module 18 · Vectors and matrices
Try it: solve a system by elimination
Code challengeInteractive · disabled in the PDF
Finish solve(a, b), which solves for a square system with one solution. Forward elimination is written, with pivoting; write the back substitution: for each row from the last up, , where m[i][n] is the right-hand side.
C++
1#include<cmath>2#include<utility>3#include<vector>45usingVec= std::vector<double>;6usingMatrix= std::vector<Vec>;78Vecsolve(constMatrix& a,constVec& b){9int n = b.size();10Matrix m = a; // a copy, with b as an extra column11for(int i =0; i < n; i++) m[i].push_back(b[i]);12for(int col =0; col < n; col++){13int p = col;14for(int r = col +1; r < n; r++)15if(std::abs(m[r][col])> std::abs(m[p][col])) p = r;16 std::swap(m[col], m[p]);17for(int r = col +1; r < n; r++){18double f = m[r][col]/ m[col][col];19for(int c = col; c <= n; c++) m[r][c]-= f * m[col][c];20}21}22Vecx(n,0.0); // n zeros23 // TODO: back substitution, from the last row up24return x;25}
Algebra229 / 260
Module 18 · Vectors and matrices
Practice problems
ProblemInteractive · disabled in the PDF
Find the length of , and the vector of length 5 that points the same way.
ProblemInteractive · disabled in the PDF
For which is perpendicular to ? And for which is it parallel to ?
ProblemInteractive · disabled in the PDF
Solve by Gaussian elimination: , and .
Algebra230 / 260
Module 18 · Vectors and matrices
More practice problems
ProblemInteractive · disabled in the PDF
The point is turned anticlockwise about the origin, then reflected in the axis. Where does it end up? And where would it end up with the two moves done the other way round?
ProblemInteractive · disabled in the PDF
A café sells coffee at 3 euros, tea at 2 euros and cake at 4 euros. On Monday it sells 20 coffees, 15 teas and 10 cakes; on Tuesday 25, 10 and 12. Put the sales in a matrix , one row per day, and the prices in a vector . What is ?
euros
euros
Algebra231 / 260
Module 18 · Vectors and matrices
Recap
A vector is a list of components; add and scale component by component.
Length ; divide by it for a unit vector.
; 0 means perpendicular.
: entry is row dotted with column , and in general.
A matrix’s columns are where it sends the unit vectors; it transforms the whole plane.
is solved by elimination to a triangle, then back substitution.
FlashcardsInteractive · disabled in the PDF
What is for perpendicular vectors?
0, since .
Size of ?
: the outer sizes.
: the order reverses.
Where is ?
The first column of .
The three row operations
Swap two rows, scale a row by a non-zero number, add a multiple of one row to another.
What is a pivot?
The non-zero entry used to clear the entries below it in its column.
Module 19: Linear maps, determinants and eigenvectors
Algebra232 / 260
Module 19 · Linear maps, determinants and eigenvectors
Mixing vectors: combinations and span
In the last module you added vectors and scaled them. Do both at once and you get a linear combination: , for any numbers and . The span of some vectors is every point you can reach this way. Two arrows that point in different directions span the whole plane: any point is some amount of one plus some amount of the other.
A linear combination of and .
x0
y3
Drag a and b: the tip of the sum can reach any point of the plane.
QuizInteractive · disabled in the PDF
What is the span of the single vector in the plane?
What is the span of the single vector in the plane?
Algebra233 / 260
Module 19 · Linear maps, determinants and eigenvectors
Independent vectors add something new
Vectors are linearly independent when none of them is a combination of the others. Put another way: the only way to mix them into the zero vector is to take none of each.
If some mix with a nonzero amount gives , they are dependent: one of them is redundant, because it can be written with the others. and are dependent, since . They lie on one line and span only that line.
QuizInteractive · disabled in the PDF
Which set of vectors is linearly dependent?
Which set of vectors is linearly dependent?
Going deeper
To test vectors in , put them as the columns of a square matrix and row-reduce it: they are independent exactly when every column gets a pivot, which is when the determinant (two slides on) is not zero.
Algebra234 / 260
Module 19 · Linear maps, determinants and eigenvectors
A basis is a coordinate system
A basis of a space is a set of vectors that is independent and spans it. Then every vector is a combination of the basis in exactly one way, and the amounts are its coordinates in that basis. The usual basis of the plane is , , which is why means "5 of and 1 of ". Any other basis works too.
In the basis , , the point has coordinates .
Every basis of a space has the same number of vectors. That number is the dimension: 2 for the plane, 3 for space, for .
QuizInteractive · disabled in the PDF
What are the coordinates of in the basis , ?
What are the coordinates of in the basis , ?
Algebra235 / 260
Module 19 · Linear maps, determinants and eigenvectors
A linear map keeps lines straight and the origin still
A linear map sends vectors to vectors and respects both operations: the image of a sum is the sum of the images, and the image of a scaled vector is the scaled image.
That has a big consequence. Since , linearity gives . So is known everywhere once you know where it sends the basis, and the matrix of is just those images written as columns. Every linear map of the plane is a matrix, and every matrix is a linear map.
QuizInteractive · disabled in the PDF
Which of these maps of the plane is linear?
Which of these maps of the plane is linear?
Fill the blanksInteractive · disabled in the PDF
A linear map sends to and to . Fill in where it sends any .
C++
1// T(x, y) = x * T(e1) + y * T(e2)2std::pair<double,double>T(double x,double y){3return{* x +* y,* x +* y};4}
Algebra236 / 260
Module 19 · Linear maps, determinants and eigenvectors
The determinant is how much area scales
A linear map sends the unit square (sides and ) to a parallelogram with sides the two columns. The determinant is the area of that parallelogram, with a sign: positive if the map keeps the orientation, negative if it flips the plane over like a mirror. Every shape's area is multiplied by the same factor.
det = ad − bc2.5
The columns and are the sides. Make them point the same way and the area, the determinant, goes to 0.
A determinant of 0 means the plane is squashed onto a line or a point: the columns are dependent, and information is lost. Determinants multiply: , because doing one map after another multiplies the area factors.
ProblemInteractive · disabled in the PDF
A linear map has matrix . By what factor does it scale areas, and what area does a shape of area have after it? What is the area of the triangle with corners , and ?
Going deeper
For a matrix the determinant is the signed volume of the box the columns span. Expanding along the first row: . Each bracket is the determinant of what is left after crossing out that entry's row and column, and the signs alternate. This is work in general; computers use elimination instead, multiplying the pivots, which is .
Algebra237 / 260
Module 19 · Linear maps, determinants and eigenvectors
Try it: a three by three determinant
Expand along the first row, as in Go deeper on the last slide: each entry of the first row times the determinant left when you cross out its row and column, with signs .
Code challengeInteractive · disabled in the PDF
Finish det3(m): the determinant of a 3×3 matrix given as a vector of rows, m[row][column].
C++
1#include<vector>23usingMatrix= std::vector<std::vector<double>>;45doubledet3(constMatrix& m){6 // TODO: expand along the first row7return0;8}
Algebra238 / 260
Module 19 · Linear maps, determinants and eigenvectors
An inverse undoes the map
The inverse is the matrix that undoes : . It exists exactly when : a map that squashes the plane flat sends many points to one, and nothing can tell them apart again. For there is a formula: swap the diagonal, negate the other two, divide by the determinant.
Check one entry of : .
With an inverse, has exactly one solution, . Note that : to undo "put on socks, then shoes", you take off the shoes first.
Find the bugInteractive · disabled in the PDF
This inverse gives a matrix that does not undo . Which line is wrong?
C++
Algebra239 / 260
Module 19 · Linear maps, determinants and eigenvectors
Eigenvectors keep their direction
Most vectors are turned by a matrix. An eigenvector is one that is only stretched: for some number , its eigenvalue. ("Eigen" is German for "own".) Below, has rows and . Turn round the circle and watch .
Turn (v × Av)0.83
Stretch along v2.56
At θ ≈ 0.79 (45°) the image lies along v, three times as long; at θ ≈ 2.36 (135°) it lies along v, unchanged. The turn readout is 0 there.
QuizInteractive · disabled in the PDF
For with rows and , is an eigenvector, and with which eigenvalue?
For with rows and , is an eigenvector, and with which eigenvalue?
Algebra240 / 260
Module 19 · Linear maps, determinants and eigenvectors
Finding eigenvalues with a determinant
Rewrite as . A nonzero is squashed to zero, so must squash the plane: its determinant is 0. That equation in is the characteristic polynomial, and its roots are the eigenvalues. For each one, solve for the eigenvectors.
Two quick checks. The eigenvalues add up to the trace (the sum of the diagonal, here ) and multiply to the determinant (). A rotation by 90° has characteristic polynomial , with roots : no real eigenvectors, which fits, since it turns every direction.
QuizInteractive · disabled in the PDF
What are the eigenvalues of the matrix with rows and ?
What are the eigenvalues of the matrix with rows and ?
ProblemInteractive · disabled in the PDF
Find the eigenvalues of , and an eigenvector for each, written as .
Algebra241 / 260
Module 19 · Linear maps, determinants and eigenvectors
Diagonalising: the matrix in its own basis
If an matrix has independent eigenvectors, use them as a basis. In that basis the map just stretches each axis by its eigenvalue: its matrix is diagonal. With the eigenvectors as columns and the eigenvalues on the diagonal, . Powers become easy, because the in the middle cancel.
For this gives rows and , which is multiplied out by hand.
Put in orderInteractive · disabled in the PDF
Put the steps of diagonalising a matrix in order.
1.Find its roots, the eigenvalues
2.Check , then write
3.Write the characteristic polynomial
4.Put the eigenvectors as the columns of and the eigenvalues on the diagonal of
5.For each eigenvalue, solve for an eigenvector
Going deeper
Not every matrix diagonalises. The shear with rows and has the eigenvalue 1 twice but only one direction of eigenvectors, ; the best you can do is the Jordan form. Symmetric matrices always diagonalise, with real eigenvalues and eigenvectors at right angles (the spectral theorem), which is why they are everywhere in physics and statistics.
Algebra242 / 260
Module 19 · Linear maps, determinants and eigenvectors
Markov chains settle on an eigenvector
Say a sunny day is followed by sun 90% of the time and rain 10%, and a rainy day by sun or rain half the time each. Write today's chances as a vector ; tomorrow's is , where each column of holds the chances from one kind of day and adds up to 1. This is a Markov chain.
The long-run weather is the eigenvector with eigenvalue 1, scaled so it adds to 1.
Chance of sun
Steady state, 5/6
Day 30.78
The chance of sun on day n, from any start. The gap to 5/6 shrinks by 0.4 a day: 0.4 is the other eigenvalue of M.The steady state: in the long run, 5 days in 6 are sunny.
Going deeper
PageRank, the idea behind early web search, is the same thing on a huge scale: a surfer clicks a random link on each page (and now and then jumps to a random page). The long-run share of time spent on each page is the eigenvector with eigenvalue 1 of the link matrix, found by multiplying a starting vector by the matrix again and again, the power method. It converges at the speed of the second-largest eigenvalue, as the curve above does.
Algebra243 / 260
Module 19 · Linear maps, determinants and eigenvectors
Try it: run a Markov chain
Multiply by the matrix again and again: that is the power method, and it finds the steady state without solving any equation.
Code challengeInteractive · disabled in the PDF
Finish runChain(m, x, steps): apply the matrix m (a vector of rows) to the vector x, steps times, and return the result. One step is y[i] = Σ m[i][j] * x[j].
C++
1#include<vector>23usingVec= std::vector<double>;4usingMatrix= std::vector<Vec>;56VecrunChain(constMatrix& m,Vec x,int steps){7 // TODO: multiply x by m, steps times8return x;9}
Algebra244 / 260
Module 19 · Linear maps, determinants and eigenvectors
Practice problems
ProblemInteractive · disabled in the PDF
Find the inverse of , and use it to solve , .
ProblemInteractive · disabled in the PDF
For which does have no inverse? And what is the determinant of ?
ProblemInteractive · disabled in the PDF
What are the coordinates of the point in the basis , ?
Algebra245 / 260
Module 19 · Linear maps, determinants and eigenvectors
More practice problems
ProblemInteractive · disabled in the PDF
A car-hire firm has 700 cars and two offices, A and B. Each day, of the cars at A, 70% end up back at A and 30% at B; of the cars at B, 40% end up at A and 60% at B. If all 700 start at A, how many are at A after one day? In the long run, how many are at A, and what is the other eigenvalue of the matrix?
ProblemInteractive · disabled in the PDF
For , diagonalising gave . Use it to find the entries of , and the largest eigenvalue of .
Algebra246 / 260
Module 19 · Linear maps, determinants and eigenvectors
Recap
A linear combination mixes vectors with amounts; the span is every point such mixes reach.
Vectors are independent when none is a mix of the others; an independent spanning set is a basis, and its size is the dimension.
A linear map is fixed by where it sends the basis; those images are its matrix's columns.
The determinant is the signed factor by which areas (or volumes) scale; 0 means space is squashed and there is no inverse.
Eigenvectors satisfy ; the eigenvalues are the roots of .
With enough eigenvectors, and ; the long run of a Markov chain is its eigenvector for .
FlashcardsInteractive · disabled in the PDF
Span
Every linear combination of a set of vectors: all the points they can reach.
Linearly independent
The only mix of the vectors that gives takes zero of each.
Basis
An independent set that spans the space; every vector is one mix of it, in one way.
Determinant of a 2×2
: the signed area of the parallelogram of the columns.
When does exist?
Exactly when .
Eigenvector
A nonzero with : the map only stretches it, by its eigenvalue .
Trace and determinant
The sum and the product of the eigenvalues.
Module 20: Abstract algebra and thinking like a mathematician
Algebra247 / 260
Module 20 · Abstract algebra and thinking like a mathematician
A proof covers every case at once
Checking examples is how you guess a rule. A proof is how you know it: a chain of steps, each following from definitions or from things already proved, that works for every case, not just the ones you tried. The simplest kind is a direct proof: start from what you are given and walk to what you want.
Claim. The sum of two odd numbers is even. An odd number is one that can be written for some integer ; an even number is for some integer . Those definitions are the whole proof's raw material.
Since is an integer, is even. The proof ends here, for every pair of odd numbers.
QuizInteractive · disabled in the PDF
You check that is prime for . What have you shown about all whole numbers ?
You check that is prime for . What have you shown about all whole numbers ?
Algebra248 / 260
Module 20 · Abstract algebra and thinking like a mathematician
Proving the other way round, and by contradiction
"If then " is true exactly when its contrapositive, "if not then not ", is true. Sometimes that is far easier to prove. Careful: the converse, "if then ", is a different claim and may be false. A proof by contradiction assumes the claim is false and reasons until something impossible appears, so the assumption must have been wrong.
Fill the blanksInteractive · disabled in the PDF
Prove "if is even, then is even" through its contrapositive.
Text
1Claim: if n² is even, then n is even.2Contrapositive: if n is , then n² is .3Proof: n = 2k + 1, so n² = 4k² + 4k + 14 = 2() + 1,5which is odd.
Put in orderInteractive · disabled in the PDF
Put the classic proof that is irrational in order.
1.Both and even contradicts lowest terms, so is irrational
2.Then , so and is even too
3.Suppose , a fraction in lowest terms
4.Square both sides:
5.So is even, hence is even: write
Algebra249 / 260
Module 20 · Abstract algebra and thinking like a mathematician
Sets and maps: the words every structure uses
A set is a collection of things, its elements: says 3 is an integer. A map (function) sends each element of to one element of . Three properties matter again and again.
Injective (one to one)
Different inputs give different outputs: only when .
Surjective (onto)
Every element of is the output of some input.
Bijective
Both: the map pairs and up exactly, and so has an inverse .
Union and intersection
is what is in either set; is what is in both.
QuizInteractive · disabled in the PDF
Which describes as a map from to ?
Which describes as a map from to ?
Algebra250 / 260
Module 20 · Abstract algebra and thinking like a mathematician
Modular arithmetic: numbers on a clock
On a 12-hour clock, 9 o'clock plus 5 hours is 2 o'clock. That is arithmetic modulo 12: keep only the remainder after dividing by 12. Write (" is congruent to mod ") when divides . You can add, subtract and multiply first and reduce at the end, or reduce at every step: the answer is the same.
Powers of 3 mod 7 run through every nonzero remainder, then repeat every 6 steps.
QuizInteractive · disabled in the PDF
What is ? Try it without working out .
What is ? Try it without working out .
ProblemInteractive · disabled in the PDF
Find the last digit of , and .
Going deeper
Fermat's little theorem: if is prime and does not divide , then . Above, . Euler extended it to any : when and share no factor, where counts the numbers from 1 to that share no factor with . That theorem is why RSA decryption works.
Algebra251 / 260
Module 20 · Abstract algebra and thinking like a mathematician
Try it: fast powers modulo n
Square and multiply works out in about steps. Look at the exponent's bits from the lowest: keep a running result and a running square of the base. When the bit is 1, multiply the result by the square; then square the square and halve the exponent. Reduce mod after every multiplication, so the numbers stay small.
Code challengeInteractive · disabled in the PDF
Finish modPow(base, exp, mod): return base to the power exp, modulo mod, by square and multiply. exp is a whole number, mod is at least 2 and below 10 000 000.
C++
1longlongmodPow(longlong base,longlong exp,longlong mod){2 // TODO: square and multiply3return1;4}
Algebra252 / 260
Module 20 · Abstract algebra and thinking like a mathematician
A group: one operation, four rules
The integers under , the nonzero reals under , the clock numbers mod under , and the turns of a square all behave alike. Algebra names what they share. A group is a set with an operation such that:
Closure: is in whenever and are.
Associativity: .
Identity: there is an with for every .
Inverses: every has an with .
If also always, the group is abelian (commutative). A theorem proved from these four rules alone holds in every group at once. For example, the identity is unique: if and are both identities, .
QuizInteractive · disabled in the PDF
Which of these is a group?
Which of these is a group?
Algebra253 / 260
Module 20 · Abstract algebra and thinking like a mathematician
Symmetries form groups, and order matters
A symmetry of a shape is a move that lands it on itself. An equilateral triangle has six: three turns (0°, 120°, 240°) and three flips. Doing one after another is the operation, and it is a group, called . Turn the triangle below and watch the labels: at 120° it fits its outline again, with the corners moved round.
Turns, in thirds0
At θ = 2.09 (120°) and 4.19 (240°) the triangle lands on itself.
Label the corners 0, 1, 2 and each symmetry is a permutation, a reordering, written as a list (in code, a std::vector<int>): p[i] is where corner i goes. A turn is {1, 2, 0}; the flip that keeps corner 0 is {0, 2, 1}. Turn then flip is not flip then turn: is the smallest group that is not abelian.
Code challengeInteractive · disabled in the PDF
Finish compose(p, q): the permutation "first q, then p", so element i goes to p[q[i]].
C++
1#include<vector>23usingPerm= std::vector<int>; // p[i] is where i goes45Permcompose(constPerm& p,constPerm& q){6 // TODO: q first, then p7return p;8}
Algebra254 / 260
Module 20 · Abstract algebra and thinking like a mathematician
Rings and fields: two operations that get along
Numbers usually have two operations. A ring is a set with and where makes an abelian group, is associative with an identity 1, and multiplication distributes over addition: . A field is a commutative ring where every nonzero element also has a multiplicative inverse: you can divide by anything but 0.
Set
Ring?
Field?
Why not a field
Yes
No
2 has no inverse:
, ,
Yes
Yes
–
(mod 7)
Yes
Yes
–
(mod 6)
Yes
No
: 2 and 3 have no inverse
2×2 matrices
Yes
No
, and singular matrices have no inverse
is a field exactly when is prime. The inverse of mod comes from the extended Euclidean algorithm: it finds integers with . If the gcd is 1, then , so is the inverse; otherwise there is none.
Code challengeInteractive · disabled in the PDF
Finish modInverse(a, n): the number x from 0 to n - 1 with a * x % n == 1, or std::nullopt if there is none (a std::optional<int> holds an int or nothing). Use the extended Euclidean algorithm.
C++
1#include<optional>23std::optional<int>modInverse(int a,int n){4 // TODO: extended Euclid; keep track of the multiplier of a5return std::nullopt;6}
ProblemInteractive · disabled in the PDF
Find the inverse of 5 modulo 17, and use it to solve , with from 0 to 16.
Algebra255 / 260
Module 20 · Abstract algebra and thinking like a mathematician
Isomorphic structures are the same in disguise
Two groups are isomorphic when a bijection between them turns one operation into the other: . Then every fact about one is a fact about the other. The turns of a square (0°, 90°, 180°, 270°) and under are one group: send a turn of to . And the exponential turns adding into multiplying.
Its inverse is , which turns products into sums: the reason slide rules and log tables worked.
y = eˣ
eᵃ × eᵇ3.669
eᵃ⁺ᵇ3.669
Drag a and b: the height over a + b is always the product of the heights over a and b.
QuizInteractive · disabled in the PDF
Are and (pairs of bits, added mod 2 in each place) isomorphic? Both have 4 elements.
Are and (pairs of bits, added mod 2 in each place) isomorphic? Both have 4 elements.
Algebra256 / 260
Module 20 · Abstract algebra and thinking like a mathematician
Where algebra goes next
Galois theory links each polynomial to a group of symmetries of its roots. The quadratic formula has cousins for degrees 3 and 4, but Abel and Ruffini proved there is none for the general degree 5; Galois showed why: its group, of 120 permutations, cannot be broken down in the way radicals need.
Linear algebra in machine learning: a neural network layer is a matrix times a vector followed by a simple function; training adjusts the matrix entries. Principal component analysis finds the eigenvectors of a covariance matrix.
Cryptography: RSA works in modular arithmetic, and elliptic-curve cryptography uses a group made of points on a curve.
A toy RSA. Anyone may know and ; finding needs , which needs the factors of . Real keys use primes hundreds of digits long.
QuizInteractive · disabled in the PDF
With and public exponent , which is the private exponent?
With and public exponent , which is the private exponent?
Going deeper
Never roll your own. Toy RSA teaches the maths, not the engineering. Real systems need padding, constant-time arithmetic and vetted libraries; textbook RSA as above leaks information. Use a well-reviewed library and treat these examples as maths only.
Algebra257 / 260
Module 20 · Abstract algebra and thinking like a mathematician
Mixed problems from the whole course
These mix ideas from several modules. Work each on paper before you choose.
QuizInteractive · disabled in the PDF
What are the roots of ?
What are the roots of ?
QuizInteractive · disabled in the PDF
Solve .
Solve .
QuizInteractive · disabled in the PDF
What is ?
What is ?
QuizInteractive · disabled in the PDF
turns the plane by 90°. What is ?
turns the plane by 90°. What is ?
Algebra258 / 260
Module 20 · Abstract algebra and thinking like a mathematician
Practice problems
These problems each need ideas from several modules. Work them on paper, then type in the answers.
ProblemInteractive · disabled in the PDF
Find all the roots of : one is real and two are complex.
ProblemInteractive · disabled in the PDF
An angle has and . Expand with the binomial theorem, and use de Moivre’s theorem to read off and .
ProblemInteractive · disabled in the PDF
Where does the line meet the parabola ? Give both points, the left one first.
Algebra259 / 260
Module 20 · Abstract algebra and thinking like a mathematician
More practice problems
ProblemInteractive · disabled in the PDF
A loan of 10 000 euros charges 1% interest a month and is repaid by 24 equal monthly payments , the first one month after the loan. The payments, each grown with interest to the end, must add up to what the loan grows to: . Find , and the total interest paid.
euros
euros
ProblemInteractive · disabled in the PDF
The Fibonacci rule is the matrix step . Find the eigenvalues of that matrix, and compare the larger one with .
ProblemInteractive · disabled in the PDF
Let . Find its inverse , and .
Algebra260 / 260
Module 20 · Abstract algebra and thinking like a mathematician
Recap
Examples suggest; a proof decides. Direct, contrapositive and contradiction are the everyday kinds; one counterexample disproves.
A map can be injective, surjective or both (bijective), and only a bijection has an inverse.
when divides ; square and multiply gives fast powers mod .
A group has closure, associativity, an identity and inverses; symmetries and permutations are groups, often not commutative.
A ring adds a distributive ; a field lets you divide by anything but 0. is a field exactly when is prime.
An isomorphism shows two structures are the same in disguise, like turning sums into products.
FlashcardsInteractive · disabled in the PDF
Contrapositive of "if P then Q"
"If not Q then not P": true exactly when the original is.
Converse of "if P then Q"
"If Q then P": a different claim, which may be false.
The four group rules
Closure, associativity, an identity, an inverse for every element.
Abelian group
One where always.
Field
A commutative ring where every nonzero element has a multiplicative inverse.
When is a field?
Exactly when is prime.
Fermat's little theorem
For a prime not dividing : .
Isomorphism
A bijection that respects the operations: .
Answer key
1. Numbers and what they count · Ten digits write every natural number · QuizIn the number 52 816, what is the digit 2 worth?C. 2000Count places from the right: 6 is ones, 1 is tens, 8 is hundreds, 2 is thousands, 5 is ten-thousands. So the 2 is worth . The usual slip is counting from the left; places are always counted from the ones, at the right.
1. Numbers and what they count · Ten digits write every natural number · ProblemIn the number 47 305, what is the 7 worth, and what is the 3 worth? Then write as one number.The 7 is worth 7000; The 3 is worth 300; The number 50806
Counting from the right in 47 305: 5 is ones, 0 is tens, 3 is hundreds, 7 is thousands and 4 is ten-thousands.
So the 7 is worth , and the 3 is worth .
The sum has 5 ten-thousands, no thousands, 8 hundreds, no tens and 6 ones. Each empty place gets a 0:
The number is 50 806. Leaving out the zeros would give 586, a different number.
1. Numbers and what they count · Code in this course: your first C++ program · QuizWhat does this line print?A. 2 2.25 09 / 4 divides two ints, so the answer is the whole part, 2, with the quarter thrown away. 9.0 / 4 has a double in it, so the division keeps its fraction: 2.25. And 1 / 3 is 0, the most common surprise of all: a fraction of two whole numbers written as code must have a .0 somewhere, as in 1.0 / 3.
1. Numbers and what they count · Functions, decisions, loops and lists in C++ · Fill the blanksFinish the function that adds up the squares of a list, so that gives 14.1: double, 2: 0, 3: for, 4: x * x, 5: returnThe function returns a double, the same type as the numbers it adds. The total starts at 0, the sum of nothing, and the range-for adds each square in turn. Squaring is x * x (or std::pow(x, 2) from <cmath>); x ^ 2 would compile and give nonsense. Without return, the caller would never get the total.
1. Numbers and what they count · Try it: split a number into its places · Code challengeWrite placeValues(n): for a natural number n, return what each digit is worth, biggest place first. placeValues(3407) is {3000, 400, 0, 7}, and placeValues(0) is {0}. parts.insert(parts.begin(), x) puts x at the front of a vector.One solution:
Solution
1#include<vector>23std::vector<int>placeValues(int n){4if(n ==0)return{0};5 std::vector<int> parts;6int place =1;7while(n >0){8 parts.insert(parts.begin(),(n %10)* place);9 n = n /10;10 place *=10;11}12return parts;13}
The loop works from the right, because the remainder by 10 always gives the ones digit; inserting at parts.begin() puts each new part at the front, so the biggest place ends up first. n / 10 needs no rounding down: on ints it already drops the fraction. place grows by ten each time, matching each step left. Zero needs its own case: the loop never runs for it, and an empty list is not how you write 0. The last test is the point of place value: the parts always add back to the number.
1. Numbers and what they count · Negative numbers fill the gap below zero · QuizAt 6 in the morning it was degrees. By noon it was 7 degrees warmer. What was the temperature at noon?B. degreesStart at on the number line and move 7 steps right: . So . The tempting adds the 3 and the 7 as if both were positive, ignoring that the start was below zero; goes the wrong way.
1. Numbers and what they count · Further right is bigger · Put in orderPut these numbers in order, smallest first.1. 2. 3. 4. 5. 6. Picture them on the number line, left to right. Among negatives, the one with the bigger size is further left, so comes before , which comes before . Then . is , so it sits between 1 and 2, before .
1. Numbers and what they count · Absolute value is distance from zero · Code challengeWrite distance(a, b): how far apart a and b are on the number line. It must never be negative. std::abs(x), from <cmath>, gives the absolute value of x.One solution:
b - a is right only when b is the bigger one; swap them and it goes negative. The absolute value removes the direction, so std::abs(a - b) and std::abs(b - a) are the same distance. Notice the test across zero: to is 7, not 1. Subtracting a negative adds its size. (The tests use EXPECT_NEAR with a tiny tolerance, 1e-9, the habit for any double a program computes.)
1. Numbers and what they count · Absolute value is distance from zero · ProblemWork out and . Then find the distance between and on the number line. 14; 9; The distance 13
is 14 steps from zero, so .
Inside the bars first: , so .
The distance between and :
Check by counting: from up to is 8 steps, and from up to is 5 more, .
1. Numbers and what they count · Fractions fill the gaps between integers · QuizWhich number lies between and ?B. Their average is . As decimals: . No two different fractions are “next to each other”: you can always average again. is smaller than both, and bigger than both.
1. Numbers and what they count · Some lengths are not fractions · QuizWhich of these are irrational? Choose all that are.B. ; D. , an integer. : repeating decimals are rational. is a fraction by definition; it is close to but not equal (, ). is irrational by the same argument as , and is irrational too, though that proof is much harder (Lambert, 1761).
1. Numbers and what they count · The real numbers fill the whole line · QuizWhat is the smallest of the sets that contains ?B. Simplify first: , an integer. It is not natural, because it is negative. It is also in and , since the sets nest, but is the smallest. Judging by looks alone (“it has a fraction bar, so it is in ”) is the common slip.
1. Numbers and what they count · Practice problems · ProblemAt 6 in the morning it was degrees. By 2 in the afternoon it had risen 13 degrees, and by midnight it had fallen 7 degrees from there. What was the temperature at 2 in the afternoon, and at midnight? How many degrees apart were the coldest and the warmest of these three readings?At 2 in the afternoon 4 degrees; At midnight -3 degrees; Coldest to warmest 13 degrees
Start at and move 13 steps right: degrees.
From 4, move 7 steps left: degrees.
The readings were , and . The coldest is and the warmest is :
1. Numbers and what they count · Practice problems · ProblemFind the number exactly halfway between and on the number line. How far is it from each of them?Halfway 1.25; Distance to each 4.75
The number halfway is the average:
Its distance to each end:
Check: the whole gap is , and half of it is .
1. Numbers and what they count · Practice problems · ProblemHow many integers lie between and on the number line? How many of those are natural numbers?Integers 8; Natural numbers 4
The first integer to the right of is ; the last one to the left of is . Between them:
That is 8 integers.
The natural numbers are the ones that are not negative, : 4 of them. (A book that starts at 1 would say 3.)
1. Numbers and what they count · Practice problems · ProblemA building’s floors are numbered from (the lowest car park) up to . A lift starts on floor , goes up to floor , and then down to floor . How many floors does it travel on each trip, and in all?Going up 12 floors; Going down 10 floors; In all 22 floors
Going up, from to :
Going down, from to :
In all, floors. From straight to is only 2 floors: that is how far it ended up from where it began, not how far it went.
2. Arithmetic, properly · An agreed order makes a sum mean one thing · QuizWhat is ?A. Multiply first: . Then add and subtract left to right: , then . comes from doing first. comes from adding before subtracting, which breaks the left-to-right rule.
2. Arithmetic, properly · An agreed order makes a sum mean one thing · ProblemWork out and .The first 14; The second 12
The first has no brackets or powers. Multiply and divide, left to right: , and . Then add and subtract, left to right:
The second: brackets first, and . Then the power, . Then multiply and divide, and subtract last:
2. Arithmetic, properly · Programming languages use the same order · QuizWhat does this print?A. 8, then 1412 / 3 * 2 goes left to right: 4 * 2 is 8. 2 + 3 * 4 multiplies first: 2 + 12 is 14. The computer applies the same agreed order you do, which is the point of having one.
2. Arithmetic, properly · Programming languages use the same order · Put in orderPut the steps for working out in order.1. Brackets: 2. Power: 3. Multiply and divide, left to right: , 4. Subtract: Brackets, then powers, then the multiply-and-divide level, then the add-and-subtract level. The answer is 97. Squaring before adding, , would give a different number entirely: the brackets say the sum is squared.
2. Arithmetic, properly · Order and grouping do not matter for adding and multiplying · QuizFor which of these is true for all numbers, where is the operation?C. Taking the larger, The larger of two numbers is the same whichever you name first, so is commutative. One counterexample is enough to break a law: but ; but ; but .
2. Arithmetic, properly · Multiplying spreads over a sum · Fill the blanksFill the blanks so each comparison is true. Each uses the distributive law.1: 3, 2: 1, 3: 20, so . , so . The last runs the law backwards, which is called factoring: both terms have a 4, so .
2. Arithmetic, properly · Zero and one change nothing · QuizWhich number has no reciprocal?A. A reciprocal of 0 would be a number with , but 0 times anything is 0. So none exists, and this is exactly why you cannot divide by zero. and are their own reciprocals; the reciprocal of is .
2. Arithmetic, properly · Primes are the numbers with no smaller factors · QuizWhich of these are prime? Choose all that are.B. ; E. 1 has one factor, so it is not prime by definition. 2 is prime, the only even one. (its digits add to 6, divisible by 3). , the classic trap: it passes the easy tests. 97 is prime: no prime up to , that is 2, 3, 5 or 7, divides it.
2. Arithmetic, properly · Every number is a product of primes in one way · Code challengeWrite primeFactors(n) for a natural number n ≥ 1: its prime factors, smallest first, each repeated as often as it divides. primeFactors(360) is {2, 2, 2, 3, 3, 5}; primeFactors(1) is empty, {}.One solution:
Solution
1#include<vector>23std::vector<int>primeFactors(int n){4 std::vector<int> factors;5for(int p =2; p * p <= n; p++){6while(n % p ==0){7 factors.push_back(p);8 n = n / p;9}10}11if(n >1) factors.push_back(n);12return factors;13}
Dividing out each factor completely, with while, is what makes the list only primes: by the time p reaches 4, every 2 is gone, so 4 can never divide what is left. Stopping when p * p > n uses the square-root rule from the last slide; whatever is left above 1 then is a prime itself, which is why the line after the loop is needed (it is how 13 and the 97 in get in).
2. Arithmetic, properly · The gcd and the lcm · QuizOne bus leaves the station every 12 minutes and another every 20 minutes. They both leave at 9:00. When do they next leave together?C. 10:00They leave together at the common multiples of 12 and 20, and the next is the least: , , so minutes, at 10:00. 4 is the gcd, which answers a different question (the biggest step that fits both). minutes is a common multiple, but not the least.
2. Arithmetic, properly · The gcd and the lcm · ProblemFactorise 84 and 120 into primes. Then find and . 12; 840
The primes they share are 2 and 3. At the lower powers: .
Every prime, at the higher power: .
Check: .
2. Arithmetic, properly · Euclid’s algorithm finds the gcd fast · Code challengeWrite gcd(a, b) with Euclid’s algorithm, for natural numbers not both zero, and lcm(a, b) for positive ones, using gcd. a % b is the remainder of a divided by b.One solution:
Solution
1intgcd(int a,int b){2while(b !=0){3int r = a % b;4 a = b;5 b = r;6}7return a;8}910intlcm(int a,int b){11return(a /gcd(a, b))* b;12}
Save the remainder before overwriting: a = b first would lose a. If a < b, the first pass just swaps them, since 105 % 252 is 105, which is why the order does not matter. For the lcm, is right, and the integer division is exact, because the gcd divides . Dividing before multiplying keeps the numbers smaller, which matters when a * b would pass an int’s limit, about 2.1 billion. The usual mistake is lcm = a * b, which is a common multiple but only the least when the gcd is 1. (C++ has both ready-made, std::gcd and std::lcm in <numeric>; this is how they work.)
2. Arithmetic, properly · Estimate before you calculate · QuizWithout calculating exactly, which is closest to ?B. and , so the answer is about (exactly ). Counting zeros is where estimates go wrong: , then add the two zeros from 400 and the one from 50.
2. Arithmetic, properly · Practice problems · ProblemWrite 1176 as a product of primes, in the form . What are , and ? 3; 1; 2
Halve while you can: .
147 is odd. Its digits add up to 12, so 3 divides it: , and .
So , and . Check: .
2. Arithmetic, properly · Practice problems · ProblemUse Euclid’s algorithm to find . Then use the gcd to find . 21; 23562
The remainder is 0, so the last non-zero remainder, 21, is the gcd.
Then, dividing before multiplying to keep the numbers small:
2. Arithmetic, properly · Practice problems · ProblemA floor 360 cm long and 264 cm wide is to be covered with square tiles, all the same size, with no gaps and no cutting. What is the largest tile side that works, and how many tiles of that size are needed?Side 24 cm; Tiles 165
The side must divide 360 and 264, and be as big as possible: it is their gcd.
Tiles of 24 cm fit along the length and across the width.
So tiles are needed.
2. Arithmetic, properly · Practice problems · ProblemThree lighthouses flash every 12, 18 and 30 seconds. They all flash together at midnight. How many seconds later do they next all flash together? How many times do they all flash together after midnight, up to and including 1 o’clock?Next together after 180 s; Times up to 1 o’clock 20
The next time they meet is the least common multiple of all three:
Every prime at its highest power: seconds, 3 minutes.
They flash together every 180 seconds: at 180, 360, …, 3600. That is times.
3. Fractions, decimals, percentages and ratios · Many fractions name the same number · QuizWhat is in lowest terms?C. and , so the gcd is , and . and are equivalent but not in lowest terms: they still share a 7 and a 2. Dividing by the gcd in one step saves the guessing.
3. Fractions, decimals, percentages and ratios · Add fractions over a common denominator · QuizWhat is ?C. The common denominator is 12: and , so the difference is . Subtracting tops and bottoms separately, , is the classic mistake: it gives , a negative number from taking a quarter away from two thirds.
3. Fractions, decimals, percentages and ratios · Add fractions over a common denominator · ProblemWork out and . Give each in lowest terms.29/24 ≈ 1.20833; 17/30 ≈ 0.566667
, so rewrite both as twenty-fourths:
29 is prime and does not divide 24, so this is in lowest terms. (It is .)
:
3. Fractions, decimals, percentages and ratios · Multiplying is easier than adding · QuizA ribbon is m long. How many pieces m long can you cut from it?B. “How many fit” is division: . multiplies instead of dividing, which would be the length of one twelfth of the ribbon. Dividing by a number less than 1 makes the answer bigger, which is a good check.
3. Fractions, decimals, percentages and ratios · Try it: add two fractions exactly · Code challengeFinish addFractions(a, b, c, d): return as a pair {top, bottom} in lowest terms, with a positive bottom. b and d are positive. A std::pair<int, int> holds two ints: {5, 12} makes one.One solution:
Solution
1#include<cmath>2#include<utility>34intgcd(int a,int b){5while(b !=0){6int r = a % b;7 a = b;8 b = r;9}10return std::abs(a);11}1213std::pair<int,int>addFractions(int a,int b,int c,int d){14int top = a * d + c * b;15int bottom = b * d;16int g =gcd(top, bottom);17return{top / g, bottom / g};18}
Over the common denominator , the tops become and . Dividing by the gcd then gives lowest terms: , and makes it . The gcd of 0 and the bottom is the bottom itself, which is how a sum of 0 comes out as . Integer division is exactly right here: the gcd divides both, so nothing is thrown away. Adding tops and bottoms, the starter’s way, gives for a quarter plus a sixth, smaller than a quarter alone.
3. Fractions, decimals, percentages and ratios · Decimals are fractions over powers of ten · QuizWhich of these have a decimal that stops? Choose all that do.A. ; C. and , so and stop. and both contain a 3: and repeat for ever. Check lowest terms first: stops, since it is .
3. Fractions, decimals, percentages and ratios · Recurring decimals turn back into fractions · QuizWhat fraction is ?B. , so , and , so and . and are the same number, exactly, which stops. is , a two-digit block.
3. Fractions, decimals, percentages and ratios · A percentage is a fraction out of one hundred · ProblemA jacket costs 80 euros. Its price goes up by 15%, and then the new price is cut by 20% in a sale. What is the sale price? What is the overall percentage change from 80 euros (negative for a fall)?Sale price 73.6 euros; Overall change -8 %
Each change multiplies:
The sale price is 73.60 euros. Overall:
Or straight from the multipliers: , which is 8% less than 1. Adding the percentages, , is the trap: the 20% is of a bigger price.
3. Fractions, decimals, percentages and ratios · Try it: percentage change · Code challengeWrite percentChange(before, after), the change as a percentage of before, and afterChanges(value, percents), which applies each percentage change in turn. afterChanges(100, {10, -10}) is about 99.One solution:
Solution
1#include<vector>23doublepercentChange(double before,double after){4return(after - before)/ before *100;5}67doubleafterChanges(double value,8const std::vector<double>& percents){9for(double p : percents) value = value *(1+ p /100);10return value;11}
Divide the change by the old value: from 80 to 60 is , but from 60 back to 80 is , because the base differs. Each change multiplies, so chains are products, never sums: . The tests use EXPECT_NEAR because and are not exact in binary, and the product is , not exactly 99. The parameters are doubles for a reason: with ints, p / 100 would be 0 for every change under 100%.
3. Fractions, decimals, percentages and ratios · Try it: percentage change · QuizA coat is reduced by 25% to 60 euros. What was the price before?B. 80 eurosDown 25% multiplies by , so and . Check: 25% of 80 is 20, and . Adding 25% of 60 back, to get 75, is the trap: the 25% was of the old price, not the new one.
3. Fractions, decimals, percentages and ratios · Ratios compare amounts; proportion keeps them fixed · QuizA recipe for 4 people uses 300 g of flour. How much flour do you need for 6?B. 450 gFlour is proportional to people: g per person, and g. Or scale by the ratio . Adding 100 g, “two more people, so a bit more”, is not proportion: it gives the two extra people only 50 g each, while the first four get 75 g each.
3. Fractions, decimals, percentages and ratios · Rates and unit conversion are fractions too · Fill the blanksConvert 72 km/h to metres per second. Fill in the two conversion numbers.1: 1000, 2: 3600A kilometre is 1000 m and an hour is s. So m/s. A quick rule: divide km/h by 3.6 to get m/s. Multiplying by 3600 instead of dividing is the usual slip; check the units cancel and the answer is sensible (20 m/s is a car on an open road, not a rocket). The variables are doubles so that 50 km/h comes out as 13.89 m/s; with ints it would be 13.
3. Fractions, decimals, percentages and ratios · Practice problems · ProblemWrite and as fractions in lowest terms.4/11 ≈ 0.363636; 5/27 ≈ 0.185185
The block 36 has two digits, so multiply by 100:
The block 185 has three digits, so multiply by 1000:
Simplify: and , so . Check:
3. Fractions, decimals, percentages and ratios · Practice problems · ProblemWork out , in lowest terms.11/10 ≈ 1.1
The bracket first, over twelfths:
Then divide by multiplying by the reciprocal:
The answer is , or . It is a bit more than , as it should be: dividing by a number less than 1 makes the answer bigger.
3. Fractions, decimals, percentages and ratios · Practice problems · ProblemAfter a rise of 12%, the rent of a flat is 896 euros a month. What was it before the rise?Before 800 euros
Up 12% multiplies by , so:
Check: 12% of 800 is 96, and . Taking 12% off 896 instead gives about 788.48: the 12% was of the old rent, not the new one.
3. Fractions, decimals, percentages and ratios · More practice problems · ProblemThree friends share 168 euros in the ratio . How much does each get?The first 24 euros; The second 60 euros; The third 84 euros
The ratio has equal parts, so one part is euros.
The shares are , and euros.
Check: .
3. Fractions, decimals, percentages and ratios · More practice problems · ProblemA car uses 6.5 litres of fuel per 100 km. How much fuel does it use on a 340 km trip? At 1.80 euros a litre, what does that fuel cost?Fuel 22.1 L; Cost 39.78 euros
The trip uses 22.1 litres, which cost 39.78 euros.
4. Powers, roots and scientific notation · A power is repeated multiplication · QuizWhat are and ?B. and : an even number of negatives makes a positive. In the power comes before the minus (Module 2’s order), so it is . The brackets decide whether the minus sign belongs to the base. And would be , a different operation.
4. Powers, roots and scientific notation · The laws of exponents follow from counting factors · QuizSimplify .A. (power of a power multiplies), then (multiplying adds), then (dividing subtracts). comes from adding instead of multiplying, the most common slip with these laws.
4. Powers, roots and scientific notation · The laws of exponents follow from counting factors · ProblemSimplify , for .a^5/2
Square the bracket, the 2 and the both: .
Multiply by (add exponents): .
Divide by , the numbers and the powers apart:
Forgetting to square the 2 gives , the most common slip here.
4. Powers, roots and scientific notation · Zero and negative exponents keep the pattern going · QuizWhat is ?C. A negative exponent means “one over”: . The minus is in the exponent, so it says nothing about the sign of the answer, which is positive. multiplies the 5 by the exponent, mixing up powers with products.
4. Powers, roots and scientific notation · Try it: powers by repeated multiplication · Code challengeWrite power(base, n) for a whole number n, which may be zero or negative, by multiplying in a loop. Do not use std::pow.One solution:
Solution
1#include<cmath>23doublepower(double base,int n){4double result =1;5for(int i =0; i < std::abs(n); i++){6 result = result * base;7}8if(n <0)return1/ result;9return result;10}
Starting result at 1, the identity for multiplication (Module 2), is what makes n = 0 give 1: the loop simply never runs. For a negative n, multiply times and take the reciprocal, exactly as says; result is a double, so 1 / result keeps its fraction. Starting at 0 instead is the usual slip: every product would be 0.
4. Powers, roots and scientific notation · A root undoes a power · QuizWhich of these are real numbers? Choose all that are.B. ; C. , so : odd roots of negatives are fine. . But no real number squares to , since squares are never negative, and the same goes for a fourth root of . Even roots of negatives need the complex numbers of Module 17.
4. Powers, roots and scientific notation · A fractional exponent is a root · QuizWhat is ?B. The bottom, 4, is a fourth root: , because . The top, 3, is a cube: . is , treating the exponent as a multiplier, which it never is.
4. Powers, roots and scientific notation · A fractional exponent is a root · ProblemWork out , and , exactly. 8; 1/9 ≈ 0.111111; 3/2 ≈ 1.5
The fifth root of 32 is 2, since . Then cube it: .
The cube root of 27 is 3. Square it, then take one over:
The square root of is , since . One over it flips it:
4. Powers, roots and scientific notation · Simplify a root by taking out squares · QuizWhat is ?B. Simplify each: and . Now they are like amounts of the same thing: . assumes roots add, , which is false: , but .
4. Powers, roots and scientific notation · Try it: a square root by halving the gap · Code challengeWrite squareRoot(a) for a ≥ 0 by bisection, without std::sqrt or std::pow. Start with low = 0 and high = std::max(1.0, a), and halve the gap 60 times. (std::max, from <algorithm>, wants two values of the same type: 1.0, not 1.)One solution:
Solution
1#include<algorithm>23doublesquareRoot(double a){4double low =0;5double high = std::max(1.0, a);6for(int i =0; i <60; i++){7double mid =(low + high)/2;8if(mid * mid < a) low = mid;9else high = mid;10}11return(low + high)/2;12}
The root always stays between low and high: low only moves to numbers whose square is below a, and high to ones whose square is not. Why std::max(1.0, a) for the start? For a below 1 the root is bigger than a (), so high = a would leave it outside the gap. Comparing mid * mid with a avoids needing a root to find a root.
4. Powers, roots and scientific notation · Scientific notation writes huge and tiny numbers · QuizWhat is in scientific notation?A. Move the point right until one non-zero digit is in front: is 4 places. Making the number bigger must be balanced by . is the same value, but not in standard form, because 45 is not below 10. A positive power would make it huge.
4. Powers, roots and scientific notation · Orders of magnitude compare by powers of ten · QuizThe Earth’s diameter is about m and the distance to the Sun about m. Roughly how many Earths would fit in a row from the Earth to the Sun?C. About 10 000Divide: , about 10 000 (about 11 500 with these figures). Subtracting the exponents, , is what dividing powers does; 4 is the exponent, not the answer, and adds them.
4. Powers, roots and scientific notation · Significant figures say how precise a number is · QuizWhat is to 3 significant figures?B. Start counting at the first non-zero digit: 4, 5, 0 are the first three, and the next digit is 7, so the 0 rounds up to 1: . is 3 decimal places, a different rule, and keeps only one significant figure. forgets to round up.
4. Powers, roots and scientific notation · Practice problems · ProblemSimplify , and rationalise the denominator of .6*sqrt(2) ≈ 8.48528; 2*sqrt(3) ≈ 3.4641
Take the biggest square out of each:
Now they are like amounts of : .
4. Powers, roots and scientific notation · Practice problems · ProblemSunlight travels about m from the Sun to the Earth, at m/s. How many seconds does the trip take? How many minutes is that?Time 500 s; In minutes 25/3 ≈ 8.33333 min
In minutes: minutes. The sunlight you see left the Sun over 8 minutes ago.
4. Powers, roots and scientific notation · Practice problems · ProblemWork out and . You can type an answer like as 3e4 or 3*10^4.The product 0.016; The quotient 30000000000
Product: , and . So it is , and in standard form:
Quotient: , and :
4. Powers, roots and scientific notation · More practice problems · ProblemRound to 3 significant figures, and to 2 significant figures. to 3 s.f. 0.00608; to 2 s.f. 49000
In the significant figures start at the 6: 6, 0, 8 are the first three, and the next digit is 1, so the 8 stays. The answer is ; the zero between 6 and 8 counts.
In the first two are 4 and 8, and the next digit is 7, so the 8 rounds up to 9. The places after it become zeros to keep the size: .
Writing would be a different number: rounding keeps the number about the same size.
4. Powers, roots and scientific notation · More practice problems · ProblemA colony of bacteria doubles every 20 minutes, starting from 1 cell. After 4 hours it has cells: what is , and how many cells is that? How many cells are there after 10 hours, in scientific notation to 3 significant figures? 12; After 4 hours 4096 cells; After 10 hours 2^30 ≈ 1073741824 cells
4 hours is 240 minutes, which is doublings, so and there are cells.
10 hours is 600 minutes, which is 30 doublings:
About a billion cells from one, in 10 hours.
5. Letters for numbers: variables and expressions · An expression names a value; an equation makes a claim · QuizWhich of these is an equation?B. Only has an equals sign, so only it says something that can be true or false. The others are expressions: values waiting for an . Asking “what is the answer to ?” has no single reply; asking “when is ?” does.
5. Letters for numbers: variables and expressions · Substitute to find an expression’s value · QuizWhat is when and ?B. . The square of is , and the minus in front of then subtracts it. Writing without brackets, or thinking “minus a negative is plus”, gives the wrong .
5. Letters for numbers: variables and expressions · Substitute to find an expression’s value · ProblemFind the value of when and , and of when . -5; 6
Top: . Bottom: . So the value is .
Second, with :
5. Letters for numbers: variables and expressions · Only like terms can be added · QuizSimplify .A. Group by kind: terms ; terms ; the constant . A term’s sign goes with it, so is subtracted. Adding all the coefficients together, , treats unlike terms as if they were alike.
5. Letters for numbers: variables and expressions · Only like terms can be added · Code challengeEach term is a Term, a coefficient and its letters, so is {3, "x"}, is {2, "x²"} and a constant 5 is {5, ""}. Write collect(terms): add the coefficients of like terms, and return a std::map from letters to coefficient. Leave out any that come to 0. In a map, m[key] is the value kept for key (0 the first time), and for (const auto& [key, value] : m) visits each entry.One solution:
The letters are the key: two terms are alike exactly when their letters match, so they land in the same entry and their coefficients add. A map’s sums[letters] starts a new kind at zero, so += works the first time too. A struct (here Term) groups named values: term.letters reads one. Leaving out the zeros afterwards is what means: the term is gone, not “”. This is how computer algebra systems store polynomials, a map from each kind of term to its coefficient.
5. Letters for numbers: variables and expressions · Expanding brackets multiplies every term · Find the bugThis simplification of goes wrong on one line. Which?Line 2: = -6x + 12 + 5xThe multiplies both terms: , and , since two negatives make a positive. Line 3 collects the terms of line 2 correctly, but from a wrong start; the right answer is . Check by substituting: at the original is , not .
5. Letters for numbers: variables and expressions · Expanding brackets multiplies every term · ProblemExpand and simplify and .2*x^2 + 5*x - 12; 7*x - 3
Four products, then collect the like terms:
Expand each bracket, minding the signs: .
Check the first at : , and .
5. Letters for numbers: variables and expressions · Factoring puts the brackets back · Fill the blanksFactor completely. The two functions must agree for every x; the last line checks a few.1: 6, 2: 2, 3: 3, and . or are also equal, but not completely factored: the inside still has a common factor. Taking out the highest common factor in one step leaves a bracket with none left.
5. Letters for numbers: variables and expressions · Factoring puts the brackets back · QuizFactor completely.B. Numbers: . Letters: each term has at least . So the common factor is , and , . The other options are all equal to the expression but leave something common inside the bracket; is not even equal, since it expands to .
5. Letters for numbers: variables and expressions · Turning words into expressions · QuizA garden is metres wide and 3 metres longer than it is wide. What is its perimeter, the distance all the way round?B. The length is . A rectangle has two widths and two lengths, so the perimeter is . goes only half way round. is the area, a different question. forgets that the extra 3 is in both lengths.
5. Letters for numbers: variables and expressions · Turning words into expressions · Code challengeWrite two expressions as functions. ticketCost(adults, children): 12 euros per adult, 7 per child. gardenPerimeter(width): the perimeter of a garden 3 m longer than it is wide.One solution:
Naming the length, width + 3, before using it keeps the code close to the words, and it is easy to check: the garden 5 m wide is 8 m long, so . The last test checks your function against the simplified expression for several widths: two expressions are the same when they agree for every value, which is the next slide’s idea.
5. Letters for numbers: variables and expressions · An identity is true for every value · QuizWhich of these are identities, true for every ? Choose all that are.A. ; C. ; E. Expanding the left side of the first and last gives the right side exactly, and is collecting like terms. , so that one is true only when , at . is an ordinary equation, true only at .
5. Letters for numbers: variables and expressions · Practice problems · ProblemFactor completely. What is the highest common factor you take out, and what is left in the bracket?Common factor 5*x*y; In the bracket 3*x - 2*y
Numbers: . Letters: both terms have at least one and at least one . So the highest common factor is .
Divide each term by it: and .
Check by expanding: and .
5. Letters for numbers: variables and expressions · Practice problems · ProblemA rectangle is cm wide, and its length is 2 cm more than three times its width. Write its perimeter in terms of , simplified. Then find the perimeter when .Perimeter 8*w + 4 cm; When 40 cm
The length is . The perimeter is two widths and two lengths:
At : cm. Check: the length is , and .
5. Letters for numbers: variables and expressions · Practice problems · ProblemA family goes to the cinema: adults at 9 euros each, and children at 6 euros each, with 3 more children than adults. Write the total cost in terms of , simplified. What does it come to for 2 adults?Total 15*a + 18 euros; For 2 adults 48 euros
There are children. The cost is the adults’ plus the children’s:
For : euros. Check: 2 adults cost 18 and 5 children cost 30, which is 48.
5. Letters for numbers: variables and expressions · Practice problems · ProblemExpand and simplify . Then use your answer to work out without a calculator.20*x; 2000
Expand each square:
Subtract, minding that the minus applies to every term of the second:
With : . Check: .
6. Solving linear equations · Undo what was done to the unknown, in reverse order · Put in orderPut the steps for solving in order.1. Start: 2. Add 3 to both sides: 3. Multiply both sides by 2: 4. Check: , as it should beThe recipe was “halve, then subtract 3”, so you undo the subtraction first, then the halving. Multiplying by 2 first also works, but then you must multiply every term: . Forgetting the 3 there, writing , is the common slip. The check at the end catches it.
6. Solving linear equations · Gather the unknowns on one side · QuizSolve .A. Add to both sides: . Add 8: . Divide by 5: . Check: and . comes from moving across as instead of , which leaves : a term changes sign when it moves, because you added its opposite to both sides. is a sign lost at the last step, which the check catches.
6. Solving linear equations · Gather the unknowns on one side · ProblemSolve .11/2 ≈ 5.5
Check with : and .
6. Solving linear equations · Always check by substituting back · Find the bugThis solution of gives , which fails the check. Which line has the mistake?Line 3: 2x = -16From , subtracting 6 from both sides gives , not : the 6 was added to instead of subtracted. Then . Check in the original: and . And fails: on the left, on the right.
6. Solving linear equations · Expand brackets first · QuizSolve .A. Expand: . The multiplies both terms, so . Collect: , so and . Check: . Writing , the classic sign slip, gives and ; dropping the sign on the 3 gives other wrong answers.
6. Solving linear equations · Clear fractions by multiplying through · QuizSolve .A. Multiply both sides by 10: . Expand: . So and . Check: and . Keep the brackets when you multiply a fraction with a sum on top: instead of is the slip to avoid.
6. Solving linear equations · Clear fractions by multiplying through · ProblemSolve .22/5 ≈ 4.4
Multiply every term by 12:
Check with : and , and .
6. Solving linear equations · Some equations have no solution, some have every number · QuizHow many solutions does have?C. Every number is a solutionExpand the left: . That is the right side exactly, so the equation is an identity and every works; subtracting from both sides leaves , always true. A linear equation can never have exactly two solutions: two lines that meet twice are the same line.
6. Solving linear equations · Try it: a solver for every linear equation · Code challengeFinish solveLinear(a, b, c, d), which solves . Return a Solution whose kind is "one" (with the solution in x), "none" when there is none, or "all" when every number is one.One solution:
Solution
1#include<string>23structSolution{4 std::string kind; // "one", "none" or "all"5double x; // the solution, when kind is "one"6};78SolutionsolveLinear(double a,double b,double c,double d){9if(a == c){10if(b == d)return{"all",0};11return{"none",0};12}13return{"one",(d - b)/(a - c)};14}
The starter is right whenever , which is why it looks finished. With it divides by zero, and a double gives inf for and nan (“not a number”) for , rather than an error. (Dividing ints by zero is worse: it is undefined behaviour, and here it stops the program.) Those two are the computer’s versions of “no solution” and “any number”, so the cases must be checked before dividing. Comparing with == is safe here because the inputs are given exactly; after a long calculation you would compare with a small tolerance instead.
6. Solving linear equations · Rearranging a formula is solving for a letter · Fill the blanksFahrenheit from Celsius is . Rearrange it to write celsius(f): subtract first, then undo the multiplication.1: 32, 2: 5, 3: 9Undo in reverse: , then multiply both sides by , the reciprocal: . Subtracting 32 after multiplying, , is the usual mistake: it undoes the steps in the wrong order. Check with 212: . In C++, keep the order of the code: 5 / 9 * (f - 32) would be 0 for every temperature, because 5 / 9 divides two ints.
6. Solving linear equations · Rearranging a formula is solving for a letter · QuizThe area of a circle is . What is in terms of ?B. Divide by : . Then undo the square with a square root: , taking the positive root because a radius is a length. treats the square as a doubling. roots the but not the : , so dividing it by does not leave .
6. Solving linear equations · Word problems: name, write, solve, check · QuizA taxi charges 3.50 euros to start plus 1.80 euros per kilometre. A ride costs 21.50 euros. How long was it?A. 10 kmLet be the kilometres: . Subtract the starting fee: , so . Check: . comes from dividing the whole fare by 1.80 and forgetting the fixed part, and from adding it instead of subtracting.
6. Solving linear equations · Practice problems · ProblemSolve .33/4 ≈ 8.25
Check with : the left is , and the right is .
6. Solving linear equations · Practice problems · ProblemThe perimeter of a rectangle is , where is its length and its width. Make the subject. Then find when cm and cm.P/2 - l; When , 8 cm
That is the same as . With and : cm.
Check: .
6. Solving linear equations · Practice problems · ProblemA mother is 3 times as old as her son. In 12 years she will be twice as old as he will be. How old are they now?The son 12 years; The mother 36 years
Let be the son’s age now; the mother is . In 12 years they will be and :
The son is 12 and the mother is 36. Check against the words: in 12 years they will be 24 and 48, and 48 is twice 24.
6. Solving linear equations · More practice problems · ProblemPhone plan A costs 15 euros a month plus 0.10 euros a minute. Plan B costs 25 euros a month plus 0.05 euros a minute. For how many minutes a month do they cost the same, and what is that cost?Minutes 200 min; Cost 35 euros
At 200 minutes, plan A costs euros, and plan B euros.
Below 200 minutes plan A is cheaper; above it, plan B.
6. Solving linear equations · More practice problems · ProblemThree consecutive odd numbers (odd numbers that follow each other, each 2 more than the last) add up to 159. What are the smallest and the largest?Smallest 51; Largest 55
The numbers are 51, 53 and 55. Check against the words: all three are odd, and .
7. Inequalities and absolute value · An inequality has a range of solutions · QuizWhich of these numbers satisfy ? Choose all that do.A. ; B. ; E. means “ or anything to its left”. and are left of , and itself is allowed by the “or equal”. is to the right of , so it is bigger, even though 1.5 is smaller than 2: compare positions on the line, not the digits.
7. Inequalities and absolute value · Multiplying by a negative flips the inequality · QuizSolve .B. Subtract 5: . Divide by and flip: . Check : , true. Check , which would include: , false. Forgetting the flip is the single most common mistake with inequalities.
7. Inequalities and absolute value · Multiplying by a negative flips the inequality · ProblemSolve . What is the largest number that satisfies it?The largest -5
So every works, and the largest is itself, since includes it.
Check two numbers: gives , true; gives , false.
7. Inequalities and absolute value · Find the missing flip · Find the bugThis solves , but the answer is wrong. Which line is the mistake?Line 3: x >= -8Going from to an answer for multiplies both sides by , a negative, so the sign must flip: . Check with , which is : , true. And , which the wrong answer allows: , false.
7. Inequalities and absolute value · Interval notation writes a range in brackets · QuizWhich interval is ?B. is included (), so its bracket is square: . is not (), so its bracket is round: . The brackets go with their own ends, read left to right just like the inequality.
7. Inequalities and absolute value · Compound inequalities: and, or · Put in orderPut the steps for solving in order.1. Subtract 7 from all three parts: 2. Divide all three by and flip both signs: 3. Rewrite smallest first: 4. As an interval: Each step is done to all three parts. Dividing by flips both signs, which reverses the order of the ends; writing it again with the smaller end on the left makes it readable. Note which end is included: the that was next to 1 became the next to 2, so 2 is in and is out.
7. Inequalities and absolute value · Try it: solve any linear inequality · Code challengeWrite solveLess(a, b, c), which solves and returns the open interval of solutions as an Interval{lower, upper}, using -inf or inf (infinity, already defined) for no end. Return std::nullopt when nothing is a solution: a std::optional<Interval> holds an Interval or nothing, s.has_value() says which, and s->lower reads its member.One solution:
The sign of a decides which side the solutions are on: gives , so the edge becomes the lower end. With a = 0 the starter divides by zero: when it happens to land on inf, the right end, but otherwise it answers an interval ending at -inf or nan instead of std::nullopt. The two cases have to be caught first, as in the equation solver of Module 6. (Comparing with inf exactly is fine: infinity is a value a double holds exactly.)
7. Inequalities and absolute value · An absolute value equation usually has two answers · QuizSolve .B. or Split it: gives , and gives , . Check: and . The answers are not the same number, because the shifts the centre: they sit either side of , where .
7. Inequalities and absolute value · An absolute value equation usually has two answers · Code challengeWrite absSolutions(a, b, r): every solution of , smallest first, for . Return {} when there is none and one number when . std::min and std::max (from <algorithm>) give the smaller and bigger of two.One solution:
Split into and and solve each. When is negative, dividing reverses which one is smaller, so sort them instead of assuming. needs its own case: both equations are the same, and listing the answer twice would claim two solutions where there is one.
7. Inequalities and absolute value · An absolute value equation usually has two answers · ProblemSolve . Give both solutions.The smaller -7/3 ≈ −2.33333; The larger 5
What is inside the bars is either or :
Check: and .
7. Inequalities and absolute value · Absolute value inequalities: inside or outside · QuizSolve .B. or “At least 3 away from 2”: either or , two pieces, an “or”. is the opposite, the numbers within 3 of 2. alone forgets the left side, where is negative but its distance is still large.
7. Inequalities and absolute value · Practice problems · ProblemSolve and write the answer as an interval. What are its left and right ends? How many integers are in it?Left end -3; Right end 5; Integers in it 8
Smallest first: , the interval : is in, is not.
The integers in it are : 8 of them. 5 is left out, because the right end is open.
7. Inequalities and absolute value · Practice problems · ProblemSolve . The answer is an interval : what are and ? -6; 3
Being less than 9 from zero means lying between and :
So and . Check the middle, : , true; and , outside: , false.
7. Inequalities and absolute value · Practice problems · ProblemA phone plan costs 12 euros a month plus 0.08 euros for each text message. You want to spend at most 20 euros in a month. What is the largest number of texts you can send?Texts 100
You can send up to 100 texts. Check: 100 texts cost euros, exactly the limit, and one more would go over.
7. Inequalities and absolute value · More practice problems · ProblemA tank holds 500 litres when a tap at its bottom is opened at . It drains at 15 litres a minute. For which times , in minutes, does it hold between 200 and 380 litres (both included)?From 8 min; To 20 min
So . Check: at the tank holds litres, and at it holds .
7. Inequalities and absolute value · More practice problems · ProblemA bag of flour is sold as 1000 g, and the law allows its weight to be off by at most 15 g: . What are the lightest and the heaviest weights allowed? A bag weighs 984 g: by how many grams is it outside the allowed range?Lightest 985 g; Heaviest 1015 g; The 984 g bag is outside by 1 g
Within 15 g of 1000 g:
A bag of 984 g is g off, 1 g more than allowed: it is 1 g below the lightest legal weight, 985 g.
8. Functions: a rule from inputs to outputs · f(x) names the output · QuizIf , what is ?A. Substitute in brackets: . The two places appears both get . comes from writing , but the whole input is squared, ; also loses the sign of . This is the same thing as calling f(-2) in code.
8. Functions: a rule from inputs to outputs · f(x) names the output · ProblemFor , find and . Then find in terms of , expanded and simplified. 24; 2/3 ≈ 0.666667; 3*a^2 - 11*a + 10
The input replaces every , in brackets:
Check with , which makes the input : , the same as .
8. Functions: a rule from inputs to outputs · Domain is what goes in, range is what comes out · QuizWhat is the domain of ?B. The square root needs what is inside to be at least 0: , so , the interval (Module 7). is allowed, since . is the domain of , but is not real.
8. Functions: a rule from inputs to outputs · The vertical line test · QuizWhich of these give as a function of ? Choose all that do.A. ; D. and give one for each . fails: at , both and work, so a vertical line at 4 crosses twice. The circle fails the same way. Note is a function if you read it the other way, from : which variable is the input matters.
8. Functions: a rule from inputs to outputs · Piecewise functions use different rules on different inputs · Code challengeWrite postage(grams) from the rule above. Its domain is : for any weight outside it, return std::nullopt, no value at all. (A std::optional<double>, from <optional>, holds a double or nothing.)One solution:
Checking the pieces in order, smallest first, means each if only has to test the upper end: by the time you reach grams <= 500, you already know it is over 100. The boundaries are where piecewise functions go wrong: “up to 100 g” includes 100, so it is <=. Returning std::nullopt outside the domain says the function has no value there, instead of quietly making one up. (The prices are compared exactly because they are copied, not computed: 1.2 returned is the same double as 1.2 expected.)
8. Functions: a rule from inputs to outputs · Composition feeds one function into another · QuizIf and , what is ?A. Inside first: . Then . Doing them the other way, , is a different function. comes from squaring the two parts separately, , but : the whole of is squared.
8. Functions: a rule from inputs to outputs · Composition feeds one function into another · Code challengeFix compose(f, g): it must return the function , which runs g first and then f. Fn is a function from double to double (a std::function, from <functional>), and [f, g](double x) { … } is a lambda, a function made on the spot that keeps f and g.One solution:
is written with first but runs first, because in the inner call is evaluated before the outer one. The starter does the opposite, which only looks right when the order happens not to matter. The answer is itself a function: compose takes two functions and returns a third, which is what composition is.
8. Functions: a rule from inputs to outputs · An inverse function runs the machine backwards · Fill the blanksWrite the inverse of , so that the check is true.1: 2, 2: 5 multiplies by 5 and then subtracts 2, so its inverse adds 2 and then divides by 5: the steps undone in reverse order, as in solving an equation. undoes them in the wrong order, and is not 1.
8. Functions: a rule from inputs to outputs · An inverse function runs the machine backwards · QuizWhy does , on all real numbers, have no inverse?B. Because two inputs give the same output, so an inverse would not know which to give back, so would have to be both 2 and , and a function gives one output. Only one-to-one functions, where different inputs give different outputs, have inverses. The fix is to restrict the domain: on , is one-to-one and its inverse is (the curves of Module 4).
8. Functions: a rule from inputs to outputs · An inverse function runs the machine backwards · ProblemFind the inverse of . Then work out .(2*x - 4)/3; 2
Renaming, . So .
Check: , so the inverse sends 5 back to 2.
8. Functions: a rule from inputs to outputs · Shift, stretch and reflect a graph · QuizHow is the graph of made from ?B. 2 left, 3 downWrite it as : , so , a move left by 2. moves it down by 3. The turning point is at : check that gives . The plus sign inside looking like “right” is the trap; changes inside the bracket act on , and so go the opposite way to how they look.
8. Functions: a rule from inputs to outputs · Practice problems · ProblemLet and . Find and , and write as one simplified expression. 13; 12; 2*x^2 + 5
, then .
, then . A different answer: the order matters.
Check at : , as found above.
8. Functions: a rule from inputs to outputs · Practice problems · ProblemLet . What is the largest number in its domain? Find , exactly. What is the smallest number in its range?Largest input 4; 2*sqrt(6) ≈ 4.89898; Smallest output 0
The inside must not be negative: , so , and . The domain is , and its largest number is 4.
A square root is never negative, and , so the smallest output is 0. The range is .
8. Functions: a rule from inputs to outputs · Practice problems · ProblemAn electricity tariff charges 0.20 euros per kWh for the first 100 kWh used in a month, and 0.30 euros for each kWh after that. What does a month of 80 kWh cost? And of 250 kWh? A household’s bill is 50 euros: how many kWh did it use?80 kWh 16 euros; 250 kWh 65 euros; A bill of 50 euros 200 kWh
With kWh, the cost in euros is
80 kWh is in the first piece: euros. 250 kWh is in the second: euros.
50 euros is more than 20, so the household used over 100 kWh: , so , and kWh.
8. Functions: a rule from inputs to outputs · Practice problems · ProblemThe graph of is moved 3 to the left, stretched upright by a factor of 2, and then moved 5 down. Write the equation of the new graph, and give its turning point.2*(x + 3)^2 - 5; Turning point, -3; Turning point, -5
Left 3: . Stretched by 2: . Down 5:
This is with , and , so the turning point is .
Check: at the bracket is 0 and , the lowest point, since is never negative.
9. Lines and slope · Two number lines make a plane · QuizIn which quadrant is the point ?B. Second (top left) is 3 to the left, is 2 up: top left, the second quadrant. Swapping the coordinates, reading as 3 down and 2 across, would put it in the fourth. Across always comes first, the same order as in the alphabet: before .
9. Lines and slope · Slope is rise over run · QuizWhat is the slope of the line through and ?A. : down 3 for each step right. Taking the points in the same order on top and bottom is essential; mixes them and gives . Putting run over rise gives .
9. Lines and slope · Slope-intercept form: y = mx + c · QuizA line crosses the axis at and goes down 2 for every 1 across. What is its equation?B. Down 2 per 1 across is a slope of ; the intercept is . So . Swapping the two numbers, , is the common slip: the number multiplying is always the slope. Check: at , ; at , , two lower.
9. Lines and slope · Try it: the line through two points · Code challengeFinish lineThrough(x1, y1, x2, y2): return a Line{m, c} for the line through the two points, or std::nullopt when the line is vertical.One solution:
With and the point : , so ; check with the other point, . The starter forgets , which is only right for lines through the origin. With x1 == x2 the slope would be , which is why vertical lines are written instead.
9. Lines and slope · Try it: the line through two points · ProblemA line passes through and . Find its slope , its -intercept , and where it crosses the axis.3/2 ≈ 1.5; 1/2 ≈ 0.5; -intercept, -1/3 ≈ −0.333333
From the point : . The line is .
It crosses the axis where , so and .
Check with the other point: .
9. Lines and slope · Point-slope form starts from any point · QuizWhich is the line with slope through ?A. , so . Check: at , . uses the point’s as if it were the intercept, which is only true when the point is on the axis.
9. Lines and slope · Standard form handles every line, vertical ones too · QuizWhat is the slope of ?C. Solve for : , so . The slope is ; with and , agrees. Reading the coefficient of in standard form as the slope is the usual mistake: it is the slope only once stands alone.
9. Lines and slope · Parallel lines share a slope; perpendicular slopes multiply to −1 · QuizWhat slope does a line perpendicular to have?D. Flip the fraction and change the sign: . Check: . Changing only the sign, , gives a line that leans the other way at the same steepness, which is not at a right angle; flipping only gives , still leaning the same way.
9. Lines and slope · Parallel lines share a slope; perpendicular slopes multiply to −1 · ProblemFind the line through that is perpendicular to . Write it as : what are and ?-3/2 ≈ −1.5; 5
Solve for : , so . Its slope is .
The perpendicular slope is . Check: .
Through , in point-slope form:
So and .
9. Lines and slope · Distance and midpoint between two points · Code challengeWrite distance(x1, y1, x2, y2), the straight-line distance between two points, and midpoint(x1, y1, x2, y2), the point halfway, as a Point{x, y}.One solution:
The starter measures the taxicab distance, going along the grid like a car in a city of square blocks: 7 for the 3-4-5 triangle instead of 5. A straight line cuts the corner, and Pythagoras says by how much. The starter’s midpoint is half the gap, which is the midpoint only when the first point is the origin; averaging the coordinates works everywhere. Squaring makes the order of the points irrelevant, since .
9. Lines and slope · A line is a model of steady change · QuizA phone plan costs euros a month for minutes of calls. What does the mean?B. The cost of each minute of calls, in eurosThe slope is the change in cost per minute: each extra minute adds 0.05 euros, so its units are euros per minute. The 12 is the intercept: the cost when , the fixed monthly fee. Reading the units of the slope, “output units per input unit”, is the quickest way to say what it means.
9. Lines and slope · Practice problems · ProblemFor the points and , find the distance , exactly (as a simplified surd), and the midpoint of .2*sqrt(13) ≈ 7.2111; Midpoint, -1; Midpoint, 1
That is about 7.21.
9. Lines and slope · Practice problems · ProblemFor the line , find where it crosses the axis and the axis, and its slope.-intercept, 4; -intercept, -10; Slope 5/2 ≈ 2.5
Set : , so . Set : , so .
Solve for : , so . The slope is .
Check with , and with the intercepts: from to rises 10 over a run of 4.
9. Lines and slope · Practice problems · ProblemA plumber charges a fixed call-out fee plus a rate per hour. A 2-hour job costs 110 euros and a 5-hour job costs 215 euros. What is the hourly rate, what is the call-out fee, and what does a 3.5-hour job cost?Rate 35 euros per hour; Call-out fee 40 euros; 3.5 hours 162.5 euros
The slope between and is the rate:
The fee is the intercept: euros. So the cost is .
For 3.5 hours: euros. Check with the 5-hour job: .
9. Lines and slope · More practice problems · ProblemThe points , and lie on one straight line. Find . 6
The slope from to is .
From to it must also be 3:
Check: from to the slope is .
9. Lines and slope · More practice problems · ProblemFind the line parallel to that passes through . What is its -intercept, and where does it cross the axis?-intercept, -5; -intercept, 5/4 ≈ 1.25
The new line is . Through : , so , and the line is .
It crosses the axis where , at .
10. Systems of equations · Two unknowns need two facts · QuizWhich pair solves both and ?A. Check each in both equations. : and , both true. and satisfy the first only, and the second only. A solution of a system has to pass every equation; passing one is not enough.
10. Systems of equations · Substitution: solve one, put it into the other · Put in orderPut the steps for solving and in order.1. Replace in the second equation: 2. Solve for : , so 3. Put back into : 4. Check in both: and Substitute, solve the one-unknown equation, back-substitute, check. Substituting into the same equation you solved, , gets you nowhere: it turns into , true but empty. The expression must go into the other equation.
10. Systems of equations · Substitution: solve one, put it into the other · ProblemSolve by substitution: and . 3; 4
Check in the second equation: .
10. Systems of equations · Elimination: add the equations to cancel a variable · QuizSolve and .A. The terms are and , so add: , . Then , so . Check in the first: . Subtracting instead of adding gives , which still has both variables: choose the operation that makes the chosen terms cancel.
10. Systems of equations · Elimination: add the equations to cancel a variable · ProblemSolve by elimination: and . 3; -1
Back into the first: , so and .
Check in the second: .
10. Systems of equations · One solution, none, or infinitely many · QuizHow many solutions does the system , have?A. NoneDouble the second: . Subtract it from the first: , which is false, so there is no solution. Both lines have slope but different intercepts: parallel. If the second had been , doubling it would give the first equation exactly, the same line, and infinitely many solutions.
10. Systems of equations · Try it: solve any two-by-two system · Code challengeFinish solveTwo(a, b, c, d, e, f) for , . Return a Solution whose kind is "one" (with x and y), "none" or "infinite". When : if both tops, and , are 0 too, it is the same line.One solution:
Solution
1#include<string>23structSolution{4 std::string kind; // "one", "none" or "infinite"5double x;6double y;7};89SolutionsolveTwo(double a,double b,double c,double d,10double e,double f){11double det = a * d - b * c;12double topX = e * d - b * f;13double topY = a * f - e * c;14if(det ==0){15if(topX ==0&& topY ==0)return{"infinite",0,0};16return{"none",0,0};17}18return{"one", topX / det, topY / det};19}
This is Cramer’s rule for two equations, and is the determinant of the system, which comes back in Module 19 as how much a matrix scales area. Computing the two tops first lets the zero case use them: with a zero determinant, the equations are multiples of each other on the left, and they agree on the right exactly when both tops vanish. Checking det == 0 before dividing matters, as in Module 6: dividing by 0 would give inf or nan, not an answer.
10. Systems of equations · Word problems with two unknowns · QuizTwo numbers add up to 30 and one is 8 more than the other. What are they?A. 19 and 11 and . Add them: , so and . Check: and . 22 and 8 satisfy “add to 30” but differ by 14; 20 and 12 differ by 8 but add to 32. Each answer has to pass both facts.
10. Systems of equations · Three unknowns need three equations · QuizTo solve a system in , and , you add equations (1) and (2) and get rid of . What do you need to do next, before you can find and ?B. Eliminate from a different pair, to get a second equation in and One equation in two unknowns has endless solutions (the first slide of this module). A second equation in the same two unknowns is needed, and it must come from a different pair, say (1) and (3) or (2) and (3), so that it carries new information. Then it is a two-by-two system. Module 18 turns this bookkeeping into an algorithm, Gaussian elimination, that works for any number of unknowns.
10. Systems of equations · Systems of inequalities mark out a region · Code challengeEach rule {a, b, c} means . Fix feasible(x, y, rules) so it is true only when the point satisfies every rule.One solution:
Solution
1#include<vector>23structRule{4double a, b, c; // a x + b y <= c5};67boolfeasible(double x,double y,const std::vector<Rule>& rules){8for(constRule& r : rules){9if(r.a * x + r.b * y > r.c)returnfalse;10}11returntrue;12}
A system means and: every rule must hold, so the first broken rule settles it, false, and only a point that breaks none gets true. The starter returns true as soon as one rule holds, which is the “or” of Module 7. Writing every rule as makes them uniform: becomes , and becomes (multiplying by flips it). The corner is on two lines, and includes it.
10. Systems of equations · Practice problems · ProblemA theatre sells 350 tickets for one show: adult tickets at 18 euros and child tickets at 11 euros. The takings are 5390 euros. How many of each kind were sold?Adult tickets 220; Child tickets 130
Then . Check against the words: euros.
10. Systems of equations · Practice problems · ProblemA drink that is 20% juice is mixed with a drink that is 50% juice, to make 30 litres of a drink that is 30% juice. How many litres of each are used?Of the 20% drink 20 L; Of the 50% drink 10 L
Multiply the second by 10 to clear decimals, , and the first by 2, . Subtract: , so and .
Check: litres of juice, which is 30% of 30 litres.
10. Systems of equations · Practice problems · ProblemSolve , and . 1; -1; 2
Number them (1), (2), (3). Two different pairs, each without :
From the first, . Then , so , and .
Back in (1): , so . Check (2): . Check (3): .
10. Systems of equations · More practice problems · ProblemFor which number does the system , have no solution? 3
There is not exactly one solution when :
With , three times the first equation is , but the second says . Both cannot hold, so the lines are parallel and there is no solution.
10. Systems of equations · More practice problems · ProblemThe region , , is a triangle. Two of its corners are on the axis. Find the third corner, where the two slanted lines meet, and the area of the triangle.Corner, 5; Corner, 3; Area 25
Where the slanted lines meet: , so , and .
On the axis () the lines are at and : the corners and .
The base along the axis is , and the third corner is 5 from the axis, so:
11. Polynomials and factoring · A polynomial is a sum of powers of one letter · QuizWhat is the degree of ?B. 3The degree is the highest power present, wherever it is written: makes it 3. In standard form it reads , so the leading term is first and the degree is easy to see. The number of terms has nothing to do with it: has one term and degree 10.
11. Polynomials and factoring · Adding and subtracting means collecting like terms · Fill the blanksSubtract: . Fill in the coefficients of the answer (a negative one with its minus sign).1: 3, 2: -5, 3: 12Flip every sign in the second bracket first: . Then collect: for , for , for the constant. If you got for or for the constant, a sign inside the bracket was not flipped.
11. Polynomials and factoring · Multiplying means every term times every term · Code challengeWrite multiply(p, q): the coefficients of the product of two polynomials with whole-number coefficients, both given constant first. The result has p.size() + q.size() - 1 coefficients; std::vector<int> out(n, 0) makes a vector of n zeros.One solution:
Index is power, and , so each product is added into out[i + j]. The += is the collecting of like terms: several pairs land on the same power, as and did above. Writing = instead keeps only the last pair and gives wrong middle coefficients. This double loop is called a convolution; it shows up again in signal processing and probability.
11. Polynomials and factoring · Three products worth knowing by heart · Find the bugThis expansion of goes wrong on one line. Which?Line 3: = x^2 - 5x - 5x + 25The last product is : a negative times a negative is positive. The pattern says so too: the term is always positive. A quick check with a number catches it: at , , but gives .
11. Polynomials and factoring · Three products worth knowing by heart · ProblemUse the special products to work out and without a calculator. 9991; 9801
Both numbers are , so the difference of two squares applies:
For the square, use with and ; the middle term is the one not to forget:
So and .
11. Polynomials and factoring · Evaluate a polynomial the fast way · Code challengeWrite evaluate(p, x): the value of the polynomial with coefficients p (constant first) at x, using Horner’s method. An empty list is the zero polynomial.One solution:
Solution
1#include<vector>23doubleevaluate(const std::vector<double>& p,double x){4double result =0;5int n = p.size();6for(int k = n -1; k >=0; k--){7 result = result * x + p[k];8}9return result;10}
The loop goes from the highest power down, because Horner’s nesting starts with the leading coefficient. (n is an int copy of p.size(), so that k can go below 0 and stop the loop; the size itself is never negative.) For a polynomial of degree it needs only multiplications, where working out each power separately needs about . Looping from index 0 upwards with the same line computes the coefficients in the wrong order: it evaluates the polynomial with its coefficients reversed.
11. Polynomials and factoring · Factoring undoes multiplying · Put in orderPut the steps for factoring by grouping in order.1. Split it into two pairs: 2. Take a common factor out of each pair: 3. Notice both pairs share the factor 4. Take it out: 5. Check by multiplying back: Grouping only works when, after the first factoring, the brackets match exactly. Here both are . Checking by multiplying back is never wasted: factoring is easy to get almost right. Note that does not factor further using real numbers, since is never 0.
11. Polynomials and factoring · Differences of squares and trinomials · QuizWhich is the factored form of ?A. You need a product of and a sum of : and work. has the right product but sums to , giving . When is negative the two numbers have opposite signs, and the bigger one takes the sign of .
11. Polynomials and factoring · Differences of squares and trinomials · Fill the blanksFactor completely: . It is a difference of squares twice.1: 4, 2: 2 and , so the first step is . Then is itself a difference of squares, . The sum stays as it is. “Completely” means keep going until no factor can be split further.
11. Polynomials and factoring · Dividing one polynomial by another · Code challengeWrite divideByLinear(p, r): divide the polynomial p (whole-number coefficients, constant first) by , returning a Division: a struct holding the quotient, also constant first, and the remainder.One solution:
Solution
1#include<vector>23structDivision{4 std::vector<int> quotient;5int remainder;6};78DivisiondivideByLinear(const std::vector<int>& p,int r){9int n = p.size()-1;10 std::vector<int>quotient(n,0);11int carry =0;12for(int k = n; k >=1; k--){13 carry = p[k]+ r * carry;14 quotient[k -1]= carry;15}16return Division{quotient, p[0]+ r * carry};17}
Each step is “coefficient plus times the last result”, from the highest power down, which is Horner’s method again: the numbers you write down on the way are the quotient’s coefficients, and the last one is . Using instead of for is the usual slip: , so . The quotient has one coefficient fewer than p, because its degree is one less.
11. Polynomials and factoring · The remainder and factor theorems · QuizWhat is the remainder when is divided by ?A. 1No division needed: the remainder is . The answer comes from adding instead of subtracting it. Dividing by means evaluating at , not . Since the remainder is not 0, is not a factor.
11. Polynomials and factoring · The remainder and factor theorems · QuizWhich of these is a factor of ?B. Test the root: , and , so is a factor. For , . Dividing gives , the sum of cubes pattern.
11. Polynomials and factoring · The remainder and factor theorems · ProblemLet . Find the remainder when is divided by . Then show that is a factor, and find all three roots of .Remainder on dividing by -8; Smallest root -3; Middle root -1; Largest root 2
By the remainder theorem, the remainder on dividing by is :
And , so is a factor. Synthetic division by on the coefficients : bring down ; then , and . The quotient is .
The remainder is , and the roots are , and .
11. Polynomials and factoring · Roots, touching and the ends of the graph · QuizAs grows large and positive, what does do?B. It falls without limitFor large enough , the leading term always wins: beats once , since then . Its coefficient is negative, so falls without limit. For moderate , say 10, the term does dominate, which is why end behaviour is only about the far ends.
11. Polynomials and factoring · Practice problems · ProblemMultiply out and collect like terms. Give each coefficient of the result.Coefficient of 3; Coefficient of 10; Coefficient of -11; Constant term 2
Multiply each term of by each term of :
Collect like terms: for , ; for , .
Check at : the left is and the right is .
11. Polynomials and factoring · Practice problems · ProblemDivide by . Give the quotient and the remainder.Quotient x^2 - x + 3; Remainder -1
Synthetic division with : bring down the leading coefficient, then each next number is the coefficient above plus times the last result.
The first three numbers are the quotient’s coefficients and the last is the remainder:
Check with the remainder theorem: . The quotient is and the remainder is .
11. Polynomials and factoring · Practice problems · ProblemFind the number for which is a factor of . With that , find the other two roots. 1; The smaller other root -1; The larger other root 2
By the factor theorem, is a factor exactly when :
Divide by (synthetic division, ): , then , and . The quotient is :
So , and the other roots are and .
11. Polynomials and factoring · More practice problems · ProblemFind all three roots of . One of them is a fraction.Smallest root -2; Middle root 1/2 ≈ 0.5; Largest root 3
Try divisors of 6: , , , and . So is a factor.
Synthetic division with on : , then , and .
For , look for two numbers with product and sum : and .
The roots are , and .
11. Polynomials and factoring · More practice problems · ProblemAn open box is made from a by sheet of card: cut a square of side from each corner and fold up the sides. Its volume is . Find the volume when , and write in standard form. 256 cm³; Leading coefficient of 4; Coefficient of -64; Coefficient of 240
At the box is high, on a base by :
For standard form, multiply the brackets, then the :
It is a cubic with leading coefficient . Only makes a real box, since the side needs .
12. Quadratic equations and parabolas · A quadratic draws a parabola · QuizWhich of these is a quadratic equation?B. Multiply out: is , degree 2. Hidden quadratics like this are common, so expand before you decide. has degree 3, and is not a polynomial at all, although multiplying by turns that one into (for ).
12. Quadratic equations and parabolas · Vertex form shows the turning point · QuizWhere is the vertex of , and does it open up or down?B. , opening downMatch it to : , so , and . The leading means , so it opens down and is the highest point. Reading is the classic slip: the sign inside the bracket is the opposite of the shift.
12. Quadratic equations and parabolas · Solving by factoring · Find the bugThis solution of finds only one of its two solutions. Which line loses the other?Line 2: x^2 - 5x = 0, so x(x - 5) = 0, and x = 0 or x = 5Dividing by is only allowed when , and is a solution: . Never divide by something that could be zero; move everything to one side and factor instead. Then gives both and .
12. Quadratic equations and parabolas · A square has two square roots · QuizSolve .B. or Divide by 3: . Then , so or . Answering only forgets the negative root. divides by 3 but then forgets the square root: means , not .
12. Quadratic equations and parabolas · Completing the square · Put in orderPut the steps for solving by completing the square in order.1. Move the constant across: 2. Halve the coefficient of and square it: 3. Add 16 to both sides: 4. Write the left as a square: 5. Take square roots, both signs: Adding to both sides keeps the equation true; adding it on one side only is the common slip. The half of is , so the square is , and the sign inside matches the sign of the term. If the leading coefficient is not 1, divide everything by it first.
12. Quadratic equations and parabolas · Completing the square · ProblemWrite in vertex form , then solve exactly. 5; -7; Smaller root 5 - sqrt(7) ≈ 2.35425; Larger root 5 + sqrt(7) ≈ 7.64575
Half the coefficient of is , and . Add it and take it away:
So and : the vertex is . To solve, set it to zero:
The roots are and .
12. Quadratic equations and parabolas · The quadratic formula, derived · Fill the blanksFinish the larger root, for .1: 4, 2: sqrt, 3: 2 * aThe part under the root is , so 4. The brackets around 2 * a matter: without them, x / 2 * a divides by 2 and then multiplies by , because / and * go left to right. That bracket bug gives right answers whenever , so tests with alone never catch it.
12. Quadratic equations and parabolas · Using the formula, step by step · Code challengeWrite solveQuadratic(a, b, c): the real roots of () in increasing order. Return two roots, one when , or none (an empty vector, {}).One solution:
Solution
1#include<cmath>2#include<vector>34std::vector<double>solveQuadratic(double a,double b,double c){5double d = b * b -4* a * c;6if(d <0)return{};7if(d ==0)return{-b /(2* a)};8double r1 =(-b - std::sqrt(d))/(2* a);9double r2 =(-b + std::sqrt(d))/(2* a);10if(r1 < r2)return{r1, r2};11return{r2, r1};12}
The discriminant decides how many roots there are before you take any square root; std::sqrt of a negative number is nan (“not a number”), not an error, so skipping the check returns {nan, nan}. When , the root is the smaller one, which is why the last lines put them in order. Comparing a double with == 0 is fine here because these inputs are exact; with measured data you would treat a tiny discriminant as zero.
12. Quadratic equations and parabolas · Using the formula, step by step · ProblemSolve with the quadratic formula. Give the discriminant, and the two roots exactly. 73; Smaller root (5 - sqrt(73))/6 ≈ −0.590667; Larger root (5 + sqrt(73))/6 ≈ 2.25733
Here , and . The discriminant first:
73 is not a perfect square, so the roots are irrational:
That is or . Check with Vieta: they add up to , which is .
12. Quadratic equations and parabolas · The discriminant counts the roots · QuizHow many real solutions does have?C. None, so none. Completing the square agrees: , which is at least 1 for every . A common slip is read as , or forgetting to square .
12. Quadratic equations and parabolas · When the textbook formula fails a computer · Code challengeThe starter uses the textbook formula. Rewrite stableRoots(a, b, c) with the stable version above, returning both roots in increasing order. Assume and ; take as 1. b >= 0 ? d : -d is d when b >= 0, and -d otherwise.One solution:
Solution
1#include<algorithm>2#include<cmath>3#include<vector>45std::vector<double>stableRoots(double a,double b,double c){6double d = std::sqrt(b * b -4* a * c);7double q =-(b +(b >=0? d :-d))/2;8double r1 = q / a;9double r2 = c / q;10return{std::min(r1, r2), std::max(r1, r2)};11}
Choosing the sign of to match makes a sum of two numbers with the same sign, so no digits cancel. The other root then comes from a division, , which is also safe. The tests multiply the small root by so that EXPECT_NEAR’s tolerance, , is relative to its size; comparing itself within that tolerance would pass almost anything. Library root finders do exactly this.
12. Quadratic equations and parabolas · The vertex answers biggest and smallest · QuizA ball thrown straight up at has height metres after seconds. What is its greatest height, to one decimal place?B. The vertex is at ; that is when, not how high. Put it back in: , or exactly . comes from dividing by instead of , mixing up the formula for the time with the one for the height.
12. Quadratic equations and parabolas · Practice problems · ProblemFor which positive number does have exactly one real solution? What is that solution? 6; -3
One real solution means a zero discriminant:
The positive one is . Then the equation is , a double root:
So , and the solution is , where the parabola touches the axis at its vertex.
12. Quadratic equations and parabolas · Practice problems · ProblemA rectangle is longer than it is wide, and its area is . Find its width and its length.Width 5 cm; Length 8 cm
With width , the length is , so:
So or . A width cannot be negative, so the second solution of the equation is not an answer to the problem.
The rectangle is wide and long. Check: .
12. Quadratic equations and parabolas · Practice problems · ProblemOne solution of is . Find and the other solution. -1; The other solution -5/2 ≈ −2.5
Put in:
The roots multiply to , so the other is . Factoring agrees:
So , and the other solution is .
12. Quadratic equations and parabolas · More practice problems · ProblemA ball is thrown upwards from above the ground. Its height after seconds is metres. When is it highest, how high is that, and when does it hit the ground?Time of the highest point 2 s; Greatest height 21.8 m; Time it hits the ground (20 + sqrt(436))/10 ≈ 4.08806 s
The parabola opens down (), so the vertex is the highest point:
It lands when . With , and :
That gives or . The negative time is before the throw, so the ball lands after about .
12. Quadratic equations and parabolas · More practice problems · ProblemA shop sells 200 mugs a week at 8 euros each. For every 1 euro it adds to the price, it sells 10 fewer mugs a week. Which price brings in the most money, and how much is that a week?Best price 14 euros; Weekly takings 1960 euros
Let the price rise by euros. Then the takings are:
The parabola opens down, so the maximum is at the vertex:
The best price is euros: 140 mugs, for 1960 euros a week. Rises of 5 and of 7 euros both give 1950, either side of the vertex.
13. Rational and radical expressions · A rational expression is a fraction of polynomials · QuizWhat is the domain of ?B. All except and Factor the denominator: , which is zero at and at . The tempting answer is “except ”, because cancels and leaves . But the domain belongs to the expression you were given: at the original divides by , which has no value. Cancelling never brings an excluded value back.
13. Rational and radical expressions · Simplify by cancelling factors, never terms · QuizWhich simplification is right?B. Only the second cancels a factor: , and the is multiplied on top and bottom. The first cancels a term (the is added, not multiplied). The third mixes up , which does not factor over the reals, with . The fourth cancels from a sum. A quick test catches all three: put in and see if both sides agree.
13. Rational and radical expressions · Simplify by cancelling factors, never terms · ProblemSimplify , and give the two values of it excludes.Simplified (x - 2)/(x + 3); The excluded value whose factor cancels 3; The other excluded value -3
Factor the top and the bottom, then cancel the common factor:
The original bottom, , is zero at and at . The factor cancelled, but stays excluded all the same.
The simplified form is , with and .
13. Rational and radical expressions · Excluded values are holes or walls · Code challengeFinish evalRational(num, den, x). Each polynomial is a list of coefficients, highest power first ({1, 0, -1} is ). Return its value at x, or std::nullopt where the denominator is zero: a std::optional<double> (from <optional>) holds a double or nothing, so return value; fills it and return std::nullopt; leaves it empty.One solution:
Solution
1#include<optional>2#include<vector>34doubleevalPoly(const std::vector<double>& coeffs,double x){5double value =0;6for(double c : coeffs) value = value * x + c;7return value;8}910std::optional<double>evalRational(const std::vector<double>& num,11const std::vector<double>& den,12double x){13double bottom =evalPoly(den, x);14if(bottom ==0)return std::nullopt;15returnevalPoly(num, x)/ bottom;16}
The loop is Horner’s method: start from 0 and, for each coefficient, multiply by and add it. For at that is . Check the denominator first: dividing a double by zero in C++ does not stop the program, it quietly gives inf or nan (“not a number”), so the excluded value would slip through as a number. (Dividing an int by zero is worse: it is undefined behaviour, and here it stops the program.) Note that gives std::nullopt even though the factor cancels: the expression as written has no value there.
13. Rational and radical expressions · Multiply and divide as you would fractions · QuizWhich values are excluded from ?C. , and Three things can go wrong. makes the first denominator zero; makes the second denominator zero; and makes the divisor equal to zero, and you cannot divide by zero. After flipping, the result is , which only shows and : has moved to the top, which is why it is easy to forget.
13. Rational and radical expressions · Add and subtract over a common denominator · QuizWhat is ?B. Over the top is . The usual slip gives : writing instead of , because the minus was only applied to the . The first option subtracts the tops, , without rewriting each fraction over the common denominator first, and the last subtracts tops and bottoms separately, which is never allowed.
13. Rational and radical expressions · Solve rational equations by clearing the denominators · Put in orderPut the steps for solving a rational equation in order.1. Factor every denominator 2. Write down the excluded values 3. Multiply both sides by the least common denominator 4. Solve the polynomial equation that is left 5. Throw out any answer that is an excluded valueYou need the factors to see both the excluded values and the common denominator, so factoring comes first. Write the excluded values down before multiplying: once the fractions are gone, nothing in the new equation reminds you of them. The check comes last, on every candidate.
13. Rational and radical expressions · Solve rational equations by clearing the denominators · Code challengeFinish checkSolutions(candidates, lhs, rhs): keep only the candidates where lhs(x) and rhs(x) are both finite numbers (std::isfinite) and differ by less than 1e-9. The two sides are functions passed in, as std::function<double(double)> (from <functional>): something you call with a double that returns a double. The tests write them in place as lambdas, [](double x) { return x + 1; }.One solution:
Solution
1#include<cmath>2#include<functional>3#include<vector>45std::vector<double>checkSolutions(6const std::vector<double>& candidates,7 std::function<double(double)> lhs,8 std::function<double(double)> rhs){9 std::vector<double> kept;10for(double x : candidates){11double l =lhs(x);12double r =rhs(x);13bool finite = std::isfinite(l)&& std::isfinite(r);14if(finite && std::abs(l - r)<1e-9) kept.push_back(x);15}16return kept;17}
At both sides divide by zero, and a double divided by zero is inf, not an error; inf - inf is nan, and nan < 1e-9 is false, but relying on that is fragile, so test std::isfinite first. Comparing with a tolerance instead of == matters for answers that are not whole numbers: floating-point arithmetic rounds, so a true solution can be off by a tiny amount.
13. Rational and radical expressions · Simplify radicals and rationalise the denominator · QuizWhich is in simplest form?A. Take out the largest square factor: , so . The second and fourth are equal to too, but still have square factors under the root (, ), so they are not finished. , which is far too big: is between and .
13. Rational and radical expressions · Radical equations: isolate, square, check · Find the bugThis solves by squaring, then tries to drop the extraneous roots. It still returns for , . Which line is wrong?Line 12: if (x + b >= 0) roots.push_back(x);Every root of the squared equation has , so checking never throws anything out. What squaring lost is the sign of the right side: a square root is never negative, so a real solution needs . For , , which a square root can never equal.
13. Rational and radical expressions · Radical equations: isolate, square, check · ProblemSolve . Squaring gives two candidates: which one is the solution, and which is extraneous?The solution 3; The extraneous candidate -1
Square both sides and solve the quadratic:
Check each in the original. At : , which matches. At : , but the right side is .
So is the solution, and is extraneous: it solves , which squaring mixed in.
13. Rational and radical expressions · Far from zero, the leading terms decide · QuizWhich line does approach as grows?B. The degrees are equal (2 and 2), so far out it is . Dividing top and bottom by shows why: , and both small fractions shrink to 0. reads only the top; is the rule for a top of lower degree.
13. Rational and radical expressions · Practice problems · ProblemWrite as one fraction over the common denominator . What is its numerator, and what is the expression’s value at ?Numerator x + 3; Value at 3/4 ≈ 0.75
The common denominator is . Rewrite each fraction over it:
The numerator is . At the fraction is , and the original agrees: .
13. Rational and radical expressions · Practice problems · ProblemSolve .Smaller solution 1/2 ≈ 0.5; Larger solution 3
Excluded: and . Multiply both sides by :
So or , and neither is excluded. Check : . Check : .
The solutions are and .
13. Rational and radical expressions · Practice problems · ProblemSolve . -1
Factor: , so and are excluded. Multiply both sides by :
is excluded: it makes two of the denominators zero. That leaves . Check: , and .
The only solution is .
13. Rational and radical expressions · Practice problems · ProblemFor , find the vertical asymptote, the horizontal asymptote, and the hole in the graph.Vertical asymptote 3; Horizontal asymptote 2; The hole’s -2; The hole’s 8/5 ≈ 1.6
Factor the top and the bottom:
The factor cancels: a hole at , at the height of the simplified form there, . The factor stays in the bottom: a vertical asymptote at .
The degrees are equal, so far out behaves like : the horizontal asymptote is .
So: a vertical asymptote , a horizontal asymptote , and a hole at .
13. Rational and radical expressions · More practice problems · ProblemRationalise the denominator of , and write the result as . 2; 2
Multiply the top and the bottom by the conjugate :
So it is : and .
13. Rational and radical expressions · More practice problems · ProblemTwo pipes together fill a tank in 4 hours. Alone, the larger pipe would fill it 6 hours faster than the smaller one. How long does each take alone?The smaller pipe 12 hours; The larger pipe 6 hours
Let the smaller pipe take hours, so the larger takes . In one hour they fill and of the tank, and together :
Multiply both sides by :
solves the equation but not the problem: the larger pipe would take hours. So : the smaller pipe takes 12 hours and the larger 6. Check: .
14. Exponentials and logarithms · Exponential growth multiplies by the same factor · QuizSavings grow by 3% each year. What is the growth factor ?B. Each year you keep all of last year’s money (the ) and gain 3% of it (the ): . Multiplying by would leave you with 3% of your money. is a 30% rise, a slip of one decimal place.
14. Exponentials and logarithms · The base decides growth or decay · QuizA car worth 20 000 euros loses 15% of its value each year. Which models its value after years?A. Losing 15% means keeping 85%, so each year multiplies by . Multiplying by would keep only 15%, a car worth 3000 euros after a year. is linear and loses almost nothing; is growth.
14. Exponentials and logarithms · Compound interest is exponential growth · Code challengeWrite compound(P, r, n, t): the amount after t years when P earns the yearly rate r (0.05 for 5%), compounded n times a year.One solution:
Solution
1#include<cmath>23doublecompound(double P,double r,double n,double t){4return P * std::pow(1+ r / n, n * t);5}
std::pow(base, exponent) makes the brackets plain: the base is all of 1 + r / n, the exponent all of n * t. The usual slip is 1 + std::pow(r / n, n * t), which raises only the interest to the power. And (1 + r / n) ^ (n * t) is no power at all: ^ is exclusive or, on whole numbers, so on doubles it does not even compile. Another slip is using the percentage, 5, as the rate: compounded yearly, each step would multiply by 6.
14. Exponentials and logarithms · Compound interest is exponential growth · ProblemYou put 2500 euros in an account paying 4% a year, compounded quarterly. How much is there after 6 years, and how much of that is interest?Amount 2500*1.01^24 ≈ 3174.34 euros; Interest earned 2500*1.01^24 - 2500 ≈ 674.337 euros
Here , , and , so each of the steps multiplies by :
The interest is what was added: euros.
14. Exponentials and logarithms · The number e is compounding without end · QuizAbout how much do 1000 euros become at 5% compounded continuously for 10 years?D. 1648.72. It is the most the 5% can give: yearly (1628.89) and monthly (1647.01) compounding are below it, and continuous is the limit they climb toward. 1500 is simple interest, 50 euros a year with no interest on interest.
14. Exponentials and logarithms · A logarithm asks which power · QuizWhat is ?B. Ask “3 to which power gives 81?”: , so . The tempting comes from dividing by ; a logarithm counts how many times you multiply, not what you get.
14. Exponentials and logarithms · The laws of logarithms come from the laws of exponents · QuizWhat is ?B. A difference of logs is the log of a quotient: . is the number inside, not its logarithm. subtracts inside the log, which is not a law, and the last option is the classic mix-up of with .
14. Exponentials and logarithms · Change of base: any logarithm from one you have · Fill the blanksIn C++, std::log (from <cmath>) is the natural logarithm. Finish logBase with the change-of-base rule.1: log, 2: b, 3: 3Divide by . Swapping them gives , the reciprocal. std::log10 and std::log2 exist too, and any base works on both top and bottom, as long as it is the same base. Printed in full, the answer can be a hair from 4, such as 4.000000000000001: floating-point rounding, not a mistake.
14. Exponentials and logarithms · Change of base: any logarithm from one you have · QuizWhat is , to three decimals?A. . It should be a bit less than 2, since is a bit more than 20: estimating first catches mistakes. is the ratio upside down, and is .
14. Exponentials and logarithms · Solve exponential equations by taking logarithms · Code challengeThe starter uses the rule of 72. Make doublingTime(r) exact: the number of years for an amount to double at the yearly rate r, compounded yearly.One solution:
Solve : . Use , the growth factor, not : std::log(0.05) is negative and gives a negative time. The rule of 72 works because and for small ; 72 is used instead of 69.3 because it divides by many rates evenly and corrects a little for the approximation. At 100% it is far off: 0.72 years instead of 1.
14. Exponentials and logarithms · Solve exponential equations by taking logarithms · ProblemSolve exactly, and to three significant figures.: 3; : ln(7)/ln(2) - 1 ≈ 1.80735
Divide by 5, then recognise the power:
For the second, take of both sides:
So , and . Check: .
14. Exponentials and logarithms · Half-life: decay measured in halvings · QuizWhat fraction of a sample is left after three half-lives?C. Each half-life halves what is left: . Decay multiplies, so the fractions do not shrink in equal steps: comes from dividing by , and from thinking a third goes each time.
14. Exponentials and logarithms · Half-life: decay measured in halvings · Code challengeWrite ageFromFraction(fraction, halfLife): how long ago a sample started decaying, if fraction of it is left now (0.25 for a quarter).One solution:
The number of half-lives is the number of halvings from 1 down to fraction, which is ; multiply by the half-life for the time. std::log2(fraction) alone is negative, a sign slip that gives a time in the future. With std::log you would need to divide by std::log(2) too: change of base. (1 / fraction is safe because fraction is a double; with two ints, 1 / 4 would be 0.)
14. Exponentials and logarithms · Log scales put huge ranges on one ruler · QuizA drink has pH 3 and water pH 5. How do their hydrogen ion concentrations compare?B. The drink has 100 times as muchpH 3 means and pH 5 means ; the ratio is . Two steps on a log scale are two factors of ten, not a difference of 2. The minus sign in the definition is why a lower pH means more acid.
14. Exponentials and logarithms · Practice problems · ProblemWithout a calculator, find and . 3; 2
A difference of logs is the log of the quotient:
For the second, move the 2 inside as a power, then combine:
The answers are , since , and , since .
14. Exponentials and logarithms · Practice problems · ProblemSolve . 2
Combine, then undo the logarithm:
is extraneous: has no value. Check : .
The solution is .
14. Exponentials and logarithms · Practice problems · ProblemA medicine has a half-life of 6 hours in the body. After a dose of 400 mg, how much is left after 15 hours, and how long until only 50 mg is left?Left after 15 hours 400*0.5^(15/6) ≈ 70.7107 mg; Time to fall to 50 mg 18 hours
With and , 15 hours is half-lives:
For 50 mg: , so three half-lives:
About 70.7 mg is left after 15 hours, and 50 mg after 18 hours.
14. Exponentials and logarithms · More practice problems · ProblemA town had 12 000 people in 2020 and 13 500 in 2025. If it grows exponentially, what is its yearly growth factor, and how many years after 2020 does it reach 20 000?Growth factor 1.125^(1/5) ≈ 1.02384; Years after 2020 5*ln(5/3)/ln(1.125) ≈ 21.685 years
Five years multiply the population by :
That is about 2.4% a year. Now solve for the time to reach 20 000:
Since , the fifth root never has to be rounded. The town reaches 20 000 about 21.7 years after 2020, during 2041.
14. Exponentials and logarithms · More practice problems · ProblemSound level is decibels. How many times more intense is a 70 dB sound than a 40 dB one? And if one speaker plays at 80 dB, what level do two identical speakers make together (twice the intensity)?Intensity ratio 1000; Two speakers 80 + 10*log(2) ≈ 83.0103 dB
30 dB more is three steps of 10 dB, each a factor of 10:
Two speakers give twice the intensity, and the product law splits the logarithm:
The 70 dB sound is 1000 times more intense, and two speakers make about 83 dB, not 160: doubling the intensity adds only about 3 dB.
15. Sequences, series and induction · A sequence is a list that follows a rule · QuizWhich explicit rule gives 3, 7, 11, 15, …?B. Check it on the first terms: , , . The terms go up by 4, so the rule has in it; the makes the first one land on 3. is the usual slip: it gives 7 first, because it forgets that starts at 1, not 0.
15. Sequences, series and induction · Arithmetic sequences add the same amount each time · QuizThe sequence 7, 12, 17, … has which term equal to 102?B. The 20thSolve : , so and . Answering 19 means stopping at ; the number of steps is one less than the index.
15. Sequences, series and induction · Geometric sequences multiply by the same amount · QuizWhat is the 5th term of 3, 6, 12, …?C. 48, so . Counting along works too: 3, 6, 12, 24, 48. 96 is , using instead of as the power; 30 is , multiplying by where the formula raises to a power.
15. Sequences, series and induction · Recursive rules build each term from the last · QuizWith and , what is ?C. 41Step by step: , , . A recursive rule has to be walked one term at a time; 14 is , one step short.
15. Sequences, series and induction · Recursive rules build each term from the last · Code challengeWrite arithmeticTerm(first, d, n) and geometricTerm(first, r, n): the -th term (counting from 1) of each kind of sequence.One solution:
Solution
1#include<cmath>23doublearithmeticTerm(double first,double d,int n){4return first +(n -1)* d;5}67doublegeometricTerm(double first,double r,int n){8return first * std::pow(r, n -1);9}
Both formulas use , the number of steps from the first term. Using n instead passes no test except by luck: it skips one term ahead. C++ has no power operator: std::pow(r, n - 1) raises r to the whole of n - 1. Writing r ^ (n - 1) is the classic slip, and on a double it does not even compile, because ^ is exclusive or, an operation on whole numbers.
15. Sequences, series and induction · Sigma notation writes a long sum in a line · Fill the blanksTurn into a loop.1: 1, 2: n, 3: k * kThe bottom of the sigma is where k starts, 1; the top is the last value it takes, so the test is k <= n, not k < n, which would leave out the last term. The term is added once per pass. sumOfSquares(4) is 30.
15. Sequences, series and induction · An arithmetic series is pairs that add to the same total · QuizWhat is ?B. 110There are 10 terms (20 ÷ 2), the first is 2 and the last 20, so . 220 forgets to halve: it counts each pair twice. Count the terms carefully: for with difference , .
15. Sequences, series and induction · An arithmetic series is pairs that add to the same total · Find the bugThis sums the first n terms of an arithmetic sequence, but arithmeticSum(3, 4, 10) gives 230 instead of 210. Which line is wrong?Line 2: double last = first + (n - 1) * d;The last of terms is : 3, 7, …, 39 for ten terms. With n * d the “last” term is 43, one past the end, and the sum comes out . Off-by-one errors live wherever you count steps between terms.
15. Sequences, series and induction · An arithmetic series is pairs that add to the same total · ProblemFind the sum .Number of terms 50; Sum 5250
Count the terms first: the last term is .
Then multiply the number of terms by the average of the first and the last:
There are 50 terms, and they add up to 5250.
15. Sequences, series and induction · A geometric series collapses when you multiply it by r · Code challengeWrite geometricSum(a, r, n): the sum of the first n terms of the geometric sequence that starts at a with ratio r. Remember the case .One solution:
Solution
1#include<cmath>23doublegeometricSum(double a,double r,int n){4if(r ==1)return a * n;5return a *(1- std::pow(r, n))/(1- r);6}
The formula is right for every except 1, where and the double division gives nan (, “not a number”) instead of stopping. Handle the special case first, as the derivation did. A formula with a division always deserves the question: what if the bottom is 0? (With ints it is worse: an integer division by zero is undefined behaviour, and here it stops the program.)
15. Sequences, series and induction · Some infinite sums have a finite total · QuizWhat is ?B. 9Each term is a third of the last, so , , and the sum is . 8 is the first two terms; the rest add up to the missing 1. The terms shrink fast enough because .
15. Sequences, series and induction · Some infinite sums have a finite total · ProblemWrite the recurring decimal as a fraction in lowest terms, by treating it as an infinite geometric series.Common ratio 1/100 ≈ 0.01; As a fraction 3/11 ≈ 0.272727
Split it into blocks of two digits:
That is a geometric series with and , and , so:
So . Check:
15. Sequences, series and induction · Induction proves a rule for every whole number · Put in orderPut the parts of a proof by induction in order.1. State the claim for every whole number 2. Base case: show is true 3. Inductive hypothesis: assume is true for some 4. Inductive step: use it to show is true 5. Conclude that holds for every You must know exactly what you are proving first, then the base case starts the chain. The hypothesis is only an assumption inside the step: you never assume what you want to prove for all . Skipping the base case is a classic error: a step can be valid while the statement is false everywhere (try “”).
15. Sequences, series and induction · Pascal’s triangle expands any power of a sum · QuizWhat is the coefficient of in ?D. 12The term is . Reading 3 straight off Pascal’s triangle forgets that the 2 in is squared too. The full expansion is .
15. Sequences, series and induction · Compute the triangle, row by row · Code challengeWrite choose(n, k): the binomial coefficient for whole numbers , as a long long. Pascal’s rule or the product both work.One solution:
Solution
1#include<vector>23longlongchoose(int n,int k){4 std::vector<longlong> row ={1};5for(int i =0; i < n; i++){6 std::vector<longlong> next ={1};7for(std::size_t j =1; j < row.size(); j++){8 next.push_back(row[j -1]+ row[j]);9}10 next.push_back(1);11 row = next;12}13return row[k];14}
Each pass turns row into row , so after passes row is row , and row[k] is . The symmetry says choosing to take is the same as choosing to leave. Computing directly works for small , but a long long overflows from , and in doubles the factorials are rounded from : comes out as 253.00000000000003 instead of 253. The product form works in whole numbers too, if each step multiplies before it divides: c * (n - i) / (i + 1) is always exact, while c * ((n - i) / (i + 1)) loses the fraction to integer division.
15. Sequences, series and induction · Practice problems · ProblemA geometric sequence has and . Find the common ratio, the first term and . 3; 4; 2916
From to is three steps of multiplying by :
One step back from : . Then:
So , and : the sequence is 4, 12, 36, 108, 324, 972, 2916.
15. Sequences, series and induction · Practice problems · ProblemFind . Then use to find . 590; 3775
Split and scale, as sums allow:
For the second, the sum up to 100 minus the sum up to 50:
The answers are and . The first is also an arithmetic series, , and agrees.
15. Sequences, series and induction · Practice problems · ProblemIn the expansion of , find the coefficient of and the coefficient of .Coefficient of 80; Coefficient of -40
With and , each term is . For , , so :
For , :
The coefficients are and .
15. Sequences, series and induction · More practice problems · ProblemA job pays 30 000 euros in its first year, with a 3% rise every year. What is the pay in year 10, and how much is earned over the first 10 years in all?Pay in year 10 30000*1.03^9 ≈ 39143.2 euros; Total over 10 years 30000*(1.03^10 - 1)/0.03 ≈ 343916 euros
Each year multiplies the pay by , so year 10 is 9 steps from year 1:
The total is the sum of the first 10 terms:
Year 10 pays about 39 143 euros, and the ten years together about 343 916 euros, against 300 000 with no rises.
15. Sequences, series and induction · More practice problems · ProblemA ball is dropped from 10 m. After each bounce it rises to 60% of the height it fell from. How high does it rise after the third bounce, and how far does it travel, up and down, before it comes to rest?Height after the third bounce 2.16 m; Total distance 40 m
Each rebound is 0.6 of the height before, so after the third bounce:
The ball falls 10 m, then goes up and down each rebound height. The rebounds form an infinite geometric series with and :
It rises 2.16 m after the third bounce, and travels 40 m in all: infinitely many bounces, but a finite distance.
16. Angles, triangles and trigonometry · An angle measures a turn · QuizTwo angles of a triangle are and . What is the third?B. The three add to : . In a right triangle the two other angles always add to , so each one fixes the other. 235 subtracts from , the full turn, which is the total around a point, not inside a triangle.
16. Angles, triangles and trigonometry · Radians measure an angle by the arc it cuts · QuizHow many radians is ?B. A quarter of a full turn is a quarter of : . A handy anchor: radians is , so is and is a half turn.
16. Angles, triangles and trigonometry · Radians measure an angle by the arc it cuts · Code challengeWrite toRadians(degrees) and toDegrees(radians). Use std::numbers::pi, from <numbers>, for .One solution:
Both are the same proportion, radians to , turned one way or the other. If you mix them up, toRadians(180) gives about 10313 instead of 3.14: a good habit is to check one value you know. C++’s std::sin and its friends in <cmath> take radians, which is why you need this.
16. Angles, triangles and trigonometry · In a right triangle, the angle fixes the ratios of the sides · QuizA right triangle has sides 3, 4 and 5. For the angle opposite the side of length 3, what is ?C. The hypotenuse is the longest side, 5; opposite is 3, so the adjacent is 4. . is and is ; is the tangent of the other acute angle, whose opposite and adjacent are swapped.
16. Angles, triangles and trigonometry · In a right triangle, the angle fixes the ratios of the sides · Fill the blanksFind the two short sides of a right triangle from its hypotenuse and an angle in radians.1: sin, 2: cos, 3: tanRearranging gives , here ; likewise . Their ratio is , about 0.577, which is why .
16. Angles, triangles and trigonometry · Solve a right triangle step by step · Find the bugheightOf(5, 70) should give about 4.70 but gives about 3.87. Which line is wrong?Line 2: double height = ladder * std::sin(angleDegrees * std::numbers::pi / 180);std::sin reads its argument as radians, so std::sin(70) is the sine of 70 radians, about 11 full turns plus a bit, which happens to be 0.774. Convert first. This is the most common trigonometry bug in code, and calculators set to the wrong mode make the same mistake on paper.
16. Angles, triangles and trigonometry · Solve a right triangle step by step · ProblemA kite flies on a straight string that makes with the ground. How high is the kite above the hand holding the string, and how far away is it horizontally?Height 30*sin(50*pi/180) ≈ 22.9813 m; Horizontal distance 30*cos(50*pi/180) ≈ 19.2836 m
The string is the hypotenuse. The height is opposite the angle, and the horizontal distance is adjacent to it:
Check with Pythagoras: .
The kite is about up and away.
16. Angles, triangles and trigonometry · The unit circle defines sine and cosine for any angle · QuizWhat is ?B. is short of a half turn, so the point is the mirror image of the point across the axis: . Its coordinate, the cosine, is . Getting the size right but the sign wrong is the usual slip: ask which quarter the angle is in.
16. Angles, triangles and trigonometry · Sine and cosine are waves; tangent repeats with gaps · QuizWhat is the period of ?B. The period is : doubling runs through the wave twice as fast. The 3 is the amplitude and doesn’t change the period. is the mistake of multiplying by instead of dividing.
16. Angles, triangles and trigonometry · Sine squared plus cosine squared is always 1 · QuizIf and is between and , what is ?B. , so . The identity only gives the size; the quarter gives the sign. Between and the point is left of the axis, so cosine is negative. comes from , forgetting to square.
16. Angles, triangles and trigonometry · The laws of sines and cosines solve any triangle · Code challengeWrite thirdSide(a, b, angleDegrees): the side across from the angle between sides a and b, by the law of cosines.One solution:
Solution
1#include<cmath>2#include<numbers>34doublethirdSide(double a,double b,double angleDegrees){5double C = angleDegrees * std::numbers::pi /180;6return std::sqrt(a * a + b * b -2* a * b * std::cos(C));7}
The starter is Pythagoras, right only at , where . The correction makes shorter for an acute angle and longer for an obtuse one, where cosine is negative. Remember to convert to radians before std::cos.
16. Angles, triangles and trigonometry · The laws of sines and cosines solve any triangle · Put in orderYou know sides , and the angle between them. Put the steps to find everything else in order.1. Find side with the law of cosines 2. Find the angle opposite the shorter of and with the law of sines 3. Find the last angle: the three add up to 4. Check: the longest side should face the largest angleThe law of sines needs a side with its opposite angle, so you need (opposite the known ) first. Take the angle opposite the shorter side next: it must be acute, so gives it without ambiguity, while the larger one might be obtuse. The last angle comes free.
16. Angles, triangles and trigonometry · The laws of sines and cosines solve any triangle · ProblemA triangle has angles and , and the side opposite is . Find the third angle and the other two sides. 75 °; 8*sin(65*pi/180)/sin(40*pi/180) ≈ 11.2797 cm; 8*sin(75*pi/180)/sin(40*pi/180) ≈ 12.0217 cm
The angles add up to : .
Each side over the sine of its opposite angle is the same number, :
Check: the longest side, , faces the largest angle, .
16. Angles, triangles and trigonometry · Inverse functions turn a ratio back into an angle · QuizWhat is ?B. , and is the angle in with that sine: . The inverse undoes the function only on its chosen stretch, so only when is in it.
16. Angles, triangles and trigonometry · Inverse functions turn a ratio back into an angle · Code challengeWrite angleOf(x, y): the angle in degrees, from 0 up to (not including) 360, from the positive axis to the point . std::atan2(y, x) gives an angle in radians between and that knows the quarter.One solution:
The starter’s can’t tell from : both have , and it answers for both. std::atan2 looks at the signs of x and y separately, so it knows the quarter. It answers between and ; adding 360 to negative answers moves them into the range asked for.
16. Angles, triangles and trigonometry · Practice problems · ProblemFind the exact values of , and .-1/2 ≈ −0.5; -sqrt(2)/2 ≈ −0.707107; sqrt(3) ≈ 1.73205
is past a half turn, in the third quarter, where the point is below the axis: .
is , short of a half turn, in the second quarter, left of the axis: .
So the values are , and .
16. Angles, triangles and trigonometry · Practice problems · ProblemAn angle lies between and , and . Find , and exactly.-12/13 ≈ −0.923077; 12/5 ≈ 2.4; 120/169 ≈ 0.710059
From the Pythagorean identity:
Between and the point is below the axis, so . Then:
So , (positive, since sine and cosine are both negative) and .
16. Angles, triangles and trigonometry · Practice problems · ProblemFor , with in radians, find the amplitude, the period, and the smallest positive where is at its maximum.Amplitude 3; Period pi/2 ≈ 1.5708; First maximum at pi/8 ≈ 0.392699
In , is the amplitude, and with :
Sine is largest, 1, first at , so first where:
Amplitude 3, period , and the first maximum at , a quarter of the way through the first period.
16. Angles, triangles and trigonometry · More practice problems · ProblemA ramp rises over a horizontal distance of . What angle does it make with the ground, in degrees, and how long is the ramp?Angle atan(1.2/5)*180/pi ≈ 13.4957 °; Length sqrt(26.44) ≈ 5.14198 m
The rise is opposite the angle and the run is adjacent, so use the tangent and its inverse:
The ramp itself is the hypotenuse:
The ramp makes about with the ground and is about long. Check: .
16. Angles, triangles and trigonometry · More practice problems · ProblemFind every angle from up to with , in degrees.Smaller angle asin(0.6)*180/pi ≈ 36.8699 °; Larger angle 180 - asin(0.6)*180/pi ≈ 143.13 °
The inverse function gives one angle:
The point at is its mirror image across the axis, at the same height, so it has the same sine:
Sine is negative from to , so there are no more. The angles are about and .
16. Angles, triangles and trigonometry · More practice problems · ProblemTwo straight paths leave a point at an angle of to each other. One is long and the other . How far apart are their ends, and what angle does the straight line between the ends make with the path?Distance between the ends sqrt(89 - 80*cos(110*pi/180)) ≈ 10.7871 km; Angle asin(8*sin(110*pi/180)/sqrt(89 - 80*cos(110*pi/180)))*180/pi ≈ 44.1789 °
The law of cosines, with , and , where :
The angle at the end of the path faces the path. By the law of sines:
cannot be obtuse, since the triangle already has a angle, so gives it directly. The ends are about apart, and the angle is about .
17. Complex numbers · Adding and multiplying work as you expect · QuizWhat is ?C. , so . A tempting slip is to think of as “ten times ” or to stop the cycle at 3; write out to once and reduce the exponent modulo 4.
17. Complex numbers · The conjugate makes division possible · Fill the blanksA complex number in code is a struct C holding two doubles, its real part re and its imaginary part im; C{a, b} makes . Finish divide(z, w), which works out . With and , .1: +, 2: +, 3: -The bottom is , a sum of squares, so it is a plus (a minus would be the classic mistake of treating as ). The top is : the real part gains a plus because , and the imaginary part is , the cross terms with the conjugate’s minus sign.
17. Complex numbers · The conjugate makes division possible · ProblemWrite in the form .7/13 ≈ 0.538462; 17/13 ≈ 1.30769
Multiply the top and the bottom by :
So and . Check by multiplying back: , and .
17. Complex numbers · Size and direction: modulus and argument · QuizWhat is the principal argument of ?D. The point is in the third quadrant, below the real axis, so the angle is negative and past a right angle: , or . is the trap: dividing by throws away both signs. Always look at the quadrant.
17. Complex numbers · Size and direction: modulus and argument · Find the bugThis gives the wrong argument for . Which line is wrong?Line 8: return std::atan2(z.im, z.re);std::atan(im / re) only answers between and , so every point left of the imaginary axis gets the angle of its opposite point, and re = 0 divides by zero (an infinity, or nan at 0 itself). std::atan2(y, x) takes the two parts separately, sees both signs, and returns the angle in . std::hypot is right: it is , computed without overflowing for huge parts.
17. Complex numbers · Size and direction: modulus and argument · ProblemFind the modulus and the principal argument, in radians, of . 2; 5*pi/6 ≈ 2.61799
The point is left of the imaginary axis and above the real one: the second quadrant. Its angle with the negative real axis has tangent , which is the tangent of , so:
Check: and . So and .
17. Complex numbers · Multiplying multiplies sizes and adds angles · QuizWhat is , and what happened to the point ?A. : turned a quarter turn anticlockwise. Its modulus is still 5 (since ) and its argument is more, so it is the same arrow turned 90° anticlockwise. Forgetting that gives , which is a reflection, not a rotation.
17. Complex numbers · Try it: complex arithmetic in code · Code challengeFinish multiply(z, w), which returns the product of two complex numbers, and modulus(z), which returns its distance from 0.One solution:
The starter multiplies part by part, which is how you add, not multiply: it forgets the cross terms and , and that . The last test checks a fact from the previous slide, , which the starter fails. Doubles are compared with EXPECT_NEAR, since square roots are rarely exact. With std::complex<double> the same product is just z * w, and the modulus std::abs(z).
17. Complex numbers · Powers, roots and the roots of unity · Put in orderPut the steps for solving in order.1. Write in polar form: 2. Take the real cube root of the modulus: 3. Divide the argument by 3: 4. Add twice for the other angles: and 5. Convert back: , and Polar form first, because powers are easy there: cubing cubes the modulus and triples the angle, so the cube root takes the cube root of 8 and a third of the angle. A third of gives three different angles, apart; stopping after the first root is the usual mistake. Check one: .
17. Complex numbers · Powers, roots and the roots of unity · Code challengeFinish rootsOfUnity(n): return the solutions of as a vector of C{re, im}, for to in order, where root has angle .One solution:
Solution
1#include<cmath>2#include<numbers>3#include<vector>45structC{double re;double im;};67std::vector<C>rootsOfUnity(int n){8 std::vector<C> roots;9for(int k =0; k < n; k++){10double angle =2* std::numbers::pi * k / n;11 roots.push_back(C{std::cos(angle), std::sin(angle)});12}13return roots;14}
Each root is . The loop stops at : would be angle , the root 1 again. The last test is a lovely fact: the roots sit symmetrically round 0, so they balance and their sum is 0 for any . Note std::cos(std::numbers::pi / 2) is about , not 0, which is why the tests use EXPECT_NEAR.
17. Complex numbers · Every polynomial has all its roots in the complex numbers · QuizA cubic with real coefficients has roots and . What is its third root?B. Real coefficients force the conjugate of to be a root too, and a cubic has exactly three roots, so the third is . is the negative, not the conjugate: the conjugate keeps the real part and flips only the sign of the imaginary part.
17. Complex numbers · Every polynomial has all its roots in the complex numbers · QuizHow many complex roots, counted with multiplicity, does have?B. Exactly 5Degree 5, so exactly 5 roots in , counted with multiplicity. Some may be real; since the coefficients are real and 5 is odd, at least one is. The theorem says the roots exist; it does not give a formula, and for degree 5 and above there is no general formula with roots, which is a theorem of Galois theory.
17. Complex numbers · Practice problems · ProblemLet and . Find , and the modulus of . 11; 10; 13
For , either expand, , so ; or use that moduli multiply:
So and .
17. Complex numbers · Practice problems · ProblemSolve . Give the real part of the roots, the positive imaginary part, and the product of the two roots.Real part -2; Positive imaginary part 3; Product of the roots 13
Use the quadratic formula; the discriminant is :
The roots are the conjugates and . Their product is , which is , as Vieta’s formulas say.
Real part , imaginary parts , and product .
17. Complex numbers · Practice problems · ProblemUse polar form to find , and the imaginary part of . 16; -8
In polar form, . By de Moivre’s theorem:
So , and , whose imaginary part is . Check the first another way: , and .
17. Complex numbers · More practice problems · ProblemFind the three cube roots of : give the real one, and the one in the first quadrant as .The real root -2; First-quadrant root: 1; First-quadrant root: sqrt(3) ≈ 1.73205
Write in polar form, . A cube root has modulus and a third of the angle, ; the others are further round:
Convert back to :
The real root is and the first-quadrant root is . Check: , and multiplying by again gives .
17. Complex numbers · More practice problems · ProblemIn a game, a sprite at the point is turned anticlockwise about the origin. Use complex multiplication to find where it lands.New 2 - sqrt(3)/2 ≈ 1.13397; New 2*sqrt(3) + 1/2 ≈ 3.9641
Turning by is multiplying by , whose modulus is 1, so the distance from the origin does not change:
The sprite lands at about . Check: its distance from the origin is still .
18. Vectors and matrices · Adding vectors goes tip to tail · QuizWhat is ?A. Scale first: . Then subtract component by component: . comes from adding the 1 instead of subtracting it; subtracting a vector subtracts every component.
18. Vectors and matrices · The length of a vector comes from Pythagoras · Fill the blanksFinish unit(v), which returns the vector in the same direction with length 1, for any number of components.1: x, 2: sqrt, 3: /The first loop adds up the squares of the components; the square root of that sum is the length. Dividing every component by the length scales the vector to length 1 without turning it. The zero vector has length 0 and no direction, so it has no unit vector: here 0.0 / 0 would give nans (“not a number”), and real code should check for it.
18. Vectors and matrices · The dot product measures how much two vectors agree · QuizWhich vector is perpendicular to ?B. , so the angle is 90°. In the plane, swapping the components and negating one always gives a perpendicular vector. only swaps them (dot product 12), and points exactly the opposite way (dot product , angle 180°).
18. Vectors and matrices · The dot product measures how much two vectors agree · ProblemFind the dot product of and , and the angle between them in degrees. 9; Angle 45 °
The dot product is 9, and the vectors are apart.
18. Vectors and matrices · Try it: the angle between two vectors · Code challengeFinish dot(u, v) and angleBetween(u, v), which returns the angle between two non-zero vectors in degrees. They work for any number of components. (using Vec = std::vector<double>; gives the type a short name.)One solution:
Solution
1#include<algorithm>2#include<cmath>3#include<numbers>4#include<vector>56usingVec= std::vector<double>;78doubledot(constVec& u,constVec& v){9double s =0;10for(std::size_t i =0; i < u.size(); i++) s += u[i]* v[i];11return s;12}1314doubleangleBetween(constVec& u,constVec& v){15double c =dot(u, v)/ std::sqrt(dot(u, u)*dot(v, v));16double clamped = std::clamp(c,-1.0,1.0);17return std::acos(clamped)*180/ std::numbers::pi;18}
dot(u, u) is the length squared, so std::sqrt(dot(u, u) * dot(v, v)) is the two lengths multiplied. The clamp matters: for parallel vectors rounding can make the cosine 1.0000000000000002, and std::acos of anything above 1 is nan; std::clamp(c, -1.0, 1.0), from <algorithm>, keeps it within . Forgetting to convert from radians, which std::acos returns, gives 1.5708 instead of 90.
18. Vectors and matrices · A matrix is a grid of numbers · QuizIn above, what is ?B. Row 2, column 1: the first number of the second row, 3. is the trap: the first index is always the row. “Rows first” holds for sizes too: is 2 rows, 3 columns.
18. Vectors and matrices · Matrix multiplication is rows times columns · Quiz is and is . Which is true?A. is , and is not defined: the inner 3s match, the outer sizes give . is : the inner sizes 4 and 2 differ, so the rows of (length 4) can’t be dotted with the columns of (length 2).
18. Vectors and matrices · Matrix multiplication is rows times columns · Code challengeFinish matMul(a, b): the product of an and an matrix, as a vector of rows. Entry [i][j] is row i of a dotted with column j of b.One solution:
Solution
1#include<vector>23usingMatrix= std::vector<std::vector<double>>;45MatrixmatMul(constMatrix& a,constMatrix& b){6Matrix result;7for(std::size_t i =0; i < a.size(); i++){8 std::vector<double> row;9for(std::size_t j =0; j < b[0].size(); j++){10double sum =0;11for(std::size_t k =0; k < b.size(); k++)12 sum += a[i][k]* b[k][j];13 row.push_back(sum);14}15 result.push_back(row);16}17return result;18}
Three loops: i over the rows of a, j over the columns of b (b[0].size()), and k along the shared size (b.size(), which equals a[0].size()) for the dot product. The result is a.size() by b[0].size(), the outer sizes. For : . (The tests can compare whole matrices exactly because every entry here is a small whole number, which a double holds exactly.)
18. Vectors and matrices · Matrix multiplication is rows times columns · Find the bugmatVec(a, v) should multiply a matrix by a column vector, but gives wrong answers for a matrix. Which line is wrong?Line 8: for (std::size_t k = 0; k < v.size(); k++) sum += row[k] * v[k];The dot product runs along a row, which has as many entries as there are columns (v.size(), or row.size()), not as many as there are rows (a.size()). For a square matrix the two are equal, which is why the bug hides until a non-square one comes along: here it stops after 2 of the 3 terms and gives a wrong answer, and for a tall matrix it reads past the end of each row. In C++ row[k] past the end is undefined behaviour: it may read whatever memory is there (here, the library’s checks stop the program instead).
18. Vectors and matrices · Matrix multiplication is rows times columns · ProblemMultiply by . Give each entry of .Row 1, column 1 4; Row 1, column 2 7; Row 2, column 1 -6; Row 2, column 2 3
Each entry is a row of dotted with a column of :
So has rows and .
18. Vectors and matrices · The identity matrix and the transpose · Quiz is . What size is , and is it symmetric?A. , and symmetric is , and is . It is always symmetric: . would be the one. Matrices like appear wherever data is fitted by least squares.
18. Vectors and matrices · A matrix moves every point of the plane · QuizWhat does do to the plane?A. Rotates it a quarter turn anticlockwiseRead the columns: goes to and goes to . Both turned 90° anticlockwise: it is the rotation matrix with , and the same as multiplying by in the complex plane. Swapping and (a reflection in ) is , with no minus sign.
18. Vectors and matrices · A system of equations is one matrix equation · QuizRead by columns. With , , which is true?A. is times the first column plus times the second: . So solving the system asks “which mix of the columns makes ?”, the column picture, while the plot above is the row picture, one line per equation. Both describe the same solution.
18. Vectors and matrices · Gaussian elimination solves any system step by step · Put in orderPut the steps of Gaussian elimination in order.1. Write the system as an augmented matrix 2. Pick a non-zero pivot in the first column, swapping rows if needed 3. Subtract multiples of the pivot row to make zeros below the pivot 4. Repeat for each next column until the matrix is triangular 5. Solve the last row, then substitute upwardsEverything happens on the augmented matrix, so the right-hand side changes along with the rows. Each column needs a non-zero pivot first, since you divide by it; a 0 there is fixed by swapping in a lower row. Back substitution only works once the triangle is complete, so it comes last. If a whole row becomes with , there is no solution; if it becomes , there are infinitely many.
18. Vectors and matrices · Try it: solve a system by elimination · Code challengeFinish solve(a, b), which solves for a square system with one solution. Forward elimination is written, with pivoting; write the back substitution: for each row from the last up, , where m[i][n] is the right-hand side.One solution:
Solution
1#include<cmath>2#include<utility>3#include<vector>45usingVec= std::vector<double>;6usingMatrix= std::vector<Vec>;78Vecsolve(constMatrix& a,constVec& b){9int n = b.size();10Matrix m = a; // a copy, with b as an extra column11for(int i =0; i < n; i++) m[i].push_back(b[i]);12for(int col =0; col < n; col++){13int p = col;14for(int r = col +1; r < n; r++)15if(std::abs(m[r][col])> std::abs(m[p][col])) p = r;16 std::swap(m[col], m[p]);17for(int r = col +1; r < n; r++){18double f = m[r][col]/ m[col][col];19for(int c = col; c <= n; c++) m[r][c]-= f * m[col][c];20}21}22Vecx(n,0.0); // n zeros23for(int i = n -1; i >=0; i--){24double s = m[i][n];25for(int j = i +1; j < n; j++) s -= m[i][j]* x[j];26 x[i]= s / m[i][i];27}28return x;29}
After elimination the matrix is upper triangular, so the last row has one unknown: . Each row above has one new unknown once the ones below are known: subtract their terms from the right-hand side and divide by the diagonal entry. The loop must run from the bottom up; going top down uses values of x that are still 0. Counting down is why i is an int: a std::size_t can’t go below 0, so i >= 0 would always be true. The third test only passes because of the row swap: without it the first pivot is 0, a double divided by 0 is infinite, and everything becomes nan.
18. Vectors and matrices · Practice problems · ProblemFind the length of , and the vector of length 5 that points the same way. 10; Its first component 3; Its second component -4
The unit vector is . Scale it to length 5:
Its length is , as it should be. The vector is , half of .
18. Vectors and matrices · Practice problems · ProblemFor which is perpendicular to ? And for which is it parallel to ?Perpendicular: 9/2 ≈ 4.5; Parallel: -2
Perpendicular: the dot product is zero.
Parallel: . The second components give , so , and then .
So for perpendicular, and for parallel: is .
18. Vectors and matrices · Practice problems · ProblemSolve by Gaussian elimination: , and . 3; -1; 2
Write the augmented matrix and clear the first column:
Swap the last two rows, so the pivot is 1, then clear below it:
Back substitution: , then , then .
Check in the second equation: . The solution is , , .
18. Vectors and matrices · More practice problems · ProblemThe point is turned anticlockwise about the origin, then reflected in the axis. Where does it end up? And where would it end up with the two moves done the other way round?Turn, then reflect: -1; Turn, then reflect: -3; Reflect, then turn: 1; Reflect, then turn: 3
Turn first, then reflect, , one step at a time:
The other way round, :
So one way and the other: . In fact , the reflection in the line .
18. Vectors and matrices · More practice problems · ProblemA café sells coffee at 3 euros, tea at 2 euros and cake at 4 euros. On Monday it sells 20 coffees, 15 teas and 10 cakes; on Tuesday 25, 10 and 12. Put the sales in a matrix , one row per day, and the prices in a vector . What is ?Monday’s takings 130 euros; Tuesday’s takings 143 euros
A matrix times a vector is : one total per day. Monday took 130 euros and Tuesday 143 euros.
19. Linear maps, determinants and eigenvectors · Mixing vectors: combinations and span · QuizWhat is the span of the single vector in the plane?B. The line through the origin in the direction With one vector you can only scale it: , every point of the line as runs over all numbers, including , the origin. A span always passes through the origin, so cannot be one. To fill the plane you need a second vector off that line.
19. Linear maps, determinants and eigenvectors · Independent vectors add something new · QuizWhich set of vectors is linearly dependent?C. , and Three vectors in the plane are always dependent: the plane has room for only two independent directions. Here . The first two pairs point in different directions, so each pair is independent, and a single nonzero vector is independent on its own. and look alike, but neither is a multiple of the other.
19. Linear maps, determinants and eigenvectors · A basis is a coordinate system · QuizWhat are the coordinates of in the basis , ?B. Solve and : adding gives , so and . Check: . The answer is the coordinates in the usual basis, not this one: the same point has different coordinates in different bases.
19. Linear maps, determinants and eigenvectors · A linear map keeps lines straight and the origin still · QuizWhich of these maps of the plane is linear?C. Each output of a linear map is a fixed mix of and , with no constants and no products: has matrix with rows and . Adding 1 moves the origin (), and a linear map always sends to . Squares and products break : doubling quadruples .
19. Linear maps, determinants and eigenvectors · A linear map keeps lines straight and the origin still · Fill the blanksA linear map sends to and to . Fill in where it sends any .1: 2, 2: -1, 3: 1, 4: 3The first output is times the first coordinate of plus times the first coordinate of : . The second is . The matrix has the images as columns, then , so reading it row by row gives these two lines. Putting the images in rows instead is the usual slip; it gives the transpose, a different map. (A std::pair, from <utility>, holds the two outputs together.)
19. Linear maps, determinants and eigenvectors · The determinant is how much area scales · ProblemA linear map has matrix . By what factor does it scale areas, and what area does a shape of area have after it? What is the area of the triangle with corners , and ?Area factor 11; Area of the image 27.5; Area of the triangle 11/2 ≈ 5.5
Every area is multiplied by 11, so a shape of area 2.5 becomes one of area .
The columns and are the sides of a parallelogram of area 11, and the triangle with corners , and is half of it, cut along a diagonal:
The factor is 11 (positive, so the orientation is kept), the image has area 27.5, and the triangle has area 5.5.
19. Linear maps, determinants and eigenvectors · Try it: a three by three determinant · Code challengeFinish det3(m): the determinant of a 3×3 matrix given as a vector of rows, m[row][column].One solution:
Solution
1#include<vector>23usingMatrix= std::vector<std::vector<double>>;45doubledet3(constMatrix& m){6double a = m[0][0], b = m[0][1], c = m[0][2];7double d = m[1][0], e = m[1][1], f = m[1][2];8double g = m[2][0], h = m[2][1], i = m[2][2];9return a *(e * i - f * h)- b *(d * i - f * g)+10 c *(d * h - e * g);11}
For the general matrix: . The usual mistake is the middle sign: the second term is subtracted, because the signs follow a checkerboard . The matrix with rows gives 0 because its third row is twice the second minus the first, so the rows are dependent and the box is flat.
19. Linear maps, determinants and eigenvectors · An inverse undoes the map · Find the bugThis inverse gives a matrix that does not undo . Which line is wrong?Line 7: {-c / det, a / det},Both off-diagonal entries are negated, and . With left positive, has a nonzero entry below the diagonal. Line 4 is right (a std::optional holds a value or none, std::nullopt): with doubles you might prefer std::abs(det) < 1e-12, because a matrix that is nearly singular gives a huge, unreliable inverse.
19. Linear maps, determinants and eigenvectors · Eigenvectors keep their direction · QuizFor with rows and , is an eigenvector, and with which eigenvalue?C. Yes, with Multiply: , the same vector, so . Checking an eigenvector is always this easy: multiply and see whether the answer is a multiple of what went in. belongs to , since .
19. Linear maps, determinants and eigenvectors · Finding eigenvalues with a determinant · QuizWhat are the eigenvalues of the matrix with rows and ?B. and , with roots and . For a triangular matrix the eigenvalues are always the diagonal entries. and are the trace and the determinant, the sum and product of the eigenvalues, not the eigenvalues themselves.
19. Linear maps, determinants and eigenvectors · Finding eigenvalues with a determinant · ProblemFind the eigenvalues of , and an eigenvector for each, written as .Smaller eigenvalue 2; Its eigenvector: -2; Larger eigenvalue 5; Its eigenvector: 1
So or . Check: they add up to , the trace, and multiply to , the determinant .
For , has first row , so and . For , the first row is , so and .
Eigenvalue 2 goes with , and eigenvalue 5 with .
19. Linear maps, determinants and eigenvectors · Diagonalising: the matrix in its own basis · Put in orderPut the steps of diagonalising a matrix in order.1. Write the characteristic polynomial 2. Find its roots, the eigenvalues 3. For each eigenvalue, solve for an eigenvector 4. Put the eigenvectors as the columns of and the eigenvalues on the diagonal of 5. Check , then write Eigenvalues come first, because each eigenvector is found from its eigenvalue. The order inside and must match: the -th column of goes with the -th diagonal entry of . Checking avoids computing an inverse, and it is the equation for all columns at once.
19. Linear maps, determinants and eigenvectors · Try it: run a Markov chain · Code challengeFinish runChain(m, x, steps): apply the matrix m (a vector of rows) to the vector x, steps times, and return the result. One step is y[i] = Σ m[i][j] * x[j].One solution:
Solution
1#include<vector>23usingVec= std::vector<double>;4usingMatrix= std::vector<Vec>;56VecrunChain(constMatrix& m,Vec x,int steps){7for(int k =0; k < steps; k++){8Vecy(x.size(),0.0); // the next vector, all zeros9for(std::size_t i =0; i < m.size(); i++)10for(std::size_t j =0; j < x.size(); j++)11 y[i]+= m[i][j]* x[j];12 x = y;13}14return x;15}
Each step is a matrix times a vector: entry of the result is row of m dotted with the current vector. The gap to the steady state shrinks by a factor 0.4 each step, so after 60 steps it is about . A common slip is updating x in place while still reading it: the second entry would then use the new first entry. Building a new vector y each step avoids that. (x is taken by value, without const &: the function gets its own copy, free to change.)
19. Linear maps, determinants and eigenvectors · Practice problems · ProblemFind the inverse of , and use it to solve , . 1; 3; -1
The system is , so:
Check: and . So and .
19. Linear maps, determinants and eigenvectors · Practice problems · ProblemFor which does have no inverse? And what is the determinant of ? 4; The determinant 13
With the columns and are dependent, the second twice the first, so the map squashes the plane onto a line.
Expand the along its first row:
So , and the determinant is 13.
19. Linear maps, determinants and eigenvectors · Practice problems · ProblemWhat are the coordinates of the point in the basis , ?Amount of 2; Amount of 3
From the first, . Then , so and .
Check: . The coordinates are .
19. Linear maps, determinants and eigenvectors · More practice problems · ProblemA car-hire firm has 700 cars and two offices, A and B. Each day, of the cars at A, 70% end up back at A and 30% at B; of the cars at B, 40% end up at A and 60% at B. If all 700 start at A, how many are at A after one day? In the long run, how many are at A, and what is the other eigenvalue of the matrix?At A after one day 490; At A in the long run 400; The other eigenvalue 0.3
Each column of holds where one office’s cars go. After one day:
The steady state is the eigenvector for eigenvalue 1: , so and . With , :
The eigenvalues add up to the trace, , and one of them is 1, so the other is : each day the gap to the steady state shrinks to 30% of what it was.
So 490 cars are at A after a day, 400 in the long run, and the other eigenvalue is .
19. Linear maps, determinants and eigenvectors · More practice problems · ProblemFor , diagonalising gave . Use it to find the entries of , and the largest eigenvalue of .Top-left entry of 122; Top-right entry of 121; Largest eigenvalue of 243
With and :
Check one entry the long way: has rows and , has top row , and the top-left entry of is .
The eigenvalues of are the diagonal of : and . So has rows and , and its largest eigenvalue is 243.
20. Abstract algebra and thinking like a mathematician · A proof covers every case at once · QuizYou check that is prime for . What have you shown about all whole numbers ?C. Nothing yet: examples can suggest a rule but not prove itThis formula really is prime for up to , which looks convincing, and yet at it gives . Forty examples did not prove it, because no number of examples can. One counterexample, on the other hand, is enough to disprove a claim about all .
20. Abstract algebra and thinking like a mathematician · Proving the other way round, and by contradiction · Fill the blanksProve "if is even, then is even" through its contrapositive.1: odd, 2: odd, 3: 2k² + 2kNot even is odd, for integers, so the contrapositive turns both halves around: odd gives odd . That direction is easy, because "odd" hands you a formula, , to square. is twice an integer plus one, so it is odd. Proving the claim head on would mean starting from " is even", which says little about directly.
20. Abstract algebra and thinking like a mathematician · Proving the other way round, and by contradiction · Put in orderPut the classic proof that is irrational in order.1. Suppose , a fraction in lowest terms 2. Square both sides: 3. So is even, hence is even: write 4. Then , so and is even too 5. Both and even contradicts lowest terms, so is irrationalThe assumption comes first, and "lowest terms" is the part that will break. " even, so even" is the claim you just proved by contrapositive: proofs build on proofs. The contradiction is that 2 divides both and , which lowest terms forbid, so no such fraction exists.
20. Abstract algebra and thinking like a mathematician · Sets and maps: the words every structure uses · QuizWhich describes as a map from to ?D. Neither injective nor surjectiveNot injective: . Not surjective: no real number squares to . The same formula from to is a bijection, with inverse . A map is the formula and its sets, which is exactly why inverses in earlier modules needed a restricted domain.
20. Abstract algebra and thinking like a mathematician · Modular arithmetic: numbers on a clock · QuizWhat is ? Try it without working out .B. , so powers of 2 repeat every 3. , so . Check: . Finding a power that is 1 and splitting the exponent is the trick behind fast modular arithmetic.
20. Abstract algebra and thinking like a mathematician · Modular arithmetic: numbers on a clock · ProblemFind the last digit of , and .Last digit of 9; 4
The last digit is the number mod 10. Powers of 7 mod 10 run and then repeat, since :
For the second, , and :
The last digit of is 9, and , the same as in the list of powers above.
20. Abstract algebra and thinking like a mathematician · Try it: fast powers modulo n · Code challengeFinish modPow(base, exp, mod): return base to the power exp, modulo mod, by square and multiply. exp is a whole number, mod is at least 2 and below 10 000 000.One solution:
Solution
1longlongmodPow(longlong base,longlong exp,longlong mod){2longlong result =1;3longlong square = base % mod;4longlong e = exp;5while(e >0){6if(e %2==1) result = result * square % mod;7 square = square * square % mod;8 e = e /2;9}10return result;11}
Writing in binary, is the product of the for the bits that are 1, and square holds at step ; e / 2 on whole numbers drops the bit just used. Reducing after each multiplication keeps every number below , here under , which a long long holds exactly (up to about ; an int stops at about , which is why it is not used here). Computing the whole power first and reducing at the end fails: overflows a long long, which in C++ is undefined behaviour (in practice, a wrong number), and std::pow gives a double that keeps only about 16 digits, long before the %.
20. Abstract algebra and thinking like a mathematician · A group: one operation, four rules · QuizWhich of these is a group?C. under is closed (, , …), has identity 1, and every element has an inverse in the set (): it is the fourth roots of unity from the complex numbers module. The whole numbers have no to undo ; the integers under have no inverse for 2; and among the reals, 0 has no inverse under .
20. Abstract algebra and thinking like a mathematician · Symmetries form groups, and order matters · Code challengeFinish compose(p, q): the permutation "first q, then p", so element i goes to p[q[i]].One solution:
Solution
1#include<vector>23usingPerm= std::vector<int>; // p[i] is where i goes45Permcompose(constPerm& p,constPerm& q){6Perm result;7for(int qi : q) result.push_back(p[qi]);8return result;9}
Like composing functions, : the right-hand one acts first. compose(turn, flip) is but compose(flip, turn) is , two different flips, so the group is not commutative. The usual slip is q[p[i]], which does first and gives the other answer.
20. Abstract algebra and thinking like a mathematician · Rings and fields: two operations that get along · Code challengeFinish modInverse(a, n): the number x from 0 to n - 1 with a * x % n == 1, or std::nullopt if there is none (a std::optional<int> holds an int or nothing). Use the extended Euclidean algorithm.One solution:
Each pair keeps the promise ; the remainders shrink exactly as in Euclid's gcd (r0 / r1 on ints is the whole quotient), and when the last nonzero remainder is 1, its is the inverse. It can come out negative ( for mod ), so the last line moves it into : , and . C++'s % keeps the sign of the left side (-2 % 7 is , not 5), which is why t0 % n alone is not enough.
20. Abstract algebra and thinking like a mathematician · Rings and fields: two operations that get along · ProblemFind the inverse of 5 modulo 17, and use it to solve , with from 0 to 16.Inverse of 5 7; 4
Euclid on 17 and 5: , then . Working back up:
So , and the inverse of 5 is 7 (indeed ). Multiply both sides of by 7:
Check: . The inverse is 7, and .
20. Abstract algebra and thinking like a mathematician · Isomorphic structures are the same in disguise · QuizAre and (pairs of bits, added mod 2 in each place) isomorphic? Both have 4 elements.B. No: in every element added to itself gives 0, but in , An isomorphism keeps every structural fact, including " for all ", which holds in and fails for in . So no bijection can work. Both groups are abelian, and is not even a bijection: 0 and 2 both go to . To show two structures differ, find a property one has and the other lacks.
20. Abstract algebra and thinking like a mathematician · Where algebra goes next · QuizWith and public exponent , which is the private exponent?C. is the inverse of mod : . The others give remainders , and . Decryption works because , by Euler's theorem.
20. Abstract algebra and thinking like a mathematician · Mixed problems from the whole course · QuizWhat are the roots of ?A. The discriminant is , so . Forgetting to halve the gives . "No roots" is true only over : over , every polynomial of degree has roots, counted with multiplicity.
20. Abstract algebra and thinking like a mathematician · Mixed problems from the whole course · QuizSolve .B. Combine: , so , . But needs and needs , so is extraneous. Check: .
20. Abstract algebra and thinking like a mathematician · Mixed problems from the whole course · QuizWhat is ?C. A geometric series with ratio , , sums to . Starting from would give ; check the first term before using the formula.
20. Abstract algebra and thinking like a mathematician · Mixed problems from the whole course · Quiz turns the plane by 90°. What is ?B. Four quarter turns are a full turn, , so only the exponent mod 4 matters: , and , a half turn, which sends every to : that is . The turns form the group , and this is modular arithmetic on exponents, as with .
20. Abstract algebra and thinking like a mathematician · Practice problems · ProblemFind all the roots of : one is real and two are complex.The real root 2; Real part of the complex roots 1; Their positive imaginary part 2
Try divisors of 10: , and . So is a factor.
Synthetic division with on : , then , and :
The quadratic has discriminant :
The roots are and : three roots for a cubic, the complex ones a conjugate pair, as the fundamental theorem and the real coefficients promise.
20. Abstract algebra and thinking like a mathematician · Practice problems · ProblemAn angle has and . Expand with the binomial theorem, and use de Moivre’s theorem to read off and .-117/125 ≈ −0.936; 44/125 ≈ 0.352
With and , the binomial theorem gives:
By de Moivre, the left side is , so match the real and the imaginary parts:
Check with the Pythagorean identity: . So and .
20. Abstract algebra and thinking like a mathematician · Practice problems · ProblemWhere does the line meet the parabola ? Give both points, the left one first.Left point: -1; Left point: -1; Right point: 3; Right point: 7
Substitute the line into the parabola, as with any system:
So or . The line gives their heights: and .
Check on the parabola: and . The points are and .
20. Abstract algebra and thinking like a mathematician · More practice problems · ProblemA loan of 10 000 euros charges 1% interest a month and is repaid by 24 equal monthly payments , the first one month after the loan. The payments, each grown with interest to the end, must add up to what the loan grows to: . Find , and the total interest paid.10000*1.01^24*0.01/(1.01^24 - 1) ≈ 470.735 euros; Total interest 24*10000*1.01^24*0.01/(1.01^24 - 1) - 10000 ≈ 1297.63 euros
The bracket is a geometric series with 24 terms:
So:
In all, euros is paid back, so the interest is about euros.
20. Abstract algebra and thinking like a mathematician · More practice problems · ProblemThe Fibonacci rule is the matrix step . Find the eigenvalues of that matrix, and compare the larger one with .Larger eigenvalue (1 + sqrt(5))/2 ≈ 1.61803; Smaller eigenvalue (1 - sqrt(5))/2 ≈ −0.618034; 89/55 ≈ 1.61818
The quadratic formula gives:
The Fibonacci numbers run 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, so . Applying the matrix again and again is the power method, so the ratio of neighbouring terms settles on the larger eigenvalue, , the golden ratio.
20. Abstract algebra and thinking like a mathematician · More practice problems · ProblemLet . Find its inverse , and .log2((x + 1)/3); 3
Write and undo each step in reverse order:
Rename: , defined for , which is exactly the range of .