160 likes | 306 Views
Summary . A language L is a set of strings over some alphabet . Set notations can be used to specify what strings belong to language. A language can be regular if it satisfies some restrictions. To describe a regular language we can use: set operations regular expressions
E N D
Summary. A language L is a set of strings over some alphabet . Set notations can be used to specify what strings belong to language. A language can be regular if it satisfies some restrictions. • To describe a regular language we can use: • set operations • regular expressions • DFA that recognizes the language. Any of this specification must be unambiguous (but may be not unique)
a, b a b a b a q0 q3 q1 q2 Example. Find the DFA to recognize the language L, which consists of all strings over the alphabet = {a, b}, L {a, b}* that include a substring aba. L= {a, b}*{aba}{a, b}* Set notation: (a+b)*aba (a+b)* Regular expression: DFA b
accepting state b ={a, b} Q ={q0, q1, q2, q3} a, b a b a b a q0 q3 q1 q2 aaaabab L start state Transition function : Q Q (q0, a)= q1 (q0, b)= q0 (q1, a)= q1 (q1, b)= q2 (q2, a)= q3 (q2, b)= q0 (q3, a)= q3 (q3, b)= q3 Configurations for the input string w=aaaabab (q1, aabab) (q1, abab) (q1, aaabab) (q0, aaaabab) (q1, bab) (q2, ab) (q3, b) (q3, )
b a 1 0 2 a b b 3 a, b a What language L {a, b}*is recognized by the following DFA? Give regular expression describing the language. L= +aa*b + aa*baa*b + aa*baa*baa*b +… = + aa*b+ (aa*b)2+ (aa*b)3+… = (aa*b)* L is the set of strings over {a, b} for which each occurrence of b is preceded by at least one a and the only string with no b’sis .
Inductive 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 =(ab+b)*(+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, RL and LR i) R L , we need to prove that for any string w [wR wL] Assume wR =(ab+b)*(+a) w (ab+b)n (+a), for some n0 Prove by induction on n0 , that for any w (ab+b)n (+a) w L.
Prove by induction on n0 , that for any w(ab+b)n(+a) w L. Basis.n=0, w(+a), we have either w = or w = a. In both cases w L, because it does not contain aa. IH. Assume that for n=k, k 0, any string from the set s(ab+b)k(+a) belongs to L. IS. We need to prove that any string w(ab+b)k+1(+a) belongs to L. w(ab+b)k+1(+a) w(ab+b)s , where s(ab+b)k(+a), either w=abs or w=bs , in both cases w does not contain aa since s does not contain aa by IH.
ii) Take any w L and prove that wR =(ab+b)*(+a). Let’s prove it by induction on the length |w|=n 0 Basis. n=0, w= , R =(ab+b)*(+a). IH. Assume that for n=k, 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 k+1 belongs to R. Take w L, |w|=k+1. We can consider two cases: 1) w=as or 2) w=bs. In the first case w L s=bu, where u L, and by IH u R, since |u|= k1<k , i. e. u (ab+b)*(+a). Then w = abu ab(ab+b)*(+a) (ab+b)*(+a).
In the second case, w=bs, where s L and |s|=k, so sR =(ab+b)*(+a) by IH. Then w b(ab+b)*(+a) (ab+b)*(+a).
Recursive functions on strings An example of recursive function on strings is the reversal of a string. Let f (w) be reversal of a string w*. It can be defined recursively as follows Basis. If |w|=0, i. e. w=, then f (w)=f ()= Recursive step. If w>0, then w=ua, for some a and u * and f (w)= f (ua)=af (u). Let’s find the reversal of w=abc by using this recursive definition. f (abc) = cf (ab) = cbf (a) =cbf (a) = cba f ()= cba = cba
We can prove by induction that for anyw f (w) gives the reverse of w, i. e. f (a1 a2 a3 … an) = an an-1…. a1 What will be the induction parameter n? Proof by induction on n = |w| 0 Basis.n = |w|=0, w = , f ()= by the basis of recursive defn IH. Assume that f (a1 a2 a3 … an) = an an-1…. a1 for n = k, k 0. In other words, we assume that for any string |w| = k, f (a1 a2 … ak) = ak ak-1… a1. IS. We need to prove that the property holds for n = k +1, i.e. for any string |w| = k+1 f (a1 … ak ak+1) = ak+1ak … a1. f(a1 a2 … ak ak+1) = f (u ak+1)= ak+1 f (u) by recursive step. = ak+1ak … a1 by IH for u= a1 … ak , |u|=k
Example. Prove by induction that f (f (w)) = w. First we need to prove the following lemma. Lemma. If |w| 1, then f (w)=f (bv)= f (v)b In words, we want to prove that at each recursive step we can reverse the first letter, e.g. f (abc)=f (bc)a, as well as f (abc)=cf (ab) Proof by induction on |v| 0 that f (bv)= f (v)b. Basis |v| =0, v=, f (b) = f (b) = bf () =b= b= f ()b IH. Assume that f (bv)= f (v)b when |v|=k, for some k 0. IS. We need to prove it for |v|=k+1. Since |v|=k+1 1, we have v=ua, for some a. f (bv)= f (bua) =a f (bu) =a f (u)b (by IH for |u|=k ) = f (ua)b (by recursive step a f (u)= f (ua) ) = f (v)b (since ua=v).
Proof by induction that f (f (w)) = w. Induction on n =|w| 0. Basis.n =0, w= . f (f ())= f ()= by the basis of recursive dfn of f (w) IH. Assume that f (f (u)) = u for n=|u|=k, for some k 0 IS. We need to prove f (f (w)) = w for n=|w|=k+1 f (f (w))= f (f (ua)) i.e. w=ua for some a, u*, |u|=k = f (af (u)) by recursive step = f (f (u))a by the Lemma. = ua because f (f (u))=u by IH =w since w=ua
What languages are not regular? Consider a language L {a, b}*, L ={anbn| n 0} Is it regular? A regular language can be obtained from , a and b by finite number applications of , and *-operation. Since L is infinite, we can get it only by *-operation. But there is no way you can get any number of a’s followed by equal number of b’s by *-operations. {ab}* = {, ab, abab, ababab, abababab, …} not what we need {a}*{b}*=? {a}n{b}n so, we can obtain it only from concatenation, but in this way we need infinitely many of them.
a a a a a 2 0 1 3 4 5 b b b b b The DFA that we need to recognize anbn needs n states … It would be a valid DFA to accept any finite language, anbn when n is limited.
Recursive definition of a language Example. Consider the following definition of L * , where ={a, b}. Basis.L Recursive step. If x L, then axb L Prove that for any string wL the number of a’s is equal to the number of b’s, i.e. |w|a=|w|b Any wL is obtained by finite number, n0, of applications of recursive step. Prove by induction on n0, that |w|a=|w|b Basis.n=0, w =, | |a=0=| |b IH. Assume that for some k 0, if u is obtained by n=kapplications of recursive step, then |u|a=|u|b .
IS Consider a string w, that is obtained by k+1 recursive steps from basis. It means that w=aub for some uL,where u is obtained in k steps. w=aub implies that |w|a= |u|a+1 and |w|b= |u|b+1 So, we have |w|a= |u|a+1 =|u|b+1 (by IH |u|a=|u|b) = |w|b We can prove also that L´={anbn | n0} =L