Definition
A variable is a symbol used within a formal system to stand for an unspecified or varying value. In logic, a variable like x ranges over a domain of objects and takes on different values depending on how it is interpreted or quantified. In mathematics, a variable can denote an unknown to be solved for, a placeholder in a function, or a quantity that changes within an equation. In programming, a variable is a named binding to a value that can be read, updated, and reused. Across all three settings the core idea is the same: a name is detached from any single value so that general patterns can be expressed and reasoned about.
The notion of a variable was already implicit in Aristotle's syllogistic — terms like S and P functioned as placeholders for arbitrary subjects and predicates — but it became fully explicit only with the rise of algebra in the medieval Islamic world and the modern symbolic logic developed by Frege, Peano, and Russell. Without variables, logic and mathematics would remain locked into specific cases; with them, they become engines of generality.
Why it matters
How it works
In predicate logic, a variable is the placeholder a quantifier binds. The formula "for all x, F of x" binds the variable x: within the scope of the quantifier, x does not refer to any particular object but ranges over the domain of discourse. A variable not bound by any quantifier is free, and the formula containing it expresses an open statement rather than a complete proposition — its truth value depends on what the free variable is taken to refer to. The distinction matters because logical inference rules are sensitive to it: universal instantiation, for example, only applies to variables that are currently bound, and substituting for a free variable can change a formula's meaning.
In mathematics and programming the same bound-versus-free pattern reappears under different names. The integration variable in a definite integral is bound by the integral sign just as a quantified variable is bound by a quantifier — and similarly, the loop counter in a for-loop is bound by the loop construct. A function's formal parameter is a bound variable that takes on whatever value the caller supplies as an argument. The variable's scope — the region of the program or formula in which the binding holds — is the operational version of the logical notion of a quantifier's scope. Across all three settings, careful attention to scope and binding is the discipline that separates working formal reasoning from confusion.