10

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?

camzor00
  • 101
  • 1
  • 3
  • 1
    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]]. – march Aug 11 '15 at 15:51

2 Answers2

19

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]]

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
6

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.

Jens
  • 97,245
  • 7
  • 213
  • 499
  • Is the ^ before the := a typo? – AccidentalFourierTransform May 23 '18 at 15:39
  • @AccidentalFourierTransform No, it's UpSetDelayed. – Jens May 23 '18 at 17:05
  • Oh, that's a new one for me, cool. Thanks! – AccidentalFourierTransform May 23 '18 at 17:14
  • 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 ? – Shamina Oct 03 '18 at 21:40
  • @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. – Jens Oct 04 '18 at 04:51
  • This solution is handy only if we have one function at hand: if we have another function g[x,y], we need to write the first 2 lines again replacing f[x,y,z] for g[x,y]. – IgnoranteX Nov 30 '20 at 10:12