I have some problem with the derivative of the 'conjugate' expression: Here I define the functions:

f[x_, y_] := x + I y;
g[x_, y_] := x + 3 I y y;
h[x_, y_] := Derivative[0, 1][f[#, #2]\[Conjugate]/g[#, #2] &][x, y]

When I try to evaluate one of the expression, for example

h[1, 1]

I got something like

Derivative[1][Conjugate][1 + I]

which is not true. If I try the code suggested in Derivative of conjugate multivariate function

 excluded = 
 "ExcludedFunctions" /. ("DifferentiationOptions" /. 
 "DifferentiationOptions" -> 
  "ExcludedFunctions" -> Union[excluded, {Conjugate}]]

I got the error

  General::ivar: 1 is not a valid variable.
  • 1
    $\begingroup$ I usually DIY my own "conjugate" by an explicit replacement rule. $\endgroup$ Dec 12, 2018 at 7:32
  • $\begingroup$ Could you please show this on the example written above $\endgroup$ Dec 12, 2018 at 7:41
  • $\begingroup$ I decided so because I think it not good enough to be posted. $\endgroup$ Dec 12, 2018 at 8:50
  • $\begingroup$ Well, I hope it helps. $\endgroup$ Dec 12, 2018 at 8:55

3 Answers 3



I am sorry, the old answer does not work, but it seems that the rule cannot be applied to pure functions.

A working way is, provided that all symbols are deemed real, which is what ComplexExpand does:

f[x_, y_] = ComplexExpand[ (*Expressions containing Conjugate*) ];
h[x_, y_] := Derivative[0, 1][f[#, #2]/g[#, #2] &][x, y]

h[x, y]
h[1, 1]
-((6 I (x - I y) y)/(x + 3 I y^2)^2) - I/(x + 3 I y^2)

-(9/50) + (37 I)/50


It is long since I made the observation that Mathematica seems not to know what to do when Conjugate meets D.

  • $\begingroup$ thx. I have already noticed that your first suggested example gives the wrong answer. Will your second example decrease the calculation rate? I have a very large amount of functions and need to do rather complex calculations. Is it possible not to replace all the functions like 'f[x,y][Conjugate]' by 'Evaluate[ComplexExpand[f[x, y][Conjugate]]]'? $\endgroup$ Dec 12, 2018 at 8:24
  • $\begingroup$ @Chipa-Chipa Then I suggest that you do not use a pure function in the middle of Derivative, but use the explicit form of the function you want to go further. $\endgroup$ Dec 12, 2018 at 8:27
  • $\begingroup$ Do you mean that I should make the replacement only when I define the derivative? $\endgroup$ Dec 12, 2018 at 8:31
  • $\begingroup$ @Chipa-Chipa I mean to obtain the explicit expression of the function, before you put it into its derivative calculation. $\endgroup$ Dec 12, 2018 at 8:33
  • 1
    $\begingroup$ I think the problem with your original way was a misplaced Evaluate. Try myConjugate = # /. {I -> -I, -I -> I} &; h[x_, y_] := Derivative[0, 1][Evaluate[myConjugate[f[#, #2]]/g[#, #2]] &][x, y] $\endgroup$
    – Michael E2
    Jan 11, 2019 at 19:54

Another workaround. Looks like the Derivative format doesn't like conjugate, but this seems to work:

f[x_, y_] := x + I y;
g[x_, y_] := x + 3 I y y;

h[x_, y_] := D[Conjugate[f[x, yy]]/g[x, yy], yy] /. yy -> y

h[1, 1] // ComplexExpand
(*-(9/50) + (37 I)/50*)
  • $\begingroup$ Hi, this code failed in v13. $\endgroup$
    – lotus2019
    Jun 21, 2023 at 3:36
  • $\begingroup$ @lotus2019 Are you sure? $\endgroup$
    – Bill Watts
    Jun 23, 2023 at 6:17
  • $\begingroup$ Yes. In v13.0, the result is 3/25 + 1/10 Im[Derivative[1][Conjugate][1]] + I (21/25 - 3/10 Im[Derivative[1][Conjugate][1]] - 1/10 Re[Derivative[1][Conjugate][1]]) - 3/10 Re[Derivative[1][Conjugate][1]] $\endgroup$
    – lotus2019
    Jun 23, 2023 at 11:50
  • $\begingroup$ @lotus2019 I don't have v13.0, but in v13.2.1, the output is as I have it. $\endgroup$
    – Bill Watts
    Jun 23, 2023 at 20:16
  • $\begingroup$ OK, it seems that I need to upgrade the version. Thank you for your reply. $\endgroup$
    – lotus2019
    Jun 24, 2023 at 0:03

Here are three similar ways. The first seems best (simplest) to me:

Block[{x, y},
 h[x_, y_] = D[ComplexExpand[f[x, y]\[Conjugate]/g[x, y]], y];

h[x, y] // Simplify
(*  -((I (x + 6 x y - 3 I y^2))/(x + 3 I y^2)^2)  *)

The following one generates message every time h[x, y] is evaluated, but it seems to give the correct answer. The reason for the messages is interesting. It implies a potential pitfall in using ComplexExpand: It appears the internal code for ComplexExpand[] creates a function with & using its arguments. The Slot[] expressions in f[#, #2] and g[#, #2] get caught up in this and lead to error messages; but the internal code seems to recover in this case. (Perhaps it should be considered a bug?)

h[x_, y_] := Derivative[0, 1][Evaluate@ComplexExpand[f[#, #2]\[Conjugate]/g[#, #2]] &][x, y]

One could also do something like this:

h[x_, y_] := 
 Derivative[0, 1][
   Block[{xx, yy}, 
    Function[{xx, yy}, 
     Evaluate@ComplexExpand[f[xx, yy]\[Conjugate]/g[xx, yy]]]]][x, y];

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.