Abstract Algebra — 00 · Integers, Relations and Modular Arithmetic
Abstract algebra studies structures: a set together with one or more operations that obey a short list of rules. Instead of asking "what is ?", it asks "which facts about multiplication follow from the rules alone, so that they hold for integers, for clock arithmetic, for matrices, for symmetries of a molecule, all at once?". That shift pays off in many places: symmetry (crystallography, chemistry, physics), cryptography (RSA and elliptic-curve systems are group theory in disguise), coding theory (error-correcting codes on every phone and disk are built over finite fields), and the classical question of solving polynomial equations, which Galois settled with groups. This series follows the standard senior undergraduate path of Dummit & Foote, Gallian, Artin and Fraleigh: groups, then rings and fields, then Galois theory. Post 00 lays the ground: the proof methods used throughout, sets and functions, equivalence relations, and the arithmetic of the integers up to modular arithmetic, the Chinese remainder theorem and a small but complete RSA example. Every later post uses and as its first examples.
Series map: 00 Integers, Relations & Modular Arithmetic (this post) → 01 Groups & Subgroups → 02 Cosets, Lagrange & Quotient Groups → 03 Homomorphisms, Group Actions & Sylow → 04 Rings, Ideals & Fields → 05 Field Extensions & Galois Theory.
Learning Outcome
- Read and write the four basic proof patterns: direct, contrapositive, contradiction, induction.
- Decide whether a function is injective, surjective or bijective, and use the fact that bijections are exactly the invertible functions.
- Prove that an equivalence relation on a set is the same thing as a partition of that set.
- State and prove the division algorithm from the well-ordering principle.
- Run the Euclidean algorithm and the extended Euclidean algorithm by hand, and prove Bézout's identity and Euclid's lemma.
- Prove the fundamental theorem of arithmetic (existence and uniqueness).
- Compute in , find inverses, and decide which classes are units.
- Use Euler's function, Fermat's little theorem and Euler's theorem to reduce huge powers.
- Solve simultaneous congruences with the Chinese remainder theorem.
- Carry out a toy RSA key generation, encryption and decryption, and explain why decryption works.
Chapter 1 — The proof toolkit
Abstract algebra is a proof-based subject. Almost every statement is an implication "if then ", and there are four standard ways to prove one.
Terminology
- Proposition / theorem / lemma / corollary — a proved statement; a lemma is a helper, a corollary follows quickly from a theorem.
- Definition — fixes the meaning of a word. Definitions are "if and only if" even when written with "if".
- Contrapositive of "" is "not not ". It is logically equivalent to the original.
- Converse of "" is "". It is a different statement and may be false.
- Counterexample — one concrete case that shows a universal statement is false.
Direct proof
Assume , reason forward, reach .
Claim. The sum of two odd integers is even.
Proof. Odd integers can be written and with . Their sum is , which is even.
Proof by contrapositive
Prove "not not " instead.
Claim. If is even, then is even.
Proof. Contrapositive: if is odd then is odd. Write ; then , which is odd.
Proof by contradiction
Assume the statement is false and derive something impossible.
Claim. is irrational.
Proof. Suppose with integers , , and the fraction in lowest terms. Then , so is even, so is even by the previous claim. Write : then , so is even and is even. Both and are even, contradicting lowest terms.
Proof by induction
To prove a statement for all integers : prove (the base case), then prove for every (the inductive step). In strong induction the inductive step may assume all at once.
Claim. For every , .
Proof. Base case : . Inductive step: if the sum of the first odd numbers is , adding the next one gives .
Watch out: proving the converse is not proving the statement. "If is even then is even" is true, but it does not prove "if is even then is even"; that needed its own proof above.
Chapter 2 — Sets, functions and equivalence relations
Terminology
- (some books start at 1; this series includes 0), the integers, the rationals, the reals, the complex numbers.
- is the Cartesian product.
- A function assigns to each exactly one . is the domain, the codomain, the image.
- is injective (one-to-one) if implies .
- is surjective (onto) if every equals for some .
- is bijective if it is both. A bijection from a set to itself is a permutation of the set.
- A relation on is a subset ; write when .
Functions and inverses
Examples on : is injective but not surjective (odd numbers are missed). is surjective but not injective (). is bijective with inverse .
Proposition 2.1. A function has an inverse function (with and ) if and only if is bijective.
Proof. If exists: gives , so is injective; and any equals , so is surjective. Conversely, if is bijective, each has exactly one preimage; define to be it. Then both compositions are identities.
Proposition 2.2 (pigeonhole). If is a finite set and is injective, then is bijective.
Proof. An injective sends the elements of to distinct elements of , so the image is all of .
This small fact drives the proofs of Fermat's little theorem below and of Cayley's theorem later in the series. It is false for infinite sets: on is injective but not surjective.
Equivalence relations
A relation on is an equivalence relation if it is
- reflexive: for all ;
- symmetric: implies ;
- transitive: and imply .
The equivalence class of is .
Examples: equality on any set; "same birthday" on people; " is divisible by " on (Chapter 5); "same determinant" on matrices. Non-examples: on is reflexive and transitive but not symmetric; "" on is reflexive and symmetric but not transitive (, , but ).
A partition of is a collection of non-empty subsets of such that every element of lies in exactly one of them.
Theorem 2.3 (equivalence relations = partitions). If is an equivalence relation on , its equivalence classes form a partition of . Conversely, every partition of comes from exactly one equivalence relation: if and only if and lie in the same block of .
Proof. Each class is non-empty and every lies in a class, because by reflexivity. It remains to show that two classes are either equal or disjoint. Suppose , so and . Take any : then , (symmetry), , so by transitivity twice, and . Hence , and by the same argument . So overlapping classes are equal.
Conversely, given a partition, "same block" is reflexive (every element is in a block), symmetric (obvious), and transitive (if share block and share block , then , so because blocks are disjoint). Its classes are exactly the blocks.
Trick: to show two classes are equal it is enough to find one common element. This "one overlap means equal" step is used again for cosets in post 02, where it gives Lagrange's theorem almost for free.
Chapter 3 — Divisibility, gcd and the Euclidean algorithm
Terminology
- divides , written , if for some integer . Every integer divides ; divides only .
- A prime is an integer whose only positive divisors are and . An integer that is not prime is composite.
- The greatest common divisor of integers not both zero is the largest integer dividing both. Set .
- and are coprime (relatively prime) if .
- Well-ordering principle: every non-empty set of non-negative integers has a least element. It is equivalent to induction and is taken as an axiom about .
The division algorithm
Theorem 3.1 (division algorithm). For integers and with there are unique integers with
Proof. Existence: let . is non-empty (take ; then ). By well-ordering has a least element . If , then is a smaller element of , a contradiction. So .
Uniqueness: if with both remainders in , then and . The only multiple of strictly between and is , so and .
For negative the remainder is still non-negative: , not .
Common pitfall: in many programming languages
-17 % 5returns-2(C, Java, JavaScript) while Python returns3. Mathematics always uses .
The Euclidean algorithm
Lemma 3.2. If , then .
Proof. Any common divisor of and divides ; any common divisor of and divides . The two pairs have the same common divisors, so the same greatest one.
Repeating the division algorithm, the remainders strictly decrease and so reach ; the last non-zero remainder is the gcd. For :
So . The number of steps is small: it grows like the number of digits (Lamé's theorem bounds it by five times the number of decimal digits of the smaller number).
Bézout's identity and the extended algorithm
Theorem 3.3 (Bézout). For integers not both zero, there are integers with . Moreover is the smallest positive integer of the form .
Proof. Let . It is non-empty (it contains ), so it has a least element . Divide: with . Then has the same form, so by minimality and . Likewise . Any common divisor of divides , so . Hence .
The proof shows exist but does not find them. The extended Euclidean algorithm does: keep, next to every remainder , integers with . Start with and ; each new row is "row two above minus times row above".
| check | |||||
|---|---|---|---|---|---|
| 0 | 240 | — | 1 | 0 | 240 |
| 1 | 46 | — | 0 | 1 | 46 |
| 2 | 10 | 5 | 1 | −5 | 240 − 230 = 10 |
| 3 | 6 | 4 | −4 | 21 | −960 + 966 = 6 |
| 4 | 4 | 1 | 5 | −26 | 1200 − 1196 = 4 |
| 5 | 2 | 1 | −9 | 47 | −2160 + 2162 = 2 |
| 6 | 0 | 2 | — | — | stop |
So . The same answer comes from back-substitution, reading the divisions from the bottom up: .
Trick: the are not unique: works for every integer , because . Add a check column like the one above; one wrong sign early ruins every later row.
Euclid's lemma
Theorem 3.4 (Euclid's lemma). If and , then . In particular, if a prime divides , then or .
Proof. By Bézout, for some . Multiply by : . The number divides and divides (because ), so . For the prime case: if then (the only positive divisors of are and ), so .
Watch out: the prime hypothesis matters. but and .
Chapter 4 — The fundamental theorem of arithmetic
Theorem 4.1 (fundamental theorem of arithmetic). Every integer can be written as a product of primes , and this factorisation is unique up to the order of the factors.
Proof. Existence, by strong induction on . If is prime, it is its own factorisation. Otherwise with ; by the induction hypothesis both and are products of primes, so is too.
Uniqueness, by induction on . Suppose with all prime. Then divides , so by Euclid's lemma (applied repeatedly) for some . Since is prime and , . Reorder so that and cancel: is a smaller number (or both sides are empty products equal to ), and by induction the remaining primes agree up to order.
Grouping equal primes gives the canonical form with . Examples: , , .
Corollary 4.2 (Euclid). There are infinitely many primes.
Proof. Given primes , the number has a prime factor by Theorem 4.1. If were some , then would divide , which is impossible. So no finite list contains every prime.
Uniqueness is not automatic. In the set , gives two genuinely different factorisations into elements that cannot be split further. Explaining when unique factorisation holds is one of the main themes of ring theory (post 04).
Chapter 5 — Congruences and
Terminology
- Fix an integer , the modulus. is congruent to modulo , written , if .
- The class of is , also written or just when the modulus is clear.
- (also written ) is the set of the classes .
- A class is a unit if there is with . The units form , also written .
- A non-zero class is a zero divisor if for some non-zero .
Congruence mod is an equivalence relation: (reflexive); implies (symmetric); and imply (transitive). By Theorem 2.3 its classes partition , and by the division algorithm each class contains exactly one of , so there are exactly classes.
Arithmetic on classes
Define and .
Proposition 5.1. These operations are well defined: the result does not depend on which representatives are chosen.
Proof. Suppose and , say and . Then and .
"Well defined" is the central worry whenever an operation is defined on classes through representatives. The same check, done for cosets, is what forces the definition of a normal subgroup in post 02.
In practice: reduce early and often. For example : (checked below), and , so .
Units and zero divisors
In : , so and are zero divisors. On the other hand , and . The units are exactly , the classes coprime to , and each of them is its own inverse.
Theorem 5.2. is a unit in if and only if . If and , then is a zero divisor.
Proof. If , Bézout gives , so and is the inverse. Conversely if , then , so and every common divisor of and divides . For the last claim: , and because .
Corollary 5.3. has every non-zero class invertible if and only if is prime.
Theorem 5.2 is also an algorithm: the inverse is the Bézout coefficient. To invert modulo : , , . Back-substitute: . So . Check: .
Linear congruences
Theorem 5.4. The congruence has a solution if and only if divides . In that case it has exactly solutions modulo .
Proof sketch. A solution means for some , and by Bézout the values of are exactly the multiples of . If , divide through: , and is a unit mod , so is unique mod . That single class mod splits into classes mod .
Example: . Here divides . Divide by 2: . Since , , so , giving or . Check: and .
Common pitfall: you may not "divide both sides" of a congruence by a number that is not a unit. , but . Division by modulo is multiplication by , which exists only when ; otherwise the modulus must be divided too, as above.
Chapter 6 — Euler's phi, Fermat and Euler
Euler's phi function
is the number of integers in coprime to ; by Theorem 5.2 it is the number of units, .
- For a prime : .
- For a prime power: , because the numbers in not coprime to are exactly the multiples of .
- Multiplicative: if then . This follows from the Chinese remainder theorem (Chapter 7): is coprime to exactly when it is coprime to both and , and the CRT bijection matches such with pairs of units.
Together these give, for ,
Examples: (the units ); ; ; .
Fermat's little theorem
Theorem 6.1 (Fermat's little theorem). If is prime and , then . Consequently for every integer .
Proof. Consider the map on the set of non-zero classes mod . It lands in (a product of two units is a unit, so never ) and is injective, because implies after multiplying by . By the pigeonhole Proposition 2.2 it is a bijection, so it just reorders . Multiply all elements of both ways:
that is . Every factor of is a unit, so is a unit and can be cancelled: . For the second statement multiply by ; if both sides are .
Check with , : multiplying by 3 gives modulo 7, the same six classes in a new order, and .
Euler's theorem
Theorem 6.2 (Euler). If , then .
Proof. Repeat the proof above with the set of the units mod instead of : permutes , so , and the product of units is a unit, so it cancels.
Fermat is the case . Post 02 re-proves both in one line from Lagrange's theorem, because is a group of order and the order of an element divides the order of the group.
Example: the last digit of . and , so . Since , . The last digit is 9.
Watch out: Euler's theorem needs . , not 1. Also, is an exponent that always works, not always the smallest one: modulo 12, every unit already satisfies although .
Chapter 7 — The Chinese remainder theorem
Theorem 7.1 (Chinese remainder theorem). Let be pairwise coprime positive integers and . For any integers the system
has a solution, and any two solutions are congruent modulo .
Proof. Existence: put . Since is coprime to every other , it is coprime to , so there is with . Let . Modulo , every term with vanishes (because ), and the -th term is . Uniqueness: if both work, each divides ; the are pairwise coprime, so (by Euclid's lemma, repeatedly) their product divides .
Worked example (Sunzi's classic puzzle). Find with , , . Here .
| 1 | 3 | 2 | 35 | 2 | 2 | 140 |
| 2 | 5 | 3 | 21 | 1 | 1 | 63 |
| 3 | 7 | 2 | 15 | 1 | 1 | 30 |
Sum: . Check: , , .
In structural language, the theorem says that the map , , is a bijection that respects addition and multiplication. Both sides have elements, so it is enough to know the map is injective, which is the uniqueness part. Post 01 meets the additive version as " is the same group as ", and post 04 the ring version.
Common pitfall: the moduli must be pairwise coprime. The system , has no solution: the first says is even, the second says is odd.
Chapter 8 — A toy RSA
RSA (Rivest, Shamir and Adleman, 1978) is Euler's theorem put to work. The numbers below are tiny so that every step can be checked by hand; real keys use primes of about 1024 bits or more and a padding scheme, and textbook RSA as shown here is not secure.
Key generation.
- Pick primes , . The modulus is .
- .
- Pick a public exponent coprime to 160: .
- The private exponent is : since , .
Public key ; private key .
Encryption of the message (any integer with ): , computed by repeated squaring so that no number exceeds :
So the ciphertext is .
Decryption: . Write and square repeatedly: , , , . Then
The original message comes back.
Why it works. for some . If , Euler gives . (If shares a factor with , the result still holds: check it modulo and modulo separately with Fermat, then combine with the CRT.)
Why it is believed hard to break. Anyone who knows can compute with the extended Euclidean algorithm, and is easy from and . So the security rests on the difficulty of factoring ; no fast classical factoring algorithm is known.
Practice Exercises
1. Prove by induction that for every integer .
Solution
Base: . Step: . The first term is divisible by 6 by hypothesis; is a product of consecutive integers, hence even, so is divisible by 6. (A direct proof also works: is a product of three consecutive integers, so it is divisible by 2 and by 3.)
2. On define if . Show this is an equivalence relation and describe the partition.
Solution
It is "" for the function , and any relation of that form inherits reflexivity, symmetry and transitivity from equality. The classes are the circles centred at the origin, plus the single point .
3. Use the extended Euclidean algorithm to find and integers with .
Solution
, , , . So the gcd is 18. Back-substitute: . Check: .
4. Find all solutions of by the method of Theorem 5.4, and explain why has none.
Solution
As in Chapter 5: or . For the second congruence, does not divide 5: the left side is always even, the right side is odd.
5. Compute and the last two digits of .
Solution
By Fermat ; , so . For the last two digits work mod 100: and , so ; , so . Now , , . (The order of 3 mod 100 is actually 20, a divisor of 40.) So . The last two digits are 29.
6. Solve , .
Solution
. , so ; and , so . Then . Check: and .
7. With , and , find , and ; encrypt and decrypt the result.
Solution
, , because . Encrypt: , so . Decrypt: , , , . With : , , . The message 7 comes back.
Cheat-sheet
| Idea | Statement or method |
|---|---|
| Equivalence relation | reflexive, symmetric, transitive; classes partition the set |
| Division algorithm | , , unique |
| Euclidean algorithm | ; last non-zero remainder |
| Bézout | ; gcd is the least positive such value |
| Extended Euclid | new row = row two above minus times row above |
| Euclid's lemma | or |
| FTA | unique factorisation into primes, up to order |
| classes; and well defined | |
| Unit test | invertible iff ; inverse from Bézout |
| solvable iff ; then solutions | |
| Euler phi | over primes |
| Fermat | if |
| Euler | if |
| CRT | pairwise coprime moduli: unique solution mod |
| RSA | , , , mod |
What's next
Post 01 takes the pattern seen here (a set, one operation, an identity, inverses) and turns it into the definition of a group. under addition, under addition and under multiplication become the first examples, joined by permutations, symmetries of polygons, invertible matrices and the quaternions. The division algorithm reappears in the proof that every subgroup of a cyclic group is cyclic, and returns in the formula for the order of in .
References
- David S. Dummit and Richard M. Foote, Abstract Algebra, 3rd edition, Wiley, 2004 — Chapter 0 (preliminaries: relations, integers, ).
- Joseph A. Gallian, Contemporary Abstract Algebra, 10th edition, CRC Press, 2021 — Chapter 0 (preliminaries, including the RSA-style applications).
- Michael Artin, Algebra, 2nd edition, Pearson, 2011.
- John B. Fraleigh, A First Course in Abstract Algebra, 7th edition, Addison-Wesley, 2003 — Section 0 (sets and relations).
- Ivan Niven, Herbert S. Zuckerman and Hugh L. Montgomery, An Introduction to the Theory of Numbers, 5th edition, Wiley, 1991 — divisibility, congruences, the CRT.
- Thomas W. Judson, Abstract Algebra: Theory and Applications (open textbook), judsonbooks.org — chapters on the integers and on RSA.
- MIT OpenCourseWare, 18.701 Algebra I (Fall 2010) — lecture notes and problem sets following Artin.
- R. L. Rivest, A. Shamir and L. Adleman, "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems", Communications of the ACM 21(2), 1978, pp. 120–126.
Note: this post is in progress. Planned additions: a proof that well-ordering and induction are equivalent, the CRT proof of multiplicativity of written out in full, Wilson's theorem, and a short section on fast modular exponentiation cost (number of multiplications versus bit length).










