Open in new tab

Probly is a Python-like mini-language for probabilistic estimation. It's based on Starlark and implemented in Go.

Start with Example 1

Probly syntax

You may use any Starlark syntax. There are only the following differences to Starlark:

  • A variable may follow a probability distribution, in addition to usual types like numbers or dictionaries
  • The Starlark math module is imported by default, so you can directly use it e.g. math.sqrt(2). Probly also has a built-in sum function not available in Starlark.

This page will show you the probability distributions of all the numeric (scalar or distribution) global variables in your program (except those starting with an underscore). The values are taken at the end of the program's execution.

Probability distributions

Name to
p10 to p90
pm
plus/minus
td
times/divide
Quantiles Notes
Normal mean sd 2
LogNormal mu sigma 2 Alternatively: mean, sd
Beta alpha beta
PERT min mode max [lambd] Like the triangular, but smoother (Wikipedia)
Uniform a b 2 a need not be less than b
LogUniform a b 2 a need not be less than b
Bernoulli p
Binomial n p
Discrete x_1 p_1 x_2 p_2 ... Generic discrete distribution over any finite set of values

math

These mathematical functions and constants are available in the math module:

  • pow(x, y) - Returns x raised to the power of y
  • exp(x)
  • sqrt(x)
  • log(x, [base]) - Natural logarithm by default if base is not specified
  • e
  • pi
  • Ceil, floor, and sign manipulation:
    • ceil(x)
    • floor(x)
    • fabs(x) - Returns the absolute value of x as float
    • copysign(x, y) - Returns a value with the magnitude of x and the sign of y
  • mod(x, y) - Returns x modulo y
  • remainder(x, y)
  • round(x) - Returns the nearest integer, rounding half away from zero
  • Trigonometry (in radians unless otherwise specified):
    • acos(x)
    • asin(x)
    • atan(x)
    • atan2(y, x) - Returns atan(y / x). The result is between -pi and pi
    • cos(x)
    • sin(x)
    • tan(x)
    • degrees(x) - Converts angle x from radians to degrees
    • radians(x) - Converts angle x from degrees to radians
    • acosh(x)
    • asinh(x)
    • atanh(x)
    • cosh(x)
    • sinh(x)
    • tanh(x)
  • hypot(x, y) - Returns the Euclidean norm, sqrt(x^2 + y^2); the distance from the origin to (x, y)
  • gamma(x) - Returns the Gamma function at x

Starlark syntax

This code provides an example of the syntax of Starlark:

# Define a number
number = 18

# Define a list
numbers = [1, 2, 3, 4, 5]

# List comprehension
halves = [n / 2 for n in numbers]

# Define a function
def is_even(n):
    """Return True if n is even."""
    return n % 2 == 0

# Define a dictionary
people = {
    "Alice": 22,
    "Bob": 40,
    "Charlie": 55,
    "Dave": 14,
}

names = ", ".join(people.keys())  # Alice, Bob, Charlie, Dave

# Modify a variable in a loop
sum_even_ages = 0
for age in people.values():
    if is_even(age):
        sum_even_ages += age

# Append to a list in a loop
over_30_names = []
for name, age in people.items():
    if age > 30:
        over_30_names.append(name)

If you've ever used Python, this should look very familiar. In fact, the code above is also valid Python code. Still, this short example shows most of the language. Starlark is a very small language that implements a limited subset of Python.

For our purposes, one notable difference to Python is that the exponentiation operator ** is not supported. You have to use math.pow.

You can also look at the Starlark language specification.

Speed

Though not designed for speed, Probly is fast enough for practical purposes: around 10 milliseconds for 3,000 samples, for most examples on this page. This is due to being implemented in Go.

The time taken to return results on this page is spent overwhelmingly in web application code, not in Probly evaluation.

Interestingly, Probly is still slower than Python code that uses entirely numpy array operations, which are very well optimised. This should only begin to matter at very large scales, or if latency is critical.

Limitations

It's not currently possible to obtain and manipulate properties of a distribution within an Probly program, like so:

x = Normal(1 to 10)
y = x.std()  # Not possible

Supporting this would require some fundamental changes to the implementation of Probly, which is currently very simplistic.

Prior work

The to binary operator was inspired by Squiggle.

Example Dissolving the Fermi Paradox (Sandberg et al.)

This example follows Section 3 of Dissolving the Fermi Paradox (Sandberg and colleagues, 2018).

From the abstract:

[The Fermi paradox] arises from the use of Drake-like equations, which implicitly assume certainty regarding highly uncertain parameters. ... When the model is recast to represent realistic distributions of uncertainty, we find a substantial ex ante probability of there being no other intelligent life in our observable universe, and thus that there should be little surprise when we fail to detect any signs of it.

The results of our simulation should approximately match Figure 2 of the paper:

The mean for N is [...] 27 million, but the median is now only 0.32 – less than one civilization per galaxy like our own. The probability of N<1 is now 52%.

Distribution details

n

Mean 33.8 E 6
Std. dev. 505 E 6
Variance 255 E 15
Quantile
0.05 0
0.25 368 E -15
0.50 1.18
0.75 5 020
0.95 12.4 E 6

longevity

Mean 527 E 6
Std. dev. 1.51 E 9
Variance 2.28 E 18
Quantile
0.05 229
0.25 9 060
0.50 886 000
0.75 91.0 E 6
0.95 4.03 E 9

detectable

Mean 0.216
Std. dev. 0.251
Variance 0.063 1
Quantile
0.05 0.012 6
0.25 0.031 3
0.50 0.098 6
0.75 0.318
0.95 0.803

intelligence

Mean 0.144
Std. dev. 0.226
Variance 0.051 2
Quantile
0.05 0.001 49
0.25 0.006 05
0.50 0.031 2
0.75 0.172
0.95 0.692

life

Mean 0.505
Std. dev. 0.494
Variance 0.244
Quantile
0.05 0
0.25 888 E -18
0.50 0.670
0.75 1.00
0.95 1.00

r_life

Mean 14.7 E 72
Std. dev. 807 E 72
Variance 652 E 147
Quantile
0.05 3.27 E -36
0.25 886 E -18
0.50 1.11
0.75 141 E 12
0.95 30.8 E 33

habitable

Mean 0.386
Std. dev. 0.245
Variance 0.059 9
Quantile
0.05 0.111
0.25 0.178
0.50 0.316
0.75 0.551
0.95 0.874

planet

Mean 0.394
Std. dev. 0.253
Variance 0.063 8
Quantile
0.05 0.114
0.25 0.177
0.50 0.316
0.75 0.565
0.95 0.903

star_formation

Mean 21.4
Std. dev. 25.3
Variance 640
Quantile
0.05 1.25
0.25 3.16
0.50 9.88
0.75 31.1
0.95 81.6

Simulation data

CSV

Download CSV

Preview

star_formation planet habitable r_life ... intelligence detectable longevity n
0 1.17 0.684 0.940 97.4 E -12 ... 0.303 0.087 3 269 521 E -12
1 11.5 0.542 0.271 196 E 12 ... 0.004 53 0.016 2 33 300 4.13
2 18.6 0.248 0.229 736 E 18 ... 0.050 0 0.178 228 000 2 140
... ... ... ... ... ... ... ... ... ...
2997 2.11 0.118 0.945 520 E 15 ... 0.097 2 0.284 1.77 E 9 11.5 E 6
2998 2.67 0.161 0.119 46 000 ... 0.022 6 0.012 0 103 0.001 42
2999 14.7 0.204 0.118 2.53 E 21 ... 0.063 8 0.067 6 8.55 E 9 13.0 E 6

API

Get the simulation data (and more) in a machine-readable format: /api/sim/D4c9mGWMYYYou5hjBMTdAy/