Free preview

83 lessons

Mathematical Foundations for ML

Free preview

Mathematical Foundations for ML · 83 lessons

Build the maths foundations that make ML click

No surprise gaps

Actually remember it

Skip what you know

One subscription. All learning paths included.

Our content is best on a larger screen

Absolute value

Definition of absolute value

Explanation

The absolute value of a number, written x|x|, measures how far xx is from zero on the number line - regardless of direction. Whether we move 55 units to the left or 55 units to the right, the distance is the same: 55. So 5=5|{-5}| = 5 and 5=5|5| = 5.

Because distance is never negative, x0|x| \geq 0 for every value of xx.

The formal piecewise definition pins this down:

Absolute value

Definition

The absolute value of a number xx is

x={xif x0xif x<0|x| = \begin{cases} x & \text{if } x \geq 0 \\ -x & \text{if } x < 0 \end{cases}
x-x is not always negative

Gotcha

When xx is already negative, x-x flips the sign and gives a positive result. For instance, if x=3x = -3 then x=(3)=3-x = -(-3) = 3. The minus sign in the definition simply removes any existing negative sign.

We can extend the distance idea beyond zero. The expression xa|x - a| gives the distance between xx and aa on the number line. For example, 27=5=5|2 - 7| = |{-5}| = 5, matching the 55 units between 22 and 77. The order does not matter: 72=5=5|7 - 2| = |5| = 5 gives the same result.

0246810−2−4−6−8−10
x=1
a=4
|xa|
|xa|=|14|=5
Drag the blue point x and the red point a along the number line. Drag a to 0 to see |x| as the distance from x to zero.

Key Point

Three equivalent views of absolute value:

  • x|x| is the distance from xx to 00.
  • x|x| equals xx when x0x \geq 0 and x-x when x<0x < 0.
  • xa|x - a| is the distance between xx and aa.

Example

Evaluate 7|{-7}| and 3|3| using the piecewise definition. Then compute x4|x - 4| when x=1x = -1 and interpret the result as a distance.

Solution

Evaluating 7|{-7}|:

Since 7<0-7 < 0, we use the second piece of the definition: x=x|x| = -x. Substituting:

7=(7)=7|{-7}| = -(-7) = 7

Evaluating 3|3|:

Since 303 \geq 0, we use the first piece: x=x|x| = x. So:

3=3|3| = 3

Computing x4|x - 4| when x=1x = -1:

Substituting x=1x = -1:

14=5|{-1} - 4| = |{-5}|

Since 5<0-5 < 0, we apply x=x|x| = -x:

5=(5)=5|{-5}| = -(-5) = 5

The result 55 confirms the distance interpretation: 1-1 and 44 are 55 units apart on the number line.

Practice questions

4 questions

What is 9|{-9}|?

Select the correct answer:

+ 3 more questions

Product and quotient rules

Explanation

Absolute value interacts neatly with multiplication and division through two rules.

Product rule

Definition

ab=ab|ab| = |a| \cdot |b| for any values aa and bb.

The absolute value of a product equals the product of the absolute values. It does not matter whether we take the absolute value before or after multiplying.

Quotient rule

Definition

ab=ab\left|\dfrac{a}{b}\right| = \dfrac{|a|}{|b|} for any values aa and bb with b0b \neq 0.

The same idea works for division - take the absolute value of each part separately.

There is no sum rule

Gotcha

It is tempting to assume a similar rule holds for addition, but it does not. In general, a+ba+b|a + b| \neq |a| + |b|. We will see the precise relationship between a+b|a + b| and a+b|a| + |b| later in this lesson.

Example

Simplify 47|{-4} \cdot 7| and 123\left|\dfrac{-12}{3}\right| using the product and quotient rules.

Solution

Product rule: 47|{-4} \cdot 7|

Applying ab=ab|ab| = |a| \cdot |b|:

47=47=47=28|{-4} \cdot 7| = |{-4}| \cdot |7| = 4 \cdot 7 = 28

We can verify: 47=28-4 \cdot 7 = -28, and 28=28|{-28}| = 28.

Quotient rule: 123\left|\dfrac{-12}{3}\right|

Applying ab=ab\left|\dfrac{a}{b}\right| = \dfrac{|a|}{|b|}:

123=123=123=4\left|\dfrac{-12}{3}\right| = \dfrac{|{-12}|}{|3|} = \dfrac{12}{3} = 4

Again we can verify: 123=4\dfrac{-12}{3} = -4, and 4=4|{-4}| = 4.

Practice questions

4 questions

What is (6)(3)|({-6}) \cdot ({-3})|?

Select the correct answer:

+ 3 more questions

The triangle inequality

Explanation

We saw that a+b|a + b| is not equal to a+b|a| + |b| in general. The triangle inequality tells us the precise relationship: the left side is always less than or equal to the right.

Triangle inequality

Definition

For any values aa and bb:

a+ba+b|a + b| \leq |a| + |b|

In other words, the absolute value of a sum is at most the sum of the absolute values. The right-hand side acts as an upper bound on a+b|a + b|.

Key Point

To verify the triangle inequality for a particular pair, compute both sides and check a+ba+b|a + b| \leq |a| + |b|.

0246810−2−4−6−8−10
a=3
b=5
a
b
a+b
|a+b|
|a+b|=|3+(5)|=2|a|+|b|=3+5=8
2<8: strict inequality. The steps point in opposite directions, so the second cancels part of the first.
The arrows show a+b as two steps: from 0 to a (blue), then a step of b (red), landing at a+b. The grey bracket measures |a+b|: the distance from 0 to the landing point.
Drag the blue point a and the red point b. Try same-sign and opposite-sign pairs.

The diagram gives both sides of the inequality a geometric meaning: a+b|a| + |b| is the total distance covered by the two steps, while a+b|a + b| is the distance from 00 to the final position.

When the steps point the same way, no ground is retraced and the two sides agree. When they oppose, the second step retraces part of the first, so the final position is closer to 00 than the total distance covered.

In terms of signs: equality holds exactly when aa and bb have the same sign (or either is zero), and opposite signs force strict inequality.

Example

To verify the triangle inequality for a pair of values, compute a+b\lvert a + b \rvert and a+b\lvert a \rvert + \lvert b \rvert separately, then check the inequality holds.

  1. a=3a = 3, b=5b = 5 (same sign): 3+5=8\lvert 3 + 5 \rvert = 8 and 3+5=8\lvert 3 \rvert + \lvert 5 \rvert = 8. We get 888 \leq 8 - equality.
  2. a=3a = 3, b=5b = -5 (opposite signs): 3+(5)=2\lvert 3 + (-5) \rvert = 2 and 3+5=8\lvert 3 \rvert + \lvert{-5}\rvert = 8. We get 282 \leq 8 - strict inequality, because the opposite signs cause partial cancellation.
  3. a=4a = -4, b=0b = 0: 4+0=4\lvert{-4} + 0\rvert = 4 and 4+0=4\lvert{-4}\rvert + \lvert 0 \rvert = 4. We get 444 \leq 4 - equality again.

Practice questions

4 questions

Let a=3a = -3 and b=8b = 8. What are a+b|a + b| and a+b|a| + |b|?

Select the correct answer:

+ 3 more questions