In mathematical logic and computer science, the Kleene star (or Kleene operator or Kleene closure) is a unary operation, either on sets of strings or on sets of symbols or characters. In mathematics, it is more commonly known as the free monoid construction. The application of the Kleene star to a set is written as . It is widely used for regular expressions, which is the context in which it was introduced by Stephen Kleene to characterize certain automata, where it means "zero or more repetitions".
The set can also be described as the set containing the empty string and all finite-length strings that can be generated by concatenating arbitrary elements of , allowing the use of the same element multiple times. If is either the empty set ∅ or the singleton set , then ; if is any other finite set or countably infinite set, then is a countably infinite set.^{[1]} As a consequence, each formal language over a finite or countably infinite alphabet is countable, since it is a subset of the countably infinite set .
The operators are used in rewrite rules for generative grammars.
Given a set , define
and define recursively the set
If is a formal language, then , the -th power of the set , is a shorthand for the concatenation of set with itself times. That is, can be understood to be the set of all strings that can be represented as the concatenation of strings in .
The definition of Kleene star on is^{[2]}
This means that the Kleene star operator is an idempotent unary operator: for any set of strings or characters, as for every .
In some formal language studies, (e.g. AFL theory) a variation on the Kleene star operation called the Kleene plus is used. The Kleene plus omits the term in the above union. In other words, the Kleene plus on is
or
Example of Kleene star applied to set of strings:
Example of Kleene plus applied to set of characters:
Kleene star applied to the same character set:
Example of Kleene star applied to the empty set:
Example of Kleene plus applied to the empty set:
where concatenation is an associative and noncommutative product.
Example of Kleene plus and Kleene star applied to the singleton set containing the empty string:
Strings form a monoid with concatenation as the binary operation and ε the identity element. The Kleene star is defined for any monoid, not just strings. More precisely, let (M, ⋅) be a monoid, and S ⊆ M. Then S^{*} is the smallest submonoid of M containing S; that is, S^{*} contains the neutral element of M, the set S, and is such that if x,y ∈ S^{*}, then x⋅y ∈ S^{*}.
Furthermore, the Kleene star is generalized by including the *-operation (and the union) in the algebraic structure itself by the notion of complete star semiring.^{[4]}
The Kleene closure L^{*} of L is defined to be .