# underworld.function.math module¶

This module provides math functions. All functions take functions (or convertibles) as arguments. These functions effectively wrap to the c++ standard template library equivalent. For example, the ‘exp’ class generates a function with uses std::exp(double).

All functions operate on and return ‘double’ type data (or ‘float’ from python).

## Classes¶

 underworld.function.math.abs Computes the absolute value of its argument function. underworld.function.math.acos Computes the principal value of the arc cosine of x, expressed in radians. underworld.function.math.acosh Computes the inverse hyperbolic cosine of its argument function. underworld.function.math.asin Computes the principal value of the arc sine of x, expressed in radians. underworld.function.math.asinh Computes the inverse hyperbolic sine of its argument function. underworld.function.math.atan Computes the principal value of the arc tangent of x, expressed in radians. underworld.function.math.atanh Computes the inverse hyperbolic tangent of its argument function. underworld.function.math.cos Computes the cosine of its argument function (measured in radians). underworld.function.math.cosh Computes the hyperbolic cosine of its argument function. underworld.function.math.dot Dot product function. underworld.function.math.erf Computes the error function of its argument function. underworld.function.math.erfc Computes the complementary error function of its argument function. underworld.function.math.exp Computes the exponent of its argument function. underworld.function.math.log Computes the natural logarithm of its argument function. underworld.function.math.log10 Computes the base 10 logarithm of its argument function. underworld.function.math.log2 Computes the base 2 logarithm of its argument function. underworld.function.math.pow Power function. underworld.function.math.sin Computes the sine of its argument function (measured in radians). underworld.function.math.sinh Computes the hyperbolic sine of its argument function. underworld.function.math.sqrt Computes the square root of its argument function. underworld.function.math.tan Computes the tangent of its argument function (measured in radians). underworld.function.math.tanh Computes the hyperbolic tangent of its argument function.
class underworld.function.math.abs(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the absolute value of its argument function.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = abs()
>>> np.allclose( func.evaluate(-0.1234), sysmath.fabs(0.1234) )
True

class underworld.function.math.acos(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the principal value of the arc cosine of x, expressed in radians.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = acos()
>>> np.allclose( func.evaluate(0.1234), sysmath.acos(0.1234) )
True

class underworld.function.math.acosh(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the inverse hyperbolic cosine of its argument function.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = acosh()
>>> np.allclose( func.evaluate(5.1234), sysmath.acosh(5.1234) )
True

class underworld.function.math.asin(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the principal value of the arc sine of x, expressed in radians.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = asin()
>>> np.allclose( func.evaluate(0.1234), sysmath.asin(0.1234) )
True

class underworld.function.math.asinh(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the inverse hyperbolic sine of its argument function.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = asinh()
>>> np.allclose( func.evaluate(5.1234), sysmath.asinh(5.1234) )
True

class underworld.function.math.atan(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the principal value of the arc tangent of x, expressed in radians.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = atan()
>>> np.allclose( func.evaluate(0.1234), sysmath.atan(0.1234) )
True

class underworld.function.math.atanh(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the inverse hyperbolic tangent of its argument function.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = atanh()
>>> np.allclose( func.evaluate(0.1234), sysmath.atanh(0.1234) )
True

class underworld.function.math.cos(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the cosine of its argument function (measured in radians).

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = cos()
>>> np.allclose( func.evaluate(0.1234), sysmath.cos(0.1234) )
True

class underworld.function.math.cosh(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the hyperbolic cosine of its argument function.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = cosh()
>>> np.allclose( func.evaluate(0.1234), sysmath.cosh(0.1234) )
True

class underworld.function.math.dot(fn1, fn2, **kwargs)[source]

Bases: underworld.function._function.Function

Dot product function. Returns fn1.fn2. Argument functions must return values of identical size.

Parameters: fn1 (underworld.function.Function (or convertible)) – Argument function 1. fn2 (underworld.function.Function (or convertible)) – Argument function 2.

Example

>>> import math as sysmath
>>> import numpy as np
>>> input1 = (2.,3.,4.)
>>> input2 = (5.,6.,7.)
>>> func = dot( input1, input2 )


The function is constant, so evaluate anywhere:

>>> np.allclose( func.evaluate(0.), np.dot(input1,input2) )
True

class underworld.function.math.erf(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the error function of its argument function.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = erf()
>>> np.allclose( func.evaluate(0.1234), sysmath.erf(0.1234) )
True

class underworld.function.math.erfc(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the complementary error function of its argument function.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = erfc()
>>> np.allclose( func.evaluate(0.1234), sysmath.erfc(0.1234) )
True

class underworld.function.math.exp(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the exponent of its argument function.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = exp()
>>> np.allclose( func.evaluate(0.1234), sysmath.exp(0.1234) )
True

class underworld.function.math.log(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the natural logarithm of its argument function.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = log()
>>> np.allclose( func.evaluate(0.1234), sysmath.log(0.1234) )
True

class underworld.function.math.log10(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the base 10 logarithm of its argument function.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = log10()
>>> np.allclose( func.evaluate(0.1234), sysmath.log10(0.1234) )
True

class underworld.function.math.log2(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the base 2 logarithm of its argument function.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = log2()
>>> np.allclose( func.evaluate(0.1234), sysmath.log(0.1234,2) )
True

class underworld.function.math.pow(fn1, fn2, **kwargs)[source]

Bases: underworld.function._function.Function

Power function. Raises fn1 to the power of fn2.

Parameters: fn1 (underworld.function.Function (or convertible)) – The base function. fn2 (underworld.function.Function (or convertible)) – The power function.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = pow(_uw.function.input(),3.)
>>> np.allclose( func.evaluate(2.), sysmath.pow(2.,3.) )
True

class underworld.function.math.sin(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the sine of its argument function (measured in radians).

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = sin()
>>> np.allclose( func.evaluate(0.1234), sysmath.sin(0.1234) )
True

class underworld.function.math.sinh(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the hyperbolic sine of its argument function.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = sinh()
>>> np.allclose( func.evaluate(0.1234), sysmath.sinh(0.1234) )
True

class underworld.function.math.sqrt(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the square root of its argument function.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = sqrt()
>>> np.allclose( func.evaluate(0.1234), sysmath.sqrt(0.1234) )
True

class underworld.function.math.tan(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the tangent of its argument function (measured in radians).

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = tan()
>>> np.allclose( func.evaluate(0.1234), sysmath.tan(0.1234) )
True

class underworld.function.math.tanh(fn=None, *args, **kwargs)[source]

Bases: underworld.function._function.Function

Computes the hyperbolic tangent of its argument function.

Parameters: fn (underworld.function.Function (or convertible)) – Optionally provided for function composition.

Example

>>> import math as sysmath
>>> import numpy as np
>>> func = tanh()
>>> np.allclose( func.evaluate(0.1234), sysmath.tanh(0.1234) )
True