How the Is Modulo Multiplication and Addition Associative, Distributive, and Commutative? works
Modular arithmetic — sometimes called "clock arithmetic" — works with the remainder left over after dividing by a fixed modulus n. Formally, mod(x, n) is defined as the unique value r with 0 ≤ r < n such that x = kn + r for some integer k, which in code is ((x % n) + n) % n so it stays correct even for negative x. The set of remainders {0, 1, …, n−1} under addition and multiplication mod n forms what mathematicians call a commutative ring, and this calculator lets you plug in three integers a, b, c and a modulus n to see, concretely, why addition and multiplication mod n are always associative and commutative, and why multiplication always distributes over addition mod n.
Formula and method
The calculator checks four identities directly by computing both sides and comparing them:
- Associativity of addition: ((a + b) mod n + c) mod n = (a + (b + c) mod n) mod n
- Associativity of multiplication: ((a × b) mod n × c) mod n = (a × (b × c) mod n) mod n
- Distributivity: a × (b + c) mod n = ((a × b) mod n + (a × c) mod n) mod n
- Commutativity: a + b mod n = b + a mod n, and a × b mod n = b × a mod n
Why these hold for every modulus
Reducing a number mod n is a ring homomorphism from the integers ℤ onto ℤ/nℤ: it maps sums to sums and products to products. Since ordinary integer addition and multiplication are already associative, commutative, and mutually distributive, taking remainders never breaks those laws — the same relationships simply carry over to the reduced values, for any n ≥ 1. That is why every check below always comes back "Yes"; the calculator's job is to make that abstract guarantee concrete with your own numbers.
Operations that do not share these properties
- Subtraction is not commutative: a − b mod n generally differs from b − a mod n unless a ≡ b (mod n).
- Division is not always defined: a ÷ b mod n only makes sense when b has a multiplicative inverse mod n, which requires gcd(b, n) = 1.
- Exponentiation is neither commutative nor associative in general: a^b mod n ≠ b^a mod n, and (a^b)^c mod n ≠ a^(b^c) mod n.
Where this matters
- Cryptography (RSA, Diffie-Hellman) relies on associativity and distributivity mod n to make modular exponentiation computable via repeated squaring.
- Hash tables and checksums use the fact that (a + b) mod n can be computed incrementally, one addition at a time, without recomputing the whole sum.
- The Chinese Remainder Theorem and other number-theory algorithms depend on addition and multiplication mod n behaving exactly like their integer counterparts.