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 , a finance app adds interest with , a chart scales data with .
- 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 <= widthis an inequality;abs(a - b) < 1e-9is an absolute-value inequality. Both have their own lessons here.
# 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 . A ride cost €15.50. How long was it?
Answer
10 km
Solution
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
: 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 . 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 for : . With that is 18.5, and since months are whole, round up to 19.
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?
- The W3Schools Python tutorial
- Debra Anne Ross's Master Math: Algebra
- A random order
- The calculus course
A sprite moves by . Which question needs you to rearrange the formula?
- Where is it after 2 s?
- Where is it at ?
- When does it reach ?
- Where is it after 5 s?
The condition 0 <= x <= width in code is an example of:
- An equation
- A compound inequality
- A polynomial
- A system of equations