Skip to content

Commit

Permalink
Improve hypergeometricU using arbitrary apparatus
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmasson committed Mar 6, 2022
1 parent cd2b1e2 commit 9307eaf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
21 changes: 20 additions & 1 deletion build/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -2547,7 +2547,26 @@ function hypergeometricU( a, b, x ) {

var t2 = mul( gamma(sub(1,b)), inv( gamma(add(a,neg(b),1)) ), hypergeometric1F1( a, b, x ) );

return add( t1, t2 );
var max = Math.max( abs(t1), abs(t2) );
if ( max < 100 ) return add( t1, t2 );

var extraDecimals = +max.toExponential().split( 'e' )[1];
setPrecisionScale( defaultDecimals + extraDecimals );

a = arbitrary(a);
b = arbitrary(b);
x = arbitrary(x);

t1 = mul( gamma(sub(b,arb1)), inv( gamma(a) ), pow( x, sub(arb1,b) ),
hypergeometric1F1( add(a,neg(b),arb1), sub(arb2,b), x ) );

t2 = mul( gamma(sub(arb1,b)), inv( gamma(add(a,neg(b),arb1)) ), hypergeometric1F1( a, b, x ) );

var result = arbitrary( add( t1, t2 ) );

resetPrecisionScale();

return result;

}

Expand Down
21 changes: 20 additions & 1 deletion src/functions/hypergeometric.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,26 @@ function hypergeometricU( a, b, x ) {

var t2 = mul( gamma(sub(1,b)), inv( gamma(add(a,neg(b),1)) ), hypergeometric1F1( a, b, x ) );

return add( t1, t2 );
var max = Math.max( abs(t1), abs(t2) );
if ( max < 100 ) return add( t1, t2 );

var extraDecimals = +max.toExponential().split( 'e' )[1];
setPrecisionScale( defaultDecimals + extraDecimals );

a = arbitrary(a);
b = arbitrary(b);
x = arbitrary(x);

t1 = mul( gamma(sub(b,arb1)), inv( gamma(a) ), pow( x, sub(arb1,b) ),
hypergeometric1F1( add(a,neg(b),arb1), sub(arb2,b), x ) );

t2 = mul( gamma(sub(arb1,b)), inv( gamma(add(a,neg(b),arb1)) ), hypergeometric1F1( a, b, x ) );

var result = arbitrary( add( t1, t2 ) );

resetPrecisionScale();

return result;

}

Expand Down

0 comments on commit 9307eaf

Please sign in to comment.