Lably
Skip to content

Free variables and bound variables

Concept in mathematics or computer science

  • 13 min read
  • 3 chapters

Related on Lably

Through Mathematics, Mathematical logic and Computer science

In computer programming, the term free variable refers to variables used in a function that are neither local variables nor parameters of that function. The term non-local variable is often a synonym in this context.

An instance of a variable symbol is bound, in contrast, if the value of that variable symbol has been bound to a specific value or range of values in the domain of discourse or universe. This may be achieved through the use of logical quantifiers, variable-binding operators, or an explicit statement of allowed values for the variable (such as, "...where n is a positive integer".)

Since the same variable symbol may appear in multiple places in an expression, some occurrences of the variable symbol may be free while others are bound, hence "free" and "bound" are at first defined for occurrences and then generalized over all occurrences of said variable symbol in the expression. A variable symbol overall is free if at least one occurrence of it is free.

While the domain of discourse in many contexts is understood, when an explicit range of values for the bound variable has not been given, it may be necessary to specify the domain in order to properly evaluate the expression. For example, consider the following expression in which both variables are bound by logical quantifiers:

∀y∃x(x2=y)

This expression evaluates to false if the domain of x and y is the real numbers, but true if the domain is the complex numbers.

The term "dummy variable" is also sometimes used for a bound variable (more commonly in general mathematics than in computer science), but this should not be confused with the identically named but unrelated concept of dummy variable as used in statistics, most commonly in regression analysis.p.17

Examples

Before stating a precise definition of free variable and bound variable, the following are some examples that perhaps make these two concepts clearer than the definition would:

  • In the expression:
∑k=110f(k,n),
n is a free variable and k is a bound variable; consequently the value of this expression depends on the value of n, but there is nothing called k on which it could depend.
  • In the expression:
∫0∞xy−1e−xdx,
y is a free variable and x is a bound variable; consequently the value of this expression depends on the value of y, but there is nothing called x on which it could depend.
  • In the expression:
limh→0f(x+h)−f(x)h,
x is a free variable and h is a bound variable; consequently the value of this expression depends on the value of x, but there is nothing called h on which it could depend.
  • In the expression:
∀x∃y[φ(x,y,z)],
z is a free variable and x and y are bound variables, associated with logical quantifiers; consequently the logical value of this expression depends on the value of z, but there is nothing called x or y on which it could depend.

In proofs

In a broader context, bound variables are fundamental to the structure of mathematical proofs. For example, the following proof shows that the square of any positive even integer is divisible by 4:

Let n be an arbitrary positive even integer. By definition, there exists an integer k such that n=2k. Substituting this into the expression for the square gives n2=(2k)2=4k2. Since k is an integer, k2 is also an integer. Therefore, n2 is divisible by 4.

In this proof, both n and k function as bound variables, but they are bound in different ways.

The variable n is introduced as an arbitrary but particular element of a set. The statement "Let n be..." implicitly functions as a universal quantifier, binding n for the scope of the proof. The proof establishes a property for this single, arbitrary n, which licenses the general conclusion that the property holds for all positive even integers.

The variable k, on the other hand, is bound by an existential quantifier ("there exists an integer k"). It is introduced to represent a specific, though unnamed, integer whose existence is guaranteed by the definition of n being even. The scope of k is limited to the reasoning that follows its introduction.

Thus, neither variable is free; their meaning is entirely determined by their role within the logical structure of the proof.

Variable-binding operators

In mathematics and logic, a number of symbols function as variable-binding operators. These operators take a function or an open formula as an argument and bind a free variable within that expression to a specific domain or range of values, creating a new expression whose meaning does not depend on the bound variable.

Common variable-binding operators include:

  • The summation (Σ) and product (Π) operators, which bind a variable over a set or range of values.
∑x∈Sf(x)∏x∈Sf(x)
  • The integral (∫) and limit (lim) operators, which bind a variable over a continuum or as it approaches a certain value.
∫abf(x)dxlimx→cf(x)
∀x,P(x)∃x,P(x)

In each case, the variable x is bound within the expression that follows the operator (e.g., f(x) or P(x)). Many of these operators act on a function of the bound variable. While standard notation is often sufficient, complex expressions with nested operators can become ambiguous, particularly if the same variable name is reused. This can lead to a problem known as variable capture, where a variable intended to be free is incorrectly bound by an operator in a different scope.

To avoid such ambiguity, it can be useful to switch to a notation that makes the binding explicit, treating the operators as higher-order functions. This approach, rooted in the principles of lambda calculus, clearly separates the function being operated on from the operator itself.

For example:

  • The summation ∑k=110f(k,n) can be written to make the functional argument explicit:
∑{1,…,10}(k↦f(k,n))

Here, the operator ∑Sf applies to the set S and the function f.

  • The derivative operator can also be represented clearly as taking a function as its argument:
D(x↦x2+2x+1)

This notation clarifies that the operator D is applied to the entire function x↦x2+2x+1, rather than just an expression in which x happens to be a variable.

Sign in to keep reading

2 more chapters are free with a Lably account.

More in Foundations