# How to obtain differential consequences of linear transport equation automatically?

Motivation

Here I've asked how to derive coefficients of numerical approximation of the linear transport equation $$u_t + u_x = 0, \tag{1}$$ on a fixed 3-point stencil automatically and here I've asked about automatical derivation on general m-point stencil as well.

In the present question I would like to ask about automatical way of derivation of the following differential consequences (DC) of (1): \begin{align} u_t &= -u_x, \\ u_{tx} &= -u_{xx}, \\ u_{tt} &= -u_{xt} = u_{xx}, \\ u_{txx} &= - u_{xxx}, \\ u_{ttt} &= -u_{xtt} = u_{xxt} = -u_{xxx}, \\ &\ldots \tag{2} \end{align}

I need DC (2), cause I need to consider the following approximation $$u_j^{n+1} = u_j^n - \tau\,u_x. \tag{3}$$

DC (2) are applied in expansion of $u_j^{n+1}$ around $(x_j,t^n)$ node as follows: \begin{align} & u_j^{n+1} = u_j^n + \tau\bigl(u_t\bigr)_j^n + \frac{\tau^2}{2!}\bigl(u_{tt}\bigr)_j^n + \frac{\tau^3}{3!}\bigl(u_{ttt}\bigr)_j^n + O(\tau^4) = \\ =\,& u_j^n - \tau\bigl(u_x\bigr)_j^n + \frac{\tau^2}{2!}\bigl(u_{xx}\bigr)_j^n - \frac{\tau^3}{3!}\bigl(u_{xxx}\bigr)_j^n + O(h^4). \tag{4} \end{align}

WM code

I've made the following semi-analytic solution.

    {
eq = D[u[x, t], t] + D[u[x, t], x] == 0,
eqdc01 = D[eq, t],
eqdc02 = D[eq, t, t],
eqdc03 = D[eq, x],
sol00 = Solve[eq, D[u[x, t], t]] // First,
sol01 = Solve[eqdc01, D[u[x, t], {x, 0}, {t, 2}]] // First,
sol02 = Solve[eqdc03, D[u[x, t], {x, 1}, {t, 1}]] // First,
sol03 = Solve[eqdc02, D[u[x, t], {x, 1}, {t, 2}]] // First,
sol04 = Solve[eqdc02, D[u[x, t], {x, 0}, {t, 3}]] // First,
sol05 = D[sol02, {t, 1}],
sol06 = D[sol00, {x, 2}],
sol07 = sol05 /. sol06,
sol08 = sol04 /. sol07
} // Column {
se01 = Series[u[x, t + \[Tau]], {\[Tau], 0, 3}] // Normal,
lhs = se01 /. sol00 /. sol01 /. sol02 /. sol08 // Normal,
rhs = Sum[
Subscript[a,
i] (Series[u[x + i h, t], {h, 0, 3}] // Normal), {i, -1, 2, 1}]
} // Column Question

The question is how to derive DC (2) automatically.

Here's a possibility that is relatively general.

Clear[diffCons]
diffCons[eq_Equal, level_Integer /; level == 0] := Reduce@eq
diffCons[eq_Equal, level_Integer /; level >= 1] :=
Reduce@Module[
{variables = DeleteDuplicates@Cases[eq, Derivative[__][_][x__] :> x, Infinity]}
, D[eq, Sequence @@ Transpose@{variables, #}] & /@ Select[Tuples[Reverse@Range[0, level], Length@variables], Plus @@ # == level &]
]


Given

eq = D[u[x, t], t] + D[u[x, t], x] == 0


we choose a level. Level 0 just spits back the equation, but Reduced:

diffCons[eq, 0]
(* {Derivative[0, 1][u][x, t] == -Derivative[1, 0][u][x, t]} *)


Level 1 means take all first derivatives of the equation:

diffCons[eq, 1]
(* Derivative[u][1, 1][x, t] == -Derivative[u][2, 0][x, t] && Derivative[u][0, 2][x, t] == -Derivative[u][2, 0][x, t] *)


And so on.

If you want Rules instead, use this modified version of the function:

Clear[diffConsRule]
diffConsRule[eq_Equal, level_Integer /; level == 0] := {Rule @@ Reduce@eq}
diffConsRule[eq_Equal, level_Integer /; level >= 1] :=
Rule@@@List@@Reduce@Module[
{variables = DeleteDuplicates@Cases[eq, Derivative[__][_][x__] :> x, Infinity]}
, D[eq, Sequence @@ Transpose@{variables, #}] & /@ Select[Tuples[Reverse@Range[0, level], Length@variables], Plus @@ # == level &]
]


In this case,

diffConsRule[eq, 0]
(* {Derivative[0, 1][u][x, t] -> -Derivative[1, 0][u][x, t]} *)


and

diffConsRule[eq, 1]
(* {Derivative[u][1, 1][x, t] -> -Derivative[u][2, 0][x, t], Derivative[u][0, 2][x, t] -> Derivative[u][2, 0][x, t]} *)


The function diffCons is not tested too well, but is should work for a general partial differential equation of any number of variables.

• Thank's a lot. I suppose, that is an aswer on my question and it will take some time to understand such an elegant code from my side. – Oleg Kravchenko Dec 1 '15 at 7:19
• @olekravchenko. In my opinion, the code is brute-forced and not very elegant at all, but thanks anyway. :) – march Dec 1 '15 at 7:20
• Bye the way, how could I use notification on a previous commenter? In my case '@march' disapear everytime. – Oleg Kravchenko Dec 1 '15 at 7:22
• @olekravchenko. If you are commenting below a question or answer, the person who wrote that question or answer is automatically notified, so you don't need too use the @ unless you are trying to talk to someone who is not the author of the question/answer you are commenting on. – march Dec 1 '15 at 7:24
• Anyway, I wasn't able to use @ couple of times ago. I could put '@march' in the end of my reply only. – Oleg Kravchenko Dec 1 '15 at 7:26