Putting Expressions into Different Forms

Complicated algebraic expressions can usually be written in many different ways. The Wolfram Language provides a variety of functions for converting expressions from one form to another.

In many applications, the most common of these functions are (RefLink[Expand, paclet:ref/Expand]), (RefLink[Factor, paclet:ref/Factor]), and (RefLink[Simplify, paclet:ref/Simplify]). However, particularly when you have rational expressions that contain quotients, you may need to use other functions.

Functions for transforming algebraic expressions.

Here is a rational expression that can be written in many different forms:

e=(x-1)^2 (2+x)/((1+x) (x-3)^2)

(RefLink[Expand, paclet:ref/Expand]) expands out the numerator, but leaves the denominator in factored form:

Expand[e]

(RefLink[ExpandAll, paclet:ref/ExpandAll]) expands out everything, including the denominator:

ExpandAll[e]

(RefLink[Together, paclet:ref/Together]) collects all the terms together over a common denominator:

Together[%]

(RefLink[Apart, paclet:ref/Apart]) breaks the expression apart into terms with simple denominators:

Apart[%]

(RefLink[Factor, paclet:ref/Factor]) factors everything, in this case reproducing the original form:

Factor[%]

According to (RefLink[Simplify, paclet:ref/Simplify]), this is the simplest way to write the original expression:

Simplify[e]

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".

Rearranging expressions in several variables.

Here is an algebraic expression in two variables:

v=Expand[(3+2 x)^2 (x+2 y)^2]

This groups together terms in v that involve the same power of x:

Collect[v,x]

This groups together powers of y:

Collect[v,y]

This factors out the piece that does not depend on y:

FactorTerms[v,y]

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 the Wolfram Language to produce each possible form. Rather, the Wolfram Language allows you to construct arbitrary sets of transformation rules for converting between different forms. Many Wolfram Language 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 Wolfram Language functions for transforming expressions.

Some other functions for transforming expressions.

This expands out the trigonometric expression, writing it so that all functions have argument x:

TrigExpand[Tan[x] Cos[2x]]

This uses trigonometric identities to generate a factored form of the expression:

TrigFactor[%]

This reduces the expression by using multiple angles:

TrigReduce[%]

This expands the sine assuming that x and y are both real:

ComplexExpand[Sin[x+I y]]

This does the expansion allowing x and y to be complex:

ComplexExpand[Sin[x+I y],{x,y}]

The transformations on expressions done by functions like (RefLink[Expand, paclet:ref/Expand]) and (RefLink[Factor, paclet:ref/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 (RefLink[PowerExpand, paclet:ref/PowerExpand]).

The Wolfram Language does not automatically expand out noninteger powers of products:

Sqrt[x y]

(RefLink[PowerExpand, paclet:ref/PowerExpand]) does the expansion:

PowerExpand[%]