Skip to content

Latest commit

 

History

History
222 lines (137 loc) · 4.84 KB

File metadata and controls

222 lines (137 loc) · 4.84 KB

spence

Spence's function, also known as the dilogarithm.

The dilogarithm is defined as

$$\mathop{\mathrm{Li}}_{2}(z) = -\int_{0}^{z}{\ln(1-u) \over u}\,du{\text{, }}z\in \mathbb {C}$$

or also alternatively as

$$\int _{1}^{v}{\frac {\ln t}{1-t}}dt=\operatorname {Li} _{2}(1-v).$$

Usage

var spence = require( '@stdlib/math/base/special/spence' );

spence( x )

Evaluates Spence's function, which is alternatively known as the dilogarithm.

var v = spence( 3.0 );
// returns ~-1.437

v = spence( 0.0 );
// returns ~1.645

v = spence( NaN );
// returns NaN

For negative numbers, the dilogarithm is not defined.

var v = spence( -4.0 );
// returns NaN

Examples

var randu = require( '@stdlib/random/base/randu' );
var spence = require( '@stdlib/math/base/special/spence' );

var x;
var i;

for ( i = 0; i < 100; i++ ) {
    x = randu() * 100.0;
    console.log( 'spence( %d ) = %d', x, spence( x ) );
}

C APIs

Usage

#include "stdlib/math/base/special/spence.h"

stdlib_base_spence( x )

Evaluates Spence's function, which is alternatively known as the dilogarithm.

double out = stdlib_base_spence( 3.0 );
// returns ~-1.437

out = stdlib_base_spence( 0.0 );
// returns ~1.645

The function accepts the following arguments:

  • x: [in] double input value.
double stdlib_base_spence( const double x );

Examples

#include "stdlib/math/base/special/spence.h"
#include <stdio.h>

int main( void ) {
    const double x[] = { 3.0, 9.0, 0.0, -10.0 };

    double y;
    int i;
    for ( i = 0; i < 4; i++ ) {
        y = stdlib_base_spence( x[ i ] );
        printf( "spence(%lf) = %lf\n", x[ i ], y );
    }
}