Polynomials: fast evaluation of polynomials given by coefficients, polynomial objects with arithmetic, and the classical families of orthogonal polynomials.
Three kinds of tools live here: evaluators of polynomials given by coefficients, polynomial objects, and orthogonal polynomial families.
Evaluation of a polynomial given by its coefficients, in ascending order of power:
evalpoly, makepoly and the macro mevalpoly for coefficients written in the code,evalpoly-complex, makepoly-complex, mevalpoly-complex for a complex z and complex coefficients, and evalpoly-scalar-complex, makepoly-scalar-complex, mevalpoly-scalar-complex for a complex z and real coefficients.Polynomial objects:
polynomial and coeffs->polynomial create a polynomial with double coefficients, ratio-polynomial and coeffs->ratio-polynomial one with exact rational coefficients,add, sub, scale, mult, derivative and evaluate operate on them, coeffs and degree describe them. The objects are also functions of x.add, sub and mult; this throws an IllegalArgumentException. The zero polynomial has degree 0.Orthogonal polynomials. Chebyshev, Legendre, Gegenbauer, Jacobi, Laguerre, Hermite, Bessel and Meixner-Pollaczek come in three forms: a function eval-* for the value at a point, a function *-ratio for a ratio-polynomial with exact rational coefficients, and a function without a suffix for a polynomial object (for example eval-chebyshev-T, chebyshev-T-ratio, chebyshev-T). Bernstein has the value and the object only.
eval-chebyshev-T, eval-chebyshev-U, eval-chebyshev-V, eval-chebyshev-W,eval-legendre-P, eval-gegenbauer-C, eval-jacobi-P,eval-laguerre-L, eval-hermite-H (physicists) and eval-hermite-He (probabilists),eval-bernstein and bernstein (Bernstein basis polynomials), eval-bessel-y and eval-bessel-t (Bessel polynomials and the reverse Bessel polynomials), eval-meixner-pollaczek-P,ince-C, ince-S and their radial forms ince-C-radial, ince-S-radial, built from the coefficients ince-C-coeffs, ince-S-coeffs.The accuracy of each function eval-* and its exceptions are stated in its own documentation. The degree must be a non-negative integer below Integer/MAX_VALUE, otherwise an IllegalArgumentException is thrown. Where a value is mathematically unique (for example at infinite x) it is returned, otherwise invalid arguments throw an IllegalArgumentException.
Polynomials: fast evaluation of polynomials given by coefficients, polynomial objects with arithmetic, and the classical families of orthogonal polynomials. Three kinds of tools live here: evaluators of polynomials given by coefficients, polynomial objects, and orthogonal polynomial families. Evaluation of a polynomial given by its coefficients, in ascending order of power: - real coefficients: [[evalpoly]], [[makepoly]] and the macro [[mevalpoly]] for coefficients written in the code, - complex coefficients: [[evalpoly-complex]], [[makepoly-complex]], [[mevalpoly-complex]] for a complex `z` and complex coefficients, and [[evalpoly-scalar-complex]], [[makepoly-scalar-complex]], [[mevalpoly-scalar-complex]] for a complex `z` and real coefficients. Polynomial objects: - [[polynomial]] and [[coeffs->polynomial]] create a polynomial with double coefficients, [[ratio-polynomial]] and [[coeffs->ratio-polynomial]] one with exact rational coefficients, - [[add]], [[sub]], [[scale]], [[mult]], [[derivative]] and [[evaluate]] operate on them, [[coeffs]] and [[degree]] describe them. The objects are also functions of `x`. - The two kinds cannot be mixed in [[add]], [[sub]] and [[mult]]; this throws an `IllegalArgumentException`. The zero polynomial has degree 0. Orthogonal polynomials. Chebyshev, Legendre, Gegenbauer, Jacobi, Laguerre, Hermite, Bessel and Meixner-Pollaczek come in three forms: a function `eval-*` for the value at a point, a function `*-ratio` for a [[ratio-polynomial]] with exact rational coefficients, and a function without a suffix for a [[polynomial]] object (for example [[eval-chebyshev-T]], [[chebyshev-T-ratio]], [[chebyshev-T]]). Bernstein has the value and the object only. - Chebyshev of the first to fourth kind: [[eval-chebyshev-T]], [[eval-chebyshev-U]], [[eval-chebyshev-V]], [[eval-chebyshev-W]], - [[eval-legendre-P]], [[eval-gegenbauer-C]], [[eval-jacobi-P]], - [[eval-laguerre-L]], [[eval-hermite-H]] (physicists) and [[eval-hermite-He]] (probabilists), - [[eval-bernstein]] and [[bernstein]] (Bernstein basis polynomials), [[eval-bessel-y]] and [[eval-bessel-t]] (Bessel polynomials and the reverse Bessel polynomials), [[eval-meixner-pollaczek-P]], - Ince polynomials [[ince-C]], [[ince-S]] and their radial forms [[ince-C-radial]], [[ince-S-radial]], built from the coefficients [[ince-C-coeffs]], [[ince-S-coeffs]]. The accuracy of each function `eval-*` and its exceptions are stated in its own documentation. The degree must be a non-negative integer below `Integer/MAX_VALUE`, otherwise an `IllegalArgumentException` is thrown. Where a value is mathematically unique (for example at infinite `x`) it is returned, otherwise invalid arguments throw an `IllegalArgumentException`.
(->Polynomial cfs d)Positional constructor of Polynomial, the polynomial object with double coefficients. Use polynomial instead.
Parameters: cfs (array of doubles): the coefficients in ascending order of power, at least one; d (long): the nominal degree, which must equal the number of coefficients minus one. Neither is validated.
Positional constructor of `Polynomial`, the polynomial object with double coefficients. Use [[polynomial]] instead. Parameters: `cfs` (array of doubles): the coefficients in ascending order of power, at least one; `d` (long): the nominal degree, which must equal the number of coefficients minus one. Neither is validated.
(->PolynomialR cfs d)Positional constructor of PolynomialR, the polynomial object with exact rational coefficients. Use ratio-polynomial instead.
Parameters: cfs (vector of rational numbers): the coefficients in ascending order of power, at least one; d (long): the nominal degree, which must equal the number of coefficients minus one. Neither is validated.
Positional constructor of `PolynomialR`, the polynomial object with exact rational coefficients. Use [[ratio-polynomial]] instead. Parameters: `cfs` (vector of rational numbers): the coefficients in ascending order of power, at least one; `d` (long): the nominal degree, which must equal the number of coefficients minus one. Neither is validated.
(add poly)(add poly1 poly2)Adds polynomials.
Parameters: poly, poly1, poly2 (polynomial objects): from polynomial or from ratio-polynomial. Both arguments of the two-argument form must be of the same kind; combining a Polynomial with a PolynomialR, or with anything that is not a polynomial object, throws an IllegalArgumentException.
Returns the polynomial itself for one argument, otherwise a new polynomial whose nominal degree is the larger of the two degrees (cancellation of leading coefficients does not lower it). The sum of PolynomialR objects is exact; for Polynomial objects each coefficient has one rounding error.
Adds polynomials. Parameters: `poly`, `poly1`, `poly2` (polynomial objects): from [[polynomial]] or from [[ratio-polynomial]]. Both arguments of the two-argument form must be of the same kind; combining a `Polynomial` with a `PolynomialR`, or with anything that is not a polynomial object, throws an `IllegalArgumentException`. Returns the polynomial itself for one argument, otherwise a new polynomial whose nominal degree is the larger of the two degrees (cancellation of leading coefficients does not lower it). The sum of `PolynomialR` objects is exact; for `Polynomial` objects each coefficient has one rounding error. See also [[sub]], [[mult]], [[scale]].
(bernstein degree order)Creates the Bernstein basis polynomial b_(k,n) as a polynomial object in the power basis.
See eval-bernstein for the definition. The coefficient of x^l is (-1)^(l-k) * C(n, l) * C(l, k), computed with exact integers and converted to a double once.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).order (integer): the index k. For an order outside 0 .. degree the result is the zero polynomial of nominal degree n (all coefficients 0.0).Returns a Polynomial (see polynomial) of degree n, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use eval-bernstein for values at a high degree. From a degree of about 600 some exact coefficients are beyond the range of a double and become infinite, and the object then evaluates to ##NaN. The exact coefficients take time and memory growing like the square of the degree (about half a minute for degree 100000).
See also eval-bernstein.
Creates the Bernstein basis polynomial `b_(k,n)` as a polynomial object in the power basis. See [[eval-bernstein]] for the definition. The coefficient of `x^l` is `(-1)^(l-k) * C(n, l) * C(l, k)`, computed with exact integers and converted to a double once. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `order` (integer): the index `k`. For an order outside `0 .. degree` the result is the zero polynomial of nominal degree `n` (all coefficients `0.0`). Returns a `Polynomial` (see [[polynomial]]) of degree `n`, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use [[eval-bernstein]] for values at a high degree. From a degree of about 600 some exact coefficients are beyond the range of a double and become infinite, and the object then evaluates to `##NaN`. The exact coefficients take time and memory growing like the square of the degree (about half a minute for degree 100000). See also [[eval-bernstein]].
(bessel-t degree)Creates the reverse Bessel polynomial theta_n as a polynomial object with double coefficients.
See eval-bessel-t for the definition and bessel-t-ratio for the exact integer coefficients, which are converted to doubles.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a Polynomial (see polynomial) of degree n, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (for a negative x the terms alternate in sign), so use eval-bessel-t for values at a high degree.
See also bessel-t-ratio, eval-bessel-t, bessel-y.
Creates the reverse Bessel polynomial `theta_n` as a polynomial object with double coefficients. See [[eval-bessel-t]] for the definition and [[bessel-t-ratio]] for the exact integer coefficients, which are converted to doubles. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `Polynomial` (see [[polynomial]]) of degree `n`, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (for a negative `x` the terms alternate in sign), so use [[eval-bessel-t]] for values at a high degree. See also [[bessel-t-ratio]], [[eval-bessel-t]], [[bessel-y]].
(bessel-t-ratio degree)Creates the reverse Bessel polynomial theta_n with exact integer coefficients.
theta_0 = 1, theta_1 = x + 1 and theta_n = (2n-1)*theta_(n-1) + x^2*theta_(n-2); the coefficient of x^(n-k) is (n+k)! / ((n-k)! * k! * 2^k), the coefficients of bessel-y-ratio in the reverse order. See eval-bessel-t for the definition.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a PolynomialR (see ratio-polynomial) of degree n: operations on it are exact, and it can be evaluated exactly at a rational argument. The polynomial is monic.
See also bessel-t (double coefficients), eval-bessel-t (direct evaluation), bessel-y-ratio.
Creates the reverse Bessel polynomial `theta_n` with exact integer coefficients. `theta_0 = 1`, `theta_1 = x + 1` and `theta_n = (2n-1)*theta_(n-1) + x^2*theta_(n-2)`; the coefficient of `x^(n-k)` is `(n+k)! / ((n-k)! * k! * 2^k)`, the coefficients of [[bessel-y-ratio]] in the reverse order. See [[eval-bessel-t]] for the definition. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `PolynomialR` (see [[ratio-polynomial]]) of degree `n`: operations on it are exact, and it can be evaluated exactly at a rational argument. The polynomial is monic. See also [[bessel-t]] (double coefficients), [[eval-bessel-t]] (direct evaluation), [[bessel-y-ratio]].
(bessel-y degree)Creates the Bessel polynomial y_n as a polynomial object with double coefficients.
See eval-bessel-y for the definition and bessel-y-ratio for the exact integer coefficients, which are converted to doubles.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a Polynomial (see polynomial) of degree n, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (for a negative x the terms alternate in sign), so use eval-bessel-y for values at a high degree.
See also bessel-y-ratio, eval-bessel-y, bessel-t.
Creates the Bessel polynomial `y_n` as a polynomial object with double coefficients. See [[eval-bessel-y]] for the definition and [[bessel-y-ratio]] for the exact integer coefficients, which are converted to doubles. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `Polynomial` (see [[polynomial]]) of degree `n`, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (for a negative `x` the terms alternate in sign), so use [[eval-bessel-y]] for values at a high degree. See also [[bessel-y-ratio]], [[eval-bessel-y]], [[bessel-t]].
(bessel-y-ratio degree)Creates the Bessel polynomial y_n with exact integer coefficients.
y_0 = 1, y_1 = 1 + x and y_n = (2n-1)*x*y_(n-1) + y_(n-2); the coefficient of x^k is (n+k)! / ((n-k)! * k! * 2^k). See eval-bessel-y for the definition.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a PolynomialR (see ratio-polynomial) of degree n: operations on it are exact, and it can be evaluated exactly at a rational argument. The coefficients are positive and grow like (2n)! / (n! * 2^n).
See also bessel-y (double coefficients), eval-bessel-y (direct evaluation), bessel-t-ratio.
Creates the Bessel polynomial `y_n` with exact integer coefficients. `y_0 = 1`, `y_1 = 1 + x` and `y_n = (2n-1)*x*y_(n-1) + y_(n-2)`; the coefficient of `x^k` is `(n+k)! / ((n-k)! * k! * 2^k)`. See [[eval-bessel-y]] for the definition. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `PolynomialR` (see [[ratio-polynomial]]) of degree `n`: operations on it are exact, and it can be evaluated exactly at a rational argument. The coefficients are positive and grow like `(2n)! / (n! * 2^n)`. See also [[bessel-y]] (double coefficients), [[eval-bessel-y]] (direct evaluation), [[bessel-t-ratio]].
(chebyshev-T degree)Creates the Chebyshev polynomial of the first kind T_n as a polynomial object with double coefficients.
See eval-chebyshev-T for the definition and chebyshev-T-ratio for the exact integer coefficients, which are converted to doubles.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a Polynomial (see polynomial) of degree n, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use eval-chebyshev-T for values at a high degree.
See also chebyshev-T-ratio, eval-chebyshev-T.
Creates the Chebyshev polynomial of the first kind `T_n` as a polynomial object with double coefficients. See [[eval-chebyshev-T]] for the definition and [[chebyshev-T-ratio]] for the exact integer coefficients, which are converted to doubles. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `Polynomial` (see [[polynomial]]) of degree `n`, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use [[eval-chebyshev-T]] for values at a high degree. See also [[chebyshev-T-ratio]], [[eval-chebyshev-T]].
(chebyshev-T-ratio degree)Creates the Chebyshev polynomial of the first kind T_n with exact integer coefficients.
T_0 = 1, T_1 = x and T_(n+1) = 2*x*T_n - T_(n-1); see eval-chebyshev-T for the definition and the orthogonality.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a PolynomialR (see ratio-polynomial) of degree n: operations on it are exact, and it can be evaluated exactly at a rational argument. The coefficients grow like 2^n and alternate in sign.
See also chebyshev-T (double coefficients), eval-chebyshev-T (direct evaluation).
Creates the Chebyshev polynomial of the first kind `T_n` with exact integer coefficients. `T_0 = 1`, `T_1 = x` and `T_(n+1) = 2*x*T_n - T_(n-1)`; see [[eval-chebyshev-T]] for the definition and the orthogonality. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `PolynomialR` (see [[ratio-polynomial]]) of degree `n`: operations on it are exact, and it can be evaluated exactly at a rational argument. The coefficients grow like `2^n` and alternate in sign. See also [[chebyshev-T]] (double coefficients), [[eval-chebyshev-T]] (direct evaluation).
(chebyshev-U degree)Creates the Chebyshev polynomial of the second kind U_n as a polynomial object with double coefficients.
See eval-chebyshev-U for the definition and chebyshev-U-ratio for the exact integer coefficients, which are converted to doubles.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a Polynomial (see polynomial) of degree n, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use eval-chebyshev-U for values at a high degree.
See also chebyshev-U-ratio, eval-chebyshev-U.
Creates the Chebyshev polynomial of the second kind `U_n` as a polynomial object with double coefficients. See [[eval-chebyshev-U]] for the definition and [[chebyshev-U-ratio]] for the exact integer coefficients, which are converted to doubles. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `Polynomial` (see [[polynomial]]) of degree `n`, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use [[eval-chebyshev-U]] for values at a high degree. See also [[chebyshev-U-ratio]], [[eval-chebyshev-U]].
(chebyshev-U-ratio degree)Creates the Chebyshev polynomial of the second kind U_n with exact integer coefficients.
U_0 = 1, U_1 = 2*x and U_(n+1) = 2*x*U_n - U_(n-1); see eval-chebyshev-U for the definition and the orthogonality.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a PolynomialR (see ratio-polynomial) of degree n: operations on it are exact, and it can be evaluated exactly at a rational argument. The coefficients grow like 2^n and alternate in sign.
See also chebyshev-U (double coefficients), eval-chebyshev-U (direct evaluation).
Creates the Chebyshev polynomial of the second kind `U_n` with exact integer coefficients. `U_0 = 1`, `U_1 = 2*x` and `U_(n+1) = 2*x*U_n - U_(n-1)`; see [[eval-chebyshev-U]] for the definition and the orthogonality. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `PolynomialR` (see [[ratio-polynomial]]) of degree `n`: operations on it are exact, and it can be evaluated exactly at a rational argument. The coefficients grow like `2^n` and alternate in sign. See also [[chebyshev-U]] (double coefficients), [[eval-chebyshev-U]] (direct evaluation).
(chebyshev-V degree)Creates the Chebyshev polynomial of the third kind V_n as a polynomial object with double coefficients.
See eval-chebyshev-V for the definition and chebyshev-V-ratio for the exact integer coefficients, which are converted to doubles.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a Polynomial (see polynomial) of degree n, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use eval-chebyshev-V for values at a high degree.
See also chebyshev-V-ratio, eval-chebyshev-V.
Creates the Chebyshev polynomial of the third kind `V_n` as a polynomial object with double coefficients. See [[eval-chebyshev-V]] for the definition and [[chebyshev-V-ratio]] for the exact integer coefficients, which are converted to doubles. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `Polynomial` (see [[polynomial]]) of degree `n`, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use [[eval-chebyshev-V]] for values at a high degree. See also [[chebyshev-V-ratio]], [[eval-chebyshev-V]].
(chebyshev-V-ratio degree)Creates the Chebyshev polynomial of the third kind V_n with exact integer coefficients.
V_0 = 1, V_1 = 2*x - 1 and V_(n+1) = 2*x*V_n - V_(n-1); see eval-chebyshev-V for the definition and the orthogonality.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a PolynomialR (see ratio-polynomial) of degree n: operations on it are exact, and it can be evaluated exactly at a rational argument.
See also chebyshev-V (double coefficients), eval-chebyshev-V (direct evaluation).
Creates the Chebyshev polynomial of the third kind `V_n` with exact integer coefficients. `V_0 = 1`, `V_1 = 2*x - 1` and `V_(n+1) = 2*x*V_n - V_(n-1)`; see [[eval-chebyshev-V]] for the definition and the orthogonality. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `PolynomialR` (see [[ratio-polynomial]]) of degree `n`: operations on it are exact, and it can be evaluated exactly at a rational argument. See also [[chebyshev-V]] (double coefficients), [[eval-chebyshev-V]] (direct evaluation).
(chebyshev-W degree)Creates the Chebyshev polynomial of the fourth kind W_n as a polynomial object with double coefficients.
See eval-chebyshev-W for the definition and chebyshev-W-ratio for the exact integer coefficients, which are converted to doubles.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a Polynomial (see polynomial) of degree n, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use eval-chebyshev-W for values at a high degree.
See also chebyshev-W-ratio, eval-chebyshev-W.
Creates the Chebyshev polynomial of the fourth kind `W_n` as a polynomial object with double coefficients. See [[eval-chebyshev-W]] for the definition and [[chebyshev-W-ratio]] for the exact integer coefficients, which are converted to doubles. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `Polynomial` (see [[polynomial]]) of degree `n`, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use [[eval-chebyshev-W]] for values at a high degree. See also [[chebyshev-W-ratio]], [[eval-chebyshev-W]].
(chebyshev-W-ratio degree)Creates the Chebyshev polynomial of the fourth kind W_n with exact integer coefficients.
W_0 = 1, W_1 = 2*x + 1 and W_(n+1) = 2*x*W_n - W_(n-1); see eval-chebyshev-W for the definition and the orthogonality.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a PolynomialR (see ratio-polynomial) of degree n: operations on it are exact, and it can be evaluated exactly at a rational argument.
See also chebyshev-W (double coefficients), eval-chebyshev-W (direct evaluation).
Creates the Chebyshev polynomial of the fourth kind `W_n` with exact integer coefficients. `W_0 = 1`, `W_1 = 2*x + 1` and `W_(n+1) = 2*x*W_n - W_(n-1)`; see [[eval-chebyshev-W]] for the definition and the orthogonality. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `PolynomialR` (see [[ratio-polynomial]]) of degree `n`: operations on it are exact, and it can be evaluated exactly at a rational argument. See also [[chebyshev-W]] (double coefficients), [[eval-chebyshev-W]] (direct evaluation).
(coeffs poly)Returns the coefficients of a polynomial object in ascending order of power: c0, c1, ..., cn.
Parameters: poly (polynomial object): from polynomial or from ratio-polynomial.
Returns a sequence of doubles for a Polynomial and a vector of ratios (integers and fractions) for a PolynomialR. The number of coefficients is degree plus one, and it is at least one: the zero polynomial has the single coefficient zero. Trailing zero coefficients are included.
See also degree, coeffs->polynomial.
Returns the coefficients of a polynomial object in ascending order of power: `c0`, `c1`, ..., `cn`. Parameters: `poly` (polynomial object): from [[polynomial]] or from [[ratio-polynomial]]. Returns a sequence of doubles for a `Polynomial` and a vector of ratios (integers and fractions) for a `PolynomialR`. The number of coefficients is [[degree]] plus one, and it is at least one: the zero polynomial has the single coefficient zero. Trailing zero coefficients are included. See also [[degree]], [[coeffs->polynomial]].
(coeffs->polynomial & coeffs)Creates a polynomial object with double coefficients from coefficients given as separate arguments.
Parameters: coeffs (numbers): the coefficients c0, c1, ... in ascending order of power. Without arguments the result is the zero polynomial.
Returns a Polynomial, the same as (polynomial coeffs).
See also polynomial, coeffs->ratio-polynomial.
Creates a polynomial object with double coefficients from coefficients given as separate arguments. Parameters: `coeffs` (numbers): the coefficients `c0`, `c1`, ... in ascending order of power. Without arguments the result is the zero polynomial. Returns a `Polynomial`, the same as `(polynomial coeffs)`. See also [[polynomial]], [[coeffs->ratio-polynomial]].
(coeffs->ratio-polynomial & coeffs)Creates a polynomial object with exact rational coefficients from coefficients given as separate arguments.
Parameters: coeffs (numbers): the coefficients c0, c1, ... in ascending order of power. Without arguments the result is the zero polynomial. A NaN or infinite coefficient throws an IllegalArgumentException.
Returns a PolynomialR, the same as (ratio-polynomial coeffs).
See also ratio-polynomial, coeffs->polynomial.
Creates a polynomial object with exact rational coefficients from coefficients given as separate arguments. Parameters: `coeffs` (numbers): the coefficients `c0`, `c1`, ... in ascending order of power. Without arguments the result is the zero polynomial. A NaN or infinite coefficient throws an `IllegalArgumentException`. Returns a `PolynomialR`, the same as `(ratio-polynomial coeffs)`. See also [[ratio-polynomial]], [[coeffs->polynomial]].
(degree poly)Returns the nominal degree of a polynomial object: the number of its coefficients minus one.
Parameters: poly (polynomial object): from polynomial or from ratio-polynomial.
The degree is nominal because leading zero coefficients are counted and no operation removes them: [1 2 0 0] has degree 3, the difference of a polynomial and itself keeps its degree, and the zero polynomial has degree 0. derivative lowers the degree by the order, and mult adds the degrees.
See also coeffs.
Returns the nominal degree of a polynomial object: the number of its coefficients minus one. Parameters: `poly` (polynomial object): from [[polynomial]] or from [[ratio-polynomial]]. The degree is nominal because leading zero coefficients are counted and no operation removes them: `[1 2 0 0]` has degree 3, the difference of a polynomial and itself keeps its degree, and the zero polynomial has degree 0. [[derivative]] lowers the degree by the order, and [[mult]] adds the degrees. See also [[coeffs]].
(derivative poly)(derivative poly order)Returns the derivative of a polynomial object, optionally of a higher order.
Parameters:
poly (polynomial object): from polynomial or from ratio-polynomial.order (non-negative integer, default 1): the order of the derivative. A non-integer is truncated; a negative order throws an IllegalArgumentException.Returns a polynomial of the same kind. Order 0 returns poly itself. For an order not above the degree the result has the nominal degree degree - order. For a larger order, and for any derivative of a constant or of the zero polynomial, the result is the zero polynomial (degree 0). The derivative of a PolynomialR is exact for any order; the coefficients of a Polynomial have a relative error of a few units of roundoff.
Returns the derivative of a polynomial object, optionally of a higher order. Parameters: - `poly` (polynomial object): from [[polynomial]] or from [[ratio-polynomial]]. - `order` (non-negative integer, default 1): the order of the derivative. A non-integer is truncated; a negative order throws an `IllegalArgumentException`. Returns a polynomial of the same kind. Order 0 returns `poly` itself. For an order not above the degree the result has the nominal degree `degree - order`. For a larger order, and for any derivative of a constant or of the zero polynomial, the result is the zero polynomial (degree 0). The derivative of a `PolynomialR` is exact for any order; the coefficients of a `Polynomial` have a relative error of a few units of roundoff. See also [[degree]], [[evaluate]].
(eval-bernstein degree order x)Evaluates the Bernstein basis polynomial b_(k,n) at x.
b_(k,n)(x) = C(n, k) * x^k * (1 - x)^(n - k) for 0 <= k <= n. The n + 1 polynomials of one degree sum to 1; on [0, 1] they are non-negative and b_(k,n)(x) is the probability of k successes in n trials of success probability x. b_(k,n)(x) = b_(n-k,n)(1 - x). They are polynomials in x for every real x.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).order (integer): the index k. For an order outside 0 .. degree the basis function is the zero function: the result is 0.0 for every x, also ##NaN and the infinities.x (double): the argument, any real number.Returns a double. For degree 0 the result is 1.0 whatever x is. ##NaN gives ##NaN for a positive degree. An infinite x gives the infinity of the leading term (the sign follows the parity of k and n - k). The value is accurate to about (n+1) units of roundoff relative to the result (1e-13 at degree 500 to 1000). The binomial coefficient and the powers are not formed separately where one of them would overflow or underflow, so a degree of thousands is evaluated without ##NaN or ##Inf for a representable result; values below 1e-290 are less accurate.
See also bernstein.
Evaluates the Bernstein basis polynomial `b_(k,n)` at `x`. `b_(k,n)(x) = C(n, k) * x^k * (1 - x)^(n - k)` for `0 <= k <= n`. The `n + 1` polynomials of one degree sum to 1; on `[0, 1]` they are non-negative and `b_(k,n)(x)` is the probability of `k` successes in `n` trials of success probability `x`. `b_(k,n)(x) = b_(n-k,n)(1 - x)`. They are polynomials in `x` for every real `x`. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `order` (integer): the index `k`. For an order outside `0 .. degree` the basis function is the zero function: the result is `0.0` for every `x`, also `##NaN` and the infinities. - `x` (double): the argument, any real number. Returns a double. For degree 0 the result is `1.0` whatever `x` is. `##NaN` gives `##NaN` for a positive degree. An infinite `x` gives the infinity of the leading term (the sign follows the parity of `k` and `n - k`). The value is accurate to about `(n+1)` units of roundoff relative to the result (1e-13 at degree 500 to 1000). The binomial coefficient and the powers are not formed separately where one of them would overflow or underflow, so a degree of thousands is evaluated without `##NaN` or `##Inf` for a representable result; values below 1e-290 are less accurate. See also [[bernstein]].
(eval-bessel-t degree x)Evaluates the reverse Bessel polynomial theta_n at x.
theta_n(x) = x^n * y_n(1/x) = sum over k of (n+k)! / ((n-k)! * k! * 2^k) * x^(n-k), with theta_0 = 1, theta_1 = x + 1 and theta_n = (2n-1)*theta_(n-1) + x^2*theta_(n-2). It is monic, theta_n(0) = (2n-1)!!, and it solves x*theta'' - 2*(x + n)*theta' + 2*n*theta = 0. The Bessel polynomial y_n is given by eval-bessel-y.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).x (double): the argument, any real number.Returns a double. The result for degree 0 is 1.0 whatever x is. ##NaN gives ##NaN for a positive degree. An infinite x gives the infinity of the leading term x^n: ##Inf for ##Inf, and for ##-Inf ##-Inf for an odd degree and ##Inf for an even one. For x >= 0 all terms are positive and the three term recurrence is used, with an error of a few units of roundoff times n relative to the value. For x < 0 the terms of the recurrence have opposite signs and it loses digits (up to the whole value), so the explicit sum is evaluated in decimal arithmetic whose precision is raised until the result settles: the result is the nearest double to about 2^-60, in a few milliseconds at degree 1000.
See also bessel-t, bessel-t-ratio, eval-bessel-y.
Evaluates the reverse Bessel polynomial `theta_n` at `x`. `theta_n(x) = x^n * y_n(1/x) = sum over k of (n+k)! / ((n-k)! * k! * 2^k) * x^(n-k)`, with `theta_0 = 1`, `theta_1 = x + 1` and `theta_n = (2n-1)*theta_(n-1) + x^2*theta_(n-2)`. It is monic, `theta_n(0) = (2n-1)!!`, and it solves `x*theta'' - 2*(x + n)*theta' + 2*n*theta = 0`. The Bessel polynomial `y_n` is given by [[eval-bessel-y]]. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `x` (double): the argument, any real number. Returns a double. The result for degree 0 is `1.0` whatever `x` is. `##NaN` gives `##NaN` for a positive degree. An infinite `x` gives the infinity of the leading term `x^n`: `##Inf` for `##Inf`, and for `##-Inf` `##-Inf` for an odd degree and `##Inf` for an even one. For `x >= 0` all terms are positive and the three term recurrence is used, with an error of a few units of roundoff times `n` relative to the value. For `x < 0` the terms of the recurrence have opposite signs and it loses digits (up to the whole value), so the explicit sum is evaluated in decimal arithmetic whose precision is raised until the result settles: the result is the nearest double to about 2^-60, in a few milliseconds at degree 1000. See also [[bessel-t]], [[bessel-t-ratio]], [[eval-bessel-y]].
(eval-bessel-y degree x)Evaluates the Bessel polynomial y_n at x.
y_n(x) = sum over k of (n+k)! / ((n-k)! * k!) * (x/2)^k, with y_0 = 1, y_1 = 1 + x and y_n = (2n-1)*x*y_(n-1) + y_(n-2). It solves x^2*y'' + (2x + 2)*y' - n*(n+1)*y = 0, y_n(0) = 1, and for x > 0 it is sqrt(2/(pi*x)) * exp(1/x) * K_(n+1/2)(1/x) with the modified Bessel function of the second kind K. The reverse polynomial x^n * y_n(1/x) is given by eval-bessel-t.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).x (double): the argument, any real number.Returns a double. The result for degree 0 is 1.0 whatever x is. ##NaN gives ##NaN for a positive degree. An infinite x gives the infinity of the leading term x^n: ##Inf for ##Inf, and for ##-Inf ##-Inf for an odd degree and ##Inf for an even one. For x >= 0 all terms are positive and the three term recurrence is used, with an error of a few units of roundoff times n relative to the value. For x < 0 the terms alternate in sign and the recurrence loses digits (up to the whole value), so the explicit sum is evaluated in decimal arithmetic whose precision is raised until the result settles: the result is the nearest double to about 2^-60, in a few milliseconds at degree 1000. Unlike evaluating the coefficients from bessel-y it stays accurate for any degree.
See also bessel-y, bessel-y-ratio, eval-bessel-t.
Evaluates the Bessel polynomial `y_n` at `x`. `y_n(x) = sum over k of (n+k)! / ((n-k)! * k!) * (x/2)^k`, with `y_0 = 1`, `y_1 = 1 + x` and `y_n = (2n-1)*x*y_(n-1) + y_(n-2)`. It solves `x^2*y'' + (2x + 2)*y' - n*(n+1)*y = 0`, `y_n(0) = 1`, and for `x > 0` it is `sqrt(2/(pi*x)) * exp(1/x) * K_(n+1/2)(1/x)` with the modified Bessel function of the second kind `K`. The reverse polynomial `x^n * y_n(1/x)` is given by [[eval-bessel-t]]. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `x` (double): the argument, any real number. Returns a double. The result for degree 0 is `1.0` whatever `x` is. `##NaN` gives `##NaN` for a positive degree. An infinite `x` gives the infinity of the leading term `x^n`: `##Inf` for `##Inf`, and for `##-Inf` `##-Inf` for an odd degree and `##Inf` for an even one. For `x >= 0` all terms are positive and the three term recurrence is used, with an error of a few units of roundoff times `n` relative to the value. For `x < 0` the terms alternate in sign and the recurrence loses digits (up to the whole value), so the explicit sum is evaluated in decimal arithmetic whose precision is raised until the result settles: the result is the nearest double to about 2^-60, in a few milliseconds at degree 1000. Unlike evaluating the coefficients from [[bessel-y]] it stays accurate for any degree. See also [[bessel-y]], [[bessel-y-ratio]], [[eval-bessel-t]].
(eval-chebyshev-T degree x)Evaluates the Chebyshev polynomial of the first kind T_n at x.
T_n(cos(a)) = cos(n*a). The polynomials are orthogonal on [-1, 1] with the weight 1/sqrt(1 - x^2) and satisfy T_0 = 1, T_1 = x and T_(n+1) = 2*x*T_n - T_(n-1). They are polynomials in x for every real x: outside [-1, 1] the value is the continuation of the polynomial, T_n(x) = cosh(n*acosh(x)) for x > 1.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).x (double): the argument, any real number.Returns a double. The result for degree 0 is 1.0 whatever x is. ##NaN gives ##NaN for a positive degree and an infinite x gives an infinity (negative for ##-Inf and an odd degree). The error is a few units of roundoff times n inside [-1, 1] (absolute, for values of at most 1) and a few units times n*log(2|x|) (relative) outside. This form stays accurate for any degree, unlike evaluating the coefficients from chebyshev-T.
See also chebyshev-T, chebyshev-T-ratio, eval-chebyshev-U, eval-chebyshev-V, eval-chebyshev-W.
Evaluates the Chebyshev polynomial of the first kind `T_n` at `x`. `T_n(cos(a)) = cos(n*a)`. The polynomials are orthogonal on `[-1, 1]` with the weight `1/sqrt(1 - x^2)` and satisfy `T_0 = 1`, `T_1 = x` and `T_(n+1) = 2*x*T_n - T_(n-1)`. They are polynomials in `x` for every real `x`: outside `[-1, 1]` the value is the continuation of the polynomial, `T_n(x) = cosh(n*acosh(x))` for `x > 1`. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `x` (double): the argument, any real number. Returns a double. The result for degree 0 is `1.0` whatever `x` is. `##NaN` gives `##NaN` for a positive degree and an infinite `x` gives an infinity (negative for `##-Inf` and an odd degree). The error is a few units of roundoff times `n` inside `[-1, 1]` (absolute, for values of at most 1) and a few units times `n*log(2|x|)` (relative) outside. This form stays accurate for any degree, unlike evaluating the coefficients from [[chebyshev-T]]. See also [[chebyshev-T]], [[chebyshev-T-ratio]], [[eval-chebyshev-U]], [[eval-chebyshev-V]], [[eval-chebyshev-W]].
(eval-chebyshev-U degree x)Evaluates the Chebyshev polynomial of the second kind U_n at x.
U_n(cos(a)) = sin((n+1)*a)/sin(a). The polynomials are orthogonal on [-1, 1] with the weight sqrt(1 - x^2) and satisfy U_0 = 1, U_1 = 2*x and U_(n+1) = 2*x*U_n - U_(n-1). They are polynomials in x for every real x: outside [-1, 1] the value is the continuation of the polynomial, U_n(x) = sinh((n+1)*acosh(x))/sinh(acosh(x)) for x > 1. U_n(1) = n+1 and U_n(-x) = (-1)^n*U_n(x).
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).x (double): the argument, any real number.Returns a double. The result for degree 0 is 1.0 whatever x is. ##NaN gives ##NaN for a positive degree and an infinite x gives an infinity (negative for ##-Inf and an odd degree). The value is finite whenever the polynomial value is representable. The error is a few units of roundoff times n inside [-1, 1] (absolute, for values of at most n+1) and a few units times n*log(2|x|) (relative) outside. This form stays accurate for any degree, unlike evaluating the coefficients from chebyshev-U.
See also chebyshev-U, chebyshev-U-ratio, eval-chebyshev-T, eval-chebyshev-V, eval-chebyshev-W, eval-gegenbauer-C.
Evaluates the Chebyshev polynomial of the second kind `U_n` at `x`. `U_n(cos(a)) = sin((n+1)*a)/sin(a)`. The polynomials are orthogonal on `[-1, 1]` with the weight `sqrt(1 - x^2)` and satisfy `U_0 = 1`, `U_1 = 2*x` and `U_(n+1) = 2*x*U_n - U_(n-1)`. They are polynomials in `x` for every real `x`: outside `[-1, 1]` the value is the continuation of the polynomial, `U_n(x) = sinh((n+1)*acosh(x))/sinh(acosh(x))` for `x > 1`. `U_n(1) = n+1` and `U_n(-x) = (-1)^n*U_n(x)`. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `x` (double): the argument, any real number. Returns a double. The result for degree 0 is `1.0` whatever `x` is. `##NaN` gives `##NaN` for a positive degree and an infinite `x` gives an infinity (negative for `##-Inf` and an odd degree). The value is finite whenever the polynomial value is representable. The error is a few units of roundoff times `n` inside `[-1, 1]` (absolute, for values of at most `n+1`) and a few units times `n*log(2|x|)` (relative) outside. This form stays accurate for any degree, unlike evaluating the coefficients from [[chebyshev-U]]. See also [[chebyshev-U]], [[chebyshev-U-ratio]], [[eval-chebyshev-T]], [[eval-chebyshev-V]], [[eval-chebyshev-W]], [[eval-gegenbauer-C]].
(eval-chebyshev-V degree x)Evaluates the Chebyshev polynomial of the third kind V_n at x.
V_n(cos(a)) = cos((n+1/2)*a)/cos(a/2). The polynomials are orthogonal on [-1, 1] with the weight sqrt((1+x)/(1-x)) and satisfy V_0 = 1, V_1 = 2*x - 1 and V_(n+1) = 2*x*V_n - V_(n-1). Also V_n = U_n - U_(n-1), V_n(1) = 1, V_n(-1) = (-1)^n*(2*n+1) and V_n(-x) = (-1)^n*W_n(x). They are polynomials in x for every real x, and the value is the polynomial for any argument outside [-1, 1] too.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).x (double): the argument, any real number.Returns a double. The result for degree 0 is 1.0 whatever x is. ##NaN gives ##NaN for a positive degree and an infinite x gives an infinity (negative for ##-Inf and an odd degree). The error is a few units of roundoff times n inside [-1, 1] (absolute, for values of at most 2*n+1), up to several times that next to x = 1, where the result is a difference of two nearly equal values, and a few units times n*log(2|x|) (relative) outside. For arguments just above 1 and degrees in the thousands the result can overflow to infinity slightly before the true value does.
See also chebyshev-V, chebyshev-V-ratio, eval-chebyshev-W, eval-chebyshev-U, eval-chebyshev-T.
Evaluates the Chebyshev polynomial of the third kind `V_n` at `x`. `V_n(cos(a)) = cos((n+1/2)*a)/cos(a/2)`. The polynomials are orthogonal on `[-1, 1]` with the weight `sqrt((1+x)/(1-x))` and satisfy `V_0 = 1`, `V_1 = 2*x - 1` and `V_(n+1) = 2*x*V_n - V_(n-1)`. Also `V_n = U_n - U_(n-1)`, `V_n(1) = 1`, `V_n(-1) = (-1)^n*(2*n+1)` and `V_n(-x) = (-1)^n*W_n(x)`. They are polynomials in `x` for every real `x`, and the value is the polynomial for any argument outside `[-1, 1]` too. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `x` (double): the argument, any real number. Returns a double. The result for degree 0 is `1.0` whatever `x` is. `##NaN` gives `##NaN` for a positive degree and an infinite `x` gives an infinity (negative for `##-Inf` and an odd degree). The error is a few units of roundoff times `n` inside `[-1, 1]` (absolute, for values of at most `2*n+1`), up to several times that next to `x = 1`, where the result is a difference of two nearly equal values, and a few units times `n*log(2|x|)` (relative) outside. For arguments just above 1 and degrees in the thousands the result can overflow to infinity slightly before the true value does. See also [[chebyshev-V]], [[chebyshev-V-ratio]], [[eval-chebyshev-W]], [[eval-chebyshev-U]], [[eval-chebyshev-T]].
(eval-chebyshev-W degree x)Evaluates the Chebyshev polynomial of the fourth kind W_n at x.
W_n(cos(a)) = sin((n+1/2)*a)/sin(a/2). The polynomials are orthogonal on [-1, 1] with the weight sqrt((1-x)/(1+x)) and satisfy W_0 = 1, W_1 = 2*x + 1 and W_(n+1) = 2*x*W_n - W_(n-1). Also W_n = U_n + U_(n-1), W_n(1) = 2*n+1, W_n(-1) = (-1)^n and W_n(-x) = (-1)^n*V_n(x). They are polynomials in x for every real x, and the value is the polynomial for any argument outside [-1, 1] too.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).x (double): the argument, any real number.Returns a double. The result for degree 0 is 1.0 whatever x is. ##NaN gives ##NaN for a positive degree and an infinite x gives an infinity (negative for ##-Inf and an odd degree). The error is a few units of roundoff times n inside [-1, 1] (absolute, for values of at most 2*n+1), up to several times that next to x = -1, where the result is a difference of two nearly equal values, and a few units times n*log(2|x|) (relative) outside. For arguments just below -1 and degrees in the thousands the result can overflow to infinity slightly before the true value does.
See also chebyshev-W, chebyshev-W-ratio, eval-chebyshev-V, eval-chebyshev-U, eval-chebyshev-T.
Evaluates the Chebyshev polynomial of the fourth kind `W_n` at `x`. `W_n(cos(a)) = sin((n+1/2)*a)/sin(a/2)`. The polynomials are orthogonal on `[-1, 1]` with the weight `sqrt((1-x)/(1+x))` and satisfy `W_0 = 1`, `W_1 = 2*x + 1` and `W_(n+1) = 2*x*W_n - W_(n-1)`. Also `W_n = U_n + U_(n-1)`, `W_n(1) = 2*n+1`, `W_n(-1) = (-1)^n` and `W_n(-x) = (-1)^n*V_n(x)`. They are polynomials in `x` for every real `x`, and the value is the polynomial for any argument outside `[-1, 1]` too. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `x` (double): the argument, any real number. Returns a double. The result for degree 0 is `1.0` whatever `x` is. `##NaN` gives `##NaN` for a positive degree and an infinite `x` gives an infinity (negative for `##-Inf` and an odd degree). The error is a few units of roundoff times `n` inside `[-1, 1]` (absolute, for values of at most `2*n+1`), up to several times that next to `x = -1`, where the result is a difference of two nearly equal values, and a few units times `n*log(2|x|)` (relative) outside. For arguments just below -1 and degrees in the thousands the result can overflow to infinity slightly before the true value does. See also [[chebyshev-W]], [[chebyshev-W-ratio]], [[eval-chebyshev-V]], [[eval-chebyshev-U]], [[eval-chebyshev-T]].
(eval-gegenbauer-C degree x)(eval-gegenbauer-C degree order x)Evaluates the Gegenbauer (ultraspherical) polynomial C_n^(a) of order a at x.
The polynomials have the generating function (1 - 2*x*t + t^2)^(-a) and satisfy C_0 = 1, C_1 = 2*a*x and n*C_n = 2*(n+a-1)*x*C_(n-1) - (n+2*a-2)*C_(n-2). For a > -1/2 and a not 0 they are orthogonal on [-1, 1] with the weight (1 - x^2)^(a - 1/2). They are polynomials in x for every real x and every real order, and C_n(-x) = (-1)^n*C_n(x). The order 1 gives the Chebyshev polynomials of the second kind and the order 0.5 the Legendre polynomials; these two orders return exactly the values of eval-chebyshev-U and eval-legendre-P.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).order (double): the order a, any real number, default 1.0 (the two-argument form). A negative order is allowed. For the order 0 the recurrence gives C_0 = 1 and C_n = 0 for every higher degree (the same values as scipy and mpmath give); the Chebyshev polynomials of the first kind are the limit of C_n/a, not the value.x (double): the argument, any real number.Returns a double. The result for degree 0 is 1.0 whatever order and x are. ##NaN as x or as order gives ##NaN for a positive degree. An infinite x gives the infinity of the leading non-zero term of the polynomial (so 0 for the order 0, and ##NaN for an infinite order). The leading term is found from the signs alone, so that case is fast for any degree; the limit is 0 for a negative integer order -k and a degree above 2k, and the constant 1 for the degree 2k.
For an order of -0.9 and above the three term recurrence is used and the error is a few units of roundoff times n (absolute, for values of at most n+1) inside [-1, 1], and relative outside; unlike evaluating the coefficients from gegenbauer-C it stays accurate for any degree. Below -0.9 the recurrence loses digits (the polynomial is small against its intermediate values and a negative integer order gives noise for a polynomial that is 0), so the explicit sum is evaluated in decimal arithmetic whose precision is raised until the result settles: the result is then the nearest double to about 2^-60, and exactly 0 for a negative integer order -k and a degree above 2k. That takes more time for a high degree (about 0.1 s for degree 1000, a second or more for degree 5000). The value is continuous in the order, also at 1 and 0.5.
See also gegenbauer-C, gegenbauer-C-ratio, eval-chebyshev-U, eval-legendre-P, eval-jacobi-P.
Evaluates the Gegenbauer (ultraspherical) polynomial `C_n^(a)` of order `a` at `x`. The polynomials have the generating function `(1 - 2*x*t + t^2)^(-a)` and satisfy `C_0 = 1`, `C_1 = 2*a*x` and `n*C_n = 2*(n+a-1)*x*C_(n-1) - (n+2*a-2)*C_(n-2)`. For `a > -1/2` and `a` not 0 they are orthogonal on `[-1, 1]` with the weight `(1 - x^2)^(a - 1/2)`. They are polynomials in `x` for every real `x` and every real order, and `C_n(-x) = (-1)^n*C_n(x)`. The order 1 gives the Chebyshev polynomials of the second kind and the order 0.5 the Legendre polynomials; these two orders return exactly the values of [[eval-chebyshev-U]] and [[eval-legendre-P]]. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `order` (double): the order `a`, any real number, default 1.0 (the two-argument form). A negative order is allowed. For the order 0 the recurrence gives `C_0 = 1` and `C_n = 0` for every higher degree (the same values as `scipy` and `mpmath` give); the Chebyshev polynomials of the first kind are the limit of `C_n/a`, not the value. - `x` (double): the argument, any real number. Returns a double. The result for degree 0 is `1.0` whatever `order` and `x` are. `##NaN` as `x` or as `order` gives `##NaN` for a positive degree. An infinite `x` gives the infinity of the leading non-zero term of the polynomial (so 0 for the order 0, and `##NaN` for an infinite order). The leading term is found from the signs alone, so that case is fast for any degree; the limit is 0 for a negative integer order `-k` and a degree above `2k`, and the constant 1 for the degree `2k`. For an order of -0.9 and above the three term recurrence is used and the error is a few units of roundoff times `n` (absolute, for values of at most `n+1`) inside `[-1, 1]`, and relative outside; unlike evaluating the coefficients from [[gegenbauer-C]] it stays accurate for any degree. Below -0.9 the recurrence loses digits (the polynomial is small against its intermediate values and a negative integer order gives noise for a polynomial that is 0), so the explicit sum is evaluated in decimal arithmetic whose precision is raised until the result settles: the result is then the nearest double to about 2^-60, and exactly 0 for a negative integer order `-k` and a degree above `2k`. That takes more time for a high degree (about 0.1 s for degree 1000, a second or more for degree 5000). The value is continuous in the order, also at 1 and 0.5. See also [[gegenbauer-C]], [[gegenbauer-C-ratio]], [[eval-chebyshev-U]], [[eval-legendre-P]], [[eval-jacobi-P]].
(eval-hermite-H degree x)Evaluates the Hermite polynomial H_n (physicists' convention) at x.
The polynomials are orthogonal on the whole real line with the weight exp(-x^2) and satisfy H_0 = 1, H_1 = 2*x and H_n = 2*x*H_(n-1) - 2*(n-1)*H_(n-2); the leading coefficient is 2^n. H_n(-x) = (-1)^n*H_n(x). The probabilists' polynomials He_n(x) = 2^(-n/2)*H_n(x/sqrt(2)) are given by eval-hermite-He.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).x (double): the argument, any real number.Returns a double. The result for degree 0 is 1.0 whatever x is. ##NaN gives ##NaN for a positive degree. An infinite x gives the infinity of the leading term: ##-Inf for ##-Inf and an odd degree, ##Inf otherwise. The error is a few units of roundoff times n relative to the value (absolute next to a zero), so this form stays accurate for any degree, unlike evaluating the coefficients from hermite-H. Where the true value is beyond the range of a double the result is the infinity with its sign, for a finite x as for an infinite one; an intermediate value that would overflow while the result is representable does not matter.
See also hermite-H, hermite-H-ratio, eval-hermite-He, eval-laguerre-L.
Evaluates the Hermite polynomial `H_n` (physicists' convention) at `x`. The polynomials are orthogonal on the whole real line with the weight `exp(-x^2)` and satisfy `H_0 = 1`, `H_1 = 2*x` and `H_n = 2*x*H_(n-1) - 2*(n-1)*H_(n-2)`; the leading coefficient is `2^n`. `H_n(-x) = (-1)^n*H_n(x)`. The probabilists' polynomials `He_n(x) = 2^(-n/2)*H_n(x/sqrt(2))` are given by [[eval-hermite-He]]. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `x` (double): the argument, any real number. Returns a double. The result for degree 0 is `1.0` whatever `x` is. `##NaN` gives `##NaN` for a positive degree. An infinite `x` gives the infinity of the leading term: `##-Inf` for `##-Inf` and an odd degree, `##Inf` otherwise. The error is a few units of roundoff times `n` relative to the value (absolute next to a zero), so this form stays accurate for any degree, unlike evaluating the coefficients from [[hermite-H]]. Where the true value is beyond the range of a double the result is the infinity with its sign, for a finite `x` as for an infinite one; an intermediate value that would overflow while the result is representable does not matter. See also [[hermite-H]], [[hermite-H-ratio]], [[eval-hermite-He]], [[eval-laguerre-L]].
(eval-hermite-He degree x)Evaluates the Hermite polynomial He_n (probabilists' convention) at x.
The polynomials are orthogonal on the whole real line with the weight exp(-x^2/2) and satisfy He_0 = 1, He_1 = x and He_n = x*He_(n-1) - (n-1)*He_(n-2); the leading coefficient is 1. He_n(-x) = (-1)^n*He_n(x). The physicists' polynomials H_n(x) = 2^(n/2)*He_n(sqrt(2)*x) are given by eval-hermite-H.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).x (double): the argument, any real number.Returns a double. The result for degree 0 is 1.0 whatever x is. ##NaN gives ##NaN for a positive degree. An infinite x gives the infinity of the leading term: ##-Inf for ##-Inf and an odd degree, ##Inf otherwise. The error is a few units of roundoff times n relative to the value (absolute next to a zero), so this form stays accurate for any degree, unlike evaluating the coefficients from hermite-He. Where the true value is beyond the range of a double the result is the infinity with its sign, for a finite x as for an infinite one; an intermediate value that would overflow while the result is representable does not matter.
See also hermite-He, hermite-He-ratio, eval-hermite-H.
Evaluates the Hermite polynomial `He_n` (probabilists' convention) at `x`. The polynomials are orthogonal on the whole real line with the weight `exp(-x^2/2)` and satisfy `He_0 = 1`, `He_1 = x` and `He_n = x*He_(n-1) - (n-1)*He_(n-2)`; the leading coefficient is 1. `He_n(-x) = (-1)^n*He_n(x)`. The physicists' polynomials `H_n(x) = 2^(n/2)*He_n(sqrt(2)*x)` are given by [[eval-hermite-H]]. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `x` (double): the argument, any real number. Returns a double. The result for degree 0 is `1.0` whatever `x` is. `##NaN` gives `##NaN` for a positive degree. An infinite `x` gives the infinity of the leading term: `##-Inf` for `##-Inf` and an odd degree, `##Inf` otherwise. The error is a few units of roundoff times `n` relative to the value (absolute next to a zero), so this form stays accurate for any degree, unlike evaluating the coefficients from [[hermite-He]]. Where the true value is beyond the range of a double the result is the infinity with its sign, for a finite `x` as for an infinite one; an intermediate value that would overflow while the result is representable does not matter. See also [[hermite-He]], [[hermite-He-ratio]], [[eval-hermite-H]].
(eval-jacobi-P degree alpha beta x)Evaluates the Jacobi polynomial P_n^(a,b) at x.
The polynomials satisfy P_0 = 1, P_1 = (a+1) + (a+b+2)*(x-1)/2 and a three term recurrence in n. They are equal to the sum over k of C(n+a, n-k)*C(n+b, k)*((x-1)/2)^k*((x+1)/2)^(n-k), with generalized binomial coefficients, which defines them for every real a and b. For a > -1 and b > -1 they are orthogonal on [-1, 1] with the weight (1-x)^a*(1+x)^b. P_n(1) = C(n+a, n) and P_n^(a,b)(-x) = (-1)^n*P_n^(b,a)(x). For a = b = 0 they are the Legendre polynomials, and for a = b = c - 1/2 they are proportional to the Gegenbauer polynomials of order c.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).alpha (double): the parameter a, any real number.beta (double): the parameter b, any real number.x (double): the argument, any real number.Returns a double. The result for degree 0 is 1.0 whatever the other arguments are. ##NaN as x, alpha or beta gives ##NaN for a positive degree. An infinite x gives the infinity of the leading non-zero term of the polynomial (a finite constant when the polynomial is constant, as for degree 1 and a + b = -2); the leading term is found from the signs alone, so that case is fast for any degree.
For a > -1, b > -1 and a + b > -1.9 the three term recurrence is used, and the error is a few units of roundoff times n (absolute, for values of at most n+1) inside [-1, 1]; it was at most 2.5 on random parameters of this range. Otherwise the recurrence is not used: it divides by zero when a + b is a negative integer from -degree to -2 (or an even one down to 2 - 2*degree) and loses digits, up to thousands of units, for a parameter below -1 or for a + b next to such a value. Then the sum above is evaluated in decimal arithmetic whose precision is raised until the result settles, so the result is the nearest double to about 2^-60, also next to a multiple root at 1 or -1 (a negative integer a or b). That takes more time for a high degree (about 0.2 s for degree 1000, a few seconds for degree 5000).
See also jacobi-P, jacobi-P-ratio, eval-gegenbauer-C, eval-legendre-P.
Evaluates the Jacobi polynomial `P_n^(a,b)` at `x`. The polynomials satisfy `P_0 = 1`, `P_1 = (a+1) + (a+b+2)*(x-1)/2` and a three term recurrence in `n`. They are equal to the sum over `k` of `C(n+a, n-k)*C(n+b, k)*((x-1)/2)^k*((x+1)/2)^(n-k)`, with generalized binomial coefficients, which defines them for every real `a` and `b`. For `a > -1` and `b > -1` they are orthogonal on `[-1, 1]` with the weight `(1-x)^a*(1+x)^b`. `P_n(1) = C(n+a, n)` and `P_n^(a,b)(-x) = (-1)^n*P_n^(b,a)(x)`. For `a = b = 0` they are the Legendre polynomials, and for `a = b = c - 1/2` they are proportional to the Gegenbauer polynomials of order `c`. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `alpha` (double): the parameter `a`, any real number. - `beta` (double): the parameter `b`, any real number. - `x` (double): the argument, any real number. Returns a double. The result for degree 0 is `1.0` whatever the other arguments are. `##NaN` as `x`, `alpha` or `beta` gives `##NaN` for a positive degree. An infinite `x` gives the infinity of the leading non-zero term of the polynomial (a finite constant when the polynomial is constant, as for degree 1 and `a + b = -2`); the leading term is found from the signs alone, so that case is fast for any degree. For `a > -1`, `b > -1` and `a + b > -1.9` the three term recurrence is used, and the error is a few units of roundoff times `n` (absolute, for values of at most `n+1`) inside `[-1, 1]`; it was at most 2.5 on random parameters of this range. Otherwise the recurrence is not used: it divides by zero when `a + b` is a negative integer from `-degree` to `-2` (or an even one down to `2 - 2*degree`) and loses digits, up to thousands of units, for a parameter below -1 or for `a + b` next to such a value. Then the sum above is evaluated in decimal arithmetic whose precision is raised until the result settles, so the result is the nearest double to about 2^-60, also next to a multiple root at 1 or -1 (a negative integer `a` or `b`). That takes more time for a high degree (about 0.2 s for degree 1000, a few seconds for degree 5000). See also [[jacobi-P]], [[jacobi-P-ratio]], [[eval-gegenbauer-C]], [[eval-legendre-P]].
(eval-laguerre-L degree x)(eval-laguerre-L degree order x)Evaluates the generalized Laguerre polynomial L_n^(a) of order a at x.
The polynomials are L_n^(a)(x) = sum over k of (-1)^k*C(n+a, n-k)*x^k/k! with generalized binomial coefficients, and satisfy L_0 = 1, L_1 = 1 + a - x and n*L_n = (2n-1+a-x)*L_(n-1) - (n-1+a)*L_(n-2). For a > -1 they are orthogonal on [0, Inf) with the weight x^a*exp(-x). L_n(0) = C(n+a, n). The order 0 gives the Laguerre polynomials (the default of the two-argument form).
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).order (double): the order a, any real number, default 0.0 (the two-argument form). A negative order is allowed: the polynomials are then defined by the same sum and recurrence, but they are not orthogonal.x (double): the argument, any real number.Returns a double. The result for degree 0 is 1.0 whatever order and x are. ##NaN as x or as order gives ##NaN for a positive degree. An infinite x gives the infinity of the leading term (-1)^n*x^n/n!: ##-Inf for ##Inf and an odd degree, ##Inf otherwise, and ##NaN for a NaN or infinite order. The error of the recurrence grows like the square of the degree: relative to the largest value of L_0 ... L_n at x it is about (n+1)^2 times the roundoff (roughly 1e-13 at degree 100 close to x = 0, much smaller at a low degree), which is larger than for eval-chebyshev-T. For a negative order of at most -3 and a high degree the intermediate values are far larger than the result and the relative error of the result can be much larger. Unlike evaluating the coefficients from laguerre-L it does not suffer from the cancellation of the large alternating coefficients. Where the true value is beyond the range of a double the result is the infinity with its sign, for a finite x as for an infinite one; an intermediate value that would overflow while the result is representable does not matter.
See also laguerre-L, laguerre-L-ratio, eval-hermite-H.
Evaluates the generalized Laguerre polynomial `L_n^(a)` of order `a` at `x`. The polynomials are `L_n^(a)(x) = sum over k of (-1)^k*C(n+a, n-k)*x^k/k!` with generalized binomial coefficients, and satisfy `L_0 = 1`, `L_1 = 1 + a - x` and `n*L_n = (2n-1+a-x)*L_(n-1) - (n-1+a)*L_(n-2)`. For `a > -1` they are orthogonal on `[0, Inf)` with the weight `x^a*exp(-x)`. `L_n(0) = C(n+a, n)`. The order 0 gives the Laguerre polynomials (the default of the two-argument form). Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `order` (double): the order `a`, any real number, default 0.0 (the two-argument form). A negative order is allowed: the polynomials are then defined by the same sum and recurrence, but they are not orthogonal. - `x` (double): the argument, any real number. Returns a double. The result for degree 0 is `1.0` whatever `order` and `x` are. `##NaN` as `x` or as `order` gives `##NaN` for a positive degree. An infinite `x` gives the infinity of the leading term `(-1)^n*x^n/n!`: `##-Inf` for `##Inf` and an odd degree, `##Inf` otherwise, and `##NaN` for a NaN or infinite `order`. The error of the recurrence grows like the square of the degree: relative to the largest value of `L_0 ... L_n` at `x` it is about `(n+1)^2` times the roundoff (roughly 1e-13 at degree 100 close to `x = 0`, much smaller at a low degree), which is larger than for [[eval-chebyshev-T]]. For a negative order of at most -3 and a high degree the intermediate values are far larger than the result and the relative error of the result can be much larger. Unlike evaluating the coefficients from [[laguerre-L]] it does not suffer from the cancellation of the large alternating coefficients. Where the true value is beyond the range of a double the result is the infinity with its sign, for a finite `x` as for an infinite one; an intermediate value that would overflow while the result is representable does not matter. See also [[laguerre-L]], [[laguerre-L-ratio]], [[eval-hermite-H]].
(eval-legendre-P degree x)Evaluates the Legendre polynomial P_n at x.
The polynomials are orthogonal on [-1, 1] with the weight 1 and satisfy P_0 = 1, P_1 = x and n*P_n = (2n-1)*x*P_(n-1) - (n-1)*P_(n-2). They are polynomials in x for every real x, so outside [-1, 1] the value is the continuation of the polynomial. P_n(1) = 1 and P_n(-x) = (-1)^n*P_n(x).
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).x (double): the argument, any real number.Returns a double. The result for degree 0 is 1.0 whatever x is. ##NaN gives ##NaN for a positive degree. An infinite x gives x for degree 1 and for a higher degree the infinity of the leading term: ##Inf for an even degree, x for an odd one. The error is a few units of roundoff times n (absolute, for values of at most n+1) inside [-1, 1], and relative outside, so this form stays accurate for any degree, unlike evaluating the coefficients from legendre-P.
See also legendre-P, legendre-P-ratio, eval-gegenbauer-C (P_n is the Gegenbauer polynomial of order 0.5), eval-jacobi-P.
Evaluates the Legendre polynomial `P_n` at `x`. The polynomials are orthogonal on `[-1, 1]` with the weight 1 and satisfy `P_0 = 1`, `P_1 = x` and `n*P_n = (2n-1)*x*P_(n-1) - (n-1)*P_(n-2)`. They are polynomials in `x` for every real `x`, so outside `[-1, 1]` the value is the continuation of the polynomial. `P_n(1) = 1` and `P_n(-x) = (-1)^n*P_n(x)`. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `x` (double): the argument, any real number. Returns a double. The result for degree 0 is `1.0` whatever `x` is. `##NaN` gives `##NaN` for a positive degree. An infinite `x` gives `x` for degree 1 and for a higher degree the infinity of the leading term: `##Inf` for an even degree, `x` for an odd one. The error is a few units of roundoff times `n` (absolute, for values of at most `n+1`) inside `[-1, 1]`, and relative outside, so this form stays accurate for any degree, unlike evaluating the coefficients from [[legendre-P]]. See also [[legendre-P]], [[legendre-P-ratio]], [[eval-gegenbauer-C]] (`P_n` is the Gegenbauer polynomial of order 0.5), [[eval-jacobi-P]].
(eval-meixner-pollaczek-P degree lambda phi x)Evaluates the Meixner-Pollaczek polynomial P_n^(l)(x; phi) at x.
The polynomials have the generating function (1 - exp(i*phi)*t)^(-l + i*x) * (1 - exp(-i*phi)*t)^(-l - i*x) (i is the imaginary unit), that is P_n = (2l)_n / n! * exp(i*n*phi) * 2F1(-n, l + i*x; 2l; 1 - exp(-2*i*phi)), and satisfy P_0 = 1, P_1 = 2*(l*cos(phi) + x*sin(phi)) and n*P_n = 2*(x*sin(phi) + (n-1+l)*cos(phi))*P_(n-1) - (n-2+2*l)*P_(n-2). They are real polynomials of degree n in x with the leading coefficient (2*sin(phi))^n / n!. For l > 0 and 0 < phi < pi they are orthogonal on the real line with the weight exp((2*phi - pi)*x) * |Gamma(l + i*x)|^2.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).lambda (double): the parameter l. The recurrence defines the polynomials for every real l (also 0 and negative), but they are orthogonal only for l > 0.phi (double): the angle. The polynomials are defined for every real phi, with the period 2*pi, and P_n(x; pi - phi) = (-1)^n * P_n(-x; phi); they are orthogonal only for 0 < phi < pi. For phi = 0 and phi = pi the polynomial does not depend on x.x (double): the argument, any real number.Returns a double. The result for degree 0 is 1.0 whatever the other arguments are. ##NaN as x, lambda or phi gives ##NaN for a positive degree. An infinite x gives the infinity of the leading term (its sign follows sin(phi) * x and the parity of the degree), the value of the constant when sin(phi) is 0, and ##NaN for a NaN or infinite lambda or phi. The error of the recurrence grows like the square of the degree relative to the largest value of P_0 ... P_n at x: at most about 3 times (n+1)^2 units of roundoff on the reference grid, so a few units at low degrees and about 1e-12 relative at degree 50 for a small phi. The sine and cosine of phi are accurate also next to their zeros. Where the true value is beyond the range of a double the result is the infinity with its sign, for a finite x as for an infinite one; an intermediate value that would overflow while the result is representable does not matter.
See also meixner-pollaczek-P, meixner-pollaczek-P-ratio, eval-hermite-H.
Evaluates the Meixner-Pollaczek polynomial `P_n^(l)(x; phi)` at `x`. The polynomials have the generating function `(1 - exp(i*phi)*t)^(-l + i*x) * (1 - exp(-i*phi)*t)^(-l - i*x)` (`i` is the imaginary unit), that is `P_n = (2l)_n / n! * exp(i*n*phi) * 2F1(-n, l + i*x; 2l; 1 - exp(-2*i*phi))`, and satisfy `P_0 = 1`, `P_1 = 2*(l*cos(phi) + x*sin(phi))` and `n*P_n = 2*(x*sin(phi) + (n-1+l)*cos(phi))*P_(n-1) - (n-2+2*l)*P_(n-2)`. They are real polynomials of degree `n` in `x` with the leading coefficient `(2*sin(phi))^n / n!`. For `l > 0` and `0 < phi < pi` they are orthogonal on the real line with the weight `exp((2*phi - pi)*x) * |Gamma(l + i*x)|^2`. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `lambda` (double): the parameter `l`. The recurrence defines the polynomials for every real `l` (also 0 and negative), but they are orthogonal only for `l > 0`. - `phi` (double): the angle. The polynomials are defined for every real `phi`, with the period `2*pi`, and `P_n(x; pi - phi) = (-1)^n * P_n(-x; phi)`; they are orthogonal only for `0 < phi < pi`. For `phi = 0` and `phi = pi` the polynomial does not depend on `x`. - `x` (double): the argument, any real number. Returns a double. The result for degree 0 is `1.0` whatever the other arguments are. `##NaN` as `x`, `lambda` or `phi` gives `##NaN` for a positive degree. An infinite `x` gives the infinity of the leading term (its sign follows `sin(phi) * x` and the parity of the degree), the value of the constant when `sin(phi)` is 0, and `##NaN` for a NaN or infinite `lambda` or `phi`. The error of the recurrence grows like the square of the degree relative to the largest value of `P_0 ... P_n` at `x`: at most about 3 times `(n+1)^2` units of roundoff on the reference grid, so a few units at low degrees and about 1e-12 relative at degree 50 for a small `phi`. The sine and cosine of `phi` are accurate also next to their zeros. Where the true value is beyond the range of a double the result is the infinity with its sign, for a finite `x` as for an infinite one; an intermediate value that would overflow while the result is representable does not matter. See also [[meixner-pollaczek-P]], [[meixner-pollaczek-P-ratio]], [[eval-hermite-H]].
(evalpoly x & coeffs)Evaluates a real polynomial at x for the given coefficients in ascending order of power.
The polynomial is c0 + c1*x + c2*x^2 + .... The roundoff error is bounded by about 2*n*eps times the sum of |ci*x^i| for n coefficients, so the result is accurate except close to a root.
Parameters:
x (number): the point of evaluation, converted to a double.coeffs (numbers): the coefficients c0, c1, ... as separate arguments; use apply for a collection. Any numeric type is accepted; a ratio is converted by double, which keeps about 16 significant digits (use ratio-polynomial with evaluate for exact coefficients).Returns a double. Without coefficients the result is 0.0; with a single coefficient it is that coefficient as a double, whatever x is. A result that cancels to exactly zero is +0.0, but negative zero coefficients can give -0.0 (the sum of negative zeros is a negative zero). For an infinite or NaN x the result follows floating point arithmetic, so ##NaN gives ##NaN and a product of an infinity and a zero gives ##NaN.
Calls with explicit coefficients give the same result as mevalpoly and as the function from makepoly, bit for bit.
See also mevalpoly, makepoly, evalpoly-complex, evalpoly-scalar-complex, polynomial.
Evaluates a real polynomial at `x` for the given coefficients in ascending order of power. The polynomial is `c0 + c1*x + c2*x^2 + ...`. The roundoff error is bounded by about `2*n*eps` times the sum of `|ci*x^i|` for `n` coefficients, so the result is accurate except close to a root. Parameters: - `x` (number): the point of evaluation, converted to a double. - `coeffs` (numbers): the coefficients `c0`, `c1`, ... as separate arguments; use `apply` for a collection. Any numeric type is accepted; a ratio is converted by `double`, which keeps about 16 significant digits (use [[ratio-polynomial]] with [[evaluate]] for exact coefficients). Returns a double. Without coefficients the result is `0.0`; with a single coefficient it is that coefficient as a double, whatever `x` is. A result that cancels to exactly zero is `+0.0`, but negative zero coefficients can give `-0.0` (the sum of negative zeros is a negative zero). For an infinite or NaN `x` the result follows floating point arithmetic, so `##NaN` gives `##NaN` and a product of an infinity and a zero gives `##NaN`. Calls with explicit coefficients give the same result as [[mevalpoly]] and as the function from [[makepoly]], bit for bit. See also [[mevalpoly]], [[makepoly]], [[evalpoly-complex]], [[evalpoly-scalar-complex]], [[polynomial]].
(evalpoly-complex z & coeffs)Evaluates a complex polynomial at z for the given coefficients in ascending order of power.
The polynomial is c0 + c1*z + c2*z^2 + .... The roundoff error is bounded by about 4*n times the machine epsilon times the sum of |ci*z^i| for n coefficients.
Parameters:
z (complex number): the point of evaluation; a real number is treated as a complex number with a zero imaginary part.coeffs (complex numbers): the coefficients c0, c1, ... as separate arguments; use apply for a collection. Each can be a Vec2 or a real number.Returns a Vec2. Without coefficients the result is fastmath.complex/ZERO; with a single coefficient it is that coefficient as a Vec2, whatever z is. For infinite or NaN parts the result follows complex floating point arithmetic, so for example an infinite real z can produce ##NaN in the imaginary part.
See also evalpoly-scalar-complex (real coefficients), mevalpoly-complex, makepoly-complex, evalpoly.
Evaluates a complex polynomial at `z` for the given coefficients in ascending order of power. The polynomial is `c0 + c1*z + c2*z^2 + ...`. The roundoff error is bounded by about `4*n` times the machine epsilon times the sum of `|ci*z^i|` for `n` coefficients. Parameters: - `z` (complex number): the point of evaluation; a real number is treated as a complex number with a zero imaginary part. - `coeffs` (complex numbers): the coefficients `c0`, `c1`, ... as separate arguments; use `apply` for a collection. Each can be a `Vec2` or a real number. Returns a `Vec2`. Without coefficients the result is `fastmath.complex/ZERO`; with a single coefficient it is that coefficient as a `Vec2`, whatever `z` is. For infinite or NaN parts the result follows complex floating point arithmetic, so for example an infinite real `z` can produce `##NaN` in the imaginary part. See also [[evalpoly-scalar-complex]] (real coefficients), [[mevalpoly-complex]], [[makepoly-complex]], [[evalpoly]].
(evalpoly-scalar-complex z & coeffs)Evaluates a complex polynomial with real coefficients at z for the given coefficients in ascending order of power.
The polynomial is c0 + c1*z + c2*z^2 + .... It gives the same result as evalpoly-complex, within roundoff, with less work when all coefficients are real. The roundoff error is bounded by about 8*n times the machine epsilon times the sum of |ci*z^i| for n coefficients.
Parameters:
z (complex number): the point of evaluation; a real number is treated as a complex number with a zero imaginary part.coeffs (numbers): the real coefficients c0, c1, ... as separate arguments; use apply for a collection. Any numeric type is accepted.Returns a Vec2. Without coefficients the result is fastmath.complex/ZERO; with a single coefficient it is that coefficient with a zero imaginary part, whatever z is. It is also valid for huge z (modulus above about 1e154), where the polynomial value is still representable, and for infinite or NaN parts, where it returns what evalpoly-complex returns.
See also evalpoly-complex, mevalpoly-scalar-complex, makepoly-scalar-complex, evalpoly.
Evaluates a complex polynomial with real coefficients at `z` for the given coefficients in ascending order of power. The polynomial is `c0 + c1*z + c2*z^2 + ...`. It gives the same result as [[evalpoly-complex]], within roundoff, with less work when all coefficients are real. The roundoff error is bounded by about `8*n` times the machine epsilon times the sum of `|ci*z^i|` for `n` coefficients. Parameters: - `z` (complex number): the point of evaluation; a real number is treated as a complex number with a zero imaginary part. - `coeffs` (numbers): the real coefficients `c0`, `c1`, ... as separate arguments; use `apply` for a collection. Any numeric type is accepted. Returns a `Vec2`. Without coefficients the result is `fastmath.complex/ZERO`; with a single coefficient it is that coefficient with a zero imaginary part, whatever `z` is. It is also valid for huge `z` (modulus above about 1e154), where the polynomial value is still representable, and for infinite or NaN parts, where it returns what [[evalpoly-complex]] returns. See also [[evalpoly-complex]], [[mevalpoly-scalar-complex]], [[makepoly-scalar-complex]], [[evalpoly]].
(evaluate poly x)Evaluates a polynomial object at a point and returns a double.
Parameters:
poly (polynomial object): from polynomial or from ratio-polynomial.x (number): the point of evaluation, converted to a double.For a PolynomialR the value is computed exactly at the decimal value of x and rounded to a double once. For NaN or infinite x both kinds of polynomial follow floating point arithmetic and give the same result. A polynomial object can also be called directly as a function of exactly one number (also through apply with one argument); then a Polynomial returns a double and a PolynomialR returns the exact ratio for a finite argument. No other call form is supported.
The monomial form loses accuracy for high degrees and close to a root. Use the eval-* functions of the orthogonal families (for example eval-legendre-P) for accurate values of those polynomials.
See also evalpoly, derivative.
Evaluates a polynomial object at a point and returns a double. Parameters: - `poly` (polynomial object): from [[polynomial]] or from [[ratio-polynomial]]. - `x` (number): the point of evaluation, converted to a double. For a `PolynomialR` the value is computed exactly at the decimal value of `x` and rounded to a double once. For NaN or infinite `x` both kinds of polynomial follow floating point arithmetic and give the same result. A polynomial object can also be called directly as a function of exactly one number (also through `apply` with one argument); then a `Polynomial` returns a double and a `PolynomialR` returns the exact ratio for a finite argument. No other call form is supported. The monomial form loses accuracy for high degrees and close to a root. Use the `eval-*` functions of the orthogonal families (for example [[eval-legendre-P]]) for accurate values of those polynomials. See also [[evalpoly]], [[derivative]].
(gegenbauer-C degree)(gegenbauer-C degree order)Creates the Gegenbauer (ultraspherical) polynomial C_n^(a) as a polynomial object with double coefficients.
See eval-gegenbauer-C for the definition and gegenbauer-C-ratio for the exact rational coefficients, which are converted to doubles.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).order (double): the order a, any real number, default 1.0 (the Chebyshev polynomials of the second kind). A NaN or infinite order throws an IllegalArgumentException for a positive degree; see gegenbauer-C-ratio for the conversion of the order.Returns a Polynomial (see polynomial) of degree n, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use eval-gegenbauer-C for values at a high degree.
See also gegenbauer-C-ratio, eval-gegenbauer-C, chebyshev-U, legendre-P.
Creates the Gegenbauer (ultraspherical) polynomial `C_n^(a)` as a polynomial object with double coefficients. See [[eval-gegenbauer-C]] for the definition and [[gegenbauer-C-ratio]] for the exact rational coefficients, which are converted to doubles. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `order` (double): the order `a`, any real number, default 1.0 (the Chebyshev polynomials of the second kind). A NaN or infinite order throws an `IllegalArgumentException` for a positive degree; see [[gegenbauer-C-ratio]] for the conversion of the order. Returns a `Polynomial` (see [[polynomial]]) of degree `n`, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use [[eval-gegenbauer-C]] for values at a high degree. See also [[gegenbauer-C-ratio]], [[eval-gegenbauer-C]], [[chebyshev-U]], [[legendre-P]].
(gegenbauer-C-ratio degree order)Creates the Gegenbauer (ultraspherical) polynomial C_n^(a) with exact rational coefficients.
C_0 = 1, C_1 = 2*a*x and n*C_n = 2*(n+a-1)*x*C_(n-1) - (n+2*a-2)*C_(n-2); see eval-gegenbauer-C for the definition, the orthogonality and the special orders.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).order (double): the order a, any real number. It is converted with rationalize, so a double becomes the exact decimal number it prints as (0.3 gives 3/10) and the coefficients are exact for that number. The orders 1 and 0.5 return chebyshev-U-ratio and legendre-P-ratio. For the order 0 every polynomial of a positive degree is the zero polynomial (zero coefficients).Returns a PolynomialR (see ratio-polynomial) of degree n: operations on it are exact, and it can be evaluated exactly at a rational argument. A NaN or infinite order throws an IllegalArgumentException for a positive degree; degree 0 returns the constant 1 for any order.
See also gegenbauer-C (double coefficients), eval-gegenbauer-C (direct evaluation).
Creates the Gegenbauer (ultraspherical) polynomial `C_n^(a)` with exact rational coefficients. `C_0 = 1`, `C_1 = 2*a*x` and `n*C_n = 2*(n+a-1)*x*C_(n-1) - (n+2*a-2)*C_(n-2)`; see [[eval-gegenbauer-C]] for the definition, the orthogonality and the special orders. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `order` (double): the order `a`, any real number. It is converted with `rationalize`, so a double becomes the exact decimal number it prints as (`0.3` gives `3/10`) and the coefficients are exact for that number. The orders 1 and 0.5 return [[chebyshev-U-ratio]] and [[legendre-P-ratio]]. For the order 0 every polynomial of a positive degree is the zero polynomial (zero coefficients). Returns a `PolynomialR` (see [[ratio-polynomial]]) of degree `n`: operations on it are exact, and it can be evaluated exactly at a rational argument. A NaN or infinite `order` throws an `IllegalArgumentException` for a positive degree; degree 0 returns the constant 1 for any `order`. See also [[gegenbauer-C]] (double coefficients), [[eval-gegenbauer-C]] (direct evaluation).
(hermite-H degree)Creates the Hermite polynomial H_n (physicists' convention) as a polynomial object with double coefficients.
See eval-hermite-H for the definition and hermite-H-ratio for the exact integer coefficients, which are converted to doubles.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a Polynomial (see polynomial) of degree n, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use eval-hermite-H for values at a high degree.
See also hermite-H-ratio, eval-hermite-H, hermite-He.
Creates the Hermite polynomial `H_n` (physicists' convention) as a polynomial object with double coefficients. See [[eval-hermite-H]] for the definition and [[hermite-H-ratio]] for the exact integer coefficients, which are converted to doubles. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `Polynomial` (see [[polynomial]]) of degree `n`, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use [[eval-hermite-H]] for values at a high degree. See also [[hermite-H-ratio]], [[eval-hermite-H]], [[hermite-He]].
(hermite-H-ratio degree)Creates the Hermite polynomial H_n (physicists' convention) with exact integer coefficients.
H_0 = 1, H_1 = 2*x and H_n = 2*x*H_(n-1) - 2*(n-1)*H_(n-2); see eval-hermite-H for the definition and the orthogonality.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a PolynomialR (see ratio-polynomial) of degree n: operations on it are exact, and it can be evaluated exactly at a rational argument. The coefficients of the powers of the wrong parity are zero, the signs alternate and the leading coefficient is 2^n.
See also hermite-H (double coefficients), eval-hermite-H (direct evaluation), hermite-He-ratio.
Creates the Hermite polynomial `H_n` (physicists' convention) with exact integer coefficients. `H_0 = 1`, `H_1 = 2*x` and `H_n = 2*x*H_(n-1) - 2*(n-1)*H_(n-2)`; see [[eval-hermite-H]] for the definition and the orthogonality. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `PolynomialR` (see [[ratio-polynomial]]) of degree `n`: operations on it are exact, and it can be evaluated exactly at a rational argument. The coefficients of the powers of the wrong parity are zero, the signs alternate and the leading coefficient is `2^n`. See also [[hermite-H]] (double coefficients), [[eval-hermite-H]] (direct evaluation), [[hermite-He-ratio]].
(hermite-He degree)Creates the Hermite polynomial He_n (probabilists' convention) as a polynomial object with double coefficients.
See eval-hermite-He for the definition and hermite-He-ratio for the exact integer coefficients, which are converted to doubles.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a Polynomial (see polynomial) of degree n, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use eval-hermite-He for values at a high degree.
See also hermite-He-ratio, eval-hermite-He, hermite-H.
Creates the Hermite polynomial `He_n` (probabilists' convention) as a polynomial object with double coefficients. See [[eval-hermite-He]] for the definition and [[hermite-He-ratio]] for the exact integer coefficients, which are converted to doubles. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `Polynomial` (see [[polynomial]]) of degree `n`, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use [[eval-hermite-He]] for values at a high degree. See also [[hermite-He-ratio]], [[eval-hermite-He]], [[hermite-H]].
(hermite-He-ratio degree)Creates the Hermite polynomial He_n (probabilists' convention) with exact integer coefficients.
He_0 = 1, He_1 = x and He_n = x*He_(n-1) - (n-1)*He_(n-2); see eval-hermite-He for the definition and the orthogonality.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a PolynomialR (see ratio-polynomial) of degree n: operations on it are exact, and it can be evaluated exactly at a rational argument. The coefficients of the powers of the wrong parity are zero, the signs alternate and the leading coefficient is 1.
See also hermite-He (double coefficients), eval-hermite-He (direct evaluation), hermite-H-ratio.
Creates the Hermite polynomial `He_n` (probabilists' convention) with exact integer coefficients. `He_0 = 1`, `He_1 = x` and `He_n = x*He_(n-1) - (n-1)*He_(n-2)`; see [[eval-hermite-He]] for the definition and the orthogonality. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `PolynomialR` (see [[ratio-polynomial]]) of degree `n`: operations on it are exact, and it can be evaluated exactly at a rational argument. The coefficients of the powers of the wrong parity are zero, the signs alternate and the leading coefficient is 1. See also [[hermite-He]] (double coefficients), [[eval-hermite-He]] (direct evaluation), [[hermite-H-ratio]].
(ince-C p m e)(ince-C p m e normalization)Creates the Ince polynomial C_p^m(x; e) as a function of the angle x.
It is the even, periodic solution of Ince's equation w'' + e*sin(2x)*w' + (a - p*e*cos(2x))*w = 0 that belongs to the m-th smallest value of a, the series sum over r of A_r * cos(k_r*x) of ince-C-coeffs. For e = 0 it is cos(m*x). The radial counterpart, with cosh instead of cos, is ince-C-radial.
Parameters:
p (non-negative integer): the order.m (integer): the degree, from 0 to p with the parity of p.e (double): the ellipticity parameter of the equation, any finite real number (negative values are allowed).normalization (keyword, default :none): the scale of the coefficients.
:none: the coefficient vector has the Euclidean norm 1.:trigonometric: the integral of C^2 over a period [0, 2*pi] divided by pi is 1; this equals :none for an odd p.:millers: Miller's normalization as used for the Ince-Gaussian modes (Bandres and Gutierrez-Vega, Ince-Gaussian modes of the paraxial wave equation and stable resonators); a positive multiple of :none. The multiple becomes very small with p (1e-65 at p = 100, 1e-300 near p = 330); beyond about p = 340 it is below the range of a double and an IllegalArgumentException is thrown.
The sign is always such that C_p^m(0) > 0.Returns a function of one double, x, that returns a double. An argument outside the ranges, a non-finite e or an unknown normalization throws an IllegalArgumentException when the function is created. The order 0 gives the constant polynomial. The coefficients come from an eigenproblem of size about p/2, solved once at creation (about 10 ms for p = 120).
See also ince-S, ince-C-coeffs, ince-C-radial.
Creates the Ince polynomial `C_p^m(x; e)` as a function of the angle `x`. It is the even, periodic solution of Ince's equation `w'' + e*sin(2x)*w' + (a - p*e*cos(2x))*w = 0` that belongs to the `m`-th smallest value of `a`, the series `sum over r of A_r * cos(k_r*x)` of [[ince-C-coeffs]]. For `e = 0` it is `cos(m*x)`. The radial counterpart, with `cosh` instead of `cos`, is [[ince-C-radial]]. Parameters: - `p` (non-negative integer): the order. - `m` (integer): the degree, from 0 to `p` with the parity of `p`. - `e` (double): the ellipticity parameter of the equation, any finite real number (negative values are allowed). - `normalization` (keyword, default `:none`): the scale of the coefficients. - `:none`: the coefficient vector has the Euclidean norm 1. - `:trigonometric`: the integral of `C^2` over a period `[0, 2*pi]` divided by `pi` is 1; this equals `:none` for an odd `p`. - `:millers`: Miller's normalization as used for the Ince-Gaussian modes (Bandres and Gutierrez-Vega, Ince-Gaussian modes of the paraxial wave equation and stable resonators); a positive multiple of `:none`. The multiple becomes very small with `p` (1e-65 at `p = 100`, 1e-300 near `p = 330`); beyond about `p = 340` it is below the range of a double and an `IllegalArgumentException` is thrown. The sign is always such that `C_p^m(0) > 0`. Returns a function of one double, `x`, that returns a double. An argument outside the ranges, a non-finite `e` or an unknown normalization throws an `IllegalArgumentException` when the function is created. The order 0 gives the constant polynomial. The coefficients come from an eigenproblem of size about `p/2`, solved once at creation (about 10 ms for `p = 120`). See also [[ince-S]], [[ince-C-coeffs]], [[ince-C-radial]].
(ince-C-coeffs p m e normalization)Returns the coefficients of the Ince polynomial C_p^m as a series of cosines.
The Ince polynomial C_p^m(x; e) is the even, periodic solution of Ince's equation w'' + e*sin(2x)*w' + (a - p*e*cos(2x))*w = 0 that belongs to the m-th smallest value of a (counting from m = 0 or m = 1 as the parity allows). It is the finite series sum over r of A_r * cos(k_r*x) with k_r = 2r for an even p (r from 0 to p/2) and k_r = 2r + 1 for an odd p (r from 0 to (p-1)/2); this function returns the vector A, the number of entries being floor(p/2) + 1. For e = 0 the polynomial is cos(m*x).
Parameters:
p (non-negative integer): the order.m (integer): the degree, from 0 to p with the parity of p.e (double): the ellipticity parameter of the equation, any finite real number (negative values are allowed).normalization (keyword): :none, :trigonometric or :millers; see ince-C.Returns a double array. The sign is chosen so that C_p^m(0) > 0; it is decided by the sum of the coefficients, so it is reliable only where |C_p^m(0)| is above rounding (about 1e-15) and can be the opposite one where that value is almost zero (large |e|). An argument outside these ranges, a non-finite e or an unknown normalization throws an IllegalArgumentException. The coefficients come from the eigenproblem of a matrix of size floor(p/2) + 1 (solved in a symmetric form), so the time grows like p^3 and the memory like p^2 (about 10 ms for p = 120); they agree with a 60 digit reference to 4e-15 for p up to 30 with e up to 2500 in modulus, and for p up to 9 with e up to 1e8. For |e| below 1e-100 the coefficients are those of e = 1e-100 (they differ by less than 1e-100).
See also ince-C, ince-S-coeffs, ince-C-radial.
Returns the coefficients of the Ince polynomial `C_p^m` as a series of cosines. The Ince polynomial `C_p^m(x; e)` is the even, periodic solution of Ince's equation `w'' + e*sin(2x)*w' + (a - p*e*cos(2x))*w = 0` that belongs to the `m`-th smallest value of `a` (counting from `m = 0` or `m = 1` as the parity allows). It is the finite series `sum over r of A_r * cos(k_r*x)` with `k_r = 2r` for an even `p` (`r` from 0 to `p/2`) and `k_r = 2r + 1` for an odd `p` (`r` from 0 to `(p-1)/2`); this function returns the vector `A`, the number of entries being `floor(p/2) + 1`. For `e = 0` the polynomial is `cos(m*x)`. Parameters: - `p` (non-negative integer): the order. - `m` (integer): the degree, from 0 to `p` with the parity of `p`. - `e` (double): the ellipticity parameter of the equation, any finite real number (negative values are allowed). - `normalization` (keyword): `:none`, `:trigonometric` or `:millers`; see [[ince-C]]. Returns a `double` array. The sign is chosen so that `C_p^m(0) > 0`; it is decided by the sum of the coefficients, so it is reliable only where `|C_p^m(0)|` is above rounding (about 1e-15) and can be the opposite one where that value is almost zero (large `|e|`). An argument outside these ranges, a non-finite `e` or an unknown normalization throws an `IllegalArgumentException`. The coefficients come from the eigenproblem of a matrix of size `floor(p/2) + 1` (solved in a symmetric form), so the time grows like `p^3` and the memory like `p^2` (about 10 ms for `p = 120`); they agree with a 60 digit reference to 4e-15 for `p` up to 30 with `e` up to 2500 in modulus, and for `p` up to 9 with `e` up to 1e8. For `|e|` below 1e-100 the coefficients are those of `e = 1e-100` (they differ by less than 1e-100). See also [[ince-C]], [[ince-S-coeffs]], [[ince-C-radial]].
(ince-C-radial p m e)(ince-C-radial p m e normalization)Creates the radial Ince function C_p^m(xi; e) as a function of the radial coordinate xi.
It is the series sum over r of A_r * cosh(k_r*xi) with the coefficients A of ince-C-coeffs: the solution of the radial equation R'' - e*sinh(2*xi)*R' - (a - p*e*cosh(2*xi))*R = 0 with the same value of a as the angular function ince-C (the equation for x = i*xi). For e = 0 it is cosh(m*xi). The parameters, the normalization and the errors are those of ince-C; the normalization is that of the coefficients, not of the integral of the radial function over a period (there is none).
Returns a function of one double, xi, that returns a double. It grows like exp(p*|xi|): where that is beyond the range of a double (p*|xi| above about 709) the result is ##Inf or ##-Inf with the sign of the exact value, also for an infinite xi; a NaN xi gives NaN.
See also ince-S-radial, ince-C, ince-C-coeffs.
Creates the radial Ince function `C_p^m(xi; e)` as a function of the radial coordinate `xi`. It is the series `sum over r of A_r * cosh(k_r*xi)` with the coefficients `A` of [[ince-C-coeffs]]: the solution of the radial equation `R'' - e*sinh(2*xi)*R' - (a - p*e*cosh(2*xi))*R = 0` with the same value of `a` as the angular function [[ince-C]] (the equation for `x = i*xi`). For `e = 0` it is `cosh(m*xi)`. The parameters, the normalization and the errors are those of [[ince-C]]; the normalization is that of the coefficients, not of the integral of the radial function over a period (there is none). Returns a function of one double, `xi`, that returns a double. It grows like `exp(p*|xi|)`: where that is beyond the range of a double (`p*|xi|` above about 709) the result is `##Inf` or `##-Inf` with the sign of the exact value, also for an infinite `xi`; a NaN `xi` gives NaN. See also [[ince-S-radial]], [[ince-C]], [[ince-C-coeffs]].
(ince-S p m e)(ince-S p m e normalization)Creates the Ince polynomial S_p^m(x; e) as a function of the angle x.
It is the odd, periodic solution of Ince's equation w'' + e*sin(2x)*w' + (a - p*e*cos(2x))*w = 0 that belongs to the m-th smallest value of a among the odd solutions of the parity of p, the series sum over r of B_r * sin(k_r*x) of ince-S-coeffs. For e = 0 it is sin(m*x). The radial counterpart, with sinh instead of sin, is ince-S-radial.
Parameters:
p (positive integer): the order. There is no S polynomial of order 0.m (integer): the degree, from 1 to p with the parity of p.e (double): the ellipticity parameter of the equation, any finite real number (negative values are allowed).normalization (keyword, default :none): the scale of the coefficients.
:none: the coefficient vector has the Euclidean norm 1; this equals :trigonometric for every S.:trigonometric: the integral of S^2 over a period [0, 2*pi] divided by pi is 1.:millers: Miller's normalization as used for the Ince-Gaussian modes (Bandres and Gutierrez-Vega, Ince-Gaussian modes of the paraxial wave equation and stable resonators); a positive multiple of :none. The multiple becomes very small with p (1e-65 at p = 100, 1e-300 near p = 330); beyond about p = 340 it is below the range of a double and an IllegalArgumentException is thrown.
The sign is always such that the slope S_p^m'(0) is positive.Returns a function of one double, x, that returns a double. An argument outside the ranges, a non-finite e or an unknown normalization throws an IllegalArgumentException when the function is created. The cost is that of ince-C.
See also ince-C, ince-S-coeffs, ince-S-radial.
Creates the Ince polynomial `S_p^m(x; e)` as a function of the angle `x`. It is the odd, periodic solution of Ince's equation `w'' + e*sin(2x)*w' + (a - p*e*cos(2x))*w = 0` that belongs to the `m`-th smallest value of `a` among the odd solutions of the parity of `p`, the series `sum over r of B_r * sin(k_r*x)` of [[ince-S-coeffs]]. For `e = 0` it is `sin(m*x)`. The radial counterpart, with `sinh` instead of `sin`, is [[ince-S-radial]]. Parameters: - `p` (positive integer): the order. There is no `S` polynomial of order 0. - `m` (integer): the degree, from 1 to `p` with the parity of `p`. - `e` (double): the ellipticity parameter of the equation, any finite real number (negative values are allowed). - `normalization` (keyword, default `:none`): the scale of the coefficients. - `:none`: the coefficient vector has the Euclidean norm 1; this equals `:trigonometric` for every `S`. - `:trigonometric`: the integral of `S^2` over a period `[0, 2*pi]` divided by `pi` is 1. - `:millers`: Miller's normalization as used for the Ince-Gaussian modes (Bandres and Gutierrez-Vega, Ince-Gaussian modes of the paraxial wave equation and stable resonators); a positive multiple of `:none`. The multiple becomes very small with `p` (1e-65 at `p = 100`, 1e-300 near `p = 330`); beyond about `p = 340` it is below the range of a double and an `IllegalArgumentException` is thrown. The sign is always such that the slope `S_p^m'(0)` is positive. Returns a function of one double, `x`, that returns a double. An argument outside the ranges, a non-finite `e` or an unknown normalization throws an `IllegalArgumentException` when the function is created. The cost is that of [[ince-C]]. See also [[ince-C]], [[ince-S-coeffs]], [[ince-S-radial]].
(ince-S-coeffs p m e normalization)Returns the coefficients of the Ince polynomial S_p^m as a series of sines.
The Ince polynomial S_p^m(x; e) is the odd, periodic solution of Ince's equation w'' + e*sin(2x)*w' + (a - p*e*cos(2x))*w = 0 that belongs to the m-th smallest value of a among the odd solutions of the parity of p. It is the finite series sum over r of B_r * sin(k_r*x) with k_r = 2(r+1) for an even p (r from 0 to p/2 - 1) and k_r = 2r + 1 for an odd p (r from 0 to (p-1)/2); this function returns the vector B, with floor((p+1)/2) entries for an odd p and p/2 for an even one. For e = 0 the polynomial is sin(m*x).
Parameters:
p (non-negative integer): the order. There is no S polynomial of order 0.m (integer): the degree, from 1 to p with the parity of p.e (double): the ellipticity parameter of the equation, any finite real number (negative values are allowed).normalization (keyword): :none, :trigonometric or :millers; see ince-S.Returns a double array. The sign is chosen so that S_p^m'(0) > 0; it is decided by a sum of the coefficients, so it is reliable only where |S_p^m'(0)| is above rounding (about 1e-15). An argument outside these ranges, a non-finite e or an unknown normalization throws an IllegalArgumentException. The cost and the accuracy are those of ince-C-coeffs.
See also ince-S, ince-C-coeffs, ince-S-radial.
Returns the coefficients of the Ince polynomial `S_p^m` as a series of sines. The Ince polynomial `S_p^m(x; e)` is the odd, periodic solution of Ince's equation `w'' + e*sin(2x)*w' + (a - p*e*cos(2x))*w = 0` that belongs to the `m`-th smallest value of `a` among the odd solutions of the parity of `p`. It is the finite series `sum over r of B_r * sin(k_r*x)` with `k_r = 2(r+1)` for an even `p` (`r` from 0 to `p/2 - 1`) and `k_r = 2r + 1` for an odd `p` (`r` from 0 to `(p-1)/2`); this function returns the vector `B`, with `floor((p+1)/2)` entries for an odd `p` and `p/2` for an even one. For `e = 0` the polynomial is `sin(m*x)`. Parameters: - `p` (non-negative integer): the order. There is no `S` polynomial of order 0. - `m` (integer): the degree, from 1 to `p` with the parity of `p`. - `e` (double): the ellipticity parameter of the equation, any finite real number (negative values are allowed). - `normalization` (keyword): `:none`, `:trigonometric` or `:millers`; see [[ince-S]]. Returns a `double` array. The sign is chosen so that `S_p^m'(0) > 0`; it is decided by a sum of the coefficients, so it is reliable only where `|S_p^m'(0)|` is above rounding (about 1e-15). An argument outside these ranges, a non-finite `e` or an unknown normalization throws an `IllegalArgumentException`. The cost and the accuracy are those of [[ince-C-coeffs]]. See also [[ince-S]], [[ince-C-coeffs]], [[ince-S-radial]].
(ince-S-radial p m e)(ince-S-radial p m e normalization)Creates the radial Ince function S_p^m(xi; e) as a function of the radial coordinate xi.
It is the series sum over r of B_r * sinh(k_r*xi) with the coefficients B of ince-S-coeffs: the solution of the radial equation R'' - e*sinh(2*xi)*R' - (a - p*e*cosh(2*xi))*R = 0 with the same value of a as the angular function ince-S. For e = 0 it is sinh(m*xi). The parameters, the normalization and the errors are those of ince-S.
Returns a function of one double, xi, that returns a double. It grows like exp(p*|xi|): where that is beyond the range of a double (p*|xi| above about 709) the result is ##Inf or ##-Inf with the sign of the exact value, also for an infinite xi; a NaN xi gives NaN.
See also ince-C-radial, ince-S, ince-S-coeffs.
Creates the radial Ince function `S_p^m(xi; e)` as a function of the radial coordinate `xi`. It is the series `sum over r of B_r * sinh(k_r*xi)` with the coefficients `B` of [[ince-S-coeffs]]: the solution of the radial equation `R'' - e*sinh(2*xi)*R' - (a - p*e*cosh(2*xi))*R = 0` with the same value of `a` as the angular function [[ince-S]]. For `e = 0` it is `sinh(m*xi)`. The parameters, the normalization and the errors are those of [[ince-S]]. Returns a function of one double, `xi`, that returns a double. It grows like `exp(p*|xi|)`: where that is beyond the range of a double (`p*|xi|` above about 709) the result is `##Inf` or `##-Inf` with the sign of the exact value, also for an infinite `xi`; a NaN `xi` gives NaN. See also [[ince-C-radial]], [[ince-S]], [[ince-S-coeffs]].
(jacobi-P degree alpha beta)Creates the Jacobi polynomial P_n^(a,b) as a polynomial object with double coefficients.
See eval-jacobi-P for the definition and jacobi-P-ratio for the exact rational coefficients, which are converted to doubles.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).alpha, beta (doubles): the parameters a and b, any real numbers. A NaN or infinite parameter throws an IllegalArgumentException for a positive degree; see jacobi-P-ratio for the conversion.Returns a Polynomial (see polynomial) of degree n, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use eval-jacobi-P for values at a high degree.
See also jacobi-P-ratio, eval-jacobi-P, gegenbauer-C, legendre-P.
Creates the Jacobi polynomial `P_n^(a,b)` as a polynomial object with double coefficients. See [[eval-jacobi-P]] for the definition and [[jacobi-P-ratio]] for the exact rational coefficients, which are converted to doubles. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `alpha`, `beta` (doubles): the parameters `a` and `b`, any real numbers. A NaN or infinite parameter throws an `IllegalArgumentException` for a positive degree; see [[jacobi-P-ratio]] for the conversion. Returns a `Polynomial` (see [[polynomial]]) of degree `n`, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use [[eval-jacobi-P]] for values at a high degree. See also [[jacobi-P-ratio]], [[eval-jacobi-P]], [[gegenbauer-C]], [[legendre-P]].
(jacobi-P-ratio degree alpha beta)Creates the Jacobi polynomial P_n^(a,b) with exact rational coefficients.
See eval-jacobi-P for the definition, the orthogonality and the parameters.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).alpha, beta (doubles): the parameters a and b, any real numbers. They are converted with rationalize, so a double becomes the exact decimal number it prints as (0.1 gives 1/10) and the coefficients are exact for those numbers.Returns a PolynomialR (see ratio-polynomial) of degree n: operations on it are exact, and it can be evaluated exactly at a rational argument. When a + b is a negative integer from -n to -2 (or an even one down to 2 - 2*n), where the three term recurrence is undefined, the explicit sum is used; the time then grows with the cube of the degree. A NaN or infinite parameter throws an IllegalArgumentException for a positive degree; degree 0 returns the constant 1 for any parameters.
See also jacobi-P (double coefficients), eval-jacobi-P (direct evaluation), gegenbauer-C-ratio.
Creates the Jacobi polynomial `P_n^(a,b)` with exact rational coefficients. See [[eval-jacobi-P]] for the definition, the orthogonality and the parameters. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `alpha`, `beta` (doubles): the parameters `a` and `b`, any real numbers. They are converted with `rationalize`, so a double becomes the exact decimal number it prints as (`0.1` gives `1/10`) and the coefficients are exact for those numbers. Returns a `PolynomialR` (see [[ratio-polynomial]]) of degree `n`: operations on it are exact, and it can be evaluated exactly at a rational argument. When `a + b` is a negative integer from `-n` to `-2` (or an even one down to `2 - 2*n`), where the three term recurrence is undefined, the explicit sum is used; the time then grows with the cube of the degree. A NaN or infinite parameter throws an `IllegalArgumentException` for a positive degree; degree 0 returns the constant 1 for any parameters. See also [[jacobi-P]] (double coefficients), [[eval-jacobi-P]] (direct evaluation), [[gegenbauer-C-ratio]].
(laguerre-L degree)(laguerre-L degree order)Creates the generalized Laguerre polynomial L_n^(a) as a polynomial object with double coefficients.
See eval-laguerre-L for the definition and laguerre-L-ratio for the exact rational coefficients, which are converted to doubles.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).order (double): the order a, any real number, default 0.0. A NaN or infinite order throws an IllegalArgumentException for a positive degree; see laguerre-L-ratio for the conversion of the order.Returns a Polynomial (see polynomial) of degree n, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use eval-laguerre-L for values at a high degree.
See also laguerre-L-ratio, eval-laguerre-L, hermite-H.
Creates the generalized Laguerre polynomial `L_n^(a)` as a polynomial object with double coefficients. See [[eval-laguerre-L]] for the definition and [[laguerre-L-ratio]] for the exact rational coefficients, which are converted to doubles. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `order` (double): the order `a`, any real number, default 0.0. A NaN or infinite order throws an `IllegalArgumentException` for a positive degree; see [[laguerre-L-ratio]] for the conversion of the order. Returns a `Polynomial` (see [[polynomial]]) of degree `n`, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use [[eval-laguerre-L]] for values at a high degree. See also [[laguerre-L-ratio]], [[eval-laguerre-L]], [[hermite-H]].
(laguerre-L-ratio degree order)Creates the generalized Laguerre polynomial L_n^(a) with exact rational coefficients.
L_0 = 1, L_1 = 1 + a - x and n*L_n = (2n-1+a-x)*L_(n-1) - (n-1+a)*L_(n-2); see eval-laguerre-L for the definition and the orthogonality.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).order (double): the order a, any real number. It is converted with rationalize, so a double becomes the exact decimal number it prints as (0.3 gives 3/10) and the coefficients are exact for that number.Returns a PolynomialR (see ratio-polynomial) of degree n: operations on it are exact, and it can be evaluated exactly at a rational argument. The coefficients alternate in sign for an order above -1. A NaN or infinite order throws an IllegalArgumentException for a positive degree; degree 0 returns the constant 1 for any order.
See also laguerre-L (double coefficients), eval-laguerre-L (direct evaluation), hermite-H-ratio.
Creates the generalized Laguerre polynomial `L_n^(a)` with exact rational coefficients. `L_0 = 1`, `L_1 = 1 + a - x` and `n*L_n = (2n-1+a-x)*L_(n-1) - (n-1+a)*L_(n-2)`; see [[eval-laguerre-L]] for the definition and the orthogonality. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `order` (double): the order `a`, any real number. It is converted with `rationalize`, so a double becomes the exact decimal number it prints as (`0.3` gives `3/10`) and the coefficients are exact for that number. Returns a `PolynomialR` (see [[ratio-polynomial]]) of degree `n`: operations on it are exact, and it can be evaluated exactly at a rational argument. The coefficients alternate in sign for an order above -1. A NaN or infinite `order` throws an `IllegalArgumentException` for a positive degree; degree 0 returns the constant 1 for any `order`. See also [[laguerre-L]] (double coefficients), [[eval-laguerre-L]] (direct evaluation), [[hermite-H-ratio]].
(legendre-P degree)Creates the Legendre polynomial P_n as a polynomial object with double coefficients.
See eval-legendre-P for the definition and legendre-P-ratio for the exact rational coefficients, which are converted to doubles.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a Polynomial (see polynomial) of degree n, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use eval-legendre-P for values at a high degree.
See also legendre-P-ratio, eval-legendre-P.
Creates the Legendre polynomial `P_n` as a polynomial object with double coefficients. See [[eval-legendre-P]] for the definition and [[legendre-P-ratio]] for the exact rational coefficients, which are converted to doubles. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `Polynomial` (see [[polynomial]]) of degree `n`, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use [[eval-legendre-P]] for values at a high degree. See also [[legendre-P-ratio]], [[eval-legendre-P]].
(legendre-P-ratio degree)Creates the Legendre polynomial P_n with exact rational coefficients.
P_0 = 1, P_1 = x and n*P_n = (2n-1)*x*P_(n-1) - (n-1)*P_(n-2); see eval-legendre-P for the definition and the orthogonality.
Parameters: degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).
Returns a PolynomialR (see ratio-polynomial) of degree n: operations on it are exact, and it can be evaluated exactly at a rational argument. The coefficients are fractions with a power of two as the denominator, vanish for the powers of the wrong parity and alternate in sign.
See also legendre-P (double coefficients), eval-legendre-P (direct evaluation), gegenbauer-C-ratio.
Creates the Legendre polynomial `P_n` with exact rational coefficients. `P_0 = 1`, `P_1 = x` and `n*P_n = (2n-1)*x*P_(n-1) - (n-1)*P_(n-2)`; see [[eval-legendre-P]] for the definition and the orthogonality. Parameters: `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). Returns a `PolynomialR` (see [[ratio-polynomial]]) of degree `n`: operations on it are exact, and it can be evaluated exactly at a rational argument. The coefficients are fractions with a power of two as the denominator, vanish for the powers of the wrong parity and alternate in sign. See also [[legendre-P]] (double coefficients), [[eval-legendre-P]] (direct evaluation), [[gegenbauer-C-ratio]].
(makepoly coeffs)Creates a function evaluating the real polynomial with the given coefficients.
The polynomial is c0 + c1*x + c2*x^2 + ....
Parameters:
coeffs (sequence of numbers): the coefficients c0, c1, ... in ascending order of power. Any numeric type is accepted.Returns a function of one number x that returns a double equal to (apply evalpoly x coeffs). An empty or nil sequence gives a function that always returns 0.0; a single coefficient gives a function that always returns that coefficient as a double. The coefficients are fixed when the function is created.
See also evalpoly, mevalpoly, makepoly-complex, makepoly-scalar-complex, polynomial.
Creates a function evaluating the real polynomial with the given coefficients. The polynomial is `c0 + c1*x + c2*x^2 + ...`. Parameters: - `coeffs` (sequence of numbers): the coefficients `c0`, `c1`, ... in ascending order of power. Any numeric type is accepted. Returns a function of one number `x` that returns a double equal to `(apply evalpoly x coeffs)`. An empty or `nil` sequence gives a function that always returns `0.0`; a single coefficient gives a function that always returns that coefficient as a double. The coefficients are fixed when the function is created. See also [[evalpoly]], [[mevalpoly]], [[makepoly-complex]], [[makepoly-scalar-complex]], [[polynomial]].
(makepoly-complex coeffs)Creates a function evaluating the complex polynomial with the given coefficients.
The polynomial is c0 + c1*z + c2*z^2 + ....
Parameters:
coeffs (sequence of complex numbers): the coefficients c0, c1, ... in ascending order of power. Each can be a Vec2 or a real number.Returns a function of one complex number z (a real number is accepted) that returns a Vec2 equal to (apply evalpoly-complex z coeffs). An empty or nil sequence gives a function that always returns fastmath.complex/ZERO; a single coefficient gives a function that always returns that coefficient as a Vec2. The coefficients are fixed when the function is created.
See also evalpoly-complex, mevalpoly-complex, makepoly-scalar-complex, makepoly.
Creates a function evaluating the complex polynomial with the given coefficients. The polynomial is `c0 + c1*z + c2*z^2 + ...`. Parameters: - `coeffs` (sequence of complex numbers): the coefficients `c0`, `c1`, ... in ascending order of power. Each can be a `Vec2` or a real number. Returns a function of one complex number `z` (a real number is accepted) that returns a `Vec2` equal to `(apply evalpoly-complex z coeffs)`. An empty or `nil` sequence gives a function that always returns `fastmath.complex/ZERO`; a single coefficient gives a function that always returns that coefficient as a `Vec2`. The coefficients are fixed when the function is created. See also [[evalpoly-complex]], [[mevalpoly-complex]], [[makepoly-scalar-complex]], [[makepoly]].
(makepoly-scalar-complex coeffs)Creates a function evaluating the complex polynomial with the given real coefficients.
The polynomial is c0 + c1*z + c2*z^2 + ....
Parameters:
coeffs (sequence of numbers): the real coefficients c0, c1, ... in ascending order of power. Any numeric type is accepted.Returns a function of one complex number z (a real number is accepted) that returns a Vec2 equal to (apply evalpoly-scalar-complex z coeffs). An empty or nil sequence gives a function that always returns fastmath.complex/ZERO; a single coefficient gives a function that always returns that coefficient with a zero imaginary part. The coefficients are fixed when the function is created.
See also evalpoly-scalar-complex, mevalpoly-scalar-complex, makepoly-complex, makepoly.
Creates a function evaluating the complex polynomial with the given real coefficients. The polynomial is `c0 + c1*z + c2*z^2 + ...`. Parameters: - `coeffs` (sequence of numbers): the real coefficients `c0`, `c1`, ... in ascending order of power. Any numeric type is accepted. Returns a function of one complex number `z` (a real number is accepted) that returns a `Vec2` equal to `(apply evalpoly-scalar-complex z coeffs)`. An empty or `nil` sequence gives a function that always returns `fastmath.complex/ZERO`; a single coefficient gives a function that always returns that coefficient with a zero imaginary part. The coefficients are fixed when the function is created. See also [[evalpoly-scalar-complex]], [[mevalpoly-scalar-complex]], [[makepoly-complex]], [[makepoly]].
(meixner-pollaczek-P degree lambda phi)Creates the Meixner-Pollaczek polynomial P_n^(l)(x; phi) as a polynomial object with double coefficients.
See eval-meixner-pollaczek-P for the definition and meixner-pollaczek-P-ratio for the exact rational coefficients, which are converted to doubles.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).lambda (double): the parameter l, any real number.phi (double): the angle, any real number. A NaN or infinite lambda or phi throws an IllegalArgumentException for a positive degree.Returns a Polynomial (see polynomial) of degree n, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use eval-meixner-pollaczek-P for values at a high degree.
See also meixner-pollaczek-P-ratio, eval-meixner-pollaczek-P.
Creates the Meixner-Pollaczek polynomial `P_n^(l)(x; phi)` as a polynomial object with double coefficients. See [[eval-meixner-pollaczek-P]] for the definition and [[meixner-pollaczek-P-ratio]] for the exact rational coefficients, which are converted to doubles. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `lambda` (double): the parameter `l`, any real number. - `phi` (double): the angle, any real number. A NaN or infinite `lambda` or `phi` throws an `IllegalArgumentException` for a positive degree. Returns a `Polynomial` (see [[polynomial]]) of degree `n`, which can be differentiated, multiplied and added. Evaluating the monomial form loses accuracy as the degree grows (the coefficients are large and alternate in sign), so use [[eval-meixner-pollaczek-P]] for values at a high degree. See also [[meixner-pollaczek-P-ratio]], [[eval-meixner-pollaczek-P]].
(meixner-pollaczek-P-ratio degree lambda phi)Creates the Meixner-Pollaczek polynomial P_n^(l)(x; phi) with exact rational coefficients.
P_0 = 1, P_1 = 2*(l*cos(phi) + x*sin(phi)) and n*P_n = 2*(x*sin(phi) + (n-1+l)*cos(phi))*P_(n-1) - (n-2+2*l)*P_(n-2); see eval-meixner-pollaczek-P for the definition and the ranges of the parameters.
Parameters:
degree (non-negative integer): the degree n. A degree that is negative or not below Integer/MAX_VALUE (2147483647) throws an IllegalArgumentException; a non-integer is truncated toward zero (so ##NaN and -0.5 give degree 0).lambda (double): the parameter l, any real number.phi (double): the angle, any real number.Returns a PolynomialR (see ratio-polynomial) of degree n: operations on it are exact, and it can be evaluated exactly at a rational argument. lambda, cos(phi) and sin(phi) are converted with rationalize, so a double becomes the exact decimal number it prints as; the coefficients are exact for those three numbers, which are not the real cosine and sine of phi (they differ by a rounding error). A NaN or infinite lambda or phi throws an IllegalArgumentException for a positive degree; degree 0 returns the constant 1.
See also meixner-pollaczek-P (double coefficients), eval-meixner-pollaczek-P (direct evaluation).
Creates the Meixner-Pollaczek polynomial `P_n^(l)(x; phi)` with exact rational coefficients. `P_0 = 1`, `P_1 = 2*(l*cos(phi) + x*sin(phi))` and `n*P_n = 2*(x*sin(phi) + (n-1+l)*cos(phi))*P_(n-1) - (n-2+2*l)*P_(n-2)`; see [[eval-meixner-pollaczek-P]] for the definition and the ranges of the parameters. Parameters: - `degree` (non-negative integer): the degree `n`. A degree that is negative or not below `Integer/MAX_VALUE` (2147483647) throws an `IllegalArgumentException`; a non-integer is truncated toward zero (so `##NaN` and `-0.5` give degree 0). - `lambda` (double): the parameter `l`, any real number. - `phi` (double): the angle, any real number. Returns a `PolynomialR` (see [[ratio-polynomial]]) of degree `n`: operations on it are exact, and it can be evaluated exactly at a rational argument. `lambda`, `cos(phi)` and `sin(phi)` are converted with `rationalize`, so a double becomes the exact decimal number it prints as; the coefficients are exact for those three numbers, which are not the real cosine and sine of `phi` (they differ by a rounding error). A NaN or infinite `lambda` or `phi` throws an `IllegalArgumentException` for a positive degree; degree 0 returns the constant 1. See also [[meixner-pollaczek-P]] (double coefficients), [[eval-meixner-pollaczek-P]] (direct evaluation).
(mevalpoly x & coeffs)Evaluates a real polynomial at x for coefficients given explicitly in the code; the macro version of evalpoly.
The polynomial is c0 + c1*x + c2*x^2 + ..., with coefficients in ascending order of power.
Parameters:
x (number): the point of evaluation. It can be evaluated several times, so pass a symbol or a literal rather than an expensive expression.coeffs (numbers): the coefficients c0, c1, ... as separate arguments (literals or symbols), not as a collection. Any numeric type is accepted and converted to a double. Expressions other than literals and symbols are evaluated in no particular order.Returns a double. Without coefficients the result is 0.0; with a single coefficient it is that coefficient as a double, whatever x is. A result that cancels to exactly zero is +0.0, but negative zero coefficients can give -0.0 (the sum of negative zeros is a negative zero). For an infinite or NaN x the result follows floating point arithmetic, so ##NaN gives ##NaN.
The result is identical, bit for bit, to the one from evalpoly and makepoly for the same coefficients.
See also evalpoly, makepoly, mevalpoly-complex, mevalpoly-scalar-complex.
Evaluates a real polynomial at `x` for coefficients given explicitly in the code; the macro version of [[evalpoly]]. The polynomial is `c0 + c1*x + c2*x^2 + ...`, with coefficients in ascending order of power. Parameters: - `x` (number): the point of evaluation. It can be evaluated several times, so pass a symbol or a literal rather than an expensive expression. - `coeffs` (numbers): the coefficients `c0`, `c1`, ... as separate arguments (literals or symbols), not as a collection. Any numeric type is accepted and converted to a double. Expressions other than literals and symbols are evaluated in no particular order. Returns a double. Without coefficients the result is `0.0`; with a single coefficient it is that coefficient as a double, whatever `x` is. A result that cancels to exactly zero is `+0.0`, but negative zero coefficients can give `-0.0` (the sum of negative zeros is a negative zero). For an infinite or NaN `x` the result follows floating point arithmetic, so `##NaN` gives `##NaN`. The result is identical, bit for bit, to the one from [[evalpoly]] and [[makepoly]] for the same coefficients. See also [[evalpoly]], [[makepoly]], [[mevalpoly-complex]], [[mevalpoly-scalar-complex]].
(mevalpoly-complex z & coeffs)Evaluates a complex polynomial at z for coefficients given explicitly in the code; the macro version of evalpoly-complex.
The polynomial is c0 + c1*z + c2*z^2 + ..., with coefficients in ascending order of power.
Parameters:
z (Vec2): the point of evaluation. It can be evaluated several times, so pass a symbol or a literal rather than an expensive expression.coeffs (Vec2s): the complex coefficients c0, c1, ... as separate arguments, not as a collection.The arguments must already be complex numbers (Vec2, for example from fastmath.complex/complex); real numbers are not converted and fail at runtime with a ClassCastException. Use evalpoly-complex when they may be real numbers.
Returns a Vec2. Without coefficients the result is fastmath.complex/ZERO; with a single coefficient it is that coefficient.
See also evalpoly-complex, makepoly-complex, mevalpoly-scalar-complex, mevalpoly.
Evaluates a complex polynomial at `z` for coefficients given explicitly in the code; the macro version of [[evalpoly-complex]]. The polynomial is `c0 + c1*z + c2*z^2 + ...`, with coefficients in ascending order of power. Parameters: - `z` (`Vec2`): the point of evaluation. It can be evaluated several times, so pass a symbol or a literal rather than an expensive expression. - `coeffs` (`Vec2`s): the complex coefficients `c0`, `c1`, ... as separate arguments, not as a collection. The arguments must already be complex numbers (`Vec2`, for example from `fastmath.complex/complex`); real numbers are not converted and fail at runtime with a `ClassCastException`. Use [[evalpoly-complex]] when they may be real numbers. Returns a `Vec2`. Without coefficients the result is `fastmath.complex/ZERO`; with a single coefficient it is that coefficient. See also [[evalpoly-complex]], [[makepoly-complex]], [[mevalpoly-scalar-complex]], [[mevalpoly]].
(mevalpoly-scalar-complex z & coeffs)Evaluates a complex polynomial with real coefficients at z for coefficients given explicitly in the code; the macro version of evalpoly-scalar-complex.
The polynomial is c0 + c1*z + c2*z^2 + ..., with coefficients in ascending order of power.
Parameters:
z (Vec2): the point of evaluation. It can be evaluated several times, so pass a symbol or a literal rather than an expensive expression.coeffs (numbers): the real coefficients c0, c1, ... as separate arguments (literals or symbols), not as a collection. Any numeric type is accepted and converted to a double.The point z must already be a complex number (Vec2); a real number is not converted and fails at runtime with a ClassCastException. Use evalpoly-scalar-complex when it may be a real number.
Returns a Vec2. Without coefficients the result is fastmath.complex/ZERO; with a single coefficient it is that coefficient with a zero imaginary part. Unlike evalpoly-scalar-complex it works with plain complex arithmetic only, so huge values of z are handled the same way as in mevalpoly-complex.
See also evalpoly-scalar-complex, makepoly-scalar-complex, mevalpoly-complex, mevalpoly.
Evaluates a complex polynomial with real coefficients at `z` for coefficients given explicitly in the code; the macro version of [[evalpoly-scalar-complex]]. The polynomial is `c0 + c1*z + c2*z^2 + ...`, with coefficients in ascending order of power. Parameters: - `z` (`Vec2`): the point of evaluation. It can be evaluated several times, so pass a symbol or a literal rather than an expensive expression. - `coeffs` (numbers): the real coefficients `c0`, `c1`, ... as separate arguments (literals or symbols), not as a collection. Any numeric type is accepted and converted to a double. The point `z` must already be a complex number (`Vec2`); a real number is not converted and fails at runtime with a `ClassCastException`. Use [[evalpoly-scalar-complex]] when it may be a real number. Returns a `Vec2`. Without coefficients the result is `fastmath.complex/ZERO`; with a single coefficient it is that coefficient with a zero imaginary part. Unlike [[evalpoly-scalar-complex]] it works with plain complex arithmetic only, so huge values of `z` are handled the same way as in [[mevalpoly-complex]]. See also [[evalpoly-scalar-complex]], [[makepoly-scalar-complex]], [[mevalpoly-complex]], [[mevalpoly]].
(mult poly)(mult poly1 poly2)Multiplies polynomials.
Parameters: poly, poly1, poly2 (polynomial objects): from polynomial or from ratio-polynomial. Both arguments of the two-argument form must be of the same kind; combining a Polynomial with a PolynomialR, or with anything that is not a polynomial object, throws an IllegalArgumentException.
Returns the polynomial itself for one argument, otherwise the product as a new polynomial whose nominal degree is the sum of the two degrees (zero coefficients keep the degree). The product of PolynomialR objects is exact; each coefficient of a Polynomial product is a sum of products of double coefficients.
Multiplies polynomials. Parameters: `poly`, `poly1`, `poly2` (polynomial objects): from [[polynomial]] or from [[ratio-polynomial]]. Both arguments of the two-argument form must be of the same kind; combining a `Polynomial` with a `PolynomialR`, or with anything that is not a polynomial object, throws an `IllegalArgumentException`. Returns the polynomial itself for one argument, otherwise the product as a new polynomial whose nominal degree is the sum of the two degrees (zero coefficients keep the degree). The product of `PolynomialR` objects is exact; each coefficient of a `Polynomial` product is a sum of products of double coefficients. See also [[scale]], [[add]], [[sub]].
(polynomial coeffs)(polynomial xs ys)Creates a polynomial object with double coefficients, from the coefficients or from points to interpolate.
The object is a Polynomial: c0 + c1*x + c2*x^2 + ..., with coefficients stored as doubles in ascending order of power. It can be called as a function of one number, and used with add, sub, scale, mult, derivative, evaluate, coeffs and degree.
Parameters:
coeffs (sequence of numbers): the coefficients c0, c1, ... in ascending order of power. Any numeric type is accepted and converted to a double (a ratio to the nearest double). An empty or nil sequence gives the zero polynomial (degree 0, the single coefficient 0.0).xs, ys (sequences of numbers): the abscissae and ordinates of the points. The result is the interpolating polynomial of degree n-1 for n points.Returns a Polynomial. Its degree is nominal: the number of coefficients minus one, so trailing zero coefficients are kept and no operation removes them. Two polynomials are equal when their coefficient arrays are equal as doubles, compared bit by bit (so 0.0 and -0.0 differ), and they have equal hashes. A Polynomial is never equal to a PolynomialR.
Interpolation needs at least two points, xs and ys of the same length and distinct xs; otherwise an IllegalArgumentException is thrown. The coefficients are computed in double precision, so the result is ill-conditioned for many points or for points close to each other.
See also ratio-polynomial (exact rational coefficients), coeffs->polynomial, evalpoly, makepoly.
Creates a polynomial object with double coefficients, from the coefficients or from points to interpolate. The object is a `Polynomial`: `c0 + c1*x + c2*x^2 + ...`, with coefficients stored as doubles in ascending order of power. It can be called as a function of one number, and used with [[add]], [[sub]], [[scale]], [[mult]], [[derivative]], [[evaluate]], [[coeffs]] and [[degree]]. Parameters: - `coeffs` (sequence of numbers): the coefficients `c0`, `c1`, ... in ascending order of power. Any numeric type is accepted and converted to a double (a ratio to the nearest double). An empty or `nil` sequence gives the zero polynomial (degree 0, the single coefficient `0.0`). - `xs`, `ys` (sequences of numbers): the abscissae and ordinates of the points. The result is the interpolating polynomial of degree `n-1` for `n` points. Returns a `Polynomial`. Its degree is nominal: the number of coefficients minus one, so trailing zero coefficients are kept and no operation removes them. Two polynomials are equal when their coefficient arrays are equal as doubles, compared bit by bit (so `0.0` and `-0.0` differ), and they have equal hashes. A `Polynomial` is never equal to a `PolynomialR`. Interpolation needs at least two points, `xs` and `ys` of the same length and distinct `xs`; otherwise an `IllegalArgumentException` is thrown. The coefficients are computed in double precision, so the result is ill-conditioned for many points or for points close to each other. See also [[ratio-polynomial]] (exact rational coefficients), [[coeffs->polynomial]], [[evalpoly]], [[makepoly]].
(ratio-polynomial coeffs)(ratio-polynomial xs ys)Creates a polynomial object with exact rational coefficients, from the coefficients or from points to interpolate.
The object is a PolynomialR: c0 + c1*x + c2*x^2 + ..., with coefficients stored as ratios (arbitrary precision integers and fractions) in ascending order of power. add, sub, scale, mult and derivative are exact for any degree and order. It can be called as a function of one number and used with evaluate, coeffs and degree.
Parameters:
coeffs (sequence of numbers): the coefficients c0, c1, ... in ascending order of power. Each is converted with rationalize, so a double becomes the exact decimal number it prints as (0.1 gives 1/10), not its binary value. An empty or nil sequence gives the zero polynomial (degree 0, the single coefficient 0). A NaN or infinite coefficient throws an IllegalArgumentException.xs, ys (sequences of numbers): the abscissae and ordinates of the points. The interpolating polynomial is computed in double precision, as for polynomial, and then converted to ratios, so only the operations on the result are exact.Returns a PolynomialR. Its degree is nominal: the number of coefficients minus one, and no operation removes trailing zero coefficients. Two polynomials are equal when their coefficients are equal as numbers (1 and 1N are equal), and they have equal hashes. A PolynomialR is never equal to a Polynomial.
Calling the object with a finite number returns the exact ratio; with NaN or an infinity it returns a double, as polynomial does.
See also polynomial, coeffs->ratio-polynomial.
Creates a polynomial object with exact rational coefficients, from the coefficients or from points to interpolate. The object is a `PolynomialR`: `c0 + c1*x + c2*x^2 + ...`, with coefficients stored as ratios (arbitrary precision integers and fractions) in ascending order of power. [[add]], [[sub]], [[scale]], [[mult]] and [[derivative]] are exact for any degree and order. It can be called as a function of one number and used with [[evaluate]], [[coeffs]] and [[degree]]. Parameters: - `coeffs` (sequence of numbers): the coefficients `c0`, `c1`, ... in ascending order of power. Each is converted with `rationalize`, so a double becomes the exact decimal number it prints as (`0.1` gives `1/10`), not its binary value. An empty or `nil` sequence gives the zero polynomial (degree 0, the single coefficient `0`). A NaN or infinite coefficient throws an `IllegalArgumentException`. - `xs`, `ys` (sequences of numbers): the abscissae and ordinates of the points. The interpolating polynomial is computed in double precision, as for [[polynomial]], and then converted to ratios, so only the operations on the result are exact. Returns a `PolynomialR`. Its degree is nominal: the number of coefficients minus one, and no operation removes trailing zero coefficients. Two polynomials are equal when their coefficients are equal as numbers (`1` and `1N` are equal), and they have equal hashes. A `PolynomialR` is never equal to a `Polynomial`. Calling the object with a finite number returns the exact ratio; with NaN or an infinity it returns a double, as [[polynomial]] does. See also [[polynomial]], [[coeffs->ratio-polynomial]].
(scale poly v)Multiplies a polynomial by a number.
Parameters:
poly (polynomial object): from polynomial or from ratio-polynomial.v (number): the factor. For a PolynomialR it is converted with rationalize (a double becomes the exact decimal number it prints as), so a NaN or infinite v throws an IllegalArgumentException; for a Polynomial any double is accepted and NaN or infinity propagate into the coefficients.Returns a new polynomial of the same kind and the same nominal degree; scaling by zero gives zero coefficients, not a lower degree. The product with a PolynomialR is exact.
Multiplies a polynomial by a number. Parameters: - `poly` (polynomial object): from [[polynomial]] or from [[ratio-polynomial]]. - `v` (number): the factor. For a `PolynomialR` it is converted with `rationalize` (a double becomes the exact decimal number it prints as), so a NaN or infinite `v` throws an `IllegalArgumentException`; for a `Polynomial` any double is accepted and NaN or infinity propagate into the coefficients. Returns a new polynomial of the same kind and the same nominal degree; scaling by zero gives zero coefficients, not a lower degree. The product with a `PolynomialR` is exact. See also [[mult]], [[add]].
(sub poly)(sub poly1 poly2)Subtracts polynomials, or negates a polynomial.
Parameters: poly, poly1, poly2 (polynomial objects): from polynomial or from ratio-polynomial. Both arguments of the two-argument form must be of the same kind; combining a Polynomial with a PolynomialR, or with anything that is not a polynomial object, throws an IllegalArgumentException.
Returns the negated polynomial for one argument, otherwise poly1 - poly2 as a new polynomial whose nominal degree is the larger of the two degrees (cancellation of leading coefficients does not lower it, so subtracting a polynomial from itself gives zero coefficients with the same degree). The difference of PolynomialR objects is exact.
Subtracts polynomials, or negates a polynomial. Parameters: `poly`, `poly1`, `poly2` (polynomial objects): from [[polynomial]] or from [[ratio-polynomial]]. Both arguments of the two-argument form must be of the same kind; combining a `Polynomial` with a `PolynomialR`, or with anything that is not a polynomial object, throws an `IllegalArgumentException`. Returns the negated polynomial for one argument, otherwise `poly1 - poly2` as a new polynomial whose nominal degree is the larger of the two degrees (cancellation of leading coefficients does not lower it, so subtracting a polynomial from itself gives zero coefficients with the same degree). The difference of `PolynomialR` objects is exact. See also [[add]], [[mult]], [[scale]].
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |