When a weak acid is very dilute, it is necessary to take into account the autoionization of water. We are going to write the two equilibria that take place in solution:

$H_2O + H_2O \rightleftharpoons H_3O^+ + OH^-$

                               x             x

$HA +H_2O\rightleftharpoons H_3O^+ + A^-$

M-y                        y              y

Both M, x and y are expressed in molarity. It must be taken into account that the concentration of protons in the medium is given by x+y.

We write the equilibrium constants:

\begin{equation}K_w=[H_3O^+][OH^-]=(x+y)x\end{equation}

\begin{equation}K_a=\frac{[H_3O^+][A^-]}{[AH]}=\frac{(x+y)y}{My}\end{equation}

Solving x from the equation of $K_a$:

\begin{equation}x=\frac{K_a(My)}{y}-y\end{equation}

\begin{equation}x+y=\frac{K_a(My)}{(MY)}\end{equation}

Replacing these values in the $K_w$:

\begin{equation}K_w=10^{14}=\frac{K_a(My)}{y}\cdot\left[\frac{K_a(My)}{y}-y\right]\end{equation}

The value of y is obtained by solving the equation by the method of successive approximations.

Once y is obtained, its value is replaced in the equation of x. The sum x+y gives us the $[H_3O^+]$ and therefore the pH of the dilute weak acid solution.