This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Putting Expressions into Different Forms

Complicated algebraic expressions can usually be written in many different ways. Mathematica provides a variety of functions for converting expressions from one form to another.
In many applications, the most common of these functions are Expand, Factor, and Simplify. However, particularly when you have rational expressions that contain quotients, you may need to use other functions.
Expand[expr]multiply out products and powers
ExpandAll[expr]apply Expand everywhere
Factor[expr]reduce to a product of factors
Together[expr]put all terms over a common denominator
Apart[expr]separate into terms with simple denominators
Cancel[expr]cancel common factors between numerators and denominators
Simplify[expr]try a sequence of algebraic transformations and give the smallest form of expr found

Functions for transforming algebraic expressions.

Here is a rational expression that can be written in many different forms.
Click for copyable input
Expand expands out the numerator, but leaves the denominator in factored form.
Click for copyable input
ExpandAll expands out everything, including the denominator.
Click for copyable input
Together collects all the terms together over a common denominator.
Click for copyable input
Apart breaks the expression apart into terms with simple denominators.
Click for copyable input
Factor factors everything, in this case reproducing the original form.
Click for copyable input
According to Simplify, this is the simplest way to write the original expression.
Click for copyable input
Getting expressions into the form you want is something of an art. In most cases, it is best simply to experiment, trying different transformations until you get what you want. Often you will be able to use palettes in the front end to do this.
When you have an expression with a single variable, you can choose to write it as a sum of terms, a product, and so on. If you have an expression with several variables, there is an even wider selection of possible forms. You can, for example, choose to group terms in the expression so that one or another of the variables is "dominant".
Collect[expr,x]group together powers of x
FactorTerms[expr,x]pull out factors that do not depend on x

Rearranging expressions in several variables.

Here is an algebraic expression in two variables.
Click for copyable input
This groups together terms in that involve the same power of .
Click for copyable input
This groups together powers of .
Click for copyable input
This factors out the piece that does not depend on .
Click for copyable input
As you have seen, even when you restrict yourself to polynomials and rational expressions, there are many different ways to write any particular expression. If you consider more complicated expressions, involving, for example, higher mathematical functions, the variety of possible forms becomes still greater. As a result, it is totally infeasible to have a specific function built into Mathematica to produce each possible form. Rather, Mathematica allows you to construct arbitrary sets of transformation rules for converting between different forms. Many Mathematica packages include such rules; the details of how to construct them for yourself are given in "Transformation Rules and Definitions".
There are nevertheless a few additional built-in Mathematica functions for transforming expressions.
TrigExpand[expr]expand out trigonometric expressions into a sum of terms
TrigFactor[expr]factor trigonometric expressions into products of terms
TrigReduce[expr]reduce trigonometric expressions using multiple angles
TrigToExp[expr]convert trigonometric functions to exponentials
ExpToTrig[expr]convert exponentials to trigonometric functions
FunctionExpand[expr]expand out special and other functions
ComplexExpand[expr]perform expansions assuming that all variables are real
PowerExpand[expr]transform into , etc.

Some other functions for transforming expressions.

This expands out the trigonometric expression, writing it so that all functions have argument .
Click for copyable input
This uses trigonometric identities to generate a factored form of the expression.
Click for copyable input
This reduces the expression by using multiple angles.
Click for copyable input
This expands the sine assuming that and are both real.
Click for copyable input
This does the expansion allowing and to be complex.
Click for copyable input
The transformations on expressions done by functions like Expand and Factor are always correct, whatever values the symbolic variables in the expressions may have. Sometimes, however, it is useful to perform transformations that are only correct for some possible values of symbolic variables. One such transformation is performed by PowerExpand.
Mathematica does not automatically expand out noninteger powers of products.
Click for copyable input
PowerExpand does the expansion.
Click for copyable input