Math, Comparison, Aggregation & Iteration
All numeric, logical, aggregation, ordering, generation, and higher-order operations available in Rayfall. Operations marked FN_ATOMIC auto-map over vectors element-wise.
Arithmetic
Arithmetic operations work on scalars and auto-map element-wise over vectors. Numeric typed-vector calls and query expressions lower to morsel-based DAG kernels where available.
(+ a b) — atomic
Addition. Works on integers, floats, dates, and times.
(- a b) — atomic
Subtraction.
(* a b) — atomic
Multiplication.
(/ a b) — atomic
Division. Always returns f64, even for integer arguments. Use div for
integer (floor) division.
(% a b) — atomic
Modulo (remainder).
(neg x) — atomic
Negate a number.
(round x) — atomic
Round to nearest integer.
(floor x) — atomic
Round down to nearest integer.
(pow x y) — atomic
Power. Always returns f64. Vector and query expressions lower to the DAG
executor for morsel-based execution; null in either operand yields 0Nf.
(ceil x) — atomic
Round up to nearest integer.
(abs x) — atomic
Absolute value.
(sqrt x) — atomic
Square root. Always returns f64; negative inputs return 0Nf.
(log x) — atomic
Natural logarithm. Always returns f64; non-positive inputs return 0Nf.
(exp x) — atomic
Exponential, e^x. Always returns f64.
(sin x) / (cos x) / (tan x) — atomic
Trigonometric functions in radians. Always return f64.
(asin x) / (acos x) / (atan x) — atomic
Inverse trigonometric functions in radians. asin and acos return 0Nf for values outside [-1, 1].
(reciprocal x) — atomic
Reciprocal, 1/x. Always returns f64; zero returns 0Nf.
(signum x) — atomic
Return the sign as i64: -1, 0, or 1. Null input stays null.
The direct numeric unary functions accept BOOL, U8, I16, I32, I64, and F64 inputs. They do not treat temporal encodings as numbers.
Comparison
All comparison operations are atomic and return boolean values (or boolean vectors).
(== a b) — atomic
Equal. Works on all types including strings and symbols.
(!= a b) — atomic
Not equal.
(< a b) — atomic
Less than.
(<= a b) — atomic
Less than or equal.
(> a b) — atomic
Greater than.
(>= a b) — atomic
Greater than or equal.
(within vec [lo hi])
Check if each element of a vector is within a range (inclusive). The second argument is a 2-element vector [lo hi].
Logic
(and a b) — atomic
Logical AND. Works on booleans and boolean vectors.
(or a b) — atomic
Logical OR.
(not x) — atomic
Logical NOT. Flips boolean values.
Aggregation
Aggregation functions reduce a vector to a single scalar. They carry the FN_AGGR flag and are recognized by the select/update query planner for group-by operations.
(sum x) — aggregate
Sum of all elements.
(prod x) — aggregate
Product of all non-null numeric elements.
(all x) — aggregate
Returns true when every non-null numeric element is truthy. Empty and all-null inputs return true.
(any x) — aggregate
Returns true when at least one non-null numeric element is truthy. Empty and all-null inputs return false.
(count x) — aggregate
Number of elements. Counts total vector length, including nulls.
(avg x) — aggregate
Arithmetic mean.
(min x) — aggregate
Minimum value.
(max x) — aggregate
Maximum value.
(med x) — aggregate
Median value.
(dev x) — aggregate
Population standard deviation.
(stddev x) — aggregate
Sample standard deviation.
(stddev_pop x) / (dev_pop x) — aggregate
Population standard deviation.
(var x) / (var_pop x) — aggregate
Sample and population variance.
(pearson_corr x y) — aggregate
Pearson correlation over paired non-null numeric inputs.
(cov x y) / (scov x y) — aggregate
Population and sample covariance over paired non-null numeric inputs.
(wsum weights values) / (wavg weights values) — aggregate
Weighted sum and weighted average over paired non-null inputs. wavg returns null when there are no valid pairs or the total weight is zero.
Unary numeric reducers skip nulls where applicable. Binary reducers skip a row when either input is null. Inside select/by:, aggregate reducers lower to morsel-based DAG paths that can run in parallel and poll for cancellation.
(first x) — aggregate
First element of a vector.
(last x) — aggregate
Last element of a vector.
(distinct x) — aggregate
Unique elements of a vector.
Ordering
Sorting and ranking operations for vectors and tables.
(asc x)
Sort a vector in ascending order.
(desc x)
Sort a vector in descending order.
(iasc x)
Return indices that would sort the vector ascending (grade up).
(idesc x)
Return indices that would sort the vector descending (grade down).
(xasc table col)
Sort a table ascending by the named column.
(xdesc table col)
Sort a table descending by the named column.
(xrank n x)
Assign each element to one of n equal-sized buckets (quantile rank).
Generation
Functions for creating, reshaping, and searching vectors.
(til n)
Generate integers from 0 to n-1.
(take x n)
Take the first n elements from a vector, or repeat/cycle x to length n.
(reverse x)
Reverse a vector.
(where x)
Return indices where the boolean vector is true.
(find x val)
Find the index of the first occurrence of val in vector x.
(xbar x n)
Round each element down to the nearest multiple of n (bucketing).
Higher-order Functions
Functions that take other functions as arguments for flexible iteration patterns.
(map f x)
Apply function f to each element of x. Returns a list of results.
(fold f init x)
Left fold. Accumulate over x starting from init using binary function f.
(scan f x)
Running fold (prefix scan). Returns a vector of intermediate accumulation results.
For common time-series scans, prefer the built-in DAG forms. They avoid per-row function calls, run through morsel-based kernels, and can be used directly inside select projections:
(sums [1 2 3 4]) ; [1 3 6 10]
(prds [1 2 3 4]) ; [1 2 6 24]
(avgs [2 4 6]) ; [2.0 3.0 4.0]
(mins [3 1 2]) ; [3 1 1]
(maxs [3 1 2]) ; [3 3 3]
(fills (as 'I64 (list 0N 2 0N))) ; [0Nl 2 2]
(fills (table [t value]
(list [1 2 3] (as 'I64 (list 10 0N 30))))) ; fills each column
(differ [1 1 2 2]) ; [true false true false]
(msum 3 [1 2 3 4]) ; [1 3 6 9]
(mavg 3 [1 2 3 4]) ; [1.0 1.5 2.0 3.0]
(mmin 3 [3 2 4 1]) ; [3 2 2 1]
(mmax 3 [3 2 4 1]) ; [3 3 4 4]
(mcount 3 [1 2 3 4]) ; [1 2 3 3]
(mvar 2 [1 3 5]) ; [0.0 1.0 1.0]
(mdev 2 [1 3 5]) ; [0.0 1.0 1.0]
The moving forms take a positive integer window first. Constant windows inside query projections lower to DAG operations; dynamic windows still evaluate as ordinary function calls.
(apply f ...args)
Apply function f to the given arguments.
(filter vec mask)
Keep elements of vec where the boolean mask is true.
(pmap f x)
Parallel map. Like map but distributes work across threads for large inputs.
Quick Reference Table
| Category | Functions |
|---|---|
| Arithmetic | + - * / % div neg round floor ceil abs sqrt log exp sin asin cos acos tan atan reciprocal signum pow |
| Comparison | == != < <= > >= within |
| Logic | and or not |
| Aggregation | sum prod all any count avg min max med dev stddev var pearson_corr cov scov wsum wavg first last distinct |
| Ordering | asc desc iasc idesc xasc xdesc xrank |
| Generation | til take reverse where find xbar |
| Higher-order | map fold scan apply filter pmap |
Auto-mapping
Arithmetic, comparison, and logic functions automatically map over vectors element-wise. You do not need explicit map calls for these — (+ [1 2 3] 10) works directly.