4
$\begingroup$

I have a complicated complex expression that can Mathematica can't simplify using neither FullSimplify, Simplify nor Refine.

I tried something very naive

myConjugate[expr_] := expr /. {a_ I :> - a I}
expr = I (a + 0.5123 I b - 1.2332 I c);
myConjugate[expr]
Refine[Conjugate[expr], Element[{a, b, c}, Reals]]
% - %% // Simplify

which should give 0, but doesn't.

So my question becomes,

how can I flip the signs of all Is in an expression? The faster the better.

$\endgroup$

1 Answer 1

9
$\begingroup$

Replace acts on the full form of an expression, not the displayed form. The full form of your expression:

expr = I (a + 0.5123 I b - 1.2332 I c); expr // FullForm

enter image description here

Therefore a complex number is represented by: Complex[..,..]. Therefore to make your "myConjugate" work you need to write:

myConjugate[expr_] := expr /. { Complex[x_, y_] -> Complex[x, -y]}
expr = I (a + 0.5123 I b - 1.2332 I c);
myConjugate[expr]
Refine[Conjugate[expr], Element[{a, b, c}, Reals]]
% - %% // Simplify

(* 0 *)

$\endgroup$
0

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