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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | 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 1x 1x 1x 1x 1x 1x 1x | /**
* @license Apache-2.0
*
* Copyright (c) 2025 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.
*
*
* ## Notice
*
* The original C code and copyright notice are from the [Cephes Mathematical Library]{@link https://www.netlib.org/cephes/}. The implementation has been modified for JavaScript.
*
* ```text
* (C) Copyright Stephen L. Moshier 1984, 1987, 1992, 2000.
*
* Use, modification and distribution are subject to the
* Cephes Mathematical Library License. (See accompanying file
* LICENSE or copy at https://smath.com/en-US/view/CephesMathLibrary/license)
* ```
*/
'use strict';
// MODULES //
var abs = require( '@stdlib/math/base/special/abs' );
var pow = require( '@stdlib/math/base/special/pow' );
var max = require( '@stdlib/math/base/special/max' );
var exp = require( '@stdlib/math/base/special/exp' );
var ln = require( '@stdlib/math/base/special/ln' );
var round = require( '@stdlib/math/base/special/round' );
var gamma = require( '@stdlib/math/base/special/gamma' );
var gammaln = require( '@stdlib/math/base/special/gammaln' );
var gammasgn = require( '@stdlib/math/base/special/gammasgn' );
var digamma = require( '@stdlib/math/base/special/digamma' );
var isNonPositiveInteger = require( './isnonpositiveinteger.js' );
var isInteger = require( './isinteger.js' );
var hys2f1 = require( './hys2f1.js' );
var config = require( './config.json' );
// VARIABLES //
var MACHEP = config.MACHEP;
var EPS = config.EPS;
var ETHRESH = config.ETHRESH;
var MAX_ITERATIONS = config.MAX_ITERATIONS;
// MAIN //
/**
* Applies transformations for `|x|` near unity before performing a power series expansion.
*
* @private
* @param {number} a - input value
* @param {number} b - input value
* @param {number} c - input value
* @param {number} x - input value
* @param {number} loss - starting loss of significance
* @returns {Object} the function value and error
*/
function hyt2f1( a, b, c, x, loss ) {
var negIntA;
var negIntB;
var qVal;
var rVal;
var sign;
var err1;
var err;
var val;
var aid;
var ax;
var id;
var d1;
var d2;
var y1;
var i;
var p;
var q;
var r;
var t;
var y;
var w;
var d;
var e;
var s;
negIntA = isNonPositiveInteger( a );
negIntB = isNonPositiveInteger( b );
err = 0.0;
err1 = 0.0;
s = 1.0 - x;
if ( x < -0.5 && !( negIntA || negIntB ) ) {
if ( b > a ) {
// Transformation based on AMS55 #15.3.4:
y = hys2f1( a, c-b, c, -x/s, err );
val = pow( s, -a ) * y.value;
} else {
// Transformation based on AMS55 #15.3.5:
y = hys2f1( c-a, b, c, -x/s, err );
val = pow( s, -b ) * y.value;
}
loss = y.error;
return {
'value': val,
'error': loss
};
}
d = c - a - b;
id = round( d );
if ( x > 0.9 && !negIntA && !negIntB ) {
if ( isInteger( d ) === false ) {
// Try the power series first:
y = hys2f1( a, b, c, x, err );
if ( y.error < ETHRESH ) {
return y;
}
// If the power series fails, then apply AMS55 #15.3.6...
err = y.error;
q = hys2f1( a, b, 1.0-d, s, err );
qVal = q.value;
err = q.error;
sign = 1.0;
w = gammaln( d );
sign *= gammasgn( d );
w -= gammaln( c-a );
sign *= gammasgn( c-a );
w -= gammaln( c-b );
sign *= gammasgn( c-b );
qVal *= sign * exp( w );
r = hys2f1( c-a, c-b, d+1.0, s, err1 );
err1 = r.error;
rVal = pow( s, d ) * r.value;
sign = 1.0;
w = gammaln( -d );
sign *= gammasgn( -d );
w -= gammaln( a );
sign *= gammasgn( a );
w -= gammaln( b );
sign *= gammasgn( b );
rVal *= sign * exp( w );
y = qVal + rVal;
err += err1 + ( ( MACHEP * max( abs( qVal ), abs( rVal ) ) ) / y );
y *= gamma( c );
} else {
// Psi function expansion, AMS55 #15.3.10, #15.3.11, #15.3.12...
if ( id >= 0.0 ) {
e = d;
d1 = d;
d2 = 0.0;
aid = id;
} else {
e = -d;
d1 = 0.0;
d2 = d;
aid = -id;
}
ax = ln( s );
// eslint-disable-next-line max-len
y = digamma( 1.0 ) + digamma( 1.0+e ) - digamma( a+d1 ) - digamma( b+d1 ) - ax;
y /= gamma( e+1.0 );
p = ( a+d1 ) * ( b+d1 ) * s / gamma( e+2.0 );
t = 1.0;
do {
// eslint-disable-next-line max-len
r = digamma( 1.0+t ) + digamma( 1.0+t+e ) - digamma( a+t+d1 ) - digamma( b+t+d1 ) - ax;
q = p * r;
y += q;
p *= s * ( a+t+d1 ) / ( t+1.0 );
p *= ( b+t+d1 ) / ( t+1.0+e );
t += 1.0;
if ( t > MAX_ITERATIONS ) {
loss = 1.0;
return {
'value': NaN,
'error': loss
};
}
} while ( y === 0.0 || abs( q/y ) > EPS );
if ( id === 0.0 ) {
y *= gamma( c ) / ( gamma( a ) * gamma( b ) );
return {
'value': y,
'error': err
};
}
y1 = 1.0;
if ( aid !== 1.0 ) {
t = 0.0;
p = 1.0;
for ( i = 1; i < aid; i++ ) {
r = 1.0 - e + t;
p *= s * ( a+t+d2 ) * ( b+t+d2 ) / r;
t += 1.0;
p /= t;
y1 += p;
}
}
p = gamma( c );
y1 *= gamma( e ) * p / ( gamma( a+d1 ) * gamma( b+d1 ) );
y *= p / ( gamma( a+d2 ) * gamma( b+d2 ) );
if ( aid % 2.0 !== 0.0 ) {
y = -y;
}
q = pow( s, id );
y = ( id > 0.0 ) ? y*q : y1*q;
y += y1;
}
return {
'value': y,
'error': err
};
}
// Perform power series if no special cases:
y = hys2f1( a, b, c, x, err );
return y;
}
// EXPORTS //
module.exports = hyt2f1;
|