Sub topic 8
Collecting variables when they appear on both sides
This chapter assumes you can solve one-step and two-step equations with inverse operations, distribute a number over parentheses, and combine like terms. It also assumes you know that every move on one side of an equation must be matched on the other side. Here you will learn a method for equations where the variable appears on both sides of the equals sign, and you will see where the method goes wrong.
The goal: get the variable on one side
In a two-step equation such as 2x + 3 = 11, the variable appears once. An equation such as 5x - 4 = 2x + 8 has x on both sides. You cannot undo one operation at a time, because x is tied up in two places.
The fix is to use the balance principle to move all variable terms to one side and all plain numbers to the other. After that, the equation is one you already know how to solve.
The rule is: add or subtract a variable term on both sides, exactly as you would a number. Subtracting 2x from both sides of 5x - 4 = 2x + 8 gives an equivalent equation, so the solution does not change.
A repeatable procedure
- Simplify each side separately. Distribute over parentheses and combine like terms.
- Choose a side for the variable terms. Either side works. Pick the side that leaves a positive coefficient if you want to avoid negative signs.
- Add or subtract the variable term from the other side to remove it there.
- Add or subtract the constant on the variable's side to isolate the variable term.
- Divide both sides by the coefficient.
- Check the answer in the original equation.
Worked example 1: 5x - 4 = 2x + 8
Subtract 2x from both sides to remove the variable term on the right.
5x - 4 = 2x + 8
5x - 2x - 4 = 8 subtract 2x from both sides
3x - 4 = 8 combine like terms
3x = 12 add 4 to both sides
x = 4 divide both sides by 3
Check: 5(4) - 4 = 16 and 2(4) + 8 = 16Both sides equal 16, so x = 4 is the solution.
Doing it in code
The two-step solver from the earlier chapters has a natural extension. If a1·x + b1 = a2·x + b2, subtract a2·x and b1 from both sides. This gives (a1 - a2)·x = b2 - b1, which has the form a·x = c.
from fractions import Fraction
def solve_both_sides(a1, b1, a2, b2):
"""Solve a1*x + b1 = a2*x + b2 by moving x terms to the left."""
a = Fraction(a1) - Fraction(a2)
c = Fraction(b2) - Fraction(b1)
if a == 0:
return "infinitely many solutions" if c == 0 else "no solution"
return c / a
x = solve_both_sides(5, -4, 2, 8) # 5x - 4 = 2x + 8
print(x) # 4
print(5 * x - 4 == 2 * x + 8) # TrueThe function uses Fraction so results such as 7/3 stay exact. A float would give 2.3333333333333335, and an equality check on it could fail because of rounding. The last line is the substitution check from an earlier chapter, applied to the original equation.
Worked example 2: parentheses first
When parentheses are present, simplify each side before you move any terms. Skipping this step is the most common source of mistakes.
3(x - 2) + 4 = 2x + 5
3x - 6 + 4 = 2x + 5 distribute
3x - 2 = 2x + 5 combine like terms
x - 2 = 5 subtract 2x from both sides
x = 7 add 2 to both sides
Check: 3(7 - 2) + 4 = 19 and 2(7) + 5 = 19Note the step from 3x - 2 = 2x + 5 to x - 2 = 5. Subtracting 2x from 3x leaves x, which has an implied coefficient of 1, so no division is needed at the end.
Choosing which side
Both choices produce the same solution, but one may involve less sign handling. Take 2x + 9 = 5x - 6.
| Choice | Steps | Coefficient before dividing |
|---|---|---|
| Move x terms left (subtract 5x) | -3x + 9 = -6, then -3x = -15 | -3 |
| Move x terms right (subtract 2x) | 9 = 3x - 6, then 15 = 3x | 3 |
Both end at x = 5. The second avoids dividing by a negative number, which is a common place for sign slips. A good habit is to subtract the smaller variable coefficient from both sides.
Negative coefficients
Dividing by a negative number is legal. It is a common source of slips, so write the division step out in full.
4 - 3x = 2x - 11
4 - 5x = -11 subtract 2x from both sides
-5x = -15 subtract 4 from both sides
x = 3 divide both sides by -5
Check: 4 - 3(3) = -5 and 2(3) - 11 = -5In the second line, 4 - 3x - 2x is 4 - 5x. The variable term keeps its sign when you subtract: -3x - 2x is -5x, not -x.
When the variable disappears
Sometimes subtracting the variable term from both sides removes it from the equation entirely. The coefficient of x is then 0, which is the a = 0 case from the general form ax + b = c. What is left is a statement about numbers only, and it is either true or false.
2(x + 3) = 2x + 6
2x + 6 = 2x + 6 distribute
6 = 6 subtract 2x from both sidesThe statement 6 = 6 is always true, so every real number is a solution. The equation is an identity.
3x + 1 = 3x + 5
1 = 5 subtract 3x from both sidesThe statement 1 = 5 is never true, so no value of x works. There is no solution. The next chapters treat these cases in full. For now, remember the signal: if the variable vanishes, read what remains.
print(solve_both_sides(2, 6, 2, 6)) # infinitely many solutions
print(solve_both_sides(3, 1, 3, 5)) # no solutionCommon errors
- Changing only one side. Subtracting 2x from the left and forgetting the right breaks the balance. Write the operation next to the line, as in the examples above.
- Sign slips when moving terms. Moving a term across the equals sign is shorthand for adding its opposite to both sides. Moving +2x gives -2x, and moving -3x gives +3x.
- Distributing incompletely. In 3(x - 2), the 3 multiplies both x and -2. The result is 3x - 6, not 3x - 2.
- Combining unlike terms. 3x - 2 cannot be reduced further. The x term and the constant are not like terms.
- Checking in a modified equation. Substitute into the original equation. A check on a line you already rearranged cannot catch an error made earlier.
Edge cases
- Variables with fractions. If coefficients are fractions, such as (1/2)x + 3 = (1/4)x + 5, you can still collect terms by subtracting (1/4)x. Clearing the denominators first, covered in the next chapter, often makes the arithmetic easier.
- A variable term that cancels partially. In x + 5 = 2x + 5, subtracting x gives 5 = x + 5, and then x = 0. A solution of zero is still a solution. It is not the same as "no solution".
- A constant on only one side. In 4x = x + 9, subtract x to get 3x = 9, so x = 3. There is no constant to move, so the step is skipped.
Exercises
Exercise
Solve 7x - 5 = 3x + 11, and check your answer in the original equation.
Show answer
Subtract 3x from both sides: 4x - 5 = 11. Add 5: 4x = 16. Divide by 4: x = 4. Check: 7(4) - 5 = 23 and 3(4) + 11 = 23, so x = 4 is correct.
Exercise
Solve 2(3x - 1) = 4x + 6.
Show answer
Distribute: 6x - 2 = 4x + 6. Subtract 4x: 2x - 2 = 6. Add 2: 2x = 8. Divide by 2: x = 4. Check: 2(12 - 1) = 22 and 4(4) + 6 = 22.
Exercise
Solve 9 - 2x = 5x - 5. Then say which side you moved the variable terms to and why.
Show answer
Adding 2x to both sides moves the variable terms to the right and keeps the coefficient positive: 9 = 7x - 5. Add 5: 14 = 7x. Divide by 7: x = 2. Check: 9 - 2(2) = 5 and 5(2) - 5 = 5.
Exercise
Decide whether each equation has one solution, no solution, or infinitely many solutions: (a) 4x + 2 = 4x - 3, (b) 3(x + 1) = 3x + 3, (c) 5x = 2x + 6.
Show answer
(a) Subtracting 4x gives 2 = -3, which is false, so there is no solution. (b) Distributing gives 3x + 3 = 3x + 3, and subtracting 3x gives 3 = 3, which is always true, so there are infinitely many solutions. (c) Subtracting 2x gives 3x = 6, so x = 2 is the single solution.
Exercise
Using solvebothsides, what are the four arguments for 6x + 1 = 2x + 9, and what does the function return?
Show answer
The arguments are a1 = 6, b1 = 1, a2 = 2, b2 = 9, so call solvebothsides(6, 1, 2, 9). It computes a = 6 - 2 = 4 and c = 9 - 1 = 8, and returns Fraction(2, 1), which prints as 2.