# Term indexing

In computer science, a term index is a data structure to facilitate fast lookup of terms and clauses in a logic program,[1] deductive database, or automated theorem prover.

## Overview

Many operations in automatic theorem provers require search in huge collections of terms and clauses. Such operations typically fall into the following scheme. Given a collection ${\displaystyle S}$ of terms (clauses) and a query term (clause) ${\displaystyle q}$, find in ${\displaystyle S}$ some/all terms ${\displaystyle t}$ related to ${\displaystyle q}$ according to a certain retrieval condition. Most interesting retrieval conditions are formulated as existence of a substitution that relates in a special way the query and the retrieved objects ${\displaystyle t}$. Here is a list of retrieval conditions frequently used in provers:

• term ${\displaystyle q}$ is unifiable with term ${\displaystyle t}$, i.e., there exists a substitution ${\displaystyle \theta }$, such that ${\displaystyle q\theta }$ = ${\displaystyle t\theta }$
• term ${\displaystyle t}$ is an instance of ${\displaystyle q}$, i.e., there exists a substitution ${\displaystyle \theta }$, such that ${\displaystyle q\theta }$ = ${\displaystyle t}$
• term ${\displaystyle t}$ is a generalisation of ${\displaystyle q}$, i.e., there exists a substitution ${\displaystyle \theta }$, such that ${\displaystyle q}$ = ${\displaystyle t\theta }$
• clause ${\displaystyle q}$ subsumes clause ${\displaystyle t}$, i.e., there exists a substitution ${\displaystyle \theta }$, such that ${\displaystyle q\theta }$ is a subset/submultiset of ${\displaystyle t}$
• clause ${\displaystyle q}$ is subsumed by ${\displaystyle t}$, i.e., there exists a substitution ${\displaystyle \theta }$, such that ${\displaystyle t\theta }$ is a subset/submultiset of ${\displaystyle q}$

More often than not, we are actually interested in finding the appropriate substitutions explicitly, together with the retrieved terms ${\displaystyle t}$, rather than just in establishing existence of such substitutions.

Very often the sizes of term sets to be searched are large, the retrieval calls are frequent and the retrieval condition test is rather complex. In such situations linear search in ${\displaystyle S}$, when the retrieval condition is tested on every term from ${\displaystyle S}$, becomes prohibitively costly. To overcome this problem, special data structures, called indexes, are designed in order to support fast retrieval. Such data structures, together with the accompanying algorithms for index maintenance and retrieval, are called term indexing techniques.

## Classic indexing techniques

Substitution trees outperform path indexing, discrimination tree indexing, and abstraction trees.[2]

A discrimination tree term index stores its information in a trie data structure.[3]

## References

1. ^ Colomb, Robert M. (1991). "Enhancing unification in PROLOG through clause indexing". The Journal of Logic Programming. 10: 23–44. doi:10.1016/0743-1066(91)90004-9.
2. ^ Peter Graf. "Substitution Tree Indexing". 1994.
3. ^ John W. Wheeler; Guarionex Jordan. "An Empirical Study of Term Indexing in the Darwin Implementation of the Model Evolution Calculus". 2004. p. 5.