Inmathematical logic, aterm is an arrangement of dependent/bound symbols that denotes amathematical object within an expression/formula. In particular, terms appear as components of a formula. This is analogous to natural language, where anoun phrase refers to an object and a wholesentence refers to a fact.
Afirst-order term isrecursively constructed from constant symbols,variable symbols, andfunction symbols.An expression formed by applying apredicate symbol to an appropriate number of terms is called anatomic formula, which evaluates totrue orfalse inbivalent logics, given aninterpretation.For example, is a term built from the constant 1, the variablex, and the binary function symbols and; it is part of the atomic formula which evaluates to true for eachreal-numbered value ofx.
Besides inlogic, terms play important roles inuniversal algebra, andrewriting systems.

Given a setV of variable symbols, a setC of constant symbols and setsFn ofn-ary function symbols, also called operator symbols, for each natural numbern ≥ 1, the set of (unsorted first-order) termsT isrecursively defined to be the smallest set with the following properties:[1]
Using an intuitive, pseudo-grammatical notation, this is sometimes written as:
Thesignature of the term language describes which function symbol setsFn are inhabited. Well-known examples are the unary function symbolssin,cos ∈F1, and the binary function symbols +, −, ⋅, / ∈F2.Ternary operations and higher-arity functions are possible but uncommon in practice. Many authors consider constant symbols as 0-ary function symbolsF0, thus needing no special syntactic class for them.
A term denotes a mathematical object from thedomain of discourse. A constantc denotes a named object from that domain, a variablex ranges over the objects in that domain, and ann-ary functionf mapsn-tuples of objects to objects. For example, ifn ∈V is a variable symbol, 1 ∈C is a constant symbol, andadd ∈F2 is a binary function symbol, thenn ∈T, 1 ∈T, and (hence)add(n, 1) ∈T by the first, second, and third term building rule, respectively. The latter term is usually written asn+1, usinginfix notation and the more common operator symbol + for convenience.
Originally, logicians defined a term to be acharacter string adhering to certain building rules.[2] However, since the concept oftree became popular in computer science, it turned out to be more convenient to think of a term as a tree. For example, several distinct character strings, like "(n⋅(n+1))/2", "((n⋅(n+1)))/2", and "", denote the same term and correspond to the same tree, viz. the left tree in the above picture.Separating the tree structure of a term from its graphical representation on paper, it is also easy to account for parentheses (being only representation, not structure) and invisible multiplication operators (existing only in structure, not in representation).
Two terms are said to bestructurally,literally, orsyntactically equal if they correspond to the same tree. For example, the left and the right tree in the above picture are structurallyunequal terms, although they might be considered "semantically equal" as they always evaluate to the same value inrational arithmetic. While structural equality can be checked without any knowledge about the meaning of the symbols, semantic equality cannot. If the function / is e.g. interpreted not as rational but astruncating integer division, then atn=2 the left and right term evaluates to 3 and 2, respectively.Structurally equal terms need to agree in their variable names.
In contrast, a termt is called arenaming, or avariant, of a termu if the latter resulted from consistently renaming all variables of the former, i.e. ifu =tσ for somerenaming substitution σ. In that case,u is a renaming oft, too, since a renaming substitution σ has an inverse σ−1, andt = uσ−1. Both terms are then also said to beequal modulo renaming. In many contexts, the particular variable names in a term don't matter, e.g. the commutativity axiom for addition can be stated asx+y=y+x or asa+b=b+a; in such cases the whole formula may be renamed, while an arbitrary subterm usually may not, e.g.x+y=b+a is not a valid version of the commutativity axiom.[note 1][note 2]
The set of variables of a termt is denoted byvars(t).A term that doesn't contain any variables is called aground term; a term that doesn't contain multiple occurrences of a variable is called alinear term.For example, 2+2 is a ground term and hence also a linear term,x⋅(n+1) is a linear term,n⋅(n+1) is a non-linear term. These properties are important in, for example,term rewriting.
Given asignature for the function symbols, the set of all terms forms thefreeterm algebra. The set of all ground terms forms theinitial term algebra.
Abbreviating the number of constants asf0, and the number ofi-ary function symbols asfi, the number θh of distinct ground terms of a height up toh can be computed by the following recursion formula:
Given a setRn ofn-ary relation symbols for each natural numbern ≥ 1, an (unsorted first-order) atomic formula is obtained by applying ann-ary relation symbol ton terms. As for function symbols, a relation symbol setRn is usually non-empty only for smalln. In mathematical logic, more complexformulas are built from atomic formulas usinglogical connectives andquantifiers. For example, letting denote the set ofreal numbers, ∀x:x ∈ ⇒ (x+1)⋅(x+1) ≥ 0 is a mathematical formula evaluating to true in the algebra ofcomplex numbers.An atomic formula is called ground if it is built entirely from ground terms; all ground atomic formulas composable from a given set of function and predicate symbols make up theHerbrand base for these symbol sets.

When the domain of discourse contains elements of basically different kinds, it is useful to split the set of all terms accordingly. To this end, asort (sometimes also calledtype) is assigned to each variable and each constant symbol, and a declaration[note 3] of domain sorts and range sort to each function symbol. Asorted termf(t1,...,tn) may be composed from sorted subtermst1,...,tn only if theith subterm's sort matches the declaredith domain sort off. Such a term is also calledwell-sorted; any other term (i.e. obeying theunsorted rules only) is calledill-sorted.
For example, avector space comes with an associatedfield of scalar numbers. LetW andN denote the sort of vectors and numbers, respectively, letVW andVN be the set of vector and number variables, respectively, andCW andCN the set of vector and number constants, respectively. Then e.g. and0 ∈CN, and the vector addition, the scalar multiplication, and the inner product is declared as, and, respectively. Assuming variable symbols anda,b ∈VN, the term is well-sorted, while is not (since + doesn't accept a term of sortN as 2nd argument). In order to make a well-sorted term, an additional declaration is required. Function symbols having several declarations are calledoverloaded.
Seemany-sorted logic for more information, including extensions of themany-sorted framework described here.
| Notation example | Bound variables | Free variables | Written as lambda-term |
|---|---|---|---|
| limn→∞x/n | n | x | limit(λn.div(x,n)) |
| i | n | sum(1,n,λi.power(i,2)) | |
| t | a,b,k | integral(a,b,λt.sin(k⋅t)) |
Mathematical notations as shown in the table do not fit into the scheme of a first-order term as definedabove, as they all introduce an ownlocal, orbound, variable that may not appear outside the notation's scope, e.g. doesn't make sense. In contrast, the other variables, referred to asfree, behave like ordinary first-order term variables, e.g. does make sense.
All these operators can be viewed as taking a function rather than a value term as one of their arguments. For example, thelim operator is applied to a sequence, i.e. to a mapping from positive integer to e.g. real numbers. As another example, aC function to implement the second example from the table, Σ, would have a function pointer argument (see box below).
Lambda terms can be used to denoteanonymous functions to be supplied as arguments tolim, Σ, ∫, etc.
For example, the functionsquare from the C program below can be written anonymously as a lambda term λi.i2. The general sum operator Σ can then be considered as a ternary function symbol taking a lower bound value, an upper bound value and a function to be summed-up. Due to its latter argument, the Σ operator is called asecond-order function symbol.As another example, the lambda term λn.x/n denotes a function that maps 1, 2, 3, ... tox/1,x/2,x/3, ..., respectively, that is, it denotes thesequence (x/1,x/2,x/3, ...). Thelim operator takes such a sequence and returns its limit (if defined).
The rightmost column of the table indicates how each mathematical notation example can be represented by a lambda term, also converting commoninfix operators intoprefix form.
intsum(intlwb,intupb,intfct(int)){// implements general sum operatorintres=0;for(inti=lwb;i<=upb;++i)res+=fct(i);returnres;}intsquare(inti){returni*i;}// implements anonymous function (lambda i. i*i); however, C requires a name for it#include<stdio.h>intmain(void){intn;scanf(" %d",&n);printf("%d\n",sum(1,n,square));// applies sum operator to sum up squaresreturn0;}
This sectionneeds expansion. You can help byadding missing information.(April 2021) |
Given a setV of variable symbols, the set of lambda terms is defined recursively as follows:
The above motivating examples also used some constants likediv,power, etc. which are, however, not admitted in pure lambda calculus.
Intuitively, the abstraction λx.t denotes a unary function that returnst when givenx, while the application (t1t2 ) denotes the result of calling the functiont1 with the inputt2. For example, the abstraction λx.x denotes the identity function, while λx.y denotes the constant function always returningy. The lambda term λx.(xx) takes a functionx and returns the result of applyingx to itself.