|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2021 The Stdlib Authors. |
| 5 | +* |
| 6 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +* you may not use this file except in compliance with the License. |
| 8 | +* You may obtain a copy of the License at |
| 9 | +* |
| 10 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +* |
| 12 | +* Unless required by applicable law or agreed to in writing, software |
| 13 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +* See the License for the specific language governing permissions and |
| 16 | +* limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +// TypeScript Version: 2.0 |
| 20 | + |
| 21 | +/* tslint:disable:max-line-length */ |
| 22 | +/* tslint:disable:max-file-line-count */ |
| 23 | + |
| 24 | +import continuedFraction = require( '@stdlib/math/base/tools/continued-fraction' ); |
| 25 | +import evalpoly = require( '@stdlib/math/base/tools/evalpoly' ); |
| 26 | +import evalrational = require( '@stdlib/math/base/tools/evalrational' ); |
| 27 | +import fibpoly = require( '@stdlib/math/base/tools/fibpoly' ); |
| 28 | +import hermitepoly = require( '@stdlib/math/base/tools/hermitepoly' ); |
| 29 | +import lucaspoly = require( '@stdlib/math/base/tools/lucaspoly' ); |
| 30 | +import normhermitepoly = require( '@stdlib/math/base/tools/normhermitepoly' ); |
| 31 | +import sumSeries = require( '@stdlib/math/base/tools/sum-series' ); |
| 32 | + |
| 33 | +/** |
| 34 | +* Interface describing the `tools` namespace. |
| 35 | +*/ |
| 36 | +interface Tools { |
| 37 | + /** |
| 38 | + * Evaluates the continued fraction approximation for the supplied series generator using the modified Lentz algorithm. |
| 39 | + * |
| 40 | + * ## References |
| 41 | + * |
| 42 | + * - Lentz, William J. 1976. "Generating bessel functions in Mie scattering calculations using continued fractions." _Applied Optics_ 15 (3): 668–71. doi:[10.1364/AO.15.000668](https://doi.org/10.1364/AO.15.000668). |
| 43 | + * |
| 44 | + * @param generator - function returning terms of continued fraction expansion |
| 45 | + * @param options - function options |
| 46 | + * @param options.maxIter - maximum number of iterations (default: 1000) |
| 47 | + * @param options.tolerance - further terms are only added as long as the next term is greater than current term times the tolerance (default: 2.22e-16) |
| 48 | + * @param options.keep - whether to keep the leading b term (default: false) |
| 49 | + * @returns value of continued fraction |
| 50 | + * |
| 51 | + * @example |
| 52 | + * // Continued fraction for (e-1)^(-1): |
| 53 | + * var gen = generator(); |
| 54 | + * var out = continuedFraction( gen ); |
| 55 | + * // returns ~0.582 |
| 56 | + * |
| 57 | + * function* generator() { |
| 58 | + * var i = 0; |
| 59 | + * while ( true ) { |
| 60 | + * i++; |
| 61 | + * yield [ i, i ]; |
| 62 | + * } |
| 63 | + * } |
| 64 | + */ |
| 65 | + continuedFraction: typeof continuedFraction; |
| 66 | + |
| 67 | + /** |
| 68 | + * Evaluates a polynomial. |
| 69 | + * |
| 70 | + * ## Notes |
| 71 | + * |
| 72 | + * - The implementation uses [Horner's rule][horners-method] for efficient computation. |
| 73 | + * |
| 74 | + * [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method |
| 75 | + * |
| 76 | + * |
| 77 | + * @param c - polynomial coefficients sorted in ascending degree |
| 78 | + * @param x - value at which to evaluate the polynomial |
| 79 | + * @returns evaluated polynomial |
| 80 | + * |
| 81 | + * @example |
| 82 | + * var v = evalpoly( [3.0,2.0,1.0], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2 |
| 83 | + * // returns 123.0 |
| 84 | + * |
| 85 | + * @example |
| 86 | + * var polyval = evalpoly.factory( [3.0,2.0,1.0] ); |
| 87 | + * |
| 88 | + * var v = polyval( 10.0 ); // => 3*10^0 + 2*10^1 + 1*10^2 |
| 89 | + * // returns 123.0 |
| 90 | + * |
| 91 | + * v = polyval( 5.0 ); // => 3*5^0 + 2*5^1 + 1*5^2 |
| 92 | + * // returns 38.0 |
| 93 | + */ |
| 94 | + evalpoly: typeof evalpoly; |
| 95 | + |
| 96 | + /** |
| 97 | + * Evaluates a rational function, i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\). |
| 98 | + * |
| 99 | + * ## Notes |
| 100 | + * |
| 101 | + * - Coefficients should be sorted in ascending degree. |
| 102 | + * - The implementation uses [Horner's rule][horners-method] for efficient computation. |
| 103 | + * |
| 104 | + * [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method |
| 105 | + * |
| 106 | + * |
| 107 | + * @param P - numerator polynomial coefficients sorted in ascending degree |
| 108 | + * @param Q - denominator polynomial coefficients sorted in ascending degree |
| 109 | + * @param x - value at which to evaluate the rational function |
| 110 | + * @returns evaluated rational function |
| 111 | + * |
| 112 | + * @example |
| 113 | + * var P = [ -6.0, -5.0 ]; |
| 114 | + * var Q = [ 3.0, 0.5 ]; |
| 115 | + * |
| 116 | + * var v = evalrational( P, Q, 6.0 ); // => ( -6*6^0 - 5*6^1 ) / ( 3*6^0 + 0.5*6^1 ) = (-6-30)/(3+3) |
| 117 | + * // returns -6.0 |
| 118 | + * |
| 119 | + * @example |
| 120 | + * var P = [ 20.0, 8.0, 3.0 ]; |
| 121 | + * var Q = [ 10.0, 9.0, 1.0 ]; |
| 122 | + * |
| 123 | + * var rational = evalrational.factory( P, Q ); |
| 124 | + * |
| 125 | + * var v = rational( 10.0 ); // => (20*10^0 + 8*10^1 + 3*10^2) / (10*10^0 + 9*10^1 + 1*10^2) = (20+80+300)/(10+90+100) |
| 126 | + * // returns 2.0 |
| 127 | + * |
| 128 | + * v = rational( 2.0 ); // => (20*2^0 + 8*2^1 + 3*2^2) / (10*2^0 + 9*2^1 + 1*2^2) = (20+16+12)/(10+18+4) |
| 129 | + * // returns 1.5 |
| 130 | + */ |
| 131 | + evalrational: typeof evalrational; |
| 132 | + |
| 133 | + /** |
| 134 | + * Evaluates a Fibonacci polynomial. |
| 135 | + * |
| 136 | + * @param n - Fibonacci polynomial to evaluate |
| 137 | + * @param x - value at which to evaluate a Fibonacci polynomial |
| 138 | + * @returns result |
| 139 | + * |
| 140 | + * @example |
| 141 | + * var v = fibpoly( 5, 1.0 ); |
| 142 | + * // returns 5.0 |
| 143 | + * |
| 144 | + * @example |
| 145 | + * var fibpolyval = fibpoly.factory( 5 ); |
| 146 | + * |
| 147 | + * var v = fibpolyval( 1.0 ); |
| 148 | + * // returns 5.0 |
| 149 | + * |
| 150 | + * v = fibpolyval( 2.0 ); |
| 151 | + * // returns 29.0 |
| 152 | + */ |
| 153 | + fibpoly: typeof fibpoly; |
| 154 | + |
| 155 | + /** |
| 156 | + * Evaluates a physicist's Hermite polynomial. |
| 157 | + * |
| 158 | + * @param n - nonnegative polynomial degree |
| 159 | + * @param x - evaluation point |
| 160 | + * @returns function value |
| 161 | + * |
| 162 | + * @example |
| 163 | + * var v = hermitepoly( 1, 1.0 ); |
| 164 | + * // returns 2.0 |
| 165 | + * |
| 166 | + * @example |
| 167 | + * var v = hermitepoly( 1, 0.5 ); |
| 168 | + * // returns 1.0 |
| 169 | + * |
| 170 | + * @example |
| 171 | + * var polyval = hermitepoly.factory( 2 ); |
| 172 | + * |
| 173 | + * var v = polyval( 0.5 ); |
| 174 | + * // returns -1.0 |
| 175 | + */ |
| 176 | + hermitepoly: typeof hermitepoly; |
| 177 | + |
| 178 | + /** |
| 179 | + * Evaluates a Lucas polynomial. |
| 180 | + * |
| 181 | + * @param n - Lucas polynomial to evaluate |
| 182 | + * @param x - value at which to evaluate a Lucas polynomial |
| 183 | + * @returns result |
| 184 | + * |
| 185 | + * @example |
| 186 | + * var v = lucaspoly( 5, 1.0 ); |
| 187 | + * // returns 11.0 |
| 188 | + * |
| 189 | + * @example |
| 190 | + * var polyval = lucaspoly.factory( 5 ); |
| 191 | + * |
| 192 | + * var v = polyval( 1.0 ); |
| 193 | + * // returns 11.0 |
| 194 | + * |
| 195 | + * v = polyval( 2.0 ); |
| 196 | + * // returns 82.0 |
| 197 | + */ |
| 198 | + lucaspoly: typeof lucaspoly; |
| 199 | + |
| 200 | + /** |
| 201 | + * Evaluates a normalized Hermite polynomial. |
| 202 | + * |
| 203 | + * @param n - nonnegative polynomial degree |
| 204 | + * @param x - evaluation point |
| 205 | + * @returns function value |
| 206 | + * |
| 207 | + * @example |
| 208 | + * var v = normhermitepoly( 1, 0.5 ); |
| 209 | + * // returns 0.5 |
| 210 | + * |
| 211 | + * @example |
| 212 | + * var polyval = normhermitepoly.factory( 2 ); |
| 213 | + * |
| 214 | + * var v = polyval( 0.5 ); |
| 215 | + * // returns -0.75 |
| 216 | + */ |
| 217 | + normhermitepoly: typeof normhermitepoly; |
| 218 | + |
| 219 | + /** |
| 220 | + * Sum the elements of the series given by the supplied function. |
| 221 | + * |
| 222 | + * @param generator - series function |
| 223 | + * @param options - function options |
| 224 | + * @param options.maxTerms - maximum number of terms to be added (default: 1000000) |
| 225 | + * @param options.tolerance - further terms are only added as long as the next term is greater than current term times the tolerance (default: 2.22e-16) |
| 226 | + * @param options.initialValue - initial value of the resulting sum (default: 0) |
| 227 | + * @returns sum of all series terms |
| 228 | + * |
| 229 | + * @example |
| 230 | + * var pow = require( `@stdlib/math/base/special/pow` ); |
| 231 | + * var gen = geometricSeriesGenerator( 0.9 ); |
| 232 | + * var out = sumSeries( gen ); |
| 233 | + * // returns 10.0 |
| 234 | + * |
| 235 | + * function* geometricSeriesGenerator( x ) { |
| 236 | + * var exponent = 0; |
| 237 | + * while ( true ) { |
| 238 | + * yield pow( x, exponent ); |
| 239 | + * exponent += 1; |
| 240 | + * } |
| 241 | + * } |
| 242 | + */ |
| 243 | + sumSeries: typeof sumSeries; |
| 244 | +} |
| 245 | + |
| 246 | +/** |
| 247 | +* Standard library basic mathematical tools. |
| 248 | +*/ |
| 249 | +declare var tools: Tools; |
| 250 | + |
| 251 | + |
| 252 | +// EXPORTS // |
| 253 | + |
| 254 | +export = tools; |
0 commit comments