Maths functions

The following Maths Functions come bundled with RiskScape for use in your function.

Built-in maths functions

RiskScape comes with a set of default functions that are useful for doing mathematics in the context of RiskScape and Risk Analysis. They are used like any other RiskScape function. For example, to round a floating point number, you can use the round function like round(-34.23).

Where possible, RiskScape makes use of maths packages that are part of the Java language. These packages are widely used and are proven to produce reliable mathematical results. For example, the square_root() RiskScape function is just a simple ‘wrapper’ for the Java Math.sqrt() function.

More specific help for all these built-in functions is available from RiskScape’s built-in help. From the command line, you can use riskscape function list to see what functions are available, the arguments each function takes, and what they return. To list the maths functions available in RiskScape, run riskscape function list --category maths.


Gives the absolute value of a number


Round number up to the closest integer


Returns Euler’s number (e) raised to the power of the value given. The inverse of log()


Convert input to a floating point number


Round number down to the closest integer


Convert input to a integer number


Return the logarithm of a number for a particular base, defaulting to natural log if none given


Returns the base-10 logarithm of the given value


Cumulative probability distribution function from a log-normal curve. Where shape is σ (standard deviation) and scale is μ (mean), both as the log of the distribution.


Probability Density Function (PDF) for a given point in a normal distribution. Where shape is σ (standard deviation) and scale is μ (mean), both as the log of the distribution.


Returns the greater of two values given


Returns the smaller of two values given


Cumulative probability distribution function from a normal curve


Probability Density Function (PDF) for a given point in a normal distribution


Computes a polynomial expression, denoted by the set of coefficients ‘c’ (starting at x⁰, x, x², etc)


Raise a number by a specific power


Picks an item from the list at random, or with an optional weighted probability


Returns a random number from the given normal distribution


Returns a random number within the range [start, stop]


Round number to the closest integer


Get the square root of the given number

Jython discrete functions


The following sections describe using RiskScape-based code from within a Jython function. Most Python users will probably find it simpler to setup RiskScape to use CPython and use standard Python maths packages instead.

A discrete function can be constructed from points, constants and other functions, to form a single function for use with risk analysis.

Using points

The simplest use of a discrete function is to join up a series of points to create a continuous sequence of lines between them.

from import DiscreteFunction

ID = 'joined-points'
DESCRIPTION = 'Demonstrates a function built by connecting points to form a series of linear functions'

FUNCTION = DiscreteFunction.builder() \
           .addPoint(-1, 4) \
           .addPoint(1, 6) \
           .addPoint(4, 8) \
           .addPoint(10, 10) \
           .withLinearInterpolation() \


As well as adding a point, a constant value can be added for a range:

# will return 0.45 when 0 <= x <= 10
DiscreteFunction.builder().addConstant(0, 10, 0.45)

Joining functions

Arbitrary RiskScape functions can be joined up to form a single function. Each function is added along with the range for which it’s applicable:

from import DiscreteFunction, Maths

ID = 'joined-polynomials'
DESCRIPTION = 'Demonstrates a function built by connecting polynomials'

quadratic = Maths.newPolynomial(0, 8, 0.25)
cubic = Maths.newPolynomial(10, 0, 4, 0.5)

FUNCTION = DiscreteFunction.builder() \
           .addFunction(-10, -5, cubic) \
           .addFunction(40, 1000, polynomial) \
           .withLinearInterpolation() \


By default, a discrete function will ‘close’ any upper bound on a range that isn’t connected to a higher range. For example, adding the range addFunction(0, 10, somePolynomial) will make that polynomial apply when 0 <= x <= 10. However, if a function is added from 10 onwards, then somePolynomial applies when 0 <= x < 10.

This closing behaviour can be disabled by calling .withoutUpperBoundClosing on the function builder.