Skip to content

Commit a07d934

Browse files
committed
feat: add inline comments
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed ---
1 parent 42b5497 commit a07d934

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

lib/node_modules/@stdlib/math/base/special/hyp2f1/lib/hys2f1.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ var MAX_ITERATIONS = config.MAX_ITERATIONS;
5252
/**
5353
* Evaluates the Gaussian hypergeometric function by two-term recurrence in `a`.
5454
*
55+
* This helps prevent losing accuracy in the highly alternating hypergeometric series and allows a and b to be reduced to smaller values.
56+
*
57+
* AMS55 #15.2.10
58+
*
5559
* @private
5660
* @param {number} a - input value
5761
* @param {number} b - input value
@@ -82,6 +86,7 @@ function hyp2f1ra( a, b, c, x, loss ) {
8286

8387
t = a - da;
8488
if ( abs( da ) > MAX_ITERATIONS ) {
89+
// Too expensive to compute
8590
loss = 1.0;
8691
return {
8792
'value': NaN,
@@ -90,6 +95,7 @@ function hyp2f1ra( a, b, c, x, loss ) {
9095
}
9196

9297
if ( da < 0.0 ) {
98+
// Backward recurrence
9399
f2Val = 0.0;
94100
f1 = hys2f1( t, b, c, x, err );
95101
loss += f1.error;
@@ -108,6 +114,7 @@ function hyp2f1ra( a, b, c, x, loss ) {
108114
t -= 1.0;
109115
}
110116
} else {
117+
// Forward recurrence
111118
f2Val = 0.0;
112119
f1 = hys2f1( t, b, c, x, err );
113120
loss += f1.error;
@@ -214,6 +221,7 @@ function hys2f1( a, b, c, x, loss ) {
214221
}
215222
} while ( s === 0.0 || abs( u / s ) > MACHEP );
216223

224+
// Estimate the relative error due to truncation by the series
217225
loss = ( ( MACHEP * umax ) / abs( s ) ) + ( MACHEP * i );
218226
return {
219227
'value': s,

lib/node_modules/@stdlib/math/base/special/hyp2f1/lib/hyt2f1.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ function hyt2f1( a, b, c, x, loss ) {
104104

105105
if ( x < -0.5 && !( negIntA || negIntB ) ) {
106106
if ( b > a ) {
107+
// Transformation based on AMS55 #15.3.4
107108
y = hys2f1( a, c - b, c, -x / s, err );
108109
val = pow( s, -a ) * y.value;
109110
} else {
111+
// Transformation based on AMS55 #15.3.5
110112
y = hys2f1( c - a, b, c, -x / s, err );
111113
val = pow( s, -b ) * y.value;
112114
}
@@ -122,10 +124,12 @@ function hyt2f1( a, b, c, x, loss ) {
122124

123125
if ( x > 0.9 && !negIntA && !negIntB ) {
124126
if ( isInteger( d ) === false ) {
127+
// Try the power series first:
125128
y = hys2f1( a, b, c, x, err );
126129
if ( y.error < ETHRESH ) {
127130
return y;
128131
}
132+
// If the power series fails, then apply AMS55 #15.3.6
129133
err = y.error;
130134
q = hys2f1( a, b, 1.0 - d, s, err );
131135
qVal = q.value;
@@ -155,6 +159,7 @@ function hyt2f1( a, b, c, x, loss ) {
155159
err += err1 + ( ( MACHEP * max( abs( qVal ), abs( rVal ) ) ) / y );
156160
y *= gamma( c );
157161
} else {
162+
// Psi function expansion, AMS55 #15.3.10, #15.3.11, #15.3.12
158163
if ( id >= 0.0 ) {
159164
e = d;
160165
d1 = d;
@@ -226,6 +231,7 @@ function hyt2f1( a, b, c, x, loss ) {
226231
'error': err
227232
};
228233
}
234+
// Use defining power series if no special cases
229235
y = hys2f1( a, b, c, x, err );
230236
return y;
231237
}

lib/node_modules/@stdlib/math/base/special/hyp2f1/lib/isinteger.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
17+
*
18+
*
19+
* ## Notice
20+
*
21+
* 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.
22+
*
23+
* ```text
24+
* (C) Copyright Stephen L. Moshier 1984, 1987, 1992, 2000.
25+
*
26+
* Use, modification and distribution are subject to the
27+
* Cephes Mathematical Library License. (See accompanying file
28+
* LICENSE or copy at https://smath.com/en-US/view/CephesMathLibrary/license)
29+
* ```
1730
*/
1831

1932
'use strict';

lib/node_modules/@stdlib/math/base/special/hyp2f1/lib/isnonpositiveinteger.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
17+
*
18+
*
19+
* ## Notice
20+
*
21+
* 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.
22+
*
23+
* ```text
24+
* (C) Copyright Stephen L. Moshier 1984, 1987, 1992, 2000.
25+
*
26+
* Use, modification and distribution are subject to the
27+
* Cephes Mathematical Library License. (See accompanying file
28+
* LICENSE or copy at https://smath.com/en-US/view/CephesMathLibrary/license)
29+
* ```
1730
*/
1831

1932
'use strict';

lib/node_modules/@stdlib/math/base/special/hyp2f1/lib/main.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,31 @@ function hyp2f1( a, b, c, x ) {
141141
return 1.0;
142142
}
143143

144+
/* The transformation for c - a or c - b negative integer
145+
* AMS55 #15.3.3
146+
*/
144147
if ( d <= -1.0 && !( !isIntD && s < 0.0 ) && !( negIntA || negIntB ) ) {
145148
return pow( s, d ) * hyp2f1( c - a, c - b, c, x );
146149
}
147150

151+
// The series diverges
148152
if ( d <= 0.0 && x === 1.0 && !( negIntA || negIntB ) ) {
149153
return PINF;
150154
}
151155

152156
if ( ax < 1.0 || x === -1.0 ) {
153157
if ( b === c ) {
158+
// 2F1(a,b;b;x) = (1-x)**(-a)
154159
return pow( s, -a );
155160
}
156161
if ( a === c ) {
162+
// 2F1(a,b;a;x) = (1-x)**(-b)
157163
return pow( s, -b );
158164
}
159165
}
160166

161167
if ( negIntC ) {
168+
// Check if termination before explosion
162169
if ( negIntA && ( ia > ic ) ) {
163170
y = hyt2f1( a, b, c, x, err );
164171
return y.value;
@@ -170,11 +177,16 @@ function hyp2f1( a, b, c, x ) {
170177
return PINF;
171178
}
172179

180+
// Function is a polynomial, so try the power series expansion
173181
if ( negIntA || negIntB ) {
174182
y = hyt2f1( a, b, c, x, err );
175183
return y.value;
176184
}
177185

186+
/**
187+
* This transform has a pole for integer b - a and may cause large cancellation errors near |1/x| = 1.
188+
* AMS55 #15.3.7
189+
*/
178190
if ( x < -2.0 && !isInteger( t1 ) ) {
179191
p = hyp2f1( a, 1.0 - c + a, 1.0 - b + a, 1.0 / x );
180192
q = hyp2f1( b, 1.0 - c + b, 1.0 - a + b, 1.0 / x );
@@ -186,19 +198,24 @@ function hyp2f1( a, b, c, x ) {
186198
return ( s * p ) + ( y * q );
187199
}
188200
if ( x < -1.0 ) {
201+
// Transformation based on AMS55 #15.3.4
189202
if ( abs( a ) < abs( b ) ) {
190203
return pow( s, -a ) * hyp2f1( a, c - b, c, x / ( x - 1.0 ) );
191204
}
205+
// Transformation based on AMS55 #15.3.5
192206
return pow( s, -b ) * hyp2f1( b, c - a, c, x / ( x - 1.0 ) );
193207
}
194208

209+
// The series diverges for |x| > 1 if above checks fail
195210
if ( ax > 1.0 ) {
196211
return PINF;
197212
}
198213

199214
p = c - a;
200215
r = c - b;
201216
negIntCaOrCb = isNonPositiveInteger( p ) || isNonPositiveInteger( r );
217+
218+
// If |x| == 1.0
202219
if ( ax === 1.0 ) {
203220
if ( x > 0.0 ) {
204221
if ( negIntCaOrCb ) {
@@ -218,11 +235,16 @@ function hyp2f1( a, b, c, x ) {
218235
}
219236
}
220237

238+
/* Conditionally make d > 0 by recurrence on c
239+
* AMS55 #15.2.27
240+
*/
221241
if ( d < 0.0 ) {
242+
// Try the power series first:
222243
y = hyt2f1( a, b, c, x, err );
223244
if ( y.error < ETHRESH ) {
224245
return y.value;
225246
}
247+
// If the power series fails, then apply the recurrence
226248
y = y.value;
227249
err = 0.0;
228250
aid = 2.0 - id;
@@ -242,11 +264,15 @@ function hyp2f1( a, b, c, x ) {
242264
return y;
243265
}
244266

267+
/* The transformation for c - a or c - b negative integer
268+
* AMS55 #15.3.3
269+
*/
245270
if ( negIntCaOrCb ) {
246271
y = hys2f1( c - a, c - b, c, x, err );
247272
return pow( s, d ) * y.value;
248273
}
249274

275+
// Try the power series
250276
y = hyt2f1( a, b, c, x, err );
251277
return y.value;
252278
}

0 commit comments

Comments
 (0)