TExcelTAD
Home › Algebra › Commutative, Associative and Distributive Properties

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 aa, bb and cc:

Property Addition Multiplication
Commutative (order) a+b=b+aa + b = b + a a⋅b=b⋅aa \cdot b = b \cdot a
Associative (grouping) (a+b)+c=a+(b+c)(a + b) + c = a + (b + c) (a⋅b)⋅c=a⋅(b⋅c)(a \cdot b) \cdot c = a \cdot (b \cdot c)
Distributive (links ×\times and ++) a(b+c)=ab+aca(b + c) = ab + ac (b+c)a=ba+ca(b + c)a = ba + ca

Two related facts are worth knowing by name: the identities a+0=aa + 0 = a and a⋅1=aa \cdot 1 = a, and the inverses a+(−a)=0a + (-a) = 0 and a⋅1a=1a \cdot \frac{1}{a} = 1 for a≠0a \ne 0.

Using them in algebra

The commutative and associative properties let you reorder a sum or product and collect pieces you want together:

3x+5+2x=3x+2x+5commutative: swap 5 and 2x=(3+2)x+5distributive, read backwards=5x+5\begin{aligned} 3x + 5 + 2x &= 3x + 2x + 5 && \text{commutative: swap 5 and } 2x \\ &= (3 + 2)x + 5 && \text{distributive, read backwards} \\ &= 5x + 5 \end{aligned}

The distributive property works in both directions. Forwards it expands a product, backwards it factors out a common factor:

expand: 4(2x−3)=8x−12factor: 6x+9=3(2x+3)mental: 7⋅98=7(100−2)=700−14=686\begin{aligned} \text{expand: } 4(2x - 3) &= 8x - 12 \\ \text{factor: } 6x + 9 &= 3(2x + 3) \\ \text{mental: } 7 \cdot 98 &= 7(100 - 2) = 700 - 14 = 686 \end{aligned}

SymPy confirms these identities by checking that the difference simplifies to 0:

python · try it yourself
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 -1
0
8*x - 12
3*(2*x + 3)
7 - x

Where the properties fail

Subtraction and division are not commutative or associative:

9−4≠4−9(5 vs −5)(12÷6)÷2≠12÷(6÷2)(1 vs 4)\begin{aligned} 9 - 4 &\ne 4 - 9 && (5 \text{ vs } {-5}) \\ (12 \div 6) \div 2 &\ne 12 \div (6 \div 2) && (1 \text{ vs } 4) \end{aligned}

The fix is to rewrite subtraction as adding a negative and division as multiplying by a reciprocal: 9−4=9+(−4)9 - 4 = 9 + (-4), 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: (a+b)2(a + b)^2 is not a2+b2a^2 + b^2. With a=2a = 2, b=3b = 3: 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:

python · try it yourself
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-math in 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 Fraction do 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) 7+y=y+77 + y = y + 7, (b) 2(3k)=(2⋅3)k2(3k) = (2 \cdot 3)k, (c) 5(x−4)=5x−205(x - 4) = 5x - 20.

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 6⋅47+6⋅536 \cdot 47 + 6 \cdot 53 without a calculator.

Answer

600

Solution
6⋅47+6⋅53=6(47+53)=6⋅100=6006 \cdot 47 + 6 \cdot 53 = 6(47 + 53) = 6 \cdot 100 = 600

Exercise 3: Factor out

Factor the greatest common factor from 12x−18y+612x - 18y + 6.

Answer

6(2x−3y+1)6(2x - 3y + 1)

Solution

The GCF of 12, 18 and 6 is 6. Divide each term by 6: 2x2x, −3y-3y and 1. Note the last term becomes 1, not 0.

python · try it yourself
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 101610^{16} has spacing 2), so the first 1.0 is lost. In the second order the big values cancel first and both 1.0s survive.

python · try it yourself
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?

  1. a+b=b+aa + b = b + a
  2. (a+b)+c=a+(b+c)(a + b) + c = a + (b + c)
  3. a(b+c)=ab+aca(b + c) = ab + ac
  4. a+0=aa + 0 = a

Which operation is commutative?

  1. Subtraction
  2. Division
  3. Exponentiation
  4. Multiplication

Why can (a+b)+c(a + b) + c differ from a+(b+c)a + (b + c) in a program using floats?

  1. Python has a bug
  2. Each float addition is rounded, so the grouping changes which roundings happen
  3. Floats are not commutative
  4. The distributive property fails