A language (set of formulae/strings) is regular if every word in it is accepted by a deterministic finite state automata.
Definition
Regular Language
Let be a language. is a regular language if there exists at least one deterministic finite automaton (DFA), that recognises :
What does recognise mean?
Regular Operations
Most operations on languages are closed over regularity or regular-preserving. That is, applying these operations on a regular language will always result in another regular language. The proofs for such properties usually involve the construction of a new DFA or NFA, since if we can construct a DFA that only recognises a set of strings, then the language corresponding to that set of strings is regular.
The following operations preserve regularity (See Theorems for more info):
Limitations
While every finite language is regular, there are some infinite languages that are non-regular.
Take the language
To prove this language is regular, we would need a DFA that can keep track of how many occurrences of it encountered, so that it is equal to the number of occurrences of 0.
However, DFAs are ‘memoryless’, so this is not possible!
Examples
- is regular
This is because is finite and can be represented by the regex . Then produces a valid regex, and hence it describes a regular language.
Theorems
T1: Every finite language is regular
Let be a language.
Finiteness here means that has a finite number of strings, and is some ‘closed’ set.
C1: Regularity is closed under any boolean combination
From the theorems below, we can construct an equivalent ‘mapping’ that maps set operations with logical connectives. That is, just like we can create a complex predicate using logical connectives over atoms, we can construct a new language using a combination of languages.
If all the ‘atomic’ languages used to make a new language are regular, then the new language is also regular
T2: Regularity is closed under union ^t2
Let be two regular languages. Then, the union (with respect to languages), preserves regularity:
The contrapositive yields:
Proof
- We know, by definition of regular languages, that there exists DFAs that recognise and . Let and (i.e. are recognised by , respectively).
- We can construct an NFA, using and :
- accepts everything that and accept, (because we are essentially running them both in parallel)
- Then, recognises , i.e.
- By the theorem of equivalence, there is an equivalent DFA, that also recognises .
- Since we have a recognising DFA, is a regular language.
T3: Complement of a regular language is regular ^t3
Let be a regular language. Then, the complement of , given by is regular:
Proof
- Since is regular, there exists a DFA, that recognises .
- We can construct a new DFA, , which ‘flips’ all the accepting states of . That is, any accept state in becomes a non-accepting state in and vice versa. Then we have:
- accepts every string that would reject, and hence it recognises
- Thus, is regular. %%🖋 Edit in Excalidraw, and the dark exported image%%
T4: Regularity is closed under concatenation ^t4
Let be two regular languages. Then, the operation of concatenation preserves regularity:
Proof
- We know, by definition of regular languages, that there exists DFAs that recognise and . Let and (i.e. are recognised by , respectively).
- We can construct an NFA, using and :
%%🖋 Edit in Excalidraw, and the dark exported image%%
- Essentially, is made by connecting the initial states of to the accepting/final states of by epsilon transitions. This ensures none of the input string gets consumed when are checking the second section.
- Then, recognises , i.e.
- By the theorem of equivalence, there is an equivalent DFA, that also recognises .
- Since we have a recognising DFA, is a regular language.
T5: Regularity is closed under Kleene star ^t5
Let be a regular language. Then, the Kleene star operation preserves regularity:
Proof
- Since is regular, there exists a DFA, that recognises .
- We can construct an NFA, that ‘loops over’ using epsilon transitions:
%%🖋 Edit in Excalidraw, and the dark exported image%%
- Then, recognises
- By the theorem of equivalence, there is an equivalent DFA, that also recognises .
- Since we have a recognising DFA, is a regular language.
Proof (Concise):
T6: More regular-preserving operations #TODO ^t6
The following operations all preserve regularity:
- Intersection
- Set Difference
- Reversal