TExcelTAD
Home › Algebra › Algebra Intro

Algebra Intro

Algebra is arithmetic with names in it: instead of working only with fixed numbers, you write rules with letters that stand for any number, and then you rearrange those rules to find the values you do not know yet. This course covers high-school Algebra I and II and checks every step with Python and SymPy, with programmers in mind throughout.

Why programmers use algebra constantly

Every program that computes something is full of algebra, even if nobody calls it that.

  • Variables. price * quantity * (1 + tax_rate) is an algebraic expression. The code works for any price, which is exactly what a letter in algebra does.
  • Formulas. A game moves a sprite with x=x0+v⋅tx = x_0 + v \cdot t, a finance app adds interest with A=P(1+r)nA = P(1 + r)^n, a chart scales data with pixel=(value−min)/(max−min)⋅height\text{pixel} = (\text{value} - \text{min}) / (\text{max} - \text{min}) \cdot \text{height}.
  • Solving for an unknown. The interesting questions usually run backwards. When does the sprite reach the wall? How many months until the savings hit €10 000? Which data value sits at pixel 120? Each answer comes from turning a formula around, which is what this course teaches.
  • Conditions. if 0 <= x <= width is an inequality; abs(a - b) < 1e-9 is an absolute-value inequality. Both have their own lessons here.
python · try it yourself
# one formula, three questions
def position(x0, v, t):
    return x0 + v * t

print(position(10, 4, 3))        # where is it after 3 s?
# when does it reach x = 50?  50 = 10 + 4t  ->  t = (50 - 10) / 4
print((50 - 10) / 4)
# what speed reaches x = 50 in 5 s?  50 = 10 + 5v  ->  v = (50 - 10) / 5
print((50 - 10) / 5)
22
10.0
8.0

The first line only evaluates the formula. The other two answer questions the formula does not answer directly: you rearrange it first, then evaluate. That rearranging is algebra.

What is in the course

The order of the main chapters follows Debra Anne Ross's Master Math: Algebra, used only as the reference for the order of topics; all explanations, examples and exercises here are original.

Section What you learn
Getting Started this page and Algebra with SymPy
Translating Problems into Algebraic Equations what algebra is, turning English into equations, the vocabulary, word problems
Simplifying Algebraic Expressions the commutative, associative and distributive properties, like terms, parentheses, order of operations
Solving Simple Equations one-unknown equations, fractions, radicals, solving formulas for a variable
Inequalities and Absolute Value solving inequalities, compound inequalities, absolute value equations and inequalities
Polynomials definitions, the four operations, factoring, special products
Algebraic Fractions reducing, multiplying, dividing, adding, rational equations
Quadratic Equations factoring, the quadratic formula, square roots, completing the square, the discriminant and complex roots
Systems of Linear Equations elimination, substitution, determinants and the matrix method for two and three unknowns
Coordinate Systems and Graphing lines, slope, line equations, parabolas, solving by graphing
Exponents and Logarithms in Algebra rational exponents, exponential and logarithmic equations
Algebra in Computing solving in code, collision timing, trend lines, game balancing, fast polynomial evaluation
Practice exercises and a mini project

Literal equations, compound and absolute-value inequalities, special factoring, rational equations, complex roots, line equations, exponent and log equations, and the computing section go beyond the book to fill standard Algebra I and II topics.

Before you start

This course assumes the arithmetic from Basic Math & Pre-Algebra: signed numbers, fractions, exponents and square roots. Its "Toward Algebra" lessons, Variables and Expressions and Solving Equations, are a gentle first look at what starts here. A little Python helps, but each example is short and explained.

Tip: Solve each worked example on paper before you run the code. The code is there to check you, not to replace you.

Learning paths

Your goal Suggested path
School math up to university Basic Math → Algebra → Pre-Calculus → Calculus Essentials → Calculus in Depth
Game developer Algebra (equations, quadratics, systems, graphing, Algebra in Computing) → Pre-Calculus → Math for Games → Game Physics
Data and machine learning Algebra (linear equations, systems, trend lines) → Linear Algebra → Statistics → Machine Learning
Quick refresher skim each section, do the quizzes and the per-lesson exercises, then the exercises page

Systems of equations lead straight into Gaussian elimination, and functions and graphs lead into functions in calculus.

Exercises

Exercise 1: Run it backwards

A taxi charges €3.50 to start plus €1.20 per km, so cost=3.5+1.2⋅km\text{cost} = 3.5 + 1.2 \cdot \text{km}. A ride cost €15.50. How long was it?

Answer

10 km

Solution
3.5+1.2⋅km=15.51.2⋅km=12subtract 3.5km=10divide by 1.2\begin{aligned} 3.5 + 1.2 \cdot \text{km} &= 15.5 \\ 1.2 \cdot \text{km} &= 12 && \text{subtract 3.5} \\ \text{km} &= 10 && \text{divide by 1.2} \end{aligned}

Exercise 2: Spot the algebra

Which part of the line if abs(measured - target) < 0.01: is an algebraic inequality, and what does it mean in words?

Answer

∣measured−target∣<0.01\lvert \text{measured} - \text{target} \rvert < 0.01: the measurement lies within 0.01 of the target.

Solution

abs is the absolute value, the distance between two numbers on the number line. The condition says that the distance between measured and target is less than 0.01, which is the same as target−0.01<measured<target+0.01\text{target} - 0.01 < \text{measured} < \text{target} + 0.01. The lesson Absolute Value Equations and Inequalities shows this rewrite.

Exercise 3: A savings goal in code

You save €40 a month and already have €260. Write a function months_to(goal) that returns how many whole months it takes to reach goal, using algebra rather than a loop. Check it with goal = 1000.

Answer

19 months (after 18 months you have €980, after 19 you have €1020).

Solution

Solve 260+40m≥goal260 + 40m \ge \text{goal} for mm: m≥(goal−260)/40m \ge (\text{goal} - 260) / 40. With goal=1000\text{goal} = 1000 that is 18.5, and since months are whole, round up to 19.

python · try it yourself
import math

def months_to(goal):
    return math.ceil((goal - 260) / 40)

m = months_to(1000)
print(m, 260 + 40 * (m - 1), 260 + 40 * m)
19 980 1020

Test yourself

Which reference sets the order of this course's main chapters?

  1. The W3Schools Python tutorial
  2. Debra Anne Ross's Master Math: Algebra
  3. A random order
  4. The calculus course

A sprite moves by x=10+4tx = 10 + 4t. Which question needs you to rearrange the formula?

  1. Where is it after 2 s?
  2. Where is it at t=0t = 0?
  3. When does it reach x=30x = 30?
  4. Where is it after 5 s?

The condition 0 <= x <= width in code is an example of:

  1. An equation
  2. A compound inequality
  3. A polynomial
  4. A system of equations