A regular language is a language that can be represented by finite automata. It can be deterministic finite automata (DFA) or non deterministic finite automata (NFA). DFAs and NFAs are equivalent to each other in terms of their computational power. DFAs are NFAs by default. NFAs can be converted into their equivalent DFAs.
The following are examples of regular languages over a set of alphabets :
In this blog, we discuss the closure properties of regular languages and pumping lemma.
Regular languages are closed under many set-theoretic operations including reversal, concatenation, Kleene closure, complement, union, and intersection. Let’s discuss and prove why regular languages are closed under all these properties.
Regular languages are closed under the reversal operation. The reverse of a string, , is notated as . If , then . If is a regular language, then there exists an NFA to recognize . An NFA can be constructed to recognize if an NFA for is given using the following procedure:
The NFA that recognizes is shown below:
The resultant NFA that recognizes is shown below.
Regular languages are closed under the concatenation operation. If two languages are regular then there exist two NFAs to recognize these languages. We create a new NFA having -transition(s) from the final state(s) of the first NFA to the start state of the second NFA and remove the final status of all final states of the first NFA. The initial state of the second NFA will no longer be the initial state of the resultant NFA. The resultant NFA recognizes the concatenation of two given languages whose NFAs have been used to construct the new NFA.
Regular languages are closed under Kleene closures. The Kleene closure of a language (or a set) is defined as follows:
Here,
and
is recursively defined as follows:
The following figure presents a DFA for a regular language :
Its Kleene closure () is computed by the construction of the NFA, as follows:
Regular languages are closed under the complement operation. If a language is regular, then there exists a DFA to recognize it. All strings whose consumption ends up in a final state are part of the language. And all strings whose consumption ends up in a nonfinal state are part of the complement of the language. So, to construct a DFA for the complement, all final states are made nonfinal and vice versa. The resulting DFA recognizes the complement of the language. The following figure represents a DFA recognizing a regular language.
The following figure presents the DFA that recognizes the complement of the given language.
Regular languages are closed under the union operation. If two languages are regular then there exist two NFAs to recognize these languages. We create a new NFA having -transitions from its start state to the start states of the given NFAs. The resultant NFA recognizes the union of two given languages whose NFAs have been used to construct the new NFA.
Regular languages are closed under the intersection operation. The intersection of two languages (or sets) is defined as follows using DeMorgan’s law:
Let’s deconstruct the expression above:
Pumping lemma is an important and interesting property of regular languages.
If a language is regular, then there exists a DFA that recognizes the language. Let’s notate the number of states of the DFA as where is a finite positive integer.
For an infinite regular language , the DFA must contain at least one nonempty loop. If and , then can be written as follows:
such that and . Because and , there must exist a walk from the start state to one of the final states of the DFA to consume . The number of states in the DFA is . So the longest walk without repeating a state can be of length. To consume , at least one of the states must be repeated, otherwise can’t be accepted. The repeating part of the walk makes the substring . The part of the string before the repeated part makes the substring , and the part of the string after the repeated part makes the substring . The following figure shows a breakdown of the substrings that make up a valid string to be accepted by the DFA:
The pumping lemma states that if and , then . It implies that if a walk from the start state to the final state is decomposed into three substrings, then there are two types of behaviors being observed: repeating parts of the walk and nonrepeating parts of the walk. Here, is the repeating part. If repeats itself times then the resulting walk from the start state to the final state remains part of the language. Therefore, all forms of the walk, where is repeating times are part of the language. For instance, , , , , and so on, will be part of the language.
A regular language can be proved to be regular using different methods including:
For example, let’s prove that the following language is regular:
One way to prove that is regular is as follows:
It's important to note here that pumping lemma can't be used to prove a language to be regular because we can't demonstrate that
.
To prove a language to be non-regular, we need to find a string and an where but , while fulfilling individual constraints on and its substrings. This implies that the given statement of the pumping lemma is not true for all .
Let’s try to understand how to prove that a language is not regular. One effective approach is to apply the pumping lemma. If is a regular infinite language, , , and , then .
Let’s understand this through two examples:
Our task is to prove that the following language is not regular:
As , therefore, is infinite. Assume that is regular. If it is regular then there exists a DFA that recognizes . The number of states in the (assumed) DFA will be a finite integer, say .
Let’s choose a string , such that .
Here, . The chosen string can be decomposed into three substrings , , and such that and . Let’s represent the length of as , where . In this string, and both have to fall within s because their combined length can’t go beyond . Let’s repeat twice and create a new string .
Because is a composition of number of s, the resulting string will be:
According to the pumping lemma, , but we 've demonstrated that . Therefore, our assumption is incorrect and the given language is not regular.
Our task is to prove that the following language is not regular:
Because , therefore, is infinite. Assume that is regular. If it’s regular, then there exists a DFA that recognizes . The number of states in the (assumed) DFA will be a finite integer, say .
Let’s choose a string , such that .
Here, . The chosen string can be decomposed into three substrings, , , and , such that and . Let’s represent the length of as where . In this string, and both have to fall within the first number of 's because their combined length can’t go beyond . Let’s repeat twice and create a new string .
The lower limit on the length of the new string is . The upper limit on the length of the new string is .
Even the upper bound of falls below the next perfect square, i.e. .
According to the pumping lemma, , but we’ve demonstrated that . Therefore, our assumption is incorrect and the given language is not regular.
For an in-depth understanding of different classes of computational problems and their characterization, you can explore the following course:
Theory of Computation
What are the mathematics behind computers? What are the theoretical foundations of computer languages? Such questions can be explored by understanding formal languages and automata models. In this comprehensive course, you’ll explore formal languages, regular languages, and how to model them with their associated automata models. Next, you’ll cover regular expressions and grammar, and their equivalents. Then, you’ll explore context-free languages (the foundations of programming languages), pushdown automata, and the relationship between them. Toward the end, you’ll learn about recursively enumerable languages, Turing machines with their variations, context-sensitive languages, and unrestricted grammars. By the end of the course, you’ll have gained a deep understanding of several formal languages and their associated automata. Also, since there are plenty of exercises throughout the course, your understanding and problem-solving skills will be thoroughly reinforced.
Free Resources