Precalculus · Chapter 1

Chapter 1
Functions

Lectures 1–5  |  how information travels, and how we draw it

In this chapter
  1. Functions: how information travels
  2. The line, the plane, and the graph
  3. Reading information off a graph
  4. Transformations: moving a shape around
  5. One-to-one functions, inverses, and codes

Lecture 1 — Functions: how information travels

Cartoon: a function machine turns a cat into a numberA stick figure points at a box labelled f. The word CAT goes in on the left and a string of binary digits comes out on the right. A speech bubble says everything is a number now. Everything is anumber now.CAT01100011f
a function does not care what the thing was

Close your eyes and listen for ten seconds. Something happened out there in the world — air moved — and something happened in here, in your head. In between, information travelled. It got converted, at least four times, into forms nothing like the original: pressure into motion, motion into electricity, electricity into whatever it is you are experiencing right now.

That chain of conversions is what this course is about. Each link takes something in and gives something out, reliably, the same way every time. We call such a link a function, and once you start looking you find them everywhere, because a function is simply the mathematical name for a rule that turns input into output.

Three senses, three branches of mathematics

The subject you are about to study did not arrive as one block. It grew out of people trying to understand what their senses were telling them, and the three great branches correspond, roughly and beautifully, to three ways of sensing the world.

Three senses and the branches of mathematics they gave rise to Sight leads to geometry, the study of shape and length. Hearing leads to trigonometry, the study of repetition and waves. The sense of change over time leads to calculus, the study of rates and accumulation. All three rest on the idea of a function. sightwhat is where soundwhat repeats change in timewhat is happening now GEOMETRY length, angle, shape chapters 5, 7 TRIGONOMETRY waves, cycles, pitch chapters 4, 6 CALCULUS rates, slopes, totals chapter 2, then next year all of it rests on: FUNCTIONS
Geometry is the mathematics of sight: it tells you what is where, and why the diagonal across the park is shorter than walking two sides of it. Trigonometry is the mathematics of sound: it handles anything that comes back around. Calculus handles the one thing you sense that is neither shape nor pitch — change itself.
idea

Geometry begins with an act of deliberate forgetting. To say that a park is a rectangle 300 metres by 200 metres is to throw away the grass, the noise, the people, the smell after rain — everything except length and width. That looks like a loss. It is what makes the calculation possible: with everything else discarded, \(\sqrt{300^2+200^2}\approx 360\) metres tells you the diagonal path saves you 140 metres of walking, and it tells you that for every rectangle that ever was. Abstraction is not the opposite of reality. It is a lens that gives up colour to gain reach.

What a function is

You have met functions in many disguises: a formula, a graph, a table, a sentence. All four describe the same kind of object.

example 1.1 — four faces of the same idea

The last one has outputs that are not numbers, and the third has no formula at all. Both are still functions. We will fix the number problem shortly, and the fix is more interesting than it sounds.

definition

A function \(f\) from a set \(A\) to a set \(B\) is a rule that assigns to each element \(x\) of \(A\) exactly one element of \(B\), written \(f(x)\).

The set \(A\) is the domain. The set of values actually produced is the range. We write \(f:A\to B\), and we read \(f(x)\) as "\(f\) of \(x\)", or "the value of \(f\) at \(x\)".

Two words in that definition are doing all the work. Each: nothing in the domain is left without an answer. Exactly one: nothing gets two answers. A rule that sometimes says 3 and sometimes says 5 for the same input is not a function — it is a coin flip, and you cannot build anything on it.

spot check
In an arrow diagram, one input has two arrows leaving it. Which word of the definition fails?
example 1.2 — is it a function?

Decide which of these rules are functions, and if not, say precisely which part of the definition fails.

  1. To each student in the room, assign their date of birth.
  2. To each date of birth, assign the student in the room born on it.
  3. To each song, assign the next song your playlist plays on shuffle.
  4. To each whole number, assign its remainder when divided by 7.
  5. To each person, assign their favourite film.

(a) A function. Every student has exactly one birthday.

(b) Not a function, twice over. Most dates have no student attached (fails each), and if two classmates share a birthday, that date has two (fails exactly one).

(c) Not a function — that is the entire point of shuffle. The same input can produce a different output tomorrow, so nothing can be predicted from it.

(d) A function, and a famously useful one. It takes infinitely many inputs to just seven outputs, so it destroys enormous amounts of information on purpose; it is the arithmetic behind check digits, hash tables and cryptography.

(e) Not reliably. Ask most people twice and you get two answers. A rule has to be stable to be a function, which is a real constraint on what parts of the world mathematics can model.

A function drawn as a machine An input x enters a box labelled f from the left. The box performs the rule square it, then add four. An output f of x leaves to the right. input x f square it, then add 4 output f(x)
The machine picture. You do not need to know what is inside the box to use it — only that the same input always produces the same output.
spot check

If \(f(x)=x^{2}+4\), what is \(f(-3)\)?

decimals, fractions, pi and sqrt( ) are all fine

Is it a function?

Tap a letter on the left, then a number on the right, to add or remove an arrow. The verdict updates as you go. Try to build something that fails, and read the reason.

domain A set B

spot check
Two different inputs are sent to the same output. Is the rule still a function?
example 1.3 — evaluating

In a game, holding the attack button charges a strike. Charging for \(x\) seconds does $$D(x)=x^2+4$$ points of damage. Describe in words what \(D\) does, then find \(D(3)\), \(D(0)\), \(D(\sqrt5)\), and \(D(a+h)\).

In words: square the charge time, then add four. The four is the damage you do with no charge at all — a tap still hurts.

\(D(3)=9+4=13\).   \(D(0)=4\).   \(D(\sqrt5)=5+4=9\).

\(D(a+h)=(a+h)^2+4=a^2+2ah+h^2+4\). The variable is a placeholder; whatever goes in the box gets squared.

That last computation looks like busywork now. It answers a real question: if you are already charging for \(a\) seconds, what does holding on for \(h\) seconds longer buy you? The extra damage is \(D(a+h)-D(a)=2ah+h^2\). Divide by \(h\) to get the damage per extra second, and you have written down a difference quotient — the object Lecture 8 is built on, and the derivative after that.

example 1.4 — net change

An astronaut weighs 130 pounds on the launch pad. At a height of \(h\) miles the weight is $$w(h)=130\left(\frac{3960}{3960+h}\right)^{2}\ \text{pounds.}$$ Find the weight at 100 miles up, and the net change between the launch pad and the altitude of the space station, 254 miles.

\(w(100)=130(3960/4060)^2\approx 123.7\) lb.

\(w(254)=130(3960/4214)^2\approx 114.8\) lb, and \(w(0)=130\), so the net change is about \(-15.2\) lb.

Notice what this does not say. A crew member on the station is weightless, yet the formula reports 115 pounds. Both are true: gravity is barely weaker up there, and things float there because they are falling around the Earth rather than standing on it. A model answers the question it was built for and no other, and knowing which question that was is most of the skill.

example 1.5 — a function defined in pieces

A rental e-scooter costs \$1.20 to unlock. The first three minutes are free; after that it costs \$0.42 per minute. Write the cost as a function of the ride length \(t\) in minutes, find \(C(2)\), \(C(3)\) and \(C(12)\), and sketch it.

$$C(t)=\begin{cases}1.20 & 0\le t\le 3\\[2pt] 1.20+0.42(t-3) & t>3\end{cases}$$

\(C(2)=1.20\), \(C(3)=1.20\), and \(C(12)=1.20+0.42(9)=\$4.98\).

Graph of the scooter cost function The cost is flat at one dollar twenty for the first three minutes, then rises as a straight line of slope forty-two cents per minute. 246 0351015 minutescost ($) free window

This is a piecewise defined function: one rule on part of the domain, another elsewhere. The two rules agree at \(t=3\), so there is no jump — but there is a kink, and at a kink the function has no single rate of change. That kink is the first thing Chapter 2 will want to talk about.

example 1.6 — a function with a jump

A campus printer charges 10 cents per page, but a job of any size is rounded up to a whole page. A document runs to 2.3 pages. What does it cost? Sketch the cost for \(0<x\le 4\) pages and describe the shape in one word.

It costs 30 cents: the machine charges for 3 pages. The function is $$C(x)=0.10\lceil x\rceil,$$ a staircase. It jumps at every whole number, and at each jump the value belongs to the upper step.

The printer charge as a staircase functionA step graph. The cost stays at ten cents for any job up to one page, jumps to twenty cents just past one page, and so on. Each step is drawn with an open circle at its left end and a filled circle at its right end. 2.3 pages costs 30c123410c20c30c40cpages sent to the printer
A staircase, and a perfectly good function. The filled circle at the right end of each step says the value there belongs to the lower price; the open circle at the left says it does not. At every jump the graph is undecided for no value of \(x\) at all — but it is not continuous, and that word will matter in Chapter 2.

Staircase functions are perfectly legal functions, and they are everywhere in pricing, postage and parking. They are also the first sign that "function" is a far wider idea than "smooth curve" — and it was exactly such awkward functions that forced mathematicians in the 1800s to write the careful definition you read above.

Everything can be a number

Our definition allows any sets \(A\) and \(B\). In practice we almost always take both to be sets of real numbers, and that sounds like a serious restriction. It is not, because anything can be encoded as numbers.

An image as a function from pixel positions to numbers On the left, a small grid of grey squares forming a diagonal shape. On the right, the same grid with each square replaced by the number giving its brightness from 0 to 9. 9 9 7 2 1 0 9 8 3 1 0 0 7 3 1 0 0 1 2 1 0 0 2 6 1 0 0 2 7 9 0 0 1 6 9 9 what you see what the computer stores →
An image is a function. Its input is a position — row 3, column 5 — and its output is a brightness. Nothing has been lost in the translation on the right; the picture is the table of numbers.
spot check

A greyscale image is 10 pixels wide and 8 pixels tall, with one number per pixel. How many numbers does it take to store?

decimals, fractions, pi and sqrt( ) are all fine

The same trick works for everything. Sound is a function from time to air pressure, sampled 44,100 times a second on a CD. Text is a function from position to character code. A colour is three numbers. A chess position is a list. Once information is numbers, functions on the real line can operate on it — which is why the mathematics you learn here applies to things that are not obviously mathematical at all.

example 1.7 — the oldest code we know

DNA is read three letters at a time. Each of the 64 possible triples — AAA, AAC, and so on — tells the cell to add one particular amino acid, or to stop. There are 20 amino acids and one stop instruction. Is the genetic code a function? Can it be run backwards?

It is a function: each triple has exactly one meaning, the same in a bacterium and in you.

It cannot be run backwards. Sixty-four inputs map onto twenty-one outputs, so on average three different triples mean the same thing; knowing that an amino acid is leucine does not tell you which of its six codons produced it. Information about the DNA is genuinely lost in the reading.

And that redundancy is a feature. A typo in the third letter of a codon very often changes nothing at all, because the alternatives were pointing at the same amino acid anyway. The code is built so that small errors are absorbed — the same design principle behind the check digit on your bank card. Lecture 5 is about exactly this trade: what you give up when a function stops being reversible, and what you can buy with it.

example 1.8 — turning a word into numbers

Encode the word CAB as numbers in three different ways, and say what each one keeps and what it throws away.

Position in the alphabet. \(C=3\), \(A=1\), \(B=2\), so the word becomes the list \((3,1,2)\). This keeps everything: the letters and their order. You can rebuild the word exactly.

Letter counts. Count how many of each letter: one A, one B, one C, and none of the rest. That is the list \((1,1,1,0,0,\ldots)\) with 26 entries. It keeps which letters appeared and how often, and throws away the order — so CAB, BAC and ABC all give the same list.

Length. The single number 3. Almost everything is gone.

All three are legitimate encodings, and which is right depends entirely on the question. If you want to recover the word, use the first. If you want to know whether two documents are about the same subject, the second is better, because order is mostly noise for that purpose. This choice — what to keep and what to discard — is the first real decision in any piece of data analysis.

A sentence as an arrow

The second encoding above is worth pushing further, because it is how text is actually handed to a computer.

Pick a small list of words to pay attention to. For each sentence, count how many times each of those words appears. The sentence is now a list of numbers — and a list of numbers, as Chapter 7 will make precise, can be drawn as an arrow.

spot check
Count (animal words, finance words) using cat, dog, chased and market, stock, analyst. Which pair encodes “the dog chased the cat past the stock market”?
example 1.9 — three sentences, three arrows

Count two kinds of word — animal words (cat, dog, chased) and finance words (market, stock, analyst) — in these three sentences, and plot each as a pair of numbers.

A has cat and nothing else from either list, and we will count mat as an animal-adjacent word for the sake of a clean picture: \((2,0)\). B has cat and chased, plus market and analyst: \((3,1)\). C has market and two more finance words: \((0,3)\).

Three sentences plotted as arrows in a plane Two axes count animal words and finance words. Sentence A points along the animal axis, sentence B points in a similar direction slightly tilted, and sentence C points straight up the finance axis, at a right angle to A. ABC animal words → finance A “the cat sat on the mat” B “my cat chased the market analyst” C “the market fell sharply today” A and B point almost the same way A and C are at a right angle: they share no words at all
Once each sentence is a list of counts, it is an arrow in a plane, and two sentences can be compared by the angle between their arrows. Nothing about this depends on there being only two kinds of word: with a thousand word-counts each sentence becomes an arrow in a thousand-dimensional space, which nobody can picture and everybody can compute with.

Now look at what the picture gives you for free. A and B point in nearly the same direction, and they are about nearly the same thing. C points at a right angle to A, and they share nothing. The direction of the arrow carries the meaning; its length carries only how many words the sentence has.

That is why length has to be divided out before two sentences are compared, and the tool that does it is the angle between the arrows. We cannot compute that angle yet — it needs the dot product, which arrives in Chapter 7 — but the picture is already doing the work, and this exact example returns there.

idea

This is the quiet premise underneath every piece of technology built since 1940: whatever it is, digitise it, and then a function can act on it. A photo filter is a function. A search ranking is a function. A large language model is a function — an extremely large one, with billions of adjustable numbers inside, taking a sequence of text-codes in and giving the next text-code out. When people ask what artificial intelligence is, the honest technical answer is: a function that somebody fitted to data. You will fit your first one in Lecture 6.

A neural network drawn as a function Inputs on the left connect through two hidden layers of nodes to a single output on the right, showing that the whole network is one function from x to y. inputs x output y one function: y = f(x)
A neural network is a composition of very simple functions, layered. Chapter 1 gives you composition; Chapter 7 gives you the matrices each layer is built from.
history

Nobody used the word function before 1673, when Leibniz wrote it down. But the idea is older than the word. In the 1350s Nicole Oresme, in Paris, drew a quantity as a height above a horizontal line and reasoned about how the height varied — a graph, three hundred years before Descartes gave us coordinates. Euler introduced the notation \(f(x)\) in 1734.

The definition you read above, with its insistence on each and exactly one, is younger still: it settled only in the nineteenth century, after mathematicians found functions so badly behaved that the old intuition ("a function is a formula") collapsed. What looks like a dry definition is a scar from an argument that lasted a century.

exercises 1.1
  1. Let \(f(x)=3x^2+x-5\). Find \(f(-2)\), \(f(0)\), \(f(\tfrac12)\), \(f(2a)\).
  2. Let \(g(t)=\dfrac{t}{t+1}\). Find \(g(0)\), \(g(1)\), \(g(-2)\). What input is forbidden, and why?
  3. Describe in words what each function does to its input: (a) \(f(x)=2(x+3)\); (b) \(g(x)=2x+3\). Are they the same function? Justify with one input.
  4. The stopping distance of a car in metres is modelled by \(s(v)=0.2v+0.01v^{2}\), where \(v\) is the speed in km/h. Find \(s(50)\) and \(s(100)\). Doubling the speed does what to the stopping distance, and why is the answer not "doubles it"?
  5. A streaming plan costs \$9 a month for up to 40 hours of viewing and 12 cents per hour after that. Write the monthly bill as a function of hours watched, and find the bill at 30, 40 and 75 hours.
  6. The rule "to each number, assign a number whose square is that number" fails to be a function. Show that it fails both requirements of the definition, and repair it in two different ways.
  7. A grayscale image is 1920 by 1080 pixels, each brightness stored as a whole number from 0 to 255. How many numbers is the image? How many different images of this size are possible? (Leave the second answer as a power.)
  1. \(f(-2)=12-2-5=5\); \(f(0)=-5\); \(f(\tfrac12)=\tfrac34+\tfrac12-5=-\tfrac{15}{4}\); \(f(2a)=12a^2+2a-5\).
  2. \(g(0)=0\), \(g(1)=\tfrac12\), \(g(-2)=2\). The input \(t=-1\) is forbidden: it makes the denominator zero, and division by zero produces no number at all, so the rule would fail to assign an output.
  3. (a) add 3, then double. (b) double, then add 3. Different: \(f(1)=8\) but \(g(1)=5\). Order of operations is part of the rule.
  4. \(s(50)=10+25=35\) m and \(s(100)=20+100=120\) m, nearly 3.5 times as far. The reaction-time term grows in proportion to speed, but the braking term grows with its square and quickly dominates. This is the whole argument behind speed limits, and a preview of Lecture 7.
  5. \(B(x)=9\) for \(0\le x\le40\) and \(B(x)=9+0.12(x-40)\) for \(x>40\). The bills are \$9.00, \$9.00 and \$13.20.
  6. It fails each, because a negative input has no real output at all, and it fails exactly one, because 9 could be sent to either 3 or \(-3\). Two repairs: restrict the domain to \([0,\infty)\) and always take the non-negative root, giving \(\sqrt{x}\); or keep both roots and accept that the object you have built is a curve rather than a function, which is the sideways parabola of Lecture 2.
  7. \(1920\times1080=2{,}073{,}600\) numbers. Each has 256 choices, so there are \(256^{2073600}\) possible images — a number with over five million digits. Every photograph that will ever be taken at this resolution is somewhere in that set.

Lecture 2 — The line, the plane, and the graph

Cartoon: hunting for a fraction on the number lineA stick figure holds a magnifying glass over a number line, peering at the square root of two between the tick marks, saying there has to be a fraction in here somewhere. There has to be afraction in heresomewhere.√2
there isn't. that is the whole of section 1.

If functions are going to eat numbers, we had better be sure the numbers are solid. They are, but only just, and the reason took two thousand years to work out.

The real line

Draw a horizontal line, mark a point as \(0\) and another as \(1\), and every real number now has a home. The picture is so familiar that it hides three separate properties, each of which we will use.

definition
spot check
Which property guarantees there is no gap on the number line where \(\sqrt2\) should be?

The third one is the deep one, and it is not obvious. The rational numbers — all the fractions — are already dense: between any two of them sits another. If you plotted every fraction, the line would look completely full. And yet it would be full of holes, because \(\sqrt2\) is not a fraction, and neither is \(\pi\), and in a precise sense almost every point on the line is one of these missing ones.

history

The Pythagoreans, around 500 BCE, believed that every length was a ratio of whole numbers. Then someone in their own school proved that the diagonal of a unit square is not. The legend — probably invented, but the shock behind it was real — says the discoverer was drowned at sea. Their entire picture of the universe had a hole in it, at a location they could construct with a ruler.

The hole was not properly filled until 1872, when Richard Dedekind defined a real number as a cut in the rationals: pick a place to slice the fractions into a left set and a right set, and the slice itself is the number. That is what completeness means. It is why calculus works, why a continuous curve that goes from below zero to above zero must cross zero, and why nothing you do in this course will fall through a gap.

Zoom into the line

This shows the interval around \(\sqrt2\approx1.41421\dots\). Every tick is a fraction with a small denominator. Zoom in as far as you like: the fractions never run out, yet the marked point never lands on one.

√2

Intervals and distance

Because the line is ordered, the most useful subsets of it are the unbroken stretches, and they get their own notation.

NotationMeansIn words
(a, b)\(a<x<b\)open: endpoints excluded
[a, b]\(a\le x\le b\)closed: endpoints included
[a, b)\(a\le x<b\)half open
(a, ∞)\(x>a\)infinity is never included; it is not a number
spot check

In interval notation, \(-2\le x<7\) is written .

Absolute value turns the order into a distance: \(|a-b|\) is how far apart \(a\) and \(b\) are, regardless of which is bigger. This single reading makes a whole family of formulas obvious rather than memorized. \(|x-3|<2\) says \(x\) is within 2 of 3, which is the interval \((1,5)\).

spot check

\(|x+4|\le1\) describes an interval. What number is at its centre?

decimals, fractions, pi and sqrt( ) are all fine

example 1.10 — a delivery radius

A restaurant on a long straight avenue delivers only to addresses within 8 blocks of itself. It sits at block 23. Write the delivery zone with absolute value, then as an interval, and decide whether an address at block 32 is inside it.

"Within 8 of 23" is exactly \(|x-23|\le 8\), which is the interval \([15,31]\).

The delivery zone on a number line A number line from block 10 to block 36 with a shaded band from 15 to 31 centred on the restaurant at 23, and a marker at 32 lying outside it. 1015 233136 32 restaurant

Block 32 falls one block outside. The picture makes the reason obvious in a way the inequality does not: absolute value is distance, and once you read it that way you stop memorising which direction the inequality flips.

example 1.11 — tolerance

A bolt is specified as 12.00 mm in diameter with a tolerance of 0.05 mm. A machine measures one at 11.94 mm. Write the acceptable range with absolute value and decide whether the bolt passes.

Acceptable means \(|d-12.00|\le 0.05\), that is \(11.95\le d\le 12.05\). At 11.94 mm the bolt fails, by one hundredth of a millimetre.

Every specification sheet in engineering is an absolute value inequality, and this is why: what matters is not the measurement but its distance from the target, in either direction.

Stacking two lines: the plane

Take a copy of the real line, take another, cross them at right angles, and you can name any point in a flat world with a pair of numbers \((x,y)\). This is Descartes' idea, and it is the hinge on which all of modern mathematics turns: it lets shape be described by equations, so that geometry and algebra become two languages for one subject.

idea

Coordinates are a choice, not a fact about the world. Nothing out there is labelled \((3,-2)\); you decided where the origin was and which way was up. This matters more than it sounds. A great deal of Chapter 7, and of data science generally, consists of choosing better coordinates for a problem — finding the axes along which your data actually varies. The freedom to relabel is a tool.

Algebra and geometry become one subject

Coordinates do something far more useful than labelling points. They let a shape be written as an equation, and an equation be drawn as a shape — and once that translation exists it runs in both directions, so a hard problem in one language can be carried across and solved in the other.

The circle of radius \(r\) about the origin is the set of points at distance \(r\) from it. Distance in the plane comes from the Pythagorean theorem, so the condition is $$x^2+y^2=r^2.$$ That single line is the whole hinge. On the left it is algebra; on the right it is a curve you could draw with a piece of string.

example 1.12 — carrying a problem across

A drone is flying the straight path \(y=x+1\). A no-fly zone is the circular region of radius 5 centred at the origin. Where does the drone cross the boundary?

The boundary is \(x^2+y^2=25\). Substituting the path: $$x^2+(x+1)^2=25 \;\Longrightarrow\; 2x^2+2x-24=0 \;\Longrightarrow\; x^2+x-12=0,$$ which factors as \((x+4)(x-3)=0\). So \(x=-4\) or \(x=3\), giving the crossing points \((-4,-3)\) and \((3,4)\).

A line crossing a circle at two points A circle of radius 5 centred at the origin, and the line y equals x plus 1 cutting through it at the points minus four, minus three and three, four. (-4,-3)(3,4)

A question about where two curves meet became a quadratic equation, which is a thing we know how to kill. Notice also that the crossing points have whole-number coordinates and satisfy \(3^2+4^2=5^2\) — Pythagorean triples turning up uninvited, as they do.

idea

René Descartes published this in 1637, in an appendix. Before it, geometry and algebra were separate subjects with separate practitioners; a Greek geometer proving a fact about conic sections and an Islamic algebraist solving a cubic were not obviously doing the same work. Afterwards they were two dialects, and any statement could be moved into whichever dialect made it easier.

That is a pattern worth watching for, because it never stopped: the whole later history of mathematics is one translation after another. Logarithms turn multiplication into addition (Chapter 3). The unit circle turns repetition into coordinates (Chapter 4). Matrices turn geometric motion into arithmetic (Chapter 7). Machine learning turns images and sentences into vectors so that geometry can be done on them. Each time, someone noticed that a hard problem was easy on the other side of a translation, and went to the trouble of building the bridge.

definition

The graph of a function \(f\) is the set of points $$\{(x,f(x)) : x \text{ in the domain of } f\}.$$ It is the picture of every input paired with its output.

spot check
The point \((2,7)\) lies on the graph of \(f\). What does that tell you?

Because each input gets exactly one output, no vertical line can meet a graph twice. That is the whole content of the vertical line test: it is not an extra rule, it is the definition of a function, drawn.

The vertical line test On the left, the parabola y equals x squared: a vertical line drawn at x equals one meets it exactly once, so it is the graph of a function. On the right, the sideways parabola x equals y squared: a vertical line meets it twice, at y equals plus and minus 1.2, so it is not the graph of a function of x. one crossing: this is a function 0 two crossings: not a function of x 0
The curve on the right is a perfectly good shape. It is just not the graph of a function of \(x\), because one input would need two outputs.
spot check
Is the circle \(x^{2}+y^{2}=4\) the graph of a function of \(x\)?

Domain from a formula

If a function is given by a formula with no domain stated, the domain is understood to be every real number for which the formula produces a real number. In practice, only two things go wrong: dividing by zero, and taking an even root of a negative.

spot check
What is the domain of \(g(x)=\sqrt{x-5}\)?
example 1.13 — where is this defined?

Find the domain of each: (a) \(f(x)=\dfrac{1}{x-4}\); (b) \(g(x)=\sqrt{x}\); (c) \(h(x)=\dfrac{1}{x^2-x}\); (d) \(j(t)=\dfrac{t}{\sqrt{t+1}}\).

(a) \(x\neq4\), that is \((-\infty,4)\cup(4,\infty)\).

(b) \(x\ge0\), that is \([0,\infty)\).

(c) \(x^2-x=x(x-1)\), so \(x\neq0\) and \(x\neq1\).

(d) Both problems at once: the root needs \(t+1\ge0\) and the denominator needs \(t+1\neq0\). So \(t>-1\), the interval \((-1,\infty)\).

example 1.14 — two kinds of domain

A drone battery lasts 28 minutes. Its remaining flight time after \(t\) minutes in the air is \(R(t)=28-t\). What is the domain of the formula? What is the domain of the situation?

The formula \(28-t\) is happy with every real number, including \(t=-9\) and \(t=1000\). The situation is not: \(0\le t\le 28\).

This gap between the mathematical domain and the physical one is where most modelling errors live. A formula fitted to sales data for prices between \$2 and \$8 will cheerfully report a prediction for a price of \$400; it has no way of knowing it is being asked something absurd. Stating the domain is not bookkeeping. It is you writing down the range of situations you are actually willing to vouch for.

Graph of the piecewise phone plan cost function The cost is flat at 39 dollars for the first 2 units, then rises as a straight line of slope 15 dollars per unit, reaching 99 dollars at 6 units. 255075 0246 units used cost ($) flat rate slope 15
A tiered utility bill: 39 dollars covers the first 2 units, and each additional unit costs 15. The kink is where the rule changes. The function is perfectly well defined there, but it has no single rate of change at the kink — which is a preview of Chapter 2.
exercises 1.2
  1. Write as intervals: (a) \(-3\le x<5\); (b) \(x>-1\); (c) \(|x-2|\le 4\); (d) \(|x+3|>1\).
  2. Find two rational numbers between \(1.4142\) and \(\sqrt2\). Explain why there are infinitely many.
  3. Find the domain: (a) \(\dfrac{x+1}{x^2-9}\); (b) \(\sqrt{5-2x}\); (c) \(\dfrac{\sqrt{x}}{x-3}\); (d) \(\sqrt[3]{x-1}\).
  4. Sketch the graph of \(f(x)=\begin{cases}-x & x<1\\ x^2 & x\ge 1\end{cases}\) and give its range.
  5. Which of these curves are graphs of functions of \(x\)? (a) a circle of radius 3 about the origin; (b) the top half of that circle; (c) a vertical line; (d) a horizontal line.
  6. A cable is strung between two poles 40 m apart. Its height above the ground is \(h(x)=0.02(x-20)^{2}+6\) metres. Find the domain that makes physical sense, the lowest point of the cable, and its height at each pole.
  7. Explain, in two sentences, why the rational numbers being dense is not enough to make calculus work.
  1. (a) \([-3,5)\); (b) \((-1,\infty)\); (c) \([-2,6]\); (d) \((-\infty,-4)\cup(-2,\infty)\).
  2. For instance \(1.41421\) and \(1.414213\). Between any two distinct reals lies a rational (truncate the decimal expansion far enough), and then repeat the argument between that one and \(\sqrt2\), forever.
  3. (a) \(x\neq\pm3\); (b) \(x\le\tfrac52\); (c) \(x\ge0\) and \(x\neq3\); (d) all reals — odd roots of negatives are fine.
  4. For \(x<1\) the graph is the falling line \(y=-x\), which approaches the height \(-1\) without reaching it; for \(x\ge1\) it is the right half of a parabola starting at \((1,1)\). The first piece contributes \((-1,\infty)\) and the second \([1,\infty)\), so the range is \((-1,\infty)\). There is a jump at \(x=1\).
The piecewise function of exercise 4A falling straight line for x less than one, ending with an open circle just below minus one, and the right half of a parabola starting with a filled circle at the point one comma one. a jump−2−112124
The two pieces do not meet. Approaching \(x=1\) from the left the values head toward \(-1\) without reaching it; at \(x=1\) the other rule takes over and the value is \(1\). The range is everything above \(-1\).
  1. (b) and (d) only. A full circle fails the vertical line test; a vertical line fails it catastrophically.
  2. The formula accepts every real number, but the situation gives \(0\le x\le 40\). The lowest point is at \(x=20\), height 6 m, since the squared term is smallest there. At either pole \(h=0.02(400)+6=14\) m. The curve is a parabola here; the shape a real hanging cable takes is a catenary, which is close but not equal, and telling the two apart needs Chapter 3.
  3. Density says you can always find another rational nearby, but a sequence of rationals can march steadily toward a place where no rational is — toward \(\sqrt2\). Calculus is built on limits, so the destination has to exist; completeness is the guarantee that it does.

Lecture 3 — Reading information off a graph

Cartoon: drawing a curve through three data pointsOne stick figure has drawn a wiggly curve through three plotted points. Another asks what happened between the dots. What happenedbetween the dots?
“art.”

A graph is a compression device. A year of daily temperature readings is 365 numbers, which no one can hold in their head; drawn as a curve, the same information becomes a shape you understand in a second. This lecture is about extracting that understanding deliberately, and about the ways a picture can mislead you.

One year of daily temperature in New York

Drag or tap anywhere on the plot to read a value, or focus it and use the left and right arrow keys (hold shift to jump a week). We will come back to this exact data in Lecture 15, when we fit a wave to it, and again in Lecture 16, when we pull its frequencies apart.

305580 °F JanAprJulOctDec

Tap the plot to read a day.

Where a function rises and falls

definition

\(f\) is increasing on an interval if \(f(x_1)<f(x_2)\) whenever \(x_1<x_2\) in that interval, and decreasing if \(f(x_1)>f(x_2)\).

\(f\) has a local maximum at \(c\) if \(f(c)\ge f(x)\) for all \(x\) near \(c\); a local minimum is defined the same way with the inequality flipped. The absolute maximum and minimum are the largest and smallest values over the whole domain.

spot check
\(f(1)=6\) and \(f(3)=2\), and the graph is unbroken in between. Which statement must be true?

"Local" means what it says: a hilltop is a local maximum even if there is a taller mountain three valleys over. When you meet gradient descent in Lecture 8, this distinction stops being pedantic and becomes the central practical difficulty of the whole method.

A curve with a local maximum and a local minimum The curve rises to a local maximum at x equals 1, falls to a local minimum at x equals 3, then rises again. local max local min 1234
\(f(x)=x^3-6x^2+9x+2\). Increasing on \((0,1)\) and on \((3,4.2)\); decreasing on \((1,3)\). The local minimum at \(x=3\) has value 2 — but \(f(0)=2\) as well, so it is not the only lowest point, and on a wider domain it would not be the lowest at all.
example 1.15 — net change

Using the temperature plot above, estimate the net change in temperature from day 60 (early March) to day 220 (early August), and say why the net change tells you almost nothing about what happened in between.

Reading the plot, day 60 is around 40°F and day 220 around 82°F, so the net change \(f(220)-f(60)\) is roughly \(+42\)°F.

But the same net change would result from a straight climb, from a climb-crash-climb, or from a summer that arrived in April and stalled. Net change is a single number extracted from 160 days of behaviour; it is the crudest possible summary. Chapter 2 asks the better question — not how much did it change, but how fast was it changing at each moment.

Symmetry: information you get for free

definition

\(f\) is even if \(f(-x)=f(x)\) for every \(x\) in the domain: the graph is a mirror image across the \(y\)-axis.

\(f\) is odd if \(f(-x)=-f(x)\): the graph is unchanged by a half-turn about the origin.

spot check
Is \(f(x)=x^{3}-x\) even, odd, or neither?
Even and odd symmetry On the left, y equals x squared, symmetric across the vertical axis. On the right, y equals x cubed, symmetric under a half turn about the origin. f(x) = x² is even g(x) = x³ is odd
Symmetry halves your work: knowing an even function on \([0,\infty)\) tells you everything about it. This is exactly the kind of structural shortcut that makes Chapter 6 possible.
spot check

\(f\) is even and \(f(4)=9\). What is \(f(-4)\)?

decimals, fractions, pi and sqrt( ) are all fine

example 1.16

Decide whether each is even, odd, or neither: (a) \(f(x)=x^4-3x^2\); (b) \(g(x)=x^3+x\); (c) \(h(x)=x^2+x\).

(a) \(f(-x)=x^4-3x^2=f(x)\): even. Only even powers appear, which is where the name comes from.

(b) \(g(-x)=-x^3-x=-g(x)\): odd.

(c) \(h(-x)=x^2-x\), which is neither \(h(x)\) nor \(-h(x)\). Mixing even and odd powers destroys both symmetries. Test with \(x=1\): \(h(1)=2\), \(h(-1)=0\).

What a graph does not tell you

idea

Every graph you have ever seen of real data is a lie by omission, and an honest scientist knows exactly which lie. The temperature curve above is drawn from 365 numbers, one per day — but the temperature at 3 a.m. on 14 March is not on that plot, and neither is anything else that happened between readings. The smooth line connecting the dots is an assumption, drawn in by us, that nothing wild occurred in the gap.

Sometimes that assumption is safe. Sometimes it hides everything that matters: a flash flood, a market crash, a heartbeat. The rate at which you sample decides what you are capable of seeing, and in Lecture 16 we will find the precise version of this statement — you cannot detect a cycle that repeats faster than you look.

example 1.17 — reading a hike

Here is the elevation profile of a 7 km ridge trail. Find the absolute maximum and where it occurs, the absolute minimum, and every local maximum and minimum. Then answer the question that actually matters to the legs doing the walking: how much total climbing is there?

Elevation profile of a seven kilometre ridge trail The trail starts at 180 metres, climbs to a main summit of 498 metres at 2.1 kilometres, drops to a saddle at 273 metres near 4.2 kilometres, rises to a second summit of 351 metres at 5 kilometres, then descends to 149 metres at the end. 498 m 273 m 351 m 100200300400500 0246 distance (km)elevation (m)

Absolute maximum 498 m at 2.1 km — the summit. Absolute minimum 149 m, at the very end of the walk, lower than the starting point.

Local maxima at 2.1 km (498 m) and 5.0 km (351 m); a local minimum at the saddle, 4.2 km (273 m). The second summit is a genuine local maximum even though it is 147 m lower than the first — local means higher than its neighbours, not highest.

Total climbing is a different quantity from net change. Net change is \(149-180=-31\) m, which makes the day sound flat. But the trail climbs \(498-180=318\) m to the summit and then another \(351-273=78\) m out of the saddle: 396 m of ascent in the legs. Net change cancels the ups against the downs; total climbing adds their sizes. Chapter 2 will separate these two questions properly, and it turns out the second one is the harder and more interesting of the two.

example 1.18 — the graph that lies

A sensor records a signal once per second and returns the readings \(0,0,0,0,0\), suggesting the signal is off. The figure shows what was actually happening.

A wave sampled exactly once per cycle A sine wave completing four full cycles, with sample points taken at each whole second. Every sample lands exactly on zero, so the samples suggest a flat signal. 0s1s2s3s4s

The signal completes exactly one full cycle between consecutive samples, so every sample catches it at the same phase — zero. Five honest measurements, taken with a working instrument, and the conclusion is completely wrong.

This is aliasing. It is why wagon wheels spin backwards in old films, why a guitar string filmed on a phone appears to wobble slowly, and why the sampling rate of an audio file caps the highest note it can contain. The rule, which we will meet properly in Lecture 17: you cannot detect a cycle that repeats faster than you look.

The moral is not that measurement is untrustworthy. It is that a set of data points has no opinion about what happened between them, and the smooth line your software draws through them is a guess you have made, not a fact you have measured.

exercises 1.3
  1. From the temperature plot, estimate: the absolute maximum and when it occurred; the absolute minimum; the intervals where the function is increasing.
  2. For \(f(x)=x^3-6x^2+9x+2\) shown above, find \(f(0)\), \(f(1)\), \(f(3)\), \(f(4)\), and confirm the local extremes by testing values on either side.
  3. Even, odd, or neither: (a) \(x^5-x\); (b) \(|x|\); (c) \(x^2+1\); (d) \(\dfrac1x\); (e) \(x+1\).
  4. Can a function be both even and odd? Find every such function, and prove there are no others.
  5. Sketch a graph with an absolute maximum but no absolute minimum, on the domain \([0,\infty)\).
  6. A company's revenue rose from \$4M to \$9M over five years. Sketch two very different revenue histories with that same net change, and say which one you would rather own.
  7. Suppose \(f\) is odd and defined at \(0\). Prove that \(f(0)=0\). Then explain why an even function has no such obligation, and give an even function with \(f(0)=7\).
  1. Maximum near 89°F in mid-to-late July; minimum near 26°F in January. Increasing roughly from mid-January to late July, decreasing from late July to mid-January — with a great deal of local wobble that is not increase or decrease in the strict sense, only in trend.
  2. \(f(0)=2\), \(f(1)=6\), \(f(3)=2\), \(f(4)=6\). Since \(f(0.5)=4.875<6\) and \(f(1.5)=5.375<6\), there is a local maximum at 1; since \(f(2.5)=2.625>2\) and \(f(3.5)=2.625>2\), there is a local minimum at 3.
  3. (a) odd; (b) even; (c) even; (d) odd; (e) neither.
  4. Yes, but only one: \(f(x)=0\). If \(f\) is both then \(f(-x)=f(x)\) and \(f(-x)=-f(x)\), so \(f(x)=-f(x)\), giving \(2f(x)=0\) and \(f(x)=0\) for every \(x\).
  5. For example \(f(x)=\dfrac{1}{1+x^2}\): maximum 1 at \(x=0\), values approaching but never reaching 0.
  6. Answers vary; a steady climb versus a crash to \$1M followed by a spike to \$9M. Same endpoints, wildly different companies.
  7. Oddness at \(x=0\) says \(f(-0)=-f(0)\), and \(-0=0\), so \(f(0)=-f(0)\), giving \(2f(0)=0\). An even function only needs \(f(0)=f(0)\), which is no constraint at all; \(f(x)=x^{2}+7\) works.

Lecture 4 — Transformations: moving a shape around

Cartoon: pushing a graph the wrong wayA stick figure pushes an arrow to the left while the parabola beside them has moved to the right. I pushed it LEFT.
inside changes never do what you just did

There are only a handful of function shapes worth memorising. Everything else is one of those shapes, moved. Learning to see a complicated formula as a simple graph that has been shifted, flipped or rescaled is one of the highest-value skills in this course, because it turns algebra you would have to compute into geometry you can see.

There are exactly five things you can do, and it pays to meet them one at a time before meeting them together. Throughout this section \(f\) is the dashed curve — some function, it does not matter which — and the solid curve is what happens to it.

1. Vertical shifts

Adding a constant to the output raises every point by that amount.

Vertical shiftsThe dashed curve is the original function. On the left it has been moved up two units; on the right, down one unit. The shape is identical in both; only its height has changed. y = f(x) + 2y = f(x) − 1
Add to the output and every point rises by the same amount. Nothing about the shape changes — the whole picture is carried straight up or straight down.
definition

The graph of \(y=f(x)+d\) is the graph of \(f\) shifted up by \(d\) units when \(d>0\), and down by \(|d|\) units when \(d<0\).

spot check
The graph of \(f\) has its lowest point at \((1,-2)\). Where is the lowest point of \(y=f(x)+5\)?

This is the easiest one, because it does exactly what it says. The domain is unchanged; the range moves by \(d\).

2. Horizontal shifts

Changing the input before the function sees it moves the graph sideways — and in the direction most people do not expect.

Horizontal shiftsThe dashed curve is the original. On the left it has been moved one unit right by replacing x with x minus one; on the right, two units left. y = f(x − 1)y = f(x + 2)
Subtracting inside moves the graph right, which feels backwards until you ask what the machine sees: to get the old output at 0 you must now feed in \(x=1\), so every feature arrives one unit later.
definition

The graph of \(y=f(x-c)\) is the graph of \(f\) shifted right by \(c\) units when \(c>0\), and left by \(|c|\) when \(c<0\).

spot check
Compared with the graph of \(f\), the graph of \(y=f(x+3)\) is…
idea — why inside feels backwards

Think of \(f\) as a machine and the change as an interception. In \(y=f(x-1)\), whatever you type in gets 1 subtracted from it before the machine ever sees it. So to make the machine produce the output it used to produce at 0, you now have to type in 1. Every feature of the graph arrives one unit later, which means the picture slides to the right.

Outside changes happen to the answer, after the work is done, so they behave straightforwardly. Inside changes happen to the question. That distinction is worth holding on to: it explains reflections and stretches too, and it is the same reason the inverse of "add 3 then double" is "halve then subtract 3".

3. Reflections

A minus sign flips the graph. Which axis it flips across depends on whether the minus sign is outside or inside.

ReflectionsOn the left the curve has been flipped upside down across the horizontal axis. On the right it has been flipped left to right across the vertical axis. y = −f(x)y = f(−x)
A minus sign outside negates every output, tipping the graph over the \(x\)-axis. A minus sign inside negates every input, so what happened at \(x=2\) now happens at \(x=-2\).
definition

\(y=-f(x)\) reflects the graph across the \(x\)-axis: every output changes sign.

\(y=f(-x)\) reflects the graph across the \(y\)-axis: every input changes sign.

spot check

\(y=f(-x)\) reflects the graph across the , because the minus sign changes every .

This gives a neat restatement of Lecture 3. An even function is one that is unchanged by a horizontal reflection, since \(f(-x)=f(x)\). An odd function is one for which the two reflections give the same result, since \(f(-x)=-f(x)\).

4. Vertical stretching and shrinking

Multiplying the output scales every height.

Vertical stretching and shrinkingOn the left every height has been doubled, making the curve taller. On the right every height has been halved, flattening it toward the horizontal axis. y = 2 f(x)y = ½ f(x)
Multiplying the output scales every height by the same factor. Points on the \(x\)-axis do not move, because twice zero is still zero — that axis is the anchor line of a vertical stretch.
definition

The graph of \(y=a\,f(x)\) is the graph of \(f\) stretched vertically by a factor of \(|a|\). If \(|a|<1\) the stretch is a shrink toward the \(x\)-axis, and if \(a<0\) there is also a reflection across the \(x\)-axis.

spot check

\(f(2)=3\). What is the value of \(y=4f(x)\) at \(x=2\)?

decimals, fractions, pi and sqrt( ) are all fine

Zeros stay put. Wherever the graph crossed the \(x\)-axis it still does, because multiplying zero by anything leaves zero — so a vertical stretch pulls the curve away from that axis without ever moving the points on it.

5. Horizontal stretching and shrinking

Multiplying the input rescales the \(x\)-direction, and once again the effect is the reciprocal of what the number looks like.

Horizontal stretching and shrinkingOn the left the curve has been squeezed toward the vertical axis into half its width. On the right it has been stretched to twice its width. y = f(2x)y = f(½x)
Multiplying the input by 2 makes the function reach each stage of its shape twice as soon, so the picture is squeezed horizontally — again the opposite of what the number suggests. The \(y\)-axis is the anchor line here.
definition

The graph of \(y=f(bx)\) is the graph of \(f\) compressed horizontally by a factor of \(|b|\). If \(|b|<1\) the compression is a stretch away from the \(y\)-axis, and if \(b<0\) there is also a reflection across the \(y\)-axis.

spot check

\(f(6)=10\). For \(y=f(3x)\), which input \(x\) produces the output 10?

decimals, fractions, pi and sqrt( ) are all fine

Chapter 4 gives this one a name you will use constantly: for a wave, \(b\) controls the period, and a larger \(b\) means the pattern repeats more often in the same space.

example 1.19 — one change at a time

The point \((3,5)\) lies on the graph of \(f\). Where does it end up on each of \(y=f(x)+4\), \(y=f(x-4)\), \(y=-f(x)\), \(y=f(-x)\), \(y=3f(x)\) and \(y=f(3x)\)?

transformationnew pointwhat moved
\(f(x)+4\)\((3,9)\)output raised by 4
\(f(x-4)\)\((7,5)\)input must be 4 larger to give the same output
\(-f(x)\)\((3,-5)\)output negated
\(f(-x)\)\((-3,5)\)input negated
\(3f(x)\)\((3,15)\)output tripled
\(f(3x)\)\((1,5)\)input only needs to be a third as large

Tracking a single point is the fastest way to check a transformation, and it never lies. If you are ever unsure which way a graph moved, take one point you know and ask what input is now needed to produce its output.

Putting them together

Now all five at once. The general form is

$$y=a\,f\big(b(x-c)\big)+d,$$

with \(a\) and \(d\) acting on the output and \(b\) and \(c\) acting on the input. Order matters when you apply them by hand: work from the inside out, exactly as the machine does — horizontal shift and stretch first, then the vertical ones.

summary
acts oneffectwatch out
\(+\,d\)outputshift up—
\(-\,c\) insideinputshift rightopposite sign
\(a\,\times\)outputstretch verticallynegative also flips
\(b\,\times\) insideinputsqueeze horizontallyreciprocal, and negative also flips

Move the shape

The faint curve is the parent function; the bright one is \(a\,f(b(x-c))+d\). Change one slider at a time until each has a feel to it.

example 1.20

Describe how to obtain the graph of \(y=-2\sqrt{x+3}+1\) from the graph of \(y=\sqrt{x}\), in the correct order.

Read it from the inside out, because that is the order the machine works in.

  1. \(\sqrt{x+3}\): shift left 3 (the input is intercepted and increased).
  2. \(2\sqrt{x+3}\): stretch vertically by 2.
  3. \(-2\sqrt{x+3}\): reflect across the \(x\)-axis.
  4. \(-2\sqrt{x+3}+1\): shift up 1.

The starting point of the graph moves from \((0,0)\) to \((-3,1)\), and the curve now falls instead of rising. Check with a single value: at \(x=1\), \(y=-2\cdot2+1=-3\).

Combining functions

Given two functions you can add, subtract, multiply and divide them pointwise: \((f+g)(x)=f(x)+g(x)\), and so on. The domain of the combination is where both are defined — and for the quotient, also where \(g(x)\neq0\).

definition

The composition of \(f\) and \(g\) is $$(f\circ g)(x) = f(g(x)),$$ read "\(f\) after \(g\)": run \(g\) first, then feed its output into \(f\). Its domain is the set of \(x\) in the domain of \(g\) whose output \(g(x)\) lies in the domain of \(f\).

spot check

\(f(x)=x^{2}\) and \(g(x)=x+1\). Find \((f\circ g)(2)\).

decimals, fractions, pi and sqrt( ) are all fine

Composition drawn as two machines in series An input x enters machine g, whose output g of x enters machine f, producing f of g of x. x g g(x) f f(g(x)) the composite f ∘ g
Order matters. Putting on socks then shoes is a different function from shoes then socks, and only one of them is comfortable.
example 1.21

Let \(f(x)=x^2\) and \(g(x)=x-3\). Find \(f\circ g\) and \(g\circ f\), and evaluate both at \(x=5\).

\((f\circ g)(x)=f(x-3)=(x-3)^2\). At 5: \(4\).

\((g\circ f)(x)=g(x^2)=x^2-3\). At 5: \(22\).

Composition is not commutative. This is not a technicality — it is the reason matrix multiplication in Chapter 7 is not commutative either, since matrices are functions being composed.

example 1.22 — decomposition

Write \(H(x)=\sqrt{4+3x^2}\) as a composition of simpler functions.

Ask what you would do first with a calculator: square, multiply by 3, add 4, take the root. So with \(g(x)=4+3x^2\) and \(f(u)=\sqrt u\), we get \(H=f\circ g\). You could go further and split \(g\) itself into three steps. Decomposing like this is exactly what the chain rule will ask of you next year.

idea

Composition is how complexity is built out of simplicity everywhere in mathematics and in computing. A neural network with twelve layers is twelve functions composed. A photo filter is a composition. A proof is a composition. It is also how complexity is tamed: faced with something intricate, the first move of a mathematician is to ask which simple steps it is made of, and in what order.

example 1.23 — match the graph to the formula

Each panel below is the parabola \(y=x^2\) after one transformation. Match them to \(y=(x-2)^2\), \(y=x^2-2\), \(y=-x^2+3\), \(y=(2x)^2\).

Four transformed parabolas Panel A shows a parabola with its lowest point at x equals two. Panel B shows one sitting two units below the origin. Panel C shows one opening downward with its top three units up. Panel D shows a narrow parabola at the origin. ABCD

A is \(y=(x-2)^2\) — the whole curve slid right, because the input was intercepted and reduced by 2 before the squaring happened.

B is \(y=x^2-2\): the subtraction happens after the squaring, so it moves the output down.

C is \(y=-x^2+3\): the minus sign flips it, the \(+3\) lifts it.

D is \(y=(2x)^2\): every input is doubled before squaring, so the curve reaches any given height twice as soon — it looks squeezed horizontally. (It is also \(4x^2\), a vertical stretch by 4. For parabolas the two descriptions coincide; for most functions they do not.)

The reliable way to tell inside from outside: ask whether the change reaches the input before \(f\) does. Inside changes move the graph horizontally and do the opposite of what they look like. Outside changes move it vertically and do exactly what they say.

example 1.24 — a photo filter, in two orders

A photo app has two operations: \(B(v)=v+40\) raises every pixel's brightness by 40, and \(S(v)=1.5v\) increases contrast by scaling it. Pixel values are capped at 255. Take a pixel at \(v=150\) and apply the two operations in each order.

Brighten then contrast: \(S(B(150))=1.5(190)=285\), which caps at 255 — blown out to pure white, and the detail that was in that pixel is gone forever.

Contrast then brighten: \(B(S(150))=225+40=265\), also capped. Try \(v=100\) instead: \(S(B(100))=210\) but \(B(S(100))=190\). Different pictures.

Composition is not commutative, and here the difference is visible to the eye. This is exactly why photo editors have a layer order, and why every image processing pipeline is a carefully chosen sequence rather than a bag of effects.

example 1.25 — three machines in a row

A contractor is paid in euros. The bank converts euros to dollars at \(c(e)=1.08e\), then charges a flat \$5 wire fee, \(w(d)=d-5\), and finally tax withholding takes 22%, \(t(d)=0.78d\). The payment is 2,000 euros. Write the whole trip as one composition and compute what lands in the account.

The bank applies them in the order stated, so the composite is \(t(w(c(e)))\), read right to left: $$t(w(c(2000)))=t(w(2160))=t(2155)=\$1680.90.$$

Now suppose the tax were taken before the fee: \(w(t(c(2000)))=w(1684.80)=\$1679.80\). A dollar and ten cents apart, from nothing but the order.

Writing the composite as a single formula, \(0.78(1.08e-5)=0.8424e-3.90\), shows something worth noticing: a chain of linear steps collapses into one linear step. That is a small miracle, and Chapter 7 explains it — it is the reason a stack of matrix layers with nothing nonlinear between them is just one matrix, and therefore the reason neural networks need activation functions at all.

exercises 1.4
  1. Starting from \(y=|x|\), describe the graph of: (a) \(y=|x-4|\); (b) \(y=|x|-4\); (c) \(y=-|x+1|+3\); (d) \(y=|2x|\) — and explain why (d) can also be described as a vertical stretch.
  2. The graph of \(f\) has a local maximum at \((2,5)\). Where is the corresponding point on the graph of \(y=-3f(x-1)+2\)?
  3. Let \(f(x)=\sqrt{x}\) and \(g(x)=x-1\). Find \(f\circ g\), \(g\circ f\), \(f\circ f\), and the domain of each.
  4. Let \(f(x)=\dfrac1x\) and \(g(x)=x+2\). Find \((f\circ g)(x)\) and state its domain carefully.
  5. Express \(F(x)=\dfrac{1}{(x+3)^{4}}\) as a composition of three functions.
  6. If \(f\) is even and \(g\) is odd, what can you say about \(f\circ g\)? Prove it.
  7. Let \(f(x)=0.9x\), the effect of one year of 10% depreciation. Compute \(f(f(x))\) and \(f(f(f(x)))\), find a formula for applying \(f\) \(n\) times, and use it to say what fraction of the value survives ten years. Why is the answer not zero?
  1. (a) the V slides right 4; (b) it slides down 4; (c) left 1, turned upside down, up 3; (d) \(|2x|=2|x|\), so squeezing horizontally by 2 and stretching vertically by 2 give the same picture here. That coincidence holds for \(|x|\) and for power functions and fails for most other families — try it on \(y=x+1\).
  2. Inside: shift right 1, so \(x=3\). Outside: multiply by \(-3\) then add 2, so \(y=-3(5)+2=-13\). A local maximum becomes a local minimum, at \((3,-13)\).
  3. \((f\circ g)(x)=\sqrt{x-1}\), domain \([1,\infty)\); \((g\circ f)(x)=\sqrt x-1\), domain \([0,\infty)\); \((f\circ f)(x)=\sqrt{\sqrt x}=x^{1/4}\), domain \([0,\infty)\).
  4. \(\dfrac{1}{x+2}\), domain all \(x\neq-2\).
  5. \(h(x)=x+3\), then \(k(u)=u^4\), then \(m(v)=1/v\): \(F=m\circ k\circ h\), with \(x\neq-3\).
  6. \(f(g(-x))=f(-g(x))=f(g(x))\), using odd then even. So \(f\circ g\) is even.
  7. \(f(f(x))=0.81x\) and \(f(f(f(x)))=0.729x\); in general \(n\) applications give \(0.9^{n}x\). After ten years \(0.9^{10}\approx0.349\), so about 35% survives. Repeatedly removing a proportion never reaches zero, since each year takes a tenth of a smaller amount. That is the shape of exponential decay, and Chapter 3 is about it.

Lecture 5 — One-to-one functions, inverses, and codes

Cartoon: a shredder as a function that cannot be undoneA stick figure holds a shredder with paper strips falling out. Another asks whether it can be undone. Can you undo it?SHRED
“No. That is what it is for.”

Every function throws information away, or it does not. That single distinction — whether the output still contains enough to reconstruct the input — turns out to be one of the most consequential ideas in mathematics, and the rest of the course keeps returning to it: it is invertibility in Chapter 3, it is the determinant in Chapter 7, and it is what a compression algorithm is doing on purpose.

definition

A function \(f\) is one-to-one if different inputs always give different outputs: whenever \(x_1\neq x_2\), we have \(f(x_1)\neq f(x_2)\).

Equivalently, and more usefully in practice: if \(f(x_1)=f(x_2)\) then \(x_1=x_2\).

spot check
Which of these is one-to-one on all of \(\mathbb{R}\)?

Graphically this is the horizontal line test: no horizontal line may meet the graph more than once. Compare it with the vertical line test, which asks whether you have a function at all. The vertical test is about the definition; the horizontal test is about whether the definition can be run backwards.

The horizontal line test On the left, y equals x squared: the horizontal line at height 1.44 meets the curve twice, at x equals minus 1.2 and plus 1.2, so two inputs share an output. On the right, a curve that rises everywhere: every horizontal line meets it exactly once. two inputs, one output: information is lost one input per output: reversible
\(f(x)=x^2\) is not one-to-one on all of \(\mathbb{R}\): the output 9 cannot tell you whether the input was 3 or \(-3\). That fact is not a defect of the formula; it is a statement about how much the output remembers.
definition

If \(f\) is one-to-one with domain \(A\) and range \(B\), its inverse \(f^{-1}\) is the function with domain \(B\) defined by $$f^{-1}(y)=x \iff f(x)=y.$$ It satisfies \(f^{-1}(f(x))=x\) and \(f(f^{-1}(y))=y\): each undoes the other.

Warning: \(f^{-1}\) does not mean \(1/f\). The notation is unfortunate and universal.

spot check

\(f(x)=3x-6\). What is \(f^{-1}(0)\)?

decimals, fractions, pi and sqrt( ) are all fine

Finding an inverse

The procedure is three lines: write \(y=f(x)\), solve for \(x\), then swap the names. Swapping the names is what reflects the graph across the line \(y=x\), since the point \((a,b)\) on \(f\) becomes \((b,a)\) on \(f^{-1}\).

A function and its inverse reflected across the line y equals x The curve y equals x squared for non-negative x, the curve y equals the square root of x, and the dashed line y equals x acting as a mirror between them. (2, 4)(4, 2) y = x² y = √x y = x
Reflecting across \(y=x\) swaps the roles of input and output. Note that we had to restrict \(x^2\) to \(x\ge0\) to get an inverse at all — and that restriction is exactly why \(\sqrt{9}\) means 3 and not \(-3\).
example 1.26

Find the inverse of \(f(x)=\dfrac{2x+3}{x-1}\), and state the domain and range of both.

Set \(y=\dfrac{2x+3}{x-1}\) and solve for \(x\): $$y(x-1)=2x+3 \Rightarrow yx-y=2x+3 \Rightarrow x(y-2)=y+3 \Rightarrow x=\frac{y+3}{y-2}.$$ So \(f^{-1}(x)=\dfrac{x+3}{x-2}\).

\(f\) has domain \(x\neq1\) and range \(y\neq2\); the inverse swaps these, with domain \(x\neq2\) and range \(y\neq1\). Domain and range always trade places, which is a good check on your work.

example 1.27 — buying back invertibility

\(f(x)=x^2\) has no inverse. Fix it.

Restrict the domain to \([0,\infty)\). On that smaller domain \(f\) is one-to-one and the inverse is \(f^{-1}(x)=\sqrt x\). Restricting to \((-\infty,0]\) instead gives the inverse \(-\sqrt x\), which is equally valid and a different function.

Nothing about \(x^2\) changed. We changed the question. This move — shrink the domain until the function becomes reversible — is exactly how the inverse trigonometric functions of Chapter 4 are defined, and it is the reason your calculator returns only one answer for \(\arcsin\).

Codes: sending information through a channel

A code is a function. Encoding is applying it; decoding is applying its inverse. A code that is not one-to-one is not a code — it is a shredder.

Encode, then decode

A shift cipher moves every letter along the alphabet by a fixed amount and wraps around. Type a message, choose a shift, and confirm that decoding recovers exactly what you started with. Then press the lossy button and try again.

spot check

A shift cipher with \(k=3\) moves each letter three places along the alphabet. What does the letter X become?

one letter

idea

Some functions destroy information by accident, and some do it on purpose. A JPEG throws away detail your eye is bad at noticing and keeps what it is good at; that is why the file is a tenth the size, and why there is no button anywhere that restores the original. An audio compressor does the same to sound. A hash function is designed so that inverting it is not merely impossible in principle but expensive in practice, which is what protects your password.

So the question is this function one-to-one? is never idle. It is the question of whether anything can be undone: a message decoded, a signal recovered, a system of equations solved, a matrix inverted. You will ask it in every remaining chapter.

history

Shift ciphers are named for Julius Caesar, who according to Suetonius used a shift of three for military correspondence. They were secure for roughly nine hundred years, until the polymath al-Kindi, working in ninth-century Baghdad — the same intellectual world that gave us the word algebra — wrote the first known account of frequency analysis: count how often each symbol appears, compare with the natural frequencies of the language, and the shift falls out immediately.

That is a striking thing to notice. Al-Kindi's attack works because the code preserves too much structure. Being one-to-one makes a code usable; it does not make it safe.

example 1.28 — shoe sizes

European and US shoe sizes are related by \(E(u)=1.27u+30.8\), rounded to the nearest half size. What should someone who wears a US 10.5 ask for in Milan? And if a shop says a shoe is EU 39, what is that in US sizes?

\(E(10.5)=1.27(10.5)+30.8=44.1\), so EU 44.

For the reverse, invert: \(e=1.27u+30.8 \Rightarrow u=\dfrac{e-30.8}{1.27}\), so \(E^{-1}(39)=\dfrac{8.2}{1.27}\approx 6.5\).

Notice the rounding, though. \(E\) is one-to-one as a formula on the reals, but the rounded version is not: US 10.4 and US 10.5 both land on EU 44. The inverse of the rounded function does not exist, which is precisely why converted sizes never quite fit and why every shop tells you to try them on.

example 1.29 — deliberately impossible to undo

A website stores your password by applying a function \(H\) and keeping only the output. When you log in, it applies \(H\) to what you typed and compares. Why is it important that \(H\) is not invertible in practice — and why must it still be a function?

It must be a function because the same password must always produce the same output; otherwise you could never log in twice.

It must be hard to invert because the stored outputs will eventually be stolen. If \(H\) could be run backwards, the thief would have every password. A hash is chosen so that going forwards is instant and going backwards is, as far as anyone knows, hopeless — even though an inverse exists in the abstract for any one-to-one \(H\).

So there are three grades of undoability worth keeping separate: invertible (a shift cipher — run it backwards in a second), not invertible at all (the genetic code, or a function that maps many inputs to one output), and invertible in principle but not in this universe (a cryptographic hash). Modern security lives entirely in that third category.

example 1.30 — can it be undone?

For each, decide whether the process is one-to-one, and say what is lost if not.

  1. Translating a sentence into Morse code.
  2. Converting a colour photo to greyscale.
  3. Sorting a list of numbers into increasing order.
  4. Multiplying by 6 and subtracting 1.
  5. Taking a student's numerical score and reporting a letter grade.

(a) One-to-one, with a catch: with the gaps between letters preserved, yes. Strip the gaps and it is not — the same dot-dash stream can be read several ways.

(b) Not one-to-one. Three numbers per pixel become one, so an enormous amount of information is discarded; no "uncolourise" button can be honest, only a plausible guess.

(c) Not one-to-one: the order was thrown away, and \([3,1,2]\) and \([2,1,3]\) sort to the same list.

(d) One-to-one, inverse \(\dfrac{x+1}{6}\).

(e) Not one-to-one, deliberately: 91 and 97 both become A. That is the purpose of grades — to discard detail that we judge not worth carrying. Every summary statistic you will ever compute is a non-invertible function, and the whole craft is choosing what to lose.

exercises 1.5
  1. Which are one-to-one on all of \(\mathbb{R}\)? (a) \(3x-7\); (b) \(x^2+1\); (c) \(x^3\); (d) \(|x|\); (e) \(x^3+x\).
  2. Find the inverse: (a) \(f(x)=5x-2\); (b) \(g(x)=x^3+4\); (c) \(h(x)=\dfrac{1}{x+2}\); (d) \(k(x)=\sqrt{x-1}\), \(x\ge1\).
  3. Verify for 2(a) that \(f^{-1}(f(x))=x\) and \(f(f^{-1}(x))=x\), both.
  4. The graph of a one-to-one \(f\) passes through \((1,4)\), \((2,7)\) and \((3,10)\). List three points on the graph of \(f^{-1}\), and guess a formula for \(f\).
  5. Encode HELLO with a shift of 5. Then decode WKLV LV D WHVW, given that it was shifted by 3.
  6. Show that \(f(x)=\dfrac{x+1}{x-1}\) is its own inverse. What does that say about the shape of its graph?
  7. Suppose \(f\) and \(g\) are both one-to-one. Prove that \(f\circ g\) is one-to-one, and show that \((f\circ g)^{-1}=g^{-1}\circ f^{-1}\). Explain the order in terms of socks and shoes.
  8. A shift cipher on 26 letters has 25 useful keys. Roughly how many messages must you try before breaking one by brute force? Now explain why frequency analysis is a better idea, and why modern encryption uses key spaces of size around \(2^{256}\).
  1. (a), (c) and (e) are one-to-one. (b) and (d) both fail: they give the same output for \(x\) and \(-x\).
  2. (a) \(\dfrac{x+2}{5}\); (b) \(\sqrt[3]{x-4}\); (c) \(\dfrac1x-2\); (d) \(x^2+1\) for \(x\ge0\).
  3. \(f^{-1}(f(x))=\dfrac{(5x-2)+2}{5}=x\), and \(f(f^{-1}(x))=5\cdot\dfrac{x+2}{5}-2=x\). Both are needed in general; one alone does not guarantee an inverse.
  4. \((4,1)\), \((7,2)\), \((10,3)\). The pattern suggests \(f(x)=3x+1\), so \(f^{-1}(x)=\dfrac{x-1}{3}\).
  5. MJQQT. The decoded message is THIS IS A TEST.
  6. Compute \(f(f(x))=\dfrac{\frac{x+1}{x-1}+1}{\frac{x+1}{x-1}-1}=\dfrac{(x+1)+(x-1)}{(x+1)-(x-1)}=\dfrac{2x}{2}=x\). Since \(f=f^{-1}\), the graph is its own reflection across \(y=x\): the mirror sends the curve to itself.
  7. If \(f(g(x_1))=f(g(x_2))\), then since \(f\) is one-to-one, \(g(x_1)=g(x_2)\); since \(g\) is one-to-one, \(x_1=x_2\). For the inverse, apply \(g^{-1}\circ f^{-1}\) to \(f(g(x))\) and watch it collapse to \(x\). Socks then shoes; to undo, shoes off first, then socks. The last thing done is the first thing undone.
  8. At most 25 — you can break it during a coffee break by hand. Frequency analysis needs no trials at all: one histogram of the ciphertext gives the key directly. Modern systems need key spaces so large that trying them all is physically impossible; \(2^{256}\) is larger than the number of atoms in the observable universe, which is the only kind of margin worth having.

Where this chapter leaves you

You now have the vocabulary the whole course runs on: a function as a rule moving information, a graph as its portrait, the translation between algebra and geometry, transformations as a way of seeing whole families at once, and invertibility as the question of whether anything was lost.

Chapter 2 asks the next question, and it is the one that opens calculus: not what does this function do, but how fast is it doing it. On the way it will ask how much a curve bends — which turns out to explain why folding a slice of pizza stops it flopping — and it will end by building complicated functions out of nothing but powers of \(x\), so that a machine with only arithmetic can compute a square root.

idea

It is worth saying plainly what calculus will and will not be. It is not a new subject that replaces this one. It is this one, with a single extra move performed at the end of every argument: let the step shrink.

You will compute an average rate of change over an interval; calculus lets the interval shrink to nothing and calls the result a derivative. You will estimate an area with rectangles; calculus lets the rectangles thin out and calls the result an integral. You will approximate a curve with a polynomial of degree three; calculus keeps going and calls the result a series. In every case the object you build here is the honest, computable, slightly-wrong version, and the limit is the icing.

That is also why we will not pretend the world is flat. Graphs bend, surfaces curve, and a shortest path on a sphere is not a straight line. You will meet the bending in Chapter 2 and again on the sphere in Chapter 5, long before anyone hands you the machinery for it — because the machinery is easier to want once you have already seen what it is for.

Next: Chapter 2 — Flat and curved functions.