Advanced Weight Expressions Â
Helix supports sophisticated mathematical expressions for calculating path weights. By combining mathematical functions with property contexts, you can model complex real-world routing scenarios with exponential decay, multi-factor scoring, conditional logic, and more.All mathematical functions available in Helix can be used in weight expressions. See the Mathematical Functions reference for the complete list.
Available Mathematical Functions
Arithmetic Operations
- ADD(a, b) - Addition
- SUB(a, b) - Subtraction
- MUL(a, b) - Multiplication
- DIV(a, b) - Division
- MOD(a, b) - Modulo (remainder)
Power & Exponential
- POW(base, exponent) - Power
- SQRT(x) - Square root
- EXP(x) - e^x (exponential)
- LN(x) - Natural logarithm
- LOG(x, base) - Logarithm with custom base
Rounding Functions
- CEIL(x) - Round up
- FLOOR(x) - Round down
- ROUND(x) - Round to nearest
- ABS(x) - Absolute value
Trigonometric Functions
- SIN(x) - Sine
- COS(x) - Cosine
- TAN(x) - Tangent
Constants
- PI() - π (3.14159…)
Example 1: Exponential time decay
POW(0.95, DIV(days_since_update, 30))creates exponential decay- At 0 days: multiplier = 1.0 (no penalty)
- At 30 days: multiplier = 0.95 (5% increase)
- At 60 days: multiplier = 0.90 (10% increase)
- At 90 days: multiplier = 0.86 (14% increase)
Example 2: Multi-factor composite scoring
- 40% latency: Direct contribution (lower is better)
- 30% reciprocal bandwidth: 1/bandwidth (lower bandwidth → higher cost)
- 30% unreliability: (1 - reliability) (less reliable → higher cost)
Example 3: Conditional weights with thresholds
- Below threshold: No penalty (multiplier = 1)
- Above threshold: Progressive penalty based on excess
- Uses CEIL to create step-function penalties
- Every 10% over threshold adds 0.5x multiplier
Complex Expression Patterns
Vector Distance with Property Weighting
Logarithmic Scaling for Large Values
Periodic Patterns with Trigonometry
Quantized Weights
Performance Considerations
Expression Complexity Impact
| Complexity | Operations | Performance Impact |
|---|---|---|
| Simple | Single property | Minimal (1% overhead) |
| Moderate | 2-5 operations | Low (1-5% overhead) |
| Complex | 6-15 operations | Moderate (5-15% overhead) |
| Very Complex | 15+ operations | Higher (15-30% overhead) |
Optimization Tips
-
Pre-calculate when possible: Store derived values as properties
-
Simplify expressions: Combine constants
-
Avoid expensive operations in hot paths:
- Trigonometric functions (SIN, COS, TAN) are slower
- Multiple POW operations add up
- Consider lookup tables for complex functions
- Profile your queries: Test with realistic data volumes