Re: Simplifying Conjugate[] with 5.2 Mac
- To: mathgroup at smc.vnet.net
- Subject: [mg59810] Re: Simplifying Conjugate[] with 5.2 Mac
- From: "James Gilmore" <james.gilmore at yale.edu>
- Date: Mon, 22 Aug 2005 02:48:36 -0400 (EDT)
- Organization: Yale University
- References: <de45i8$qtf$1@smc.vnet.net> <de6maf$cj5$1@smc.vnet.net> <de9cqi$q5a$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"Steuard Jensen" <sbjensen at midway.uchicago.edu> wrote in message news:de9cqi$q5a$1 at smc.vnet.net... > Quoth "James Gilmore" <james.gilmore at yale.edu> in article > <de6maf$cj5$1 at smc.vnet.net>: > [I wrote:] >> > In[5]:= Simplify[Conjugate[x+I y]] >> > >> > Out[5]= Conjugate[x + I y] > >> With regard to this behaviour, it may be useful to use PlusMap (or Map if >> there are always at least two terms when expanded), see FurtherExamples, >> in >> the Map documentation. >> $Assumptions = {{a, b} \[Element] Reals}; >> PlusMap[f_, expr_ /; Head[expr] =!= Plus, ___] := f[expr]; >> PlusMap[f_, expr_Plus, r___] := Map[f, expr, r]; >> Trace[Simplify[PlusMap[Conjugate, Expand[a + I*b]]]] >> Trace[Simplify[PlusMap[Conjugate, Expand[a + b]]]] > > This approach would presumably work in principle (since we've seen > that Simplify can deal with one term at a time). But in practice, my > expressions often involve products and sums of many terms at many > levels. So I would either need to devise a way to Map Conjugate > properly onto each term by hand (at which point I might as well just > change all the I's to -I's myself!), or come up with an automated way > of doing it Are you just interested in changing I's to -I's? If so, I would suggest that you forget about Conjugate altogether and use pattern matching instead. This will give you an efficient method that will not depend on the internals of Conjugate. You will also not have to deal with changes in future versions of Mathematica. The other suggestions in this thread are compared to the pattern matching method below. It is clear pattern matching is the most efficient for the simple form tested: $ProductInformation {"ProductIDName" -> "Mathematica", "ProductKernelName" -> "Mathematica 5 Kernel", "ProductVersion" -> "5.0 for Microsoft Windows (June 11, 2003)", "ProductVersionNumber" -> 5.} ConjugateSimple[z_] := z /. {I -> -I, -I -> I} ConjugateSimple[{x - I*y, x + I*y, Exp[(-I)*z], Log[I + q]}] (*Works fine on _simple_ conjugations*) Timing[Table[ConjugateSimple[x + I*y], {i, 1, 10^4}]; ] {x + I*y, x - I*y, E^(I*z), Log[-I + q]} {0.391*Second, Null} ComplexExpand[Conjugate[x + I*y]]; Timing[Table[ComplexExpand[Conjugate[x + I*y]], {i, 1, 10^4}]; ] {8.882*Second, Null} ComplexExpand[Simplify[Conjugate[x + I*y]]]; Timing[Table[ComplexExpand[Simplify[Conjugate[x + I*y]]], {i, 1, 10^4}]; ] {9.954999999999998*Second, Null} $Assumptions = {{x, y} \[Element] Reals}; Refine[Conjugate[x + I*y]]; Timing[Table[Refine[Conjugate[x + I*y]], {i, 1, 10^4}]; ] {1.402000000000001*Second, Null} FullSimplify[Conjugate[x + I*y]]; Timing[Table[FullSimplify[Conjugate[x + I*y]], {i, 1, 10^4}]; ] {1.4519999999999982*Second, Null} Extend the definition to include purely complex variables: ConjugateVariables[z_] := z /. {w -> -w, -w -> w, "OtherComplexVariableListetc" -> -OCVL,-"OCVL"->OCVL} ConjugateSimple[ConjugateVariables[(-w)*x + w*I]] I*w + w*x Of course, the safeguards of Conjugate are lost using pattern-matching, but if you already know which variables are real and complex then that wont be an issue. -- James Gilmore Graduate Student Department of Physics Yale University New Haven, CT 06520 USA >(which would probably end up being equivalent to > explicitly defining Conjugate[expr_Plus]:=Map[Conjugate,expr], etc., > as I suggested in a different reply). > > But I hope it's not unreasonable for me to feel a bit frustrated that > I've got to work around this behavior at all. Regression bugs between > versions are no fun for anyone. > Steuard Jensen >