4

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" /. 
    SystemOptions["DifferentiationOptions"])
SetSystemOptions[
 "DifferentiationOptions" -> 
  "ExcludedFunctions" -> Union[excluded, {Conjugate}]]

I got the error

  General::ivar: 1 is not a valid variable.
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Chipa-Chipa
  • 167
  • 5

3 Answers3

1

Update

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


Old

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

  • 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]]]'? – Chipa-Chipa Dec 12 '18 at 08:24
  • @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. – Αλέξανδρος Ζεγγ Dec 12 '18 at 08:27
  • Do you mean that I should make the replacement only when I define the derivative? – Chipa-Chipa Dec 12 '18 at 08:31
  • @Chipa-Chipa I mean to obtain the explicit expression of the function, before you put it into its derivative calculation. – Αλέξανδρος Ζεγγ Dec 12 '18 at 08:33
  • 1
    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] – Michael E2 Jan 11 '19 at 19:54
  • @MichaelE2 Great! Thx for your comment! – Αλέξανδρος Ζεγγ Jan 12 '19 at 06:37
0

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

ClearAll[h];
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?)

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

One could also do something like this:

ClearAll[h];
h[x_, y_] := 
 Derivative[0, 1][
   Block[{xx, yy}, 
    Function[{xx, yy}, 
     Evaluate@ComplexExpand[f[xx, yy]\[Conjugate]/g[xx, yy]]]]][x, y];
Michael E2
  • 235,386
  • 17
  • 334
  • 747
0

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*)
Bill Watts
  • 8,217
  • 1
  • 11
  • 28