Before you start

  • You are comfortable with arithmetic and sets — sets.

What you will be able to do after this lesson:

  1. Explain what a variable is and what it is not.
  2. Distinguish a variable from a constant and from a parameter.
  3. Substitute values into an expression correctly.
  4. Explain how a mathematical variable differs from a programming variable.

Study route: read the lesson, then attempt every problem before opening the answers.


Now things get interesting.

Suppose I tell you:

I have some number, but I don’t know what it is.

We could call it (x).

So:

That (x) is a variable.

For example:

means:

“Take whatever value (x) represents and add 5.”

If:

then:

If:

then:

The variable is therefore a symbol representing a value.


Practice — problems

Attempt all of these before opening the answers.

  1. Evaluate at .
  2. Evaluate at . What happens at , and what is the rule being violated?
  3. Name the role of each symbol in : which is a variable, which a constant, and which depends on which?
  4. The key difference. In maths, has no solution. In most programming languages it is a perfectly ordinary statement. Explain what = means in each case.
  5. Write an expression for “a number is three more than twice another”, naming your variables explicitly.
Answers — open only after an attempt
  1. At : . At : . At : .
  2. . At the denominator is zero and the expression is undefined — division by zero is not a value, not even infinity.
  3. is a constant; is the independent variable; is the dependent variable, determined by .
  4. In mathematics = asserts that two things are equal, so claims a number equals its own successor, which is false for every . In most programming languages = is assignment — “compute the right side, store it in the left” — which is an instruction, not a claim. Languages that use = for equality (or ==, or := for assignment) are trying to keep these apart.
  5. Let be the first number and the second: .

Before moving on

You are done with this lesson when you can, closed-book:

  • Say what a variable is without saying ‘a letter’.
  • Distinguish variable, constant, parameter, independent and dependent.
  • Substitute values correctly, including spotting an undefined result.
  • Explain the difference between mathematical equality and programming assignment.

Recap: A variable is a name for a quantity that may vary or is not yet known — not merely a letter. Constants hold fixed values, parameters are held fixed within a problem but vary between problems, and dependent variables are determined by independent ones. The most consequential distinction for a programmer is that mathematical = asserts equality while programming = usually commands assignment, which is why is false in one and routine in the other.

Next: Equations — once you can name an unknown, the next question is how to find it.

↑ Back to Mathematics