CHAPTER 2

image

Algebraic Expressions and Operations: Factoring Algebraic Fractions

MATLAB handles all calculations involving simple, rational, and complex algebraic expressions with mastery. It quickly and efficiently performs the operations of simplification, factorization, grouping, and expansion of algebraic expressions, no matter how complicated, including trigonometric expressions and expressions involving complex variables. All of this is possible provided the symbolic math Toolbox is available. The following is a list of commands which implement the algebraic transformations most commonly used in work with MATLAB.

2-1. Expansion of Algebraic Expressions

The following commands enable MATLAB to expand or develop algebraic expressions:

  • expand(expr) expands an algebraic expression, presenting the result as a sum of products and powers. It applies multiple angle rules for trigonometric expressions and formally applies the properties of exponential and logarithmic functions. It also decomposes quotients of polynomials by expanding the numerator, presenting the original expression as a sum of algebraic quotients.
  • maple('expand(expr)')  completely expands the algebraic expression, transforming products and powers into sums of terms, applying multiple angle rules for trigonometric functions and expansion rules for exponential functions. It then simplifies the end result.
  • maple('Expand(expr)') performs the inert expansion of expr (that is, it goes through the steps of expansion without evaluation).
  • maple('expand(expr) mod n') performs the expansion of expr modulo n.
  • maple('Expand(expr) mod n') gives the inert expansion of expr modulo n.
  • maple('expand(expr, sub1,...,subn)') expands expr without expanding its subexpressions sub1,..., subn.
  • maple('expand(rational)') expands the numerator of the given rational algebraic expression.
  • maple('expand(equation)') expands both sides of the equation.
  • maple('expand([expr1,...,exprn])') creates a list of expanded expressions.
  • maple('expand({expr1,...,exprn})') creates a set of expanded expressions.
  • maple('expandoff(command)') suppresses the expansion of expressions involving the specified command in future calculations.
  • maple('expandoff(com1,...,comn)') suppresses the expansion of expressions involving the specified commands in future calculations.
  • maple('expand(expandoff ())') suppresses the expansion of expressions for all commands in future calculations.
  • maple('expandon(command)') enables the expansion of expressions involving the specified command in future calculations. First, it checks whether the command has been previously affected by expandoff, and if so, it eliminates its effect.
  • maple('expandon(com1,...,comn)') enables the expansion of expressions involving the specified commands in future calculations.
  • maple('expand(expandon ())') enables the expansion of expressions for all commands in future calculations.
  • maple('frontend(command, [expr1,..., exprn])') paralyzes the expansion of the given expressions before submitting to the specified command or procedure.
  • maple('frontend(command, [expr1,..., exprn], [arg1,..., argm])') paralyzes the expansion of the given expressions expr1,...,exprn before submitting to the specified command or procedure, but does not freeze arg1,...,argm.

Now let’s look at several examples of algebraic manipulations using the commands we’ve just seen:

>> syms x y z t a b
>> pretty(expand((x+1)*(x+2)))
                                 2
                                x  + 3 x + 2
>> pretty(expand((x+1)/(x+2)))
                                   x         1
                                ------ + -------
                                x + 2     x + 2
>> pretty (expand (sin (x + y)))
                         sin(x) cos(y) + cos(x) sin(y)
>> pretty(expand(cos(2*x)))
                                         2
                                 2 cos(x)  - 1
>> pretty(expand(exp(a+log(b))))
                                    exp(a) b
>> pretty(expand(log(x/(1-x)^2)))
                            log(x) - 2 log(1 - x)
>> pretty(expand((x+1)*(y+z)))
                               x y + x z + y + z
>> pretty(expand(BesselJ(2,t)))
                            besselJ(1, t)
                        2 ------------------ - besselJ(0, t)
                                     t
>> maple('expandoff(exp):expand(exp(a+b))')
ans =

exp(a+b)
>> maple('expandon(exp):expand(exp(c+d))')
ans =

exp(c)*exp(d)

EXERCISE 2-1

Find the greatest common divisor of the following algebraic expressions a and b:

a = sin2(x) + 2 sin(x) + 1, b = sin(x) + 1

First, we try to solve the problem directly.

>> syms a b x
>> maple ('a: = sin (x) ^ 2 + 2 * sin (x) + 1, b: = sin(x) + 1:gcd(a,b)')

Error, (in gcd) arguments must be polynomials over the rationals.

To avoid this error, use the command frontend as follows:

>> maple('frontend(gcd,[a,b])')

ans =

sin (x) + 1

EXERCISE 2-2

Expand the polynomial (x+2)2(x-2) as much as possible modulo 3. Also expand the polynomial (x +α)2(x -α) where α = RootOf (x2- 2). At the same time, expand the polynomial (x +β)2(x -β) modulo 2 where β = RootOf (x2+x+1).

>> pretty(sym(maple('expand( (x+2)^2*(x-2) ) mod 3')))

                          3      2
                         x  + 2 x  + 2 x + 1

>> pretty(sym(maple('alias(a=RootOf(x^2-2)):evala(Expand( (x+a)^2*(x-a) ))')))

                          3      2
                         x  + a x  - 2 x - 2 a

>> pretty(sym(maple('alias(b=RootOf(x^2+x+1)):evala(Expand( (x+b)^2*(x-b) ) mod 2)')))


                          3          2
                         x  + x + b x  + b x + 1

The command alias is used to define abbreviations for objects, which helps to reduce the complexity of the output.

2-2. Factoring Expressions over Fields and their Algebraic Extensions

The following commands enable Maple to factorize algebraic expressions, whether univariate, multivariate, over the field of real numbers or over the field of their coefficients or algebraic extensions thereof. The command syntax is as follows:

  • factor(expr) writes an algebraic expression as a product of factors (the reverse of expand). Factoring is performed by default over the field or ring defined by the coefficients of the expression. For algebraic fractions, the numerator and denominator are individually factored and common factors are cancelled.
  • maple('factor(expression)') factorizes a non-polynomial or polynomial algebraic expression over the field or ring defined by its coefficients.
  • maple('factor(expr,a)')  factorizes the polynomial algebraic expression over the field defined by its coefficients and the extension element a (where a is usually a simple or compound radical or an algebraic number defined by a RootOf expression).
  • maple('factor(expression,radical)') factorizes the polynomial expression over the field extension Q(radical) of Q. For example, Q(√2) or Q(RootOf(x^2-3)).
  • maple('factor(expr,[rad1,..., radn]) or factor(expr, {rad1,..., radn})') factorizes the polynomial expression over the field extension Q(rad1,..., radn) of Q. For example, Q (√2,√3).
  • maple('factor(rational)') factorizes the numerator and denominator of the given rational expression, normalizing it.
  • maple('factor(equation)') factorizes both sides of an equation.
  • maple('factors(expression)') returns the factors and their multiplicities for the given polynomial algebraic expression, over the field defined by their coefficients.
  • maple('factors(expr,radical)') returns factors and their multiplicities for the given polynomial expression over the field extension Q(radical) of Q. For example,Q(√2) or Q(RootOf(x^2-3)).
  • maple('factors(expr,[rad1,..., radn]) or factors(expr, {rad1,..., radn})') gives the factors and their multiplicities for the given polynomial expression over the field Q(rad1,..., radn); for example, Q(√2, √3).
  • maple('factor(expr) mod n') performs the factorization of the given non-polynomial or polynomial expression over the field determined by its coefficients modulo n.
  • maple('Factor(expression)') gives in inert form the factorization of the given polynomial or non-polynomial expression over the field defined by its coefficients.
  • maple('Factors(expression)') represents in inert form the factors of the given polynomial expression.
  • maple('Factor(expr) mod n') performs the inert factorization of the given expression, whether non-polynomial or polynomial, over the field defined by its coefficients  modulo n.
  • maple('Factors(expression)') represents in inert form the factors of the given polynomial expression modulo n.
  • maple('AFactor(expression)') performs the inert absolute factorization of the given  expression.
  • maple('AFactors(expression)') represents in inert form the factors of the absolute factorization of the given polynomial expression.
  • maple('Berlekamp(expr,var)') represents the inert form of the Berlekamp factorization of varying degrees for the multivariate expression expr with respect to the variable var.
  • maple('Berlekamp(expr, var) mod n') represents the inert form of the Berlekamp factorization of varying degrees modulo n for the multivariate expression expr with respect to var.
  • maple('readlib(split):split(expr, variable)') performs the complete factorization of the given polynomial expression in the specified variable.
  • maple('grading(Inert_command(expr1,..., exprn))') evaluates the specified function or inert command over the field defined by the coefficients of the expressions. Applies to inert commands such as Factor, Factors, AFactor, AFactors, Expand, and so on.
  • maple('grading(Inert_command(expr1,..., exprn, n))') evaluates the specified function or inert command over  Z modulo n.
  • maple('value(expr_inert)') evaluates the given expression containing inert commands or functions of the type Diff, Int, Product, Sum or Limit.

Here are some examples:

>> syms x y
>> pretty(factor(6*x^2+18*x-24))
                               6 (x + 4) (x - 1)

In the following example we simplify the numerator and denominator of an algebraic fraction, cancelling common factors:

>> pretty (factor ((x^3-y^3) /(x^4-y^4)))
                                   2          2
                                 x  + y x + y
                               ---------------------
                                          2    2
                                (x + y) (x  + y   )

The following examples show factorizations of expressions over field extensions defined by the coefficients of the expression and the element(s) given in the second argument:

>> pretty(sym(maple('factor(x^3+5, 5^(1/3))')))
                           2    1/3      2/3        1/3
                        (x  - 5    x + 5   ) (x + 5   )
>> pretty(sym(maple('factor(x^3+5, {5^(1/3),(-3)^(1/2)})')))
                 1/3       1/2  1/3          1/3       1/2  1/3        1/3
     1/4 (2 x - 5    - (-3)    5   ) (2 x - 5    + (-3)    5   ) (x + 5   )
 >> pretty(sym(maple('factor(y^4-2,sqrt(2))')))
                              2    1/2    2    1/2
                            (y  + 2   ) (y  - 2   )
>> pretty (sym (maple ('factor (y^ 4-2, RootOf(x^2-2))')))
                   2            2         2            2
                 (y  + RootOf(_Z  - 2)) (y  - RootOf(_Z  - 2))

The following example highlights the difference between factoring a polynomial expression over the field defined by its coefficients and the extension of this field by (- 3) ^(1/2):

>> pretty (factor(x^3+y^3))
                                      2          2
                            (x + y) (x  - x y + y  )
>> pretty(sym(maple('factor(x^3+y^3,(-3)^(1/2))')))
                              1/2                  1/2
            1/4 (2 x - y - (-3)    y) (2 x - y + (-3)    y) (x + y)
>> pretty (sym (maple ('factor(x^3+5,complex)')))
 (x + 1.7099759466766969893531088725439). (x - .85498797333834849467655443627193
+ 1.4808826096823642385229974586353 +i)
(x -.85498797333834849467655443627193 - 1.4808826096823642385229974586353 i)

In the following examples we perform factorizations using factors. This command returns the factors together with their multiplicities.

>> maple('readlib(factors)'),
>> pretty(sym(maple('factors( 3*x^2+6*x+3 )')))
                          [3, [[x + 1, 2]]]
>> pretty(sym(maple('Digits:=10:factors( x^4-4.0 )')))
                                               2
[1.,[[x+1.414213562, 1], [x-1.414213562, 1], [x +1.999999999, 1]]]
>> pretty(sym(maple(factors( x^4-4.0,complex)')))
[1., [[x + 1.414213562, 1], [x + 1.414213562 i, 1], [x - 1.414213562 i, 1],
    [x - 1.414213562, 1]]]

The following are examples of the inert and complete factorization commands Factor, Factors, AFactor, AFactors, split and Berlekamp.

>> pretty(sym(maple('Factor(x^2+3*x+3) mod 7')))
                           (x + 6) (x + 4)
>> pretty(sym(maple('alias(sqrt2=RootOf(x^2-2)):evala(Factor(x^2-2,sqrt2))')))
                       (x + sqrt2) (x - sqrt2)
>> pretty(sym(maple('evala(Factor(x^2-2*y^2,sqrt2))')))
                     (x - sqrt2 y) (x + sqrt2 y)
>> pretty(sym(maple('expand((x^3+y^5+2)*(x*y^2+3)) mod 7')))
                4  2      3    7        5        2
               x  y  + 3 x  + y  x + 3 y  + 2 x y  + 6
>> pretty (sym (maple ('Factor ('') mod 7')))
                          3    5          2
                       (x  + y  + 2) (x y  + 3)
>> pretty(sym(maple('Factors(2*x^2+6*x+6) mod 7')))
                    [2, [[x + 4, 1], [x + 6, 1]]]
>> pretty(sym(maple('Factors(x^5+1) mod 2')))
                                     4    3    2
             [1, [[x + 1, 1], [x  + x  + x  + x + 1, 1]]]
>> pretty(sym(maple('evala(Factors(2*x^2-1,sqrt2))')))
            [2, [[x + 1/2 sqrt2, 1], [x - 1/2 sqrt2, 1]]]
>> pretty(sym(maple('alias(sqrtx=RootOf(y^2-x,y)):evala(Factors(x*y^2-1,sqrtx))')))
                         sqrtx         sqrtx
               [x, [[y + -----, 1], [- ----- + y, 1]]]
                           x             x
>> pretty (sym (maple ('grading (AFactor(x^2-2*y^2))')))
(x sqrt2 y) (x + sqrt2 y)
>> pretty (sym (maple ('grading (AFactors(x^2-2*y^2))')))
                   [1, [[x - sqrt2 y, 1], [x + sqrt2 y, 1]]]

The following are examples of complete and Berlekamp factorizations.

>> pretty(sym(maple('readlib(split):split(x^2+x+1,x)')))
                    2                              2
      (x - RootOf(_Z  + _Z + 1)) (x + 1 + RootOf(_Z  + _Z + 1))
>> pretty(sym(maple('split(x^2+y*x+1+y^2, x, b)')))
              2             2                    2               2
(x - RootOf(_Z +y _Z + 1 + y ))(x + y + RootOf(_Z  + y _Z + 1 + y ))
>> pretty(sym(maple('b')))
                              2               2
                    {RootOf(_Z  + y _Z + 1 + y )}
>> pretty(sym(maple('p:= 10^10-33:Berlekamp(x^4+2,x) mod p')))
     2                               2
   {x  + 6972444635 x + 9284865757, x  + 3027555332 x + 9284865757}

EXERCISE 2-3

Factorize the polynomial x3 + 5 in the algebraic extension defined by 51/3 and the algebraic extension defined by {51/3, √-3}. Also perform the complete factorization.

>> pretty(sym(maple('factor(x ^ 3 + 5, 5 ^(1/3))')))

                          2    1/3      2/3        1/3
                        (x  - 5    x + 5   ) (x + 5   )

>> pretty(sym(maple('factor(x^3+5, {5^(1/3),(-3)^(1/2)})')))

                 1/3      1/2  1/3          1/3      1/2  1/3        1/3
     1/4 (2 x - 5    + i 3    5   ) (2 x - 5    - i 3    5   ) (x + 5   )

>> pretty(sym(maple('readlib(split):split(x^3+5,x)')))

              2            3        3           2
(x - RootOf(_Z  + RootOf(_Z  + 5) _Z + RootOf(_Z  + 5) ))
                 3                 2            3        3           2
   (x + RootOf(_Z  + 5) + RootOf(_Z  + RootOf(_Z  + 5) _Z + RootOf(_Z  + 5) ))

                  3
    (x - RootOf(_Z  + 5))

EXERCISE 2-4

Find the factors and their multiplicities for the polynomial x4 - 4 over the real numbers, complex numbers, the algebraic extension defined by √2, the algebraic extension defined by {√2,i}, the algebraic extension defined by α = RootOf(x2-2), the algebraic extension defined by β = RootOf (x2+ 2), and the algebraic extension defined by {α, β }.

>> pretty(sym(maple('readlib(factors):factors( x^4-4 )')))

                           2           2
                   [1, [[x  - 2, 1], [x  + 2, 1]]]

>> pretty(sym(maple('readlib(factors):factors( x^4-4, complex)')))

[1, [[x + 1.414213562 i, 1], [x + 1.414213562, 1],
    [x - 1.414213562 i, 1], [x - 1.414213562, 1]]]

>> pretty(sym(maple('readlib(factors):factors( x^4-4, sqrt(2) )')))

                         1/2             1/2        2
               [1, [[x - 2   , 1], [x + 2   , 1], [x  + 2, 1]]]

>> pretty(sym(maple('readlib(factors):factors( x^4-4, {sqrt(2), i } )')))

                  1/2              1/2            1/2            1/2
     [1, [[x - i 2   , 1], [x + i 2   , 1], [x - 2   , 1], [x + 2   , 1]]]

>> pretty(sym(maple('readlib(factors):alias(a=RootOf(x^2-2)): alias(b=RootOf(x^2+2)):factors( x^4-4, a )')))

                                                 2
                  [1, [[x - a, 1], [x + a, 1], [x  + 2, 1]]]

>> pretty(sym(maple('readlib(factors):factors( x^4-4, b )')))

                                                 2
                  [1, [[x + b, 1], [x - b, 1], [x  - 2, 1]]]

>> pretty(sym(maple('readlib(factors):factors( x^4-4, {a,b} )')))

             [1, [[x + b, 1], [x - a, 1], [x + a, 1], [x - b, 1]]]

EXERCISE 2-5

Let α = RootOf(x2 + x + 1) and β = RootOf(y2 - x, y). Factorize modulo 2 the univariate polynomial x3 + 1 over the algebraic extension defined by α . Factorize modulo 5 the bivariate polynomial x2+ 2xy + y2 + 1 + x + y over the algebraic extension defined by α . Factorize  modulo 5 the following bivariate polynomial: x2y + xy2 + 2αxy + α2 + 4xαx + y +α. Find the factors and their multiplicities modulo 5 for the bivariate polynomial x2y + xy2 + 2αxy +α2+ 4 xαx + y +α. Find the factors and their multiplicities modulo 2 for the univariate polynomial x5 + 1 over the algebraic extension defined by α . Factorize the bivariate polynomial xy2 - 1 over the algebraic extension defined by β .

>> pretty(sym(maple('alias(a=RootOf(x^2+x+1)):Factor(x^3+1,a) mod 2')))

                      (x + a + 1) (x + 1) (x + a)

>> pretty (sym (maple ('Factor(x^2+2*x*y+y^2+1+x+y,a) mod 5')))

                         (y + x + 4) (y + x + a + 1)

>> pretty (sym (maple ('Factor(x^2*y+x*y^2+2*a*x*y+a*x^2+4*a*x+y+a) mod 5')))

                          (x+ x + 1) (y + x + a)

>> pretty (sym (maple ('Factors(x^2*y+x*y^2+2*a*x*y+a*x^2+4*a*x+y+a) mod 5')))

                   [1, [[x y + x + 1, 1], [y + x + a, 1]]]

>> pretty (sym (maple ('Factors(x^5+1,a) mod 2')))

                           2                        2
        [1, [[x + 1, 1], [x + (a + 1) x + 1, 1], [x + x + 1, 1]]]

>> pretty (sym (maple ('alias (b = RootOf(y^2-x,y)):evala(Factor(x*y^2-1,b))'))))))

                             x (y - b/x) (b/x + y)

EXERCISE 2-6

Let p = x6 + x5 + x4 + x3 + 2x2 + 2 x + 1. Find the Berlekamp factorization of p modulo 2. Also factorize the bivariate algebraic expression x4y2 + 3x3+ y7x +3y5 + 2xy2 + 6 over the field defined by its coefficients.

>> pretty(sym(maple('p:=x^6+x^5+x^4+x^3+2*x^2+2*x+1:Berlekamp(p,x) mod 2')))

                         4          2
                       {x + x + 1, x + x + 1}

>> pretty(sym(maple('factor(x^4*y^2+3*x^3+y^7*x+3*y^5+2*x*y^2+6)')))

                               2       3   5
                           (x y + 3) (x + y + 2)

2-3. Simplifying Algebraic Expressions

The following commands enable MATLAB to simplify algebraic expressions:

  • simplify(expr) simplifies an algebraic expression as much as possible. It sums algebraic fractions, but does not completely simplify them.
  • simplify(expr, rule1, rule2,..., rulen) simplifies the expression taking into account the rules specified. The possible values of the rules are Ei, GAMMA, atsign, hypergeom, ln, polar, power, radical, sqrt and trig, which allow simplification of expressions containing the exponential integral, gamma functions, functional operators, hypergeometric functions, logarithms, polar functions, powers, radicals, square roots and trigonometric functions, respectively.
  • simplify(expr,assume=property) simplifies the expression taking into account the specified mathematical property.
  • simplify(expr,symbolic) simplifies the expression so that all radical subexpressions are positive.
  • R = simple('expr') returns the most simplified form R of the algebraic expression. This is the most efficient command to completely simplify an algebraic fraction.
  • [R, HOW] = simple('expr') returns the most simplified form R of the given algebraic expression together with a list HOW  describing the path followed to reach the simplification (i.e. the commands used).
  • maple ('simplify(expression,option1,...,optionn)') simplifies the given algebraic expression using the specified options. Valid options are atsign, Ei, exp, GAMMA, Hypergeom, ln, polar, power, radical, RootOf, sqrt, trig, symbolic, &*, piecewise and assume.
  • maple('simplify(expression,atsign) or simplify(expression, '@')') simplifies expressions containing functional operators, such as the composition of functions and inverse functions. It is particularly useful when simplifying inversefunction ( function (x)) = x.
  • maple('simplify(expression,polar)') simplifies complex expressions by passing them to polar form and applying the rules of complex operations. If necessary, the complex expression must first be simplified to its polar form with convert(expression,polar) before applying the simplification.
  • maple('simplify(expression,power)') simplifies algebraic expressions containing potential, exponential, and logarithmic functions, applying typical rules of simplification, such as (a ^ b) ^ c = a ^(b*c), ln(x*y) = ln (x) + ln (y) and exp (a * ln (x) + 1) =(x^a) * exp (1).
  • maple('simplify(expr,exp)') simplifies algebraic expressions that contain base e exponential functions,  by applying typical rules of simplification such as ex *ey = e^ (x + y) , (e ^ x) ^ a = e ^(x*a) and e ^ (x+ln (y)*n) =(e^x) * (y ^ n).
  • maple('simplify(expr,radical)') simplifies algebraic expressions containing radicals or fractional powers, applying typical rules of simplification.
  • maple('simplify(expr,radical,symbolic)') simplifies algebraic expressions containing radicals or fractional powers, applying typical rules of simpllification and assuming that all the radicals are positive.
  • maple('simplify(expr,RootOf)') simplifies algebraic expressions containing terms of type RootOf.
  • maple('simplify(expr,sqrt)') simplifies algebraic expressions containing square roots or fractional powers of denominator 2, applying typical rules of simplification.
  • maple('simplify(expr,ln)') simplifies algebraic expressions containing logarithms, applying typical rules such as ln(a^r) = r * ln (a), ln(a*b) = ln (a) + ln (b), ....
  • maple('simplify(expr,trig)') simplifies trigonometric algebraic expressions, applying the typical trigonometric rules such as sin(x) ^ 2 + cos(x)^2 = 1, cosh (x) ^ 2-sinh (x) ^ 2 = 1, tan(x) = sin (x) /cos (x) and 1 + tan (x) ^ 2 = 1/cos (x) ^ 2.
  • maple('simplify(expr,Ei)') simplifies algebraic expressions that include functions of the type Ei, Si and Ci, using the existing relationships between them. Sometimes, it is convenient to apply convert(expr, Ei) before applying this type of simplification.
  • maple('simplify(expr,GAMMA)') simplifies algebraic expressions involving GAMMA-like functions using the existing relationships between the same. Sometimes, it is convenient to apply convert(expr, GAMMA)  before applying this type of simplification
  • maple('simplify(expression,hypergeom)') simplifies algebraic expressions involving functions of the type hypergeom using existing relations between the same. Sometimes, it is convenient to apply convert(expr, hypergeom) before applying this type of simplification.
  • maple('simplify(expression,piecewise)') simplifies algebraic expressions involving piecewise-defined functions.
  • maple('simplify(expr,' &* ')') simplifies algebraic expressions that include the &* operator.
  • maple('simplify(expr,{equ1,...,equn})') or maple ('simplify(expr,[equ1,...,equn])') simplifies the given algebraic expression subject to the specified equations.
  • maple('simplify(expression,inequality _variable)') simplifies the given algebraic expression assuming the specified inequality in some given variable. For example, simplify(expression, a> 0).
  • maple('simplify(expression,variable=type)') simplifies the given algebraic expression assuming that all the variables are of the type specified (for example, assume = real assume = positive, and so on). In general, the type can be any option of the command type.
  • maple('simplify(expression,assume(variable,property))') simplifies the given algebraic expression, assuming the property specified for the specified variable (for example, integer, rational, and so on.). In general, the property can be any option of the command type.
  • maple('simplify(expr,assume(variable, AndProp(prop1,...,propn)))') simplifies the given algebraic expression by assuming all the given properties prop1,..., propn for the specified variable.
  • maple('simplify(expr,assume(variable, OrProp(prop1,...,propn)))') simplifies the given algebraic expression by assuming some of the properties prop1,..., propn for the specified variable.
  • maple('simplify(expression,assume(variable, RealRange(a,b)))') simplifies the given algebraic expression by assuming that the variable varies in the real closed interval [a, b].
  • maple('simplify(expr,assume(variable, RealRange(Open(a),Open(b))))') simplifies the given algebraic expression by assuming that the variable varies in the  interval (a, b).
  • maple('simplify(expr, assume(variable, RealRange(Open(a),b)))') simplifies the given algebraic expression by assuming that the variable varies in the interval (a, b].
  • maple('simplify(expr,assume(variable, RealRange(a,Open(b)))') simplifies the given algebraic expression by assuming that the variable varies in the interval [a,b).

We give several examples which involve the command simplify:

>> syms x y b c
>> simplify (sin (x) ^ 2 + cos (x) ^ 2)
ans =

1
>> simplify(exp(a+log(b*exp(c))))
ans =
b*exp(a+c)
>> pretty(sym(maple('simplify((x^a)^b+4^(1/2), power)')))
                                  (a b)
                                 x      + 2
>> pretty (sym (maple ('simplify (sin (x) ^ 4 + 2 * cos (x) ^ 2 - 2 * sin (x) ^ 2 - cos(2*x), trig)')))
                                          4
                                    cos(x)
>> pretty (sym (maple ('simplify(-1/3*x^5*y+x^4*y^2+1/3*x*y^3+1, {x^3=x*y, y^2=x+1})')))
                               5   4   2        3
                          1 + y + y - y + y - 2y
>> pretty (sym (maple ('simplify (((x-1) ^ 2) ^(3/2) * sqrt(a^2), assume(x-1>0))')))
                                      3
                              (x~ - 1)  csgn(a) a

The tilde (~) that appears at the top-right of the variable x indicates that a condition x has been assumed.

>> pretty(sym(maple('simplify(exp(5*ln(x)+1), power)')))
                               5
                              x  exp(1)
>> pretty (sym (maple ('simplify (cos (x) ^ 5 + sin (x) ^ 4 + 2 * cos (x) ^ 2 - 2 * sin (x) ^ 2 - cos(2*x))')))
                                5         4
                          cos(x)  + cos(x)
>> pretty (sym (maple ('simplify(-1/3*x^5*y + x^4*y^2 + 1/3*x*y^3 + 1,{x ^ 3 = x * y, y ^ 2 = x + 1})')))
                          5    4    2          3
                     1 + y  + y  - y  + y - 2 y
>> pretty(sym(maple('simplify((x+1)^(4/3)-x*(x+1)^(1/3),radical)')))
                                     1/3
                              (x + 1)
>> pretty(sym(maple('simplify(Ei(1,i*x)+Ei(1,-i*x),Ei)')))
                             -2 cosint(x)
>> pretty(sym(maple('simplify(n!/((2*n)^2)!, GAMMA)')))
                                 gamma(n + 1)
                                ---------------
                                         2
                                gamma(4 n  + 1)

We now give some examples of how the simple command works:

>> pretty (sym (simple (cos (3 * acos (x)))))
                                       3
                                   4 x  - 3 x
>> [R, HOW] = simple (cos (3 * acos (x)))
R =

4 * x ^ 3-3 * x

HOW =

expand

In the latter case, the command that led to the final simplification was expand:

>> pretty (simple (cos (x) + (-sin (x) ^ 2) ^(1/2)))
                               cos(x) + i sin (x)
>> pretty(simple((x^2-y^2) /(x-y) ^ 3))
                                      x + y
                                    ----------
                                            2
                                    (x - y)

EXERCISE 2-7

Given the functions g(x) = sqrt x2 and e(x) =(-8ab3)1/3, simplify them as much as possible. Perform the simplification of g(x) for a real argument and a positive argument. Also simplify e(x) for positive radical and then negative b.

>> pretty(sym(maple('simplify(sqrt(x^2))')))

                              csgn(x) x

>> pretty(sym(maple('simplify(sqrt(x^2),assume=real)')))

                             signum(x) x

>> pretty(sym(maple('simplify(sqrt(x^2),assume=positive)')))

                                  x

>> pretty(sym(maple('simplify((-8*b^3*a)^(1/3))')))

                                  3   1/3
                             2 (-b  a)

>> pretty(sym(maple('simplify((-8*b^3*a)^(1/3),radical,symbolic)')))

                                      1/3
                             2 b (-a)

>> pretty(sym(maple('simplify((-8*b^3*a)^(1/3),assume(b<0),radical)')))

                                      1/3
                              -2 b~ a

EXERCISE 2-8

Directly simplify the expression ((x-1)2)3/2 (a2)1/2. Then simplify it assuming the condition that x > 1. Finally, perform a simplification assuming in addition that a > 0.

>> pretty(sym(maple('simplify(((x-1) ^ 2) ^(3/2) *(a^2) ^(1/2))')))

                                       3
                    csgn(x - 1) (x - 1)  csgn(a) a

>> pretty(sym(maple('simplify(((x-1)^2)^(3/2)*(a^2)^(1/2),assume(x>1))')))

                                 3
                         (x~ - 1)  csgn(a) a

>> pretty(sym(maple('simplify(((x-1)^2)^(3/2)*(a^2)^(1/2), assume(x>1,a>0))')))

                                     3
                             (x~ - 1)  a~

The last expression also can be simplified without assignments, assuming positive radicals with the option symbolic.

>> pretty(sym(maple('simplify(((x-1)^2)^(3/2)*(a^2)^(1/2),symbolic)')))

                                     3
                              (x - 1)  a

2-4. Combining Algebraic Expressions

MATLAB allows you to combine terms composed of functions of certain types within an algebraic expression, in order to simplify the expression as much as possible after grouping. Among the commands that enable you to do this are the following (always preceded by the command maple):

  • combine(expression) combines terms that contain functions in the given algebraic expression; they may be exponential, logarithmic, trigonometric, sums (Sum), products (Prod), limits (Limit), integrals (Int), derivatives (Diff), and so on. Once the combination or grouping of terms is done according to the different types of functions, there is an overall simplification. Combine can be considered the reverse of expand; for example, expand transforms sin (a + b) into sin (a) * cos (b) + cos (a) * (b) and combine does the opposite.
  • combine(expression,option1,...,optionn) combines terms in the given expression using the specified options. The valid options are atsign, Psi, exp, artan conjugate, polylog, ln, product, power, plus range, RootOf, sqrt, trig, signum, radical,  abs and piecewise.
  • combine(expression,atsign) or combine(expression, '@') combines expressions that contain functional operators, such as the composition of functions and inverse functions. It is particularly useful when simplifying inversefunction(function (x)) = x.
  • combine(expression,product) combines expressions that contain products.
  • combine(expression,plus) combines expressions that contain sums.
  • combine(expression,artan) combines expressions that contain arctangent functions.
  • combine(expression,conjugate) combines expressions by grouping terms with their conjugates.
  • combine(expression,power) combines terms of expressions containing exponential functions, potentially by applying rules such as (x ^ y) *(x^z) = x ^ (y+z), (x ^ y) ^ z = x ^(y*z), √ -a = i *√a .
  • combine(expression,radical) combines terms of expressions that contain radicals or fractional powers, applying the typical rules for working with radicals.
  • combine(expression,radical,symbolic) combines terms of expressions that contain radicals or fractional powers, applying the typical rules for working with radicals and assuming that all the radicals are positive.
  • combine(expression,abs) combines terms of expressions that contain absolute values (moduli).
  • combine(expression,signum) combines terms of expressions that contain the function signum.
  • combine(expression,ln) combines terms of expressions that contain logarithms, applying the typical rules of working with logarithms, such as r * ln (a) = ln(a^r),  ln (a) + ln (b) = ln(a*b), and so on.
  • combine(expression,trig) combines terms of trigonometric expressions, eliminating products and powers of sines and cosines, hyperbolic sines and hyperbolic cosines, using multiple angle trigonometric rules such as sin (a) * cos (b) = sin ((a + b) / 2) + sin ((a-b)/2) or sinh (a) * sinh (b) = cosh ((a + b) / 2)-cosh ((a-b)/2).
  • combine(expression,Psi) combines terms of expressions that include functions of the type Psi, applying rules such as   Ψ(n) (z + 1) =  Ψ( n) (z) +(-1)n n! z(- n - 1 ).
  • combine(expression,range) combines terms of expressions that include ranges.
  • combine(expression,polylog) combines terms of expressions that include polylogarithmic functions, using the existing relationships between them.
  • combine(expression,exp) combines expressions that contain base e exponential functions, applying the typical rules for them such as (e ^ x) *(e^y) = e ^ (x + y) , (e ^ x) ^ a = e ^(x*a) and e ^ (x+ln (y)*n) =(e^x) * y^ n.
  • combine(expression,piecewise) combines terms of expressions involving piecewise-defined functions.
  • combine(expression, ln, type) combines terms of expressions that include logarithmic functions, only simplifying expressions whose coefficients are of the given type.

Here are some examples:

>> pretty(sym(maple('combine(4 * sin (x) ^ 3, trig)')))
                         -sin(3 x) + sin (x) 3
>> pretty(sym(maple('combine(exp(x) ^ 2 * exp(y), exp)')))
                             exp(2 x + y)
>> pretty(sym(maple('assume(y>0,z>0):combine(2*ln(y)-ln(z),ln)')))
                                    2
                                  y~
                               ln(---)
                                  z~
>> pretty(sym(maple('combine((x^a)^2,power)')))
                                 (2 a)
                                x
>> pretty(sym(maple('combine(Psi(-x)+Psi(x),Psi)')))
                    2 Psi(x) + Pi cot(Pi x) + 1/x
>> pretty(sym(maple('combine([2*sin(x)*cos(x),2*cos(x)^2-1],trig)')))
                         [sin(2 x), cos(2 x)]
>> pretty(sym(maple('combine(Int(x,x=a..b)-Int(x^2,x=a..b))')))

image

>> pretty(sym(maple('combine(Limit(x,x=a)*Limit(x^2,x=a)+c)')))

image

>> pretty(sym(maple('combine(conjugate(x) ^ 3 + 3 * conjugate(y) * conjugate(z), conjugate)')))

                                   3
                                  x  + 3 y z
>> pretty(sym(maple('combine(x^3*x^(m-3),power)')))
                                   m
                                  x
>> pretty(sym(maple('combine((3^n)^m*3^n,power)')))
                                 n m  n
                               (3 )  3
>> pretty(sym(maple('assume(m,integer):combine((3^n)^m*3^n,power)')))
                              (n m~ + n)
                             3
>> pretty(sym(maple('combine(exp(x)^7*exp(y),power)')))
                             exp(7 x + y)
>> pretty(sym(maple('combine(piecewise(x > 0, cos(x) ^ 2 + sin(x) ^ 2, exp(x) ^ 2 * exp(y)))')))
                     | exp(2 x + y)        x <= 0
                     image
                     |      1              0 < x
>> pretty(sym(maple('combine(piecewise(x<1, exp(x)*exp(-2*x), x>3, 4*sin(x)^3))')))
                 |       exp(-x)              x < 1
                 |
                 image          0                 x <= 3
                 |
                 | 3 sin(x) - sin(3 x)        3 < x
>> pretty(sym(maple('combine(b*ln(y)+3*ln(y)-ln(1-y)+ln(1+y)/2, ln,anything,symbolic)')))
                                 b  3        1/2
                                y  y  (1 + y)
                             ln(----------------)
                                     1 – y

EXERCISE 2-9

Simplify as much as possible the trigonometric-exponential expression exp (sin (a) * cos (b)) * exp (cos (a) * (b), as well as the polylogarithmic expression polylog(a, x) + polylog(a,-x).  Simplify the polylogarithmic expression defined by polylog(4,x) + polylog(4,1/x) assuming first that x > 1, and secondly that x is between - 1 and 1.

>> maple combine (exp (sin (a) * cos (b)) * exp (cos (a) * (b)), [trig, exp])

                           exp(sin(a + b))

>> maple combine(polylog(a,x)+polylog(a,-x),polylog)

                        (1 - a)             2
                       2        polylog(a, x )

>> pretty(sym(maple('polylog(4,x) + polylog(4,1/x)')))

                   polylog(4, x) + polylog(4, 1/x)

>> pretty(sym(maple('assume(x > 1):combine(polylog(4,x) + polylog(4,1/x), polylog)')))

                         2   2           4               4
           - 1/12 ln(-x~)  Pi  - 7/360 Pi  - 1/24 ln(-x~)

>> pretty(sym(maple('assume(x, RealRange(-1,1)):combine(polylog(4,x) + polylog(4,1/x),polylog)')))

                     1   2   2           4              1   4
        - 1/12 ln(- ----)  Pi  - 7/360 Pi  - 1/24 ln(- ----)
                     x~                                 x~

EXERCISE 2-10

Simplify the following expressions as much as possible:

image, image, image

>> pretty(sym(maple('combine(sqrt(2)*sqrt(6) + sqrt(2)*sqrt(x+1),radical)')))

                                1/2            1/2
                             2 3    + (2 x + 2)

>> pretty(sym(maple('combine(sqrt(4-sqrt(3))*sqrt(4+sqrt(3)),radical)')))

                                       1/2
                                     13

>> pretty(sym(maple('combine(sqrt(x)*sqrt(y) + sqrt(2)*sqrt(x+1)^3*sqrt(y), radical)')))

                      1/2  1/2            1/2          1/2
                     x    y    + (x + 1) y    (2 x + 2)

EXERCISE 2-11

Combine terms as much as possible in the following expression:

a * ln(x) + 3 * ln(x) - ln(1-x) + ln(1+x)/2

Simplify assuming that is real and x > 0. Additionally, try to simplify assuming that x is real and that it varies between 0 and 1.

>> pretty(sym(maple('combine(a*ln(x)+3*ln(x)-ln(1-x)+ln(1+x)/2,ln)')))

            a ln(x) + 3 ln(x) - ln(1 - x) + 1/2 ln(1 + x)

>> pretty(sym(maple('assume(a,real):assume(x>0):combine(a*ln(x)+3*ln(x) -ln(1-x)+ln(1+x)/2,ln)')))

                                                3         1/2
                 a~ ln(x~) - ln(1 - x~) + ln(x~  (x~ + 1)   )

>> pretty(sym(maple('assume(a,real):assume(x,RealRange(0,1)): combine(a*ln(x)+3*ln(x)-ln(1-x)+ln(1+x)/2,ln)')))

                                                  3         1/2
                                               x~  (x~ + 1)
                               a~ ln(x~) + ln(---------------)
                                                   1 - x~

The additional assumption does not improve the result.

EXERCISE 2-12

Expand and simplify  the following trigonometric expressions as much as possible:

(a) sin[3 x] cos[5 x]

(b) cot[a]2 + (sec[a])2 - (csc[a])2

(c) sin[a] / (1 + cot[a]2) - sin[a]3

>>  pretty(sym(maple('combine(sin(3*x)*cos(5*x),trig)')))

                          1/2 sin (x 8) - 1/2 sin (2 x)

>>  pretty(sym(maple('simplify((cot(a))^2+(sec(a))^2-(csc(a))^2, trig)')))

                                         2
                                   cos(a) - 1
                                 - --------------
                                           2
                                     cos(a)

>> pretty(sym(maple('simplify(sin(a)/(1 + cot(a) ^ 2)-sin(a) ^ 3, trig)')))

                                       0

EXERCISE 2-13

Simplify the following trigonometric expressions as much as possible:

(a) sin[3 Pi/2 + a] cot[3 Pi/2] / cot[3 Pi/2 + a] + tan[3 Pi/2] cot[Pi/2 + a] / sin[3 Pi/2 + a] cot[-a]

(b) (a2 - b2) cot[Pi-a] / tan[Pi/2] - (a2 + b2) tan[Pi/2-a] / cot[Pi-a]

(c) (cot[a] + tan[a]) / (cot[a]-tan[a]) - sec[2a]

(d) sin[a-b] cos[c] + sin[b- c] cos[a] + sin[c-a] cos[b]

>> pretty(sym(maple('simplify(sin(3*Pi/2+a)*cot(3*Pi/2-a)/cot(3*Pi/2+a)+
(tan(3*Pi/2-a) * cot(Pi/2+a) /sin(3*Pi/2+a) * cot(-a), trig)')))

                               cos(a) sin (a) - 1
                               ----------------------
                                     sin(a)

>> pretty(sym(maple('combine(sin(3*Pi/2+a)*cot(3*Pi/2-a)/cot(3*Pi/2+a)+
(tan(3*Pi/2-a) * cot(Pi/2+a) /sin(3*Pi/2+a) * cot(-a), trig)')))

                                                2
                        cos(2 a) + 1 - 2 cot (a) tan (a)
                 1/2 -------------------------------
                                 cos(a)

>> pretty(sym(maple('simplify((a^2-b^2)*cot(Pi-a)/tan(Pi/2-a)-
(a^2+b^2)*tan(Pi/2-a)/cot(Pi-a),trig)')))

                                    2
                                 2 b

>> pretty(sym(maple('combine((a^2-b^2)*cot(Pi-a)/tan(Pi/2-a)-
(a^2+b^2)*tan(Pi/2-a)/cot(Pi-a),trig)')))

                                    2
                                 2 b

>>  pretty(sym(maple('simplify((cot(a)+tan(a))/(cot(a)-tan(a))-sec(2*a), trig)')))

                                       0

>> pretty (sym (maple ('combine (sin(a-b) * cos(c) + sin(b-c) * cos(a) +
sin(c-a) * cos(b), trig)')))

                                       0

In general, you will get the most efficient simplification of trigonometric expressions using the commands combine and simplify, with the option trig.

2-5. Grouping of Similar Terms in Algebraic Expressions

MATLAB allows you to group terms within algebraic expressions according to specified variables. This helps to simplify the expression and possibly to optimize performance. Among the commands that enable the grouping of similar terms in algebraic expressions, we have the following:

  • maple('collect(expr,x)') gathers the polynomial algebraic expression in ordinate powers of the variable x. If the variable is not specified, it takes by default the main symbolic variable.
  • maple('collect(expr,[x,y])') gathers the polynomial algebraic expression in ordinate powers of the variables x and y.
  • maple('collect(expr,f(x))') gathers the algebraic expression in ordinate powers of a function f(x) contained in the expression.
  • maple('collect(expr,var)') organises the algebraic expression, taking as the main variable the variable var. It gathers terms with respect to the variable.
  • maple('collect(expr,[var1,..,varn])') or maple('collect(expr,{var1,...,varn})') organizes the algebraic expression and gathers terms for the given variables.
  • maple('collect(expr,expr1)') organizes the algebraic expression expr by grouping in terms of expr1, where expr1 is typically a sin(x) or exp(2*x) function.
  • maple('collect(expr,[var1,...,varn],distributed)')  organizes the algebraic expression grouping terms by the given variables and presenting the result as polynomial expanded as a sum of terms. Each term of the sum is a product of powers of the specified variables, the coefficient of the term being a constant or any expression in terms of unspecified variables (which are considered constants in this case).
  • maple('collect(expr,[var1,...,varn],recursive)') organizes the algebraic expression by grouping terms with respect to the variables given in a hierarchical manner; that is, it first groups terms with respect to the variable var1, then uses the resulting expression to group terms with respect to the variable var2, and so on.
  • maple('collect(expr,[var1,...,varn],option,command)') organizes the algebraic expression grouping terms with respect to the variables given according to the specified option (distributed or recursive). Organizing occurs once the specified command has been applied to each coefficient of the expression. Any command can be used, but it is usually one that works with algebraic expressions (factor, expand, and so on).

Let’s see some examples of the command collect:

>> syms x y z p a
>> pretty(collect( (x+1)*(x+2) ))
                                    2
                                  x + 3 x + 2
>> pretty (collect (y * (sin (x) + 1) + sin (x), sin (x)))
                               (y + 1) sin(x) + y
>> pretty(collect(x^3*y+x^2*y^3+x+3, y))
                               3      2  3
                              x  y + x  y  + x + 3
' p = x * y+ z * x * y+ y* x ^ 2-z * y* x ^ 2 + x + z * x;
>> pretty(collect(p, [x,y]))
                                       2        2
                     x y + z x y + y x  - z y x  + x + z x
>> f = a*log(x)-log(x)*x-x;
>> pretty(collect(f,log(x)))
                          (a - x) ln(x) - x
>> g = int(x^2*(exp(x)+exp(-x)),x);
>> pretty(collect(g,exp(x)))
                                                 2
                           2                 -2 x - 2 - x
                     (2 + x  - 2 x) exp(x) + -------------
                                             exp(x)
>> pretty (sym (maple ('collect(x*y+a*x*y+y*x^2-a*y*x^2+x+a*x, [x,y], recursive)')))
                           2
                 (1 - a) y x  + ((1 + a) y + 1 + a) x
>> pretty (sym (maple ('collect(x*y+a*x*y+y*x^2-a*y*x^2+x+a*x, [y,x], recursive)')))
                          2
                ((1 - a) x  + (1 + a) x) y + (1 + a) x
>> pretty (sym (maple ('collect(x*y+a*x*y+y*x^2-a*y*x^2+x+a*x, [x,y], distributed)')))
                                                     2
                (1 + a) x + (1 + a) x y + (1 - a) y x

EXERCISE 2-14

Given the function f (x) = a3x - x + a3 + a, group terms in the variable x, and then factorize the coefficients. Group terms in x for the function p (x) = y/x+2z/x+x1/3- y1/3x.

>> syms a x y z
>> pretty(collect(a^3*x-x+a^3+a, x))

                           3           3
                         (a  - 1) x + a  + a

>> pretty(sym(maple('collect(a^3*x-x+a^3+a, x,factor)')))

                           2                  2
                 (a - 1) (a  + a + 1) x + a (a  + 1)

>> pretty (collect (y/x+2 * z/x + x ^(1/3) - y* ^(1/3) x, x))

                                 1/3     y + 2 z
                        (1 - y) x    +   -------
                                            x

EXERCISE 2-15

Given the following differential expression:

image

Group terms in differentials. Subsequently, group terms into sines.

>> pretty (sym (maple ('DF: = diff (y (x), x, x) * sin (x) - diff (y (x), x) * sin (y(x)) + sin (x) * diff (y (x), x) + sin (y (x)) * diff (y (x), x, x)')));
>> pretty(sym(maple('collect(DF,diff)')))

                                                               / 2      
                              /d                              |d       |
      (-sin(y (x)) + sin(x)) | - y (x) | +(sin(x) + sin(y(x))) |- y (x) |
                              dx     /                        |  2     |
                                                               dx      /

>> pretty(sym(maple('collect(DF,sin)')))

     /             / 2      \             // 2                  
     | /d         |d       ||             ||d       |   /d      |
     |-|-- y(x)| + |--- y(x)|| sin(y(x)) + ||--- y(x)| + |-- y(x)|| sin(x)
     | dx     /   |  2     ||             ||  2     |   dx     /|
                  dx      //             \dx      /            /

2-6. Sorting Terms in Algebraic Expressions

MATLAB also allows the sorting of terms within algebraic expressions in terms of specified variables. This helps to generate the best possible expression for optimal performance. Among the commands that enable the management of terms in algebraic expressions are the following:

  • maple('sort(expression)') sorts the terms of the multivariate algebraic polynomial expression according to the degrees of all terms of the expression (in descending order). The degree of a term equals the sum of the exponents of its variables.
  • maple('sort(expr,plex)') performs the ordering of the algebraic expression for all the indeterminates using pure lexicographic order (the dictionary order) for each component of the algebraic expression.
  • maple('sort(expr,tdeg)') performs the ordering of the algebraic expression with respect to all the indeterminates using the total degree for each term component of the algebraic expression. For example, the total degree of  is 10. (This is the default option.)
  • maple('sort(expr,[var1,...,varn],option)') or maple('sort(expr,{var1,...,varn},option)') performs the ordering of the multivariate polynomial algebraic expression with respect to the indeterminates var1,..., varn, according to the specified option (plex or tdeg).
  • maple('sort(list)') or maple('sort(list,lexorder)') or maple('sort(list,string)') sorts the elements of a list using lexicographical order.
  • maple('sort([var1,...,varn])') or maple(‘sort(list,'<')’) or maple('sort(list,numeric)') sorts numeric values specified in the list in descending numerical order.
  • maple('sort(list,address)') sorts the elements of the list according to their internal addresses assigned by MATLAB.

Here are some examples:

>> pretty(sym(maple('sort([3,2,1])')))
                              [1, 2, 3]
>> pretty(sym(maple('sort(1+x+x^2)')))
                               2
                              x  + x + 1
>> pretty(sym(maple('sort([c,a,d],lexorder)')))
                              [a, c, d]
>> pretty(sym(maple('sort(y^3+y^2*x^2+x^3,[x,y])')))
                            2  2    3    3
                           x  y  + x  + y
>> pretty(sym(maple('sort(y^3+y^2*x^2+x^3,[x,y],plex)')))
                            3    2  2    3
                           x  + x  y  + y
>> pretty(sym(maple('sort((y+x)/(y-x),x)')))
                                x + y
                                ------
                                -x + y
>> pretty(sym(maple('sort(x+x^3+w^5+y^2+z^4,[w,x,y,z])')))
                         5    4    3    2
                        w  + z  + x  + y  + x
>> pretty(sym(maple('sort(x+x^3+w^5+y^2+z^4,[w,x,y,z],plex)')))
                         5    3        2    4
                        w  + x  + x + y  + z
>> pretty(sym(maple('sort(x+x^3+w^5+y^2+z^4,[w,x,y,z],tdeg)')))
                         5    4    3    2
                        w  + z  + x  + y  + x
>> pretty(sym(maple('sort(x*y^5+x^3*y*z+w^5*y^3+y^2*z^4+z^4,[w,x,y,z],plex)')))
                   5  3    3          5    2  4    4
                  w  y  + x  y z + x y  + y  z  + z
>> pretty(sym(maple('sort(x*y^5+x^3*y*z+w^5*y^3+y^2*z^4+z^4,[w,x,y,z],tdeg)')))
                   5  3      5    2  4    3        4
                  w  y  + x y  + y  z  + x  y z + z

2-7. Algebraic Fractions

MATLAB also enables you to work fluidly with algebraic fractions. Among the commands that can be used we have the following (all of which must be preceded by the command maple):

  • normal(exprational) simplifies the given algebraic fraction.
  • normal(expr,expanded) fully expands the numerator and denominator of the rational algebraic expression after it has been simplified.
  • normal([exprat1,...,expratn]) or normal({exprat1,...,expartn}) normalizes the set or list of rational algebraic expressions.
  • Normal(expratn) returns the inert normalization of a rational algebraic expression.
  • normal(expr) mod n finds the normalization of the given rational algebraic expression modulo n.
  • numer(exprational) returns the numerator of the rational algebraic expression after normalizataion.
  • denom(exprational) returns the denominator of the rational algebraic expression after normalization.
  • radnormal(exprational) normalizes a rational algebraic expression that contain radical numbers by eliminating all possible radical levels. It is also valid for non-rational algebraic expressions.
  • radnormal(exprational,rationalized) normalizes a rational algebraic expression that contains radicals, rationalizing  the denominator.
  • readsimp(exprational) normalizes a rational algebraic expression that contains radicals. It is also valid for non-rational algebraic expressions.
  • readsimp(exprational,name) normalizes the algebraic expression by rationalizing the denominator and assigns the specified name to the simplified expression.
  • expand(exprational) expands the numerator of a rational algebraic expression.
  • factor(exprational) factors the numerator and denominator of the rational algebraic expression and normalizes it.
  • convert(expr,confrac) converts the algebraic expression into an approximate continued fraction. Returns a list with the partial quotients of the continued fraction.
  • convert(expr,confrac,variable) converts the polynomial expression to its approximation by the rational polynomial continued fraction in the variable var.
  • convert(numeric expression,confrac,n) converts the numeric expression to its continued fraction expansion to at least n partial quotients.
  • convert(expression,parfrac,variable) converts the rational expression to simple fractions in the given variable. (Breaks up an algebraic fraction into partial fractions.)
  • convert(expression,parfrac,variable,true) applies the command factor to the denominator of the algebraic fraction prior to decomposing it into simple fractions.
  • convert(expression,fullparfrac,variable) fully decomposes a rational expression in the variable given into simple fractions (using RootOf expressions if necessary).

Here are some examples:

>> pretty(sym(maple('normal((x^2-y^2) /(x-y) ^ 3)')))
                                x + y
                               --------
                                      2
                               (x y)
>> pretty(sym(maple('normal((f (x) ^ 2-1) / (f (x) - 1))')))
                               f (x) + 1
>> pretty(sym(maple('normal({2/x + y/3 = 0})')))
                               6 + y x
                          {1/3 ------- = 0}
                                  x
>> pretty(sym(maple('normal( 1/x+x/(x+1) )')))
                                       2
                              x + 1 + x
                              ----------
                              x (x + 1)
>> pretty(sym(maple('normal( 1/x+x/(x+1),expanded)')))
                                       2
                              x + 1 + x
                              ----------
                                 2
                                x + x
>> pretty(sym(maple('numer( (1+x)/x^(1/2)/y ) ')))
                                x + 1
>> pretty(sym(maple('numer( 2/x + y )')))
                               2 + y x
>> pretty(sym(maple('numer( x+1/(x+1/x))')))
                                  2
                              x (x + 2)
>> pretty(sym(maple('denom(x+1/(x+1/x))')))
                                 2
                                x + 1
>> pretty(sym(maple('Normal( (x^3-2*x^2+2*x+1)/(x^4+1)) mod 5')))
                                x + 3
                                ------
                                 2
                                x + 3
>> pretty(sym(maple('evala(Normal((x^2-2)/(x-RootOf(_Z^2-2))))')))
                                      2
                         x + RootOf(_Z-2)
>> pretty(sym(maple('expand((x+1)/(x+2))')))
                              x       1
                            ----- + -----
                            x + 2   x + 2
>> pretty(sym(maple('expand(y^3*(x+1)^3/((x+2)*y^2))')))
                     3         2
                   yx        yx        yx      y
                  ----- + 3 ----- + 3 ----- + -----
                  x + 2     x + 2     x + 2   x + 2
>> pretty(sym(maple('factor((x^3-y^3)/(x^4-y^4))')))
                             2          2
                            x + x y + y
                          -----------------
                                2   2
                          (y + x) (x + y)
>> pretty(sym(maple('factor(y ^ 3 * (x + 1) ^ 3/((x^2+2*x+1) *(y^2+y)))')))
                                       2
                              (x + 1) y
                              ----------
                                y + 1
>> pretty(sym(maple('radsimp((1 + 2^(1/2))^(-1)/(1 + 2*x + x^2)^(1/2))')))
                                      1
                              ------------------
                                1/2
                              (2    + 1) (x + 1)
>> pretty(sym(maple(' p:= x^5-2*x^4-2*x^3+4*x^2+x-2')))
>> pretty(sym(maple(' f:= 36 / p')))

>> pretty(sym(maple('convert(f,parfrac,x)')))
                   4        9          3         4
                 ----- - -------- - -------- - -----
                 x - 2          2          2   x + 1
                         (x -1)    (x + 1)
>> pretty(sym(maple('convert(f,parfrac,x,sqrfree)')))
                     4       x + 2         x + 2
                   ----- - 4 ------ - 12 ---------
                   x - 2      2            2     2
                             x  - 1      (x  - 1)
>> pretty(sym(maple('f:= 36 / convert(p,sqrfree,x)')))

>> pretty(sym(maple('convert(f,parfrac,x,true)')))
                     4       x + 2         x + 2
                   ----- - 4 ------ - 12 ---------
                   x - 2      2            2     2
                             x  - 1      (x  - 1)

EXERCISE 2-16

Given the following algebraic fractions:

image, image

Simplify them all as much as possible and rationalize the denominators.

>> maple('A:=((x^2+2*x*2^(1/2)-2*x*3^(1/2)+5-2*2^(1/2)*3^(1/2))/(x^2-2*x*3^(1/2)+1))')
>> pretty(sym(maple(' radnormal(A) ')))

                                     1/2 1/2
                               -x - 2 + 3
                               ----------------
                                     1/2 1/2
                               -x + 2 + 3

>> pretty(sym(maple(' readlib(rationalize):rationalize(A) ')))

            2       1/2     1/2       1/2 1/2   2           1/2
        (- x - 2 x 2 + 2 x 3 - 5 + 2 2   3  ) (x + 1 + 2 x 3 )
      - -------------------------------------------------------
                                  4      2
                                 x - 10 x + 1

>> pretty(sym(maple(' B:= 1/(2^(1/2)+3^(1/2)+6^(1/2)) ')))
>> pretty(sym(maple(' radnormal(B) ')))

                                       1
                            -----------------------
                             1/2    1/2     1/2 1/2
                            2    + 3    + 2    3

>> pretty(sym(maple(' radnormal(B,rationalized) ')))

                        1/2      1/2 1/2      1/2 12
                  5/23 3 - 1/23 2   3 + 7/23 2  - --
                                                  23

EXERCISE 2-17

Convert the following algebraic fractions to continued fractions:

image, image

>> pretty(sym(maple(' convert(1/exp(x),confrac,x) ')))

                                    x
                     1 + -----------------------
                                      x
                         -1 + ------------------
                                         x
                              -2 + -------------
                                           x
                                   3 + ---------
                                       2 1/5 x

>> pretty(sym(maple(' r:= (1+1/2*x+1/12*x^2) / (1-1/2*x+1/12*x^2) ')))
>> pretty(sym(maple(' convert(r,confrac,x) ')))

                                    12
                           1 + ------------
                                        12
                               x - 6 + ----
                                         x

EXERCISE 2-18

Break down the following algebraic fractions into simple fractions:

image, image, image

>> pretty(sym(maple(' f:= (x^5+1)/(x^4-x^2) ')))
>> pretty(sym(maple(' convert(f,parfrac,x) ')))

                                 1          1
                           x + -----   -   ----
                               x - 1         2
                                            x

>> pretty(sym(maple(' f:= x/(x-b)^2 ')))
>> pretty(sym(maple('  convert(f,parfrac,x) ')))

                              b         1
                           -------- + -----
                                  2   x - b
                           (x - b)

>> pretty(sym(maple(' f:= (2.3*x)/(5.4*x^3-2.3*x+1) ')))

>> pretty(sym(maple(' convert(f,parfrac,x) ')))

       .2240312285                  .3421473558 + 1.209768633 x
   - --------------- + .1851851852 --------------------------------
     x +.8091847442                 2
                                   x -.8091847442 x +.2288540244

EXERCISE 2-19

Decompose into simple fractions the rational function given by f (x) = (4*x3 - 6*x2 - 2) / (x4-2*x3 - 2*x + 4) over the field of their coefficients, over the real field, over the complex field, and over the algebraic extension Q(√3).

>> pretty(sym(maple(' f:= (4*x^3-6*x^2-2)/(x^4-2*x^3-2*x+4) ')))
>> pretty(sym(maple(' convert(f,parfrac,x) ')))

                                        2
                             1         x
                           ----- + 3 ------
                           x - 2      3
                                     x - 2

>> pretty(sym(maple(' convert(f,parfrac,x,real) ')))

     1.000000000      1.000000000         1.259921050 + 2. x
   --------------- +  ----------- + -------------------------------
   x-1.259921050        x - 2.       2
                                   x + 1.259921050 x + 1.587401052

>> pretty(sym(maple(' convert(f,parfrac,x,complex) ')))

                     -9                                -9
    1 +.2803082855 10  I              1. -.2803082855 10 I
------------------------------- + -------------------------------
x +.6299605249 + 1.091123636 I     x +.6299605249 - 1.091123636 I
                        -10
       1 +.2631183713 10   I      1.000000000
     + ------------------------ + -----------
           x - 1.259921050             x - 2

>> pretty(sym(maple(' convert(f,parfrac,x,2^(1/3)) ')))

                     1/3
                    2    + 2 x          1          1
                ------------------ +  -------- + -----
                 2   1/3   2/3              1/3  x - 2
                x + 2 x + 2          x - 2

EXERCISE 2-20

Perform the following algebraic operations, simplifying the results as much as possible:

image

To treat operations with algebraic fractions, the best command to use is normal, but you can also use the simple commands factor and simplify:

>> pretty (sym (maple ('normal (x / (x + y) - y/(x-y) + 2 * x * y/(x^2-y^2))')))

                                  1

>> pretty (sym (maple ('factor (x / (x + y) - y/(x-y) + 2 * x * y/(x^2-y^2))')))

                                  1

>> pretty (sym (maple ('simplify (x / (x + y) - y/(x-y) + 2 * x * y/(x^2-y^2))')))

                                  1

>> pretty(sym(maple('normal((1+a^2)/b + (1-b^2)/a - (a^3-b^3)/(a*b))')))

                                a + b
                                -----
                                 a b

>> pretty(sym(maple('factor((1+a^2)/b + (1-b^2)/a - (a^3-b^3)/(a*b))')))

                                a + b
                                -----
                                 a b

>> pretty(sym(maple('simplify((1+a^2)/b + (1-b^2)/a - (a^3-b^3)/(a*b))')))

                                a + b
                                -----
                                 a b

EXERCISE 2-21

Simplify the following algebraic fractions as much as possible:

image

Because these are simple algebraic fractions, use the commands standard, factor or simplify:

>> pretty(sym(maple('normal((a^3-a^2*b+a*c^2-b*c^2)/(a^3+a*c^2+a^2*b+b*c^2))')))

                                a - b
                                -----
                                a + b

>> pretty(sym(maple('factor((a^3-a^2*b+a*c^2-b*c^2)/(a^3+a*c^2+a^2*b+b*c^2))')))

                                a - b
                                -----
                                a + b

>> pretty(sym(maple('simplify((a^3-a^2*b+a*c^2-b*c^2)/(a^3+a*c^2+a^2*b+b*c^2))')))

                                a - b
                                -----
                                a + b

>> pretty(sym(simple(((x^2-9)*(x^2-2*x+1)*(x-3))/((x^2-6*x+9)*(x^2-1)*(x-1)))))

                                x + 3
                                -----
                                x + 1

EXERCISE 2-22

Perform the following algebraic operations, simplifying the results as much as possible.

a)                        2
  3 x - 1    5 - x     4 x     2    2        4
(———————— - ——————— - ————————) * (x  (x + 1) - (x + 4))) / (4 + 5 x)]
   x + 2     x - 2      2
                       x - 4
b)
             2 x            2
 (—————————————————————————)
                 4 x
  (x - y) ———————————————
           2           2
          x + 2 x y + y
[———————————————————————————]
                  y
            1 + ————
                  x   4
          (——————————)
                  y
            1 - ————
                  x

In this type of combined operations, featuring both sums and differences, as well as ratios products and powers of algebraic expressions, the most efficient command is normal:

>> pretty(sym(maple('normal(((3*x-1)/(x+2)-(5-x)/(x-2)-4*x^2/(x^2-4))* ((x^2*(x^2+1)-(x^4+4))/(4+5*x)))')))

                                  -2

>> pretty (sym (maple ('normal (((2 * x /(x-y))/(4*x/(x^2+2*x*y+y^2)))^ 2 /((1+y/x)/(1-y/x))^4)')))

                                        2
                             1/4 (x - y)

2-8. Transforming Algebraic Expressions by Conversion

MATLAB enables the conversion of an algebraic expression dependent on a specific function into another expression that depends on another function related to the first. An expression can be transformed from logarithmic, trigonometric, inverse trigonometric or hyperbolic to exponentials, factorials to gamma functions, and so on. Among the commands that enable you to do this are the following (all of them must be preceded by the maple command):

  • convert(expression,exp) converts all trigonometric functions of the expression into their corresponding exponential form.
  • convert(expression,ln) converts all inverse trigonometric functions of the expression into their corresponding logarithmic form.
  • convert(expression,trig) converts all exponential functions of the expression into their corresponding trigonometric or hyperbolic trigonometric form.
  • convert(expression,tan) converts the trigonometric functions of the expression so that it depends only on the tangent.
  • convert(expression,sincos) converts trigonometric functions of the expressions depending only on sines, cosines, hyperbolic sines, and hyperbolic cosines.
  • convert(expression,expsincos) converts the trigonometric functions of the expression in terms of only sines and cosines, and at the same time converts all hyperbolic functions of the expression into its exponential form.
  • convert(expression,expln) converts the trigonometric functions of the expression into its exponential form, and at the same time converts  inverse trigonometric functions into logarithmic form.
  • convert(expression,GAMMA) converts all factorials and binomial and multinomial coefficients of the expression in terms of the GAMMA function.
  • convert(expression,factorial) converts all GAMMA functions, binomial and multinomial coefficients of the expression in terms of factorials.
  • convert(expression,binomial) converts  GAMMA and factorial expressions in terms of the binomial function.
  • convert(expr,piecewise) converts an expression containing moduli (abs), sign (signum), or Heaviside functions into a piecewise-defined function.
  • convert(expression,parlist) converts an expression containing defined functions into a piecewise function according to the specified list.
  • convert(expr,Heaviside) converts an expression containing piecewise functions into an expression  in terms of Heaviside functions.
  • convert(expression,surd) converts an expression containing roots and standard powers into its equivalent expresssion in terms of the surd function.
  • convert(expression,pair) converts an expression containing surd functions into its equivalent expression containing standard powers.
  • convert(expression,erf) converts an expression containing erfc functions into its equivalent in terms of the function erf.
  • convert(expression,erfc) converts an expression containing the function erf into its equivalent in terms of the function erfc.
  • convert(expression,Ei) converts an expression containing logarithmic, hyperbolic, and trigonometric integrals into an equivalent expression with exponential integrals.
  • convert(expression,Airy) converts an expression containing Bessel functions into its equivalent expression containing Airy functions.
  • convert(expression,Bessel) converts an expression containing Airy functions into an equivalent expression containing Bessel functions.
  • convert(expr,'+') converts an expression in the form of sums (the first level of operators must be sums, for example, a sum of products).
  • convert(expr,'.') converts an expression in the form of products (the first level of operands must be products, for example, a product of sums).
  • convert(expression,degree) converts an expression in radians to degrees.
  • convert(expression,radian) converts an expression in degrees to radians.
  • convert(expression,metric) converts an expression of type number * units to the metric system (for example, 34 * feet is converted to the decimal metric system).
  • convert(expr,metric,US) converts an expression given in U.S. units to the metric system.
  • convert(expr,metric,imp) converts an expression given in terms of imperial units to the metric system.
  • convert(expression,float) converts all the numeric values of an expression to their floating-point form.
  • convert(expr,hypergem) converts the expression sums (sum or Sum) according to terms to the equivalent hypergeometric functions.
  • convert(expr,rational) or convert(expr,fraction) converts all floating-point values of an expression to their rational form.
  • convert(expr,rational,n) converts all floating-point values of an expression to its rational form with n digits of precision.
  • convert(expression,rational and exact) converts all floating-point values of an expression to its rational form with infinite precision.
  • convert(expression,mod2) converts the expression containing the Boolean operators and, or , and not to an expression of the form modulo2 (an expression with only numeric values 0 and 1).
  • convert(expression,string) or convert(expression,name) converts the expression to a string.
  • convert(exprcompl,polar) converts the complex to expression to polar form.
  • convert(expression,radical) converts all RootOf expressions  to their radical equivalents.
  • convert(expression,RootOf) converts all radical expressions into RootOf notation.
  • convert(series,polynom) converts a Taylor series to a polynomial.
  • convert(booleanexpression,'and') converts all of the binary operators in a Boolean expression (and, or, & and, or, & nand, $nor, & xor, & diff and & implies) into their equivalent in terms of the operator and.
  • convert(booleanexpression,'or') or convert(expression,disjcyc) converts all of the binary operators in the Boolean expression (and, or, & and, or, & nand, $nor, & xor, & diff e & implies) into their equivalents depending on the operator or. The permutations of the expression are converted to disjoint cycles.
  • convert(expression,permlist) converts the expression’s disjoint cycles to their equivalent permutations.
  • convert(expression,multiset) converts the expression into a list of lists. For each element of the expression, it returns a list consisting of the element and its multiplicity (the number of times it is repeated).
  • convert([expr1,...,exprn],option) creates a list with the given expressions converted according to the specified option (trig, exp, ln,...).
  • convert({expression1,...,expressionn},option) creates an array with the given expression converted according to the specified option.

Here are some examples:

>> pretty(sym(maple('convert(exp(x^2)-2 * sinh(x^2),exp)')))
                                  1
                               -------
                                    2
                               exp(x )
>> pretty(sym(maple('convert(cot(x),expsincos)')))
                                cos(x)
                                ------
                                sin(x)
>> pretty(sym(maple('convert(sinh(x),expsincos)')))
                                          1
                       1/2 exp(x) - 1/2 ------
                                        exp(x)
>> pretty(sym(maple('convert(cot(x),sincos)')))
                                cos(x)
                                ------
                                sin(x)
>> pretty(sym(maple('convert(tanh(x),sincos)')))
                               sinh(x)
                               -------
                               cosh(x)
>> pretty(sym(maple('convert(arctanh(x),ln)')))
                    1/2 ln(x + 1) - 1/2 ln(1 - x)
>> pretty(sym(maple('convert(1/2*exp(x) + 1/2*exp(-x),trig)')))
                               cosh(x)
>> pretty(sym(maple('convert(cos(x)*sin(x), expln)')))
                  /                      1     /              1    
          - 1/2 I |1/2 exp(I x) + 1/2 --------| |exp(I x) - --------|
                                     exp(I x)/            exp(I x)/
>> pretty(sym(maple('convert(binomial(m,3),GAMMA)')))
                               GAMMA(m + 1)
                           1/6 ------------
                               GAMMA(m - 2)
>> pretty(sym(maple('convert(binomial(m,3),factorial)')))
                                    m!
                             1/6 --------
                                 (m - 3)!
>> pretty(sym(maple('convert(erfc(x),erf)')))
                              1 - erf(x)
>> pretty(sym(maple('convert(erfc(2,x),erf)')))
                                               2
               2        2              x exp(-x )
          1/2 x  - 1/2 x  erf(x) - 1/2 ---------- + 1/4 - 1/4 erf(x)
                                           1/2
                                         Pi
>> pretty(sym(maple('convert(",erfc) ')))
                                                     2
              2        2                     x exp(-x )
         1/2 x  - 1/2 x  (1 - erfc(x)) - 1/2 ---------- + 1/4 erfc(x)
                                                 1/2
                                               Pi
>> pretty(sym(maple('convert(BesselI(1/3,x),Airy) ')))
    / 1/3  2/3 1/2
    |3    2   |
1/2 |---------|
    |   2/3   |
      x      /

       1/2             2/3  1/3  2/3                2/3  1/3  2/3
    (-3    AiryAi(1/2 3    2    x   ) + AiryBi(1/2 3    2    x   ))
>> pretty(sym(maple('convert(HankelH2(-2/3,z),Bessel)')))
                BesselJ(-2/3, z) - I BesselY(-2/3, z)
>> pretty(sym(maple('convert(sin(BesselK(1/3,z^2)),Airy)')))
                    / 1/3  2/31/2
                    |3    2   |                2/3  1/3   2 2/3
             sin(Pi |---------|    AiryAi(1/2 3    2    (z )   ))
                    |   2 2/3 |
                     (z )    /

2-9. Subexpressions and Parts of Expressions

MATLAB implements a broad group of commands that allow you to work with subexpressions, either to operate on parts of expressions in general, to perform assignments of parts of expressions, to make substitutions in expressions, or for any other operations on the contents of algebraic expressions. The most important commands for this kind of task are summarized below (all of them must be preceded by the maple command):

  • indets(expression) determines all the indeterminates contained in the expression.
  • indets(expression,name) returns all subexpressions of the expression of the type given by name.
  • has(expression,subexpression) determines whetherthe given expression contains the specified subexpression.
  • has(expr,[subexp1,...,subexpn]) or has(expr,{subexp1,...,subexpn}) determines whether the expression expr contains one of the given subexpressions.
  • hasfun(expression,command) determines whether the expression contains a call to the command or function specified.
  • hasfun(expression,function,variable,etc.) determines whether the expression contains the specified function of the given variable.
  • hasfun(expression,[fun1,...,funn]) or hasfun(expression,{fun1,...,funn}) determines whether the expression contains at least one of the specified functions.
  • hasfun(expr,function,[var1,...,varn]) or hasfun(expr,function,{var1,..., varn}) determines whether the expression contains at least one of the functions function(vari) i = 1... n.
  • hastype(expression,type) determines whether the expression contains a subexpression of the specified type.
  • readlib(freeze): freeze(expr) replaces the (usually very long) expression by the variables _R0, _R1, etc. This is used to avoid overcomplicating expressions.
  • readlib(freeze): thaw(var) replaces the variable var by the expression that was previously assigned to it by freeze.
  • alias(name=expression) or macro(name=expression) assigns to the alias name the given expression. The aim is to work more easily with long expressions and subexpressions.
  • alias(name1=expr1,...,namen=exprn) or macro(name1=expr1,...,namen=exprn) assigns all the aliases to the specified expressions.
  • alias(name=name) or macro(name=name) removes the alias for name.
  • assign({var1=expr1,...,varn=exprn}) or assign([var1=expr1,...,varn=exprn]) assigns the specified expressions to the given variables. This is usually used for long expressions or complicated subexpressions to facilitate further work.
  • assign(variable=expression) or assign(variable,expression) assigns the given expression to the aforementioned variable.
  • unassign('var1',...,'varn') removes the assignments for the given variables.
  • op(expression) displays the first level of elements, parts, or operands of the expression.
  • op(i,expression) returns the ith element (part or operat or) of the expression according to the first level of operations.
  • op(i..j,expression) returns the ith through to the jth elements of the expression.
  • nops(expression) returns the number of elements (parts or operators) of the expression according to the first level of operations.
  • nops(op(i expression)) returns the number of elements of the ith element of the expression.
  • subsop(i=expresion2,expression1) replaces the ith element of expression1 according to the first level of operations with expression2.
  • op(0,expression) returns the type of the expression.
  • op(-i, expression) returns the ith element of the expression starting from the end according to the first level of operations.
  • applyop(function,expr) applies the function or specified command to the nth element of the expression according to the first level of operations.
  • select(function,expression) applies the Boolean function or command to each term of the expression (sum or product) and selects the terms for which the Boolean function or command returns true.
  • remove(function,expression) applies the Boolean function or command to all of the terms of the expression of sums or products and removes those for which the given Boolean function or command is true.
  • map(function,expr) applies the function to each operand of expr.
  • map2(function,arg,expr) applies the function with specified first argument to each operator of the expression expr.
  • add(expression,variable=a..b) sums the sequence obtained by evaluating the expression for the variable ranging over a, a+1,..., b-1, b.
  • mul(expression,variable=a..b) returns the product of the sequence obtained by evaluating the expression for the variable ranging over the values a, a+1,..., b-1, b.
  • seq(expression,variable=a..b) creates the sequence of expressions obtained by evaluating the specified expression for the variable over the values a, a+1,..., b-1, b.
  • numboccur(expr,subexpr) determines how many times the subexpression specified occurs in the given expression.
  • readlib(optimize): optimize (expression) optimizes the representation of the algebraic expression using common subexpressions.
  • readlib(optimize): optimize(expression, name=expression) optimizes the specified equation whose right-hand side is an algebraic expression.
  • readlib(optimize): optimize(expression,[name1=expr1,...,namen=exprn]) optimizes the specified equations whose right-hand sides are algebraic expressions.
  • shake(expression) creates a range of floating-point numbers that approximates the value of the expression.
  • shake(expression,n) creates a range of floating-point numbers that approximates the value of the expression with an accuracy given by n.
  • subs(exprold=exprnew,expression) replaces exprold with exprnew in the specified expression.
  • subs(expold1=expn1,expold2=expn2,..., expoldn=expnn, expression) replaces the specified old expressions in the given expression by the new expressions, sequentially.
  • subs({expold1=expn1,expold2=expn2,...,expoldn=expnn},expression) or subs([expold1=expn1,expold2=expn2,...,expoldn=expnn],expression) replaces the old expressions with the new expression, simultaneously.
  • subsop(n1=expr1,...,nk=exprk,expr) replaces the elements n1, n2,..., nk of the expression by expressions expr1,..., exprk respectively (according to the first level of operations), simultaneously.
  • readlib(trigsubs): trigsubs(identity,expression) applies the given trigonometric identity to the specified expression.
  • algsubs(exprold=exprnew,expr) substitutes exprnew in place of exprant in the given expression.
  • algsubs(exprold=exprnew,expression,exact) substitutes exprnew in place of exprant in the given expression only if the exact division of monomials is possible.
  • asubs(exprold=exprnew,expression) substitutes exprnew in place of exprold in the given expression in terms of sums.
  • asubs(exprold=exprnew,expression,always) substitutes exprnew in place of exprold in the given expression in all its addends.
  • LHS(equation) returns the left-hand side of the equation.
  • LHS(inequality) returns the left-hand side of the inequality.
  • LHS(range) returns the left side of an expression of type range.
  • RHS(equation) returns the right-hand side of the equation.
  • RHS(inequality) returns the right-hand side of the inequality.
  • RHS(range) returns the right side of an expression of type range.
  • readlib(isolate): isolate (equation, expression) isolates the specified expression in the given equation.
  • readlib(isolate): isolate (expr1, expr2) isolates the subexpression expr2  in the equation expr1 = 0.
  • readlib(isolate): isolate (equation, expression, n) isolates the specified expression in the given equation by running at least n transformations or passes.
  • setattribute(expression,attri1,...,attrin) assigns the attributes attri1,..., attrin for the specified expression. Only strings, lists, sets, floating-point values, and unevaluated function calls can have attributes.
  • setattribute(expression) removes all attributes previously assigned to the specified expression.
  • attributes(expression) returns all the attributes previously assigned to the specified expression.

Here are some examples:

>> pretty(sym(maple('indets(x*y + z/x)')))
                                   {y, z, x}
>> pretty(sym(maple('e:= x^(1/2) + exp(x^2) + f(9):')))
>> pretty(sym(maple('indets(e),  indets(e,function)')))
                           1/2      2          2
                      {x, x, exp (x)}, {exp (x), x (9)}
>> pretty(sym(maple('f:= (a+b^3+c)^(4/3)')))
>> pretty(sym(maple('has( f, a ),  has( f, b^3 ),  has( f, b^2 ),  has( f, a+b^3+c )')))
                       true, true, false, true
>> pretty(sym(maple('f:= Int(g(t),t=a..b)')))
>> pretty(sym(maple('has(f,a),   has(f,g),   has(f,t)')))
true, true, true
>> pretty(sym(maple('e:= sin(x)+exp(y)+1')))
>> pretty (sym (maple (' hasfun(e,exp), hasfun(e,cos), hasfun(e,exp,y), hasfun(e,exp,x),
   hasfun(e,exp,[x,y]), hasfun(e,{sin,cos},x)')))
                 true, false, true, false, true, true
>> pretty(sym(maple(' f:= x^(1/2)*y ')))

>> pretty(sym(maple('hastype(f,`*`), hastype(f, `+`), hastype(f, name^fraction),
   hastype(f,integer^fraction), hastype(f,radical ), hastype( f,function )')))
                true, false, true, false, true, false
>> pretty(sym(maple('readlib(freeze): z:= freeze(x+y)')))
>> pretty(sym(maple(' thaw(z) ')))
                                x + y
>> pretty(sym(maple('w:= f(g(a,b),h(c,d))')))
>> pretty(sym(maple('op(1,op(2,w)), op([2,1],w), op([-1,-1],w)')))
 c, c, d
>> pretty(sym(maple('Int(sin(sqrt(x)),x=0..t)')))

image

>> pretty(sym(maple('subsop( [1,1]=u, " ), subsop( 1=2*u*op(1,"), [2,1]=u, " ),
   applyop( sqrt, [2,2,2], " )')))

image

>> pretty (sym (maple ('readlib (isolate): isolate (4 * x * sin (x) = 3, sin (x)),
   isolate(x^2-3*x-5,x^2)')))
                                                 2
                        sin (x) = 3/4 x, x = 3 x + 5
>> pretty(sym(maple(' f:= 2*exp(a*x)*sin(x)*ln(y) ')))
>> pretty(sym(maple('select(has, f, x),
   remove(has, f, x)')))
                           exp (w x) sin (x), 2 ln (y)
>> pretty(sym(maple('attributes(a), setattribute(a,blue), attributes(a)')))
                               a, blue
>> pretty(sym(maple('setattribute(a,yellow,green)')))
                                  A
>> pretty(sym(maple('attributes(a)')))
                            yellow, green

EXERCISE 2-23

Perform the substitution sin (x)2= 1-cos (x)2 in the following expression: sin (x)3 - cos (x) sin (x)2 + cos (x)2 sin (x) + cos (x)3. Also substitute PV/T = R in the expression P2 V/T2 - PR.

>> pretty (sym (maple ('f: = sin (x) ^ 3-cos (x) * sin (x) ^ 2 + cos (x) ^ 2 * sin (x) +    cos (x) ^ 3')))
>> pretty (sym (maple ('algsubs (sin (x) ^ 2 = 1 - cos (x) ^ 2, f)')))

                                              3
                     sin (x) - cos (x) + 2 cos (x)

>> pretty(sym(maple('algsubs( P*V/T=R, P^2*V/T^2-P*R) ')))

                                     R P
                              -P R + ---
                                      T

EXERCISE 2-24

Perform the replacement defined by x2+ 3 = k in the expressions (x2 + 3 x + 3)3+ x and ((x2 + 3x + 3)3 + x) / (x2 +2)2.

>> pretty(sym(maple('readlib(asubs):')))
>> pretty(sym(maple('asubs( x^2 + 3 =k, (x^2 + 3*x + 3 ) ^ 3 + x )')))

                                          3
                            (3 x + k)  + x

>> pretty(sym(maple('asubs( x^2 + 3 =k, (x^2 + 3*x + 3 ) ^ 3 + x ,always)')))

                                   3    2
                     (3 x + k)  + x - x  - 3 + k

>> pretty(sym(maple('asubs( x^2 + 3 =k, ((x^2 + 3*x + 3 ) ^ 3 + x)/(x^2 +2)^2)')))

                                          3
                            (3 x + k)  + x
                            --------------
                                      2
                              (-1 + k)

EXERCISE 2-25

Change the variable x = r1/3 in the expression 3xln(x3) and also change the variable sin (x) = y in the expression sin(x) / (1-sin (x))1/2.

>> pretty(sym(maple('subs(x=r^(1/3), 3*x*log(x^3))')))

                                    1/3
                                 3 r    log(r)

>> pretty (sym (maple ('subs (y= sin (x), sin (x) / (1 - sin (x)) ^(1/2))')))

                                      y
                                  ----------
                                         1/2
                                  (1 - y)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset