The earlier chapters separate three questions: what belongs to a set, how functions pair elements, and how a sequence assigns values to indices. Here those ideas meet arithmetic and computation. We first compare the standard number systems, then study the integer operations used by algorithms, and finally prove that iterative and recursive procedures do what they claim.
The prerequisites are Naive Set Theory, Functions and Mappings, and Sequences and Series. Throughout, ; positive integers are written . The treatments of infinite sets, recursive data, and invariants in Mathematics for Computer Science provide further practice [1][1] E. Lehman, F. T. Leighton, and A. R. Meyer, Mathematics for Computer Science. MIT OpenCourseWare, 2015. Revised May 18, 2015; infinite sets, recursive data, and invariants. https://ocw.mit.edu/courses/6-042j-mathematics-for-computer-science-spring-2015/mit6_042js15_textbook.pdf.
Number systems extend the available operations
The familiar inclusions are
Under these standard identifications, moving right retains the earlier numbers while permitting new solutions or limits.
| System | What it contains | What the extension provides |
|---|---|---|
| Counting and induction | ||
| Integers, positive, negative, and zero | Subtraction always stays in the system | |
| Ratios , with integers and | Division by any nonzero element | |
| Rational and irrational real numbers | A complete ordered field | |
| Numbers , with and | A solution of and a broader algebraic setting |
The first steps can be motivated by equations: has no solution in , and has no solution in . Passing from to also addresses limiting processes, not just one missing root. Complex numbers are developed in their own chapter.
A rational number has many fractional representations. For nonzero denominators,
The fractions and therefore represent one number, not two elements of . A formal construction treats equivalent integer pairs as the same rational number; this is an application of equivalence classes.
The irrational numbers form . They are not another nested field: and are irrational, but their sum is rational. Prime numbers likewise form a special subset of , rather than a new number system in the inclusion chain. A prime is an integer greater than whose only positive divisors are and itself; in particular, is not prime.
Decimal representations are not the numbers themselves
A rational number has a terminating or eventually periodic decimal expansion. In long division by a positive denominator , there are only possible remainders. A zero remainder ends the expansion; otherwise a remainder repeats and the subsequent digits repeat. Conversely, an eventually repeating tail is a geometric series, so it represents a rational number.
For instance, . Decimal expansions can also have two representations of the same value: . Infinite nonperiodic decimals represent irrational numbers, but merely seeing a long finite prefix does not establish nonperiodicity. A real number can be approximated by rational decimal truncations; this is a property of the real system, not a self-contained construction of it before limits have been defined.
Cardinality: Cantor’s diagonal argument
The rationals are dense: between any two distinct rationals there is another rational. Yet they can still be listed. To prove that the reals are uncountable, we need a different obstruction: every proposed list misses a real number, regardless of how cleverly it is arranged.
There is no sequence whose entries include every real number in .
The indices here start at to match the decimal places. Starting at instead would not affect countability. Repetitions in the proposed list are allowed: even a list with repetitions cannot cover the interval.
Step 1: suppose a complete list exists
Assume that all the reals in appear in a sequence. For each entry, choose the decimal expansion that is not eventually all nines. For example, use rather than .
Write
The first subscript specifies the row; the second specifies a digit position. Thus is the th decimal digit of the th number. A finite table can display only finitely many rows and columns, but the assumed list and all its decimal expansions continue indefinitely.
The diagonal digits shown are ; the construction changes them to . Only the first five positions are displayed: the rule defines every subsequent digit as well.
Step 2: change the diagonal, one digit per row
Read : the first digit of the first number, the second digit of the second number, and so on. Define
In either case, . The essential choice is the pairing of row with position : we reserve a specific position at which to defeat each row.
Step 3: the new digits define a real number
Set . More explicitly,
Because each digit is or , the partial sums are increasing and bounded. They define a real number, with
These bounds follow from the geometric series with all digits equal to or all equal to . In particular, , so it belongs to the set that the list supposedly covers.
Step 4: no row can equal the new number
Choose any row . At position , the number in that row has digit , while has digit . By construction,
The implication uses our decimal convention: all listed expansions avoid eventual nines, and the expansion of , containing only ones and twos, has no terminating-decimal ambiguity. A full explanation is given below.
Since was arbitrary, differs from every number in the list. But is in and should therefore occur in a complete list. This contradiction proves that no such list exists.
Why the decimal convention matters
A difference between two digit strings does not always mean a difference between the numbers they represent. For example,
Changing diagonal digits to or without handling this issue could leave a gap in the proof. Our construction uses only and , so its expansion is neither eventually zero nor eventually nine. The proposed list also uses the convention excluding eventual nines.
Why these are the only ambiguous decimal expansions
Suppose two decimal strings first differ at position , with . The advantage of the larger digit is at least . The entire tail can compensate by at most
Equality between the represented numbers is therefore possible only if , the smaller-digit string has nothing but nines after position , and the larger-digit string has nothing but zeros after that position. Any smaller tail compensation leaves a strict difference.
This explains both and why excluding eventual nines gives a unique expansion. It also shows directly that a string containing only ones and twos cannot participate in such an ambiguity.
What the argument does and does not say
The constructed number depends on the proposed list. The conclusion is “for every list, there exists a missing number,” not that one fixed number is missing from every list. If a new list includes the previous missing number, apply the same construction to that new list: it produces another missing number. An infinite list also has no final row after which a number can simply be appended.
Nor does the construction prove that its new number is irrational. Depending on the diagonal, its digits might repeat. What matters is that it is a real number outside the proposed list. Applying a similar digit-changing rule to a list of rationals does not contradict their countability, because the constructed real number need not be rational.
Since , the real numbers are uncountable too. The irrationals are also uncountable: if they were countable, interleaving their list with a list of the rationals would make all reals countable, contradicting the result just proved.
The same “disagree with row at position ” pattern appears for infinite binary sequences in Sequences and Common Sequences and for subsets of the natural numbers in Naive Set Theory. The objects change; the diagonal construction serves the same purpose.
Countability, numerical order, and available operations must be assessed separately. Adding negative numbers or rational fractions does not change the countably infinite cardinality of the natural numbers; extending to all real numbers does.
Fields, order, and completeness
A field makes arithmetic reversible where permitted
A field has addition and multiplication mapping into , and distinct elements . Addition is associative and commutative, has identity , and gives every element an additive inverse. Multiplication is associative and commutative, has identity , and gives every nonzero element a multiplicative inverse. Multiplication distributes over addition.
Subtraction means adding an additive inverse; division by a nonzero element means multiplying by its inverse. These axioms hold in , , and , but not in , where has no multiplicative inverse, or in , where has no additive inverse.
Distributivity gives
Subtracting yields . Therefore cannot equal .
If and , multiplying by gives . If , the equality holds for all and provides no such conclusion. Likewise, if and , multiplying by gives : a field has no nonzero zero divisors.
Order must be compatible with arithmetic
An ordered field is a field equipped with a total order . The order is reflexive, antisymmetric, transitive, and compares every two elements. It satisfies
and multiplying a strict inequality by a positive element preserves it:
Here antisymmetry uses and to conclude . For the strict order, exactly one of , , and holds. Omitting the equality case would fail already when .
Multiplying by a negative number reverses inequalities. Every square is nonnegative: if , multiply nonnegative factors; if , use with . In particular , and implies by multiplying by the positive number .
The usual orders make and ordered fields. No order can make an ordered field, because would be a nonnegative square, contradicting . The issue is compatibility with field operations, not whether complex numbers can be ordered by some other rule.
Completeness fills an order-theoretic gap
An upper bound for a subset satisfies for all . A supremum, or least upper bound, is an upper bound no larger than any other upper bound. A maximum must belong to ; a supremum need not. For example, has supremum and no maximum.
An ordered field is complete if every nonempty subset that is bounded above has a supremum in that field. The real numbers form a complete ordered field.
The qualifier “in that field” matters. The rational set
has supremum in , but no supremum in . Rational numbers approach from below, and every rational upper bound can be decreased while remaining above . Irrationality of was proved in Indirect Proof. Density of rational numbers in the real line explains these approximations; one proof is an exercise below. Having a number between two others is weaker than having every required supremum. Further development of complete ordered fields is given in Lebl’s Basic Analysis [2][2] J. Lebl, Basic Analysis I: Introduction to Real Analysis, Volume I. . Online edition; Sections 1.1--1.2 on ordered fields and completeness; accessed September 6, 2026. https://www.jirka.org/ra/html/.
Completeness also implies that natural numbers are unbounded above in . Otherwise, if , the smaller number would not be an upper bound, so some would satisfy . Then , contradicting the bound. This Archimedean property ensures integers can be found beyond any fixed real threshold, as needed for floor and ceiling.
Floor, ceiling, and Euclidean remainders
For real , the floor is the greatest integer at most , and the ceiling is the least integer at least . Their defining bounds are
The Archimedean property and the well-ordering of the nonnegative integers ensure these integers exist. Floor rounds downward, not toward zero: , whereas . At an integer , both equal .
For every integer , floor is constant at on , while ceiling is constant at on . These half-open intervals specify the endpoint values precisely.
Put . Its bounds give . Negating reverses the inequalities:
Thus . Replacing by also gives .
A positive divisor fixes the remainder convention
Let and . Set
The floor bounds imply , hence
This proves existence of the Euclidean quotient and remainder. For uniqueness, two such expressions would give . The right side lies strictly between and , whose only integer multiple of is zero. Therefore and .
We write . For example, , so . Divisibility means if for some integer ; for a positive , this is equivalent to a zero remainder. Programming-language operators and conventions for negative divisors must be checked separately; all remainder operations below use positive divisors.
Algorithms need a contract and a correctness argument
A procedure consists of precise, executable steps. To claim that it solves a problem on a specified domain, state valid inputs and required outputs, prove it terminates on every valid input, and prove the returned result meets that requirement. Correctness is not established merely because the arithmetic problem has a solution.
Pseudocode describes these steps without committing to a programming language. The symbol means assignment; an equality in a proof states a mathematical relation. We use exact arithmetic here, so machine overflow is outside this model.
Halving and doubling multiplication
Given and , the following algorithm returns . Only the second input must be nonnegative; zero is included.
Algorithm 1 Halving and Doubling Multiplication
Require: ,
Ensure: the product
1:, ,
2:while do
3:if then
4:
5:end if
6:
7:
8:end while
9:return
For , the loop visits the following values before updating them:
| Contribution to | ||
|---|---|---|
The sum is .
At the start of every iteration, the invariant is . It holds initially. Write the current , where . One full iteration changes the state to , , , giving
Thus the invariant is preserved in both parity cases. While , its new value is a strictly smaller nonnegative integer. The loop therefore terminates. At termination , and the invariant yields . If , the loop is skipped and the result is already correct.
Complexity depends on the input size and cost model
For , after completed iterations, while that state exists,
Repeated integer halving gives this expression; it follows by dividing into a multiple of and a remainder. If , then and . Hence the exact iteration count is
This counts the iteration starting with . For , there are zero iterations and no logarithm is used. The value is also the binary length of a positive , so logarithmic dependence on the numerical value is linear dependence on that input’s bit length.
For eventually nonnegative functions on the natural numbers, write if there exist constants and such that
Write when both upper and lower bounds by positive constant multiples of hold eventually.
Big-O is an asymptotic upper bound on a function, not a statement that an algorithm has been measured, nor a synonym for worst-case analysis. One may bound a worst-case, average-case, or other specified cost function. Common growth rates include , , , , , and .
If each exact integer operation is charged one unit, multiplication above uses loop work for and a constant number of integer registers. That does not mean constant memory in bits: those registers store larger integers as inputs grow. With ordinary binary representations and schoolbook operations, an upper bound is bit operations and working bits, where is the bit length of , taking at least one bit for zero. This bound charges up to for each iteration. A sharper implementation analysis may improve it, but must still state its model.
Recursion defines objects by smaller objects
A recursive definition needs starting cases, construction rules, and a reason the recursive dependencies cannot descend forever. For instance,
defines a unique value for each : reaching the next value uses one already defined. A recursive evaluation of reduces the nonnegative argument until it reaches zero. A formula referring to itself does not by itself guarantee existence, uniqueness, or termination.
Finite full binary trees
Define trees by exactly these rules: is a tree, and if are trees, then is a tree. Nothing else is a tree. Here constructors are distinct and their arguments are ordered, so every non-leaf has unique left and right subtrees. These are finite full binary trees, built using finitely many constructor applications; every internal node has exactly two children.
Define the number of leaves and internal nodes recursively:
This gives a recursive algorithm for counting leaves:
Algorithm 2 Count Leaves
Require: a finite full binary tree
Ensure: the number of leaves in
1:if then
2:return
3:else
4:let
5: CountLeaves()
6: CountLeaves()
7:return
8:end if
Each call uses a proper subtree with fewer nodes, so recursion terminates on the specified finite inputs. This justification would not automatically apply to infinite trees.
Structural induction follows the construction rules
To prove a property for every tree, prove it for , then assume it for arbitrary and prove it for . These cases cover every permitted finite construction. This is structural induction; induction on natural numbers is the corresponding pattern for zero and successor.
For a leaf, . Suppose and , and put . Then
Thus every finite full binary tree has exactly one more leaf than internal nodes. The hypotheses concern both immediate subtrees, rather than an unspecified “previous tree.”
Exercises
For , determine its cardinality, supremum, and whether it has a maximum.
Show solution
The listed values are strictly increasing, giving a bijection from positive integers onto , so is countably infinite. Every value is less than . If , choose an integer using the Archimedean property; then . Thus no number below is an upper bound, and . It is not a maximum because ; also the next listed value always exceeds the current one.
Let be real. Use the Archimedean property and floor to find integers and such that .
Show solution
Choose a positive integer with , then put . The floor bounds give
Dividing by positive proves the claim. This establishes density in the real line without implying uncountability of .
For integer , characterize each condition: , , , , , and .
Show solution
Their equivalent conditions, in the same order, are
The last two are the defining intervals. The second says that integer is a candidate at or below , so it is no greater than the greatest such integer; the first is its negation. For the third and fourth, apply these facts with integer and use that no integer lies strictly between and .
Prove both identities for every integer :
Show solution
If , the two sides of the first equality are , and those of the second are . If , both sides of each equality are . Every integer has one of these forms, including negative integers. For example, gives on both sides of both equalities.
Find the Euclidean quotient and remainder of divided by . Why is truncating toward zero not the required quotient?
Show solution
The quotient is and the remainder is , since with . Truncation gives and hence a remainder of , outside the specified range. The sign convention belongs to the definition, rather than being an implementation detail one can ignore.
Let be a field with three distinct elements. Show that and , and construct its operation tables.
Show solution
By cancellation, . If , then could be neither nor by cancellation, nor because would give . There would be no possible value in . Thus . Next, is neither nor , so it is . Associativity gives
Also because a field has no nonzero zero divisors, and because multiplying by would give . Hence . The tables are
This is arithmetic modulo , with representing . The additive inverse of is , and the additive inverse of is ; inverse relationships are mutual.
Can fields have exactly four or exactly six elements? Distinguish a four-element field from arithmetic modulo .
Discussion guide
A four-element field exists with elements . Compute polynomial coefficients modulo and reduce using . Formally, this is the polynomial quotient by over the two-element field. The inherited operations satisfy the ring laws, and its nonzero elements have inverses: and . In contrast, modulo , the nonzero element has square zero, so that arithmetic is not a field.
A finite field has prime characteristic : the smallest positive number of copies of summing to zero cannot be composite, since a factorization would give nonzero zero divisors. It contains a copy of the -element field. As a vector space over that subfield it has some finite dimension , so counting coefficient choices gives exactly elements. Six is not a prime power, so a six-element field cannot exist. This argument previews polynomial quotients and vector spaces; those constructions belong to Abstract Algebra.
Assume an associative multiplication with identity , and let . Prove that the following algorithm returns . Powers of exponent zero mean the identity.
Algorithm 3 Square-and-Multiply
Require: and an element
Ensure:
1:, ,
2:while do
3:if then
4:
5:end if
6:
7:
8:end while
9:return
Show solution
Use as the invariant. Initially it holds. Write the current with . The updated values are , , and , so
Associativity and laws for powers of the same element suffice; arbitrary elements need not commute. Positive strictly decreases, so the loop terminates. At the invariant says . For it returns the identity without entering the loop. For positive the number of iterations is , as in multiplication. Any lower bound asserting applies only before termination, not for every nonnegative .
Give a leaf height zero and define a node’s height as one plus the maximum of its two subtree heights. Prove that a finite full binary tree of height has at most leaves.
Show solution
A leaf has leaves. At a node of height , both subtree heights are at most . By the two induction hypotheses, each subtree has at most leaves, so together they have at most . This proves the claim for every finite constructor-built tree; no assumption that the two subtrees have equal height is needed.
An implementation uses three integer variables and makes loop iterations. Does that alone prove bit space and bit time?
Show solution
No. A constant number of variables gives a constant register count, but their values may require an increasing number of bits. Similarly, iterations imply time only when each iteration has bounded cost in the stated model. Exact arithmetic on growing integers must account for operand lengths. Identify both input encoding and operation cost before reporting a complexity bound.
References
- [1] E. Lehman, F. T. Leighton, and A. R. Meyer, Mathematics for Computer Science. MIT OpenCourseWare, 2015. Revised May 18, 2015; infinite sets, recursive data, and invariants. https://ocw.mit.edu/courses/6-042j-mathematics-for-computer-science-spring-2015/mit6_042js15_textbook.pdf ↩
- [2] J. Lebl, Basic Analysis I: Introduction to Real Analysis, Volume I. . Online edition; Sections 1.1--1.2 on ordered fields and completeness; accessed September 6, 2026. https://www.jirka.org/ra/html/ ↩
Comments