Skip to main content

Standard Library Reference

The Orbital Standard Library provides domain-agnostic building blocks for S-expressions. These are fundamental operations that compose to form complex logic in guards, effects, and computed fields.

Auto-Generated

This documentation is automatically generated from the std library source code. All operators listed here are available in every Almadar schema.

How to use operators

Operators are invoked as S-expressions — a JSON array where the first element is the operator name:

["math/abs", -5]          // => 5
["str/upper", "hello"] // => "HELLO"
["arr/length", [1, 2, 3]] // => 3

Operators compose naturally:

["str/concat",
["str/upper", "@entity.firstName"],
" ",
["str/upper", "@entity.lastName"]
]

🔢Mathematical Operations

Numeric operations for calculations, rounding, clamping, and randomization.

16 operators

math/abs✨ Pure

Absolute value

ParameterTypeDescription
nnumberThe number
Example
["math/abs", -5] // => 5
Returns: numberArgs: 1 argument
math/min✨ Pure

Minimum of values

ParameterTypeDescription
...numsnumber[]Numbers to compare
Example
["math/min", 3, 1, 4] // => 1
Returns: numberArgs: 2 or more
math/max✨ Pure

Maximum of values

ParameterTypeDescription
...numsnumber[]Numbers to compare
Example
["math/max", 3, 1, 4] // => 4
Returns: numberArgs: 2 or more
math/clamp✨ Pure

Constrain value to range [min, max]

ParameterTypeDescription
nnumberThe value to clamp
minnumberMinimum bound
maxnumberMaximum bound
Example
["math/clamp", 150, 0, 100] // => 100
Returns: numberArgs: 3 arguments
math/floor✨ Pure

Round down to integer

ParameterTypeDescription
nnumberThe number
Example
["math/floor", 3.7] // => 3
Returns: numberArgs: 1 argument
math/ceil✨ Pure

Round up to integer

ParameterTypeDescription
nnumberThe number
Example
["math/ceil", 3.2] // => 4
Returns: numberArgs: 1 argument
math/round✨ Pure

Round to nearest integer or specified decimals

ParameterTypeDescription
nnumberThe number
decimals (opt)numberDecimal places (default: 0)
Example
["math/round", 3.456, 2] // => 3.46
Returns: numberArgs: 1–2 arguments
math/pow✨ Pure

Exponentiation (base^exp)

ParameterTypeDescription
basenumberThe base
expnumberThe exponent
Example
["math/pow", 2, 8] // => 256
Returns: numberArgs: 2 arguments
math/sqrt✨ Pure

Square root

ParameterTypeDescription
nnumberThe number
Example
["math/sqrt", 16] // => 4
Returns: numberArgs: 1 argument
math/mod✨ Pure

Modulo (remainder)

ParameterTypeDescription
anumberDividend
bnumberDivisor
Example
["math/mod", 7, 3] // => 1
Returns: numberArgs: 2 arguments
math/sign✨ Pure

Returns -1, 0, or 1 indicating sign

ParameterTypeDescription
nnumberThe number
Example
["math/sign", -42] // => -1
Returns: numberArgs: 1 argument
math/lerp✨ Pure

Linear interpolation between a and b by factor t

ParameterTypeDescription
anumberStart value
bnumberEnd value
tnumberInterpolation factor (0-1)
Example
["math/lerp", 0, 100, 0.5] // => 50
Returns: numberArgs: 3 arguments
math/map✨ Pure

Map value from one range to another

ParameterTypeDescription
nnumberThe value
inMinnumberInput range minimum
inMaxnumberInput range maximum
outMinnumberOutput range minimum
outMaxnumberOutput range maximum
Example
["math/map", 5, 0, 10, 0, 100] // => 50
Returns: numberArgs: 5 arguments
math/random✨ Pure

Random number between 0 (inclusive) and 1 (exclusive)

Example
["math/random"] // => 0.7234...
Returns: numberArgs: 0 arguments
math/randomInt✨ Pure

Random integer in range [min, max] (inclusive)

ParameterTypeDescription
minnumberMinimum (inclusive)
maxnumberMaximum (inclusive)
Example
["math/randomInt", 1, 6] // => 4
Returns: numberArgs: 2 arguments
math/default✨ Pure

Return default if value is null, undefined, or NaN

ParameterTypeDescription
nnumber | nullThe value
defaultnumberDefault value
Example
["math/default", null, 0] // => 0
Returns: numberArgs: 2 arguments

📝String Operations

Text manipulation including formatting, splitting, trimming, and templating.

27 operators

str/len✨ Pure

String length

ParameterTypeDescription
sstringThe string
Example
["str/len", "hello"] // => 5
Returns: numberArgs: 1 argument
str/concat✨ Pure

Concatenate strings together

ParameterTypeDescription
stringsstringStrings to concatenate
Example
["str/concat", "/users/", "@entity.id"] // => "/users/123"
Returns: textArgs: 1–99 arguments
str/upper✨ Pure

Convert to uppercase

ParameterTypeDescription
sstringThe string
Example
["str/upper", "hello"] // => "HELLO"
Returns: textArgs: 1 argument
str/lower✨ Pure

Convert to lowercase

ParameterTypeDescription
sstringThe string
Example
["str/lower", "HELLO"] // => "hello"
Returns: textArgs: 1 argument
str/trim✨ Pure

Remove leading and trailing whitespace

ParameterTypeDescription
sstringThe string
Example
["str/trim", " hello "] // => "hello"
Returns: textArgs: 1 argument
str/trimStart✨ Pure

Remove leading whitespace

ParameterTypeDescription
sstringThe string
Example
["str/trimStart", " hello"] // => "hello"
Returns: textArgs: 1 argument
str/trimEnd✨ Pure

Remove trailing whitespace

ParameterTypeDescription
sstringThe string
Example
["str/trimEnd", "hello "] // => "hello"
Returns: textArgs: 1 argument
str/split✨ Pure

Split string into array by delimiter

ParameterTypeDescription
sstringThe string
delimstringDelimiter
Example
["str/split", "a,b,c", ","] // => ["a", "b", "c"]
Returns: listArgs: 2 arguments
str/join✨ Pure

Join array elements into string

ParameterTypeDescription
arrarrayArray to join
delimstringDelimiter
Example
["str/join", ["a", "b", "c"], ", "] // => "a, b, c"
Returns: textArgs: 2 arguments
str/slice✨ Pure

Extract substring

ParameterTypeDescription
sstringThe string
startnumberStart index
end (opt)numberEnd index (exclusive)
Example
["str/slice", "hello", 1, 4] // => "ell"
Returns: textArgs: 2–3 arguments
str/replace✨ Pure

Replace first occurrence

ParameterTypeDescription
sstringThe string
findstringString to find
replacestringReplacement
Example
["str/replace", "hello world", "world", "there"] // => "hello there"
Returns: textArgs: 3 arguments
str/replaceAll✨ Pure

Replace all occurrences

ParameterTypeDescription
sstringThe string
findstringString to find
replacestringReplacement
Example
["str/replaceAll", "a-b-c", "-", "_"] // => "a_b_c"
Returns: textArgs: 3 arguments
str/includes✨ Pure

Check if string contains substring

ParameterTypeDescription
sstringThe string
searchstringSubstring to find
Example
["str/includes", "hello world", "world"] // => true
Returns: true/falseArgs: 2 arguments
str/startsWith✨ Pure

Check if string starts with prefix

ParameterTypeDescription
sstringThe string
prefixstringPrefix to check
Example
["str/startsWith", "hello", "hel"] // => true
Returns: true/falseArgs: 2 arguments
str/endsWith✨ Pure

Check if string ends with suffix

ParameterTypeDescription
sstringThe string
suffixstringSuffix to check
Example
["str/endsWith", "hello", "lo"] // => true
Returns: true/falseArgs: 2 arguments
str/padStart✨ Pure

Pad string from start to target length

ParameterTypeDescription
sstringThe string
lennumberTarget length
char (opt)stringPadding character (default: )
Example
["str/padStart", "5", 3, "0"] // => "005"
Returns: textArgs: 2–3 arguments
str/padEnd✨ Pure

Pad string from end to target length

ParameterTypeDescription
sstringThe string
lennumberTarget length
char (opt)stringPadding character (default: )
Example
["str/padEnd", "5", 3, "0"] // => "500"
Returns: textArgs: 2–3 arguments
str/repeat✨ Pure

Repeat string n times

ParameterTypeDescription
sstringThe string
countnumberRepeat count
Example
["str/repeat", "ab", 3] // => "ababab"
Returns: textArgs: 2 arguments
str/reverse✨ Pure

Reverse string

ParameterTypeDescription
sstringThe string
Example
["str/reverse", "hello"] // => "olleh"
Returns: textArgs: 1 argument
str/capitalize✨ Pure

Capitalize first character

ParameterTypeDescription
sstringThe string
Example
["str/capitalize", "hello"] // => "Hello"
Returns: textArgs: 1 argument
str/titleCase✨ Pure

Convert to Title Case

ParameterTypeDescription
sstringThe string
Example
["str/titleCase", "hello world"] // => "Hello World"
Returns: textArgs: 1 argument
str/camelCase✨ Pure

Convert to camelCase

ParameterTypeDescription
sstringThe string
Example
["str/camelCase", "hello world"] // => "helloWorld"
Returns: textArgs: 1 argument
str/kebabCase✨ Pure

Convert to kebab-case

ParameterTypeDescription
sstringThe string
Example
["str/kebabCase", "Hello World"] // => "hello-world"
Returns: textArgs: 1 argument
str/snakeCase✨ Pure

Convert to snake_case

ParameterTypeDescription
sstringThe string
Example
["str/snakeCase", "Hello World"] // => "hello_world"
Returns: textArgs: 1 argument
str/default✨ Pure

Return default if value is null/undefined/empty

ParameterTypeDescription
sstring | nullThe value
defaultstringDefault value
Example
["str/default", null, "N/A"] // => "N/A"
Returns: textArgs: 2 arguments
str/template✨ Pure

Variable substitution in template string

ParameterTypeDescription
templatestringTemplate with {placeholders}
varsobjectVariables to substitute
Example
["str/template", "Hello, {name}!", {"name": "World"}] // => "Hello, World!"
Returns: textArgs: 2 arguments
str/truncate✨ Pure

Truncate string with optional suffix

ParameterTypeDescription
sstringThe string
lennumberMaximum length
suffix (opt)stringSuffix for truncated strings (default: ...)
Example
["str/truncate", "Hello World", 8, "..."] // => "Hello..."
Returns: textArgs: 2–3 arguments

📋Collection Operations

Work with lists and arrays including filtering, mapping, and aggregation.

39 operators

array/len✨ Pure

Array length

ParameterTypeDescription
arrarrayThe array
Example
["array/len", [1, 2, 3]] // => 3
Returns: numberArgs: 1 argument
array/empty?✨ Pure

Check if array is empty

ParameterTypeDescription
arrarrayThe array
Example
["array/empty?", []] // => true
Returns: true/falseArgs: 1 argument
array/first✨ Pure

Get first element

ParameterTypeDescription
arrarrayThe array
Example
["array/first", [1, 2, 3]] // => 1
Returns: any valueArgs: 1 argument
array/last✨ Pure

Get last element

ParameterTypeDescription
arrarrayThe array
Example
["array/last", [1, 2, 3]] // => 3
Returns: any valueArgs: 1 argument
array/nth✨ Pure

Get element at index

ParameterTypeDescription
arrarrayThe array
indexnumberIndex (0-based)
Example
["array/nth", [1, 2, 3], 1] // => 2
Returns: any valueArgs: 2 arguments
array/slice✨ Pure

Extract subarray

ParameterTypeDescription
arrarrayThe array
startnumberStart index
end (opt)numberEnd index (exclusive)
Example
["array/slice", [1, 2, 3, 4], 1, 3] // => [2, 3]
Returns: listArgs: 2–3 arguments
array/concat✨ Pure

Concatenate arrays

ParameterTypeDescription
...arrsarray[]Arrays to concatenate
Example
["array/concat", [1, 2], [3, 4]] // => [1, 2, 3, 4]
Returns: listArgs: 2 or more
array/append✨ Pure

Add item to end (returns new array)

ParameterTypeDescription
arrarrayThe array
itemanyItem to add
Example
["array/append", [1, 2], 3] // => [1, 2, 3]
Returns: listArgs: 2 arguments
array/prepend✨ Pure

Add item to start (returns new array)

ParameterTypeDescription
arrarrayThe array
itemanyItem to add
Example
["array/prepend", [2, 3], 1] // => [1, 2, 3]
Returns: listArgs: 2 arguments
array/insert✨ Pure

Insert item at index (returns new array)

ParameterTypeDescription
arrarrayThe array
indexnumberIndex to insert at
itemanyItem to insert
Example
["array/insert", [1, 3], 1, 2] // => [1, 2, 3]
Returns: listArgs: 3 arguments
array/remove✨ Pure

Remove item at index (returns new array)

ParameterTypeDescription
arrarrayThe array
indexnumberIndex to remove
Example
["array/remove", [1, 2, 3], 1] // => [1, 3]
Returns: listArgs: 2 arguments
array/removeItem✨ Pure

Remove first matching item (returns new array)

ParameterTypeDescription
arrarrayThe array
itemanyItem to remove
Example
["array/removeItem", [1, 2, 3, 2], 2] // => [1, 3, 2]
Returns: listArgs: 2 arguments
array/reverse✨ Pure

Reverse array order (returns new array)

ParameterTypeDescription
arrarrayThe array
Example
["array/reverse", [1, 2, 3]] // => [3, 2, 1]
Returns: listArgs: 1 argument
array/sort✨ Pure

Sort array (returns new array)

ParameterTypeDescription
arrarrayThe array
key (opt)stringField to sort by (for objects)
dir (opt)string"asc" or "desc" (default: asc)
Example
["array/sort", "@items", "price", "desc"]
Returns: listArgs: 1–3 arguments
array/shuffle✨ Pure

Randomly shuffle array (returns new array)

ParameterTypeDescription
arrarrayThe array
Example
["array/shuffle", [1, 2, 3, 4, 5]]
Returns: listArgs: 1 argument
array/unique✨ Pure

Remove duplicates (returns new array)

ParameterTypeDescription
arrarrayThe array
Example
["array/unique", [1, 2, 2, 3, 1]] // => [1, 2, 3]
Returns: listArgs: 1 argument
array/flatten✨ Pure

Flatten nested arrays one level

ParameterTypeDescription
arrarrayThe array
Example
["array/flatten", [[1, 2], [3, 4]]] // => [1, 2, 3, 4]
Returns: listArgs: 1 argument
array/zip✨ Pure

Pair elements from two arrays

ParameterTypeDescription
arr1arrayFirst array
arr2arraySecond array
Example
["array/zip", [1, 2], ["a", "b"]] // => [[1, "a"], [2, "b"]]
Returns: listArgs: 2 arguments
array/includes✨ Pure

Check if array contains item

ParameterTypeDescription
arrarrayThe array
itemanyItem to find
Example
["array/includes", [1, 2, 3], 2] // => true
Returns: true/falseArgs: 2 arguments
array/indexOf✨ Pure

Find index of item (-1 if not found)

ParameterTypeDescription
arrarrayThe array
itemanyItem to find
Example
["array/indexOf", [1, 2, 3], 2] // => 1
Returns: numberArgs: 2 arguments
array/find✨ Pure

Find first element matching predicate

ParameterTypeDescription
arrarrayThe array
predlambdaPredicate function
Example
["array/find", "@items", ["fn", "x", ["=", "@x.status", "active"]]]
Returns: any valueArgs: 2 arguments
array/findIndex✨ Pure

Find index of first element matching predicate (-1 if none)

ParameterTypeDescription
arrarrayThe array
predlambdaPredicate function
Example
["array/findIndex", "@items", ["fn", "x", ["=", "@x.status", "active"]]]
Returns: numberArgs: 2 arguments
array/filter✨ Pure

Keep elements matching predicate

ParameterTypeDescription
arrarrayThe array
predlambdaPredicate function
Example
["array/filter", "@items", ["fn", "x", [">", "@x.price", 100]]]
Returns: listArgs: 2 arguments
array/reject✨ Pure

Remove elements matching predicate

ParameterTypeDescription
arrarrayThe array
predlambdaPredicate function
Example
["array/reject", "@items", ["fn", "x", ["=", "@x.status", "deleted"]]]
Returns: listArgs: 2 arguments
array/map✨ Pure

Transform each element

ParameterTypeDescription
arrarrayThe array
fnlambdaTransform function
Example
["array/map", "@items", ["fn", "x", ["*", "@x.price", 1.1]]]
Returns: listArgs: 2 arguments
array/reduce✨ Pure

Reduce array to single value

ParameterTypeDescription
arrarrayThe array
fnlambdaReducer function (acc, item) => newAcc
initanyInitial accumulator value
Example
["array/reduce", "@items", ["fn", ["acc", "x"], ["+", "@acc", "@x.price"]], 0]
Returns: any valueArgs: 3 arguments
array/every✨ Pure

Check if all elements match predicate

ParameterTypeDescription
arrarrayThe array
predlambdaPredicate function
Example
["array/every", "@items", ["fn", "x", [">", "@x.price", 0]]]
Returns: true/falseArgs: 2 arguments
array/some✨ Pure

Check if any element matches predicate

ParameterTypeDescription
arrarrayThe array
predlambdaPredicate function
Example
["array/some", "@items", ["fn", "x", ["=", "@x.status", "active"]]]
Returns: true/falseArgs: 2 arguments
array/count✨ Pure

Count elements (optionally matching predicate)

ParameterTypeDescription
arrarrayThe array
pred (opt)lambdaPredicate function
Example
["array/count", "@tasks", ["fn", "t", ["=", "@t.status", "done"]]]
Returns: numberArgs: 1–2 arguments
array/sum✨ Pure

Sum values (optionally by field)

ParameterTypeDescription
arrarrayThe array
key (opt)stringField to sum
Example
["array/sum", "@cart.items", "price"]
Returns: numberArgs: 1–2 arguments
array/avg✨ Pure

Average of values (optionally by field)

ParameterTypeDescription
arrarrayThe array
key (opt)stringField to average
Example
["array/avg", "@ratings", "score"]
Returns: numberArgs: 1–2 arguments
array/min✨ Pure

Minimum value (optionally by field)

ParameterTypeDescription
arrarrayThe array
key (opt)stringField to compare
Example
["array/min", "@products", "price"]
Returns: numberArgs: 1–2 arguments
array/max✨ Pure

Maximum value (optionally by field)

ParameterTypeDescription
arrarrayThe array
key (opt)stringField to compare
Example
["array/max", "@products", "price"]
Returns: numberArgs: 1–2 arguments
array/groupBy✨ Pure

Group elements by field value

ParameterTypeDescription
arrarrayThe array
keystringField to group by
Example
["array/groupBy", "@orders", "status"]
Returns: any valueArgs: 2 arguments
array/partition✨ Pure

Split array by predicate into [matches, nonMatches]

ParameterTypeDescription
arrarrayThe array
predlambdaPredicate function
Example
["array/partition", "@items", ["fn", "x", [">", "@x.price", 50]]]
Returns: listArgs: 2 arguments
array/take✨ Pure

Take first n elements

ParameterTypeDescription
arrarrayThe array
nnumberNumber of elements
Example
["array/take", "@items", 5]
Returns: listArgs: 2 arguments
array/drop✨ Pure

Skip first n elements

ParameterTypeDescription
arrarrayThe array
nnumberNumber of elements to skip
Example
["array/drop", "@items", 5]
Returns: listArgs: 2 arguments
array/takeLast✨ Pure

Take last n elements

ParameterTypeDescription
arrarrayThe array
nnumberNumber of elements
Example
["array/takeLast", "@items", 3]
Returns: listArgs: 2 arguments
array/dropLast✨ Pure

Skip last n elements

ParameterTypeDescription
arrarrayThe array
nnumberNumber of elements to skip
Example
["array/dropLast", "@items", 2]
Returns: listArgs: 2 arguments

🔑Object Utilities

Access and manipulate object properties safely.

19 operators

object/keys✨ Pure

Get object keys as array

ParameterTypeDescription
objobjectThe object
Example
["object/keys", {"a": 1, "b": 2}] // => ["a", "b"]
Returns: listArgs: 1 argument
object/values✨ Pure

Get object values as array

ParameterTypeDescription
objobjectThe object
Example
["object/values", {"a": 1, "b": 2}] // => [1, 2]
Returns: listArgs: 1 argument
object/entries✨ Pure

Get [key, value] pairs as array

ParameterTypeDescription
objobjectThe object
Example
["object/entries", {"a": 1}] // => [["a", 1]]
Returns: listArgs: 1 argument
object/fromEntries✨ Pure

Create object from [key, value] pairs

ParameterTypeDescription
entriesarrayArray of [key, value] pairs
Example
["object/fromEntries", [["a", 1], ["b", 2]]] // => {"a": 1, "b": 2}
Returns: any valueArgs: 1 argument
object/get✨ Pure

Get nested value by path

ParameterTypeDescription
objobjectThe object
pathstringDot-separated path (e.g., "user.name")
default (opt)anyDefault if path not found
Example
["object/get", "@user", "profile.name", "Anonymous"]
Returns: any valueArgs: 2–3 arguments
object/set✨ Pure

Set nested value by path (returns new object)

ParameterTypeDescription
objobjectThe object
pathstringDot-separated path
valueanyValue to set
Example
["object/set", "@user", "profile.name", "John"]
Returns: any valueArgs: 3 arguments
object/has✨ Pure

Check if path exists

ParameterTypeDescription
objobjectThe object
pathstringDot-separated path
Example
["object/has", "@user", "profile.name"]
Returns: true/falseArgs: 2 arguments
object/merge✨ Pure

Shallow merge objects (later wins)

ParameterTypeDescription
...objsobject[]Objects to merge
Example
["object/merge", {"a": 1}, {"b": 2}] // => {"a": 1, "b": 2}
Returns: any valueArgs: 2 or more
object/deepMerge✨ Pure

Deep merge objects (later wins)

ParameterTypeDescription
...objsobject[]Objects to merge
Example
["object/deepMerge", {"a": {"b": 1}}, {"a": {"c": 2}}]
Returns: any valueArgs: 2 or more
object/pick✨ Pure

Select only specified keys

ParameterTypeDescription
objobjectThe object
keysarrayKeys to keep
Example
["object/pick", "@entity", ["name", "email"]]
Returns: any valueArgs: 2 arguments
object/omit✨ Pure

Exclude specified keys

ParameterTypeDescription
objobjectThe object
keysarrayKeys to exclude
Example
["object/omit", "@entity", ["password", "secret"]]
Returns: any valueArgs: 2 arguments
object/mapValues✨ Pure

Transform all values

ParameterTypeDescription
objobjectThe object
fnlambdaTransform function
Example
["object/mapValues", "@stats", ["fn", "v", ["*", "@v", 100]]]
Returns: any valueArgs: 2 arguments
object/mapKeys✨ Pure

Transform all keys

ParameterTypeDescription
objobjectThe object
fnlambdaTransform function
Example
["object/mapKeys", "@data", ["fn", "k", ["str/upper", "@k"]]]
Returns: any valueArgs: 2 arguments
object/filter✨ Pure

Filter entries by predicate

ParameterTypeDescription
objobjectThe object
predlambdaPredicate (key, value) => boolean
Example
["object/filter", "@data", ["fn", ["k", "v"], ["!=", "@v", null]]]
Returns: any valueArgs: 2 arguments
object/empty?✨ Pure

Check if object has no keys

ParameterTypeDescription
objobjectThe object
Example
["object/empty?", {}] // => true
Returns: true/falseArgs: 1 argument
object/equals✨ Pure

Deep equality check

ParameterTypeDescription
aobjectFirst object
bobjectSecond object
Example
["object/equals", {"a": 1}, {"a": 1}] // => true
Returns: true/falseArgs: 2 arguments
object/clone✨ Pure

Shallow clone object

ParameterTypeDescription
objobjectThe object
Example
["object/clone", "@entity"]
Returns: any valueArgs: 1 argument
object/deepClone✨ Pure

Deep clone object

ParameterTypeDescription
objobjectThe object
Example
["object/deepClone", "@entity"]
Returns: any valueArgs: 1 argument
path✨ Pure

Build a dot-separated path string from segments. Used with set effect for dynamic field paths.

ParameterTypeDescription
...segmentsstring[]Path segments to join with dots
Example
["path", "formValues", "@payload.fieldId"] // => "formValues.customerName"
Returns: textArgs: 1 or more

Date & Time

Work with dates, times, durations, and timestamps.

25 operators

time/now✨ Pure

Current timestamp

Example
["time/now"] // => 1705593600000
Returns: numberArgs: 0 arguments
time/today✨ Pure

Today at midnight (local time)

Example
["time/today"]
Returns: numberArgs: 0 arguments
time/parse✨ Pure

Parse string to timestamp

ParameterTypeDescription
strstringDate string
format (opt)stringFormat pattern
Example
["time/parse", "2024-01-18", "YYYY-MM-DD"]
Returns: numberArgs: 1–2 arguments
time/format✨ Pure

Format timestamp to string

ParameterTypeDescription
datenumberTimestamp
formatstringFormat pattern
Example
["time/format", "@entity.createdAt", "MMM DD, YYYY"]
Returns: textArgs: 2 arguments
time/year✨ Pure

Get year from timestamp

ParameterTypeDescription
datenumberTimestamp
Example
["time/year", "@entity.createdAt"] // => 2024
Returns: numberArgs: 1 argument
time/month✨ Pure

Get month from timestamp (1-12)

ParameterTypeDescription
datenumberTimestamp
Example
["time/month", "@entity.createdAt"] // => 1
Returns: numberArgs: 1 argument
time/day✨ Pure

Get day of month from timestamp (1-31)

ParameterTypeDescription
datenumberTimestamp
Example
["time/day", "@entity.createdAt"] // => 18
Returns: numberArgs: 1 argument
time/weekday✨ Pure

Get day of week (0=Sunday, 6=Saturday)

ParameterTypeDescription
datenumberTimestamp
Example
["time/weekday", "@entity.createdAt"] // => 4 (Thursday)
Returns: numberArgs: 1 argument
time/hour✨ Pure

Get hour from timestamp (0-23)

ParameterTypeDescription
datenumberTimestamp
Example
["time/hour", "@entity.createdAt"] // => 14
Returns: numberArgs: 1 argument
time/minute✨ Pure

Get minute from timestamp (0-59)

ParameterTypeDescription
datenumberTimestamp
Example
["time/minute", "@entity.createdAt"] // => 30
Returns: numberArgs: 1 argument
time/second✨ Pure

Get second from timestamp (0-59)

ParameterTypeDescription
datenumberTimestamp
Example
["time/second", "@entity.createdAt"] // => 45
Returns: numberArgs: 1 argument
time/add✨ Pure

Add time to timestamp

ParameterTypeDescription
datenumberTimestamp
amountnumberAmount to add
unitstringTime unit (year/month/week/day/hour/minute/second/ms)
Example
["time/add", ["time/now"], 7, "day"]
Returns: numberArgs: 3 arguments
time/subtract✨ Pure

Subtract time from timestamp

ParameterTypeDescription
datenumberTimestamp
amountnumberAmount to subtract
unitstringTime unit
Example
["time/subtract", ["time/now"], 1, "hour"]
Returns: numberArgs: 3 arguments
time/diff✨ Pure

Difference between timestamps

ParameterTypeDescription
anumberFirst timestamp
bnumberSecond timestamp
unit (opt)stringResult unit (default: ms)
Example
["time/diff", "@entity.birthDate", ["time/now"], "year"]
Returns: numberArgs: 2–3 arguments
time/startOf✨ Pure

Get start of time period

ParameterTypeDescription
datenumberTimestamp
unitstringTime unit (year/month/week/day/hour/minute)
Example
["time/startOf", ["time/now"], "month"]
Returns: numberArgs: 2 arguments
time/endOf✨ Pure

Get end of time period

ParameterTypeDescription
datenumberTimestamp
unitstringTime unit
Example
["time/endOf", ["time/now"], "month"]
Returns: numberArgs: 2 arguments
time/isBefore✨ Pure

Check if a is before b

ParameterTypeDescription
anumberFirst timestamp
bnumberSecond timestamp
Example
["time/isBefore", "@entity.startDate", "@entity.endDate"]
Returns: true/falseArgs: 2 arguments
time/isAfter✨ Pure

Check if a is after b

ParameterTypeDescription
anumberFirst timestamp
bnumberSecond timestamp
Example
["time/isAfter", ["time/now"], "@entity.deadline"]
Returns: true/falseArgs: 2 arguments
time/isBetween✨ Pure

Check if date is between start and end

ParameterTypeDescription
datenumberTimestamp to check
startnumberRange start
endnumberRange end
Example
["time/isBetween", ["time/now"], "@entity.startDate", "@entity.endDate"]
Returns: true/falseArgs: 3 arguments
time/isSame✨ Pure

Check if timestamps are same (optionally by unit)

ParameterTypeDescription
anumberFirst timestamp
bnumberSecond timestamp
unit (opt)stringComparison unit
Example
["time/isSame", "@a", "@b", "day"]
Returns: true/falseArgs: 2–3 arguments
time/isPast✨ Pure

Check if timestamp is in the past

ParameterTypeDescription
datenumberTimestamp
Example
["time/isPast", "@entity.expiresAt"]
Returns: true/falseArgs: 1 argument
time/isFuture✨ Pure

Check if timestamp is in the future

ParameterTypeDescription
datenumberTimestamp
Example
["time/isFuture", "@entity.scheduledAt"]
Returns: true/falseArgs: 1 argument
time/isToday✨ Pure

Check if timestamp is today

ParameterTypeDescription
datenumberTimestamp
Example
["time/isToday", "@entity.createdAt"]
Returns: true/falseArgs: 1 argument
time/relative✨ Pure

Format as relative time ("2 hours ago", "in 3 days")

ParameterTypeDescription
datenumberTimestamp
Example
["time/relative", "@entity.lastActivityAt"] // => "2 hours ago"
Returns: textArgs: 1 argument
time/duration✨ Pure

Format milliseconds as duration ("2h 30m")

ParameterTypeDescription
msnumberDuration in milliseconds
Example
["time/duration", 9000000] // => "2h 30m"
Returns: textArgs: 1 argument

Input Validation

Validate user input with common patterns like email, required, length checks.

23 operators

validate/required✨ Pure

Check if value is not null, undefined, or empty string

ParameterTypeDescription
valueanyValue to check
Example
["validate/required", "@payload.name"]
Returns: true/falseArgs: 1 argument
validate/string✨ Pure

Check if value is a string

ParameterTypeDescription
valueanyValue to check
Example
["validate/string", "@payload.name"]
Returns: true/falseArgs: 1 argument
validate/number✨ Pure

Check if value is a number

ParameterTypeDescription
valueanyValue to check
Example
["validate/number", "@payload.age"]
Returns: true/falseArgs: 1 argument
validate/boolean✨ Pure

Check if value is a boolean

ParameterTypeDescription
valueanyValue to check
Example
["validate/boolean", "@payload.active"]
Returns: true/falseArgs: 1 argument
validate/array✨ Pure

Check if value is an array

ParameterTypeDescription
valueanyValue to check
Example
["validate/array", "@payload.items"]
Returns: true/falseArgs: 1 argument
validate/object✨ Pure

Check if value is an object

ParameterTypeDescription
valueanyValue to check
Example
["validate/object", "@payload.data"]
Returns: true/falseArgs: 1 argument
validate/email✨ Pure

Check if value is a valid email format

ParameterTypeDescription
valuestringEmail to validate
Example
["validate/email", "@payload.email"]
Returns: true/falseArgs: 1 argument
validate/url✨ Pure

Check if value is a valid URL format

ParameterTypeDescription
valuestringURL to validate
Example
["validate/url", "@payload.website"]
Returns: true/falseArgs: 1 argument
validate/uuid✨ Pure

Check if value is a valid UUID

ParameterTypeDescription
valuestringUUID to validate
Example
["validate/uuid", "@payload.id"]
Returns: true/falseArgs: 1 argument
validate/phone✨ Pure

Check if value is a valid phone number

ParameterTypeDescription
valuestringPhone number to validate
Example
["validate/phone", "@payload.phone"]
Returns: true/falseArgs: 1 argument
validate/creditCard✨ Pure

Check if value is a valid credit card number (Luhn algorithm)

ParameterTypeDescription
valuestringCard number to validate
Example
["validate/creditCard", "@payload.cardNumber"]
Returns: true/falseArgs: 1 argument
validate/date✨ Pure

Check if value is a valid date

ParameterTypeDescription
valueanyValue to check
Example
["validate/date", "@payload.birthDate"]
Returns: true/falseArgs: 1 argument
validate/minLength✨ Pure

Check if string/array has minimum length

ParameterTypeDescription
valuestring | arrayValue to check
minnumberMinimum length
Example
["validate/minLength", "@payload.password", 8]
Returns: true/falseArgs: 2 arguments
validate/maxLength✨ Pure

Check if string/array has maximum length

ParameterTypeDescription
valuestring | arrayValue to check
maxnumberMaximum length
Example
["validate/maxLength", "@payload.name", 50]
Returns: true/falseArgs: 2 arguments
validate/length✨ Pure

Check if string/array has exact length

ParameterTypeDescription
valuestring | arrayValue to check
exactnumberRequired length
Example
["validate/length", "@payload.code", 6]
Returns: true/falseArgs: 2 arguments
validate/min✨ Pure

Check if number is >= minimum

ParameterTypeDescription
valuenumberNumber to check
minnumberMinimum value
Example
["validate/min", "@payload.age", 18]
Returns: true/falseArgs: 2 arguments
validate/max✨ Pure

Check if number is <= maximum

ParameterTypeDescription
valuenumberNumber to check
maxnumberMaximum value
Example
["validate/max", "@payload.quantity", 100]
Returns: true/falseArgs: 2 arguments
validate/range✨ Pure

Check if number is within range [min, max]

ParameterTypeDescription
valuenumberNumber to check
minnumberMinimum value
maxnumberMaximum value
Example
["validate/range", "@payload.rating", 1, 5]
Returns: true/falseArgs: 3 arguments
validate/pattern✨ Pure

Check if string matches regex pattern

ParameterTypeDescription
valuestringString to check
regexstringRegex pattern
Example
["validate/pattern", "@payload.code", "^[A-Z]{3}[0-9]{3}$"]
Returns: true/falseArgs: 2 arguments
validate/oneOf✨ Pure

Check if value is in list of allowed values

ParameterTypeDescription
valueanyValue to check
optionsarrayAllowed values
Example
["validate/oneOf", "@payload.role", ["admin", "user", "guest"]]
Returns: true/falseArgs: 2 arguments
validate/noneOf✨ Pure

Check if value is not in list of disallowed values

ParameterTypeDescription
valueanyValue to check
optionsarrayDisallowed values
Example
["validate/noneOf", "@payload.username", ["admin", "root", "system"]]
Returns: true/falseArgs: 2 arguments
validate/equals✨ Pure

Deep equality check

ParameterTypeDescription
aanyFirst value
banySecond value
Example
["validate/equals", "@payload.password", "@payload.confirmPassword"]
Returns: true/falseArgs: 2 arguments
validate/check✨ Pure

Run multiple validation rules, return { valid, errors }

ParameterTypeDescription
valueanyValue or object to validate
rulesobjectValidation rules by field
Example
["validate/check", "@payload.data", { "name": [["required"], ["minLength", 2], ["maxLength", 50]], "email": [["required"], ["email"]], "age": [["number"], ["min", 18]] }]
Returns: any valueArgs: 2 arguments

🎨Data Formatting

Display formatting for currency, numbers, dates, and file sizes.

9 operators

format/number✨ Pure

Format number with locale-aware separators

ParameterTypeDescription
nnumberNumber to format
opts (opt)objectFormat options (decimals, locale)
Example
["format/number", 1234567.89] // => "1,234,567.89"
Returns: textArgs: 1–2 arguments
format/currency✨ Pure

Format as currency

ParameterTypeDescription
nnumberAmount
currencystringCurrency code (USD, EUR, etc.)
locale (opt)stringLocale (default: en-US)
Example
["format/currency", 1234.56, "USD"] // => "$1,234.56"
Returns: textArgs: 2–3 arguments
format/percent✨ Pure

Format as percentage

ParameterTypeDescription
nnumberNumber (0.5 = 50%)
decimals (opt)numberDecimal places (default: 0)
Example
["format/percent", 0.856, 1] // => "85.6%"
Returns: textArgs: 1–2 arguments
format/bytes✨ Pure

Format bytes as human-readable size

ParameterTypeDescription
nnumberBytes
Example
["format/bytes", 2500000] // => "2.4 MB"
Returns: textArgs: 1 argument
format/ordinal✨ Pure

Format number as ordinal (1st, 2nd, 3rd)

ParameterTypeDescription
nnumberNumber
Example
["format/ordinal", 42] // => "42nd"
Returns: textArgs: 1 argument
format/plural✨ Pure

Format count with singular/plural word

ParameterTypeDescription
nnumberCount
singularstringSingular form
pluralstringPlural form
Example
["format/plural", 5, "item", "items"] // => "5 items"
Returns: textArgs: 3 arguments
format/list✨ Pure

Format array as natural language list

ParameterTypeDescription
arrarrayArray of strings
style (opt)string"and" or "or" (default: and)
Example
["format/list", ["Alice", "Bob", "Charlie"], "and"] // => "Alice, Bob, and Charlie"
Returns: textArgs: 1–2 arguments
format/phone✨ Pure

Format phone number

ParameterTypeDescription
strstringPhone number digits
format (opt)stringFormat pattern (default: US)
Example
["format/phone", "5551234567"] // => "(555) 123-4567"
Returns: textArgs: 1–2 arguments
format/creditCard✨ Pure

Format credit card with masked digits

ParameterTypeDescription
strstringCard number
Example
["format/creditCard", "4111111111111234"] // => "•••• •••• •••• 1234"
Returns: textArgs: 1 argument

Async Operations

Control timing with delays, debouncing, retries, and timeouts.

9 operators

async/delay⚡ Effect

Wait for specified milliseconds, optionally execute an effect after

ParameterTypeDescription
msnumberMilliseconds to wait
effectexpressionOptional effect to execute after delay
Example
["async/delay", 2000, ["emit", "RETRY"]] // Wait 2s then emit
Returns: any valueArgs: 1–2 arguments
async/interval⚡ Effect

Execute an effect periodically at a fixed interval

ParameterTypeDescription
msnumberInterval in milliseconds
effectexpressionEffect to execute each interval
Example
["async/interval", 5000, ["emit", "POLL_TICK"]] // Emit every 5s
Returns: textArgs: 2 arguments
async/timeout⚡ Effect

Add timeout to an effect

ParameterTypeDescription
effectexpressionEffect to execute
msnumberTimeout in milliseconds
Example
["async/timeout", ["call", "api", "fetchData"], 5000]
Returns: any valueArgs: 2 arguments
async/debounce⚡ Effect

Debounce an event (wait for pause in events)

ParameterTypeDescription
eventstringEvent name to emit
msnumberDebounce delay in milliseconds
Example
["async/debounce", "SEARCH", 300]
Returns: nothingArgs: 2 arguments
async/throttle⚡ Effect

Throttle an event (emit at most once per interval)

ParameterTypeDescription
eventstringEvent name to emit
msnumberThrottle interval in milliseconds
Example
["async/throttle", "SCROLL", 100]
Returns: nothingArgs: 2 arguments
async/retry⚡ Effect

Retry an effect with configurable backoff

ParameterTypeDescription
effectexpressionEffect to retry
optsobject{ attempts, backoff, baseDelay }
Example
["async/retry", ["call", "api", "fetchData", { "id": "@entity.id" }], { "attempts": 3, "backoff": "exponential", "baseDelay": 1000 }]
Returns: any valueArgs: 2 arguments
async/race⚡ Effect

Execute effects in parallel, return first to complete

ParameterTypeDescription
...effectsexpression[]Effects to race
Example
["async/race", ["call", "api1"], ["call", "api2"]]
Returns: any valueArgs: 2 or more
async/all⚡ Effect

Execute effects in parallel, wait for all to complete

ParameterTypeDescription
...effectsexpression[]Effects to execute
Example
["async/all", ["call", "api1"], ["call", "api2"]]
Returns: listArgs: 2 or more
async/sequence⚡ Effect

Execute effects in sequence (one after another)

ParameterTypeDescription
...effectsexpression[]Effects to execute in order
Example
["async/sequence", ["call", "validate"], ["call", "save"]]
Returns: listArgs: 2 or more

🧠Neural Network Operations

Define and compose neural network layers and modules.

14 operators

nn/sequential✨ Pure

Create a sequential neural network from layers

ParameterTypeDescription
...layersnn/layer[]Layers to stack sequentially
Example
["nn/sequential", ["nn/linear", 16, 64], ["nn/relu"], ["nn/linear", 64, 4]]
Returns: nn/moduleArgs: 1 or more
nn/linear✨ Pure

Fully connected linear layer (output = input * weights + bias)

ParameterTypeDescription
inFeaturesnumberInput dimension
outFeaturesnumberOutput dimension
Example
["nn/linear", 16, 64] // 16 inputs -> 64 outputs
Returns: nn/layerArgs: 2 arguments
nn/relu✨ Pure

ReLU activation function: max(0, x)

Example
["nn/relu"]
Returns: nn/layerArgs: 0 arguments
nn/tanh✨ Pure

Tanh activation function: (e^x - e^-x) / (e^x + e^-x)

Example
["nn/tanh"]
Returns: nn/layerArgs: 0 arguments
nn/sigmoid✨ Pure

Sigmoid activation function: 1 / (1 + e^-x)

Example
["nn/sigmoid"]
Returns: nn/layerArgs: 0 arguments
nn/softmax✨ Pure

Softmax activation function (normalizes to probability distribution)

ParameterTypeDescription
dim (opt)numberDimension to apply softmax (default: -1)
Example
["nn/softmax"]
Returns: nn/layerArgs: 0–1 arguments
nn/dropout✨ Pure

Dropout layer for regularization (randomly zeros elements during training)

ParameterTypeDescription
p (opt)numberDropout probability (default: 0.5)
Example
["nn/dropout", 0.3] // 30% dropout
Returns: nn/layerArgs: 0–1 arguments
nn/batchnorm✨ Pure

Batch normalization layer

ParameterTypeDescription
numFeaturesnumberNumber of features to normalize
Example
["nn/batchnorm", 64]
Returns: nn/layerArgs: 1 argument
nn/layernorm✨ Pure

Layer normalization

ParameterTypeDescription
normalizedShapenumber | number[]Shape to normalize over
Example
["nn/layernorm", 64]
Returns: nn/layerArgs: 1 argument
nn/forward✨ Pure

Execute forward pass through network

ParameterTypeDescription
modulenn/moduleThe neural network module
inputtensorInput tensor
Example
["nn/forward", "@entity.architecture", "@entity.sensors"]
Returns: tensorArgs: 2 arguments
nn/getWeights✨ Pure

Get network weights as a flat tensor

ParameterTypeDescription
modulenn/moduleThe neural network module
Example
["nn/getWeights", "@entity.architecture"]
Returns: tensorArgs: 1 argument
nn/setWeights⚡ Effect

Set network weights from a flat tensor

ParameterTypeDescription
modulenn/moduleThe neural network module
weightstensorNew weights as flat tensor
Example
["nn/setWeights", "@entity.architecture", "@payload.newWeights"]
Returns: nn/moduleArgs: 2 arguments
nn/paramCount✨ Pure

Get total number of trainable parameters

ParameterTypeDescription
modulenn/moduleThe neural network module
Example
["nn/paramCount", "@entity.architecture"] // => 3300
Returns: numberArgs: 1 argument
nn/clone✨ Pure

Create a deep copy of the network with same weights

ParameterTypeDescription
modulenn/moduleThe neural network module to clone
Example
["nn/clone", "@entity.architecture"]
Returns: nn/moduleArgs: 1 argument

📊Tensor Operations

Create and manipulate multi-dimensional arrays for numerical computing.

29 operators

tensor/from✨ Pure

Create tensor from array

ParameterTypeDescription
dataarrayArray of numbers (can be nested for multi-dimensional)
Example
["tensor/from", [1.0, 2.0, 3.0]]
Returns: tensorArgs: 1 argument
tensor/zeros✨ Pure

Create tensor filled with zeros

ParameterTypeDescription
shapenumber[]Shape of the tensor
Example
["tensor/zeros", [3, 4]] // 3x4 tensor of zeros
Returns: tensorArgs: 1 argument
tensor/ones✨ Pure

Create tensor filled with ones

ParameterTypeDescription
shapenumber[]Shape of the tensor
Example
["tensor/ones", [3, 4]] // 3x4 tensor of ones
Returns: tensorArgs: 1 argument
tensor/rand✨ Pure

Create tensor with random values in [0, 1)

ParameterTypeDescription
shapenumber[]Shape of the tensor
Example
["tensor/rand", [16]] // Random 16-element vector
Returns: tensorArgs: 1 argument
tensor/randn✨ Pure

Create tensor with random values from standard normal distribution

ParameterTypeDescription
shapenumber[]Shape of the tensor
Example
["tensor/randn", [16]] // Random normal 16-element vector
Returns: tensorArgs: 1 argument
tensor/shape✨ Pure

Get tensor shape as array

ParameterTypeDescription
tensortensorThe tensor
Example
["tensor/shape", "@entity.sensors"] // => [16]
Returns: number[]Args: 1 argument
tensor/get✨ Pure

Get element at index

ParameterTypeDescription
tensortensorThe tensor
indexnumber | number[]Index (single for 1D, array for multi-D)
Example
["tensor/get", "@entity.output", 3] // Get 4th element
Returns: numberArgs: 2 arguments
tensor/slice✨ Pure

Get slice of tensor

ParameterTypeDescription
tensortensorThe tensor
startnumberStart index
endnumberEnd index (exclusive)
Example
["tensor/slice", "@entity.output", 0, 3] // First 3 elements
Returns: tensorArgs: 3 arguments
tensor/reshape✨ Pure

Reshape tensor to new shape (total elements must match)

ParameterTypeDescription
tensortensorThe tensor
shapenumber[]New shape
Example
["tensor/reshape", "@entity.data", [4, 4]] // Reshape to 4x4
Returns: tensorArgs: 2 arguments
tensor/flatten✨ Pure

Flatten tensor to 1D

ParameterTypeDescription
tensortensorThe tensor
Example
["tensor/flatten", "@entity.data"]
Returns: tensorArgs: 1 argument
tensor/add✨ Pure

Element-wise addition

ParameterTypeDescription
atensorFirst tensor
btensor | numberSecond tensor or scalar
Example
["tensor/add", "@entity.a", "@entity.b"]
Returns: tensorArgs: 2 arguments
tensor/sub✨ Pure

Element-wise subtraction

ParameterTypeDescription
atensorFirst tensor
btensor | numberSecond tensor or scalar
Example
["tensor/sub", "@entity.a", "@entity.b"]
Returns: tensorArgs: 2 arguments
tensor/mul✨ Pure

Element-wise multiplication

ParameterTypeDescription
atensorFirst tensor
btensor | numberSecond tensor or scalar
Example
["tensor/mul", "@entity.weights", 0.99] // Decay weights
Returns: tensorArgs: 2 arguments
tensor/div✨ Pure

Element-wise division

ParameterTypeDescription
atensorFirst tensor
btensor | numberSecond tensor or scalar
Example
["tensor/div", "@entity.gradient", "@entity.batchSize"]
Returns: tensorArgs: 2 arguments
tensor/matmul✨ Pure

Matrix multiplication

ParameterTypeDescription
atensorFirst tensor (NxM)
btensorSecond tensor (MxK)
Example
["tensor/matmul", "@entity.input", "@entity.weights"]
Returns: tensorArgs: 2 arguments
tensor/dot✨ Pure

Dot product of two 1D tensors

ParameterTypeDescription
atensorFirst vector
btensorSecond vector
Example
["tensor/dot", "@entity.a", "@entity.b"]
Returns: numberArgs: 2 arguments
tensor/sum✨ Pure

Sum of tensor elements

ParameterTypeDescription
tensortensorThe tensor
dim (opt)numberDimension to reduce
Example
["tensor/sum", "@entity.rewards"] // Total reward
Returns: number | tensorArgs: 1–2 arguments
tensor/mean✨ Pure

Mean of tensor elements

ParameterTypeDescription
tensortensorThe tensor
dim (opt)numberDimension to reduce
Example
["tensor/mean", "@entity.losses"]
Returns: number | tensorArgs: 1–2 arguments
tensor/max✨ Pure

Maximum value in tensor

ParameterTypeDescription
tensortensorThe tensor
dim (opt)numberDimension to reduce
Example
["tensor/max", "@entity.qValues"]
Returns: number | tensorArgs: 1–2 arguments
tensor/min✨ Pure

Minimum value in tensor

ParameterTypeDescription
tensortensorThe tensor
dim (opt)numberDimension to reduce
Example
["tensor/min", "@entity.distances"]
Returns: number | tensorArgs: 1–2 arguments
tensor/argmax✨ Pure

Index of maximum value

ParameterTypeDescription
tensortensorThe tensor
dim (opt)numberDimension to reduce
Example
["tensor/argmax", "@entity.qValues"] // Best action index
Returns: number | tensorArgs: 1–2 arguments
tensor/norm✨ Pure

L2 norm of tensor

ParameterTypeDescription
tensortensorThe tensor
p (opt)numberNorm order (default 2) (default: 2)
Example
["tensor/norm", "@entity.gradient"]
Returns: numberArgs: 1–2 arguments
tensor/allInRange✨ Pure

Check if all elements are within range [min, max]

ParameterTypeDescription
tensortensorThe tensor
range[number, number]Range as [min, max]
Example
["tensor/allInRange", "@payload.input", [-1.0, 1.0]]
Returns: true/falseArgs: 2 arguments
tensor/outOfRangeIndices✨ Pure

Get indices of elements outside range

ParameterTypeDescription
tensortensorThe tensor
range[number, number]Range as [min, max]
Example
["tensor/outOfRangeIndices", "@payload.input", [-1.0, 1.0]]
Returns: number[]Args: 2 arguments
tensor/clamp✨ Pure

Clamp all elements to range [min, max]

ParameterTypeDescription
tensortensorThe tensor
minnumberMinimum value
maxnumberMaximum value
Example
["tensor/clamp", "@entity.output", -10.0, 10.0]
Returns: tensorArgs: 3 arguments
tensor/clampPerDim✨ Pure

Clamp each dimension to its specified range

ParameterTypeDescription
tensortensorThe tensor
rangesobjectPer-dimension ranges { "0": {min, max}, ... }
Example
["tensor/clampPerDim", "@entity.rawOutput", "@entity.outputContract.ranges"]
Returns: tensorArgs: 2 arguments
tensor/outOfRangeDims✨ Pure

Get dimensions that exceed their specified ranges

ParameterTypeDescription
tensortensorThe tensor
rangesobjectPer-dimension ranges { "0": {min, max}, ... }
Example
["tensor/outOfRangeDims", "@entity.rawOutput", "@entity.outputContract.ranges"]
Returns: listArgs: 2 arguments
tensor/toArray✨ Pure

Convert tensor to nested array

ParameterTypeDescription
tensortensorThe tensor
Example
["tensor/toArray", "@entity.output"]
Returns: listArgs: 1 argument
tensor/toList✨ Pure

Convert 1D tensor to flat array

ParameterTypeDescription
tensortensorThe tensor (must be 1D)
Example
["tensor/toList", "@entity.output"]
Returns: number[]Args: 1 argument

🎯Training Operations

Training loops, loss functions, and optimization for neural networks.

19 operators

train/loop⚡ Effect

Execute training loop with constraints

ParameterTypeDescription
modulenn/moduleThe neural network to train
dataarrayTraining data (array of {input, target} or experiences)
configtrain/configTraining configuration with constraints
Example
["train/loop", "@entity.architecture", "@entity.buffer", "@entity.trainingConfig"]
Returns: train/resultArgs: 3 arguments
train/step⚡ Effect

Execute single training step (forward, loss, backward, update)

ParameterTypeDescription
modulenn/moduleThe neural network
inputtensorInput tensor
targettensorTarget tensor
configtrain/configTraining configuration
Example
["train/step", "@entity.architecture", "@batch.input", "@batch.target", "@entity.config"]
Returns: train/stepResultArgs: 4 arguments
train/validate✨ Pure

Validate model on test cases, returns pass/fail metrics

ParameterTypeDescription
modulenn/moduleThe neural network
testCasesarrayArray of {input, expected, tolerance?}
Example
["train/validate", "@entity.architecture", "@entity.validationSet"]
Returns: train/validationResultArgs: 2 arguments
train/checkRegression✨ Pure

Check if new model regresses on required invariants

ParameterTypeDescription
newModulenn/moduleNewly trained network
oldModulenn/modulePrevious network
invariantsarrayTest cases that must not regress
Example
["train/checkRegression", "@payload.newWeights", "@entity.architecture", "@entity.requiredInvariants"]
Returns: train/regressionResultArgs: 3 arguments
train/checkConstraints✨ Pure

Check if network weights satisfy all constraints

ParameterTypeDescription
modulenn/moduleThe neural network
constraintstrain/constraintsConstraint specification
Example
["train/checkConstraints", "@payload.newWeights", "@entity.constraints"]
Returns: train/constraintResultArgs: 2 arguments
train/checkWeightMagnitude✨ Pure

Check if all weights are within magnitude limit

ParameterTypeDescription
modulenn/moduleThe neural network
maxMagnitudenumberMaximum allowed weight magnitude
Example
["train/checkWeightMagnitude", "@entity.architecture", 10.0]
Returns: true/falseArgs: 2 arguments
train/checkForbiddenOutputs✨ Pure

Check if model produces outputs in forbidden regions

ParameterTypeDescription
modulenn/moduleThe neural network
testInputsarrayInputs to test
forbiddenRegionsarrayForbidden output regions
Example
["train/checkForbiddenOutputs", "@entity.architecture", "@entity.testInputs", "@entity.forbiddenOutputRegions"]
Returns: train/forbiddenResultArgs: 3 arguments
train/clipGradients⚡ Effect

Clip gradients to max norm (modifies in place)

ParameterTypeDescription
modulenn/moduleThe neural network
maxNormnumberMaximum gradient norm
Example
["train/clipGradients", "@entity.architecture", 1.0]
Returns: numberArgs: 2 arguments
train/getGradientNorm✨ Pure

Get current gradient norm

ParameterTypeDescription
modulenn/moduleThe neural network
Example
["train/getGradientNorm", "@entity.architecture"]
Returns: numberArgs: 1 argument
train/clipWeights⚡ Effect

Clip weights to max magnitude (modifies in place)

ParameterTypeDescription
modulenn/moduleThe neural network
maxMagnitudenumberMaximum weight magnitude
Example
["train/clipWeights", "@entity.architecture", 10.0]
Returns: nothingArgs: 2 arguments
train/getMaxWeightMagnitude✨ Pure

Get maximum weight magnitude in network

ParameterTypeDescription
modulenn/moduleThe neural network
Example
["train/getMaxWeightMagnitude", "@entity.architecture"]
Returns: numberArgs: 1 argument
train/mse✨ Pure

Mean squared error loss

ParameterTypeDescription
predictedtensorPredicted values
targettensorTarget values
Example
["train/mse", "@entity.output", "@batch.target"]
Returns: numberArgs: 2 arguments
train/crossEntropy✨ Pure

Cross-entropy loss for classification

ParameterTypeDescription
logitstensorRaw model outputs (logits)
labelstensorTarget class labels
Example
["train/crossEntropy", "@entity.logits", "@batch.labels"]
Returns: numberArgs: 2 arguments
train/huber✨ Pure

Huber loss (smooth L1, robust to outliers)

ParameterTypeDescription
predictedtensorPredicted values
targettensorTarget values
delta (opt)numberThreshold for quadratic vs linear (default: 1)
Example
["train/huber", "@entity.qValues", "@batch.targets", 1.0]
Returns: numberArgs: 2–3 arguments
train/sgd⚡ Effect

Stochastic gradient descent optimizer step

ParameterTypeDescription
modulenn/moduleThe neural network
lrnumberLearning rate
momentum (opt)numberMomentum factor (default: 0)
Example
["train/sgd", "@entity.architecture", 0.01, 0.9]
Returns: nothingArgs: 2–3 arguments
train/adam⚡ Effect

Adam optimizer step

ParameterTypeDescription
modulenn/moduleThe neural network
lrnumberLearning rate
beta1 (opt)numberFirst moment decay (default: 0.9)
beta2 (opt)numberSecond moment decay (default: 0.999)
Example
["train/adam", "@entity.architecture", 0.001]
Returns: nothingArgs: 2–4 arguments
train/sampleBatch✨ Pure

Sample random batch from experience buffer

ParameterTypeDescription
bufferarrayExperience buffer
batchSizenumberNumber of samples
Example
["train/sampleBatch", "@entity.experienceBuffer", 32]
Returns: listArgs: 2 arguments
train/computeReturns✨ Pure

Compute discounted returns from rewards

ParameterTypeDescription
rewardsarrayArray of rewards
gammanumberDiscount factor
Example
["train/computeReturns", "@episode.rewards", 0.99]
Returns: tensorArgs: 2 arguments
train/computeAdvantages✨ Pure

Compute GAE advantages for policy gradient

ParameterTypeDescription
rewardsarrayArray of rewards
valuestensorValue estimates
configobjectConfig with gamma, lambda
Example
["train/computeAdvantages", "@episode.rewards", "@episode.values", { "gamma": 0.99, "lambda": 0.95 }]
Returns: tensorArgs: 3 arguments

🎲Probabilistic Programming

Distribution sampling, Bayesian inference via rejection sampling, and statistical summaries.

16 operators

prob/seed⚡ Effect

Set seeded PRNG for deterministic probabilistic sampling

ParameterTypeDescription
nnumberSeed value (integer)
Example
["prob/seed", 42]
Returns: nothingArgs: 1 argument
prob/flip✨ Pure

Bernoulli trial: returns true with probability p

ParameterTypeDescription
pnumberProbability of true (0 to 1)
Example
["prob/flip", 0.5] // => true or false with equal probability
Returns: true/falseArgs: 1 argument
prob/gaussian✨ Pure

Sample from a Gaussian (normal) distribution

ParameterTypeDescription
munumberMean
sigmanumberStandard deviation
Example
["prob/gaussian", 0, 1] // => standard normal sample
Returns: numberArgs: 2 arguments
prob/uniform✨ Pure

Sample from a uniform distribution [lo, hi)

ParameterTypeDescription
lonumberLower bound (inclusive)
hinumberUpper bound (exclusive)
Example
["prob/uniform", 0, 10] // => number in [0, 10)
Returns: numberArgs: 2 arguments
prob/beta✨ Pure

Sample from a Beta(alpha, beta) distribution

ParameterTypeDescription
alphanumberAlpha shape parameter (> 0)
betanumberBeta shape parameter (> 0)
Example
["prob/beta", 2, 5] // => number in [0, 1], mean ~ 0.286
Returns: numberArgs: 2 arguments
prob/categorical✨ Pure

Weighted random selection from items

ParameterTypeDescription
itemsarrayArray of items to choose from
weightsnumber[]Array of weights (same length as items)
Example
["prob/categorical", ["a", "b", "c"], [1, 2, 1]] // => "b" most likely
Returns: any valueArgs: 2 arguments
prob/poisson✨ Pure

Sample from a Poisson distribution

ParameterTypeDescription
lambdanumberRate parameter (> 0)
Example
["prob/poisson", 4] // => non-negative integer, mean ~ 4
Returns: numberArgs: 1 argument
prob/condition⚡ Effect

Mark current sample as rejected if predicate is false

ParameterTypeDescription
predicatebooleanCondition that must hold
Example
["prob/condition", [">", "@entity.x", 0]]
Returns: nothingArgs: 1 argument
prob/sample✨ Pure

Evaluate an expression n times and collect results

ParameterTypeDescription
nnumberNumber of samples
exprSExprExpression to evaluate (lazy)
Example
["prob/sample", 1000, ["prob/flip", 0.5]] // => array of booleans
Returns: listArgs: 2 arguments
prob/posterior✨ Pure

Rejection sampling: returns accepted query values

ParameterTypeDescription
modelSExprModel expression (lazy, may call set/condition)
evidenceSExprEvidence expression (lazy, boolean)
querySExprQuery expression (lazy, value to collect)
nnumberNumber of samples to attempt
Example
["prob/posterior", model, evidence, query, 5000]
Returns: listArgs: 4 arguments
prob/infer✨ Pure

Like posterior but returns {mean, variance, samples, acceptRate}

ParameterTypeDescription
modelSExprModel expression (lazy)
evidenceSExprEvidence expression (lazy, boolean)
querySExprQuery expression (lazy)
nnumberNumber of samples to attempt
Example
["prob/infer", model, evidence, query, 5000]
Returns: objectArgs: 4 arguments
prob/expected-value✨ Pure

Mean of numeric samples

ParameterTypeDescription
samplesnumber[]Array of numeric samples
Example
["prob/expected-value", [2, 4, 6, 8]] // => 5
Returns: numberArgs: 1 argument
prob/variance✨ Pure

Population variance of numeric samples

ParameterTypeDescription
samplesnumber[]Array of numeric samples
Example
["prob/variance", [2, 4, 4, 4, 5, 5, 7, 9]] // => 4
Returns: numberArgs: 1 argument
prob/histogram✨ Pure

Bin numeric samples into a histogram

ParameterTypeDescription
samplesnumber[]Array of numeric samples
binsnumberNumber of bins
Example
["prob/histogram", [1, 2, 3, 4, 5], 2] // => {binEdges, counts}
Returns: objectArgs: 2 arguments
prob/percentile✨ Pure

Get the p-th percentile (0-100) from samples

ParameterTypeDescription
samplesnumber[]Array of numeric samples
pnumberPercentile (0 to 100)
Example
["prob/percentile", [1, 2, 3, 4, 5], 50] // => 3
Returns: numberArgs: 2 arguments
prob/credible-interval✨ Pure

Compute symmetric credible interval from samples

ParameterTypeDescription
samplesnumber[]Array of numeric samples
alphanumberSignificance level (e.g., 0.05 for 95% interval)
Example
["prob/credible-interval", samples, 0.05] // => [lo, hi]
Returns: listArgs: 2 arguments