Skip to content

Formula language

A parameter can be computed from others, and the amount of an exchange can be a formula of parameters: 1 / yield with yield at 0.8 gives 1.25 kg of flour. Formulas read from SimaPro, EcoSpold 2, openLCA or a Brightway workbook are translated into this one language when the database loads, so every formula VoLCA shows or keeps reads the same way.

This page is generated from the engine’s own table of the language: what is listed here is what the engine reads.

  • A number takes a point before its decimals and may take an exponent: 0.5, 1.2e-3.
  • Arguments are parted by a semicolon or a comma: max(a; b) and max(a, b) are one formula.
  • A name starts with a letter or an underscore and goes on with letters, digits and underscores. It is a parameter, or a named line of the process, whatever its case: Yield and yield are one name.
  • A name followed by an opening parenthesis calls a function; a function the language does not have is refused by its name.
  • A comparison gives 1 when it holds and 0 when it does not; a condition holds when it is not 0.
  • There is no comment and no word operator: and, or and not are functions, and pi or e is a name like any other.

From loosest to tightest: in a + b * c, the product is taken first. A function called by name binds tighter than any of them.

BindingOperators
1a = b a <> b a < b a <= b a > b a >= b
2a + b a - b
3a * b a / b
4-x
5a ^ b
OperatorMeaningExampleGives
-xx with its sign changed-(2 - 5)3
a + ba plus b2 + 35
a - ba minus b5 - 32
a * ba times b2 * 36
a / ba divided by b6 / 41.5
a ^ ba raised to the power b: 2 ^ 3 ^ 2 is 2 ^ 9, -2 ^ 2 is -42 ^ 38
a = b1 when a equals b, 0 otherwise2 = 21
a <> b1 when a differs from b, 0 otherwise2 <> 20
a < b1 when a is below b, 0 otherwise1 < 21
a <= b1 when a is not above b, 0 otherwise2 <= 21
a > b1 when a is above b, 0 otherwise1 > 20
a >= b1 when a is not below b, 0 otherwise1 >= 20

The language has 35 functions.

FunctionMeaningExampleGives
not(x)1 when x is 0, 0 otherwisenot(2 > 3)1
abs(x)the absolute value of xabs(-3)3
sqrt(x)the square root of xsqrt(16)4
sqr(x)x times xsqr(3)9
exp(x)e raised to the power xexp(0)1
ln(x)the natural logarithm of xln(1)0
log10(x)the decimal logarithm of xlog10(1000)3
trunc(x)x without its fractional parttrunc(-2.7)-2
frac(x)the fractional part of x, with the sign of xfrac(-2.75)-0.75
round(x)x rounded to the nearest whole number, a half upward: round(-2.5) is -2round(2.5)3
roundeven(x)x rounded to the nearest whole number, a half to the even oneroundeven(2.5)2
ceil(x)the smallest whole number not below xceil(1.2)2
floor(x)the largest whole number not above xfloor(1.8)1
sin(x)the sine of x, in radianssin(0)0
cos(x)the cosine of x, in radianscos(0)1
tan(x)the tangent of x, in radianstan(0)0
cotan(x)the cotangent of x, in radians: 1 / tan(x)cotan(1)0.6420926159343306
asin(x)the angle whose sine is x, in radiansasin(1)1.5707963267948966
acos(x)the angle whose cosine is x, in radiansacos(1)0
atan(x)the angle whose tangent is x, in radiansatan(0)0
sinh(x)the hyperbolic sine of xsinh(0)0
cosh(x)the hyperbolic cosine of xcosh(0)1
tanh(x)the hyperbolic tangent of xtanh(0)0
log(x; base)the logarithm of x in the given base; log(x) alone is ln(x)log(8; 2)3
ipower(x; n)x raised to the power n, n without its fractional partipower(2; 3.7)8
xor(a; b)1 when exactly one of a and b is not 0, 0 otherwisexor(1; 0)1
div(a; b)a and b rounded half upward, then divided, without the fractional partdiv(7.6; 2)4
mod(a; b)the remainder of a divided by b, with the sign of amod(-7; 3)-1
min(a; b; ...)the smallest of its argumentsmin(4; 2; 8)2
max(a; b; ...)the largest of its argumentsmax(1; 7; 3)7
sum(a; b; ...)the sum of its argumentssum(1; 2; 3)6
average(a; b; ...)the mean of its argumentsaverage(1; 2; 3)2
and(a; b; ...)1 when none of its arguments is 0, 0 otherwiseand(1; 2 > 1)1
or(a; b; ...)1 when any of its arguments is not 0, 0 otherwiseor(0; 2 < 1)0
if(condition; then; else)then when the condition is not 0, else otherwise, 0 when left out; only the value taken is computedif(2 > 1; 10; 20)10

The engine checks a formula where it would be written, at the database’s own values, without saving anything:

Terminal window
POST /api/v1/db/my-copy/formula-check
{"formula": "1 / yield", "process": "{process_id}", "exchange": 3}
{"value": 1.25, "reads": ["yield"], "warnings": [], "problem": null}

A formula that gives nothing comes back with its problem instead: a name with no value, two parameters that need each other’s values, a formula that does not read. With exchange, a line’s position as the activity’s exchanges list it (the first line is 0), the formula stands in for that line’s own, and a parameter whose unit does not convert to the line’s is warned. The same check is the MCP tool check_formula and check_formula() in pyvolca; the language itself is GET /api/v1/formula-language.