# Constructing PDA to accept language { $a^i b^j c^k \mid i,j,k \geq0, i+2k = j$ }

I'm trying to understand the approach to constructing a PDA which accepts the language { $a^i b^j c^k \mid i,j,k \geq0, i+2k = j$ }

• Are you able to write automatons for just $\{ a^i b^j c^k \mid i,j,k \geq0, i+2k = j \}$ and just $a^3b^7c^2$? – Karolis Juodelė Mar 6 '13 at 15:20
• Your question is weird. For constructing a PDA you need no instance of a string, just the whole language. So if you want to be understood you should ask two questions: (a) how do I construct a PDA for $\lbrace a^i b^j c^k \mid i, j, k \geq 0, i + 2 k = j\rbrace$, and (b) how does the PDA work to accept the string $a^3 b^7 c^2$? – Andrej Bauer Mar 6 '13 at 15:21
• Notice that $a^ib^jc^k=a^ib^{i+2k}c^k=a^ib^ib^{2k}c^k=$. – mrk Mar 6 '13 at 15:21
• @AndrejBauer I think he means crafting the PDA and matching the string. I might be wrong. – mrk Mar 6 '13 at 15:24
• Carelessly didn't realized it was part of the language, so i fixed it to one question, but yeah Andrej, that's exactly what I meant – Iancovici Mar 6 '13 at 15:26

Your language is equivalent to the language $a^ib^ib^{2k}c^k$, and since concatenation is associative, this is equivalent to $(a^ib^i)(b^{2k}c^k)$.

A PDA for the first of these parts pushes an $a$ for each $a$ it sees and pops an $a$ when it sees a $b$. If the topmost stack symbol after this is $Z_0$, transition to the second PDA, which pushes a $b$ for every two $b$s it sees and then pops a $b$ for every $c$ it sees, accepting if, after this, you end up with no input and $Z_0$ as the topmost symbol.

• what about PDA for $a^ib^jc^k \mid i + j =k$ how can you count a's and b's and execute c's enough so it is accepted. must the stack be empty for the pda to accept the language? One grammar for that could be $A \rightarrow aAc \mid B \mid \epsilon,$ $B \rightarrow bBc \mid \epsilon$ – Iancovici Mar 12 '13 at 18:52
• @echadromani 1. Add an $a$ to the stack for every $a$ you read. 2. Add a $b$ to the stack for every $b$ you read. 3. Remove the top stack symbol for each $c$ you read. 4. Accept if the stack is empty and you have no more input. Reject if you crash or run out of input without emptying the stack. – Patrick87 Mar 12 '13 at 19:36
• 1 how exactly do you accept if the stack is empty, 2 and remove the top stack symbol for each c? $c, a/\epsilon$ $c, b/\epsilon$? – Iancovici Mar 12 '13 at 19:46
• @echadromani 1 If the topmost stack symbol is the special bottom-of-stack symbol (I've usually seen this represented as $Z_0$), transition to a new state. Any subsequent input either crashes or takes you to a dead state. Only if the input stops there do you accept. 2. Yes, you have the two transitions you mention. – Patrick87 Mar 12 '13 at 20:00
• I'm new to the PDA, at the state in which those two transitions are available, do we assume it won't try to perform $c, a/ \epsilon$ while $b$ is at the top of the stack? – Iancovici Mar 13 '13 at 11:25

Hint: The PDA has three phases: an $a$ phase, a $b$ phase and a $c$ phase. Your goal in the $a$ phase is to "compute" $i$ by strong an appropriate load on the stack. Your goal in the $b$ phase is to compute $j-i$. Finally, your goal in the $c$ phase is to compare $j-i$ to $2k$.

Hint: find a PDA for the language $\{a^kb^k:k\ge 0\}$ and apply it twice.

The other approach is to find a grammar for the language and convert it to an equivalent PDA. Here is the grammar version:

$S \to AB \mid \epsilon$

$A \to aAb \mid ab$

$B \to bbBc \mid bbc$

I think the best solution would be to form the CFG first and convert it to the equivalent PDA. the CFG can be constructed as follows: there are 2 cases:
1> an a for a b
2> a c for 2 b's

so when you add up, you make it equalized.

i.e.,
S -> AB
A -> aAb / epsilon
B -> bbBc / epsilon