Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 68 · Getting Started

The Algebra Toolkit for Calculus

Refresh factoring, exponent and logarithm rules and key trig identities, then use sympy simplify, expand, factor and solve to check algebra and avoid slips.

Most mistakes in calculus are not calculus mistakes. A derivative or limit is usually correct in idea and wrong in the algebra around it: a sign that flipped, a square root that lost its second branch, an exponent that was added instead of multiplied. This lesson collects the algebra you will use constantly, and shows how sympy can check each step.

Treat sympy as a proofreader, not a crutch. Do the algebra yourself, then ask the machine whether you agree. Where you disagree, the machine is right far more often, but the habit of checking is what matters.

Factoring and expanding

Factoring rewrites a sum as a product; expanding does the reverse. Factoring matters because products reveal zeros and let you cancel terms, which resolves many limits. Patterns to know by heart:

  • Difference of squares: a**2 - b**2 = (a - b)(a + b)
  • Perfect squares: a**2 + 2ab + b**2 = (a + b)**2
  • Difference of cubes: a**3 - b**3 = (a - b)(a**2 + ab + b**2)
  • Quadratics: x**2 + bx + c factors if you find two numbers that multiply to c and add to b.
Python Factor and expand with sympy

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The output shows (x - 3)*(x + 3), (x + 2)*(x + 3), (x - 2)*(x**2 + 2*x + 4), then the expanded cubic and x**4 - 1. Notice that the last product is a chain of difference-of-squares steps.

Exponent rules

For positive a and any real m, n:

Rule Example
a**m * a**n = a**(m+n) 2**3 * 2**4 = 2**7
a**m / a**n = a**(m-n) x**5 / x**2 = x**3
(a**m)**n = a**(m*n) (x**2)**3 = x**6
a**(-n) = 1 / a**n x**(-2) = 1/x**2
a**(1/n) = n-th root of a x**(1/2) = sqrt(x)

Rewriting roots and reciprocals as powers is the single most useful algebra move in calculus, because the power rule for derivatives then handles them all: 1/sqrt(x) becomes x**(-1/2).

The classic slips: (a + b)**2 is not a**2 + b**2, and sqrt(a + b) is not sqrt(a) + sqrt(b).

Logarithms

The logarithm answers "what exponent gives this number?" So log_b(y) = x means b**x = y. The natural logarithm ln uses base e, about 2.71828, and is the one calculus prefers. In Python, math.log and sympy.log are natural logs; log10 and log2 are separate.

The rules mirror the exponent rules:

  • ln(a*b) = ln(a) + ln(b)
  • ln(a/b) = ln(a) - ln(b)
  • ln(a**n) = n * ln(a)
  • ln(1) = 0, ln(e) = 1, and e**(ln x) = x for x > 0.

The argument must be positive, so ln(x**2) equals 2*ln|x|, not 2*ln(x), when x can be negative.

Python Exponents and logs together

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Taking logs turns the unknown exponent into a multiplier: 2**t = 40 gives t = ln(40)/ln(2), about 5.32.

Trigonometry you must know

Angles in calculus are measured in radians, never degrees: pi radians is 180 degrees. Derivatives of sine and cosine are only clean in radians.

Key identities:

  • sin(x)**2 + cos(x)**2 = 1
  • tan(x) = sin(x)/cos(x)
  • sin(2x) = 2 sin(x) cos(x)
  • cos(2x) = cos(x)**2 - sin(x)**2 = 1 - 2 sin(x)**2 = 2 cos(x)**2 - 1
  • sin(x + y) = sin x cos y + cos x sin y
  • cos(x + y) = cos x cos y - sin x sin y

The double-angle forms rearrange into power-reducing formulas: sin(x)**2 = (1 - cos(2x))/2 and cos(x)**2 = (1 + cos(2x))/2. These are indispensable for integrating squares of sine and cosine.

flowchart TD
    A["sin²x + cos²x = 1"] --> B["divide by cos²x:<br/>tan²x + 1 = sec²x"]
    A --> C["divide by sin²x:<br/>1 + cot²x = csc²x"]
    D["cos 2x = cos²x - sin²x"] --> E["sin²x = (1 - cos 2x)/2"]
    D --> F["cos²x = (1 + cos 2x)/2"]
    A --> D

One identity generates the others: divide it, or combine it with the double-angle formula.

Python Check identities and degrees versus radians

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

math.sin(30) is about -0.988 because 30 is interpreted as 30 radians. The value you wanted, one half, appears when you convert from degrees first.

Solving equations

sympy.solve finds exact solutions. It is the quickest way to find zeros of a function, which you will do constantly when locating peaks and valleys.

Python Solve, simplify and sanity-check

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The simplified form x + 1 hides an important fact: the original expression is undefined at x = 1. The two functions agree everywhere except that one point, and noticing that gap is the heart of limits.

Common algebra slips

  • Distributing a negative: -(x - 3) = -x + 3, not -x - 3.
  • Cancelling terms instead of factors: (x + 4)/4 is not x + 1. Only common factors cancel.
  • Squaring a sum: (x + 3)**2 = x**2 + 6x + 9.
  • Dropping the second root: x**2 = 9 gives x = 3 and x = -3.
  • Dividing by zero silently: dividing both sides by x loses the solution x = 0.

When in doubt, substitute a number. If x = 2 makes your before and after expressions differ, one of them is wrong. That ten-second test catches most slips; you will see a longer list in Common Mistakes in Calculus.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. Which expression equals x**2 - 16?

    Difference of squares: a2 - b2 = (a - b)(a + b), with a = x and b = 4.
  2. 2. Which rewrite of 1/sqrt(x) is useful before differentiating?

    The square root is a power of 1/2 and the reciprocal flips the sign, giving x**(-1/2). The power rule then applies directly.
  3. 3. What is ln(a**3 * b) in terms of ln(a) and ln(b)?

    The product rule turns the product into a sum, and the power rule brings the exponent 3 down in front of ln(a).
  4. 4. Why is math.sin(30) about -0.988 rather than 0.5?

    Python trig functions use radians. To get sin of 30 degrees, convert with math.radians(30) first.

Summary

  • Factor to find zeros and cancel; expand to compare forms. Learn the difference of squares and perfect squares.
  • Rewrite roots and reciprocals as powers so the power rule applies.
  • Logarithm rules turn products into sums and powers into multipliers; ln needs positive arguments.
  • Work in radians; keep the Pythagorean and double-angle identities at hand.
  • Use sympy.simplify, expand, factor and solve to check your algebra, and test slips with a quick number substitution.

Next: Limits: The Core Idea.