-2

I found the following problem in a past exam: Construct a PDA with void stack acceptance and a CF grammar for the language:

L={w| w={a,b}* such that 2* (number of "a"-s in w) != 3* (number of "b"-s in w) +2 }

Assume that w = {a, b}* with that property. I've tried to construct PDA for equality between the left-hand side and the right-hand side and I think I got it right, but I don't know how to do it for inequality. As for the CF grammar, I find it a bit trickier. Can someone help me?

1 Answers1

0

An inequality (a≠b) is usually best thought of as the disjunction of two strict comparisons (a>b ∨ b>a). If you know how to do a=b, a>b is usually very straightforward; all you need to do is introduce more a.

As a trivial example, {aibj | i=j} is easy:

S→aSb | ε

{aibj | i≠j} is not so obvious, but {aibj | i>j} is just

S→aSb | aS | a

And {aibj | j>i} is very similar, so we can put the two together like this:

S→A | B
A→aAb | aA | a
B→aBb | Bb | b

Alternatively,

S→aSb | A | B
A→Aa | a
B→Bb | b

Exam problems can't be so trivial, I suppose, but that one will easily yield to the same kind of analysis.

rici
  • 234,347
  • 28
  • 237
  • 341