# Define the substitution procedure as a function

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.

• f = # /. {I -> -I, -I -> I} &; May 8 '17 at 15:52
• 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 /.) May 8 '17 at 18:23
• 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. 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:

conjugate1[list]
conjugate2[list]
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.

• In fact, I am sure that symbols are real. Unfortunately, Conjugate has some problems when we work with symbols. May 8 '17 at 17:53
• @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. May 9 '17 at 8:39