# Kleene algebra

{{#invoke:Hatnote|hatnote}}

In mathematics, a **Kleene algebra** (Template:IPAc-en Template:Respell; named after Stephen Cole Kleene) is an idempotent (and thus partially ordered) semiring endowed with a closure operator.^{[1]} It generalizes the operations known from regular expressions.

## Definition

Various inequivalent definitions of Kleene algebras and related structures have been given in the literature.^{[2]} Here we will give the definition that seems to be the most common nowadays.

A Kleene algebra is a set *A* together with two binary operations + : *A* × *A* → *A* and · : *A* × *A* → *A* and one function ^{*} : *A* → *A*, written as *a* + *b*, *ab* and *a*^{*} respectively, so that the following axioms are satisfied.

- Associativity of + and ·:
*a*+ (*b*+*c*) = (*a*+*b*) +*c*and*a*(*bc*) = (*ab*)*c*for all*a*,*b*,*c*in*A*. - Commutativity of +:
*a*+*b*=*b*+*a*for all*a*,*b*in*A* - Distributivity:
*a*(*b*+*c*) = (*ab*) + (*ac*) and (*b*+*c*)*a*= (*ba*) + (*ca*) for all*a*,*b*,*c*in*A* - Identity elements for + and ·: There exists an element 0 in
*A*such that for all*a*in*A*:*a*+ 0 = 0 +*a*=*a*. There exists an element 1 in*A*such that for all*a*in*A*:*a*1 = 1*a*=*a*. *a*0 = 0*a*= 0 for all*a*in*A*.

The above axioms define a semiring. We further require:

- + is idempotent:
*a*+*a*=*a*for all*a*in*A*.

It is now possible to define a partial order ≤ on *A* by setting *a* ≤ *b* if and only if *a* + *b* = *b* (or equivalently: *a* ≤ *b* if and only if there exists an *x* in *A* such that *a* + *x* = *b*; with any definition, *a* ≤ *b* ≤ *a* implies *a* = *b*). With this order we can formulate the last two axioms about the operation ^{*}:

- 1 +
*a*(*a*^{*}) ≤*a*^{*}for all*a*in*A*. - 1 + (
*a*^{*})*a*≤*a*^{*}for all*a*in*A*. - if
*a*and*x*are in*A*such that*ax*≤*x*, then*a*^{*}*x*≤*x* - if
*a*and*x*are in*A*such that*xa*≤*x*, then*x*(*a*^{*}) ≤*x*^{[3]}

Intuitively, one should think of *a* + *b* as the "union" or the "least upper bound" of *a* and *b* and of *ab* as some multiplication which is monotonic, in the sense that *a* ≤ *b* implies *ax* ≤ *bx*. The idea behind the star operator is *a*^{*} = 1 + *a* + *aa* + *aaa* + ... From the standpoint of programming language theory, one may also interpret + as "choice", · as "sequencing" and ^{*} as "iteration".

## Examples

Kleene algebras and | + | · | ^{*} |
0 | 1 |
---|---|---|---|---|---|

Regular expressions | | | not written | ^{*} |
∅ | ε |

Let Σ be a finite set (an "alphabet") and let *A* be the set of all regular expressions over Σ. We consider two such regular expressions equal if they describe the same language. Then *A* forms a Kleene algebra. In fact, this is a free Kleene algebra in the sense that any equation among regular expressions follows from the Kleene algebra axioms and is therefore valid in every Kleene algebra.

Again let Σ be an alphabet. Let *A* be the set of all regular languages over Σ (or the set of all context-free languages over Σ; or the set of all recursive languages over Σ; or the set of *all* languages over Σ). Then the union (written as +) and the concatenation (written as ·) of two elements of *A* again belong to *A*, and so does the Kleene star operation applied to any element of *A*. We obtain a Kleene algebra *A* with 0 being the empty set and 1 being the set that only contains the empty string.

Let *M* be a monoid with identity element *e* and let *A* be the set of all subsets of *M*. For two such subsets *S* and *T*, let *S* + *T* be the union of *S* and *T* and set *ST* = {*st* : *s* in *S* and *t* in *T*}. *S*^{*} is defined as the submonoid of *M* generated by *S*, which can be described as {*e*} ∪ *S* ∪ *SS* ∪ *SSS* ∪ ... Then *A* forms a Kleene algebra with 0 being the empty set and 1 being {*e*}. An analogous construction can be performed for any small category.

Suppose *M* is a set and *A* is the set of all binary relations on *M*. Taking + to be the union, · to be the composition and ^{*} to be the reflexive transitive closure, we obtain a Kleene algebra.

Every Boolean algebra with operations and turns into a Kleene algebra if we use for +, for · and set *a*^{*} = 1 for all *a*.

A quite different Kleene algebra can be used to implement the Floyd–Warshall algorithm, computing the shortest path's length for every two vertices of a weighted directed graph, by Kleene's algorithm, computing a regular expression for every two states of a deterministic finite automaton.
Using the extended real number line, take *a* + *b* to be the minimum of *a* and *b* and *ab* to be the ordinary sum of *a* and *b* (with the sum of +∞ and −∞ being defined as +∞). *a*^{*} is defined to be the real number zero for nonnegative *a* and −∞ for negative *a*. This is a Kleene algebra with zero element +∞ and one element the real number zero.
A weighted directed graph can then be considered as a deterministic finite automaton, with each transition labelled by its weight.
For any two graph nodes (automaton states), the regular expressions computed from Kleene's algorithm evaluates, in this particular Kleene algebra, to the shortest path length between the nodes.^{[4]}

## Properties

Zero is the smallest element: 0 ≤ *a* for all *a* in *A*.

The sum *a* + *b* is the least upper bound of *a* and *b*: we have *a* ≤ *a* + *b* and *b* ≤ *a* + *b* and if *x* is an element of *A* with *a* ≤ *x* and *b* ≤ *x*, then *a* + *b* ≤ *x*. Similarly, *a*_{1} + ... + *a*_{n} is the least upper bound of the elements *a*_{1}, ..., *a*_{n}.

Multiplication and addition are monotonic: if *a* ≤ *b*, then

*a*+*x*≤*b*+*x*,*ax*≤*bx*, and*xa*≤*xb*

for all *x* in *A*.

Regarding the star operation, we have

- 0
^{*}= 1 and 1^{*}= 1, *a*≤*b*implies*a*^{*}≤*b*^{*}(monotonicity),*a*^{n}≤*a*^{*}for every natural number*n*, where*a*^{n}is defined as*n*-fold multiplication of*a*,- (
*a*^{*})(*a*^{*}) =*a*^{*}, - (
*a*^{*})^{*}=*a*^{*}, - 1 +
*a*(*a*^{*}) =*a*^{*}= 1 + (*a*^{*})*a*, *a*≤*b*^{*}if and only if*a*^{*}≤*b*^{*},*ax*=*xb*implies (*a*^{*})*x*=*x*(*b*^{*}),- ((
*ab*)^{*})*a*=*a*((*ba*)^{*}), - (
*a*+*b*)^{*}=*a*^{*}(*b*(*a*^{*}))^{*}, and *pq*= 1 =*qp*implies*q*(*a*^{*})*p*= (*qap*)^{*}.^{[5]}

If *A* is a Kleene algebra and *n* is a natural number, then one can consider the set M_{n}(*A*) consisting of all *n*-by-*n* matrices with entries in *A*.
Using the ordinary notions of matrix addition and multiplication, one can define a unique ^{*}-operation so that M_{n}(*A*) becomes a Kleene algebra.

## History

Kleene introduced regular expressions and gave some of their algebraical laws.^{[6]}^{[7]}
Although he didn't define Kleene algebras, he asked for a decision procedure for equivalence of regular expressions.^{[8]}
Redko proved that no finite set of axioms can characterize the algebra of regular languages.^{[9]}
Salomaa gave complete axiomatizations of this algebra, however depending on problematic inference rules.^{[10]}
The problem of providing a complete set of axioms, which would allow derivation of all equations among regular expressions, was intensively studied by John Horton Conway under the name of *regular algebras*,^{[11]} however, the bulk of his treatment was infinitary.
In 1981, Kozen gave a complete infinitary equational deductive system for the algebra of regular languages.^{[12]}
In 1994, he gave the above finite axiom system, which uses unconditional and conditional equalities,^{[13]} and is complete for the algebra of regular languages. Two regular expressions *a* and *b* denote the same language if *a*=*b* follows from the above axioms.^{[14]}

## Generalization (or relation to other structures)

Kleene algebras are a particular case of closed semirings, also called quasi-regular semirings or Lehmann semirings, which are semirings in which every element has at least one quasi-inverse satisfying the equation: a* = aa* + 1 = a*a + 1. This quasi-inverse is not necessarily unique.^{[15]}^{[16]} In a Kleene algebra, a* is the least solution to the fixpoint equations: X = aX + 1 and X = Xa + 1.^{[16]}

Closed semirings and Kleene algebras appear in algebraic path problems, a generalization of the shortest path problem.^{[16]}

## See also

## Notes and references

- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }}
- ↑ For a survey, see: {{#invoke:citation/CS1|citation |CitationClass=book }}
- ↑ Kozen (1990), sect.2.1, p.3
- ↑ {{#invoke:citation/CS1|citation |CitationClass=citation }}.
- ↑ Kozen (1990), sect.2.1.2, p.5
- ↑ Template:Cite techreport Here: sect.7.2, p.52
- ↑ {{#invoke:Citation/CS1|citation |CitationClass=journal }} Here: sect.7.2, p.26-27
- ↑ Kleene (1956), p.35
- ↑ {{#invoke:Citation/CS1|citation |CitationClass=journal }} (In Russian)
- ↑ {{#invoke:Citation/CS1|citation |CitationClass=journal }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }} Chap.IV.
- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }}
- ↑ considering
*a*≤*b*as an abbreviation for*a*+*b*=*b* - ↑ {{#invoke:Citation/CS1|citation |CitationClass=journal }} — An earlier version appeared as: Template:Cite techreport
- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }}
- ↑
^{16.0}^{16.1}^{16.2}{{#invoke:citation/CS1|citation |CitationClass=book }}

## Further reading

- {{#invoke:citation/CS1|citation

|CitationClass=book }} The introduction of this book reviews advances in the field of Kleene algebra made in the last 20 years, which are not discussed in the article above.