6

Bug introduced after 12.0.1, in or before 12.3, persisting through 13.0. Fixed in 13.2.0 or earlier.


Consider the following sample:

{Re, Im}[u'[t]] // Through // ComplexExpand

In v9.0.1 u'[t] is assumed as real:

enter image description here

But at least since v12.3.1 the behavior changes:

enter image description here

Is this a bug or incompatible change?

Is there a simple way to bring back the old behavior? (This answer of mine is broken at the moment due to the change. )

AsukaMinato
  • 9,758
  • 1
  • 14
  • 40
xzczd
  • 65,995
  • 9
  • 163
  • 468

2 Answers2

6

Comments have identified this as a bug; in the meantime, a simple way to bring back the old behavior for ComplexExpand in a given session can be obtained by adding the following definition to ComplexExpand. This builds on Michael E2's (in)activation workaround; I noticed that it really is just the Derivative symbol itself that gives us grief, so we can restrict our inactivation to Derivative per se.

Unprotect[complexExpandIntercept, ComplexExpand];
complexExpandIntercept = True;
ComplexExpand[args___] := 
 Block[{complexExpandIntercept = False}, 
   Activate[
    ComplexExpand @@ Inactivate[{args}, Derivative], 
    Derivative]] /; complexExpandIntercept
Protect[complexExpandIntercept, ComplexExpand];
{Re, Im}[u'[t]] // Through // ComplexExpand

(* Out: {Derivative[1][u][t], 0} *)

Note: for a brief moment this answer was incorrect due to flipped booleans; now it should be fixed. :)

thorimur
  • 9,010
  • 18
  • 32
6

Here another workaround that may be safe (as it would likely affect only expressions containing u'):

ComplexExpand[Null]; (* autoload ComplexExpandDump *)
Block[{System`ComplexExpandDump`ConjugateFunctions = 
   Append[System`ComplexExpandDump`ConjugateFunctions, u']},
 ComplexExpand[{Re, Im}[u'[t]] // Through]]
(*  {u'[t], 0}  *)
Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • I think you mean ComplexExpand[u'[t] // Re] :) ? Then, it seems that we need to use ComplexExpand at least once before using the solution, otherwise System`ComplexExpandDump`ConjugateFunctions won't be loaded. – xzczd Jun 25 '22 at 02:01
  • @xzczd Thanks! (It turns out internally it complex-expands the real and imaginary parts of u'[t] anyway, so that at some point I dropped the Re and Im.) – Michael E2 Jun 25 '22 at 03:09