Expand | put polynomial in expanded form |
Degree | degree of a polynomial |
Coef | coefficient of a polynomial |
Content | content of a univariate polynomial |
PrimitivePart | primitive part of a univariate polynomial |
LeadingCoef | leading coefficient of a polynomial |
Monic | monic part of a polynomial |
RandomPoly | construct a random polynomial |
Horner | convert polynomial into Horner form |
ExpandBrackets | expand all brackets |
EvaluateHornerScheme | fast evaluation of polynomials |
OrthoP | Legendre and Jacobi orthogonal polynomials |
OrthoH | Hermite orthogonal polynomials |
OrthoG | Gegenbauer orthogonal polynomials |
OrthoL | Laguerre orthogonal polynomials |
OrthoT, OrthoU | Tschebyscheff polynomials |
OrthoPSum, OrthoHSum, OrthoLSum, OrthoGSum, OrthoTSum, OrthoUSum | sums of series of orthogonal polynomials |
OrthoPoly | internal function for constructing orthogonal polynomials |
OrthoPolySum | internal function for computing series of orthogonal polynomials |
SquareFree | Return square-free part of polynom p=p(x) in x |
FindRealRoots | Find the real roots of a polynom p=p(x) in x |
NumRealRoots | Return the number of real roots of a polynom p=p(x) in x |
MinimumBound | Return a lower bound on the absolute value of the real roots of a polynom p=p(x) in x |
MaximumBound | Return an upper bound on the absolute value of the real roots of a polynom p=p(x) in x |
Expand(expr) Expand(expr, var) Expand(expr, varlist) |
var -- a variable
varlist -- a list of variables
If the polynomial "expr" contains only one variable, the first calling sequence can be used. Otherwise, the second form should be used which explicitly mentions that "expr" should be considered as a polynomial in the variable "var". The third calling form can be used for multivariate polynomials. Firstly, the polynomial "expr" is expanded with respect to the first variable in "varlist". Then the coefficients are all expanded with respect to the second variable, and so on.
In> PrettyPrinter("PrettyForm"); True |
In> Expand((1+x)^5); 5 4 3 2 x + 5 * x + 10 * x + 10 * x + 5 * x + 1 |
In> Expand((1+x-y)^2, x); 2 2 x + 2 * ( 1 - y ) * x + ( 1 - y ) |
In> Expand((1+x-y)^2, {x,y}); 2 2 x + ( -2 * y + 2 ) * x + y - 2 * y + 1 |
Degree(expr) Degree(expr, var) |
var -- a variable occurring in "expr"
In> Degree(x^5+x-1); Out> 5; In> Degree(a+b*x^3, a); Out> 1; In> Degree(a+b*x^3, x); Out> 3; |
Coef(expr, var, order) |
var -- a variable occurring in "expr"
order -- integer or list of integers
In> e := Expand((a+x)^4,x) Out> x^4+4*a*x^3+(a^2+(2*a)^2+a^2)*x^2+ (a^2*2*a+2*a^3)*x+a^4; In> Coef(e,a,2) Out> 6*x^2; In> Coef(e,a,0 .. 4) Out> {x^4,4*x^3,6*x^2,4*x,1}; |
Content(expr) |
In> poly := 2*x^2 + 4*x; Out> 2*x^2+4*x; In> c := Content(poly); Out> 2*x; In> pp := PrimitivePart(poly); Out> x+2; In> Expand(pp*c); Out> 2*x^2+4*x; |
PrimitivePart(expr) |
In> poly := 2*x^2 + 4*x; Out> 2*x^2+4*x; In> c := Content(poly); Out> 2*x; In> pp := PrimitivePart(poly); Out> x+2; In> Expand(pp*c); Out> 2*x^2+4*x; |
LeadingCoef(poly) LeadingCoef(poly, var) |
var -- a variable
In> poly := 2*x^2 + 4*x; Out> 2*x^2+4*x; In> lc := LeadingCoef(poly); Out> 2; In> m := Monic(poly); Out> x^2+2*x; In> Expand(lc*m); Out> 2*x^2+4*x; In> LeadingCoef(2*a^2 + 3*a*b^2 + 5, a); Out> 2; In> LeadingCoef(2*a^2 + 3*a*b^2 + 5, b); Out> 3*a; |
Monic(poly) Monic(poly, var) |
var -- a variable
In> poly := 2*x^2 + 4*x; Out> 2*x^2+4*x; In> lc := LeadingCoef(poly); Out> 2; In> m := Monic(poly); Out> x^2+2*x; In> Expand(lc*m); Out> 2*x^2+4*x; In> Monic(2*a^2 + 3*a*b^2 + 5, a); Out> a^2+(a*3*b^2)/2+5/2; In> Monic(2*a^2 + 3*a*b^2 + 5, b); Out> b^2+(2*a^2+5)/(3*a); |
RandomPoly(var,deg,coefmin,coefmax) |
deg -- degree of resulting univariate polynomial
coefmin -- minimum value for coefficients
coefmax -- maximum value for coefficients
In> RandomPoly(x,3,-10,10) Out> 3*x^3+10*x^2-4*x-6; In> RandomPoly(x,3,-10,10) Out> -2*x^3-8*x^2+8; |
Horner(expr, var) |
var -- a variable
If one converts this polynomial into Horner form, one gets the equivalent expression
Both expression are equal, but the latter form gives a more efficient way to evaluate the polynomial as the powers have disappeared.
In> expr1:=Expand((1+x)^4) Out> x^4+4*x^3+6*x^2+4*x+1; In> Horner(expr1,x) Out> (((x+4)*x+6)*x+4)*x+1; |
ExpandBrackets(expr) |
In> Expand((a-x)*(b-x),x) Out> x^2-(b+a)*x+a*b; In> Expand((a-x)*(b-x),{x,a,b}) Out> x^2-(b+a)*x+b*a; In> ExpandBrackets((a-x)*(b-x)) Out> a*b-x*b+x^2-a*x; |
EvaluateHornerScheme(coeffs,x) |
x -- expression
In> EvaluateHornerScheme({a,b,c,d},x) Out> a+x*(b+x*(c+x*d)); |
OrthoP(n, x); OrthoP(n, a, b, x); |
x -- point to evaluate polynomial at
a, b -- parameters for Jacobi polynomial
The Jacobi polynomials are orthogonal with respect to the weight function (1-x)^a*(1+x)^b on the interval [-1,1]. They satisfy the recurrence relation
Legendre polynomials are a special case of Jacobi polynomials with the specific parameter values a=b=0. So they form an orthogonal system with respect to the weight function identically equal to 1 on the interval [-1,1], and they satisfy the recurrence relation
Most of the work is performed by the internal function OrthoPoly.
In> PrettyPrinter("PrettyForm"); True In> OrthoP(3, x); / 2 \ | 5 * x 3 | x * | ------ - - | \ 2 2 / In> OrthoP(3, 1, 2, x); 1 / / 21 * x 7 \ 7 \ - + x * | x * | ------ - - | - - | 2 \ \ 2 2 / 2 / In> Expand(%) 3 2 21 * x - 7 * x - 7 * x + 1 ---------------------------- 2 In> OrthoP(3, 1, 2, 0.5); -0.8124999999 |
OrthoH(n, x); |
x -- point to evaluate polynomial at
The Hermite polynomials are orthogonal with respect to the weight function Exp(-x^2/2) on the entire real axis. They satisfy the recurrence relation
Most of the work is performed by the internal function OrthoPoly.
In> OrthoH(3, x); Out> x*(8*x^2-12); In> OrthoH(6, 0.5); Out> 31; |
OrthoG(n, a, x); |
a -- parameter
x -- point to evaluate polynomial at
The Gegenbauer polynomials are orthogonal with respect to the weight function (1-x^2)^(a-1/2) on the interval [-1,1]. Hence they are connected to the Jacobi polynomials via
Most of the work is performed by the internal function OrthoPoly.
In> OrthoG(5, 1, x); Out> x*((32*x^2-32)*x^2+6); In> OrthoG(5, 2, -0.5); Out> 2; |
OrthoL(n, a, x); |
a -- parameter
x -- point to evaluate polynomial at
The Laguerre polynomials are orthogonal with respect to the weight function x^a*Exp(-x) on the positive real axis. They satisfy the recurrence relation
Most of the work is performed by the internal function OrthoPoly.
In> OrthoL(3, 1, x); Out> x*(x*(2-x/6)-6)+4; In> OrthoL(3, 1/2, 0.25); Out> 1.2005208334; |
OrthoT(n, x); OrthoU(n, x); |
x -- point to evaluate polynomial at
The Tschebyscheff polynomials are orthogonal with respect to the weight function (1-x^2)^(-1/2). Hence they are a special case of the Gegenbauer polynomials G(n,a,x), with a=0. They satisfy the recurrence relations
Tschebyscheff polynomials are evaluated using fast (but numerically unstable) recurrence relations
Warning: because of numerical instability of this algorithm, polynomials of very large orders on floating-point arguments should be evaluated with increased precision.
In> OrthoT(3, x); Out> 2*x*(2*x^2-1)-x; In> OrthoT(10, 0.9); Out> -0.2007474688; In> OrthoU(3, x); Out> 4*x*(2*x^2-1); In> OrthoU(10, 0.9); Out> -2.2234571776; |
Here is an example numerical calculation where the loss of precision is catastrophic:
In> OrthoT(10000000000001, 0.9) Out> 0.1851470834; In> Precision(20); Out> True; In> OrthoT(10000000000001, 0.9) Out> -0.79727552022438356731; |
OrthoPSum(c, x); OrthoPSum(c, a, b, x); OrthoHSum(c, x); OrthoLSum(c, a, x); OrthoGSum(c, a, x); OrthoTSum(c, x); OrthoUSum(c, x); |
a, b -- parameters of specific polynomials
x -- point to evaluate polynomial at
The list of coefficients starts with the lowest order, so that for example OrthoLSum(c, a, x) = c[1] L[0](a,x) + c[2] L[1](a,x) + ... + c[N] L[N-1](a,x).
See pages for specific orthogonal polynomials for more details on the parameters of the polynomials.
Most of the work is performed by the internal function OrthoPolySum. The individual polynomials entering the series are not computed, only the sum of the series.
In> Expand(OrthoPSum({1,0,0,1/7,1/8}, 3/2, \ 2/3, x)); Out> (7068985*x^4)/3981312+(1648577*x^3)/995328+ (-3502049*x^2)/4644864+(-4372969*x)/6967296 +28292143/27869184; |
OrthoPoly(name, n, par, x) |
n -- degree of the polynomial
par -- list of values for the parameters
x -- point to evaluate at
All known families are stored in the association list KnownOrthoPoly. The name serves as key. At the moment the following names are known to Yacas: "Jacobi", "Gegenbauer", "Laguerre", "Hermite", "Tscheb1", and "Tscheb2". The value associated to the key is a pure function that takes two arguments: the order n and the extra parameters p, and returns a list of two lists: the first list contains the coefficients A,B of the n=1 polynomial, i.e. A+B*x; the second list contains the coefficients A,B,C in the recurrence relation, i.e. P[n]=(A+B*x)*P[n-1]+C*P[n-2]. (There are only 3 coefficients in the second list, because none of the polynomials use C+D*x instead of C in the recurrence relation. This is assumed in the implementation!)
If the argument x is numerical, the function OrthoPolyNumeric is called. Otherwise, the function OrthoPolyCoeffs computes a list of coefficients, and EvaluateHornerScheme converts this list into a polynomial expression.
OrthoPolySum(name, c, par, x) |
c -- list of coefficients
par -- list of values for the parameters
x -- point to evaluate at
The algorithm used to compute the series without first computing the individual polynomials is the Clenshaw-Smith recurrence scheme. (See the algorithms book for explanations.)
If the argument x is numerical, the function OrthoPolySumNumeric is called. Otherwise, the function OrthoPolySumCoeffs computes the list of coefficients of the resulting polynomial, and EvaluateHornerScheme converts this list into a polynomial expression.
SquareFree(p) |
with irreducible polynoms p[i], return the square-free version part (with all the factors having multiplicity 1):
In> Expand((x+1)^5) Out> x^5+5*x^4+10*x^3+10*x^2+5*x+1; In> SquareFree(%) Out> (x+1)/5; In> Monic(%) Out> x+1; |
FindRealRoots(p) |
In> p:=Expand((x+3.1)^5*(x-6.23)) Out> x^6+9.27*x^5-0.465*x^4-300.793*x^3- 1394.2188*x^2-2590.476405*x-1783.5961073; In> FindRealRoots(p) Out> {-3.1,6.23}; |
NumRealRoots(p) |
In> NumRealRoots(x^2-1) Out> 2; In> NumRealRoots(x^2+1) Out> 0; |
MinimumBound(p) |
MaximumBound(p) |
In> p:=SquareFree(Rationalize((x-3.1)*(x+6.23))) Out> (-40000*x^2-125200*x+772520)/870489; In> MinimumBound(p) Out> 5000000000/2275491039; In> N(%) Out> 2.1973279236; In> MaximumBound(p) Out> 10986639613/1250000000; In> N(%) Out> 8.7893116904; |