Skip to main content

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

Here’s how to run the query using the SDKs or curl
How it works:
  • 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

Here’s how to run the query using the SDKs or curl
Weight breakdown:
  • 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

Here’s how to run the query using the SDKs or curl
How conditional weighting works:
  • 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

Optimization Tips

  1. Pre-calculate when possible: Store derived values as properties
  2. Simplify expressions: Combine constants
  3. Avoid expensive operations in hot paths:
    • Trigonometric functions (SIN, COS, TAN) are slower
    • Multiple POW operations add up
    • Consider lookup tables for complex functions
  4. Profile your queries: Test with realistic data volumes

Common Patterns Library

Time-based Decay

Multi-factor Scoring

Threshold-based Penalties

Normalization

Custom Weights

Property contexts and basic weight patterns

Mathematical Functions

Complete reference of all math functions

ShortestPathDijkstras

Dijkstra’s algorithm documentation

Overview

Compare all shortest path algorithms