Pre-Calculus for Programmers

Algebra foundations: the toolkit calculus never reteaches

2 / 397
Contents

Contents

Pre-Calculus for Programmers

0 of 397 complete

9 min read

Writing down a set of numbers

A thermostat, a run of accepted values, and the three notations that describe that run.

A thermostat in a server room is set to hold the temperature at 18 degrees or warmer, and strictly below 22, because at 22 the alarm sounds. Somebody hands you a list of readings and asks which ones the thermostat would call acceptable.

That is a question about a set of numbers, and the fastest way to see the shape of the answer is to test every candidate and look at the pattern.

Which temperatures pass?Python

Change t < high to t <= high and run it again. Exactly one line changes. That single line is the whole difference between two of the notations below.

The accepted readings are not scattered. They form one unbroken run, from 18 up to 22, with 18 in and 22 out. The interesting information is only at the two ends: where the run starts, where it stops, and whether each end is itself included.

Interval notation

An interval is an unbroken run of the number line, described by its two ends. The notation records the ends and whether each one is included. A square bracket means the end is included; a round bracket means it is not.

IntervalRead asIn words
[a,b][a, b]closedeverything from aa to bb, both ends included
(a,b)(a, b)openeverything strictly between aa and bb, neither end included
[a,b)[a, b)half-openaa is included, bb is not
(a,b](a, b]half-openbb is included, aa is not
The four finite intervals with ends $a$ and $b$, where $a$ is the smaller.

The thermostat's acceptable set is [18,22)[18, 22). Eighteen is in, so it gets a square bracket. Twenty-two is out, so it gets a round one. That is the entire answer, written in five characters.

For a run that never stops, the symbol ∞\infty (infinity) marks the end that goes on forever, and −∞-\infty marks one that goes on forever to the left. So [3,∞)[3, \infty) is every number 3 or above, and (−∞,0)(-\infty, 0) is every negative number.

Set-builder notation

Interval notation only describes unbroken runs. Set-builder notation describes a set by stating the condition its members satisfy, so it can describe anything. It is written { x∣condition }\{\, x \mid \text{condition} \,\}, and read aloud as "the set of all xx such that the condition holds". The vertical bar is read "such that"; some books use a colon instead, and it means the same.

[18, 22)  =  { x∣18≤x<22 }[18,\,22) \;=\; \{\, x \mid 18 \le x < 22 \,\}
The same set twice. The left is compact, the right says exactly what the program tested.

Notice that the right hand side is the condition your program computed, character for character. Set-builder notation is the mathematical spelling of an if.

Combining two sets

Two conditions can be demanded at once, or either one accepted. Run both over the same numbers and watch which values survive each.

Two conditions at oncePython

Change the second condition to (x > 4) and (x <= 5) and run it again. Now no value at all is in both. Which column is the one that went empty?

The values in both sets form the intersection, written A∩BA \cap B. The values in one or the other or both form the union, written A∪BA \cup B. Intersection is and; union is or.

A worked example, every step

Take A=[−2,3)A = [-2, 3) and B=(0,5]B = (0, 5]. Find A∩BA \cap B and A∪BA \cup B.

  1. Draw both on one line, or list the conditions: AA says −2≤x<3-2 \le x < 3, and BB says 0<x≤50 < x \le 5.
  2. For the intersection, both conditions must hold. The left end has to satisfy the stricter of the two left conditions: x≥−2x \ge -2 and x>0x > 0 together mean x>0x > 0, because 0 is the further right of the two starting points, and it is excluded.
  3. The right end works the same way: x<3x < 3 and x≤5x \le 5 together mean x<3x < 3, because 3 is the further left of the two stopping points, and it is excluded.
  4. So A∩B=(0,3)A \cap B = (0, 3). Both ends are round, because both came from a strict condition.
  5. For the union, a number needs only one condition. AA covers from −2-2 (included) up to 3, and BB covers from just after 0 up to 5 (included). They overlap on (0,3)(0,3), so the two runs join into one run with no gap.
  6. So A∪B=[−2,5]A \cup B = [-2, 5]. The left end keeps the square bracket it had in AA, and the right end keeps the square bracket it had in BB.
Check yourself

Which of these is the set of all xx with x≥−4x \ge -4?

Write { x∣x<1 or x≥6 }\{\, x \mid x < 1 \text{ or } x \ge 6 \,\} in interval notation.

(−∞,1)∪[6,∞)(-\infty, 1) \cup [6, \infty). The word "or" is a union. The first piece runs from the far left up to 1, excluded, so it is (−∞,1)(-\infty, 1). The second starts at 6, included, and never stops, so it is [6,∞)[6, \infty). The two pieces do not touch, so the union symbol has to stay.

All lessons in Pre-Calculus for Programmers