Construct Pushdown Automaton that accepts language $x\in\{a,b\}^*, a=2b$
GPDA$\to$PDA Approach

See you have got a solution from chat. But the first thing popped my mind is a Generalized_pushdown_automaton(GPDA), which can be constructed pretty straight forward. 

GPDA construction

$M=(Q,\Sigma,\Gamma,\delta,q_0,Z,\{q_f\})$, where $Q=\{q_0,q_f\},\Sigma=\{a,b\},\Gamma=\{a,A,Z\}$,$\delta$ includes following rules:


$(q_0,a,Z)\to(q_0,aZ)$
$(q_0,b,Z)\to(q_0,AAZ)$
$(q_0,a,a)\to(q_0,aa)$
$(q_0,b,A)\to(q_0,AAA)$
$(q_0,a,A)\to(q_0,\epsilon)$
$(q_0,b,aa)\to(q_0,\epsilon)$
$(q_0,b,aZ)\to(q_0,AZ)$
$(q_0,\epsilon,Z)\to(q_f,\epsilon)$


GPDA$\to$PDA convertion

Using the algorithm provided on Wikipedia, we can convert it to PDA easily. Only 6. and 7. need to convert:

6.1 $(q_0,b,a)\to(p_0,\epsilon)$

6.2 $(p_0,\epsilon,a)\to(q_0,\epsilon)$

7.2 $(p_0,\epsilon,Z)\to(q_0,AZ)$

Resulting PDA is $M=(Q',\Sigma,\Gamma,\delta',q_0,Z,\{q_f\})$ where $Q'=\{q_0,p_0,q_f\}$ and $\delta'=(\delta\setminus\{6,7\})\cup\{6.1,6.2,7.2\}$. The constructed PDA is non-deterministic.

Convert to DPDA

To convert to DPDA, the only affected transitions are 1. 2. and 8 in above rules:

$M=(Q,\Sigma,\Gamma,\delta,q_0,Z,\{q_f\})$, where $Q=\{q_0,p_0,q_f\},\Sigma=\{a,b\},\Gamma=\{a,A,Z\}$,$\delta$ includes following rules:


$\mathbf{(q_0,\epsilon,Z)\to(q_f,Z)}$
$(q_0,a,a)\to(q_0,aa)$
$(q_0,b,A)\to(q_0,AAA)$
$(q_0,a,A)\to(q_0,\epsilon)$
$(q_0,b,a)\to(p_0,\epsilon)$
$(p_0,\epsilon,a)\to(q_0,\epsilon)$
$(p_0,\epsilon,Z)\to(q_0,AZ)$
$\mathbf{(q_f,a,Z)\to(q_0,aZ)}$
$\mathbf{(q_f,b,Z)\to(q_0,AAZ)}$