Advice for Mathematica as Mathematician's Aid
In the first case PowerExpand
comes to the rescue:
PowerExpand@Power[p^(n m) q, 1/n]
(* Out: p^m q^(1/n) *)
Note however that "the transformations made by PowerExpand
are correct only if $c$ is an integer or $a$ and $b$ are positive real numbers".
Generally speaking, your assumptions can be listed in Reduce
, Simplify
, or FullSimplify
using the Assumptions
option, or alternatively using by wrapping those functions within Assuming
.
If you know that certain assumptions about one or more parameters will hold throughout your calculation, however, it can be very handy to declare them globally using the $Assumptions
variable, to whose documentation I refer you. This will make them "sticky".
This variable is empty at kernel start. If you set it to e.g.
$Assumptions = {Element[n, Integers], n > 0}
whenever you use any function that has an Assumptions
option (e.g. Simplify
, FullSimplify
, Reduce
) then the contents of $Assumptions
will be automatically added to any further local assumptions you might want to make and will carry throughout your computation.
Even more generally, simplification in Mathematica is sometimes frustrating because the user's and the system's concepts of "simpler" may not coincide. The Simplify
family of functions use an automatic ComplexityFunction
to gauge how "complicated" an expression is; the system strives to generate an expression that minimizes this complexity function. Left to its own devices, the system primarily attempts to minimize the LeafCount
of the resulting expression (see the "Details" section of the docs). Code that approximates the behavior of the standard ComplexityFunction
is available in its docs, under "Properties and Relations".
One can write one's own ComplexityFunction
to hand-hold the system and arrive at specific results. A good example is provided by the expression in the OP's comment to the question:
expr = ((d^2 + g)^2 (256 d^8 g^4 - 1024 d^6 g^5 - 1024 d^2 g^7 +
256 g^8 + d^4 (1536 g^6 + 65536 g^5 r^2 + t^4)))/ d^6 ==
(32 g^2 (d^8 + g^4 - 2 d^4 g (g - 64 r^2)) t^2)/d^4
Assuming that $d>0$, Carl would like the expression to be simplified by multiplication by a $d^4$ or $d^6$ factor. Although they do modify the expression somewhat, neither Simplify[expr, Assumptions -> d > 0
nor the equivalent FullSimplify
will do that.
FullSimplify[expr, Assumptions -> d > 0]
However, we can write a custom complexity function that penalizes the presence of denominators, as measured by the count of Power
terms with negative exponents.
FullSimplify[expr,
ComplexityFunction -> (Count[#, Power[_, _?Negative], Infinity] &),
Assumptions -> d > 0
]
This removes the denominators, but the resulting expression is quite messy (the LeafCount
is a staggering 162!). We can still achieve the desired rewriting while retaining some tidiness in the result by using a more nuanced complexity function that highly disfavors the presence of denominators (see the $1000$ weighing factor in front of Count
) and also penalizes the presence of a high number of terms:
FullSimplify[expr,
ComplexityFunction -> (1000 Count[#, Power[_, _?Negative], Infinity] + LeafCount[#] &),
Assumptions -> d > 0
]
The leaf count of the last expression is a much more agreeable 72, and the denominators have been removed as desired.
A simpler approach may be to augment the list of manipulating functions that Simplify
&co. will try out on your input expression. This can be achieved using a custom TransformationFunctions
option. For instance, one could add PowerExpand
from above to the standard list of manipulator functions:
Simplify[Power[p^(n m) q, 1/n]]
Simplify[Power[p^(n m) q, 1/n], TransformationFunctions -> {Automatic, PowerExpand}]
(*Out:
(p^(m n) q)^(1/n)
p^m q^(1/n)
*)
This may be dangerous though, because PowerExpand
carries implicit assumptions (see above) that may not always be appropriate!
Here are a few links for bed-time reading on the subject :-)
- What is the difference between a few simplification techniques?
- Simplify Sin[x]/x to Sinc[x] has a nice example of the use of a custom
TransformationFunction
orComplexityFunction
(see the comments) to achieve the desired rewriting - A method to see what Simplify is actually doing under the hood: How can I see which transformations Simplify attempts?
- Search results from this site mentioning
ComplexityFunction
yield excellent examples of custom-built weighing functions designed to achieve a desired rewriting.
I use Mathematica in much the same way as you, although in the context of multi-stage physics derivations. Since no one has mentioned it, I'll describe an obvious approach to successive rewrites of an expression.
I label each step a calculation with an indexed symbol that I can refer to later. This is preferable to In's and Out's whose numbers can change if you go back and redo something.
w[1] = ((d^2 + g)^2 (256 d^8 g^4 - 1024 d^6 g^5 - 1024 d^2 g^7 +
256 g^8 + d^4 (1536 g^6 + 65536 g^5 r^2 + t^4)))/ d^6 ==
(32 g^2 (d^8 + g^4 - 2 d^4 g (g - 64 r^2)) t^2)/d^4
Visual inspection of the result suggests the cancellation of the denominators -- so just do it.
w[2] = (#d^6)& /@ w[1]
and carry on.
If you see a simplification you would make in a pen and paper calculation, you can almost always duplicate it in Mathematica by application of function or pattern matching rule. Also, this step by step process allows you much more control over the appearance of an intermediate results. A bonus is that if you find that a series of calculations is to be repeated for other initial conditions, you can simply gather w[1], ..., w[n] into an encapsulating function and perform the various rewrites automatically.
I can't help you with functions beyond Reduce
, Simplify
, ... but I can offer you a tip to help with reducing errors from manual translation.
In order to validate that your manual transformation is correct, one can subtract the original expression from the manual transformation and then use Simplify
on that expression.
Sometimes it will return zero using symbols, but if that doesn't work you can put in numbers from the domain where you are working.
For example, the problem where you want (p^(m n) q)^(1/n)
to simplify to p^m (q)^(1/n)
you can execute:
FullSimplify[(p^(m n) q)^(1/n) - p^m (q)^(1/n) /.
{p -> 2.3, m -> 1.5, n -> 3.}]
which returns 0
.
I have successfully used this to reduce my mistakes in manual translation.