REDUCE

9.10 Obtaining Parts of Polynomials and Rationals

These operators select various parts of a polynomial or rational function structure. Except for the cost of rearrangement of the structure, these operations take very little time to perform.

For those operators in this section that take a kernel VAR as their second argument, an error results if the first expression is not a polynomial in VAR, although the coefficients themselves can be rational as long as they do not depend on VAR. However, if the switch RATARG is on, denominators are not checked for dependence on VAR, and are taken to be part of the coefficients.

9.10.1 DEG Operator

This operator is used with the syntax

        DEG(EXPRN:polynomial,VAR:kernel):integer.

It returns the leading degree of the polynomial EXPRN in the variable VAR. If VAR does not occur as a variable in EXPRN, 0 is returned.

Examples:

        deg((a+b)*(c+2*d)^2,a) ->  1  
        deg((a+b)*(c+2*d)^2,d) ->  2  
        deg((a+b)*(c+2*d)^2,e) ->  0.

Note also that if RATARG is on,

        deg((a+b)^3/a,a)       ->  3

since in this case, the denominator A is considered part of the coefficients of the numerator in A. With RATARG off, however, an error would result in this case.

9.10.2 DEN Operator

This is used with the syntax:

        DEN(EXPRN:rational):polynomial.

It returns the denominator of the rational expression EXPRN. If EXPRN is a polynomial, 1 is returned.

Examples:

        den(x/y^2)   ->  Y**2  
        den(100/6)   ->  3  
                [since 100/6 is first simplified to 50/3]  
        den(a/4+b/6) ->  12  
        den(a+b)     ->  1

9.10.3 LCOF Operator

LCOF is used with the syntax

        LCOF(EXPRN:polynomial,VAR:kernel):polynomial.

It returns the leading coefficient of the polynomial EXPRN in the variable VAR. If VAR does not occur as a variable in EXPRN, EXPRN is returned.

Examples:

        lcof((a+b)*(c+2*d)^2,a) ->  C**2+4*C*D+4*D**2  
        lcof((a+b)*(c+2*d)^2,d) ->  4*(A+B)  
        lcof((a+b)*(c+2*d),e)   ->  A*C+2*A*D+B*C+2*B*D

9.10.4 LPOWER Operator

Syntax:

        LPOWER(EXPRN:polynomial,VAR:kernel):polynomial.

LPOWER returns the leading power of EXPRN with respect to VAR. If EXPRN does not depend on VAR, 1 is returned.

Examples:

        lpower((a+b)*(c+2*d)^2,a) ->  A  
        lpower((a+b)*(c+2*d)^2,d) ->  D**2  
        lpower((a+b)*(c+2*d),e)   ->  1

9.10.5 LTERM Operator

Syntax:

        LTERM(EXPRN:polynomial,VAR:kernel):polynomial.

LTERM returns the leading term of EXPRN with respect to VAR. If EXPRN does not depend on VAR, EXPRN is returned.

Examples:

        lterm((a+b)*(c+2*d)^2,a) ->  A*(C**2+4*C*D+4*D**2)  
        lterm((a+b)*(c+2*d)^2,d) ->  4*D**2*(A+B)  
        lterm((a+b)*(c+2*d),e)   ->  A*C+2*A*D+B*C+2*B*D

Compatibility Note:  In some earlier versions of REDUCE, LTERM returned 0 if the EXPRN did not depend on VAR. In the present version, EXPRN is always equal to LTERM(EXPRN,VAR) + REDUCT(EXPRN,VAR).

9.10.6 MAINVAR Operator

Syntax:

        MAINVAR(EXPRN:polynomial):expression.

Returns the main variable (based on the internal polynomial representation) of EXPRN. If EXPRN is a domain element, 0 is returned.

Examples:

Assuming A has higher kernel order than B, C, or D:

        mainvar((a+b)*(c+2*d)^2) ->  A  
        mainvar(2)               ->  0

9.10.7 NUM Operator

Syntax:

        NUM(EXPRN:rational):polynomial.

Returns the numerator of the rational expression EXPRN. If EXPRN is a polynomial, that polynomial is returned.

Examples:

        num(x/y^2)  ->  X  
        num(100/6)   ->  50  
        num(a/4+b/6) ->  3*A+2*B  
        num(a+b)     ->  A+B

9.10.8 REDUCT Operator

Syntax:

        REDUCT(EXPRN:polynomial,VAR:kernel):polynomial.

Returns the reductum of EXPRN with respect to VAR (i.e., the part of EXPRN left after the leading term is removed). If EXPRN does not depend on the variable VAR, 0 is returned.

Examples:

     reduct((a+b)*(c+2*d),a) ->  B*(C + 2*D)  
     reduct((a+b)*(c+2*d),d) ->  C*(A + B)  
     reduct((a+b)*(c+2*d),e) ->  0

Compatibility Note:  In some earlier versions of REDUCE, REDUCT returned EXPRN if it did not depend on VAR. In the present version, EXPRN is always equal to LTERM(EXPRN,VAR) + REDUCT(EXPRN,VAR).

9.10.9 TOTALDEG Operator

Syntax:

     totaldeg(a*x^2+b*x+c, x)  => 2  
     totaldeg(a*x^2+b*x+c, {a,b,c})  => 1  
     totaldeg(a*x^2+b*x+c, {x, a})  => 3  
     totaldeg(a*x^2+b*x+c, {x,b})  => 2  
     totaldeg(a*x^2+b*x+c, {p,q,r})  => 0

totaldeg(u, kernlist) finds the total degree of the polynomial u in the variables in kernlist. If kernlist is not a list it is treated as a simple single variable. The denominator of u is ignored, and "degree" here does not pay attention to fractional powers. Mentions of a kernel within the argument to any operator or function (eg sin, cos, log, sqrt) are ignored. Really u is expected to be just a polynomial.