0% found this document useful (0 votes)
12 views5 pages

HW3 Solutions: Non-Regular Languages

The document contains solutions to homework problems involving models of computation and regular/context-free languages. Problem 1 proves that two languages are not regular by using the pumping lemma to derive contradictions. Problem 2 determines whether two languages are regular. Problem 3 determines whether three languages are regular, using the pumping lemma. Problem 4 provides context-free grammars for two languages.

Uploaded by

陳星雨
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

HW3 Solutions: Non-Regular Languages

The document contains solutions to homework problems involving models of computation and regular/context-free languages. Problem 1 proves that two languages are not regular by using the pumping lemma to derive contradictions. Problem 2 determines whether two languages are regular. Problem 3 determines whether three languages are regular, using the pumping lemma. Problem 4 provides context-free grammars for two languages.

Uploaded by

陳星雨
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Models of Computation, HW3 Solutions

Standard mathematical notation: implies that,  there exists, for each, such that.

Problem 1: Prove the following are not regular


A (122/4b): L = {anblak : k  n+l }

Consider L = {anblak : k  n+l }


By construction, L  L = {a*b*a*} and L  L = 
 L = {w : w  L, w  {a*b*a*}} = Lc  {a*b*a*} (Lc == L complement)

The language {a*b*a*} is regular (since a*b*a* is a regular expression).

Furthermore, since regular languages are closed under complement and intersection, we have:
If L is regular then Lc is regular then Lc  {a*b*a*} = L is regular.

Therefore, if L is not regular then L is not regular either. It suffices to show that Lis not regular.
____________

Assume (for contradiction) that L is regular.

Since Lis regular and infinite we have from the pumping lemma that there exists m such that:
w  L with |w|  m,  x, y, z such that:
|xy|  m, |y| = k > 0, w = xyz and xyiz  L  i  0.

Let w = xyz = amba(m+1)  L. By construction, y = ak for some k  [1, m].


Consider xy2z  L
a(m+k)ba(m+1)  L
 m+k+1 = m+1 (by definition of L)
k=0

but k>0 (from pumping lemma)


which is a contradiction
 L is not regular.
 L is not regular.

B (122/4g): L = {wwwwR : w  {a,b}*}

Note:  w, |w| = |wR|


 u (= wwwwR) L,  c  0 such that |u| = 4|w| = 4c

Assume (for contradiction) that L is regular.

Since L is regular and infinite we have from the pumping lemma that there exists m such that:
 u  L with |u|  m,  x, y, z such that
|xy|  m, |y| = k > 0, u = xyz and xyiz  L  i  0.

Let w = amb (u = xyz = ambambambbam). By construction, y = ak for some k  (0,m).


Since |xy|  m and xy is a substring am
 y = ak
Consider u = xy2z  L
u = a(m+k)bambambbam  L
there exists string wsuch that u = www(w)R
We can assume k = 4n, since if k  4n for some n, then |u|  4c and u L
We can further assume n > 0, since if n = 0, k = 0, and  |y| = 0, which is a contradiction
Since |u| = 4m+4, |u| = 4m+4+k, |w| = m+1+n
n 1, 3n > 1
m + 1 + n < m + 3n + n = m + 4n = m + k
 w = a(m + n + 1) (first m+n+1 characters of u)  (first m+k characters of u) = a(m+k)
 u = wwwwR = a4(m + n + 1)
which is a contradiction, since u is known to contain 4 ‘b’s
 L is not regular.

Problem 2: Are the following regular?


A (122/5b): L = {an : n is not prime}

No.
Consider Lc = {an : n is prime}. (Lc is the coplement of L).

From the closure of regular languages under complement we have:


If L is regular then Lc is regular.

Therefore, if Lc is not regular then L is not regular either. It suffices to show that Lc is not regular.

Assume (for contradiction) that Lc is regular.

Since Lc is regular and infinite we have from the pumping lemma that the exists m such that:
 w  Lc with |w|  m,  x, y, z such that:
|xy|  m, |y| = k > 0, w = xyz and xyiz  Lc  i  0.

Let p > m be prime ; then w = xyz = ap  Lc


By observation, y must be ak
Consider xy(p+1)z  Lc
a(p + kp)  Lc
 (p+kp) is prime (by definition of Lc)

but (p+kp) = p*(k+1)


 (p+kp) is not prime
which is a contradiction
Lc is not regular

B (122/5d): L = {an : n = 2k for some k }

No.
Assume (for contradiction) that L is regular.

Since L is regular and infinite we have from the pumping lemma that there exists m such that:
 w  L with |w|  m,  x, y, z such that:
|xy|  m, |y| = k > 0, w = xyz and xyiz  L  i  0.

Let c = 2j > m ; then w = xyz = ac  L


By observation, y must be ak
Consider xy2z  L
a(c + k)  L
 q  2q = c+k (by definition of L)

but k  m < c,
 2j = c < c+k < 2c = 2*2j = 2(j+1)
 q  2q = c+k
which is a contradiction
 L is not regular

Problem 3: Which of the following are regular?


A (123/9c): L = {anbl : n is an integral multiple of l }

No.
We can use the pumping lemma.

Assume (for contradiction) that L is regular. By definition,


 m   w  L, |w|  m,  x, y, z  |xy|  m, |y| = k > 0, w = xyz and xyiz  L  i  0.
Let w = xyz = ambm  L (m = 1*m)
Since |xy|  m, xy  am
 y = ak
Consider xy2z  L
a(m+k)bm  L
 n  (m+k) = n*m (by definition of L)

but k<m
 1m = m < m+k < m+m = 2m
 n  (m+k) = n*m
which is a contradiction
 L is not regular

B: L = {anbl : (n-l) is a multiple of 3 }


Yes.
The following equivalent statements are used to simplify the problem:
(n-l) is a multiple of 3
 x  n-l = 3x + 0
n-l  0 (mod 3)
n  l (mod 3)
The last of these has 3 cases:
n  l  0 (mod 3) n  l  1 (mod 3) n  l  2 (mod 3)
Note that the extended regular expression { (cx)*cy : x > y } represents { cn : n  y (mod x) }
(this is only an extended regular expression when x and y are left as exponents of c; when
expanded out to { (cccc…c)*ccc…c } , it is a normal regular expression)
Since anbl is simply a concatenation of two such expressions, the union of the 3 cases is:
L = L( ((aaa)* (bbb)*) + ((aaa)*a (bbb)*b) + ((aaa)*aa (bbb)*bb) )
 L is regular
note: the above can also be simplified to: (aaa)*( + ab + aabb)(bbb)*

C (123/9g): L = {anbl : |n-l| = 2 }

No.

We use the pumping lemma.

Assume (for contradiction) that L is regular. By definition,


 m   w  L, |w|  m,  x, y, z  |xy|  m, |y| = k > 0, w = xyz and xyiz  L  i  0.
Let w =xyz = amb(m-2)  L ( |(m) – (m – 2)| == 2)
Since |xy| < m, xy  am
 y = ak
Consider xy2z  L
a(m+k)b(m-2)  L
| (m+k) – (m–2) | = | k + 2 | = k + 2 = 2 (by definition of L)
k=0
but k>0 (by definition of regular, above)
which is a contradiction
 L is not regular

D: L = {anbl : n + l = 100 }
Yes.
L is finite (101 elements), and all finite languages are regular; therefore L is regular.

Problem 4: Find a Context-Free Grammar for the following:


A (134/8c): L = {anbmck : k = n + m }
Let G be the grammar with productions:
S  aSc | B
B  bBc | 

Claim: L(G) = L
Proof:
Consider the following derivation:
S * anScn  anBcn * anbmBcmcn  anbmc(n + m)
(where the first * applies S  aSc n times, the second B  bBc m times)
Since all words in L(G) must follow this pattern in their derivations, it is clear that L(G)  L

Consider w  L, w = anbmc(n+m) for some n, m  0


The derivation S * anScn  anBcn * anbmBcmcn  anbmc(n + m) clearly produces w for any n, m.
 L  L(G)
 L  L(G)
 G is a CFG for L
B (134/8c): L = {anbmck : k  n + m }
Let G be the grammar with productions:
S  EcC | aAE | AU
A  aA | 
B  bB | 
C  cC | 
E  aEc | F
F  bFc | 
U  aUc | V
V  bVc | bB

Note: L(E) = {anbmck : k  n + m } (from 4(a))


Let L1 = {anbmck : k  n + m }, L2 = {anbmck : k > n + m }

Claim: L(G) = L = L1  L2

Proof:
Consider the leftmost productions following S  EcC
S  EcC * anbmc(n+m)cC * anbmc(n+m)cckC  anbmc(n+m)cck = anbmc(n+m+k+1)
(where the first * follows from 4(a), the second from k repetitions of { C  cC })
Since (n+m) < (n+m+k+1), L(EcC)  L2  L

Consider the leftmost productions following S  aAE


S  aAE * aakAE  aakE * aakanbmc(n+m)c = a(n+k+1)bmc(n+m)
(where the first * follows from k repetitions of { A aA }, the second from 4(a))
Since (n+m+k+1) > (n+m), L(aAE)  L1  L

Consider the leftmost productions following S  AU


S  AU * akAU  akU * akanUcn  akanVcn * akanbmVcmcn  akanbmbBcmcn
* akanbmbbjBcmcn  akanbmbbjcmcn = a(k+n)b(m+j+1)c(m+n)
(where the first, second, third and fourth * are k, n, m, and j repetitions of
{ A  aA }, { U  aUc }, { V  bVc }, and { B  bB }, respectively)
Since ((k+n)+(m+j+1)) > (m+n), L(AU)  L1  L

 L(G) = L(S) = L(EcC)  L(aAE)  L(AU)  L1  L2 = L

Consider w L1, w = anbmc(n+m+k) for some n, m, k, with k > 0


Then w has the leftmost derivation:
S  EcC * anbmc(n+m)cC * anbmc(n+m)cc(k-1)C  anbmc(n+m)cck(k-1) = anbmc(n+m+k) = w
 L2  L(G)

Consider w  L2, w = a(n+j)b(m+k)c(n+m) for some j, k, m, n, with j+k > 0


If k = 0, w has the leftmost derivation:
S  aAE * aa(j-1)AE  aa(j-1)E * aa(j-1)anEcn  aa(j-1)anFcn * aa(j-1)anbmFcmcn
 aa(j-1)anbmcmcn = a(j+n)b(0+m)c(m+n) = w
 L1 (k = 0)  L(G)
If k > 0, then w has the leftmost derivation:
S  AU * ajAU  ajU * ajanUcn  ajanVcn * ajanbmVcmcn  ajanbmbBcmcn
 ajanbmbb(k-1)Bcmcn  ajanbmbb(k-1)cmcn = a(j+n)b(m+k)c(m+n) = w
 L1 (k > 0)  L(G)

 L1  L(G)
 L = L1  L2  L(G)
 L = L(G)

Problem 5 (170/3): Convert the following to Chomsky Normal Form:


S aSaA | A
A  abA | b

S  I1I2 | TA | b
A  TA | b
I1  T1S
I2  T1A
T  T1T2
T1  a
T2  b

Method:

( (1) : skipping : G has no -productions )


(2) : Create productions for each terminal and substitute
T1  a, T2  b
(3) : Split productions of length > 2, creating intermediary productions of length 2
S  T1ST1A  { S  I1I2 , I1  T1S, I2T1A }
A  T1T2A  { A  TA, T  T1T2 }
(4) : remove unit productions
SA  { S  TA | b }

Common questions

Powered by AI

The Pumping Lemma provides a method to prove non-regularity by showing a contradiction arises when assuming a language is regular. It states that for any sufficiently long word in a regular language, the word can be split and pumped (repeatedly altered) in a manner that always returns a word in the language. When pumping introduces contradictions, it proves the language isn’t regular .

To show that L = {a^n : n is not prime} is not regular, we consider its complement L' = {a^n : n is prime}. Regular languages are closed under complementation, so if L' were regular, then L would be regular. Using the Pumping Lemma, we show that assuming L' is regular leads to a contradiction (factoring problems with primes and non-primes), thus L isn't regular by indirect proof .

The CFG with productions S → aSc | B, B → bBc | λ correctly generates L = {a^n b^m c^k : k = n+m} by iteratively pairing an 'a' with a 'c' and then a 'b' with a 'c' until the conditions are satisfied, thereby ensuring the count constraint on 'c' always matches the total of 'a' and 'b' produced .

L is non-regular because assuming regularity and applying the Pumping Lemma leads to logical contradictions. For a palindrome configuration like w = ww^R, pumping different parts of the word and attempting to maintain length equality and symmetry results in discrepancies, especially due to increased characters breaking the palindrome form .

L is not regular because its complement L' = {a^n b^l a^k : k = n+l} has to be shown as not regular. We assume L' is regular, leading to a contradiction via the pumping lemma: if a string in L' can be pumped, it must still satisfy the form k = n+l, which leads to logical inconsistencies, confirming L' is not regular .

L = {a^n b^l : n-l is a multiple of 3} is shown to be regular by devising a regular expression that covers all cases of modulus conditions (n ≡ l (mod 3)). The language can be expressed using regular expressions that represent repetitions mod 3, unioning these cases into a regular representation. Constructing such expressions without contradiction demonstrates the language's regularity .

L = {a^n b^m c^k : k ≠ n+m} is more complex as it entails all deviations and exceptions from a clean linear constraint and doesn't simplify into repeated or pattern-based regular structures. A CFG, differing from regex, captures infinite and exception rule-based generation, fundamentally organizing with auxiliary conditions for violation sequences .

Finite languages are regular by definition because they can be expressed by a finite enumerated list of strings or a small number of exact pattern repetitions. They do not need complex pumping structures as their finite nature makes them directly and simply matchable by a finite automaton .

L adheres to regular complexity constraints since it's finite and regular by virtue of encompassing a fixed size with specific defined constraints—namely n = l + 2—only having a limited, fixed number of strings meeting this pattern constructible by finite state means .

Closure under intersection and complementation can be used to argue a language's regularity by demonstrating that its decomposition (into known closure-preserved combinations) results in regular language structures. This is overridden by the Pumping Lemma's failure to preserve the necessary n to m ratio when altering sections, indicating non-regularity even under assumed closure transformations .

You might also like