I have to take the partial differentiation of an unknown function. For example, take the unknown function to be $g(x)$. Then it's derivative w.r.t $x$ is $g'(x)$.
By default, Mathematica differentiates the function. I want to keep the result of differentiation as $d(g(x))$ and not $g'(x)$. Is there any way to achieve this?
More precisely, I am using Conjugate[g[x]]
as the unknown function and I want the output should be displayed only as d[Conjugate[g[x]]
and not as Conjugate'[x]g'[x]
.
Also, can I handle the conjugate more efficiently than just carrying it all along in the code?
Answer
Edited because the goal was changed in the comment:
This can be done by directly defining the outcome of Derivative
when applied to g
in the two combinations that you seem to be interested in:
Derivative[1][g][x_] := d[g[x]]
Derivative[1][Conjugate][g[x_]] := Conjugate[d[g[x]]]/d[g[x]];
Derivative[1][Conjugate][d[x_]] := Conjugate[d[d[x]]]/d[d[x]]
Derivative[1][d][x_] := d[d[x]]/d[x];
Derivative[1][d][x_Symbol] := d[d[x]]
On the second line, I used the fact that g
is a generic function whose derivative under a Conjugate
by default invokes the chain rule. All I do then is to reverse the chain rule by dividing by the factor d[g[x]]
that the chain rule will produce. This leaves only the factor I want, and I then replace that by the desired outcome d[Conjugate[g[x]]]
.
The analogous thing is done for d
to allow higher derivatives. The exception is when d[x]
is encountered where x
is the differentiation variable (which isn't in the question, but I expect may happen). Then there is no chain rule needed, and I therefore specify a separate rule for it with the pattern x_Symbol
.
Here is the test:
D[g[x], x]
(* ==> d[g[x]] *)
D[Conjugate[g[x]], x]
(* ==> d[Conjugate[g[x]]] *)
D[g[x], x, x]
(* ==> d[d[g[x]]] *)
D[d[g[x]], x]
(* ==> d[d[g[x]]] *)
D[d[x], x]
(* ==> d[d[x]] *)
D[Conjugate[g[x]], x]
(* ==> Conjugate[d[g[x]]] *)
D[Conjugate[g[x]], x, x]
(* ==> Conjugate[d[d[g[x]]]] *)
Now the remaining issue is to replace the repeated application of d
by formatting of the type d^2 g[x]
for d[d[g[x]]]
. I'll wait to see if this is really desired before doing it.
Comments
Post a Comment