Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1008x 1008x 1008x 1008x 1008x 1008x 3x 3x 1005x 1008x 3x 3x 3x 1008x 2x 2x 1008x 500x 500x 500x 500x 500x 1008x 1008x 1x 1x 1x 1x 1x | /**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
// MODULES //
var acos = require( '@stdlib/math/base/special/acos' );
var acosh = require( '@stdlib/math/base/special/acosh' );
var sin = require( '@stdlib/math/base/special/sin' );
var sinpi = require( '@stdlib/math/base/special/sinpi' );
var sqrt = require( '@stdlib/math/base/special/sqrt' );
var expm1 = require( '@stdlib/math/base/special/expm1' );
var exp = require( '@stdlib/math/base/special/exp' );
var abs = require( '@stdlib/math/base/special/abs' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
// MAIN //
/**
* Evaluates a Chebyshev polynomial of the second kind for a non-integer degree `n` using its closed-form representation.
*
* ## Notes
*
* - For \\( -1 < x < 1 \\) and \\( x = \cos\theta \\),
*
* ```tex
* U_n(x) = \frac{\sin\left( (n+1)\theta \right)}{\sin\theta}
* ```
*
* where \\( \sin\theta = \sqrt{(1-x)(1+x)} \\).
*
* - For \\( x > 1 \\) and \\( x = \cosh t \\),
*
* ```tex
* U_n(x) = \frac{\sinh\left( (n+1)t \right)}{\sinh t} = \operatorname{sgn}(a) \, e^{(|a|-1)t} \, \frac{1 - e^{-2|a|t}}{1 - e^{-2t}}
* ```
*
* where \\( a = n+1 \\). The second form avoids overflow in the intermediate hyperbolic sines.
*
* - Both forms are equal to \\( (n+1) \, {}_2F_1\left( -n, n+2; \tfrac{3}{2}; \tfrac{1}{2}(1-x) \right) \\).
*
* - For \\( x < -1 \\), the function is complex-valued, and we return `NaN`.
*
* @private
* @param {number} n - non-integer degree
* @param {number} x - input value
* @returns {number} function value
*
* @example
* var y = closedForm( 0.5, 0.5 );
* // returns ~1.155
*/
function closedForm( n, x ) {
var a;
var b;
var t;
var y;
if ( x < -1.0 ) {
return NaN;
}
a = n + 1.0;
if ( x === -1.0 ) {
// The limit as `x` approaches `-1` from above (i.e., as `θ` approaches `π` from below):
return ( sinpi( a ) > 0.0 ) ? PINF : NINF;
}
if ( x === 1.0 ) {
return a;
}
if ( x < 1.0 ) {
return sin( a * acos( x ) ) / sqrt( ( 1.0-x ) * ( 1.0+x ) );
}
t = acosh( x );
b = abs( a );
y = exp( ( b-1.0 ) * t ) * ( expm1( -2.0*b*t ) / expm1( -2.0*t ) );
return ( a < 0.0 ) ? -y : y;
}
// EXPORTS //
module.exports = closedForm;
|