Free variables and bound variables

In mathematics, and in other disciplines involving formal languages, including mathematical logic and computer science, a free variable is a notation (symbol) that specifies places in an expression where substitution may take place and is not a parameter of this or any container expression. Some older books use the terms real variable and apparent variable for free variable and bound variable, respectively. The idea is related to a placeholder (a symbol that will later be replaced by some value), or a wildcard character that stands for an unspecified symbol.

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.

A bound variable, in contrast, is a variable that 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 {\displaystyle n} n is a positive integer”.) Examples are given in the next section. However it is done, the variable ceases to be an independent variable on which the value of the expression depends, whether that value be a truth value or the numerical result of a calculation, or, more generally, an element of an image set of a function. Note that 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   ( x = y ) . {\displaystyle \forall y\,\exists x\,\left(x={\sqrt {y}}\right).} yx(x=y ).
This expression evaluates to false if the domain of x {\displaystyle x} x and y {\displaystyle y} 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.

1 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 = 1 10 f ( k , n ) , {\displaystyle \sum _{k=1}^{10}f(k,n),} k=110f(k,n),
n n n is a free variable and k k k is a bound variable; consequently the value of this expression depends on the value of n n n, but there is nothing called k k k on which it could depend.

In the expression
∫ 0 ∞ x y − 1 e − x   d x , {\displaystyle \int _{0}^{\infty }x^{y-1}e^{-x}\,dx,} 0xy1exdx,
y y y is a free variable and x x x is a bound variable; consequently the value of this expression depends on the value of y y y, but there is nothing called x x x on which it could depend.

In the expression
lim ⁡ h → 0 f ( x + h ) − f ( x ) h , {\displaystyle \lim _{h\rightarrow 0}{\frac {f(x+h)-f(x)}{h}},} h0limhf(x+h)f(x),
x x x is a free variable and h h h is a bound variable; consequently the value of this expression depends on the value of x x x, but there is nothing called h h h on which it could depend.

In the expression
∀ x   ∃ y   [ φ ( x , y , z ) ] , {\displaystyle \forall x\ \exists y\ {\Big [}\varphi (x,y,z){\Big ]},} x y [φ(x,y,z)],
z z z is a free variable and x x x and y y y are bound variables, associated with logical quantifiers; consequently the logical value of this expression depends on the value of z z z, but there is nothing called x x x or y y y on which it could depend.

More widely, in most proofs, bound variables are used. For example, the following proof shows that all squares of even integers are divisible by 4 {\displaystyle 4} 4

Let n {\displaystyle n} n be a positive even integer. Then there is an integer k {\displaystyle k} k such that n = 2 k {\displaystyle n=2k} n=2k . Since n 2 = 4 k 2 {\displaystyle n^{2}=4k^{2}} n2=4k2, we have n 2 {\displaystyle n^{2}} n2 divisible by 4 {\displaystyle 4} 4
not only k k k but also n n n have been used as bound variables as a whole in the proof.

1.1 Variable-binding operators


The following
∑ x ∈ S ∏ x ∈ S ∫ 0 ∞ ⋯   d x lim ⁡ x → 0 ∀ x ∃ x {\displaystyle \sum _{x\in S}\quad \quad \prod _{x\in S}\quad \quad \int _{0}^{\infty }\cdots \,dx\quad \quad \lim _{x\to 0}\quad \quad \forall x\quad \quad \exists x} xSxS0dxx0limxx
are some common variable-binding operators. Each of them binds the variable x x x for some set S S S.

Note that many of these are operators which act on functions of the bound variable. In more complicated contexts, such notations can become awkward and confusing. It can be useful to switch to notations which make the binding explicit, such as
∑ 1 , … , 10 ( k ↦ f ( k , n ) ) {\displaystyle \sum _{1,\ldots ,10}\left(k\mapsto f(k,n)\right)} 1,,10(kf(k,n))
for sums or
D ( x ↦ x 2 + 2 x + 1 ) {\displaystyle D\left(x\mapsto x^{2}+2x+1\right)} D(xx2+2x+1)
for differentiation.

2 Formal explanation


Variable-binding mechanisms occur in different contexts in mathematics, logic and computer science. In all cases, however, they are purely syntactic properties of expressions and variables in them. For this section we can summarize syntax by identifying an expression with a tree whose leaf nodes are variables, constants, function constants or predicate constants and whose non-leaf nodes are logical operators. This expression can then be determined by doing an inorder traversal of the tree. Variable-binding operators are logical operators that occur in almost every formal language. A binding operator Q Q Q takes two arguments: a variable v v v and an expression P P P, and when applied to its arguments produces a new expression Q ( v , P ) Q(v, P) Q(v,P). The meaning of binding operators is supplied by the semantics of the language and does not concern us here.

Variable binding relates three things: a variable v v v, a location a a a for that variable in an expression and a non-leaf node n n n of the form Q ( v , P ) Q(v, P) Q(v,P). Note: we define a location in an expression as a leaf node in the syntax tree. Variable binding occurs when that location is below the node n n n.

In the lambda calculus, x is a bound variable in the term M = λx. T and a free variable in the term T. We say x is bound in M and free in T. If T contains a subterm λx. U then x is rebound in this term. This nested, inner binding of x is said to “shadow” the outer binding. Occurrences of x in U are free occurrences of the new x.

Variables bound at the top level of a program are technically free variables within the terms to which they are bound but are often treated specially because they can be compiled as fixed addresses. Similarly, an identifier bound to a recursive function is also technically a free variable within its own body but is treated specially.

A closed term is one containing no free variables.

在这里插入图片描述

Tree summarizing the syntax of the expression ∀ x   ( ( ∃ y   A ( x ) ) ∨ B ( z ) ) {\displaystyle \forall x\,((\exists y\,A(x))\vee B(z))} x((yA(x))B(z))

2.1 Function expressions


To give an example from mathematics, consider an expression which defines a function
f = [ ( x 1 , … , x n ) ↦ t ] {\displaystyle f=\left[(x_{1},\ldots ,x_{n})\mapsto t\right]} f=[(x1,,xn)t]
where t t t is an expression. t t t may contain some, all or none of the x 1 , … , x n x_1, …, x_n x1,,xn and it may contain other variables. In this case we say that function definition binds the variables x 1 , … , x n x_1, …, x_n x1,,xn.

In this manner, function definition expressions of the kind shown above can be thought of as the variable binding operator, analogous to the lambda expressions of lambda calculus. Other binding operators, like the summation sign, can be thought of as higher-order functions applying to a function. So, for example, the expression
∑ x ∈ S x 2 {\displaystyle \sum _{x\in S}{x^{2}}} xSx2
could be treated as a notation for
∑ S ( x ↦ x 2 ) {\displaystyle \sum _{S}{(x\mapsto x^{2})}} S(xx2)
where ∑ S f {\displaystyle \sum _{S}{f}} Sf is an operator with two parameters—a one-parameter function, and a set to evaluate that function over. The other operators listed above can be expressed in similar ways; for example, the universal quantifier ∀ x ∈ S   P ( x ) {\displaystyle \forall x\in S\ P(x)} xS P(x) can be thought of as an operator that evaluates to the logical conjunction of the boolean-valued function P P P applied over the (possibly infinite) set S S S.

3 Natural language


When analyzed in formal semantics, natural languages can be seen to have free and bound variables. In English, personal pronouns like he, she, they, etc. can act as free variables.

Lisa found her book.

In the sentence above, the possessive pronoun her is a free variable. It may refer to the previously mentioned Lisa or to any other female. In other words, her book could be referring to Lisa’s book (an instance of coreference) or to a book that belongs to a different female (e.g. Jane’s book). Whoever the referent of her is can be established according to the situational (i.e. pragmatic) context. The identity of the referent can be shown using coindexing subscripts where i i i indicates one referent and j j j indicates a second referent (different from i i i). Thus, the sentence Lisa found her book has the following interpretations:

L i s a i Lisa_i Lisai found h e r i her_i heri book. (interpretation #1: her = of Lisa)
L i s a i Lisa_i Lisai found h e r j her_j herj book. (interpretation #2: her = of a female that is not Lisa)

The distinction is not purely of academic interest, as some languages do actually have different forms for h e r i her_i heri and h e r j her_j herj: for example, Norwegian and Swedish translate coreferent h e r i her_i heri as sin and noncoreferent h e r j her_j herj as hennes.

English does allow specifying coreference, but it is optional, as both interpretations of the previous example are valid (the ungrammatical interpretation is indicated with an asterisk):

L i s a i Lisa_i Lisai found h e r i her_i heri own book. (interpretation #1: her = of Lisa)
∗ L i s a i {}^*Lisa_i Lisai found h e r j her_j herj own book. (interpretation #2: her = of a female that is not Lisa)

However, reflexive pronouns, such as himself, herself, themselves, etc., and reciprocal pronouns, such as each other, act as bound variables. In a sentence like the following:

Jane hurt herself.

the reflexive herself can only refer to the previously mentioned antecedent, in this case Jane, and can never refer to a different female person. In this example, the variable herself is bound to the noun Jane that occurs in subject position. Indicating the coindexation, the first interpretation with Jane and herself coindexed is permissible, but the other interpretation where they are not coindexed is ungrammatical:

J a n e i Jane_i Janei hurt h e r s e l f i herself_i herselfi. (interpretation #1: herself = Jane)
∗ J a n e i {}^*Jane_i Janei hurt h e r s e l f j herself_j herselfj. (interpretation #2: herself = a female that is not Jane)

Note that the coreference binding can be represented using a lambda expression as mentioned in the previous Formal explanation section. The sentence with the reflexive could be represented as

(λx.x hurt x) Jane

in which Jane is the subject referent argument and λx.x hurt x is the predicate function (a lambda abstraction) with the lambda notation and x x x indicating both the semantic subject and the semantic object of sentence as being bound. This returns the semantic interpretation JANE hurt JANE with JANE being the same person.

Pronouns can also behave in a different way. In the sentence below

Ashley hit her.

the pronoun her can only refer to a female that is not Ashley. This means that it can never have a reflexive meaning equivalent to Ashley hit herself. The grammatical and ungrammatical interpretations are:

∗ A s h l e y i {}^*Ashley_i Ashleyi hit h e r i her_i heri. (interpretation #1: her = Ashley)
A s h l e y i Ashley_i Ashleyi hit h e r j her_j herj. (interpretation #2: her = a female that is not Ashley)

The first interpretation is impossible. Only the second interpretation is permitted by the grammar.

Thus, it can be seen that reflexives and reciprocals are bound variables (known technically as anaphors) while true pronouns are free variables in some grammatical structures but variables that cannot be bound in other grammatical structures. The binding phenomena found in natural languages was particularly important to the syntactic government and binding theory (see also: Binding (linguistics)).

4 See also


5 References

@Skip

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值