Title: Example.%20Simplify%20a%20regular%20expression:
1- Distinct regular expressions may represent the
same language - ab and ba represent the same language a, b.
- Two expressions R and S that represent the same
language, - L(R) L(S), are considered equal. For example,
a a a - because L(a a) L(a) ?, a, aa, aaa,
Example. Simplify a regular expression
(ab)
?L ?, ab, abab, ababab,
aa (ba)
a(ab)
To prove it we can show that aa(ab) ? a
(ab)(ab)? a(ab) and aaa(ab) ? a(ab).
Then use A ?B ? A?B B
2Properties of Regular Expressions 1) properties
RTTR R??RR
RRR (RS)TR(ST)
? L(R) ? L(T) L(R) ?L(T)
? L(R) ?? L(R)
? L(R)?L(R) L(R)
? (L(R)?L(S))?L(T) L(R)?(L(S)?L(T))
2) ? properties of regular expressions
R????R? R????RR (R?S)?TR?(S?T)
3) distributive properties of regular
expressions R?(ST)R?SR?T (ST)?RS?R S?T
34) closure properties ??? RRR(R)RR
R? R(? R)(?R) R?R R R(R
Rk) for any k?1 R? R R2 Rk?1Rk
R for any k?1 RRR R (RS)(RS
)(RS)(RS)RR(SR) R(SR)(RS)R (RS
)?(RS)S (RS)?R(RS)
4- Each of this properties can be proved.
- For example, let's prove that R RR.
Proof. We need to prove two inclusion properties,
i) R? R? R and ii) R ? R ?R.
i) To prove R?R? R it is sufficient to note
that for any expression S (understand for any
set of strings, described by expression S) S ?
S? R because ? ?R.
ii) To prove R? R ?R let's take arbitrary
string w? R? R ..(1) to prove that w?R.
(1) ? wuv, where u?R and v?R.. (2)
(2) ? u?Rn and v?Rm for some integer n and m.
Then wuv?Rnm ? R. So, we proved both subset
relations, i.e. two regular expressions are
equal, RRR.
5Let's prove one more property of regular
expressions, (RS)(RS)R.
Proof. We understand the equality of two
expressions as the equality of two sets of
strings denoted by these expressions. So, we are
going to prove two subset relations i)
(RS) ?(RS)R and ii) (RS)R ?(RS).
i). Take arbitrary string w?(RS)
? w?(RS)n for some integer n?0.
? wu1u2un, where ui?RS for i1, 2,n.
ui?RS ? ui?R or ui?S.
Denote any substring ui?R as uir and a substring
ui?S as uis. Then string w is a sequence of
substrings r and s, like wrrrssrsssrsrr
rrrs?s?rs?s?s?rs?rr v1v2v3v4v5v6 t, , where
vj?RS, wv1v2vkt, where t?R
So, any string w?(RS)R.
6In the same way we may prove that ii) (RS)?R
?(RS).
(left as an exercise).
Example. Using properties of regular expressions
prove the equality ba(baa) b( a ba ).
We can prove the equality by using the
property (RS) R(SR)
Take R a, S ba, then (aba) (RS)
R(SR) a(baa)
7We can also establish simple rules, that can be
used in proofs by double inclusion. Let A,
B and C be sets of strings, then 1) A ? B ? A?C
? B?C 2) A ? B ? A? B 3) ? ? B ? A ? A?B and
A ? B?A
Then we can prove a(ab)aa(ab)aaa(ab)
a(ab) by proving aa(ab)? a(ab) and
aaa(ab)? a(ab)
a ? ab
? (ab)
a(ab)? (ab)(ab)
? (ab)(ab) (ab)
aa(ab)? a(ab)
aaa(ab)? aa(ab) ? a(ab)
8Example. Prove that (? aba)b (a b).
We can show two subset relations i) (?
aba)b ? (a b) and ii) (a b) ? (?
aba)b
i) (? aba)b ? (a b)
b ?ab
b?(ab)
? ? (ab)
(? a ba) ?(ab)
a ?ab?(ab)
ba ?(ab) (ab) (ab)
(? a ba)?(ab) (ab)
Finally, (? a ba) b ?(ab) (ab) (a b)
9ii) (a b) ? (? aba)b
by ba ? (? a ba)
? (? aba)b
10Deterministic Finite Automata (DFA)
DFA is a recognizer for regular languages. They
model the behavior of real computing devices
which are designed to distinguish a correct
input over a given alphabet.
This abstract machine (DFA) is a device that
reads an input string, one symbol at a time and
decides whether the string belongs to the
language or not (accept or reject).
11- DFA includes
- alphabet
- finite nonempty set of states
- transition function defined for each state and
on each symbol - start states
- accepting states
The DFA can be depicted as a directed graph,
where vertices represent states and each edge is
labeled by the input symbol and dictates how the
machine changes its state on reading this symbol.
12Example. Construct a DFA to recognize the
regular language over alphabet a, b described
by regular expression L(aba).
So, we need to find a DFA that is able to
distinguish between strings, that belong to
L(aba) and strings that do not.
Transition function
?(q0, a)q1, ?(q0, b)q2
?(q1, a)q3, ?(q1, b)q1
?(q2, a)q2, ?(q2, b)q2
?(q3, a)q2, ?(q3, b)q2
13DFA ? L (aba)
DFA consists of
- Set of states Qq0, q1, q2, q3
including q0 - start state q3 - accepting
state
- Transition function ?(qi, ak)
- that assigns the nest state on
- reading any ak ?? for each qi ?Q
14Assume w abbaa enters the DFA.
By reading an input DFA goes through sequence of
configurations
15The configuration is a pair of a state and
remaining input, (qi, w)
(q0, abbaa)
? (q1, bbaa)
? (q1, baa)
? (q1, aa)
? (q3, a)
? (q2, ?)
A string is accepted by a DFA if and only if on
the reading this string the DFA comes to the
configuration (qa, ?), where qa is an
accepting state.
16The string is accepted (recognized to be in the
language) if DFA comes to accepting state after
reading the input string
Instead of using transition function ?(qi, ak) we
can give the equivalent transition table.
17Inductive proofs on strings.
Usually induction is done on the length of a
string w n, or the number of repetition of
some pattern.
Prove that the regular expression R (abb)(?a)
describes the language L ?a, b , consisting
of all strings that do not contain aa.
Proof. To prove the equality of two sets of
strings, L and R, we can prove two subset
relations, R?L and L?R
i) R ?L , we need to prove that for any string w
w?R ? w?L
Assume w?R (abb)(?a)
? w? (abb)n (?a), for some n?0
Prove by induction on n?0 , that for any w?
(abb)n (?a) ? w ? L.
18Prove by induction on n?0 , that for any
w?(abb)n(?a) ? w ? L.
Basis. n0, w?(?a), we have either w ? or w
a. In both cases w ? L, because it does not
contain aa.
IH. Assume that for nk, k ?0, any string from
the set s?(abb)k(?a) belongs to L.
IS. We need to prove that any string
w?(abb)k1(?a) belongs to L.
w?(abb)k1(?a) ? w?(abb)s , where
s?(abb)k(?a), either wabs or wbs , in both
cases w does not contain aa since s does not
contain aa by IH.
19ii) Take any w ? L and prove that w?R
(abb)(?a).
Lets prove it by induction on the length wn ?0
Basis. n0, w ?, ? ?R (abb)(?a).
IH. Assume that for nk, k ?0, we have that any
string v ?L with length v? k belongs to R.
IS. We need to prove that any string from L with
length k1 belongs to R.
Take w ?L, wk1. We can consider two cases 1)
was or 2) wbs. In the first case w ?L ? sbu,
where u ?L, and by IH u ?R, since u k?1ltk ,
i. e. u ?(abb)(?a).
Then w abu ?ab(abb)(?a) ? (abb)(?a).
20In the second case, wbs, where s ?L and sk,
so s ?R (abb)(?a) by IH.
Then w ?b(abb)(?a) ? (abb)(?a).