Closure Properties of Regular Grammars¶
1. Closure Properties of Regular Grammars¶
1.1. Closure Concept¶
Definition: A set is closed over a (binary) operation if, whenever that operation is applied to any two members of the set, the result is a member of the set.
Example 1
\(L = \{x\ |\ x\ \mbox{is a positive even integer}\}\)
Is \(L\) is closed under the following?
addition? Yes. [How do you know? You need a proof.]
multiplication? Yes. [How do you know? You need a proof.]
subtraction? No. \(6 - 10 = -4\). [Now you know!]
division? No. \(4 / 4 = 1\). [Now you know!]
Notice the difference between the requirement to determine that an operation is closed (need a proof covering all cases) and versus recognizing that the operation is not closed (just need a counter-example).
1.2. Closure of Regular Languages¶
Consider regular languages \(L_1\) and \(L_2\). Since they are regular languages, we know that there exist regular expressions \(r_1\) and \(r_2\) such that \(L_1 = L(r_1)\) and \(L_2 = L(r_2)\).
These we already know: [Ask yourself: Why do we know this?]
\(r_1 + r_2\) is a regular expression denoting \(L_1 \cup L_2\) So, regular languages are closed under union.
\(r_1r_2\) is a regular expression denoting \(L_1 L_2\). So, regular languages are closed under concatenation.
\(r_1^*\) is a regular expression denoting \(L_1^*\). So, regular languages are closed under star-closure.
Theorem: Regular languages are closed under complementation.
Proof:
Note
Q: Why a DFA, will an NFA work? A: With difficulty. It must be a complete NFA with trap states added.
Theorem: Regular languages are closed under intersection.
Proof:
One simple way to prove this is using DeMorgan’s Law:
Here is another approach, by construction.
Note
The idea is to construct a DFA so that it accepts only if both \(M_1\) and \(M_2\) accept
1.3. Regular languages are closed under these operations¶
Reversal: \(L^R\)
Difference: \(L_1 - L_2\)
Right quotient:
Definition: \(L_1 \backslash L_2 = \{x\ |\ xy \in L_1\ \mbox{for some}\ y \in L_2\}\)
In other words, it is prefixs of appropriate strings in \(L_1\).
Example 3
Theorem: If \(L_1\) and \(L_2\) are regular, then \(L_1 \backslash L_2\) is regular.
Proof: (sketch)
There exists a DFA \(M = (Q, \Sigma, \delta, q_0, F)\) such that \(L_1 = L(M)\).
Construct DFA \(M'=(Q, \Sigma, \delta, q_0, F')\) (equivalent to \(M\) except for final states).
Note
Not empty means there’s a path between start and a final state.
QED.
Homomorphism:
Definition: Let \(\Sigma, \Gamma\) be alphabets. A homomorphism is a function \(h : \Sigma \rightarrow \Gamma^*\)
Homomorphism means to substitute a single letter with a string.
Example 4
1.4. Questions about regular languages¶
\(L\) is a regular language.
Given \(L, \Sigma, w \in \Sigma^*\), is \(w \in L\)?
Answer: Construct a FA and test if it accepts \(w\).
Is \(L\) empty?
Example: \(L = \{a^nb^m | n > 0, m > 0\} \cap \{b^na^m | n > 1, m > 1\}\) is empty.
Construct a FA. If there is a path from the start state to any final state, then \(L\) is not empty.
Note
Perform depth first search on the graph beginning with the start state.
Is the complement of \(L\) regular?
Answer: Simply take the DFA and reverse the final and non-final states.
This was easy! But we will see in other contexts that complement is not so simple to decide.
Is \(L\) infinite?
Construct a FA. Determine if any of the vertices on a path from the start state to a final state are the base of some cycle. If so, then \(L\) is infinite.
Note: This idea of cycles in DFAs will be important later!
Does \(L_1 = L_2\)?
Construct \(L_3 = (L_1 \cap \bar{L_2}) \cup (\bar{L_1} \cap L_2)\). If \(L_3 = \emptyset\), then \(L_1 = L_2\).
Again, in other contexts, whether two representations for computation do the same thing can be impossible to answer. For example, we will prove that its not possible to decide, in general, if two programs do the same thing.
1.5. Summary: How do we prove that a language is regular?¶
We have a number of approaches in our toolbox.
Write a DFA that accepts the language.
Write a NFA that accepts the language.
Write a regular expression that accepts the language.
Write a regular grammar that accepts the language.
Define the language in terms of one or more known regular languages that are manipulated by operators known to be closed for regular languages.