Skip to content

Numbers And Arithmetic

Algebra is a generalization of arithmetic: instead of only working with fixed numbers, it introduces variables and rules for manipulating expressions that contain them. Before you can manipulate expressions, you need to be fluent with the objects inside them, which are numbers and the operations on numbers. This note covers the number systems, fractions, powers, roots, rational exponents and radicals. Solving equations builds on all of this and lives in "Equations".


Anatomy Of An Algebraic Expression

An algebraic expression mixes numbers, letters and operations. Each letter has a specific role, and knowing the role tells you what you are allowed to change while solving a problem.

7x3+ax+c7x^3 + ax + c

PartIn the exampleRole
Coefficient77 and aaNumber multiplying a variable term
VariablexxCan take any value, this is what we usually solve for
Exponent (power)33How many times xx is multiplied by itself
ParameteraaTreated as fixed for one particular problem, but can change between problems
ConstantccNever changes

The difference between a parameter and a variable is a matter of perspective. Think of a function in code with a default argument: inside one call, the argument is fixed (parameter), but the function body is written for any input (variable). Once you know aa and cc, the expression gives a result for every value of xx.


Number Systems

Numbers need a representation for the human mind, and we generally use the decimal system (base 10). As a computer scientist you also know binary (base 2), octal (base 8) and hexadecimal (base 16). The representation changes, the number itself does not: 0b1010, 0xA and 10 are the same value.

Mathematics uses several classes of numbers. Each class extends the previous one so that more problems can be solved.

Nested number sets

The Five Sets

SetSymbolContainsExamplesTypical use
Natural numbersN\mathbb{N}Counting numbers0,1,2,3,…0, 1, 2, 3, \dotsCounting, indexing arrays and lists
IntegersZ\mathbb{Z}Naturals plus negatives…,−2,−1,0,1,2,…\dots, -2, -1, 0, 1, 2, \dotsGains and losses, signed coordinates
Rational numbersQ\mathbb{Q}Fractions pq\frac{p}{q} with p,q∈Zp, q \in \mathbb{Z}, q≠0q \neq 012,−34,5=51\frac{1}{2}, -\frac{3}{4}, 5 = \frac{5}{1}Ratios, exact decimal values
Real numbersR\mathbb{R}Rationals plus irrationals2,π,e\sqrt{2}, \pi, eEvery point on the number line, calculus, ML
Complex numbersC\mathbb{C}a+bia + bi with a,b∈Ra, b \in \mathbb{R} and i=−1i = \sqrt{-1}3+2i,−i,53 + 2i, -i, 5Signal processing, graphics, control theory

The sets form a strict hierarchy:

N⊂Z⊂Q⊂R⊂C\mathbb{N} \subset \mathbb{Z} \subset \mathbb{Q} \subset \mathbb{R} \subset \mathbb{C}

Every set contains all the elements of the previous one, so 55 is a natural number, but also an integer, a rational (51\frac{5}{1}), a real and a complex number (5+0i5 + 0i). When you classify a number, you name the smallest set it belongs to.

How To Recognise Each Kind

A rational number always has a decimal expansion that either terminates (0.250.25, 1.751.75) or repeats (0.333…0.333\dots). An irrational number has a decimal expansion that never stops and never repeats, which is exactly why it cannot be written as a fraction of two integers. Some irrationals, such as π\pi and ee, are so special that they are called transcendental: they are not the root of any polynomial equation with integer coefficients.

Why Bigger Sets Exist

The need for a larger number system usually comes from an equation that has no solution in the current one. Each step up the ladder below is forced by an equation.

Each equation forces a bigger set

The pattern is that every inverse operation eventually breaks out of its set: subtraction breaks N\mathbb{N}, division breaks Z\mathbb{Z}, square roots break Q\mathbb{Q}, and square roots of negatives break R\mathbb{R}.

Proving √2 Is Irrational

This classic proof shows the technique of proof by contradiction: assume the opposite of what you want, and show that it leads to something impossible.

  1. Assume 2\sqrt{2} is rational, so 2=ab\sqrt{2} = \frac{a}{b} with a,b∈Za, b \in \mathbb{Z}, b≠0b \neq 0, and the fraction in lowest terms, meaning gcd⁡(a,b)=1\gcd(a, b) = 1.
  2. Square both sides: 2=a2b22 = \frac{a^2}{b^2}, so a2=2b2a^2 = 2b^2. That means a2a^2 is even.
  3. The square of an odd number is odd, so aa itself must be even. Write a=2ka = 2k.
  4. Substitute: (2k)2=2b2⇒4k2=2b2⇒b2=2k2(2k)^2 = 2b^2 \Rightarrow 4k^2 = 2b^2 \Rightarrow b^2 = 2k^2. So b2b^2 is even, and therefore bb is even.
  5. Now both aa and bb are even, so 22 divides both. That contradicts gcd⁡(a,b)=1\gcd(a, b) = 1.

The assumption was false, so 2\sqrt{2} is irrational. The same proof works for p\sqrt{p} with any prime pp: replace "even" with "divisible by pp" and use the fact that if a prime divides a2a^2, it divides aa.


Fractions

A fraction ab\frac{a}{b} represents a part of a whole, or more generally the division of aa by bb. The top number aa is the numerator, the bottom number bb is the denominator, and the denominator must never be 00.

Simplifying

A fraction is simplified (in lowest terms) when the numerator and denominator have no common divisor other than 11. Divide both by their greatest common divisor:

68=6÷28÷2=34\frac{6}{8} = \frac{6 \div 2}{8 \div 2} = \frac{3}{4}

This works because dividing top and bottom by the same number is the same as dividing the fraction by 22=1\frac{2}{2} = 1, which does not change its value.

Adding And Subtracting

You can only add fractions that describe pieces of the same size, so the denominators must match first. If they differ, rewrite both fractions over a common denominator:

13+23=33=112+13=36+26=56\frac{1}{3} + \frac{2}{3} = \frac{3}{3} = 1 \qquad\qquad \frac{1}{2} + \frac{1}{3} = \frac{3}{6} + \frac{2}{6} = \frac{5}{6}

Subtraction works exactly the same way.

Multiplying

Multiplying is simpler, because no common denominator is needed. Multiply the numerators together and the denominators together, then simplify:

ab⋅cd=acbd23⋅54=1012=56\frac{a}{b} \cdot \frac{c}{d} = \frac{ac}{bd} \qquad\qquad \frac{2}{3} \cdot \frac{5}{4} = \frac{10}{12} = \frac{5}{6}

Dividing: Keep, Change, Flip

To divide by a fraction, multiply by its reciprocal. The reciprocal of cd\frac{c}{d} is dc\frac{d}{c}.

ab÷cd=ab⋅dc\frac{a}{b} \div \frac{c}{d} = \frac{a}{b} \cdot \frac{d}{c}

The memory rule is keep, change, flip: keep the first fraction, change ÷\div into ⋅\cdot, flip the second fraction.

Keep change flip

Why does flipping work? Dividing by a number asks "how many of these fit in?". Asking how many quarters fit into one half is the same as multiplying by 44, because each whole holds four quarters: 12÷14=12⋅4=2\frac{1}{2} \div \frac{1}{4} = \frac{1}{2} \cdot 4 = 2.

Common Mistakes With Fractions

MistakeWrongRight
Dividing top and bottom separately12÷14=1÷12÷4\frac{1}{2} \div \frac{1}{4} = \frac{1 \div 1}{2 \div 4}12⋅41=2\frac{1}{2} \cdot \frac{4}{1} = 2
Flipping the first fraction23÷54=32⋅54\frac{2}{3} \div \frac{5}{4} = \frac{3}{2} \cdot \frac{5}{4}23⋅45=815\frac{2}{3} \cdot \frac{4}{5} = \frac{8}{15}
Forgetting to simplify34÷12=64\frac{3}{4} \div \frac{1}{2} = \frac{6}{4}64=32\frac{6}{4} = \frac{3}{2}
Dividing by zero12÷0=?\frac{1}{2} \div 0 = ?Undefined: 00 has no reciprocal

A useful sanity check: dividing a positive number by a fraction smaller than 11 always makes it bigger. If your answer shrank, something went wrong.


Powers

Powers are shorthand for repeated multiplication. Instead of writing 2⋅2⋅2⋅22 \cdot 2 \cdot 2 \cdot 2, you write 242^4.

an=a⋅a⋅…⋅a⏟n factorsa^n = \underbrace{a \cdot a \cdot \ldots \cdot a}_{n \text{ factors}}

Here aa is the base and nn is the exponent (or power). a2a^2 is called the square of aa and a3a^3 the cube.

Zero And Negative Exponents

Two definitions extend powers beyond positive whole exponents, and both follow from the division rule below. Since anan=1\frac{a^n}{a^n} = 1 and also anan=an−n=a0\frac{a^n}{a^n} = a^{n-n} = a^0, it must be that:

a0=1(a≠0)a^0 = 1 \quad (a \neq 0)

And since a−n=a0−n=a0ana^{-n} = a^{0-n} = \frac{a^0}{a^n}, a negative exponent means a reciprocal:

a−n=1an2−3=123=18a^{-n} = \frac{1}{a^n} \qquad\qquad 2^{-3} = \frac{1}{2^3} = \frac{1}{8}

The Three Rules

All three rules come straight from counting factors. am⋅ana^m \cdot a^n is mm factors followed by nn more factors, so m+nm + n factors in total.

RuleFormulaExample
Product (same base)am⋅an=am+na^m \cdot a^n = a^{m+n}23⋅24=27=1282^3 \cdot 2^4 = 2^7 = 128
Quotient (same base)aman=am−n\frac{a^m}{a^n} = a^{m-n}, a≠0a \neq 03532=33=27\frac{3^5}{3^2} = 3^3 = 27
Power of a power(am)n=amn(a^m)^n = a^{mn}(23)2=26=64(2^3)^2 = 2^6 = 64

In computer science you meet powers constantly: a byte holds 28=2562^8 = 256 values, an IPv4 address space has 2322^{32} addresses, and 1 KiB=2101\text{ KiB} = 2^{10} bytes.

Common Mistakes With Powers

The order of operations matters a lot with powers, because the exponent binds tighter than a minus sign.

MistakeWrongRight
Power is not multiplication32=3⋅2=63^2 = 3 \cdot 2 = 632=3⋅3=93^2 = 3 \cdot 3 = 9
Adding powers is not adding exponents23+23=262^3 + 2^3 = 2^623+23=8+8=162^3 + 2^3 = 8 + 8 = 16
Minus sign outside the power−22=4-2^2 = 4−22=−(22)=−4-2^2 = -(2^2) = -4, but (−2)2=4(-2)^2 = 4
Anything to the power zero50=05^0 = 050=15^0 = 1

The same trap exists in code. In Python, -2**2 evaluates to -4 because ** binds tighter than unary minus.

python
print(-2**2)    # -4
print((-2)**2)  # 4
print(2**3 + 2**3 == 2**6)  # False: 16 vs 64

Roots

Roots are the inverse operation of powers. Just as division undoes multiplication, taking a root undoes raising to a power.

Square Roots

The square root a\sqrt{a} is the non-negative number whose square equals aa. So 9=3\sqrt{9} = 3 because 32=93^2 = 9. Squaring and square rooting undo each other:

a2=a(a≥0)(a)2=a\sqrt{a^2} = a \quad (a \geq 0) \qquad\qquad (\sqrt{a})^2 = a

The condition a≥0a \geq 0 matters. For negative aa, (−3)2=9=3\sqrt{(-3)^2} = \sqrt{9} = 3, not −3-3. The fully general rule is a2=∣a∣\sqrt{a^2} = |a|, the absolute value.

A perfect square is an integer that is the square of another integer: 1,4,9,16,25,36,49,…1, 4, 9, 16, 25, 36, 49, \dots Their roots are whole numbers. Every other positive integer has an irrational square root, such as 2≈1.4142\sqrt{2} \approx 1.4142 and 3≈1.7321\sqrt{3} \approx 1.7321.

Higher Roots

The cube root a3\sqrt[3]{a} undoes a cube: 83=2\sqrt[3]{8} = 2 because 23=82^3 = 8, and 1253=5\sqrt[3]{125} = 5. In general an\sqrt[n]{a} is the number that gives aa when raised to the power nn. Unlike square roots, odd roots of negative numbers are fine in R\mathbb{R}: −83=−2\sqrt[3]{-8} = -2.

Common Mistakes With Roots

The square root of a negative number does not exist in R\mathbb{R}, only in C\mathbb{C}. The biggest mistake, though, is splitting a root over a sum:

9+16=3+4=7but9+16=25=5\sqrt{9} + \sqrt{16} = 3 + 4 = 7 \qquad\text{but}\qquad \sqrt{9 + 16} = \sqrt{25} = 5

a+b≠a+b\sqrt{a + b} \neq \sqrt{a} + \sqrt{b}

Roots split over multiplication and division, never over addition or subtraction. The same is true for powers: (a+b)2≠a2+b2(a + b)^2 \neq a^2 + b^2.


Rational Exponents

Exponents can also be fractions. A rational exponent is just another notation for a root, and the big advantage is that all the power rules keep working.

a12=aa13=a3amn=amn=(an)ma^{\frac{1}{2}} = \sqrt{a} \qquad\qquad a^{\frac{1}{3}} = \sqrt[3]{a} \qquad\qquad a^{\frac{m}{n}} = \sqrt[n]{a^m} = \left(\sqrt[n]{a}\right)^m

Why is a12=aa^{\frac{1}{2}} = \sqrt{a}? Apply the product rule: a12⋅a12=a12+12=a1=aa^{\frac{1}{2}} \cdot a^{\frac{1}{2}} = a^{\frac{1}{2} + \frac{1}{2}} = a^1 = a. A number that multiplied by itself gives aa is exactly the definition of a\sqrt{a}.

Radical anatomy and rational exponents

Reading m/n

The denominator is the root, the numerator is the power. A good way to remember it: the denominator is "down at the root".

823=(83)2=22=41634=(164)3=23=88^{\frac{2}{3}} = \left(\sqrt[3]{8}\right)^2 = 2^2 = 4 \qquad\qquad 16^{\frac{3}{4}} = \left(\sqrt[4]{16}\right)^3 = 2^3 = 8

Common Mistakes With Rational Exponents

Swapping the numerator and denominator is the classic error: 8238^{\frac{2}{3}} is the cube root squared, not the square root cubed (832\sqrt[2]{8^3}). The second tip is about order: mathematically both orders give the same result, but taking the root first keeps the numbers small. Computing 163416^{\frac{3}{4}} as 1634=40964\sqrt[4]{16^3} = \sqrt[4]{4096} is much harder by hand than (164)3=23(\sqrt[4]{16})^3 = 2^3.


Radicals

The symbol a\sqrt{\phantom{a}} is the radical sign, and any expression with roots is a radical. In an\sqrt[n]{a}, nn is the index and aa is the radicand. For square roots the index 22 is left out.

Simplifying Radicals

Look for a perfect square factor inside the radicand, split it off and take its root. This uses the rule ab=ab\sqrt{ab} = \sqrt{a}\sqrt{b}.

12=4⋅3=43=2375=25⋅3=53\sqrt{12} = \sqrt{4 \cdot 3} = \sqrt{4}\sqrt{3} = 2\sqrt{3} \qquad\qquad \sqrt{75} = \sqrt{25 \cdot 3} = 5\sqrt{3}

Always pick the largest perfect square factor. For 72\sqrt{72}, using 44 gives 2182\sqrt{18} which is not finished, while using 3636 gives 626\sqrt{2} directly.

Multiplying And Dividing Radicals

Radicals with the same index can be combined under one radical sign:

a⋅b=abab=ab(b>0)\sqrt{a} \cdot \sqrt{b} = \sqrt{ab} \qquad\qquad \frac{\sqrt{a}}{\sqrt{b}} = \sqrt{\frac{a}{b}} \quad (b > 0)

2⋅8=16=4502=25=5\sqrt{2} \cdot \sqrt{8} = \sqrt{16} = 4 \qquad\qquad \frac{\sqrt{50}}{\sqrt{2}} = \sqrt{25} = 5

Adding And Subtracting Radicals

Radicals behave like variables here: you can only add like terms, meaning the same radical part. Think of 3\sqrt{3} as a unit, just like xx in 2x+5x=7x2x + 5x = 7x.

23+53=732+3 cannot be simplified2\sqrt{3} + 5\sqrt{3} = 7\sqrt{3} \qquad\qquad \sqrt{2} + \sqrt{3} \text{ cannot be simplified}

Often the radicals only become like terms after simplifying them, so always simplify first:

12+27=23+33=538+18=22+32=52\sqrt{12} + \sqrt{27} = 2\sqrt{3} + 3\sqrt{3} = 5\sqrt{3} \qquad\qquad \sqrt{8} + \sqrt{18} = 2\sqrt{2} + 3\sqrt{2} = 5\sqrt{2}


Worked Exercises

These are representative exercises from the course book, with the reasoning written out. Try them yourself first, then compare.

Classify Numbers

Name the smallest set for 77, −12-12, 83\frac{8}{3} and 2\sqrt{2}. The answers are 7∈N7 \in \mathbb{N}, −12∈Z-12 \in \mathbb{Z}, 83∈Q\frac{8}{3} \in \mathbb{Q} and 2∈R\sqrt{2} \in \mathbb{R}. For 5\sqrt{5}, since 55 is prime, the generalised proof says it is irrational, so 5∈R\sqrt{5} \in \mathbb{R}.

Fractions In Context

A recipe needs 34\frac{3}{4} cup of flour and you make half the recipe. "Half of" means multiply by 12\frac{1}{2}: 34⋅12=38\frac{3}{4} \cdot \frac{1}{2} = \frac{3}{8} cup.

Spot the error in 12÷14=18\frac{1}{2} \div \frac{1}{4} = \frac{1}{8}. The fractions were multiplied instead of divided. Keep, change, flip gives 12⋅41=2\frac{1}{2} \cdot \frac{4}{1} = 2.

Converting decimals: 0.75=75100=340.75 = \frac{75}{100} = \frac{3}{4} and 1.2=1210=651.2 = \frac{12}{10} = \frac{6}{5}.

Powers And Roots

(−2)2=4(-2)^2 = 4 is true, 23+23=262^3 + 2^3 = 2^6 is false (16≠6416 \neq 64), (23)2=26(2^3)^2 = 2^6 is true and 50=05^0 = 0 is false (50=15^0 = 1).

3245=(325)4=24=1632^{\frac{4}{5}} = (\sqrt[5]{32})^4 = 2^4 = 16 and 2723=(273)2=32=927^{\frac{2}{3}} = (\sqrt[3]{27})^2 = 3^2 = 9.

Radicals

38−18=3⋅22−32=62−32=323\sqrt{8} - \sqrt{18} = 3 \cdot 2\sqrt{2} - 3\sqrt{2} = 6\sqrt{2} - 3\sqrt{2} = 3\sqrt{2}.

7⋅28=196=14\sqrt{7} \cdot \sqrt{28} = \sqrt{196} = 14, and x25=x25\sqrt[5]{x^2} = x^{\frac{2}{5}}.


Quick Recap

  • Expression parts: coefficients multiply, variables vary, parameters are fixed per problem, constants never change.
  • Number sets: N⊂Z⊂Q⊂R⊂C\mathbb{N} \subset \mathbb{Z} \subset \mathbb{Q} \subset \mathbb{R} \subset \mathbb{C}. Each one exists because some equation has no solution in the smaller set. Classify by the smallest set.
  • Rational vs irrational: rational decimals stop or repeat, irrational decimals do neither. p\sqrt{p} is irrational for every prime pp (proof by contradiction).
  • Fractions: common denominator for ++ and −-, straight across for ⋅\cdot, keep change flip for ÷\div. Never divide by 00.
  • Powers: aman=am+na^m a^n = a^{m+n}, aman=am−n\frac{a^m}{a^n} = a^{m-n}, (am)n=amn(a^m)^n = a^{mn}, a0=1a^0 = 1, a−n=1ana^{-n} = \frac{1}{a^n}. Watch −22=−4-2^2 = -4.
  • Roots: inverse of powers, a2=∣a∣\sqrt{a^2} = |a|. Roots split over ⋅\cdot and ÷\div, never over ++ or −-.
  • Rational exponents: amn=(an)ma^{\frac{m}{n}} = (\sqrt[n]{a})^m, denominator is the root, numerator the power. Take the root first.
  • Radicals: pull out the largest perfect square, then add only like radicals.