Skip to content

Math Expressions

Math expressions let you compute values inline on either side of a comparison, or inside computed values, without needing to pre-compute fields in your data.

Math expressions support full nested arithmetic:

<expression> <comparison> <expression>

An expression can contain:

  • properties
  • literal numbers
  • computed value references like @total
  • +, -, *, /, %, ^
  • math functions: floor, ceil, round, abs, sqrt, min, max, clamp
  • aggregate expressions: sum of, average of, min of, max of
  • natural-language aliases
  • parentheses
OperatorAccepted forms
addition+, plus, added to
subtraction-, minus, subtracted by
multiplication*, times, multiplied by
division/, divided by
modulo%, modulo, remainder of
power^, power of, to the power of

The engine applies normal arithmetic precedence:

  1. parentheses and math functions
  2. exponentiation
  3. multiplication, division, and modulo
  4. addition and subtraction

This means multiplication happens before addition:

__subtotal__ of **Order** + __tax__ of **Order** * 2 is greater than 100

Use parentheses when you want a different grouping:

(__subtotal__ of **Order** + __tax__ of **Order**) * 2 is greater than 100
__subtotal__ of **Order** + __tax__ of **Order** is greater than 100

Aliases also work:

__subtotal__ of **Order** plus __tax__ of **Order** is greater than 100

Interactive Example

Policy Rule
Test Data (JSON)

Mix a property with a literal:

Interactive Example

Policy Rule
Test Data (JSON)
__balance__ of **Account** - __pending__ of **Account** is at least 0

Interactive Example

Policy Rule
Test Data (JSON)
__quantity__ of **Order** * __unit_price__ of **Order** is greater than 1000

Interactive Example

Policy Rule
Test Data (JSON)
__revenue__ of **Store** / __expenses__ of **Store** is greater than 1.5

Interactive Example

Policy Rule
Test Data (JSON)

Modulo returns the remainder after division. It shares precedence with * and /.

__count__ of **Order** % 2 is equal to 0

Aliases also work:

__count__ of **Order** modulo 2 is equal to 0
__count__ of **Order** remainder of 2 is equal to 0

Interactive Example

Policy Rule
Test Data (JSON)

Exponentiation raises the left side to the power of the right side.

__score__ of **Applicant** power of 2 is greater than 49

Aliases also work:

__score__ of **Applicant** ^ 2 is greater than 49
__score__ of **Applicant** to the power of 2 is greater than 49

Interactive Example

Policy Rule
Test Data (JSON)

Math functions return transformed numbers. Unary functions accept one expression; min, max, and clamp accept multiple arguments.

FunctionDescription
floor of (...)round down to the nearest integer
ceil of (...)round up to the nearest integer
round of (...)round to the nearest integer
round X to N placesround to a fixed number of decimal places
abs of (...)absolute value
sqrt(...)square root
min(...)smallest argument
max(...)largest argument
clamp(value, min, max)bound a value within a range
floor of (__price__ of **Order** * 1.1) is equal to 11

Interactive Example

Policy Rule
Test Data (JSON)
ceil of (__price__ of **Order** * 1.1) is equal to 12

Interactive Example

Policy Rule
Test Data (JSON)
round of (__score__ of **User** / 3) is equal to 4

Interactive Example

Policy Rule
Test Data (JSON)

You can also use the natural form round X to N places:

round __score__ of **User** to 2 places is equal to 3.14
abs of (__balance__ of **Account** - __limit__ of **Account**) is less than 50

Interactive Example

Policy Rule
Test Data (JSON)
sqrt(81) is equal to 9
min(9, 4, 7) is equal to 4
max(2, 9, 4) is equal to 9
clamp(20, 0, 10) is equal to 10

sum of, average of, min of, and max of can be used as arithmetic expressions, not just directly in comparisons:

total := sum of __prices__ of **Order**.
average_price := average of __prices__ of **Order**.

A **Order** qualifies
if @total is greater than 50
and @average_price is greater than 10.

These aggregate expressions also accept numeric strings in arrays, such as ["15", "25", "20"].

Math functions compose with the rest of the grammar:

Interactive Example

Policy Rule
Test Data (JSON)

You can nest expressions and put arithmetic on both sides of the comparison:

(__used__ of **Quota** + __buffer__ of **Quota**) * 2 is less than __limit__ of **Quota** * 3 - 1

Interactive Example

Policy Rule
Test Data (JSON)

Math expressions can be combined with and and or like any other condition:

Interactive Example

Policy Rule
Test Data (JSON)

Every arithmetic step must resolve to numbers.

  • Numeric strings such as "12.5" are accepted in arithmetic.
  • Non-numeric operands return a type error that includes the failing expression.
  • Division by zero returns an evaluation error that includes the full expression.
  • Execution traces expose the evaluated left-hand expression path and the final right-hand value, so the UI can explain what was compared.

Example errors:

Arithmetic expression $.Applicant.status resolved to a non-numeric string "active", but numeric operands are required
Division by zero in arithmetic expression ($.Student.total / ($.Student.count - $.Student.count))
CapabilitySupported
literal numbersyes
property referencesyes
math on the left sideyes
math on the right sideyes
nested expressionsyes
parenthesesyes
precedence (^ before *///% before +/-)yes
computed value references (@name)yes
aggregate expressions (sum of, average of, min of, max of)yes
math functions (floor, ceil, round, abs, sqrt, min, max, clamp)yes
OperatorAccepted formsExample
addition+, plus, added to__subtotal__ of **Order** plus __tax__ of **Order** is greater than 50
subtraction-, minus, subtracted by__balance__ of **Account** minus __reserved__ of **Account** is at least 0
multiplication*, times, multiplied by__qty__ of **Order** times __price__ of **Order** is greater than 100
division/, divided by__revenue__ of **Store** divided by __costs__ of **Store** is greater than 1
modulo%, modulo, remainder of__count__ of **Order** % 2 is equal to 0
power^, power of, to the power of__score__ of **Applicant** power of 2 is greater than 49
FunctionExample
floor offloor of (__price__ of **Order** * 1.1) is equal to 11
ceil ofceil of (__price__ of **Order** * 1.1) is equal to 12
round ofround of (__score__ of **User** / 3) is equal to 4
round ... to ... placesround __score__ of **User** to 2 places is equal to 3.14
abs ofabs of (__balance__ of **Account** - __limit__ of **Account**) is less than 50
sqrtsqrt(81) is equal to 9
minmin(9, 4, 7) is equal to 4
maxmax(2, 9, 4) is equal to 9
clampclamp(20, 0, 10) is equal to 10