User Tools

Site Tools


prime:programming:cas-polynomial_commands

CAS-Polynomial Commands

Return to the Prime Programming Page: Prime Programming Language (PPL)

This section will cover the Polynomial commands of the HP Prime. Unless noted, the commands are practically useful only in CAS Mode and in CAS programs.

Examples given in this section is with the CAS Simplify setting set to Maximum. The “Include complex results in variables” option is turned off.  

proot

Solves a polynomial based on a vector of coefficients. The order is in decreasing order. For example, proot([a3, a2, a1, a0]) is equivalent to finding the roots of the polynomial:

a3*x^3 + a2*x^2 + a1*x + a0 = 0.

Zeros must be filled whenever appropriate. The vector can have either real or complex coefficients.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

proot([vector of coefficients])

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.proot([vector of coefficients])

Home Mode - RPN Entry:

n-1: coefficient of x^(n-1)
n-2: coefficient of x^(n-2)

2: coefficient of x
1: coefficient of 1
CAS. proot(order + 1)

Examples:

CAS Mode
In Radians Mode:

proot([4, -7, 9]) returns
[0.875-1.218349231*i, 0.875+1.218349231*i]

proot([4+3*i, -8, 2-2*i]) returns
[0.314164853807-0.396522203581*i, 0.965835146193-0.563477796419*i]

Home Mode - RPN Entry:

Solve x^2 - 9*x + 1: (2nd order polynomial, 3 arguments)

1 , Enter,
9, +/-, Enter,
1, Enter
CAS.proot(3)

Solutions:
[0.112517806304, 8.8874821937]

Access: Toolbox, CAS, 6. Polynomial, 1. proot

See Also: coeff, factors

coeff

The coeff command retrieves all of the coefficients of a symbolic polynomial. The coefficients are returned in a sequence of coefficients of decreasing order. Zeroes are placed whenever appropriate. For example coeff(a3*x^3 + a2*x^2 +a1*x + a0) returns the sequence [a3, a2, a1, a0].

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

Polynomial of x:
coeff(polynomial)

Polynomial of any variable:
coeff(polynomial, variable)

If you want a specific coefficient:
coeff(polynomial, variable, term)

Note: If the polynomial is a function of x, you can leave out the variable argument.

Examples:

CAS Mode
In Radians Mode:

coeff(2*x^3+11*x) returns [2, 0, 11, 0]

coeff(2*x^3+11*x, t) returns [2*x^3 + 11*x]

coeff(2*t^3+11*t, t) returns [2,0,11,0]

To extract each coefficient separately:
coeff(-2*x^2+3*x+1, 0) returns 1. constant coefficient
coeff(-2*x^2+3*x+1, 1) returns 3
coeff(-2*x^2+3*x+1, 2) returns -2

Notes: coeff is not recommended for Home Mode use.

Access: Toolbox, CAS, 6. Polynomial, 2. coeff

See Also: proot, factors  

divis

Returns the divisors of a polynomial. The polynomial is assumed to be a function of one variable. You can even list more than one polynomial, and divis will list each divisor of each polynomial separately.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

divis(polynomial)

Examples:

CAS Mode
In Radians Mode:

divis(5*x^2+3*x) returns [1, x, 5*x+3, x*(5*x+3)]

divis(t^2-4) returns [1, t-2, t+2, (t+2)*(t-2)]

divis(t^2-4, x^3+1) returns
[ [1, t-2, t+2, (t+2)*(t-1)], [1, x+1, x^2-x+1, (x+1)*(x^2-x+1)] ]

Notes:

divis will not return the divisors of integers:
divis(45) returns [1 45]

Use idivis instead: idivis(45) returns [1,3, 9,5, 15, 45]

divis is not recommended for Home Mode use.

Access: Toolbox, CAS, 6. Polynomial, 3. divis

See Also: factors, idivis, ifactors

factors

Returns the prime factors of a polynomial. The sequence will list each prime factor, followed by its multiplicity. The polynomial is assumed to be a function of one variable.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

factors(polynomial)

Examples:

CAS Mode
In Radians Mode:

factors(5*x^2+3*x) returns [x,1, 5*x+3, 1] meaning
x * (5*x+3)

factors(4*t^5-15*t^3+5*t^2+15*t-9) returns [t-1, 3, 2*t+3, 2] meaning
(t-1)^3 * (2*t+3)^2

Notes:

factors will not return the prime factors of integers:
factors(45) returns [1, 45]

Use ifactors instead: ifactors(45) returns [3, 2, 5, 1] 3^2*5

divis is not recommended for Home Mode use.

Access: Toolbox, CAS, 6. Polynomial, 4. factors

See Also: ifactors, divis, idivis

gcd

Greatest common divisor of two polynomials or integers.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

Greatest Common Divisor of Polynomials:
gcd(polynomial, polynomial)

Greatest Common Divisor of Integers:
gcd(integer, integer)

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.gcd(integer, integer)

Home Mode - RPN Entry:

2: integer
1: integer
CAS.gcd(2)

Examples:

CAS Mode
In Radians Mode:

Polynomials:
gcd(2x^2+4x, 4x) returns 2x

gcd(2x^3+2, 3x^5+3) returns x+1

Integers:
gcd(175, 225) returns 25

Access: Toolbox, CAS, 6. Polynomial, 5. gcd OR
Toolbox, CAS, 5. Integers, 5. gcd

See Also: lcm

Create

symb2poly

Takes a polynomial from a symbolic polynomial and returns a list of coefficients.

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor

CAS.symb2poly(polynomial in single quotes, variable in single quotes)

Home - RPN

Does not work as expected

CAS

Polynomial of x:
symb2poly(polynomial)

Polynomial of any variable:
Symb2poly(polynomial, variable)

Examples:

CAS Mode:
symb2poly(x^3-2*x+1) returns [1 0 -2 1]

symb2poly(t^3-6*t,t) returns [1 0 -6 0]

Home Mode:
CAS.symb2poly(‘4*X^2-3*X+1’, ‘X’) returns [4 -3 1]

Access: Toolbox, CAS, 6. Polynomial, 7. Create, 1. Poly. → Coef.

See Also: poly2symb 

poly2symb

Takes a polynomial from a list of coefficients and returns a symbolic polynomial.

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor

CAS.poly2symb(vector of coefficients)

Home - RPN

1: vector of coefficients
CAS.poly2symb(1), press ENTER

CAS

Polynomial of x desired:
poly2symb(vector of coefficients)

Polynomial of any variable:
poly2symb(vector of coefficients, variable)

Examples:

CAS Mode:
Simplification Mode is turned off:
poly2symb([2, 8, 9]) returns (2*x+8)*x+9

poly2symb([2, 8, 9], t) returns (2*t+8)*t+9

Home Mode:
CAS.poly2symb([4, 7, 8]) returns (4*x+7)*x+8

Notes: How the polynomial is returned is dependent on Simplify settings.

Access: Toolbox, CAS, 6. Polynomial, 7. Create, 2. Coef. → Poly.

See Also: symb2poly

pcoeff

Turns a vector of roots into a polynomial represented by a vector of its coefficients. The order of the powers are dependent on the setting of the Increase Polynomial order in CAS.

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor

CAS.pcoeff(vector of coefficients)

Home - RPN

1: vector of coefficients
CAS.pcoeff(1), press ENTER

CAS

pcoeff(vector of coefficients)

Examples:

CAS Mode:
pcoeff([0, 1, 0, 4, 2*i]) returns [1, -5-2*i, 4+10*i, -8*i, 0, 0]

pcoeff([4,2,5]) returns [1, -11, 38, -40]

Access: Toolbox, CAS, 6. Polynomial, 7. Create, 3. Roots → Coef.

See Also: poly2symb, fcoeff, proot, pmin  

fcoeff

Give the roots and their multiplicities, fcoeff will return a polynomial.

Syntax

As long as a root is paired with a multiplicity, they can either be given in one vector, or just in a plain sequence.

Input:

Home - Algebraic
Home - Textbook
Program Editor

Not available

Home - RPN

Not available

CAS

fcoeff(root, order, root, order, …) or
fcoeff([root, order, root, order, …])

Examples:

CAS Mode:
fcoeff([2,3,-1,2]) or fcoeff(2,3,-1,2) returns (x-2)^3*(x+1)^2

Access: Toolbox, CAS, 6. Polynomial, 7. Create, 4. Roots → Coef.

See Also: poly2symb, pcoeff, proot, pmin  

pmin

Returns the minimum polynomial of a square matrix. There are two possible outputs with pmin:

1. Numerical: Give the matrix by itself and pmin returns a polynomial as a vector of coefficients. 2. Symbolic: Give the matrix and a desired variable, and pmin returns a symbolic polynomial.

Only the numerical option is available in RPN mode.

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor

CAS.pmin(square matrix) or CAS.pmin(square matrix,variable in single quotes)

Home - RPN

1: square matrix
CAS.pmin(1), press Enter

CAS

pmin(square matrix) or pmin(square matrix, variable)

Examples:

Home Mode:
CAS.pmin( [ [5, -1],[-2, -3] ] ) returns [1, -2, -17]

CAS.pmin( [ [5, -1],[-2, -3] ], ‘X’) returns ‘X^2-2*X-17’

Access: Toolbox, CAS, 6. Polynomial, 7. Create, 5. Minimum

See Also: poly2symb, pcoeff, proot, froot, randPoly

randPoly

Returns a randomly generated polynomial. You control the range of coefficients. The default is the range of integers from -99 to 99.

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor
Home - RPN

Not availble

CAS

Coefficients: default range of integers from -99 to 99:
randPoly(degree)

Coefficients: specific range of real numbers:
randPoly(degree, a .. b)

Coefficients: choose from a specific list:
randPoly(degree, {a,b,c,d,e…})

Examples:

Answers will vary:

randPoly(2) returns [-96, -69, 67]

randPoly(2, -5 .. 5) returns [4.6269, -4.5072, -3.2060]

randPoly(2, {-5,-4,-3,-2,-1,0,1,2,3,4,5}) returns [4, 3, -3]

Access: Toolbox, CAS, 6. Polynomial, 7. Create, 5. Minimum

See Also: poly2symb, pcoeff, proot, froot, randPoly

CAS – Polynomial – Algebra

quo

Gives the quotient of p(x)/q(x) where p(x) and q(x) are two polynomials. Polynomials can be entered as a vector of coefficients or symbolic objects (CAS mode only).

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor

CAS.quo(numerator vector, denominator vector)

Home - RPN

2: numerator vector
1: denominator vector
CAS.quo(2), press Enter

CAS

Using Vectors:
quo(numerator vector, denominator vector)

Using Symbolic Polynomials:
quo(numerator polynomial, denominator polynomial,var)

Output:

P(x)/Q(x) = D(x) + R/Q(x)

The quo command returns D(x).

Examples:

CAS Mode:
quo([1,4,7], [2,4]) returns [.5, 1]

quo(x^3-1, x+1, x) returns x^2-x+1

Access: Toolbox, CAS, 6. Polynomial, 8. Algebra, 1. Quotient

See Also: rem, iquo, irem, mod  

rem

Gives the numeric remainder of p(x)/q(x) where p(x) and q(x) are two polynomials. Polynomials can be entered as a vector of coefficients or symbolic objects (CAS mode only).

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor

CAS.rem(numerator vector, denominator vector)

Home - RPN

2: numerator vector
1: denominator vector
CAS.rem(2), press Enter

CAS

Using Vectors:
rem(numerator vector, denominator vector)

Using Symbolic Polynomials:
rem(numerator polynomial, denominator polynomial,var)

Output:

P(x)/Q(x) = D(x) + R/Q(x)

The rem command returns R.

Examples:

CAS Mode:
rem([1,4,7], [2,4]) returns [3]

rem(x^3-1, x+1, x) returns x^2-x+1

Access: Toolbox, CAS, 6. Polynomial, 8. Algebra, 1. Quotient

See Also: quo, iquo, irem, mod

degree

The degree command returns the degree of a polynomial. The polynomial can either be a symbolic algebraic object, or a vector of coefficients.

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor

CAS.degree(vector of coefficients)

CAS.degree(polynomial in single quotes,variable)

Home - RPN

1: vector of coefficients
CAS.degree(1), press Enter

CAS

Using Vectors:
degree(vector of coefficients)

Using Symbolic Polynomials:
degree(polynomial, variable)

Notes: The variable can be omitted if the polynomial is in terms of x.

Examples:

CAS Mode:
degree(x^2-3) return 2

degree([8,7,-1,0,5]) return 4

Access: Toolbox, CAS, 6. Polynomial, 8. Algebra, 3. Degree

See Also: factor_xn

factor_xn

Factors out x^n of a symbolic polynomial, where n the degree of the polynomial. Works in CAS Mode only.

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor
Home - RPN

Not Available

CAS

factor_xn(polynomial)

Examples:

CAS Mode:
factor_xn(x^6 – 3*x^3 + 1) returns x^6 * (1 – 3*x^-3 + x^-6)

factor_xn(x^2 * (x^3 – 2*x^2) + 2*x – x) returns x^5 * (1 – 2*x^-1 + x^-4)

Access: Toolbox, CAS, 6. Polynomial, 8. Algebra, 4. Factor by Degree

See Also: degree  

content

Returns the gcd of the polynomial’s coefficients. The command does not work in RPN mode.

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor

CAS.content(polynomial in single quotes,variable in single quotes)

Home - RPN

Not available.

CAS

content(polynomial,variable)

Examples:

CAS Mode:
content(2*x^2 + 10*x + 6, x) returns 2

Home Mode:
CAS.content(‘2*N^3-4*N+6’, ‘N’) returns 2

Access: Toolbox, CAS, 6. Polynomial, 8. Algebra, 5. Coef. GCD

See Also: gcd, factor  

sturmab

The sturmab command returns the number of sign changes that a polynomial takes in a given interval (a,b).

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor

CAS.sturmab(polynomial in single quotes,variable,a,b)

Home - RPN

Not available.

CAS

sturmab(polynomial, variable, a, b)

Examples:

CAS Mode:
sturmab(x^3 – 2*x^2 + 1, x, -10, 10) returns 3

Home Mode:
CAS.sturmab(‘X^3-3*X^2-6*X+1’, ‘X’, -10, 10) returns 3

Access: Toolbox, CAS, 6. Polynomial, 8. Algebra, 6. Zero Count

See Also: zeros, cZeros  

chinrem

Chinese Remainder for polynomials. For this command, the polynomials are written as matrices.

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor

CAS.chinrem(matrix, matrix)

Home - RPN

Not available.

CAS

chinrem(matrix, matrix)

Examples:

CAS Mode:
chinrem( [ [1, -1], [3, 5] ], [ [3, 0], [2, -3] ] ) returns [ 43/19, 21/19 ] , [6, 1, -15]

Home Mode:
CAS.chinrem( [ [4, 8], [-1, 2] ], [ [2, 0], [0, -1] ] ) returns [4, 8], [0, 1, -2]

Access: Toolbox, CAS, 6. Polynomial, 8. Algebra, 7. Chinese Remainder

See Also: mod

Special Commands

cyclomtic

Generate the cyclotomic polynomial as a vector of coefficients.

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor

CAS.cyclotomic(order)

Home - RPN

1: order CAS.cyclotomic(1), press Enter

CAS

cyclotomic(order)

Examples:

CAS Mode:
cyclotomic(2) returns [1, 1]

cyclotomic(6) returns [1, -1, 1]

Home Mode:
CAS.cyclotomic(5) returns [1, 1, 1, 1, 1]

Access: Toolbox, CAS, 6. Polynomial, 9. Special, 1. Cyclotomic

See Also: hermite, lagrange, Laguerre, legendre, tchebyshev1, tchebyshev2, randPoly

gbasis

Groebner basis of the ideal spanned by a given list of polyonmials.

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor
Home – RPN

Not Available

CAS

gbasis(list of polynomials, list of variables)

Examples:

CAS Mode:
gbasis( { 4x+y^3, x^2-y^2 }, { x, y } ) returns [ y^6 – 16*y^2, 4*x + y^3 ]

gbasis( { t^2 * (t + x + 2*x^2), x, 2*t^4 }, { x, t } ) returns [ t^4, x ]

Access: Toolbox, CAS, 6. Polynomial, 9. Special, 2. Groebner Basis

See Also: greduce  

greduce

Remainder division of a polynomial by a Groebner Basis.

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor
Home – RPN

Not Available

CAS

greduce(polynomial, list of polynomials, list of variables)

Examples:

CAS Mode:
greduce( x^2 + y^2, { x^2, y^2 }, { x, y } ) returns 0.

Access: Toolbox, CAS, 6. Polynomial, 9. Special, 3. Groebner Remainder

See Also: gbasis  

hermite

Returns the Hermite Polynomial:

H_n(x) = ( -1 )^n * e^( x^2 ) * d^n/dx^n ( e^ ( -x^2 ) )

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor

Polynomial: CAS.hermite(order)

Numerical: CAS.hermite(order, numeric value)

Home - RPN

Polynomial
1: order
CAS.hermite(1), press Enter

Numerical:
2: order
1: numeric value
CAS.hermite(2), press Enter

CAS

Polynomial: hermite(order)

Numerical: hermite(order, numeric value)

Examples:

CAS Mode:
hermite(3) returns 8*x^3 – 12*x

Home Mode:
CAS.hermite(2) returns ‘4*X^2 – 2’

Access: Toolbox, CAS, 6. Polynomial, 9. Special, 4. Hermite

See Also: cyclotomic, lagrange, Laguerre, legendre, tchebyshev1, tchebyshev2, randPoly  

lagrange

Returns the polynomial of degree n-1 where:

P(x_k) = y_k for k = 0 to n-1

Syntax

Input:

Home - Algebraic
Home - Textbook
Program Editor

Input by List: CAS.lagrange(list x, list y)

Input by Matrix: CAS.lagrange(square matrix)

Home - RPN

Input by Matrix: 1: square matrix
CAS.lagrange(1), press Enter

CAS

Input by List: lagrange(list x, list y)

Input by Matrix: lagrange(square matrix)

Examples:

CAS Mode:

lagrange( [ [1,7], [4,7] ] ) returns ½*(x – 1) + 4

lagrange( {-1, 1}, {0, 2} ) returns x + 1

Access: Toolbox, CAS, 6. Polynomial, 9. Special, 5. Lagrange

See Also: cyclotomic, hermite, Laguerre, legendre, tchebyshev1, tchebyshev2, randPoly

Laguerre

Returns the Laguerre polynomial, which satisfied the differential equation:

x*y’’ + (a + 1 – x) *y’ + n * y = 0

Syntax

Input:

General Input: Laguerre(integer, value of x, value of a)

The arguments value of x and value of a are optional.

Home - Algebraic
Home - Textbook
Program Editor

CAS.laguerre(integer, value of x, value of a)

Home - RPN

3: integer
2: value of x
1: value of a
CAS.laguerre(3), press Enter

2: integer
1: value of x
CAS.laguerre(2), press Enter

1: integer
CAS.laguerre(1), press Enter

CAS

laguerre(integer, value of x, value of a)

Examples:

CAS Mode:

laguerre(3) returns a^3/6 – a^2*x/2 + a*x^2/2 – 5*a*x/2 + 11*a/6

laguerre(3,2) returns a^3/6 – 7*a/6 – 1/3 laguerre(3,2,3) returns 2/3

Access: Toolbox, CAS, 6. Polynomial, 9. Special, 6. Laguerre

See Also: cyclotomic, hermite, lagrange, legendre, tchebyshev1, tchebyshev2, randPoly  

legendre

Returns the nth degree of the Legendre polynomial:

p(x) = 1/(2^n * n!) * d^n/dx^n (x^2 – 1)^n

Syntax

Input:

General: lengendre(order, value of x)

The argument value of x is optional.

Home - Algebraic
Home - Textbook
Program Editor

CAS.lengendre(order, value of x)

Home - RPN

2: order
1: value of x
CAS.legendre(2), press Enter

1: order
CAS.legendre(1), press Enter

CAS

laguerre(integer, value of x, value of a)

Examples:

CAS Mode:

legendre(2) returns 3/2*x^2 – 1/2

legendre(2, 2) returns 11/2

Access: Toolbox, CAS, 6. Polynomial, 9. Special, 7. legendre

See Also: cyclotomic, hermite, lagrange, Laguerre, tchebyshev1, tchebyshev2, randPoly  

tchebyshev2

Chebyshev’s polynomial of the Second Kind. A simple recurrence formula for this polynomial is:

U_0 = 1 U_1 = 2*x U_n = 2*x*U_(n-1) – U_(n-2)

Syntax

Input:

General: tchebyshev2(order, value of x)

The argument value of x is optional.

Home - Algebraic
Home - Textbook
Program Editor

CAS.tchebyshev2(order, value of x)

Home - RPN

2: order
1: value of x
CAS.tchebyshev2(2), press Enter

1: order
CAS.tchebyshev2(1), press Enter

CAS

Tchebyshev2(order, value of x)

Examples:

CAS Mode:

tchebyshev2(4) returns 16*x^4 – 12*x^2 + 1

tchebyshev2(4, 2.5) returns 551

Access: Toolbox, CAS, 6. Polynomial, 9. Special, 8. Chebyshev Un

See Also: cyclotomic, hermite, lagrange, Laguerre, legendre, tchebyshev1, randPoly  

Return to the Prime Programming Page: Prime Programming Language (PPL)

prime/programming/cas-polynomial_commands.txt · Last modified: 2013/12/01 09:03 by ed314