Skip to content

Numerical Calculations

Numerical features can be calculated using the imply keyword within a behavior block. When using the imply keyword, it always needs to be followed by a feature reference (e.g. a path) and subsequently an equal sign (=). Hence, no greater-than, lower-than, and unequal is allowed here.

In the following example, the value for the numerical feature weight is determined by adding the static weight of the frame (10,000 grams) to the weights of both wheels and the weights of the bags, which vary based on their capacity.

behavior {
    imply weight = 10000 + rearWheel.weight + frontWheel.weight 
                   + carrier.bag.capacity.weight
}

Only numerical features, attributes, and constants can be used within the formulas. The following standard numerical operations are supported.

Operation Syntax Comment
addition +
subtraction -
multiplication *
division / be aware of downward rounding to integer and division by zero
power ^

Furthermore, the following advanced mathematical functions are supported.

Function Description Example
sum(x+) The sum of all x sum(wheels.weight, engine.weight)
count(x+) The amount of present values in x count(left.items, middle.items, right.items)
min(x+) The minimum of x min(options.price)
max(x+) The maximum of x max(options.price)
pow(x, y) The power x^y pow(2, 8) = 256
sqrt(x) The square root of x sqrt(9) = 3
ceil(x) The result of up-rounding x ceil(2.5) = 3
floor(x) The result of down-rounding x floor(2.5) = 2
round(x) The result of rounding x round(0.45) = 0, round(0.5) = 1
mod(x, y) The remainder of x / y mod(5, 3) = 2
log(x, y) The logarithm of x to the base y log(16, 2) = 4
ln(x, y) The natural logarithm of x (basis e) ln(2.71828) = 1
sin(x) The sine of x from degrees sin(90) = 1
cos(x) The cosine of x from degrees cos(0) = 1
tan(x) The tangent of x from degrees tan(45) = 1
asin(x) The inverse sine of x to degrees asin(1) = 90
acos(x) The inverse cosine of x to degrees acos(1) = 0
atan(x) The inverse tangent of x to degrees atan(1) = 45
sinh(x) The hyperbolic sine of x sinh(1) = 67.3341
cosh(x) The hyperbolic cosine of x cosh(1) = 88.4120
tanh(x) The hyperbolic tangent of x tanh(1) = 43.6361

Note: + means, that the function takes any number >= 1 of arguments. All functions work with both whole and floating point numbers.