Sub topic 12
Checking Rearrangements with a Computer Algebra System
Prerequisites and purpose
Assume you can solve linear equations, work with fractions and exponents, and understand that a formula may have restrictions such as a nonzero denominator. A computer algebra system (CAS) is software that manipulates symbols and expressions. It can solve equations, simplify expressions, and compare two formulas.
A CAS is useful for checking algebra, especially when a variable appears on both sides or inside a fraction. It does not replace the reasoning. You still need to identify the target variable, state restrictions, and decide whether the result makes sense in the original problem.
Ask the CAS to solve
In Python, the SymPy library represents symbols and equations. The solve function returns values or expressions that satisfy an equation.
Consider:
a x + b = c x + d
Collecting the terms containing x gives:
(a - c)x = d - b
Therefore:
x = (d - b) / (a - c)
A CAS can confirm this rearrangement:
from sympy import symbols, Eq, solve
a, b, c, d, x = symbols("a b c d x")
equation = Eq(a * x + b, c * x + d)
result = solve(equation, x)
print(result)The result is usually displayed as:
[(b - d)/(c - a)]This is equivalent to (d - b)/(a - c), because multiplying both the numerator and denominator by -1 does not change a fraction.
The result requires a - c to be nonzero. If a = c, the equation becomes either inconsistent or true for every value of x:
- If
bandddiffer, no value of x works. - If
b = d, every value of x works.
The symbolic result alone does not always explain these cases.
Test equivalence by simplifying the difference
Suppose you have two possible rearrangements. To test whether they are equivalent, subtract one from the other and simplify. If the difference simplifies to zero, they are equal wherever both expressions are defined.
from sympy import symbols, simplify
a, b, c, d = symbols("a b c d")
manual = (d - b) / (a - c)
cas_form = (b - d) / (c - a)
print(simplify(manual - cas_form))The output is:
0This proves symbolic equivalence under the expressions' domain restrictions. It does not mean the expressions are defined when a = c or c = a.
Check the original equation
A stronger check substitutes the proposed result back into the original equation. For the general equation, use a candidate expression and simplify both sides.
from sympy import symbols, simplify
a, b, c, d, x = symbols("a b c d x")
candidate = (d - b) / (a - c)
left = a * candidate + b
right = c * candidate + d
print(simplify(left - right))The output is 0, provided a != c. This confirms that the candidate satisfies the original equation wherever it is valid.
The check is different from asking SymPy to solve the equation. Solving discovers a candidate. Substitution verifies that candidate against the equation you started with.
Powers and assumptions
When solving equations involving powers, a CAS may return several roots or may need assumptions. For example:
A = πr²
Algebraically, r = ±√(A/π). For a geometric radius, r is normally positive, so only the positive root is meaningful.
from sympy import symbols, Eq, solve, pi
A = symbols("A", positive=True)
r = symbols("r", positive=True)
solutions = solve(Eq(A, pi * r**2), r)
print(solutions)Declaring r positive tells SymPy to use the physical domain. Without that assumption, the negative root may also appear.
A practical checking process
Use this order:
- Rearrange the formula by hand and show the main algebraic steps.
- Ask the CAS to solve the original equation for the target.
- Simplify the difference between your result and the CAS result.
- Substitute your result into the original equation.
- State restrictions, such as nonzero denominators or positive lengths.
- Test a simple numerical case when possible.
Exercise
A formula is 1/R = 1/R1 + 1/R2. Use a CAS check to confirm that solving for R2 gives R2 = R*R1/(R1 - R). What restriction must be stated?
Show answer
The formula is valid when R1 - R is not zero. A SymPy check can solve the equation and simplify the difference between the returned expression and R*R1/(R1 - R).