Commutative, Associative and Distributive Properties
Three properties of addition and multiplication explain almost every simplification in algebra: you may swap the order (commutative), regroup (associative) and multiply into a bracket (distributive). This lesson states each one with letters, shows where it fails (subtraction, division and floating-point numbers) and connects it to the arithmetic version in Properties of Operations.
The three properties
For all numbers , and :
| Property | Addition | Multiplication |
|---|---|---|
| Commutative (order) | ||
| Associative (grouping) | ||
| Distributive (links and ) |
Two related facts are worth knowing by name: the identities and , and the inverses and for .
Using them in algebra
The commutative and associative properties let you reorder a sum or product and collect pieces you want together:
The distributive property works in both directions. Forwards it expands a product, backwards it factors out a common factor:
SymPy confirms these identities by checking that the difference simplifies to 0:
from sympy import symbols, expand, factor, simplify
a, b, c, x = symbols("a b c x")
print(simplify(a*(b + c) - (a*b + a*c))) # 0 means always equal
print(expand(4*(2*x - 3)))
print(factor(6*x + 9))
print(expand(-(x - 7))) # a minus sign is a factor of -10
8*x - 12
3*(2*x + 3)
7 - x
Where the properties fail
Subtraction and division are not commutative or associative:
The fix is to rewrite subtraction as adding a negative and division as multiplying by a reciprocal: , and then the addition properties apply again. That is why algebra keeps the sign attached to its term.
Note: Exponents do not distribute over addition: is not . With , : 25 versus 13. The square of a sum is expanded with the distributive property, as in Multiplying Polynomials.
In software: floating point breaks associativity
On real numbers the properties hold exactly. Computer floats round after every operation, so addition of floats is commutative but not associative:
a, b, c = 0.1, 0.2, 0.3
print((a + b) + c)
print(a + (b + c))
print((a + b) + c == a + (b + c))
big = 1e16
print((big + 1.0) - big, "vs", big - big + 1.0)0.6000000000000001
0.6
False
0.0 vs 1.0
This has real consequences:
- Compilers will not reorder float additions unless you allow it (
-ffast-mathin C/C++), because the answer can change. - Parallel sums on a GPU add numbers in a different grouping than a sequential loop, so a neural network's loss can differ in the last digits between runs.
- Integer arithmetic and Python's
Fractiondo obey all three properties, which is why exact money code uses integers (cents) or decimals. See Floating Point.
The distributive property is also the basis of a classic optimisation: a*x + a*y costs two multiplications, a*(x + y) only one. Compilers apply it to integers, and Horner's method uses it to evaluate polynomials quickly.
Exercises
Exercise 1: Name the property
Which property justifies each step? (a) , (b) , (c) .
Answer
(a) commutative (addition), (b) associative (multiplication), (c) distributive.
Solution
(a) only the order changes. (b) only the grouping changes. (c) multiplication by 5 is spread over both terms of the bracket.
Exercise 2: Mental math
Use the distributive property to compute without a calculator.
Answer
600
Solution
Exercise 3: Factor out
Factor the greatest common factor from .
Answer
Solution
The GCF of 12, 18 and 6 is 6. Divide each term by 6: , and 1. Note the last term becomes 1, not 0.
from sympy import symbols, factor
x, y = symbols("x y")
print(factor(12*x - 18*y + 6))6*(2*x - 3*y + 1)
Exercise 4: Order changes a float sum
Add the list [1e16, 1.0, -1e16, 1.0] from left to right with a loop, and then in the order [1e16, -1e16, 1.0, 1.0]. What does each give, and what is the true sum?
Answer
1.0 for the first order, 2.0 for the second; the exact sum is 2.
Solution
In the first order, 1e16 + 1.0 rounds back to 1e16 (a float near has spacing 2), so the first 1.0 is lost. In the second order the big values cancel first and both 1.0s survive.
def loop_sum(xs):
total = 0.0
for v in xs:
total += v
return total
print(loop_sum([1e16, 1.0, -1e16, 1.0]), loop_sum([1e16, -1e16, 1.0, 1.0]))1.0 2.0
Test yourself
Which equation shows the associative property?
Which operation is commutative?
- Subtraction
- Division
- Exponentiation
- Multiplication
Why can differ from in a program using floats?
- Python has a bug
- Each float addition is rounded, so the grouping changes which roundings happen
- Floats are not commutative
- The distributive property fails