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.
Operators
Section titled “Operators”From loosest to tightest: in a + b * c, the product is taken first. A function
called by name binds tighter than any of them.
| Binding | Operators |
|---|---|
| 1 | a = b a <> b a < b a <= b a > b a >= b |
| 2 | a + b a - b |
| 3 | a * b a / b |
| 4 | -x |
| 5 | a ^ b |
| Operator | Meaning | Example | Gives |
|---|---|---|---|
-x | x with its sign changed | -(2 - 5) | 3 |
a + b | a plus b | 2 + 3 | 5 |
a - b | a minus b | 5 - 3 | 2 |
a * b | a times b | 2 * 3 | 6 |
a / b | a divided by b | 6 / 4 | 1.5 |
a ^ b | a raised to the power b: 2 ^ 3 ^ 2 is 2 ^ 9, -2 ^ 2 is -4 | 2 ^ 3 | 8 |
a = b | 1 when a equals b, 0 otherwise | 2 = 2 | 1 |
a <> b | 1 when a differs from b, 0 otherwise | 2 <> 2 | 0 |
a < b | 1 when a is below b, 0 otherwise | 1 < 2 | 1 |
a <= b | 1 when a is not above b, 0 otherwise | 2 <= 2 | 1 |
a > b | 1 when a is above b, 0 otherwise | 1 > 2 | 0 |
a >= b | 1 when a is not below b, 0 otherwise | 1 >= 2 | 0 |
Functions
Section titled “Functions”The language has 35 functions.
| Function | Meaning | Example | Gives |
|---|---|---|---|
not(x) | 1 when x is 0, 0 otherwise | not(2 > 3) | 1 |
abs(x) | the absolute value of x | abs(-3) | 3 |
sqrt(x) | the square root of x | sqrt(16) | 4 |
sqr(x) | x times x | sqr(3) | 9 |
exp(x) | e raised to the power x | exp(0) | 1 |
ln(x) | the natural logarithm of x | ln(1) | 0 |
log10(x) | the decimal logarithm of x | log10(1000) | 3 |
trunc(x) | x without its fractional part | trunc(-2.7) | -2 |
frac(x) | the fractional part of x, with the sign of x | frac(-2.75) | -0.75 |
round(x) | x rounded to the nearest whole number, a half upward: round(-2.5) is -2 | round(2.5) | 3 |
roundeven(x) | x rounded to the nearest whole number, a half to the even one | roundeven(2.5) | 2 |
ceil(x) | the smallest whole number not below x | ceil(1.2) | 2 |
floor(x) | the largest whole number not above x | floor(1.8) | 1 |
sin(x) | the sine of x, in radians | sin(0) | 0 |
cos(x) | the cosine of x, in radians | cos(0) | 1 |
tan(x) | the tangent of x, in radians | tan(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 radians | asin(1) | 1.5707963267948966 |
acos(x) | the angle whose cosine is x, in radians | acos(1) | 0 |
atan(x) | the angle whose tangent is x, in radians | atan(0) | 0 |
sinh(x) | the hyperbolic sine of x | sinh(0) | 0 |
cosh(x) | the hyperbolic cosine of x | cosh(0) | 1 |
tanh(x) | the hyperbolic tangent of x | tanh(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 part | ipower(2; 3.7) | 8 |
xor(a; b) | 1 when exactly one of a and b is not 0, 0 otherwise | xor(1; 0) | 1 |
div(a; b) | a and b rounded half upward, then divided, without the fractional part | div(7.6; 2) | 4 |
mod(a; b) | the remainder of a divided by b, with the sign of a | mod(-7; 3) | -1 |
min(a; b; ...) | the smallest of its arguments | min(4; 2; 8) | 2 |
max(a; b; ...) | the largest of its arguments | max(1; 7; 3) | 7 |
sum(a; b; ...) | the sum of its arguments | sum(1; 2; 3) | 6 |
average(a; b; ...) | the mean of its arguments | average(1; 2; 3) | 2 |
and(a; b; ...) | 1 when none of its arguments is 0, 0 otherwise | and(1; 2 > 1) | 1 |
or(a; b; ...) | 1 when any of its arguments is not 0, 0 otherwise | or(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 computed | if(2 > 1; 10; 20) | 10 |
Trying a formula
Section titled “Trying a formula”The engine checks a formula where it would be written, at the database’s own values, without saving anything:
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.