We want to define a function of substitution (as a pure function) which can apply to a number or to a list. This desired function is as

/.{I -> -I, -I -> I}

However this work will do by Conjugate, but we do not want to use that.

For example: list={I, 2, b, I b, -I b};

list/.{I -> -I, -I -> I}={-I, 2, b, -I b, I b}; The desired format is F[list]={-I, 2, b, -I b, I b}; This procedure even should be apply just for a number as I/.{I -> -I, -I -> I}=-I. How can we write F? For instant: Map[/.{I -> -I, -I -> I}, list] or conj[# _] & = {I -> -I, -I -> I} /@ #; which are written too bad.

  • 2
    $\begingroup$ f = # /. {I -> -I, -I -> I} &; $\endgroup$
    – Bob Hanlon
    May 8 '17 at 15:52
  • $\begingroup$ Kindly expand upon the problems you experience with Conjugate and symbols. You will get more help if you make your question as clear as possible. You have some typos (./ needs to be /.) $\endgroup$ May 8 '17 at 18:23
  • $\begingroup$ Thank you for your comment, I corrected the typos. Some of my questions are related to Conjugate but I am hopeless to use that correctly. $\endgroup$ May 8 '17 at 18:42

Let me first point something important out before answering the question: I suspect that you want to "replace" Conjugate with an own function. However your approach as you presented it won't work. Just try 1+I/.I->-I and observe the output (this is because complex numbers are atomic quantities).

Anyways, here's how you can create such a function:

conjugate1[expr_] := expr /. x_Complex :> Conjugate[x];
conjugate2[expr_] := expr /. Complex[a_, b_] :> Complex[a, -b];

You may then just do what you wish:

Map[conjugate1, list]
Map[conjugate2, list]

all return {-I, 2, b, -I b, I b} as output which is of course the same as Conjugate[list] AS LONG AS b is real! I want to remind you to bear in mind that this will not give the proper Conjugateed result if any of the symbols can be complex.

  • $\begingroup$ In fact, I am sure that symbols are real. Unfortunately, Conjugate has some problems when we work with symbols. $\endgroup$ May 8 '17 at 17:53
  • $\begingroup$ @Irreversible If you are sure that all symbols are real you should be good to go with this approach. What are these "problems" you encounter when working with Conjugate? Check this (mathematica.stackexchange.com/a/118956/21606), maybe it helps a bit - if my suspicion about your issues is correct. $\endgroup$
    – Lukas
    May 9 '17 at 8:39

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .