A formula is a sentence
Every symbol in a formula stands for a word or two. Here is the average of numbers:
Read it aloud: "x-bar equals x-one plus x-two, and so on up to x-n, all divided by n." Once you can say a formula, you can write it in code.
| Symbol | Say it | It means |
|---|---|---|
| "n" | how many values there are | |
| "x one" or "x sub one" | the first value | |
| "x i" | the value in position | |
| "and so on" | the pattern carries on | |
| "x bar" | the average of the values |
Subscripts are positions
A subscript is a small number or letter written low and to the right. It labels a position in a list: is the first value, the second, and is "the -th one", whichever you pick.
Rule: Subscripts
Maths usually counts from 1. Python counts from 0. So is x[0], and is x[i - 1].
Try it
Take four values: , , , .
Their total is 43 and , so the average is . The cell checks it and shows the shift by one.
Sets and membership
A set is a collection of different objects, written inside curly brackets: . The objects are its elements. Order does not matter and repeats do not count, so is the same set as .
Rule: Membership
says " is an element of ". says it is not. With : and .
A few sets have their own letters, and they appear everywhere:
| Symbol | Name | What is in it |
|---|---|---|
| natural numbers | (some books start at 0) | |
| integers | ||
| real numbers | every point on the number line, such as , , | |
| closed interval | every real number from to , ends included | |
| open interval | every real number strictly between and |
Try it
Python has sets too, with the same curly brackets. The keyword in is the symbol .
The second print shows that repeats vanish. The last line counts the elements.
Set-builder notation: "such that"
Listing every element only works for small sets. Set-builder notation describes a set by a rule instead:
Read the colon as "such that": "the set of integers such that is between 1 and 10 and is even". Some books write a vertical bar instead of the colon. It means the same thing.
Rule: Set-builder notation
Everything in that passes the condition. The part before the colon says where to look. The part after says what to keep.
Try it
A Python set comprehension reads almost word for word like set-builder notation.
range(1, 11) gives the integers from 1 to 10, because a range stops just before its second number. x % 2 == 0 tests "x is even".
"For all" and "there exists"
Two symbols turn a condition into a statement that is true or false about a whole set.
Rule: Quantifiers
reads "for all". The statement is true when every element of passes the test . reads "there exists". It is true when at least one element passes.
With :
- is true. Every element is bigger than 1.
- is true, because of 7.
- is false. The single element 2 is enough to break it.
Try it
Python's all is and any is . Each line checks one statement from the list.
You will also read the word let. "Let be the number of values" gives a name to something, like n = len(x) in Python. "Let " means "assume is positive from here on".
Function notation
A function is a rule that turns each input into exactly one output. The formula names the rule and says what it does to an input : square it, then add 1.
Rule: Function notation
means "the output of when the input is 3". It is not times 3. To evaluate, replace every in the formula with the input.
The letter inside the brackets is only a placeholder. is the same function. The input can be an expression too: . Keep the brackets when you substitute.
You will also see . Read it as " takes a real number and gives back a real number". The set before the arrow holds the allowed inputs; outputs land in the set after it. Lesson 1.1.1 returns to this.
Try it
In Python a function is a def. The cell evaluates and .
Both give 10: two different inputs may share an output. What a function may not do is give two outputs for one input.
Common mistakes
Try it
- is not . With , , but .
- A subscript is a label, a superscript is a power. and are different things.
- Python counts from 0. The maths is
x[0], so the last of values isx[n - 1]. - Sets have no order and no repeats. , but the Python lists
[1, 2]and[2, 1]are different.
Symbols and functions
0 of 7 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
How to type answers
- Powers with
^:x^7,2^(1/3),a^-2. - Multiply with
*or by writing side by side:3x^2,2(x+1). ln(x)is the natural log,log(x, 2)is log base 2,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for sin²x.- Your first answer to each question is saved: it counts towards your score and brings the question back for review.
- Exact answers like
ln(20)/ln(3)are best. Decimals need about 4 significant figures.
Summary card
- is the value in position . Maths counts from 1 and Python from 0, so is
x[i - 1]. - A set lists different elements in curly brackets. means is in .
- means everything in that passes the condition. The colon reads "such that".
- is "for all" (
allin Python). is "there exists" (any). One counterexample breaks a "for all". - is the output of at input 3. Substitute with brackets: , not .