Languages are sets, so we can take unions and intersections. Two further operations are special to languages: the product (concatenate a string from one language with a string from another) and the star (concatenate any number of strings from a language). These two operations are exactly what regular expressions are built from.
Definition 2.4 · Product of languages
The product of languages S S S and T T T is S T = { s t ∣ s ∈ S , t ∈ T } ST = \{st \mid s \in S,\ t \in T\} S T = { s t ∣ s ∈ S , t ∈ T } : every string of S S S followed by every string of T T T , in that order.
Example 2.5 Products of two small languages
Goal. Compute S T ST S T for S = { a , a a , a a a } S = \{a, aa, aaa\} S = { a , aa , aaa } , T = { b b , b b b } T = \{bb, bbb\} T = { bb , bbb } , and for S = { a , b b , b a b } S = \{a, bb, bab\} S = { a , bb , bab } , T = { λ , b b b b } T = \{\lambda, bbbb\} T = { λ , bbbb } .
Step. First pair: each of 3 strings of S S S with each of 2 strings of T T T : S T = { a b b , a b b b , a a b b , a a b b b , a a a b b , a a a b b b } ST = \{abb, abbb, aabb, aabbb, aaabb, aaabbb\} S T = { abb , abbb , aabb , aabbb , aaabb , aaabbb } — 6 strings.
Step. Second pair: with t = λ t = \lambda t = λ we get S S S itself: a , b b , b a b a, bb, bab a , bb , bab .
Step. With t = b b b b t = bbbb t = bbbb : a b b b b , b b b b b b , b a b b b b b abbbb, bbbbbb, babbbbb abbbb , bbbbbb , babbbbb .
Result. { a , a a , a a a } { b b , b b b } \{a, aa, aaa\}\{bb, bbb\} { a , aa , aaa } { bb , bbb } has 6 strings; { a , b b , b a b } { λ , b b b b } = { a , b b , b a b , a b b b b , b b b b b b , b a b b b b b } \{a, bb, bab\}\{\lambda, bbbb\} = \{a, bb, bab, abbbb, bbbbbb, babbbbb\} { a , bb , bab } { λ , bbbb } = { a , bb , bab , abbbb , bbbbbb , babbbbb } .
Kleene star and positive closure
Definition 2.6 · Kleene closure and positive closure
For a language S S S , the Kleene closure (Kleene star) S ∗ S^* S ∗ is the set of all strings formed by concatenating zero or more strings of S S S (any string may be reused); it always contains λ \lambda λ . The positive closure S + S^+ S + is the set of strings formed by concatenating one or more strings of S S S . In symbols, S ∗ = { λ } ∪ S ∪ S S ∪ S S S ∪ … S^* = \{\lambda\} \cup S \cup SS \cup SSS \cup \dots S ∗ = { λ } ∪ S ∪ S S ∪ S S S ∪ … and S + = S ∪ S S ∪ S S S ∪ … S^+ = S \cup SS \cup SSS \cup \dots S + = S ∪ S S ∪ S S S ∪ …
For an alphabet, Σ ∗ \Sigma^* Σ ∗ is the set of all strings over Σ \Sigma Σ : if Σ = { 0 , 1 } \Sigma = \{0, 1\} Σ = { 0 , 1 } , then Σ ∗ = { λ , 0 , 1 , 00 , 01 , 10 , 11 , 000 , … } \Sigma^* = \{\lambda, 0, 1, 00, 01, 10, 11, 000, \dots\} Σ ∗ = { λ , 0 , 1 , 00 , 01 , 10 , 11 , 000 , … } . Every language over Σ \Sigma Σ is a subset of Σ ∗ \Sigma^* Σ ∗ .
Intuition
S ∗ S^* S ∗ is like building words from a box of fridge-magnet pieces. If the pieces are “cc” and “d”, you can make λ \lambda λ (use nothing), d d d , c c cc cc , c c d ccd cc d , d c c dcc d cc , c c c c d ccccd cccc d , … — but never c c c ccc ccc , because “c” only comes in pairs.
Example 2.7 Recognising strings of S*
Goal. For S = { c c , d } S = \{cc, d\} S = { cc , d } , describe S ∗ S^* S ∗ and decide whether c c d c c c d ccdcccd cc d ccc d and d c c c c d dccccd d cccc d are in it.
Step. A string is in S ∗ S^* S ∗ when it can be cut into pieces c c cc cc and d d d . So S ∗ S^* S ∗ = all strings of c c c ‘s and d d d ‘s in which every block of consecutive c c c ‘s has even length (including λ \lambda λ ).
Step. c c d c c c d ccdcccd cc d ccc d has a block c c c ccc ccc of length 3, which cannot be cut into c c cc cc pieces: not in S ∗ S^* S ∗ .
Step. d c c c c d = d ⋅ c c ⋅ c c ⋅ d dccccd = d \cdot cc \cdot cc \cdot d d cccc d = d ⋅ cc ⋅ cc ⋅ d : in S ∗ S^* S ∗ .
Result. c c d c c c d ∉ S ∗ ccdcccd \notin S^* cc d ccc d ∈ / S ∗ , d c c c c d ∈ S ∗ dccccd \in S^* d cccc d ∈ S ∗ .
Theorem 2.8 · Closure of a closure
For every language S S S , ( S ∗ ) ∗ = S ∗ (S^*)^* = S^* ( S ∗ ) ∗ = S ∗ .
Proof. S ∗ ⊆ ( S ∗ ) ∗ S^* \subseteq (S^*)^* S ∗ ⊆ ( S ∗ ) ∗ , because every string of S ∗ S^* S ∗ is a product of one string of S ∗ S^* S ∗ . Conversely, a string of ( S ∗ ) ∗ (S^*)^* ( S ∗ ) ∗ is x 1 x 2 … x n x_1 x_2 \dots x_n x 1 x 2 … x n with each x i ∈ S ∗ x_i \in S^* x i ∈ S ∗ ; each x i x_i x i is a product of strings of S S S , so the whole string is a product of strings of S S S , i.e. it is in S ∗ S^* S ∗ . Hence ( S ∗ ) ∗ ⊆ S ∗ (S^*)^* \subseteq S^* ( S ∗ ) ∗ ⊆ S ∗ . ■ \blacksquare ■
Common mistake
Forgetting λ \lambda λ in S ∗ S^* S ∗ . S ∗ S^* S ∗ always contains λ \lambda λ (zero pieces), even if λ ∉ S \lambda \notin S λ ∈ / S . S + S^+ S + contains λ \lambda λ only if λ ∈ S \lambda \in S λ ∈ S .
Common mistake
Thinking S ∗ S^* S ∗ only repeats one string. { a , b a } ∗ \{a, ba\}^* { a , ba } ∗ contains a ⋅ b a ⋅ a = a b a a a \cdot ba \cdot a = abaa a ⋅ ba ⋅ a = abaa : you may mix different strings of S S S in any order.
Key idea
S ∗ S^* S ∗ is every concatenation of zero or more strings of S S S (so it contains λ \lambda λ ); S + S^+ S + uses one or more; and the product S T ST S T concatenates a string of S S S with a string of T T T .
TEE Exam note
“Write the Kleene closure of …” (Ex.2): list strings in order of length and describe the pattern in words. { a a , b } ∗ = { λ , b , a a , b b , a a b , b a a , b b b , a a a a , … } \{aa, b\}^* = \{\lambda, b, aa, bb, aab, baa, bbb, aaaa, \dots\} { aa , b } ∗ = { λ , b , aa , bb , aab , baa , bbb , aaaa , … } = strings of a a a ‘s and b b b ‘s in which every block of a a a ‘s has even length. { a , b a } ∗ = { λ , a , a a , b a , a a a , a b a , b a a , … } \{a, ba\}^* = \{\lambda, a, aa, ba, aaa, aba, baa, \dots\} { a , ba } ∗ = { λ , a , aa , ba , aaa , aba , baa , … } = strings in which every b b b is immediately followed by an a a a . Also be ready to prove ( S ∗ ) ∗ = S ∗ (S^*)^* = S^* ( S ∗ ) ∗ = S ∗ .
Key takeaways
S T ST S T : a string of S S S followed by a string of T T T .
S ∗ = { λ } ∪ S ∪ S S ∪ … S^* = \{\lambda\} \cup S \cup SS \cup \dots S ∗ = { λ } ∪ S ∪ S S ∪ … ; S + = S ∪ S S ∪ … S^+ = S \cup SS \cup \dots S + = S ∪ S S ∪ …
Σ ∗ \Sigma^* Σ ∗ is the set of all strings over Σ \Sigma Σ .
( S ∗ ) ∗ = S ∗ (S^*)^* = S^* ( S ∗ ) ∗ = S ∗ .
Practice questions Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 1 · multiple choice Which string is in { a b , b } ∗ \{ab, b\}^* { ab , b } ∗ ?
Check answer
Show answer Answer: C. b a b b babb babb
b a b b = b ⋅ a b ⋅ b babb = b \cdot ab \cdot b babb = b ⋅ ab ⋅ b . Option 2, b a ba ba , ends with an a a a that is not followed by b b b , so it cannot be cut into pieces a b ab ab and b b b .
Question 2 · multiple choice How many strings does { a , b } { a , b , λ } \{a, b\}\{a, b, \lambda\} { a , b } { a , b , λ } contain?
A 4 B 6 C 5 D 3
Check answer
Show answer Answer: B. 6
Each of 2 strings is followed by each of 3 strings, giving a a , a b , a , b a , b b , b aa, ab, a, ba, bb, b aa , ab , a , ba , bb , b — 6 different strings. Option 1 forgets the strings formed with λ \lambda λ .
Question 3 · multiple choice Is λ ∈ { a b } + \lambda \in \{ab\}^+ λ ∈ { ab } + ?
Check answer
Show answer Answer: A. No
S + S^+ S + uses at least one string of S S S , and λ ∉ { a b } \lambda \notin \{ab\} λ ∈ / { ab } . Option 2 is true only for the Kleene star S ∗ S^* S ∗ .
Question 4 · multiple choice For Σ = { 0 , 1 } \Sigma = \{0, 1\} Σ = { 0 , 1 } , how many strings of length at most 2 are in Σ ∗ \Sigma^* Σ ∗ ?
A 4 B 6 C 7 D 8
Check answer
Show answer Answer: C. 7
1 + 2 + 4 = 7 1 + 2 + 4 = 7 1 + 2 + 4 = 7 (one of length 0, two of length 1, four of length 2). Option 2 forgets λ \lambda λ .
Question 5 · multiple choice Which statement is always true?
Check answer
Show answer Answer: D. S ∗ = S + ∪ { λ } S^* = S^+ \cup \{\lambda\} S ∗ = S + ∪ { λ }
The star adds the zero-piece case λ \lambda λ to the positive closure. Option 1 fails when λ ∉ S \lambda \notin S λ ∈ / S .
Question 6 · short answer
Describe { c c , d } ∗ \{cc, d\}^* { cc , d } ∗ in words and decide whether c c c c d c c cccc d cc cccc d cc and d c d dcd d c d belong to it.
Show worked answer { c c , d } ∗ \{cc, d\}^* { cc , d } ∗ is the set of all strings over { c , d } \{c, d\} { c , d } (including λ \lambda λ ) in which every maximal block of consecutive c c c ‘s has even length. c c c c d c c = c c ⋅ c c ⋅ d ⋅ c c ccccdcc = cc \cdot cc \cdot d \cdot cc cccc d cc = cc ⋅ cc ⋅ d ⋅ cc , so it belongs. d c d dcd d c d has a block of one c c c (odd length), so it does not belong.