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 //
TraditionalForm;
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[f[x],g[x],1]
(* ==> HirotaD[Sin[x], Cos[x], 1] *)
How do I make it work on predefined functions?
a
andb
, literally, with any argument, calledx
. Trya_[x_]
etc. on the LHS of the definition. $\endgroup$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. $\endgroup$a_[x_]
cannot possibly matcha[x]*b[x]
, can it? It seems the two arguments should be general expressions, i.e. justa_
,b_
, see @Lucas's answer. $\endgroup$SetAttributes[HirotaD, HoldAll]
, then define your function witha_[x_]
andb_[x_]
as suggested by @MariusLadegårdMeyer , it should work the way you're expecting. $\endgroup$