Wolfram ResearchProductsPurchasingServices & ResourcesAbout UsOur Sites
Mathematica Technical FAQs Services & Resources / Mathematica / Mathematics
-----
 /
Symbolic Algebra
*Mathematica
*Network Mathematica
*webMathematica
*gridMathematica
*Personal Grid Edition
*Wolfram Workbench
*Wolfram Education Group
*Application Packages
*Mathematica for Students
*Mathematica CalcCenter
*Publicon
*A New Kind of Science Explorer
*Mathematical Explorer
*Mathematica Teacher's Edition
*Calculus WIZ
*Mathematica Player
*Ask about this page
*Print this page
*Email this page
*Give us feedback
*
Sign up for our newsletter:

Why are transformations of Sqrt[x^2], Log[x y], Log[ⅇ^x], etc. not automatically done?

There are many transformations, such as replacing by x, or replacing Log[x y] by Log[x] + Log[y], that are not done automatically in Mathematica. These transformations are omitted because, in general, they are not mathematically correct.

For example, if x is negative, then is not equal to x, so it would be wrong to replace by x without first checking that x is positive. More generally, if x is a complex number, then replacing by x is wrong for all values of x in the left half of the complex plane.

On the other hand, if x is known to be positive or is known to lie in the right half of the complex plane, then replacing by x is correct and can be a very useful simplification.

Another example is illustrated by the relationship between Log[x y] and Log[x] + Log[y]. If x and y are positive, then these expressions are equivalent. If x and y are negative, then replacing Log[x y] by Log[x] + Log[y], or replacing Log[x] + Log[y] by Log[x y], would be incorrect since these expressions differ by 2 π ⅈ.

Similar questions come up for nearly all expressions involving square roots, non-integer powers, logarithms, inverse trigonometric functions, inverse hyperbolic functions, and inverses of other special functions.

The most difficult aspect of applying these transformations is not the transformations themselves, but determining when they are valid and being careful to apply them only when they are known to be correct.

If you are only interested in the transformations and don't need Mathematica to check that they are valid, then it is fairly easy to write the necessary transformation rules. That, in fact, is exactly how the PowerExpand function works.

Here is an example of a transformation rule for nested powers. This is the rule that is used by PowerExpand to replace by x.

In[1]:=
Out[1]=
 

 
In[2]:=
Out[2]=
 

 

Here is a rule for transforming the logarithm of a product.

In[3]:=
Out[3]=
 

 

If you wish, you can write your own function to apply these or other transformations. As an example, here is the rule that defines PowerExpand[expr] in Mathematica.

The definition of PowerExpand[expr] includes both of the rules that were used in the preceding examples.

In[4]:=
Out[4]=
 

 
In[5]:=
Out[5]=
 

 

If you want to write transformation rules of your own or add a function similar to PowerExpand, here are several points that you may want to keep in mind.

Rules corresponding to the inverse of PowerExpand are typically more difficult to write than the rules in PowerExpand, and some of these inverse rules are mathematically ambiguous. For example, since , , and are all replaced by x, it isn't necessarily obvious what should be done if the inverse operation is applied to x.

On the other hand, some of the rules that correspond to the inverse of PowerExpand, such as a rule to replace Log[x] + Log[y] by Log[x y], are quite simple. If you are interested in this transformation, you may want to write your own function to apply such a rule. Here, for example, is a simple function LogCombine, which applies the inverses of the two logarithm rules from PowerExpand.

In[6]:=
In[7]:=
Out[7]=
 

 

You should be careful, of course, to avoid competing rules. For example, a function that includes both a rule to replace Log[x] + Log[y] by Log[x y] and a rule to replace Log[x y] by Log[x] + Log[y] will run forever, or more likely, until reaching the value of the MaxIterations option in ReplaceRepeated.

You may also want to include conditions in your rules to check the validity of the transformation before applying the rule. In general, this is a very difficult problem, which is the main reason that it has not yet been broadly implemented in Mathematica. In simple cases, it is relatively easy. Here, for example, is a rule that replaces by x only if Positive[x] evaluates to True.

In[8]:=
In[9]:=
Out[9]=
 

 

It is likely that more sophisticated features for applying these types of transformations will be added for future versions of Mathematica. The underlying programming and mathematical problems are quite difficult, but these features are sufficiently valuable that this is a high priority for future development.

Download this FAQ as a Mathematica 5.2 Notebook






 © 2008 Wolfram Research, Inc.  Terms of Use  Privacy Policy | [ja]