Formulas & Functions

    Build calculations using mathematical expressions, operators, and built-in functions.

    Syntax

    Reference connected variables by their variable name (the identifier, not the display name). Input ports are created automatically for each variable referenced in your expression.

    (revenue - cost) / revenue * 100

    This expression creates two input ports: revenue and cost.

    Operators

    Operator Description Example
    + Addition a + b
    - Subtraction a - b
    * Multiplication a * b
    / Division a / b
    ^ Exponentiation a ^ 2
    % Modulo a % b
    () Grouping (a + b) * c

    ** is also accepted for exponentiation.

    Constants

    Constant Value Description
    PI / pi 3.14159... Circle constant π
    E / e 2.71828... Euler's number e
    phi 1.61803... Golden ratio φ
    tau 6.28318... 2π (full circle)

    Functions

    Basic Math
    Function Description Example
    abs(x) Absolute value abs(-5) → 5
    sqrt(x) Square root sqrt(16) → 4
    pow(x, y) Power pow(2, 3) → 8
    exp(x) Exponential (e^x) exp(1) → 2.718
    log(x) Natural logarithm log(E) → 1
    Rounding
    Function Description Example
    floor(x) Round down floor(3.7) → 3
    ceil(x) Round up ceil(3.2) → 4
    round(x) Round to nearest round(3.5) → 4
    Comparison
    Function Description Example
    min(a, b, ...) Minimum value min(3, 1, 4) → 1
    max(a, b, ...) Maximum value max(3, 1, 4) → 4
    Conditional
    Function Description Example
    if(cond, a, b) If-then-else if(x > 0, x, 0) → x or 0
    cond(cond, a, b) Alias for if() cond(x > 0, x, 0) → x or 0
    Finance
    Function Description Example
    FV(rate, n, pmt, pv, type) Future value of investment FV(0.05, 10, -100, -1000, 0) → 1628.89
    PV(rate, n, pmt, fv, type) Present value of cash flows PV(0.08, 5, 0, -10000, 0) → 6805.83
    NPV(rate, cf1, cf2, ...) Net present value (Excel-compatible) NPV(0.1, -1000, 300, 400, 500) → -19.12
    PMT(rate, n, pv, fv, type) Periodic payment amount PMT(0.05/12, 360, 200000, 0, 0) → -1073.64
    CAGR(start, end, periods) Compound annual growth rate CAGR(100, 200, 5) → 0.1487
    ROI(gain, cost) Return on investment ROI(150, 100) → 0.5
    Trigonometry
    Function Description Example
    sin(x) Sine (radians) sin(PI/2) → 1
    cos(x) Cosine (radians) cos(0) → 1
    tan(x) Tangent (radians) tan(PI/4) → 1

    Best Practices

    Prevent division by zero

    Guard denominators using the max() function to ensure they never reach zero. This prevents errors when random samples produce extreme values.

    value / max(divisor, 0.0001)

    Protect logarithms

    Logarithm functions require positive arguments. Wrap inputs in max() to handle cases where random sampling might produce zero or negative values.

    log(max(x, 0.0001))

    Use parentheses for clarity

    Even when operator precedence handles the order correctly, explicit parentheses make your formulas easier to read and verify. This is especially important for complex expressions.

    (a * b) + (c * d)

    Conditional logic

    Use if() or cond() for conditional calculations. The condition is true when greater than 0.

    if(revenue > 100000, revenue * 0.10, 0)

    Automatic connections

    When you type a variable name in your expression, an input port is automatically created and connected to the matching block. Renaming variables in the expression updates the connections accordingly—no manual wiring required.