Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 3

Building Languages with Set Operations

Recommended resources

Hello! Welcome to your third lesson in the Theory of Computation.

In our last lesson, we developed the crucial skill of proving properties of string operations using mathematical induction. We now have a solid grasp on the building blocks (alphabets, strings, languages) and a powerful method for reasoning about them formally.

Today, we will build upon this foundation to achieve this lesson's learning outcome: to construct languages using set operations (union, intersection, complement, concatenation, and Kleene star). We will explore how to combine simple languages into more complex and interesting ones. These operations are not just abstract concepts; they form the very core of tools you've likely used, such as regular expressions for pattern matching in code or text processing pipelines.

Let's begin by exploring these operations, starting with those that are likely already familiar to you from set theory.

1. Set-Theoretic Operations on Languages

Since we defined a language as a set of strings, it follows that we can apply standard set operations to them. The three fundamental set operations are union, intersection, and complement.

Set Operations with Venn Diagrams
Venn diagrams illustrating the set operations of Union, Intersection, Difference (a form of complement), and Complement. For languages, the universal set is \(\Sigma^*\), the set of all possible strings over a given alphabet.

Let's consider two languages, and , over an alphabet .

  • Union (∪): The union of and , written as , is the language containing all strings that are in , or in , or in both.
  • Intersection (∩): The intersection of and , written as , is the language containing all strings that are in both and .
  • Complement (L̄): The complement of a language , written as or , is the set of all strings over the alphabet that are not in . It's crucial to remember this is a relative complement with respect to .

Example:
Let , , and .

  • contains every string made of 'a's and 'b's that is not in . This is an infinite language. A few of its strings are:

2. Language-Specific Operations

Next, we'll explore operations that are unique to formal languages and leverage the concatenative nature of strings. For a high-level, intuitive overview, the following video is an excellent starting point.

Introduction to Languages, Strings, and Operations

This video from the lydia channel provides clear, animated examples of the key language operations: union, intersection, concatenation, and the star operation. It will help build your intuition before we dive into the formal definitions.

Watch the video from 01:47 to 04:30. Focus on how new languages are constructed from the example languages A and B for each operation, especially for concatenation and the star operation.

Now that you have a visual feel for these operations, let's establish their formal definitions. The following reading from Jean Gallier's notes provides the rigorous definitions we need.

Chapter 1 Basics of Formal Language Theory

This document provides the precise, mathematical definitions for all the operations we are studying in this lesson.

Please read Section 1.3, 'Operations on Languages' (pages 19-24). Start from the heading '1.3 Operations on Languages' and read through to the end of Definition 1.3.2 and its subsequent explanation. Focus on the formal definitions of concatenation, language exponentiation (L^n), and the Kleene closures (L* and L+).

Let's review and expand on the key definitions from the reading.

Language Concatenation

This operation is a natural extension of string concatenation, which we studied in the previous lesson.

  • Concatenation (·): The concatenation of and , written as or , is the language formed by taking every string in and appending to it every string in . Important: Like string concatenation, language concatenation is not commutative. In general, .

Example:
Let and .

Language Exponentiation and Kleene Closure

These operations allow us to generate languages of infinite size from finite ones, which is a cornerstone of this field.

First, we define the power of a language , denoted , as concatenating the language with itself times.

  • (This is a crucial definition: the "zeroth power" of any language is the set containing only the empty string).
  • In general, for .

With this, we can define the two most powerful operations: Kleene Star and Kleene Plus.

  • Kleene Star (∗): The Kleene star (or Kleene closure) of a language , written as , is the union of all powers of . It represents concatenating zero or more strings from .

    Since , the language always contains the empty string , regardless of whether is in .

  • Kleene Plus (+): The Kleene plus of , written as , is similar but excludes the case. It represents concatenating one or more strings from .

    This leads to the simple relationship: .

Let's visualize the Kleene Star with an example.

Example of Kleene Star Operation
This image demonstrates the Kleene star operation on the language \(L = \{aa, b\}\). It shows how \(L^0\), \(L^1\), and \(L^2\) are formed, and then defines \(L^*\) as the infinite union of all such powers. Strings in \(L^*\) include \(\epsilon\), \(aa\), \(b\), \(aaaa\), \(aab\), \(baa\), \(bb\), and so on.

This operation directly corresponds to the * quantifier in regular expressions. For example, the regex a* describes the language , which is .


3. Putting It All Together

Let's work through an example that combines these operations.

Let .
Let (this is just itself).
Let .

  1. : This is the set of all strings that can be formed by concatenating zero or more symbols from . This is simply , the set of all possible binary strings.
  2. : This is the set of all strings formed by concatenating one or more strings from .
    • includes all of these and more, like , etc. Notice that every string in has an even length.
  3. : . This is the set of all 3-bit binary numbers.
  4. :
    • .
    • The star of this set includes , any string from the set itself (like 0 or 11), and any concatenation of them (like 011, 110, 0010). This language is also equivalent to . Why? Because 0 and 1 are in the base set, any binary string can be formed.
Test your understanding!

Let , , and .

Calculate the following languages. List at least 4-5 strings for any infinite languages.

Show answer
  1. : The intersection contains elements present in both sets. There are no common strings.

  2. : The complement of is every string in except for 'b'.

  3. : We concatenate each string from with each from .

  4. : This is one or more concatenations of the string 'b'.

  5. : This is zero or more concatenations of strings from . Since concatenating with doesn't change a string (, ), this is equivalent to zero or more concatenations of just 'a'.


Conclusion

In this lesson, we have equipped ourselves with a powerful toolkit for constructing and describing languages.

Key Takeaways:

  • Languages can be combined using standard set operations: union (∪), intersection (∩), and complement (L̄). The complement is always taken with respect to .
  • Languages also have special operations based on string structure: concatenation (L₁L₂) and the powerful closure operations.
  • Kleene Star (L)* generates the set of all strings formed by concatenating zero or more elements of a language L. It always includes .
  • Kleene Plus (L+) generates the set of all strings formed by concatenating one or more elements of L.

These operations are the verbs of our formal language theory. They allow us to precisely define languages, including infinite ones, from simple, finite building blocks.

In the next lesson, we will formalize the distinction between finite and infinite languages and introduce our first computational model: the automaton. We will see that these operations are not just for description; they are intimately connected to what simple machines can—and cannot—compute.