Algebra

Index

This index gives a list of keywords that are associated with various cells in this Notebook. If you Command-Double-click one of the keywords below,  Mathematica  will find the cell associated with that keyword, select it, and display it in the center of  your window.

AlgebraicRules  
Apart      
ArcCos  
ArcCot  
ArcCsc  
ArcSec  
ArcSin  
ArcTan  
Assignments  
Cancel  
Coefficient  
CoefficientList  
Collect  
ComplexExpand  
Cos  
Cot  
Csc  
Decompose  
Denominator  
Expand        
ExpandAll      
ExpandDenominator  
ExpandNumerator  
Exponent  
Factor        
FactorSquareFree  
FactorTerms  
Numerator  
Output`suppressing  
Part  
PolynomialGCD  
PolynomialLCM  
PolynomialMod  
PolynomialQuotient  
PolynomialRemainder  
Replacements  
Resultant  
Sec  
Short  
Simplify      
Sin  
Tan  
Together      
Variables

Basic Algebraic Operations

Syntax (see pages 76 and 591)

Expand

Expand[poly ]  expands out products and positive integer powers in poly.

Factor

Factor[poly ]  factors a polynomial over the integers.

Simplify

Simplify[expr ] performs a sequence of algebraic transformations on expr , and returns the simplest one it finds.

ExpandAll

ExpandAll[expr ]  expands numerators and denominators completely.

Together

Together[expr ]  combines all terms over a common denominator, and cancels factors in the result.

Apart

Apart[expr ]  writes expr  as a sum of terms with simple denominators.

Expanding Out Products and Powers

Expand[(x + y )^3]

Factoring

Factor[x^2 - 9]

Simplifying

Simplify[x^2 + 2x +1]

Simplify[x^4 - 1]

Expanding Both Numerator and Denominator

ExpandAll [(x+1)^2/ (x - 1)^2]

Combining Terms over a Common Denominator

Together[ 1/(2x) + 3 x^2/(x-1)]

Separating into Terms with Simple Denominators

Apart[(x - 1) / (x^2 + 2x +1)]

Expanding Noninteger Powers

PowerExpand[(x y)^3.2]

A Note on Expanding Noninteger Powers

Mathematica  does not automatically expand out expressions of the form           (a b )^c , except when c  is an integer. In general, it is only correct to do this expansion if a  and b  are positive reals. Sometimes it is useful to perform transformations that are correct only if certain assuptions are made about the possible values of symbolic variables. One such transformation is done by PowerExpand.  It effectively assumes that a  and b  are positive reals.

Replacements and Assignments

Syntax (see  pages 74, 243 and 622)

Replacements

expr  /. x  -> value   replaces x  by value  in expr .

expr  /. {x  -> xval, y  ->yval } performs several replacements.

Assignments

x  = value   assigns a value for x  that will always be used.

x  =.  removes any value defined for x .

AlgebraicRules

AlgebraicRules[eqns , {x1 , x2 , ...}]  generates a set of algebraic rules that replace variables earlier in the list of xi   with ones later in the list, according to the equations eqns .

expr  /. algrules  applies algebraic rules to a particular expression.

Replacing a Variable with a Number

1 + 2x /. x -> 3

Assigning a Numerical Value to a Variable

x = 3

1 + 2x

A Note on Replacements and Assignments

The replacement operator /. allows you to apply transformation rules to a particular expression.  Sometimes, however, you will want to define transformation rules that should always be applied.  In this case, you would use an assignment such as x  = 3. You should understand that explicit definitions such as x  = 3  have a global effect. On the other hand, a replacement such as expr  /.x  -> 3  affects only the specific expression expr . It is usually much easier to keep things straight if you avoid using explicit definitions except when absolutely necessary. Probably the single most common mistake in using Mathematica  is to make an assignment for a variable like x  at one point in your session, and later using x  having forgotten about the assignment you made.

Replacing a Variable by an Expression

1 + x + x^2 /. x -> 2 - y

Making Several Replacements

(x + y) (x - y)^2 /. {x -> 3, y -> 1 - a}

Giving a Name to a Transformation Rule

transrule = x -> 2 - y

1 + x + x^2 /. transrule

Assigning an Expression to a Variable

x = a + 1

x ^2 - 1

Removing an Assigned Value

x = a + 1

x ^2 - 1

x = .

x ^2 - 1

Using Algebraic Rules

ar = AlgebraicRules[ x^2 == a, {x, a}]

1 + x^2 + x^4 /. ar

A Note on Algebraic Rules

Transformation rules in Mathematica  are usually based on the structure of expressions, not their algebraic meaning. Thus, the transformation rule          x^2 -> a   says nothing about objects like x^4 that are algebraically related to x^2. The previous example shows how to use AlgebraicRules to make transformations based on algebraic relationships.

Algebraic Rules in Several Variables

ar2 = AlgebraicRules[ { a == x+y, b == x y},
                             {x, y, a, b}]

x^5 + y^5 /. ar2

Transforming Polynomials

Syntax (see pages 78 and 591)

Expand

Expand[poly ] expands out products and positive integer powers in poly .

Expand[poly , patt ] expands out poly  avoiding those parts which do not contain terms matching patt .

Factor

Factor[poly ] factors a polynomial over the integers.

Factor[poly , GaussianIntegers -> True] factors a polynomial, allowing coefficients that are complex numbers with rational real and imaginary parts.

Simplify

Simplify[poly ] performs a sequence of algebraic transformations on expr , and returns the simplest one it finds.

Collect

Collect[poly , x ] collects together terms involving the same power of x .

Collect[poly , {x1 ,  x2 , ...}] collects together terms involving the same powers of x1 , x2 , ... .

FactorTerms

FactorTerms[poly ] factors out any overall numerical factor.

FactorSquareFree

FactorSquareFree[poly ]  pulls out any square-free factors in poly .

Expanding Out Products and Powers

Expand[(x + y )^3]

Expanding Only Certain Forms

Expand[(x+1)^2 (y +1)^2, x]

Factoring

Factor[x^2 - 9]

Factoring with Gaussian Integers

Factor[ x^2 + 1, GaussianIntegers -> True]

Factor[ x^2 - 2I, GaussianIntegers -> True]

Simplifying

Simplify[x^2 + 2x +1]

Simplify[x^4 - 1]

A Note on Simplifying

There are many situations where you want to write a particular algebraic expression in the simplest possible form. Although it is difficult to know exactly what one means in all cases by the "simplest form", a worthwhile practical procedure is to look at many different forms of an expression, and pick out the one that involves the smallest number of parts. This is essentially what Simplify does.  For many simple algebraic calculations, you may find it convenient to use Simplify routinely on your results. In more complicated calculations, however, you often need to exercise more control over the exact form of the answer that you get.  In addition, when your expressions are complicated, Simplify may spend a long time testing a large number of possible forms in its attempt to find the simplest one.

Collecting  Terms

Collect[x + n x + m, x]

Collecting  Terms in Several Variables

Collect[ x^2 y +  x^2 + y z + z, {x,z}]

Pulling Out a Numerical Factor

FactorTerms[2 x^2 + 6 y^2 - 12]

Pulling Out Squared Factors

FactorSquareFree[Expand[(1 + x)^2 
                    (2 +x) (3 + x)]]

Transforming Rational Expressions

Syntax (see pages 78 and 594)

Expand

Expand[expr ]  expands out products and positive integer powers in the numerator of expr , dividing the denominator into each term.

Expand[expr , patt ] expands expr  avoiding those parts which do not contain terms matching patt .

ExpandNumerator

ExpandNumerator[expr ] expands the numerator only.

ExpandDenominator

ExpandDenominator[expr ] expands the denominator only.

ExpandAll

ExpandAll[expr ] expands the numerator and denominator completely.

ExpandAll[expr ,  patt ] expands the numerator and denominators avoiding those parts that do not contain terms matching patt .

Factor

Factor[expr ] puts all terms over a common denominator and factors the result.

Together

Together[expr ] combines all terms over a common denominator, and cancels factors in the result.

Apart

Apart[expr ] writes expr as a sum of terms with simple denominators.

Cancel

Cancel[expr ] cancels out common factors in the numerator and denominator of expr  .

Expanding

Note that Expand leaves the denominator in factored form and divides the denominator into each term.

Expand[(x+1)^2/ (x - 1)^2]

Expanding Both Numerator and Denominator

ExpandAll [(x+1)^2/ (x - 1)^2]

Expanding Just the Numerator

ExpandNumerator[(x+1)^2/ (x - 1)^2]

Expanding Just the Denominator

ExpandDenominator[(x+1)^2/ (x - 1)^2]

Expanding Only Certain Forms

Terms that do not contain y  are not expanded.

ExpandAll[(1+x)^2 / (y+1)^2 + (y + 1)^2 / y^2, y]

Factoring

Factor[1 / (x^2 -1) + x^3 / (x +1)]

Combining Terms over a Common Denominator

Together[ 1/(2x) + 3 x^2/(x-1)]

Separating into Terms with Simple Denominators

Apart[(x - 1) / (x^2 + 2x +1)]

A Partial Fraction

Apart[1/(x^2 - 1)]

Canceling Common Factors

Cancel[(x^2 - 1) / (x^2 + 2x +1)]

Picking Out Pieces of Algebraic Expressions

Syntax (see pages 82 and 593)

Coefficient

Coefficient[poly , expr ] gives the coefficient of expr  in poly .

Coefficient[poly , expr , n ] gives the coefficient of expr ^n  in   poly .

Coefficient[poly , expr, 0] gives the term  in poly  that is independent of expr .

CoefficientList

CoefficientList[poly , {x1, x2 , ...}] gives a matrix of the coefficients of x1 , x2 , ...  in poly .

Exponent

Exponent[poly , x ] gives the maximum power of x  in poly .

Variables

Variables[poly ] gives a list of all independent variables in poly .

Numerator

Numerator[expr ] gives the numerator of expr .

Denominator

Denominator[expr ] gives the denominator of expr .

Part

Part[expr , n ]  gives the n th term in expr .

Picking Out a Coefficient

Coefficient[x^2 - 3 x^4 + y - 1  , x^4]

Coefficient[x^2 - 3 x^4 + y - 1  , x, 4]

Picking Out the Term Independent of x

Coefficient[x^2 - 3 x^4 + y - 1, x, 0]

Getting a List of Coefficients

CoefficientList[ Expand[ (x + y)^3], {x,y}]

The Maximum Exponent of x  in a Polynomial

Exponent[x^2 + 3 x^4 + y x , x]

Picking Out the Numerator

Numerator[(y^2 - 1)/(x - 1)]

Picking Out the Denominator

Denominator[(y^2 - 1)/(x - 1)]

Denominator[x^2 + 1]

Picking Out the n th Term

Part[ x^2 + 2 x + 7, 2]

A Note on Manipulating Expressions like Lists

Every Mathematica  expression can be manipulated structurally much like a list. For example, the function Part used in the previous example also picks out the n th element of a list. This flexibility is one of the things that makes Mathematica  so powerful. However, all functions that manipulate the structure of expressions act on the internal form of these expressions. You can see these forms using FullForm[expr ].  You must be careful, because Mathematica  often shows algebraic expressions in a form that is different from the way it treats them internally. For more information, see page 196.

Algebraic Operations on Polynomials

Syntax (see page 597)

PolynomialQuotient

PolynomialQuotient[poly1 , poly2 , x ] gives the result of dividing poly1  by poly2 , treated as polynomials in x , with any remainder dropped.

PolynomialRemainder

PolynomialRemainder[poly1 , poly2 , x ] gives the remainder from dividing poly1  by poly2 , treated as polynomials in x .

PolynomialGCD

PolynomialGCD[poly1 , poly2 ] gives the greatest common divisor of poly1  and poly2  .

PolynomialLCM

PolynomialLCM[poly1 , poly2 ] gives the least common multiple of poly1  and poly2  .

PolynomialMod

PolynomialMod[poly ,m ] gives poly  reduced modulo m .

Resultant

Resultant[poly1 ,poly2 , x ] gives the resultant of poly1  and poly2  with respect to x .

Decompose

Decompose[poly ,x ] decomposes a polynomial, if possible, into a composition of simpler polynomials.

The Quotient of Polynomials

PolynomialQuotient[ x^2, x+1, x]

The Remainder in a Polynomial Quotient

PolynomialRemainder[ x^2, x+1, x]

The Greatest Common Divisor

PolynomialGCD[ (1-x)^2 (1+x) (2+x),
                        (1-x) (2+x) (3+x)]

The Least Common Multiple

PolynomialLCM[ (1-x)^2 (1+x) (2+x),
                        (1-x) (2+x) (3+x)]

Reduction Modulo 2

PolynomialMod[ 2 x^2 - 7 x^3 + 3, 2]

The Resultant

Resultant[ (x-y)^2 - 2, y^2 - 3, y]

Decomposing a Polynomial

Decompose [ x^4 + x^2 + 1, x]

Expressions Involving Complex Variables

Syntax (see pages 81 and 604)

ComplexExpand

ComplexExpand[expr ] expands expr   assuming that all variables are real.

ComplexExpand[expr , {x1 , x2 , ...}] expands expr   assuming that the xi  are complex.

ComplexExpand[expr , TargetFunctions ->                 {Abs ,Arg }] gives the result in polar form.

ComplexExpand[expr , TargetFunctions  ->                   {Conjugate, Sign}] gives the result in terms of complex conjugates.

ComplexExpand[Tan[x + I y]]

Expanding the Exponential

ComplexExpand[Exp[x + I y]]

Expanding Sine with Real x  and y

ComplexExpand[Sin[x + I y]]

Expanding Sine with Complex z

ComplexExpand[Sin[z], z]

Expanding in Polar Form

ComplexExpand[x^2, {x},
               TargetFunctions -> {Abs, Arg}]

Expanding Using Complex Conjugates

ComplexExpand[x^2, {x},
         TargetFunctions -> {Conjugate, Sign}]

Controlling the Display of Large Expressions

Syntax (see pages 83 and 346)

Supressing Output

command ;     executes command  but does not print the result.

Short

Short[expr ] or  expr //Short   shows a one-line outline of expr .

Short[expr ,n ]  shows an outline of expr  about n  lines long.

Supressing Output

Note that you can still use % to get the output that would have been produced.

Expand[ (x + 5y + 10) ^ 4];

Short[%]

Getting Short Output

Expand[ (x + 5y + 10) ^ 4] // Short

Short[Expand[ (x + 5y + 10) ^ 4], 3]

Trigonometry

Index

This index gives a list of keywords that are associated with various cells in this Notebook. If you Command-Double-Click one of the  keywords below,  Mathematica  will find the cell associated with that keyword, select it, and display it in the center of  your window.

AlgebraicRules  
Apart      
ArcCos  
ArcCot  
ArcCsc  
ArcSec  
ArcSin  
ArcTan  
Assignments  
Cancel  
Coefficient  
CoefficientList  
Collect  
ComplexExpand  
Cos  
Cot  
Csc  
Decompose  
Denominator  
Expand        
ExpandAll      
ExpandDenominator  
ExpandNumerator  
Exponent  
Factor        
FactorSquareFree  
FactorTerms  
Numerator  
Output`suppressing  
Part  
PolynomialGCD  
PolynomialLCM  
PolynomialMod  
PolynomialQuotient  
PolynomialRemainder  
Replacements  
Resultant  
Sec  
Short  
Simplify      
Sin  
Tan  
Together      
Variables

Trigonometric Functions

Syntax (see pages 49 and 562)

Trigonometric Functions

Sin[x ], Cos[x ], Tan[x ], Csc[x ], Sec[x ], and Cot[x ]  give the value of the trigonometric functions at x  radians.

Inverse Trigonometric Functions

ArcSin[x ], ArcCos[x ], ArcTan[x ], ArcCsc[x ], ArcSec[x ], and ArcCot[x ]  give the value of the inverse trigonometric functions at x .

Trigonometric Function with Exact Result

Note that the arguments to trigonometric functions are always in radians.

Sin[Pi/3]

N[%]

Trigonometric Function with Approximate Result

Note the explicit use of the decimal point.

Tan[2.]

Trigonometric Function Using Degrees

Multiplying by the constant Degree converts the argument to radians.

Tan[2 Degree] //N

Inverse Trigonometric Function

ArcCsc[1]

ArcTan[.12]

A Note on Inverse Functions

An inverse function is the solution to an equation. For example, the inverse or arc sine function gives a solution to the equation y  = Sin[x ]. However, there are many such solutions. Thus, in defining an inverse function one must make a choice of a "principal value". For the inverse trigonometric and hyperbolic functions there are standard choices made in mathematics. These same choices are used by Mathematica .  For example, the values of  ArcSin are always in the range -Pi/2 to Pi/2.  For information on a specific inverse function, see  its reference guide entry in The Mathematica  Book.

Transforming Trigonometric Expressions

Expand

Expand[expr , Trig->True]  writes Sin[x ]^2  in terms of Sin[2x ], etc.

ExpandAll

ExpandAll[expr , Trig->True]  expands the numerator and denominators completely and uses trigonometric identities.

Factor

Factor[expr , Trig->True]  writes Sin[2x ] in terms of    Sin[x ]^2, etc.

Simplify

Simplify[expr , Trig->True]  simplifies and uses trigonometric identities.

Together

Together[expr ,  Trig->True]  combines all terms over a common denominator and uses trigonometric identities.

Apart

Apart[expr ,  Trig->True]  writes expr  as a sum of terms with simple denominators and uses trigonometric identities.

Expanding a Trigonometric Expression

Expand[Cos[x]^3 Sin[x]^2, Trig -> True]

Factoring a Trigonometric Expression

Factor[1/2 - Cos[2x]/2, Trig -> True]

Simplifying a Trigonometric Expression

Simplify[Sin[x]^2 + Cos[x]^2, Trig -> True]

Simplify[Tan[x]^2 + 1, Trig -> True]

A Note on Using Trig->True

Trigonometric expressions like Sin[2x ] are by default left unchanged by Mathematica' s algebraic manipulation functions. Any trigonometric expression can be viewed as a rational function of exponentials. What the option setting  Trig->True effectively does is to use this form in performing algebraic manipulations you specify. With Trig->True, Mathematica  first converts all trigonometric functions to exponentials. Then it performs the algebraic operation you specify. Then it takes the exponentials in the result and attempts to combine them into trigonometric functions.

Using Apart

Apart[ 1/(Cos[2x] Sin[2x]), Trig -> True]

Using Together

Together[ Cos[2x]/Sin[x]^2 - Sin[2x]/Cos[x],
                             Trig -> True]