Here copy of the accepted answer given on the linked above MSE thread:
Here's how I go about doing this type of algebra with Mathematica:
eqn = D[u[x, t], t] + D[u[x, t], x] == 0;
First, expand the function u[x, t + dt]
to first order in dt
around 0
and the function u[x -h, t]
to first order in h
around 0
:
eqn1 = u[x, t + dt] == Series[u[x, t + dt], {dt, 0, 1}] // Normal
eqn2 = u[x - h, t] == Series[u[x - h, t], {h, 0, 1}] // Normal

We want to eliminate the partial derivatives, so we solve for them:
sols = First@Solve[{eqn1, eqn2}, {D[u[x, t], t], D[u[x, t], x]}]

Finally, we use the fact that the partial derivatives are negative each other because of the original differential equation to eliminate them from the equation:
differenceEquation = eqn /. sols

Finally, we solve for the next time step and collect terms on the right hand side
Collect[Equal @@ Solve[differenceEquation, u[x, dt + t]][[1, 1]], u[x, t]]

From there, you can read off a1
and a2
.