Prev: SFTP
Next: calculating mean prediction bands
From: David Park on 26 Jun 2010 03:10 Well, thanks for the clarification, and looking more closely at the ComplexExpand usage and the Function page I believe I have a better understanding of it. I do think the Function help page could be written more clearly. What does the "Expand" in ComplexExpand and "expands" in the usage message actually mean? The first examples you give make it look as its principal operation is as in Expand, such as expanding polynomials. I think the principal design was something like this: ComplexExpand[f[z], {z}] expands f[z] to x[z] + I y[z] where x[z] and y[z] are real valued functions of z and f[z] is a defined expression in z. x[z] and y[z] are expressed in terms of TargetFunctions. That seems to me to be a different meaning to "Expand" than expanding products of polynomials. But the Help doesn't actually give that definition and hence they leave its principal usage vague. Their second definition should be the first one, and the first one the second one - if they want to emphasize the basic functionality. Nevertheless, whether you want to call it simplification or not, ComplexExpand does employ considerable transformation of functions and identities and to many users this will look like more than a simple Expand. Also, users will often be working with expressions that contain only real variables and with everything that happens they overlook the basic expansion to x + I y. The Help could also better specify the use of TargetFunctions. It should say that it has the default value of TargetFunctions -> {Re, Im, Abs, Arg, Conjugate, Sign} and that Mathematica will choose among all of them by the internal algorithm. One might have the impression that {Re, Im} are the default TargetFunctions, which is not the case. For example the following does not give what one might expect and doesn't even expand to the usual form. ComplexExpand[Abs[(x + I y)^2]] Abs[x + I y]^2 Maybe it's a bug or a weakness in the algorithm. Or maybe the meaning of "Expand" isn't quite what I wrote above. One would usually want: ComplexExpand[Abs[(x + I y)^2], TargetFunctions -> {Re, Im}] x^2 + y^2 David Park djmpark(a)comcast.net http://home.comcast.net/~djmpark/ From: Andrzej Kozlowski [mailto:akoz(a)mimuw.edu.pl] On 25 Jun 2010, at 20:28, David Park wrote: > Maybe ComplexExpand should have been called ComplexSimplify or ComplexReduce > - but it's too late now and I don't know if that, in itself, would alleviate > the problem for beginners. But, as has been pointed out many times, it *does" expand. How would ComplexSImplify and ComplexReduce fit with the following behaviour: In[63]:= ComplexExpand[(a + b)^3] Out[63]= a^3 + 3*a^2*b + 3*a*b^2 + b^3 ComplexExpand[(a + b)*(c + d)] a*c + a*d + b*c + b*d Is this reduction? Is is simplification? It's clearly *expansion* as it this: ComplexExpand[z, {z}] Re(z)+I Im(z) and this ComplexExpand[z, {z}, TargetFunctions -> {Arg, Abs}] Abs[z]*Cos[Arg[z]] + I*Abs[z]*Sin[Arg[z]] In fact, I don't think there is any other name but ComplexExpand or something synonymous that fits this and all other behaviour of ComplexExpand. To say that it "should have been called something else" is actually misleading. Andrzej Kozlowski
From: Andrzej Kozlowski on 26 Jun 2010 03:11 On 25 Jun 2010, at 20:28, David Park wrote: > Maybe ComplexExpand should have been called ComplexSimplify or ComplexReduce > - but it's too late now and I don't know if that, in itself, would alleviate > the problem for beginners. But, as has been pointed out many times, it *does" expand. How would ComplexSImplify and ComplexReduce fit with the following behaviour: In[63]:== ComplexExpand[(a + b)^3] Out[63]== a^3 + 3*a^2*b + 3*a*b^2 + b^3 ComplexExpand[(a + b)*(c + d)] a*c + a*d + b*c + b*d Is this reduction? Is is simplification? It's clearly *expansion* as it this: ComplexExpand[z, {z}] Re(z)+I Im(z) and this ComplexExpand[z, {z}, TargetFunctions -> {Arg, Abs}] Abs[z]*Cos[Arg[z]] + I*Abs[z]*Sin[Arg[z]] In fact, I don't think there is any other name but ComplexExpand or something synonymous that fits this and all other behaviour of ComplexExpand. To say that it "should have been called something else" is actually misleading. Andrzej Kozlowski
From: Andrzej Kozlowski on 26 Jun 2010 08:42
On 26 Jun 2010, at 16:10, David Park wrote: > The Help could also better specify the use of TargetFunctions. It should say > that it has the default value of TargetFunctions -> {Re, Im, Abs, Arg, > Conjugate, Sign} and that Mathematica will choose among all of them by the > internal algorithm. One might have the impression that {Re, Im} are the > default TargetFunctions, which is not the case. For example the following > does not give what one might expect and doesn't even expand to the usual > form. > > ComplexExpand[Abs[(x + I y)^2]] > > Abs[x + I y]^2 > > Maybe it's a bug or a weakness in the algorithm. Or maybe the meaning of > "Expand" isn't quite what I wrote above. One would usually want: > > ComplexExpand[Abs[(x + I y)^2], TargetFunctions -> {Re, Im}] > > x^2 + y^2 There is no bug here at all. Look at the default value of the option TargetFunctions of ComplexExpand: OptionValue[ComplexExpand, TargetFunctions] {Re,Im,Abs,Arg,Conjugate,Sign} So when you evaluate ComplexExpand[Abs[(x + I y)^2]] you are asking Mathematica to expand the expression as a sum of real and imaginary parts in terms of any of these TargetFunctions. But the expression you gave to ComplexExpand is already expanded in terms of these functions (actually one of them). Hence of course ComplexExpand does nothing. If you remove Abs from the list of allowable TargetFunctions you will get the expected expansion. The same thing will happen every time when you apply ComplexExpand to something that is already "expanded" in terms of any of the default Target Functions. ComplexExpand[Sign[x]] Sign[x] ComplexExpand[Sign[x], TargetFunctions -> {Re, Im, Abs, Arg, Conjugate}] x/Sqrt[x^2] ComplexExpand[Sign[x], TargetFunctions -> {Arg}] E^(I*Arg[x]) Of course ComplexExpand will use non-listed target functions if it can't expand an expression in terms of the listed ones: ComplexExpand[Sign[x], TargetFunctions -> {Abs}] x/Sqrt[x^2] Andrzej Kozlowski |