Introduction to Math

When someone says math, most people think about calculating something with numbers, e.g. "what is 6 times 7". You don't need to be good at that sort of things in order to read this tutorial. If we need something like that, we'll just calculate it using our favorite programming language or calculator, which is Python in my case, but you can use anything you want. Python calculates 6 * 7 a lot faster than you can or I can, and a lot more reliably.

>>> 6 * 7

Instead of boring number stuff, we'll look into formulas written with letters, like this one:

$$\begin{align}(a+b)c = ac + bc\end{align}$$

Memorizing these formulas is not the point. Instead, we'll derive these ourselves, prove that they work and do other stuff like that. It's called mathematics.

The above formula says that if you add two numbers and you multiply them by a third number (we write $ac$ instead of a*c in math, as explained later), you get the same result as if you had multiplied the first two numbers with the third number and added the results. Does it actually work?

>>> (1 + 2)*3   # left side: a=1, b=2, c=3
>>> 1*3 + 2*3   # right side: a=1, b=2, c=3
>>> (3 + (-2))*(-5)     # left side: a=3, b=-2, c=-5
>>> 3*(-5) + (-2)*(-5)  # right side: a=3, b=-2, c=-5

It seems to work. This is important: now we know for sure that it works for some $a$, $b$ and $c$ values, but we don't know for sure if it works for all values. Maybe there are some special $a$, $b$ and $c$ that break it? You can easily create a for loop that tries this formula with many different values, but what if you forgot to check for some very special value? Trying out different values isn't the thing to do it in math, and instead we need things that you'll learn in this tutorial.

<Zaab1t>     if n is even
<Zaab1t>     is a**n then equal to a**(n/2) * a**(n/2)
<Akuli>      yes
<laplous3>   on the surface that seems reasonable, but how do you actually
             prove something like that?
<laplous3>   <- doesn't have a breeze what's involved in proving something
<laplous3>   I mean, I suppose picking arbitrary numbers and showing it
             works doesn't cut it right

Variable Names and Notation Stuff

If you are a programmer, you already know what a variable is. The concept is quite similar in math.

Mathematicians like single-letter variable names. It's bad style in most programming languages, but if you look at this...

$$\begin{align}(a+b)c = ac + bc\end{align}$$

...then how would you name the variables, if you wanted to avoid single-letter variable names? Maybe like this:

(first_number + second_number)*third_number = first_number*third_number + second_number*third_number

It is much longer now, and not any easier to read. The variables don't have a specific meaning in the formula. Each of them represents a number, and it's hard to come up with better variable names than the ones above. Also, math was originally written by hand, and writing things like third_number by hand would be really annoying.

In math, we can define variables like this:

Let $a=5$.

But in the case of $(a+b)c=ac+bc$ we don't know the values of $a$, $b$ and $c$ yet, so we might define those like this:

Let $a$, $b$ and $c$ be real numbers.

A real number means any number between $-\infty$ and $\infty$, but not $-\infty$ or $\infty$; that is, pretty much any number you can think of, like $2$, $0.1$, $3.14159$, $-5$ or $1000000$. We say "real number" to make a difference between other kinds of numbers; for example, "let $n$ be an integer" means that $n$ can be $2$ or $-5$ or $1000000$, but not $0.1$ or $3.14159$.

Mathematicians are lazy, so usually we don't want to write out "let $x$ be a real number" (think about writing by hand) every time we want to work with numbers. We can do better by abbreviating "real numbers" as "reals"...

Let $a$, $b$ and $c$ be reals.

...but instead, we make it even shorter:

Let $a,b,c \in \mathbb{R}$.

That's a mess! Let me explain how to read it:

Real numbers don't have anything to do with things that we can measure in real life. If we say "let $x=2$", we don't mean that $x$ is 2 inches or metres or whatever. It's $2$. This is also true when we draw stuff; it's perfectly normal to draw a rectangle like this:

The rectangle's width is 3 and its height is 2, and therefore its area is 6. It is not 3 inches wide or 2 inches high, and its area is not 6 square inches. If we use the math for something practical, then we need inches and centimeters and pixels and other stuff, but the math itself is written without that.

A note about $ab$ and a*b: if I had written something like $a \cdot c + b \cdot c$ you would need to think about that for a while. What was the operator precedence again? Oh right, multiplication is done first, so we have $(a \cdot c)+(b \cdot c)$. That's bad because I want to let you focus on important things instead of notation details, and $ac+bc$ is better; you can see right away what it means because the multiplied things are closely together.

Finally, here is some boring but important stuff. You probably know what $a < b$ and $a > b$ mean, but we also use these things in math:

Proofs and Axioms

Here is a proof of $(a+b)c = ac + bc$. The proof works only if $c \in \{1,2,3,...\}$, because otherwise it doesn't make sense to add a number to itself $c$ times. We'll talk about other $c$ values soon.

$$\begin{align}(a+b)c &= \underbrace{(a+b)+(a+b)+...+(a+b)}_{c\text{ times}} \\ &= \underbrace{a+b+a+b+...+a+b}_{ a\text{ repeated }c\text{ times, }b\text{ repeated }c\text{ times}} \\ &= \underbrace{a+a+...+a}_{c\text{ times}} + \underbrace{b+b+...+b}_{c\text{ times}} \\ &= ac + bc\end{align}$$

The point with proofs is that you don't believe things because they are in a book, but because the proof convinces you that the formulas actually work like they're supposed to work.

First of all, if you want to prove that $x=y$, the most basic way to do it is to start with $x$, and do some stuff to it until you end up with $y$. That's what we did above.

The above proof relies on a few facts that you probably know already, and we can't do the proof without these "basic facts":

That's all there is to our proof. But we assumed that $c \in \{1,2,3,...\}$. Let's see if the thing works with a different $c$:

>>> (1+2)*0     # left side: a=1, b=2, c=0
>>> 1*0 + 2*0   # right side: a=1, b=2, c=0
>>> (3+4)*(-3.14)           # left side: a=3, b=4, c=-3.14
>>> 3*(-3.14) + 4*(-3.14)   # right side: a=3, b=4, c=-3.14

Again, it seems to work and we can guess that it will work, but how do we prove it this time? I thought about this for a while and struggled with it, and turns out that we can't really do it with the "basic facts" I listed above. The $(a+b)c=ac+bc$ thing itself is yet another "basic fact" that we need to take for granted in order to get anything done. These "basic facts" are called axioms, and you can google something like "axioms of real numbers" to get a complete list if you want. There are a few more than the ones we saw here, but not many.

Proof Techniques

If you want to prove that $\green x=\blue y$, you can try to simplify $\green x$ and get $\blue y$, or you can simplify $\blue y$ and try to get $\green x$. Alternatively, if you simplify $\green x$ and get a third thing $\maroon z$, you can try to simplify $\blue y$; if you also get the same $\maroon z$ from that, you know that $\green x=\maroon z$ and $\blue y=\maroon z$, and so $\green x=\blue y$. For example, to prove this...

$$\begin{align}(1+2) \cdot 3 = 1 \cdot 3 + 2 \cdot 3\end{align}$$

...without the $(a+b)c$ axiom, you can do this:

$$\begin{align}\green{(1+2) \cdot 3} = 3 \cdot 3 = \maroon9 \\ \blue{1 \cdot 3 + 2 \cdot 3} = 3 + 6 = \maroon9\end{align}$$

If you want to prove that something is false, all you need to do is to give an example of the thing not working. For example, if you want to prove that this is false...

For all $a,b,c \in \mathbb{R}$, $(a+b)c=a+bc$.

...all you need to do is to plug in some values:

>>> (1+2)*3
>>> 1 + 2*3

Here is the proof that the above statement is false:

$(1+2) \cdot 3 = 3 \cdot 3 = 9 \ne 7 = 1+6 = 1+(2 \cdot 3)$

We found such $a,b,c$ that $(a+b)c \ne a+bc$.

So far we have talked about proving that something is true for all $a$, $b$ and $c$ values, but what if you need to prove that there is some number or combination of numbers that satisfies a thing? For example, what if you want to prove this statement?

There is a number $x \in \mathbb{R}$ so that $2x = 6$.

Here is the proof:

$2 \cdot 3 = 6$, so $3$ is the number.

Well, that was easy.

Here's yet another powerful technique: proof by contradiction. If you want to prove something, you can assume that what you want to prove is false, and see what happens; if you end up with nonsense like $1=2$, the assumption was wrong, and what you're trying to prove must then be correct.

For example, let's prove this statement...

There are no positive reals $a$ and $b$ so that $a+b=0$. this:

Let $a,b \in \mathbb{R}$ and $a,b > 0$. Let's assume $a+b=0$. Substracting $b$ on both sides gives $a+b-b=0-b$; that is, $a=-b$. $b$ is positive, so $-b$ is negative, and $a$ is also negative because it's $-b$. This is not possible because we just said that $a$ is positive. Our assumption gave us nonsense, so it must be false. This means that there are no positive $a$ and $b$ so that $a+b=0$, which is what we wanted.

Of course, you don't need to write down that much text every time. This is enough:

Let $a,b \in \mathbb{R}$ and $a,b > 0$. If $a+b=0$, then $a = -b < 0$, which is a contradiction.

Simplification Techniques

In this tutorial, division is usually not written as $a/b$; it is almost always $\frac a b$, and later you'll find that much nicer to work with.

Let $a,b,c,d,e,x,y,z \in \mathbb{R}$. The things I'm about to show can be proved with axioms of reals.

For every $a$, there is a number $-a$ such that $a + (-a) = 0$. If $a$ is positive, then $-a$ is negative, and vice versa. On a number line, this looks like flipping to the other side. In this picture, $a$ is positive and $b$ is negative:

Substraction $a-b$ actually means $a + (-b)$.

A similar thing happens with division: for any real number $a$ except $0$ (we'll talk about dividing by $0$ soon), $\frac 1 a$ is a number that gives 1 when you multiply it by $a$:

$$\begin{align}a + (-a) &= 0 \\ a \cdot \frac 1 a &= 1, \qquad a \ne 0\end{align}$$

As you can see, adding and multiplying rules look similar, but some of them are slightly different.

If you add together many things, you can put them to any order you want. The same thing works with multiplying.

$$\begin{align}a+b+c+d+e &= e+d+a+c+b \\ abcde &= edacb\end{align}$$

If we combine this with the $a-b=a+(-b)$ thing, we'll notice that we can order $+\text{something}$ and $-\text{something}$ things however we want. For example:

$$\begin{align}a-b-c &= a + (-b) + (-c) \\ &= (-c) + a + (-b) \\ &= -c+a-b\end{align}$$

It works the same way with more things too:

$$\begin{align}\red{a} \blue{+b} \green{-c} \maroon{+d} \color{black}{-e} = \color{black}{-e} \maroon{+d} \red{+a} \green{-c} \blue{+b}\end{align}$$

Note that $a = +a$.

With multiplication and division, you can also reorder things however you want, as long as things under the horizontal line are being divided, and things above it are being multiplied.

$$\begin{align}a \cdot \frac{b}{c} \cdot \frac{d}{e} = \frac{abd}{ce}\end{align}$$

The $a$ goes to top because $\frac b c=b\frac 1 c$, and so $a\frac b c = ab\frac 1 c=\frac{ab}{c}$.

In the above math, $c$ and $e$ must not be $0$ because you can't divide by zero.

<laplous3>   when you divide by 0 you get theelous3
<laplous3>   it's a sort of math black hole

Division $\frac x y$ is essentially "I want a number that gives $x$ when I multiply it by $y$":

$$\begin{align}\frac{x}{y}y = x\end{align}$$

Division by zero is saying "I want a number that gives $x$ when I multiply it by zero". If you multiply a number by zero, you always get zero:

$$\begin{align}0z = 0 \qquad \text{for all } z \in \mathbb{R}\end{align}$$

So, saying $z = \frac x 0$ means $0z = x$, which never works if $x \ne 0$. However, if $x=0$, it works for any $z$. In other words, it seems like $\frac 0 0$ can be anything. That doesn't really make sense either, but later we'll see that if we are getting $\frac 0 0$, we don't know what the answer should be based on just that, and we need to go back and look at where the $\frac 0 0$ came from. Usually there's a way to do whatever we're trying to do so that we can avoid $\frac 0 0$, but if you get $\frac x 0$ with $x \ne 0$, you probably did something wrong.

Sometimes things cancel out nicely:

$$\begin{align}\red{x}+y\red{-x} = y\end{align}$$

We're adding the $x$ and taking it away, so after all the $x$ goes away completely, no matter what the value of $x$ is. It works similarly with multiplication and division:

$$\begin{align}\frac{ \red{x} y }{ \red{x} } = y\end{align}$$$$\begin{align}\frac{ ab\red{c}d\blue{e} }{ \red{c}\blue{e}xy} = \frac{abd}{xy}\end{align}$$

Sometimes it's useful to use this canceling rule right-to-left and add more stuff:

$$\begin{align}\frac{ a\blue c }{ b\blue c } &= \frac a b \\ \frac a b &= \frac{ a\blue c }{ b\blue c }\end{align}$$

The "backwards canceling" thing also works with $+$ and $-$; sometimes it's useful to look at $y$ as $y+x-x$ or something like that.

Be aware of mixing adding and multiplying rules. They don't mix very well, for example:

$$\begin{align}\frac{a+b}{2} c = \frac{a+bc}{2} \qquad \red{\text{wrong!}}\end{align}$$

The problem is that with multiplying and dividing, we need to treat $a+b$ as one thing; if we had $ab$ on the top instead of $a+b$, then $a$ and $b$ would be multiplied with the other stuff as we've seen before, but now the $a+b$ as a whole is being multiplied with the other stuff. We need to do this instead:

$$\begin{align}\frac{a+b}{2} c = \frac{(a+b)}{2} c = \frac{(a+b)c}{2}\end{align}$$

Of course, you can skip the middle step if you like:

$$\begin{align}\frac{a+b}{2} c = \frac{(a+b)c}{2}\end{align}$$

The same thing happens with $a-b$ instead of $a+b$.

Also, when doing the multiplication-division canceling, you can only cancel multipliers; that is, things that we're multiplying everything by:

$$\begin{align}\frac{ \red{2}+b }{ \red2 } = b \qquad \red{\text{wrong!}}\end{align}$$

The problem is that $2+b$ is not $2 \cdot \text{something}$, so $2$ is not a multiplier here and it can't be cancelled. However, if we have $2b$ instead of $b$, we can use $(a+b)c=ac+bc$ backwards with $c=2$ and then cancel:

$$\begin{align}\frac{2a+2b}{2} = \frac{ (a+b)\red2 }{ \red2 } = a+b\end{align}$$

If you want to simplify $\frac{2+b}{2}$, recall that $\frac x y = x\frac 1 y$:

$$\begin{align}\frac{\blue{2+b}}{2} = \blue{(2+b)}\frac{1}{2} = \blue2\cdot\frac 1 2 + \blue b\cdot\frac 1 2 = 1 + \frac b 2\end{align}$$

Or use one of these handy rules that do the same thing...

$$\begin{align}\frac{\blue{a+b}}{c} &= \frac{\blue a}c + \frac{\blue b}c \\ \frac{\blue{a-b}}{c} &= \frac{\blue a}c - \frac{\blue b}c\end{align}$$ this:

$$\begin{align}\frac{\blue{2+b}}{2} = \frac{\blue2}2 + \frac{\blue b}2 = 1 + \frac b 2\end{align}$$

Note that this does not work if $a + b$ is on the bottom: $\frac{c}{a+b}$ doesn't simplify nicely in any way because it's $c\frac{1}{a+b}$, not $(a+b)\frac c 1$ or something.

Here's another thing that does not work:

$$\begin{align}\frac a b + \frac c d = \frac{a+b}{c+d} \qquad \red{\text{wrong!}}\end{align}$$

You can combine fractions with $+$ and $-$ between them only if the bottoms are the same. This is using the $\frac{a+b}{c} = \frac a c + \frac b c$ rule right to left. If you want the bottoms to be the same, you may need to do "canceling backwards":

$$\begin{align}\frac a b + \frac c d = \frac{a\blue d}{b\blue d} + \frac{c\green b}{d\green b}\end{align}$$

Now both bottoms are $bd$, so they combine nicely.

$$\begin{align}\frac a b + \frac c d = \frac{a\blue d + c\green b}{bd}\end{align}$$

Putting a minus in front of stuff means multiplying by $-1$, so $-x$ is $(-1)x$. Keep this in mind when you have something like $-(a+b)$; that's not $-a+b$ because you need to use the $(a+b)c=ac+bc$ thing with $c=-1$ here:

$$\begin{align}-(a+b) &= (-1)(a+b) \\ &= (a+b)(-1) \\ &= a(-1) + b(-1) \\ &= (-a) + (-b) \\ &= -a-b\end{align}$$

Of course, there's no need to write down these steps every time; just remember that if you have a $-($, you need to add a $-$ in front of each thing between $($ and $)$.

Negative Times Negative

You have probably been taught that if you multiply a negative number with another negative number, the result will always be a positive number. As usual, I don't want you to believe it just because someone says so, but because there is a proof. To keep things simple, we'll first prove that $(-1)(-1) = 1$, and then using that result, we'll show that it works for any negative numbers.

Let $x = (-1)(-1)$. This is an equation; we have two things with an equal sign between them. With an equation, we can divide both sides by anything nonzero (more details below), so let's do that:

$$\begin{align}\frac{x}{(\color{green}{-1})} = \frac{(-1)(-1)}{(\color{green}{-1})}\end{align}$$

The right side cancels:

$$\begin{align}\frac{x}{(-1)} &= \frac{(-1)\color{blue}{(-1)}}{\color{blue}{(-1)}} = (-1) \\ \frac{x}{-1} &= -1\end{align}$$

We can also add and substract things on both sides. Let's add $1$...

$$\begin{align}\frac{x}{-1} + 1 &= -1 + 1 \\ \frac{x}{-1} + 1 &= 0\end{align}$$

...and substract the $\frac{x}{-1}$ thing:

$$\begin{align}\color{blue}{\frac{x}{-1}} + 1 - \color{blue}{\frac{x}{-1}} &= 0 - \frac{x}{-1} \\ 1 &= -\frac{x}{-1}\end{align}$$

Let's rewrite the prefix $-$ as multiplying by $-1$:

$$\begin{align}1 &= (-1)\frac{x}{-1} = \frac{(-1)x}{(-1)}\end{align}$$

Things cancel again, and we get $1=x$.

Now, let $x,y \in \mathbb{R}$ be positive. Then $-x$ and $-y$ are negative:

$$\begin{align}\overbrace{(-x)}^{\text{negative}}\underbrace{(-y)}_{\text{negative}} = ((-1)x)((-1)y) = \overbrace{(-1)(-1)}^1 xy = \underbrace{xy}_{\text{positive}}\end{align}$$

The $x$ and $y$ can be any positive reals, so $-x$ and $-y$ can be any negative reals. It works!

Earlier I said that $\color{green}{a} \cdot \frac b c$ simplifies to $\frac{\color{green}{a}b}{c}$, not $\frac{b}{\color{green}{a}c}$. However, if $a=-1$, both are correct:

$$\begin{align}\frac{(-1)b}{c} = \frac{b}{(-1)c} = \frac{-b}{c} = \frac{b}{-c}\end{align}$$

Here is a quick proof that $\frac{(-1)b}{c} = \frac{b}{(-1)c}$. Other parts of the above math are more straight-forward. This is one of the cases when "canceling backwards" is useful:

$$\begin{align}\frac{(-1)b}{c} = \frac{\color{blue}{(-1)}(-1)b}{\color{blue}{(-1)}c} = \frac{1b}{(-1)c} = \frac{b}{(-1)c}\end{align}$$

Using Formulas to Make More Formulas

Let $a,b,c,x,y \in \mathbb{R}$. Now we know that $ac+bc=(a+b)c$. This is known as factoring. We end up with a bunch of things multiplied together, so the thing is factorized. The factors are the things that are multiplied together; in our case, $(a+b)$ and $c$.

Undoing factoring is known as expanding; $(a+b)c=ac+bc$ is a formula that we can use to expand simple things. But how do we expand something like $(a+b)^2$? That means $(a+b)(a+b)$, and mathematicians like to use the $x^2$ notation because copy/pasting and repeating things is bad.

Anyway, maybe there is a nice formula for expanding $(a+b)^2$? You can google it or look it up from a book, but don't believe it blindly; instead, you should also find a proof of the formula and read it. Or better yet, you can figure out how to do the thing yourself. Let's do that.

We know that $(a+b)\blue c = a\blue c+b\blue c$ and now we want to do $(a+b)\blue{(a+b)}$. The $\blue c$ can be any number, and $a$ and $b$ are also numbers, so there's nothing wrong with letting $c=a+b$. Let's see what we get from that:

$$\begin{align}(a+b)\blue{(a+b)} = a\blue{(a+b)} + b\blue{(a+b)}\end{align}$$

What can we do now? We use the $(a+b)c$ thing again! For $a(a+b)$, we need to let $c=a$, and for $b(a+b)$ we do $c=b$:

$$\begin{align}& a\blue{(a+b)} + b\blue{(a+b)} \\ =& a\blue a + a\blue b + b\blue a + b\blue b\end{align}$$

Next, notice that $ab = ba$, so we have $ab+ab$ in the middle. That's $2ab$. With the $x^2$ notation, $aa=a^2$ and $bb=b^2$.

$$\begin{align}(a+b)^2 = a^2 + 2ab + b^2\end{align}$$

Tada! It's done now, and this is what you'll find if you google "expand (a+b)^2". Let's make sure that it actually seems to work, just to see if we did any fatal mistakes along the way:

>>> (3+4)**2                # (a+b)²
>>> 3**2 + 2*3*4 + 4**2     # a² + 2ab + b²

Figuring this out took quite a while because we had never done anything like this before, but if you want to present your work to someone else, you should usually write it as a concise proof instead:

$$\begin{align}(a+b)^2 &= (a+b)(a+b) \\ &= a(a+b) + b(a+b) \\ &= a^2+ab+ba+b^2 \\ &= a^2+2ab+b^2\end{align}$$

Now that we have gotten started with this, we can do more. For example, we know that $a-b=a+(-b)$, so using $(a+b)c=ac+bc$ we get this:

$$\begin{align}(a-b)c &= (a+(-b))c \\ &= ac+(-b)c \\ &= ac-bc\end{align}$$

That's all we need for doing a very similar thing for $(a-b)^2$.

$$\begin{align}(a-b)^2 &= (a-b)(a-b) \\ &= a(a-b)-b(a-b) \\ &= a(a-b)+(-b)(a-b) \\ &= a(a-b)+(-b)a-(-b)b \\ &= a^2-ab-ba-(-b)b\end{align}$$

Hmm, what can we do to $-(-b)b$? We have two minuses, and we can bring them both to front, so we have $-(-(b^2))$. If you think about this on the number line, every $-$ means flipping to the other side of the number line:

So, $-(b^2)$ is $b^2$ flipped to the other side. If we flip again, we end up right back to where we started:

$$\begin{align}-(-(b^2)) &= +b^2 \\ (a-b)^2 &= a^2-2ab+b^2\end{align}$$

Here's another way that's easier to remember: $-x = (-1)x$, so $-(-(b^2)) = (-1)(-1)b^2$, and $(-1)(-1)=1$ because we proved it (see above).

There's another, easier way to prove the $(a-b)^2$ formula, which is using the $(a+b)^2$ formula we already proved with $x-y=x+(-y)$:

$$\begin{align}(a-b)^2 = (a+(-b))^2 = a^2+2a(-b)+(-b)^2\end{align}$$

Let's do a similar thing to the $(-b)^2$ as we did last time:


If you don't want to do this mess ever again, you can memorize that $(-b)^2=b^2$ for all $b \in \mathbb{R}$, which is what we just proved. We are almost done:


This happens all the time in math: we have proved a thing or we have an axiom for a thing, and then we use it to prove another thing, and then using that other thing we prove even more stuff, and so on.

$$\begin{align}(a+b)c &= ac+bc \\ \Downarrow \\ (a+b)^2 =&\ a^2+2ab+b^2 \\ \Downarrow \\ (a-b)^2 =&\ a^2-2ab+b^2\end{align}$$

There's one more formula I want to show you. I promise, this will be the last one. So far we have looked at $\green{(a+b)(a+b)}$ and $\blue{(a-b)(a-b)}$, but what if we mix them, like $\green{(a+b)}\blue{(a-b)}$?

$$\begin{align}(a+b)(a-b) &= a(a-b) + b(a-b) \\ &= aa-ab+ba+b(-b)\end{align}$$

The $-ab$ and $+ba$ cancel because $+ba=+ab$, and $b(-b)=-b^2$:

$$\begin{align}(a+b)(a-b) = a^2 - b^2\end{align}$$

Here is an example of using this formula.

Let $x,y \in \mathbb{R}$. If $x^2 = y^2$, what can we say about $x$ and $y$?

We know that this is true at least if $x=y$ because $x^2=x^2$, or if $x=-y$ because then $x^2=(-y)^2=y^2$. But are there other $x$ and $y$ values that also happen to make this work? We can check it like this: the difference of two numbers is zero only if the two numbers are equal.

$$\begin{align}x^2 - y^2 &= 0 \\ \green{(x+y)}\blue{(x-y)} &= 0\end{align}$$

This is true only if $\green{(x+y)}=0$ or $\blue{(x-y)}=0$; the only ways how multiplying two things can give $0$ are that one of the things is zero, or they are both zero. So we have two cases:

$$\begin{align}\green{x+y}=0 &\text{ or } \blue{x-y}=0 \\ x=-y &\text{ or } x=y\end{align}$$

We are done. There are no other solutions because of all the only words I have bolded; there are more details about this below.

It is kind of surprising that we started with expanding $(a+b)(a-b)$, and we ended up using our result to solve $x^2=y^2$, which doesn't seem to have anything to do with expanding. Things like this often happen in math, and they make math challenging but interesting.

Or Note

If you read the $x^2=y^2$ thing carefully, you notice that there may be some $x$ and $y$ that have both $\green{x+y}=0$ and $\blue{x-y}=0$ at the same time. It seems like I didn't handle that case at all; I just did "$\green{x+y}=0$ or $\blue{x-y}=0$". The thing is, I actually handled that case. Let me explain how.

Let $A$ and $B$ be Booleans. Then "$A$ or $B$" means:

This is why I didn't need to have a third "$\green{x+y}=0$ and $\blue{x-y}=0$" case above; just "or" was enough. If you haven't seen this "or" thing before, it's kind of surprising, but almost all programming languages do it too:

>>> True or True

This is useful for writing code like this:

if ((x is wrong) or (y is wrong)) {
    something is wrong
} else {
    everything is fine

If both x and y are wrong, something is wrong and we must not pretend that everything is fine; that's why True or True == True makes sense. In general, if you don't think about this "or" thing at all, you'll probably get it right, and that's why True or True == True.

If and Only If

Let $A$ and $B$ be Booleans. Saying "if $A$, then $B$" means that if $A$ is true, then $B$ is also true. That's it. It doesn't say anything about what happens if $A$ is false. Also, if $B$ is true, $A$ can be still false. Here is a list of the possible cases:

"$B$ is true if $A$ is true"
"if $A$, then $B$"
"$A \implies B$"

$A$ $B$
true true
false true or false

For example, if $1 = 2$, then $1 \cdot 0 = 2 \cdot 0$; that is, $0 = 0$. In other words, we have "if $1=2$, then $0=0$", but we don't have "if $0=0$, then $1=2$". Math is not broken.

Here's a similar table for "if and only if", sometimes written "iff" with double "f":

"$B$ is true if and only if $A$ is true"
"if $A$, and only if $A$, then $B$"
"$A \iff B$"

$A$ $B$
true true
false false

Now $B$ can't be true unless $A$ is also true. "If and only if" guarantees that $A$ and $B$ are either both true, or both false. This is written like $A \iff B$ because you can prove $A \iff B$ by proving that $A \Rightarrow B$ and $A \Leftarrow B$ (exercise for you: why does that work).

tl;dr: "$A \iff B$" or "$A$ if and only if $B$" or "$A$ iff $B$" means that $A$ and $B$ have the same Boolean value, and you can prove that by proving $A \implies B$ and $B \implies A$.

Solving Equations

Earlier we proved that there is a real number $x$ so that $2x = 6$ by showing that 3 is that number. In this case, it's easy to find the 3 by trying out different values. But what if we have something more complicated?

$$\begin{align}3x^2+2x+9 = 4x^2+4+5\end{align}$$

So, we're trying to find the $x$ values that this equation happens to work for. The basic idea is that if we do something to both sides of an equation, it still works. For example, $1 + 1 = 2$, so $(1+1)^2 = 2^2$.

However, there are things that give you "fake solutions" if you do them to both sides. For example, $x=x+1$ is quite obviously false with any $x$ because the left side is always smaller than the right side, but if you multiply both sides by zero, you get this:

$$\begin{align}0x &= 0(x+1) \\ 0 &= 0\end{align}$$

Now it seems to be always true, even though it was supposed to be always false. We got all real numbers as "fake solutions" that seem to work fine, even though they don't actually work at all. This is an if and only if problem, because we showed that if $x=x+1$, then $0=0$. It's perfectly correct, but it's useless because it tells nothing about $x=x+1$.

Usually when dealing with equations, we need "if and only if" things. If we apply an "if and only if" thing to an equation, we don't introduce any "fake solutions"; the equation we had before applying the "if and only if" thing is true exactly for the same $x$ values as the equation after the applying. Obviously, if we apply multiple "if and only if" things, we don't introduce any "fake solutions" either.

Let $a,x,y \in \mathbb{R}$. Here is a list of "if and only if" things that are commonly done to both sides of an $x=y$ equation:

Most things on this list are quite straight-forward, but maybe the last thing isn't, so let's prove that. Earlier we proved that $x^2=y^2 \iff (x=y\text{ or }x=-y)$, but we have also proved that $x=-y$ never happens if $x$ and $y$ are positive. This means that if $x > 0$ and $y > 0$, then $x^2=y^2 \iff x=y$, which is what we wanted.


Prove that the last thing also works for $x \ge 0$ and $y \ge 0$, not only for $x > 0$ and $y > 0$.

You can also "move" stuff to the other side of an equation. For example, if you have $x+2 = 3$, you can "move" the $2$ to the right side, if you add a $-$ in front of it, so you get $x = 3-2$. What you're actually doing is substracting 2 on both sides, but the moving may be easier to do if you need to do these things a lot. A similar thing works with multiplication and division: $\frac x 2 = 3$ can be solved by "moving" the 2 to the other side, and it gives $x = 3 \cdot 2 = 6$.

Yet another exercise

Do the $(-1)(-1)=1$ proof by "moving" things to the other side of the equation as much as possible.

Now we know enough stuff to solve our horribly complicated equation. Let's do it.

$$\begin{align}3x^2+2x+9 &= 4x^2+4+5\end{align}$$

Simplify $4+5$ to $9$.

$$\begin{align}3x^2+2x+9 &= 4x^2+9\end{align}$$

Substract $9$ on both sides to cancel the $+9$.

$$\begin{align}3x^2+2x+9-9 &= 4x^2+9-9 \\ 3x^2+2x &= 4x^2\end{align}$$

Substract $3x^2$ on both sides.

$$\begin{align}3x^2+2x-3x^2 &= 4x^2-3x^2 \\ 2x &= x^2\end{align}$$

Divide both sides by $x$.


Of course, there's no need to write down that much text between the lines. In fact, you need no text, and much less steps. I would solve the equation like this:

$$\begin{align}3x^2+2x+9 &= 4x^2+\overbrace{4+5}^9 \\ 3x^2+2x &= 4x^2 \\ 2x &= x^2 \\ 2 &= x\end{align}$$

Look carefully, we didn't 100% follow the rules. We can divide both sides by something, but only if that something is not zero; in the last step we divided by $x$, and it only works if $x \ne 0$, so we need to handle that case specially. Like this:

$$\begin{align}\text{...same }&\text{stuff as before...} \\ 2x &= x^2 \\ \text{if }x \ne 0\text{:} \quad 2 &= x\end{align}$$

If $x=0$, then $2x = 2 \cdot 0 = 0=0^2=x^2$, so $0$ is also a solution.

Answer: $x=0$ or $x=2$