Mathematical Constants
HelixQL provides built-in mathematical constants PI and E for use in calculations. These constants are provided as functions that return their respective values with high precision.
Available Constants
PI - Pi Constant
PI () // Returns Ο β 3.14159265358979323846
Returns the mathematical constant Ο (pi), the ratio of a circleβs circumference to its diameter.
E - Eulerβs Number
E () // Returns e β 2.71828182845904523536
Returns the mathematical constant e (Eulerβs number), the base of natural logarithms.
When using the SDKs or curling the endpoint, the query name must match what is defined in the queries.hx file exactly.
Example 1: Circle calculations with PI
Calculate circle properties using the PI constant:
QUERY CalculateCircleProperties () =>
circles <- N :: Circle
:: {
radius ,
circumference : MUL ( MUL ( 2.0 , PI ()), _ :: { radius }),
area : MUL ( PI (), POW ( _ :: { radius }, 2.0 ))
}
RETURN circles
QUERY CreateCircle ( radius : F64 ) =>
circle <- AddN < Circle >({ radius : radius })
RETURN circle
Hereβs how to run the query using the SDKs or curl
Python
Rust
Go
TypeScript
Curl
from helix.client import Client
client = Client( local = True , port = 6969 )
# Create circles with different radii
radii = [ 1.0 , 5.0 , 10.0 , 15.0 , 20.0 ]
for radius in radii:
client.query( "CreateCircle" , { "radius" : radius})
result = client.query( "CalculateCircleProperties" , {})
print ( "Circle properties:" , result)
See all 12 lines
Example 2: Exponential growth with E
Model exponential growth and decay using Eulerβs number:
QUERY CalculateExponentialGrowth ( time : F64 , rate : F64 ) =>
populations <- N :: Population
:: {
initial_size ,
time_elapsed : time ,
final_size : MUL ( _ :: { initial_size }, POW ( E (), MUL ( rate , time )))
}
RETURN populations
QUERY CreatePopulation ( initial_size : F64 ) =>
population <- AddN < Population >({ initial_size : initial_size })
RETURN population
Hereβs how to run the query using the SDKs or curl
Python
Rust
Go
TypeScript
Curl
from helix.client import Client
client = Client( local = True , port = 6969 )
# Create populations with different initial sizes
initial_sizes = [ 100.0 , 500.0 , 1000.0 , 5000.0 ]
for size in initial_sizes:
client.query( "CreatePopulation" , { "initial_size" : size})
# Calculate growth after 10 time units with 5% growth rate
result = client.query( "CalculateExponentialGrowth" , {
"time" : 10.0 ,
"rate" : 0.05
})
print ( "Population growth:" , result)
See all 17 lines
Common Use Cases
Degree-Radian Conversion
Use PI for converting between degrees and radians:
// Degrees to radians
radians = MUL ( degrees , DIV ( PI (), 180.0 ))
// Radians to degrees
degrees = MUL ( radians , DIV ( 180.0 , PI ()))
Circular Motion
Calculate properties of circular motion:
QUERY CalculateAngularVelocity () =>
objects <- N :: RotatingObject
:: {
rpm ,
angular_velocity : MUL ( MUL ( 2.0 , PI ()), DIV ( _ :: { rpm }, 60.0 ))
}
RETURN objects
Compound Interest
Use E for continuous compound interest calculations:
QUERY CalculateCompoundInterest ( principal : F64 , rate : F64 , time : F64 ) =>
amount <- MUL ( principal , POW ( E (), MUL ( rate , time )))
RETURN amount
Natural Decay
Model radioactive decay or other natural decay processes:
QUERY CalculateDecay () =>
samples <- N :: Sample
:: {
initial_amount ,
half_life ,
time_elapsed ,
remaining : MUL (
_ :: { initial_amount },
POW ( E (), MUL ( DIV ( LN ( 0.5 ), _ :: { half_life }), _ :: { time_elapsed }))
)
}
RETURN samples
Constants are particularly useful when combined with trigonometric functions (SIN, COS, TAN) and exponential functions (EXP, LN).
Precision
Both PI() and E() return high-precision values suitable for scientific and engineering calculations:
PI() returns Ο to approximately 20 decimal places
E() returns e to approximately 20 decimal places
The constants are implemented as functions rather than literals to maintain consistency with HelixQLβs function-based syntax.
Constants are often used in complex mathematical formulas:
// Gaussian distribution
QUERY CalculateGaussian ( x : F64 , mean : F64 , std_dev : F64 ) =>
coefficient <- DIV ( 1.0 , MUL ( std_dev , SQRT ( MUL ( 2.0 , PI ()))))
exponent <- DIV ( POW ( SUB ( x , mean ), 2.0 ), MUL ( 2.0 , POW ( std_dev , 2.0 )))
probability <- MUL ( coefficient , POW ( E (), MUL ( - 1.0 , exponent )))
RETURN probability
// Euler's formula: e^(iΞΈ) = cos(ΞΈ) + i*sin(ΞΈ)
QUERY EulerFormula ( theta : F64 ) =>
result <- N :: ComplexNumber
:: {
real : COS ( theta ),
imaginary : SIN ( theta ),
magnitude : POW ( E (), 0.0 ) // Always 1 for pure imaginary exponent
}
RETURN result
Trigonometric Functions SIN, COS, TAN, ASIN, ACOS, ATAN, ATAN2
Unary Math Functions SQRT, ABS, LN, LOG10, EXP, CEIL, FLOOR, ROUND
Arithmetic Functions ADD, SUB, MUL, DIV, POW, MOD
Math Overview Overview of all math functions