In universal algebra and mathematical logic, a term algebra is a freely generated algebraic structure over a given signature.[1][2] For example, in a signature consisting of a single binary operation, the term algebra over a set X of variables is exactly the free magma generated by X. Other synonyms for the notion include absolutely free algebra and anarchic algebra.[3]

From a category theory perspective, a term algebra is the initial object for the category of all X-generated algebras of the same signature, and this object, unique up to isomorphism, is called an initial algebra; it generates by homomorphic projection all algebras in the category.[4][5]

A similar notion is that of a Herbrand universe in logic, usually used under this name in logic programming,[6] which is (absolutely freely) defined starting from the set of constants and function symbols in a set of clauses. That is, the Herbrand universe consists of all ground terms: terms that have no variables in them.

An atomic formula or atom is commonly defined as a predicate applied to a tuple of terms; a ground atom is then a predicate in which only ground terms appear. The Herbrand base is the set of all ground atoms that can be formed from predicate symbols in the original set of clauses and terms in its Herbrand universe.[7][8] These two concepts are named after Jacques Herbrand.

Term algebras also play a role in the semantics of abstract data types, where an abstract data type declaration provides the signature of a multi-sorted algebraic structure and the term algebra is a concrete model of the abstract declaration.

## Universal algebra

A type ${\displaystyle \tau }$ is a set of function symbols, with each having an associated arity (i.e. number of inputs). For any non-negative integer ${\displaystyle n}$, let ${\displaystyle \tau _{n))$ denote the function symbols in ${\displaystyle \tau }$ of arity ${\displaystyle n}$. A constant is a function symbol of arity 0.

Let ${\displaystyle \tau }$ be a type, and let ${\displaystyle X}$ be a non-empty set of symbols, representing the variable symbols. (For simplicity, assume ${\displaystyle X}$ and ${\displaystyle \tau }$ are disjoint.) Then the set of terms ${\displaystyle T(X)}$ of type ${\displaystyle \tau }$ over ${\displaystyle X}$ is the set of all well-formed strings that can be constructed using the variable symbols of ${\displaystyle X}$ and the constants and operations of ${\displaystyle \tau }$. Formally, ${\displaystyle T(X)}$ is the smallest set such that:

• ${\displaystyle X\cup \tau _{0}\subseteq T(X)}$   — each variable symbol from ${\displaystyle X}$ is a term in ${\displaystyle T(X)}$, and so is each constant symbol from ${\displaystyle \tau _{0))$.
• For all ${\displaystyle n\geq 1}$ and for all function symbols ${\displaystyle f\in \tau _{n))$ and terms ${\displaystyle t_{1},...,t_{n}\in T(X)}$, we have the string ${\displaystyle f(t_{1},...,t_{n})\in T(X)}$   — given ${\displaystyle n}$ terms ${\displaystyle t_{1},...,t_{n))$, the application of an ${\displaystyle n}$-ary function symbol ${\displaystyle f}$ to them represents again a term.

The term algebra ${\displaystyle {\mathcal {T))(X)}$ of type ${\displaystyle \tau }$ over ${\displaystyle X}$ is, in summary, the algebra of type ${\displaystyle \tau }$ that maps each expression to its string representation. Formally, ${\displaystyle {\mathcal {T))(X)}$ is defined as follows:[9]

• The domain of ${\displaystyle {\mathcal {T))(X)}$ is ${\displaystyle T(X)}$.
• For each nullary function ${\displaystyle f}$ in ${\displaystyle \tau _{0))$, ${\displaystyle f^((\mathcal {T))(X)}()}$ is defined as the string ${\displaystyle f}$.
• For all ${\displaystyle n\geq 1}$ and for each n-ary function ${\displaystyle f}$ in ${\displaystyle \tau }$ and elements ${\displaystyle t_{1},...,t_{n))$ in the domain, ${\displaystyle f^((\mathcal {T))(X)}(t_{1},...,t_{n})}$ is defined as the string ${\displaystyle f(t_{1},...,t_{n})}$.

A term algebra is called absolutely free because for any algebra ${\displaystyle {\mathcal {A))}$ of type ${\displaystyle \tau }$, and for any function ${\displaystyle g:X\to {\mathcal {A))}$, ${\displaystyle g}$ extends to a unique homomorphism ${\displaystyle g^{\ast }:{\mathcal {T))(X)\to {\mathcal {A))}$, which simply evaluates each term ${\displaystyle t\in {\mathcal {T))(X)}$ to its corresponding value ${\displaystyle g^{\ast }(t)\in {\mathcal {A))}$. Formally, for each ${\displaystyle t\in {\mathcal {T))(X)}$:

• If ${\displaystyle t\in X}$, then ${\displaystyle g^{\ast }(t)=g(t)}$.
• If ${\displaystyle t=f\in \tau _{0))$, then ${\displaystyle g^{\ast }(t)=f^{\mathcal {A))()}$.
• If ${\displaystyle t=f(t_{1},...,t_{n})}$ where ${\displaystyle f\in \tau _{n))$ and ${\displaystyle n\geq 1}$, then ${\displaystyle g^{\ast }(t)=f^{\mathcal {A))(g^{\ast }(t_{1}),...,g^{\ast }(t_{n}))}$.

## Example

As an example type inspired from integer arithmetic can be defined by ${\displaystyle \tau _{0}=\{0,1\))$, ${\displaystyle \tau _{1}=\{\))$, ${\displaystyle \tau _{2}=\{+,*\))$, and ${\displaystyle \tau _{i}=\{\))$ for each ${\displaystyle i>2}$.

The best-known algebra of type ${\displaystyle \tau }$ has the natural numbers as its domain and interprets ${\displaystyle 0}$, ${\displaystyle 1}$, ${\displaystyle +}$, and ${\displaystyle *}$ in the usual way; we refer to it as ${\displaystyle {\mathcal {A))_{nat))$.

For the example variable set ${\displaystyle X=\{x,y\))$, we are going to investigate the term algebra ${\displaystyle {\mathcal {T))(X)}$ of type ${\displaystyle \tau }$ over ${\displaystyle X}$.

First, the set ${\displaystyle T(X)}$ of terms of type ${\displaystyle \tau }$ over ${\displaystyle X}$ is considered. We use red color to flag its members, which otherwise may be hard to recognize due to their uncommon syntactic form. We have e.g.

• ${\displaystyle {\color {red}x}\in T(X)}$, since ${\displaystyle x\in X}$ is a variable symbol;
• ${\displaystyle {\color {red}1}\in T(X)}$, since ${\displaystyle 1\in \tau _{0))$ is a constant symbol; hence
• ${\displaystyle {\color {red}+x1}\in T(X)}$, since ${\displaystyle +}$ is a 2-ary function symbol; hence, in turn,
• ${\displaystyle {\color {red}*+x1x}\in T(X)}$ since ${\displaystyle *}$ is a 2-ary function symbol.

More generally, each string in ${\displaystyle T(X)}$ corresponds to a mathematical expression built from the admitted symbols and written in Polish prefix notation; for example, the term ${\displaystyle {\color {red}*+x1x))$ corresponds to the expression ${\displaystyle (x+1)*x}$ in usual infix notation. No parentheses are needed to avoid ambiguities in Polish notation; e.g. the infix expression ${\displaystyle x+(1*x)}$ corresponds to the term ${\displaystyle {\color {red}+x*1x))$.

To give some counter-examples, we have e.g.

• ${\displaystyle {\color {red}z}\not \in T(X)}$, since ${\displaystyle z}$ is neither an admitted variable symbol nor an admitted constant symbol;
• ${\displaystyle {\color {red}3}\not \in T(X)}$, for the same reason,
• ${\displaystyle {\color {red}+1}\not \in T(X)}$, since ${\displaystyle +}$ is a 2-ary function symbol, but is used here with only one argument term (viz. ${\displaystyle {\color {red}1))$).

Now that the term set ${\displaystyle T(X)}$ is established, we consider the term algebra ${\displaystyle {\mathcal {T))(X)}$ of type ${\displaystyle \tau }$ over ${\displaystyle X}$. This algebra uses ${\displaystyle T(X)}$ as its domain, on which addition and multiplication need to be defined. The addition function ${\displaystyle +^((\mathcal {T))(X)))$ takes two terms ${\displaystyle p}$ and ${\displaystyle q}$ and returns the term ${\displaystyle {\color {red}+}pq}$; similarly, the multiplication function ${\displaystyle *^((\mathcal {T))(X)))$ maps given terms ${\displaystyle p}$ and ${\displaystyle q}$ to the term ${\displaystyle {\color {red}*}pq}$. For example, ${\displaystyle *^((\mathcal {T))(X)}({\color {red}+x1},{\color {red}x})}$ evaluates to the term ${\displaystyle {\color {red}*+x1x))$. Informally, the operations ${\displaystyle +^((\mathcal {T))(X)))$ and ${\displaystyle *^((\mathcal {T))(X)))$ are both "sluggards" in that they just record what computation should be done, rather than doing it.

As an example for unique extendability of a homomorphism consider ${\displaystyle g:X\to {\mathcal {A))_{nat))$ defined by ${\displaystyle g(x)=7}$ and ${\displaystyle g(y)=3}$. Informally, ${\displaystyle g}$ defines an assignment of values to variable symbols, and once this is done, every term from ${\displaystyle T(X)}$ can be evaluated in a unique way in ${\displaystyle {\mathcal {A))_{nat))$. For example,

${\displaystyle {\begin{array}{lll}&g^{*}({\color {red}+x1})\\=&g^{*}({\color {red}x})+g^{*}({\color {red}1})&{\text{ since ))g^{*}{\text{ is a homomorphism ))\\=&g({\color {red}x})+g^{*}({\color {red}1})&{\text{ since ))g^{*}{\text{ coincides on ))X{\text{ with ))g\\=&7+g^{*}({\color {red}1})&{\text{ by definition of ))g\\=&7+1&{\text{ since ))g^{*}{\text{ is a homomorphism ))\\=&8&{\text{ according to the well-known arithmetical rules in )){\mathcal {A))_{nat}\\\end{array))}$

In a similar way, one obtains ${\displaystyle g^{*}({\color {red}*+x1x})=...=8*g({\color {red}x})=...=56}$.

## Herbrand base

 Main articles: Herbrand interpretation and Herbrand structure

The signature σ of a language is a triple <O, F, P> consisting of the alphabet of constants O, function symbols F, and predicates P. The Herbrand base[10] of a signature σ consists of all ground atoms of σ: of all formulas of the form R(t1, ..., tn), where t1, ..., tn are terms containing no variables (i.e. elements of the Herbrand universe) and R is an n-ary relation symbol (i.e. predicate). In the case of logic with equality, it also contains all equations of the form t1 = t2, where t1 and t2 contain no variables.

## Decidability

Term algebras can be shown decidable using quantifier elimination. The complexity of the decision problem is in NONELEMENTARY because binary constructors are injective and thus pairing functions.[11]

## References

1. ^ Wilfrid Hodges (1997). A Shorter Model Theory. Cambridge University Press. pp. 14. ISBN 0-521-58713-1.
2. ^ Franz Baader; Tobias Nipkow (1998). Term Rewriting and All That. Cambridge University Press. p. 49. ISBN 0-521-77920-0.
3. ^ Klaus Denecke; Shelly L. Wismath (2009). Universal Algebra and Coalgebra. World Scientific. pp. 21–23. ISBN 978-981-283-745-5.
4. ^ T.H. Tse (2010). A Unifying Framework for Structured Analysis and Design Models: An Approach Using Initial Algebra Semantics and Category Theory. Cambridge University Press. pp. 46–47. doi:10.1017/CBO9780511569890. ISBN 978-0-511-56989-0.
5. ^ Jean-Yves Béziau (1999). "The mathematical structure of logical syntax". In Carnielli, Walter Alexandre; D'Ottaviano, Itala M. L. (eds.). Advances in Contemporary Logic and Computer Science: Proceedings of the Eleventh Brazilian Conference on Mathematical Logic, May 6-10, 1996, Salvador, Bahia, Brazil. American Mathematical Society. p. 9. ISBN 978-0-8218-1364-5. Retrieved 18 April 2011.
6. ^ Dirk van Dalen (2004). Logic and Structure. Springer. p. 108. ISBN 978-3-540-20879-2.
7. ^ M. Ben-Ari (2001). Mathematical Logic for Computer Science. Springer. pp. 148–150. ISBN 978-1-85233-319-5.
8. ^ Monroe Newborn (2001). Automated Theorem Proving: Theory and Practice. Springer. p. 43. ISBN 978-0-387-95075-4.
9. ^ Stanley Burris; H. P. Sankappanavar (1981). A Course in Universal Algebra. Springer. pp. 68–69, 71. ISBN 978-1-4613-8132-7.((cite book)): CS1 maint: multiple names: authors list (link)
10. ^ Rogelio Davila. Answer Set Programming Overview.
11. ^ Jeanne Ferrante; Charles W. Rackoff (1979). The Computational Complexity of Logical Theories. Springer, Chapter 8, Theorem 1.2.