Use
NonCommutativeMultiply to represent composition in an algebra of differential operators.
The base case, where

is a function, simply multiplies by

:
The next two properties express linearity:
Here the operator is
D.
HoldPattern stops the derivative from acting on the double blank:
Composition of operators applied to an expression:
Power of an operator applied to an expression:
Apply these rules to derive the KdV equation for the Lax pair:
Build a function to expand non-commutative products. Distributivity with respect to
Plus:
Handling the commutative product inside the non-commutative one:
Fall-back operation applied to everything else: