# Defining the Hirota operator

The Hirota $D$-operator (derivative) is mathematically defined as follows:

$$D_x^n f\cdot g=\left.\frac{\partial^n}{\partial s ^n} f(x+s)g(x-s)\right|_{s=0}$$

An example of this operator acting on two functions $a(x)$ and $b(x)$ is the following:

$$D_x a(x)\cdot b(x) = a'(x)b(x)-a(x)b'(x)$$

I'm trying to make a Hirota $D$-operator function in Mathematica. What I've tried is the following

HirotaD[a[x_], b[x_], n_] :=
Module[{},
sol = D[a[x + y]*b[x - y], {y, n}] /. y -> 0 //

Print[("\!$$\*SubscriptBox[\(D$$, $$x$$]\)")^n, "=", sol]
];


This appears to work at first when I simply use arbitrary functions a[x] and b[z] as input functions:

HirotaD[a[x], b[x], 1]
(* ==> Subscript[D, x]=b(x)a'(x)-a(x) b'(x)  *)


However, it fails to output anything when I use any predefined functions.

f[x_]:=Sin[x];
g[x_]:=Cos[x];

(* ==> HirotaD[Sin[x], Cos[x], 1] *)


How do I make it work on predefined functions?

• Your definition only accepts the functions a and b, literally, with any argument, called x. Try a_[x_] etc. on the LHS of the definition. Jul 17, 2016 at 19:28
• @MariusLadegårdMeyer That was it! Jul 17, 2016 at 19:29
• @MariusLadegårdMeyer Hold on though, when I change it to a_[x_] it works with some simple predefined functions, but not with any functions which involve multiplication in it (weird...). For example, f[x_]=a[x]*b[x] doesn't work as a valid input function. Jul 17, 2016 at 19:33
• It's not weird: the pattern a_[x_] cannot possibly match a[x]*b[x], can it? It seems the two arguments should be general expressions, i.e. just a_, b_, see @Lucas's answer. Jul 17, 2016 at 21:38
• If you do SetAttributes[HirotaD, HoldAll], then define your function with a_[x_] and b_[x_] as suggested by @MariusLadegårdMeyer , it should work the way you're expecting. Jul 18, 2016 at 15:47

The following definition takes as arguments two pure functions, a and b, their argument x and the parameter n.

HirotaD[a_, b_, x_, n_] :=
Module[{},
sol = D[a[x + y]*b[x - y], {y, n}] /. y -> 0 // TraditionalForm;
Print[("\!$$\*SubscriptBox[\(D$$, $$x$$]\)")^n, "=", sol]];


It works on general functions, not yet defined.

HirotaD[a, b, x, 1]
(* Subscript[D, x]=b(x) a'(x)-a(x) b'(x) *)


On built in functions, like Sin and Cos

HirotaD[Sin, Cos, x, 1]
(* Subscript[D, x]=sin^2(x)+cos^2(x) *)


And on products of functions, but for more complicated uses, one has to define a pure function, as follows:

HirotaD[a[#] b[#] &, u, x, 1]
(* Subscript[D, x]=b(x) u(x) a'(x)+a(x) u(x) b'(x)-a(x) b(x) u'(x) *)


I thought I'd offer a definition that works more like Mathematica's D function:

HirotaD[a_, b_, x_, n_] := Module[{fa, fb, d, s}, (
fa = a /. (x -> (x + s));
fb = b /. (x -> (x - s));
d = D[fa fb, {s, n}];
d /. s -> 0 // Simplify
)]



Which you can call like

HirotaD[a[x], b[x], x] (* General Example *)
HirotaD[Sin[x], Cos[x], x] (* Should give 1 *)
HirotaD[Sin[y], Cos[y], x] (* df[y]/dx = 0, should give 0 *)
HirotaD[a[x], b[x], x, 2] (* Second order *)


which gives

$b(x) a'(x) - a(x) b'(x)$

$0$

$1$

$b(x) a''(x)-2 a'(x) b'(x)+a(x) b''(x)$

• Using the product rule: HirotaD[a_, b_, x_, n_:1] := Sum[(-1)^(n - k) Binomial[n, k] Derivative[k][Function[x, a]][x] Derivative[n - k][Function[x, b]][x], {k, 0, n}] Jul 18, 2016 at 0:23
• @J.M. Yup, kind of obvious when you see the form of the higher order derivatives. Jul 18, 2016 at 15:26