Regular expressions are used whenever a task requires pattern matching:
search engines
protein analysis (bioinformatics)
search and replace in text editors
text processing utilities such as sed and awk
Many programming languages provide various regular expression capabiltiies. Lexical analysers in compilers also use regular expressions.
Finite representation of languages
Consider the following language:
L=all strings of α and β that have two or three occurrences of β, the first and second of which are not consecutive
Can we describe this infinite language with a finite pattern?
Strings in L can start with any number (possibly none) of α: α∗
Then we have the first β, it should be alone and followed by at least one α: βα
Then any number (possibly none) of α: α∗
Then comes the second β: β
Then either:
No more β but can be any number (possible none) of α.
Or after some (possibly none) α, there is a third β somewhere, followed by any number (possibly none) α.
This gives us: α∗∪α∗βα∗
Combining all of these together gives us:
α∗βαα∗β(α∗∪α∗βα∗)⇝ regular expression representing LLink to original
2. Examples of regular expressions
Example 2
Given the following language:
L=all the strings consisting of some number (possibly none) of a followed by some number (possibly none) of b={ϵ,a,b,aa,bb,ab,aaa,aab,bbb,abb,abb,...,aaaabbbbbbb}
We can use the regular expression:
a∗b∗⇝L is represented by the regular expression a∗b∗
We use the notation: L=Language_of(a∗b∗)
Which we read as “the language of a∗b∗ is L”,
or “the language represented by a∗b∗ is L”.
Example 3
Langauge_of(a(a∗∪b∗))=all words starting with a followed by either a(possibly empty) word of a or a (possibly empty)word of b={a,aa,ab,aaa,abb,aaaa,abbb,aaaaaa,abbbbbbb}
Example 4
Language_of(a(a∪b∗))=all words starting with a followed byany word over {a,b}=all words over {a,b} starting with a={a,aa,ab,aaa,aab,aba,abb,aaaaa}
Example 5
Find the Language_of((b∪aaa∗)∗).
Start by finding Language_of(aaa∗)
Language_of(aaa∗)=all words of a of length ≥2={aa,aaa,aaaa,aaaaa,...}
Find Language_of(b∪aaa∗)
Language_of(b∪aaa∗)= as above plus the word b={b,aa,aaa,aaaa,...}
Find Language_of((b∪aaa∗)∗)
We can take any number (possibly none) of words from Language_of(b∪aaa∗) and concatenate them together.
Example 6
Find the Language_of((b∪a)aa∗).
Find Language_of(b∨a)={a,b}.
Find Language_of((b∨a)a)={aa,ba}.
Find Language_of((b∨a)aa∗)= all words starting with aa or ba followed by a (possibly empty) word of as.
Example 7
Find the Language_of(ϵ∨c∗(a∨bc∗))
All the strings that are either empty or start with some (possibly none) cs followed by either an a, or a b followed by (possibly none) cs.
Each regular expression over some alphabet Srepresentsa language over $S$.
The following are two different things:
A regular expression R.
A string or finite pattern.
The language R represents: Language_of(R).
A set of words over S, words following the pattern.
Regular Language
A regular language is any language that can be representeed by a regular expression. A language L is regular if L=Language_of(R) for some regular expression R.
There is a general ‘mechanical’ proecedure P1 that converts any regular expression R to an NFA AR such that L(AR)=Language_of(R).
So every regular language is accepted by some automaton.
There is a general ‘mechanical’ procedure P2 that converts any NFA A to a regular expression RA such that Language_of(RA)=L(a).
So every language that is accepted by some automaton is regular.
This algorithm is out of scope.
title: Regular langauges are <u>precisely those</u> languages that are accepted by finite automata.
Procedure P1
The procedure P1 which converts any regular expression R to an NFA AR such that L(AR)=Language_of(R) operates along the recursive description of the regular expression R.
Consider the following language over the alphabet {a,b}:
L=all words starting with a word of a’s followedby an equal-length word of b’s={anbn∣n=0,1,2,...}
Suppose that a finite automaton A tries to recongise words in this language. Then A must store the entire sequence of a‘s before the first b shows up. Otherwise A will not be able to compare the length of the coming word of bs with the length of the prefix of as.
As each automaton is capable for a fixed finite amount of storage with the help of its states, no automaton A exists such that L(A)=L.
There is a precise mathematical proof justifying this informal argument: this language L is indeed not regular.