Mathematical Functions in HelixQL
HelixQL provides a comprehensive set of mathematical functions for performing calculations, transformations, and aggregations within your queries. These functions can be used anywhere expressions are allowed, including custom weight calculations for shortest paths, property transformations, and conditional logic.Function Categories
Arithmetic
Basic math operations: ADD, SUB, MUL, DIV, POW, MOD
Unary Math
Single-argument functions: ABS, SQRT, LN, LOG, EXP, CEIL, FLOOR, ROUND
Trigonometry
Trig functions: SIN, COS, TAN, ASIN, ACOS, ATAN, ATAN2
Constants
Mathematical constants: PI, E
Aggregates
Collection operations: MIN, MAX, SUM, AVG, COUNT
Common Use Cases
1. Custom Weight Calculations
Use math functions to calculate dynamic weights for shortest path algorithms:2. Property Transformations
Transform property values during queries:3. Distance Calculations
Calculate distances using mathematical formulas:4. Aggregation and Statistics
Perform statistical calculations on collections:Function Composition
Math functions can be nested and composed to create complex expressions:Type Handling
Mathematical functions in HelixQL handle numeric types appropriately:- Integer types: I8, I16, I32, I64, U8, U16, U32, U64
- Floating-point types: F32, F64
Functions that produce fractional results (like DIV, SQRT) will return floating-point values. Ensure your type annotations match the expected output types.
Performance Considerations
- Simple operations (ADD, SUB, MUL) are highly optimized and add negligible overhead
- Complex functions (trigonometry, logarithms) have more computational cost
- Aggregate functions process entire collections and scale with collection size
- Use math functions in weight calculations for shortest paths to enable dynamic routing