Use variables and equations to model program behaviour, then master arithmetic
and geometric progressions for indexed values, loop totals and growth patterns.
๐ฏ 1. Learning Objectives
After completing this topic, you should be able to:
Identify variables, constants, coefficients, expressions and equations.
Simplify expressions using the correct order of operations.
Solve linear equations, paired equations and basic inequalities.
Use exponents and roots in programming calculations.
Find any term and the sum of terms in an AP or GP.
Translate formulas into loop counts, array indices and growth models.
๐งฉ 2. Algebra Building Blocks
Variable
A symbol whose value can change.
x, y, count, index
Constant
A fixed value in an expression or program.
7 in 3x + 7
Coefficient
A number multiplying a variable.
3 is the coefficient of x in 3x
Equation
A statement that two expressions are equal.
3x + 7 = 25
๐งฎ 3. Simplifying Expressions
Combine only like terms, and always respect operator precedence.
4x + 3 + 2x โ 5 = 6x โ 2
1. Parentheses
2. Powers
3. ร and รท
4. + and โ
Programming connection: The expression
2 + 3 * 4 equals 14, while (2 + 3) * 4 equals 20.
โ๏ธ 4. Linear Equations
Apply the same inverse operation to both sides until the variable is isolated.
General Form
ax + b = c, a โ 0
x = (c โ b) / a
Example: 3x + 5 = 20
Subtract 5: 3x = 15
Divide by 3: x = 5
Verify: Substitute the answer back into the original equation.
Here, 3(5) + 5 = 20, so the solution is correct.
๐ 5. Two-Variable Equations and Inequalities
Simultaneous Equations
Two independent equations can determine two unknowns.
x + y = 10 x โ y = 2 x = 6, y = 4
Inequalities
Solve like an equation, but reverse the sign when multiplying or dividing by a negative number.
โ2x > 8 โ x < โ4
โก 6. Exponents and Roots
Rule
Meaning
Example
am ร an = am+n
Add exponents
2ยณ ร 2โด = 2โท = 128
am รท an = amโn
Subtract exponents
5โถ รท 5ยฒ = 5โด
(am)n = amn
Multiply exponents
(3ยฒ)ยณ = 3โถ
aโฐ = 1
Zero power
12โฐ = 1
โa = a1/2
Square root
โ81 = 9
๐ป 7. Algebra in Programming
Array Index Formula
The kth positive even number is calculated directly.
value = 2k
Loop Total
A loop running 1, 2, ..., n times performs:
n(n + 1) / 2 operations
Coordinate Mapping
A row and column can be mapped into one linear index.