10
$\begingroup$

I have a problem with Mathematica, taking the derivative of the conjugate of some function. I know that a similar question has been posed before here, but the solution did not work for multivariate function.

Problem is: I try to evaluate

D[Conjugate[f[x, y, z]], x]

And get the result

Conjugate'[f[x, y, z]] f^(1, 0, 0)[x, y, z]

But would like

Conjugate[f^(1, 0, 0)[x, y, z]]

where ^ is supposed to be superscript. Can anyone help me resolve this?

$\endgroup$
1
  • 1
    $\begingroup$ MapAt[D[#, x] &, Conjugate[f[x, y, z]], 1] or Map[D[#, x] &, Conjugate[f[x, y, z]]] or D[#, x] & /@ Conjugate[f[x, y, z]]. $\endgroup$
    – march
    Commented Aug 11, 2015 at 15:51

2 Answers 2

19
$\begingroup$

There are System options one can set to control the behavior of D. One of these is the "ExcludedFunctions" option:

excluded="ExcludedFunctions"/.
    ("DifferentiationOptions"/.SystemOptions["DifferentiationOptions"])

{Hold,HoldComplete,Less,LessEqual,Greater,GreaterEqual,Inequality,Unequal,Nand,Nor,Xor,Not,Element,Exists,ForAll,Implies,Positive,Negative,NonPositive,NonNegative,Replace,ReplaceAll,ReplaceRepeated}

These are functions that D will not differentiate. We can add Conjugate to this list by using:

SetSystemOptions["DifferentiationOptions"->
    "ExcludedFunctions"->Union[excluded,{Conjugate}]]

DifferentiationOptions->{AlwaysThreadGradients->False,DifferentiateHeads->True,DifferentiateIteratorIndexed->True,DirectHighDerivatives->True,DirectHighDerivativeThreshold->10,ExcludedFunctions->{Conjugate,Element,Exists,ForAll,Greater,GreaterEqual,Hold,HoldComplete,Implies,Inequality,Less,LessEqual,Nand,Negative,NonNegative,NonPositive,Nor,Not,Positive,Replace,ReplaceAll,ReplaceRepeated,Unequal,Xor},ExitOnFailure->False,HighDerivativeMaxTerms->1000,SymbolicAutomaticDifferentiation->False}

Now, D will not try to differentiate Conjugate:

D[Conjugate[f[x]], x]//InputForm

D[Conjugate[f[x]], x]

We are now free to give D rules for differentiating Conjugate:

Unprotect[Conjugate];
Conjugate /: D[Conjugate[f_], x__] := Conjugate[D[f, x]]
Protect[Conjugate];

Let's see what happens to the OP example now:

D[Conjugate[f[x, y, z]], x]

Conjugate[Derivative[1][f][x]]

$\endgroup$
6
$\begingroup$

I think what you want is something like this:

Conjugate[f[x_, y_, z_]] ^:= cf[x, y, z]

Derivative[d__][cf][x__] := Conjugate[Derivative[d][f][x]]

D[Conjugate[f[x, y, z]], x]

Conjugate[Derivative[1, 0, 0][f][x, y, z]]

All I did here is to define the derivative of the function f to be another function cf which then can be given the property you want.

$\endgroup$
6
  • $\begingroup$ Is the ^ before the := a typo? $\endgroup$ Commented May 23, 2018 at 15:39
  • $\begingroup$ @AccidentalFourierTransform No, it's UpSetDelayed. $\endgroup$
    – Jens
    Commented May 23, 2018 at 17:05
  • $\begingroup$ Oh, that's a new one for me, cool. Thanks! $\endgroup$ Commented May 23, 2018 at 17:14
  • $\begingroup$ Just a last question, as this is going to be very helpful for me. If we take cf[x,y,z] =-E^(-2 I x) + 2 E^(-I y - I z) + 2 E^(-3 I z - I x) + 12 E^(-2 I y - 2 I x). It doesn't work. I'm sure I'm missing something ? $\endgroup$
    – Shamina
    Commented Oct 3, 2018 at 21:40
  • $\begingroup$ @Shamina cf is supposed to remain purely symbolic. I don't understand what you're trying to do with the = assignment. Even if you change that to cf[x_,y_,z_] := ... it wouldn't correspond to what this question was originally about. You may have to ask a new question. $\endgroup$
    – Jens
    Commented Oct 4, 2018 at 4:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.