Kleene star
Template:Short description Template:Use dmy dates In formal language theory, the Kleene star (or Kleene operator or Kleene closure) refer to two related unary operations, that can be applied either to an alphabet of symbols or to a formal language, a set of strings (finite sequences of symbols).
The Kleene star operator on an alphabet Template:Mvar generates the set Template:Mvar of all finite-length strings over Template:Mvar,<ref group="note" name="strings"/> that is, finite sequences whose elements belong to Template:Mvar; in mathematics, it is more commonly known as the free monoid construction. The Kleene star operator on a language Template:Mvar generates another language Template:Mvar, the set of all strings that can be obtained as a concatenation of zero or more members of Template:Mvar. In both cases, repetitions are allowed.
The Kleene star operators are named after American mathematician Stephen Cole Kleene, who first introduced and widely used it to characterize automata for regular expressions.
Of an alphabet
Given an alphabet <math>V</math>, define
- <math>V^{0}=\{\varepsilon\}</math> (the set consists only of the empty string),
- <math>V^{1}=V,</math>
and define recursively the set
- <math>V^{i+1}=\{wv: w\in V^{i} \text{ and } v\in V \}</math> for each <math>i>0,</math>
where <math>wv</math> denotes the string obtained by appending the single character <math>v</math> to the end of <math>w</math>. Here, <math>V^i</math> can be understood to be the set of all strings of length exactly <math>i</math>, with characters from <math>V</math>.
The definition of Kleene star on <math>V</math> is<ref name=nayuki/>
- <math> V^*=\bigcup_{i \ge 0 }V^i = V^0 \cup V^1 \cup V^2 \cup V^3 \cup V^4 \cup \cdots.</math>
Of a language
Given a language <math>L</math> (any finite or infinite set of strings), define
- <math>L^{0}=\{\varepsilon\}</math> (the language consisting only of the empty string),
- <math>L^{1}=L,</math>
and define recursively the set
- <math>L^{i+1}=\{wv: w\in L^{i} \text{ and } v\in L \}</math> for each <math>i>0,</math>
where <math>wv</math> denotes the string obtained by concatenating <math>w</math> and <math>v</math>. Here, <math>L^i</math> can be understood to be the set of all strings that can be obtained by concatenating exactly <math>i</math> strings from <math>L</math>, allowing repetitions.
The definition of Kleene star on <math>L</math> is<ref>Template:Cite book</ref>
- <math> L^*=\bigcup_{i \ge 0 }L^i = L^0 \cup L^1 \cup L^2 \cup L^3 \cup L^4 \cup \cdots.</math>
Kleene plus
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 <math>V^{0}</math> or <math>L^0</math> term in the above unions. In other words, the Kleene plus on <math>V</math> is
- <math>V^+=\bigcup_{i \geq 1} V^i = V^1 \cup V^2 \cup V^3 \cup \cdots,</math>
or
- <math>V^+ = V^*V.</math><ref group="note" name="kleene-plus"/>
Examples
Example of Kleene star applied to a set of strings:
- {"ab","c"}* = { ε, "ab", "c", "abab", "abc", "cab", "cc", "ababab", "ababc", "abcab", "abcc", "cabab", "cabc", "ccab", "ccc", ...}.
Example of Kleene star applied to a set of strings without the prefix property:
- {"a","ab","b"}* = { ε, "a", "ab", "b", "aa", "aab", "aba", "abab", "abb", "ba", "bab", "bb", ...};
In this example, the string "aab" can be obtained in two different ways. The Sardinas-Patterson algorithm can be used to check for a given V whether any member of V* can be obtained in more than one way.
Example of Kleene and Kleene plus applied to a set of characters (following the C programming language convention where a character is denoted by single quotes and a string is denoted by double quotes):
- {'a', 'b', 'c'}* = { ε, "a", "b", "c", "aa", "ab", "ac", "ba", "bb", "bc", "ca", "cb", "cc", "aaa", "aab", ...}.
- {'a', 'b', 'c'}+ = { "a", "b", "c", "aa", "ab", "ac", "ba", "bb", "bc", "ca", "cb", "cc", "aaa", "aab", ...}.
Properties
- If <math>V</math> is any finite or countably infinite set of characters, then <math>V^*</math> is a countably infinite set.<ref name=nayuki>Template:Cite web</ref> As a result, each formal language over a finite or countably infinite alphabet <math>\Sigma</math> is countable, since it is a subset of the countably infinite set <math>\Sigma^{*}</math>.
- <math>(L^{*})^{*}=L^{*}</math>, which means that the Kleene star operator is an idempotent unary operator, as <math>(L^{*})^{i}=L^{*}</math> for every <math>i\geq 1</math>.
- <math>V^{*}=\{\varepsilon\}</math>, if <math>V</math> is the empty set ∅. For the version of the Kleene star operator on languages, <math>L^{*}=\{\varepsilon\}</math> when <math>L</math> is either the empty set ∅ or the singleton set <math>\{\varepsilon\}</math>.
Generalization
Strings form a monoid with concatenation as the binary operation and ε the identity element. In addition to strings, the Kleene star is defined for any monoid. 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.<ref name="droste">Template:Cite book</ref>