Beyond FOIL
What’s wrong with FOIL?
The FOIL (First, Outer, Inner, Last) method to algebraic multiplication states that:
{$(a + b)(c + d) \quad = \quad \underbrace{a c}_{\text{First}} \quad + \quad \underbrace{a d}_{\text{Outer}} \quad + \quad \underbrace{b c}_{\text{Inner}} \quad + \quad \underbrace{b d}_{\text{Last}}$}
This is a special case of the Distributive Law. The FOIL method is very inefficient when multiplying lots of terms together, like in {$(a+b+f+g)(c+d+e)$}. Using FOIL, one gets
{$\Big(\underline{a+b}\,+\,\underline{f+g}\Big) \quad\quad \Big(\underline{c+d}\,+\,\underline{e}\Big)$}
{$= \underbrace{(a+b) (c+d)}_{\text{First}} \;+\; \underbrace{(a+b) e}_{\text{Outer}} \;+\; \underbrace{(f+g) (c+d)}_{\text{Inner}} \;+\; \underbrace{(f+g) e}_{\text{Last}}$}
{$= \; \ldots$}
and FOIL must be used again on each term. Instead it is better to think directly in terms of the Distributive Law. This becomes more obvious when we look at multiplication geometrically.
Beyond FOIL
The area of a rectangle of height {$a$} and width {$c$}
c
XXXXXXXXXX
a XXXXXXXXXX
XXXXXXXXXX
is {$a \times c$}. Similarly, a rectangle of height {$(a+b)$} and width {$(c+d)$} has area
c + d
XXXXXXXXXXxxx
a XXXXXXXXXXxxx
+ XXXXXXXXXXxxx
b OOOOOOOOOOooo
OOOOOOOOOOooo
is {$(a+b)\times(c+d)$}. This rectangle decomposes into four separate rectangles with areas {$a c, \, a d, \, b c, \, b d$}
c d c d
XXXXXXXXXX xxx XXXXXXXXXX xxx
a XXXXXXXXXX xxx a XXXXXXXXXX a xxx
XXXXXXXXXX xxx ===> XXXXXXXXXX xxx
b OOOOOOOOOO ooo c d
OOOOOOOOOO ooo b OOOOOOOOOO b ooo
OOOOOOOOOO ooo
demonstrating that the total area {$(a + b)(c + d)$} does indeed equal {$a c + a d + b c + b d$} as predicted by FOIL.
Now we can expand {$(a+b+f+g)(c+d+e)$} just as easily
c + d + e
XXXXXXXXXXxxxeeee
a XXXXXXXXXXxxxeeee
+ XXXXXXXXXXxxxeeee
b OOOOOOOOOOoooEEEE
+ OOOOOOOOOOoooEEEE
f CCCCCCCCCCcccBBBB
+ DDDDDDDDDDdddGGGG
g DDDDDDDDDDdddGGGG
DDDDDDDDDDdddGGGG
by noting the smaller rectangles that form the larger one:
c d e
c d e XXXXXXXXXX xxx eeee
XXXXXXXXXX xxx eeee a XXXXXXXXXX a xxx a eeee
a XXXXXXXXXX xxx eeee XXXXXXXXXX xxx eeee
XXXXXXXXXX xxx eeee
c d e
b OOOOOOOOOO ooo EEEE b OOOOOOOOOO b ooo b EEEE
OOOOOOOOOO ooo EEEE ===> OOOOOOOOOO ooo EEEE
f CCCCCCCCCC ccc BBBB c d e
f CCCCCCCCCC f ccc f BBBB
DDDDDDDDDD ddd GGGG
g DDDDDDDDDD ddd GGGG c d e
DDDDDDDDDD ddd GGGG DDDDDDDDDD ddd GGGG
g DDDDDDDDDD g ddd g GGGG
DDDDDDDDDD ddd GGGG
Going row by row on the figure at the right, we can see that {$(a+b+f+g)(c+d+e) = a c + a d + a e \quad + \quad b c + b d + b e \quad + \quad f c + f d + f e \quad + \quad g c + g d + g e$}.
See the pattern? Every variable on the left side (i.e. {$a, b, f, g$}) is multiplied by every term on the right side (i.e. {$c, d, e$}), and all these products are added together. This is the Distributive Law in its most general form.