# Allen's interval algebra

Allen's interval algebra is a calculus for temporal reasoning that was introduced by James F. Allen in 1983.
The calculus defines possible relations between time intervals and provides a composition table that can be used as a basis for reasoning about temporal descriptions of events.

## Formal description
### Relations

The following 13 base relations capture the possible relations between two intervals.
| Relation | Interpretation |
| $X\,{\mathrel {\mathbf {<} }}\,Y$ $Y\,{\mathrel {\mathbf {>} }}\,X$ | X precedes Y Y is preceded by X |
| $X\,{\mathrel {\mathbf {m} }}\,Y$ $Y\,{\mathrel {\mathbf {mi} }}\,X$ | X meets Y Y is met by X (i stands for inverse) |
| $X\,{\mathrel {\mathbf {o} }}\,Y$ $Y\,{\mathrel {\mathbf {oi} }}\,X$ | X overlaps with Y Y is overlapped by X |
| $X\,{\mathrel {\mathbf {s} }}\,Y$ $Y\,{\mathrel {\mathbf {si} }}\,X$ | X starts Y Y is started by X |
| $X\,{\mathrel {\mathbf {d} }}\,Y$ $Y\,{\mathrel {\mathbf {di} }}\,X$ | X during Y Y contains X |
| $X\,{\mathrel {\mathbf {f} }}\,Y$ $Y\,{\mathrel {\mathbf {fi} }}\,X$ | X finishes Y Y is finished by X |
| $X\,{\mathrel {\mathbf {=} }}\,Y$ | X is equal to Y |
To see that the 13 relations are exhaustive, note that each point of $X$ can be at 5 possible locations relative to $Y$: before, at the start, within, at the end, after. These give $5+4+3+2+1=15$ possible relative positions for the start and the end of $X$. Of these, we cannot have $X_{0}=X_{1}=Y_{0}$ since $X_{0}<X_{1}$, and similarly we cannot have $X_{0}=X_{1}=Y_{1}$, thus giving us 13 possible relations.
In general, the number of different relations between n intervals, starting with n = 0, is 1, 1, 13, 409, 23917, 2244361... OEIS A055203. The special case shown above is for n = 2.

### Composition of relations between intervals

For reasoning about the relations between temporal intervals, Allen's interval algebra provides a composition table. Given the relation between $X$ and $Y$ and the relation between $Y$ and $Z$, the composition table allows for concluding about the relation between $X$ and $Z$. Together with a converse operation, this turns Allen's interval algebra into a relation algebra.
Using this calculus, given facts can be formalized and then used for automatic reasoning. Relations between intervals are formalized as sets of base relations.
The sentences
    During dinner, Peter reads the newspaper. Afterwards, he goes to bed.
are formalized in Allen's Interval Algebra as follows:
${\mbox{newspaper }}\mathbf {\{\operatorname {d} \}} {\mbox{ dinner}}$
${\mbox{dinner }}\mathbf {\{\operatorname {<} \}} {\mbox{ bed}}$
For the example, one can infer ${\mbox{newspaper }}\mathbf {\{\operatorname {<} \}} {\mbox{ bed}}$.

## Extensions

Allen's interval algebra can be used for the description of both temporal intervals and spatial configurations. For the latter use, the relations are interpreted as describing the relative position of spatial objects. This also works for three-dimensional objects by listing the relation for each coordinate separately.
The study of overlapping markup uses a similar algebra (see). Its models have more variations depending on whether endpoints of document structures are permitted to be truly co-located, or merely [tangent].

## Temporal primitives

In the cultural heritage ontology CIDOC CRM, Allen relations are replaced by so-called temporal primitives, which facilitate the formulation of attestable statements as well as reasoning about these statements. Temporal primitives split up the Allen relations into individual statements about the start or end of the intervals. For example, X overlaps with Y ($X\mathbf {\operatorname {o} } Y$) can be split as follows:
* $X\mathbf {\operatorname {o} } Y$ ⇔ starts before the start of ($X$,$Y$) ∧ ends after the start of ($X$,$Y$) ∧ ends before the end of ($X$,$Y$)
In addition, the equal to of the Allen relations is replaced by before or with and after or with. A simple example:
* The reign of King Harold II starts before the start of the Battle of Hastings
* The reign/life of Harold II ends after or with the start of the Battle of Hastings
* The reign/life of Harold II ends before or with the end of the Battle of Hastings
In the example, it is not necessary to specify whether Harold II was killed at the beginning or during or at the end of the battle, i.e. whether $X\mathbf {\operatorname {m} } Y$, $X\mathbf {\operatorname {o} } Y$ or $X\mathbf {\operatorname {fi} } Y$ applies (disjunctions such as $\mathbf {\{\operatorname {m} ,\operatorname {o} ,\operatorname {fi} \}}$ cannot be expressed in CIDOC CRM, except in queries). If it is relevant for a particular historical question, it can be specified later by adding e.g. ends after the start of.
CIDOC CRM distinguishes between events and their corresponding time intervals. Allen relations and temporal primitives are statements between events and only as a consequence between their time intervals. Another difference is that temporal, spatial and spatiotemporal entities in CIDOC CRM are seen as having fuzzy borders. Especially statements about exact simultaneity are otherwise extremely rare.

## Implementations

* A simple java library implementing the concept of Allen's temporal relations and the path consistency algorithm
* Java library implementing Allen's Interval Algebra (incl. data and index structures, e.g., interval tree)
* OWL-Time Time Ontology in OWL an OWL-2 DL ontology of temporal concepts, for describing the temporal properties of resources in the world or described in Web pages.
* GQR is a reasoner for Allen's interval algebra (and many others)
* qualreas is a Python framework for qualitative reasoning over networks of relation algebras, such as RCC-8, Allen's interval algebra, and Allen's algebra integrated with Time Points and situated in either Left- or Right-Branching Time.
* SparQ is a reasoner for Allen's interval algebra (and many others)
* EveXL is a small domain-specific language for the detection of events that implements the Interval Algebra's operators via ASCII art patterns.