# Choice of conjugate momentum for Ostrogradsky instability

I was reading this post and I don't understand why chosing: $$Q_1=q\$$ and $$\ Q_2=\dot{q}$$ implies that $$P_1=\dfrac{\partial L}{\partial \dot{q}}-\dfrac{\mathrm{d}}{\mathrm{d}t}\dfrac{\partial L}{\partial \ddot{q}}\qquad \text{ and }\qquad P_2=\dfrac{\partial L}{\partial \ddot{q}}.$$

Naively, I would have choosen $$P_1=\dfrac{\partial L}{\partial \dot{Q_1}}=\dfrac{\partial L}{\partial \dot{q}}\qquad \text{ and }\qquad P_2=\dfrac{\partial L}{\partial \dot{Q_2}}=\dfrac{\partial L}{\partial \ddot{q}}$$ but it's apparently wrong.

What did I miss?

1. Since the Legendre transformation should be $$L+H ~=~P_1\dot{Q}_1+ P_2\dot{Q}_2 ,\tag{1}$$ then $$\frac{\partial (L+H)}{\partial Q_1}~=~0. \tag{2}$$
2. Now the higher Lagrange equation reads $$\frac{\partial L}{\partial Q_1} - \frac{d}{dt} \frac{\partial L}{\partial \dot{Q}_1} + \frac{d^2}{dt^2} \frac{\partial L}{\partial \dot{Q}_2} = 0,\tag{3}$$ and we would like the Hamilton's equation $$\frac{\partial H}{\partial Q_1}~=~-\dot{P}_1.\tag{4}$$
3. Comparing (2)+(3)+(4), we conclude that we should choose $$P_1 ~=~\frac{\partial L}{\partial \dot{Q}_1} -\frac{d}{dt} \frac{\partial L}{\partial \dot{Q}_2}. \tag{5}$$