4.5.1.1–4.5.1.7 - Number systems, counting and measurement

4.5.1.1–4.5.1.7 - Number systems, counting and measurement

In 4.5.1.1–4.5.1.5 you will distinguish the sets used to describe numbers. In 4.5.1.6–4.5.1.7 you will use numbers for position, counting and measurement. These distinctions help you decide what a stored value means before choosing how to represent it.

Natural numbers and integers

A count of completed downloads can be zero, one, two and so on; it cannot be negative or halfway between two whole counts.

Natural numbers

For this specification, the natural numbers include zero: N={0,1,2,3,…}\mathbb{N}=\{0,1,2,3,\ldots\}.

The dots mean that the set continues without a largest member. Zero belongs to this set even though some other mathematical conventions begin the natural numbers at one. Use the convention stated here.

An integer is a whole number, positive, negative or zero. The set is Z={…,−3,−2,−1,0,1,2,3,…}\mathbb{Z}=\{\ldots,-3,-2,-1,0,1,2,3,\ldots\}. A change of −4-4 in the number of files is an integer: four files were removed. A current count of files still cannot be negative. Distinguish a quantity from a change in that quantity.

Every natural number is also an integer. The reverse is false: −4∈Z-4\in\mathbb{Z}, but −4∉N-4\notin\mathbb{N}. Neither set includes 2.52.5, because it is not a whole number. The symbols ∈\in and ∉\notin mean “is a member of” and “is not a member of”.

Rational, irrational and real numbers

A fraction such as 3/43/4 introduces a wider set than the integers, while values such as 2\sqrt{2} require a further distinction.

Rational numbers

A rational number can be written as p/qp/q, where pp and qq are integers and q≠0q\ne0. The set of rational numbers is Q\mathbb{Q}.

The condition on the denominator prevents division by zero. Every integer is rational because z=z/1z=z/1. For example, −6=−6/1-6=-6/1, 0=0/10=0/1 and 0.75=3/40.75=3/4. A terminating decimal is rational. So is a recurring decimal: 0.333…=1/30.333\ldots=1/3. Writing a number with a decimal point therefore does not make it irrational.

An irrational number cannot be written as a ratio of integers. Its decimal expansion neither terminates nor repeats a fixed pattern. Examples include 2\sqrt{2} and π\pi. Not every square root is irrational: 9=3\sqrt{9}=3 is an integer and is rational. A rounded display such as 1.4141.414 is rational even when it approximates an irrational quantity; the exact quantity and the displayed approximation differ.

The real numbers, R\mathbb{R}, consist of all rational and irrational numbers. They correspond to points on the number line and describe quantities such as position, time and length. The inclusions are N⊂Z⊂Q⊂R\mathbb{N}\subset\mathbb{Z}\subset\mathbb{Q}\subset\mathbb{R}; “subset” means every member of the smaller set belongs to the larger set. Irrational numbers belong to R\mathbb{R} but not Q\mathbb{Q}.

For example, 55 belongs to all four named sets; −2-2 belongs to Z,Q,R\mathbb{Z},\mathbb{Q},\mathbb{R}; 2/52/5 belongs to Q,R\mathbb{Q},\mathbb{R}; and 3\sqrt{3} belongs to R\mathbb{R} but none of the other three. “Real” is a mathematical classification: a computer still has finite storage and cannot store every real value exactly.

Ordinal numbers

The same ordered list can have both a size and a position for each entry, and those numbers answer different questions.

An ordinal number tells you where an object occurs in an order: first, second, third and so on. If an ordered playlist is (A,B,C,D)(A,B,C,D), there are four entries, and CC is the third entry. “Four” counts the entries; “third” describes CC's position. The ordinal depends on the chosen ordering. Sorting the playlist differently may change an entry's position without changing the number of entries.

Use the ordering stated in the task. A race position, a queue position and the fifth page of a document are ordinal uses. A label printed on a participant's shirt is an identifier; it does not necessarily give their finishing position. Similarly, an implementation may number array indices from zero, but the first item is still the first item in ordinary ordinal language. An index and an ordinal may use different conventions.

Discrete counting and continuous measurement

Choosing a number set begins with the kind of quantity you are describing, rather than the number of decimal places on a screen.

Counting is discrete: each complete object adds one to the total. Use natural numbers for a number of users, stored images or vehicles that pass a sensor. Zero is meaningful when no objects have been counted. A value of 6.5 users would not be a count of complete users.

Measurement concerns a quantity such as duration, distance or temperature, modeled using real numbers. A journey may take 6.5 s6.5\,\mathrm{s}, and values between whole seconds are meaningful. A thermometer reading of −3.2 ∘C-3.2\,^{\circ}\mathrm{C} shows why a measurement need not be non-negative. Measurement resolution limits the values reported by a device; a display that reports only whole degrees does not make the underlying temperature a count.

A camera controller might store 24 for the count of captured photographs and 2.75 s2.75\,\mathrm{s} for an exposure duration. Both displayed values are rational, but the suitable general mathematical models are natural numbers for the count and real numbers for the duration. The model describes the possible quantity; the recorded reading is one member or approximation within it.

Ask what the number does: counts use N\mathbb{N}, positions use ordinal numbers, and measurements use R\mathbb{R}. A finite computer representation is a separate choice from the mathematical set.