You are on page 1of 5

CS321: Homework #6

Zachary Comito
November 18, 2017

1
1.1
We choose a string s, which is p 1s, followed by 0, followed by p 1s, followed by c, followed by p + 1
1s, followed by p 0s. So |s| = 4p + 3 p:

| {z } c 1111...111
{z } 0111...111
s = |111...111 | {z } 000...000
| {z }
p p+1 p+1 p

Name the above partitioning as regions 1 through 5 (r1 , r2 , r3 , r4 , r5 ). Then we consider all
possible cases for the string vwx (and, more specifically, v ... x):

Case 1: vwx contains only characters from the first three regions. If v ... x contains the third region
at all (the c), then we win, since any i > 1 will cause the resulting string to have more than
one c, and thus not be in the language.
If not, then i > 1 still ensures a win since we can use i to make the first two regions represent
an arbitrarily large number (in binary), violating the bin(r1 r2 ) + 1 = bin(r4 r5 ) part of the
language.
Case 2: vwx contains characters from regions 2, 3, and 4 (and thus not regions 1 or 5, since |vwx| p).
If v ... x contains the third region at all (the c), then we win, by the same logic as above.
If not, then v ... x could contain only characters from region 2 or from region 4. In either
case, we simply choose i > 1 to make the corresponding binary number arbitrarily large and
we win.
The only possibility left, then, is that v has characters from region 2 only and x has characters
from region 4 only. In this case, we can still win by choosing i > 1 because pumping up region
2 would have to pump up the number of trailing 0s (region 5) due to the carrying that occurs
during the addition of 1 (bin(r1 r2 ) + 1). So the adversary has no way to make up for this by
also forcing us to pump region 4, since regions 4 and 5 do not overlap.
Case 3: vwx contains only characters from the last three regions. The strategy is symmetric/identical
with the strategy for case 1, we are just pumping up bin(r4 r5 ) instead.

There are no other cases due to the |vwx| p restriction.

1.2
We choose a starting s, which is p as, followed by p bs, followed by p2 cs. So |s| = p2 + 2p p:

s = aa...aa
| {z } bb...bb
| {z } cccc...cccc
| {z }
p p p2

Name the above partitioning as regions 1, 2, and 3 (p1 , r2 , r3 ). Then we consider all possible
cases for the string vwx (and, more specifically, v ... x):

Case 1: vwx inhabits only one of the three regions. We can trivially break the equality k = mn by
choosing any i > 1.

1
Case 2: v ... x contains characters from regions 1 and 2 (and thus none from region 3, since |vwx| p).
We choose some i > 1, so mn increases. k is untouched (since region 3 is untouched), so it
can no longer be true that k = mn.
Case 3: v ... x contains characters from regions 2 and 3 (and thus none from region 1, since |vwx| p).
Setting i = 0 shortens region 2 by |v| and region 3 by |x|. The original value of mn was
of course p p = p2 , so now that m is m |v| = p |v|, we have the new mn equal to
(p |v|)p = p2 p|v|. k was originally p2 , and is now p2 |x|.
In order to be a member of the language, k = mn must hold, viz. p2 |x| = p2 p|v|
must hold. Subtracting p2 from both sides and then multiplying both sides by (1) gives
|x| = p|v|. |v| and |x| must both be strictly greater than zero, otherwise this would fall under
case 1 above. We also know that |v| + |x| p due to |vwx| p. Rearranging this inequality
gives |x| p |v|. Substituting the previous equation gives p|v| p |v|. Since both p and
|v| are positive integers, this is a contradiction1 , therefore the string resulting from i = 0 is
not in the language.

There are no other cases due to the |vwx| p restriction.

2
2.1
First we add a new leading start state:

S S
S Sa | Sb | T
T aT a | bT b | cU
U aU | bU |

Then decompose all right-hand-side alternatives that have more than two components:

S S
S Sa | Sb | T
T aV | bW | cU
U aU | bU |
V T a
W T b

Clean up right-hand-side alternatives that have both a terminal and a non-terminal:

S S
S SA | SB | T
T AV | BW | CU
U AU | BU |
V T A
W T B
A a
B b
C c

Eliminate usage of empty string:


1 You can see this by considering that p |v| is at most p 1, whereas p|v| is at least p. So the best case

scenario is p p 1, which is still false.

2
S S
S SA | SB | T
T AV | BW | CU | C
U AU | BU | A | B
V T A
W T B
A a
B b
C c

Clean up lonely non-terminals, and the grammar is now in CNF:

S SA | SB | AV | BW | CU | c
S SA | SB | AV | BW | CU | c
T AV | BW | CU | c
U AU | BU | a | b
V T A
W T B
A a
B b
C c

2.2
The following diagram represents the transition function () of the PDA called M :

M := (Q, , , , S, F ),
where

Q := {, , U ?, T1 ?, T2 ?, T3 ?, S?, S!}
|Q| = 8
:= {a, b, c}
:= {], U, U1+2 , T, T1 , T2 , T3 , S}
|| = 8
S :=
F := S!

3
S? S!
(, ], )

(c, , )

(b, , T2 )

T1 ? T2 ?
(, S, ) (c, , )
(a, , T1 )
(a, , T1 )
(a + b, , ) (b, , T2 )
(a, , T1 ) (b, , T2 )

U? (a + b, , U1+2 ) T3 ?

(c, , T3 )
(, U1+2 , U ) (a, T1 , T )
(, T, S)
(b, T2 , T ) (, T3 , T )
(a + b, S, S)
(, ], U ]) (a, T1 , T )
(b, T2 , T )
(, , ])

(, , )

Note: In the above PDA diagram, the clustered transition tuples (, U1+2 , U ), (a, T1 , T ),
(b, T2 , T ), and (, T3 , T ) are all intended to be possible transitions that go from U ? . Also,
a + b is just the character a or the character b.

3
The set of all non-palindromes is context-free because it can be recognized be the following PDA:

(, , ]) (a, a, )

1
(, , )
(a, , a) 2
== (b, b, )

(b, , b)
(a, b, )

(b, a, )

(a + b, a + b, ) != $
(, ], )

4
This PDA is like a PDA that reads characters and puts them on the stack, then epsilon-
transitioning into a second phase in which the characters read from the input are popped off the
stack. This allows the recognition of strings which are palindromes, since reading a character
that is not on the top of the stack causes the control flow to fall off in the second phase, and
reading too few characters in the second phase disallows the final transition, which requires the
bottom-of-stack character (]) to be at the top of the stack (i.e. the stack is effectively empty).
This PDA is different in that it requires a transition that would normally cause falling off
during the second stage to occur for the control flow to get to the final state at all. Otherwise
the logic is essentially the same. Once such a transition is made, we can freely pop off (arbitrary)
characters from the stack as more (arbitrary) characters are read, just to ensure that we indeed
have the same number of characters in the first half as in the second half, i.e. to ensure that
the (, , ) transition was made at the right point in the input.

You might also like