Formula Syntax and Supported Math Functions
*PACKAGE NOTE: Formula authoring is available to customers who subscribe to the Tempo Digital, Tempo Core, or Tempo Pro package as part of their Tempo Manufacturing Cloud system. Table Formula authoring and some operator categories, such as Constants and Parameters, require Tempo Core or Tempo Pro.
Use formulas to calculate values from inputs, process actions, parameters, constants, tables, and special values inside a procedure. A formula can contain numbers, reference tokens, arithmetic operators, parentheses, and supported math functions.
This article is composed of the following topics:
- Open a formula action
- Structure formula syntax
- Review supported reference formats
- Review supported math functions
- Review additional Math.js function references
Before you begin, make sure you can edit the target procedure template and that the step already includes the inputs, actions, parameters, constants, or tables you want to reference.
- The safest way to build a formula is to insert references from the operator picker instead of typing token names manually.
- Formula reference categories are lowercase inside the token, for example
{input.actual_weight}and{action.yield_calc}. - Special values use the
{special...}token format. The current special values are{special.PI}and, in dilution table formulas,{special.DF}. The Special category appears in the operator picker only after you select a source table;{special.PI}can also be typed manually in any formula. - When you insert Count from the operator picker, the builder inserts
count([]). Place the table reference inside the brackets, for examplecount([{table.sample_table.result}]).
Open a formula action
- From the left navigation menu, click Procedures. The Procedures page displays.
- Open the procedure template you want to update.
- Open the step where you want to add the calculation.
- In Process Actions, open Formulas.
- Select Standard Formula or Table Formula. (The Formulas menu also includes Time Formula, which is covered in a separate article.)
- In the Formula field, build the expression by typing directly or by selecting items from the operator picker.
Use Standard Formula when you want one calculated result for the step. Use Table Formula when you want to calculate values from one or more source table columns.
Structure formula syntax
Use the following building blocks when you structure a formula:
| Element | Syntax | Example |
|---|---|---|
| Number | 12, 12.5 |
2.5 |
| Arithmetic operator | +, -, *, /, %, ^ |
{input.actual} / {input.target} |
| Parentheses | ( ... ) |
({input.a} + {input.b}) / 2 |
| Function call | function_name(value) |
round(({input.a} / {input.b}) * 100, 2) |
| Reference token | {category.reference} |
{input.actual_weight} |
| Table reference token | {table.source_table_variable.column_variable} |
{table.sample_table.ph} |
Use this pattern for most standard formulas:
({reference_or_number} operator {reference_or_number})
Example:
round(({input.actual_weight} / {input.target_weight}) * 100, 2)
Use this pattern for row-level table formulas:
{table.source_table_variable.column_variable} operator value
Example:
{table.sample_table.ph} * 100
Use this pattern for grouped table formulas:
function_name({table.source_table_variable.column_variable})
Example:
mean({table.sample_table.ph})
For table formulas that reference {table...} tokens, aggregation is required only when the formula is grouped across table rows, such as Full Table, Sample, or Dilution. A row-level table formula can use a direct {table...} reference. Grouped formulas accept the following aggregate wrappers around a table reference: max, mean, min, std, sum, and count.
Review supported reference formats
Use the following token formats when you build formulas:
| Reference type | Syntax | Example |
|---|---|---|
| Input | {input.input_variable} |
{input.actual_weight} |
| Process action | {action.action_variable} |
{action.yield_calc} |
| Parameter | {parameter.parameter_id} |
{parameter.batch_size} |
| Constant | {constant.constant_id} |
{constant.theoretical_yield} |
| Table column | {table.source_table_variable.column_variable} |
{table.sample_table.result} |
| Special value | {special.PI} |
{special.PI} |
| Dilution factor | {special.DF} |
{special.DF} |
- When you type a token manually, use the underlying variable ID or field ID, not the display label shown in the picker.
- Parameters and constants appear in the operator picker only when their type is Numeric or Measure.
Review supported math functions
The following functions are supported in Tempo formula authoring.
| Function | Syntax | Standard Formula | Table Formula | Example |
|---|---|---|---|---|
| Round | round(value, precision) |
Yes | Yes | round(({input.a} / {input.b}) * 100, 2) |
| Root | nthRoot(value, n) |
Yes | Yes | nthRoot({input.volume}, 3) |
| Logarithm | log(value, base) |
Yes | Yes | log({input.signal}, 10) |
| Decadic logarithm | log10(value) |
Yes | Yes | log10({input.signal}) |
| Mean | mean(value1, value2, ...) or mean({table...}) |
Yes | Yes | mean({table.sample_table.result}) |
| Min | min(value1, value2, ...) or min({table...}) |
Yes | Yes | min({table.sample_table.result}) |
| Max | max(value1, value2, ...) or max({table...}) |
Yes | Yes | max({table.sample_table.result}) |
| Standard deviation | std(value) or std({table...}) |
Yes | Yes | std({table.sample_table.result}) |
| Absolute value | abs(value) |
No | Yes | abs({table.sample_table.deviation}) |
| Sum | sum({table...}) |
No | Yes | sum({table.sample_table.result}) |
| Count | count([{table...}]) |
No | Yes | count([{table.sample_table.result}]) |
- The Standard Formula and Table Formula columns describe which functions are offered in the operator picker for each formula type.
- The runtime evaluator is math-based, so functions that are not listed in this article may still evaluate when typed manually, but they are not supported authoring syntax. Validate any manually entered function in a non-production procedure before relying on it.
Review additional Math.js function references
The following functions come from the Math.js reference library that powers Tempo formula evaluation. These entries are listed separately from the supported function table above because they are not surfaced as operator buttons in the authoring UI and are not officially supported Tempo formula syntax.
- Use these entries as a technical manual-entry reference, not as the primary supported function list.
- Validate any manually entered function in a non-production procedure before standardizing it for authors.
- Some functions are general-purpose Math.js functions and may be less practical when your formula depends on Tempo-specific references, units of measure, or table aggregation rules.
- If you need a supported commitment, use the Review supported math functions section above rather than this appendix.
Arithmetic
| Function | Description |
|---|---|
abs(x) |
Calculate the absolute value of a number. |
add(x, y) |
Add two or more values. |
cbrt(x) |
Calculate the cubic root of a value. |
ceil(x) |
Round a value towards plus infinity. |
cube(x) |
Compute the cube of a value. |
divide(x, y) |
Divide two values. |
exp(x) |
Calculate the exponential of a value. |
expm1(x) |
Calculate exp(x) - 1. |
fix(x) |
Round a value towards zero. |
floor(x) |
Round a value towards minus infinity. |
gcd(a, b) |
Calculate the greatest common divisor for two or more values. |
hypot(a, b, ...) |
Calculate the hypotenuse of a list of values. |
invmod(a, b) |
Calculate the modular multiplicative inverse of a modulo b. |
lcm(a, b) |
Calculate the least common multiple for two or more values. |
log(x [, base]) |
Calculate the logarithm of a value. |
log10(x) |
Calculate the base-10 logarithm of a value. |
log1p(x) |
Calculate the logarithm of value + 1. |
log2(x) |
Calculate the base-2 logarithm of a value. |
mod(x, y) |
Calculate the modulus, or remainder, of an integer division. |
multiply(x, y) |
Multiply two or more values. |
nthRoot(a, root) |
Calculate the nth root of a value. |
pow(x, y) |
Calculate x ^ y. |
round(x [, n]) |
Round a value towards the nearest integer or decimal precision. |
sign(x) |
Compute the sign of a value. |
sqrt(x) |
Calculate the square root of a value. |
square(x) |
Compute the square of a value. |
subtract(x, y) |
Subtract two values. |
unaryMinus(x) |
Invert the sign of a value. |
unaryPlus(x) |
Apply the unary plus operation. |
xgcd(a, b) |
Calculate the extended greatest common divisor. |
Trigonometry
| Function | Description |
|---|---|
acos(x) |
Calculate the inverse cosine of a value. |
acosh(x) |
Calculate the hyperbolic arccosine of a value. |
acot(x) |
Calculate the inverse cotangent of a value. |
acoth(x) |
Calculate the inverse hyperbolic cotangent of a value. |
acsc(x) |
Calculate the inverse cosecant of a value. |
acsch(x) |
Calculate the inverse hyperbolic cosecant of a value. |
asec(x) |
Calculate the inverse secant of a value. |
asech(x) |
Calculate the inverse hyperbolic secant of a value. |
asin(x) |
Calculate the inverse sine of a value. |
asinh(x) |
Calculate the hyperbolic arcsine of a value. |
atan(x) |
Calculate the inverse tangent of a value. |
atan2(y, x) |
Calculate the two-argument inverse tangent. |
atanh(x) |
Calculate the hyperbolic arctangent of a value. |
cos(x) |
Calculate the cosine of a value. |
cosh(x) |
Calculate the hyperbolic cosine of a value. |
cot(x) |
Calculate the cotangent of a value. |
coth(x) |
Calculate the hyperbolic cotangent of a value. |
csc(x) |
Calculate the cosecant of a value. |
csch(x) |
Calculate the hyperbolic cosecant of a value. |
sec(x) |
Calculate the secant of a value. |
sech(x) |
Calculate the hyperbolic secant of a value. |
sin(x) |
Calculate the sine of a value. |
sinh(x) |
Calculate the hyperbolic sine of a value. |
tan(x) |
Calculate the tangent of a value. |
tanh(x) |
Calculate the hyperbolic tangent of a value. |
Statistics
| Function | Description |
|---|---|
corr(A, B) |
Compute the correlation coefficient of two lists. |
mad(a, b, c, ...) |
Compute the median absolute deviation. |
max(a, b, c, ...) |
Compute the maximum value of a matrix or list. |
mean(a, b, c, ...) |
Compute the mean value of a matrix or list. |
median(a, b, c, ...) |
Compute the median of a matrix or list. |
min(a, b, c, ...) |
Compute the minimum value of a matrix or list. |
prod(a, b, c, ...) |
Compute the product of a matrix or list. |
std(a, b, c, ...) |
Compute the standard deviation of a matrix or list. |
sum(a, b, c, ...) |
Compute the sum of a matrix or list. |
variance(a, b, c, ...) |
Compute the variance of a matrix or list. |
Probability
| Function | Description |
|---|---|
bernoulli(n) |
Return the nth Bernoulli number. |
combinations(n, k) |
Compute the number of ways of picking k unordered outcomes from n. |
combinationsWithRep(n, k) |
Compute combinations where individual outcomes can repeat. |
factorial(n) |
Compute the factorial of a value. |
gamma(n) |
Compute the gamma function of a value. |
lgamma(n) |
Compute the logarithm of the gamma function. |
multinomial(a) |
Compute multinomial coefficients. |
permutations(n [, k]) |
Compute the number of ordered subsets of k elements from n. |
random([min, max]) |
Return a uniform random number between min and max. |
randomInt([min, max]) |
Return a uniform random integer between min and max. |
Complex
| Function | Description |
|---|---|
arg(x) |
Compute the argument, or angle, of a complex value. |
im(x) |
Get the imaginary part of a complex number. |
re(x) |
Get the real part of a complex number. |
Fraction
| Function | Description |
|---|---|
den(x) |
Get the denominator of a fraction. |
num(x) |
Get the numerator of a fraction. |
Special
| Function | Description |
|---|---|
erf(x) |
Compute the error function of a value. |
zeta(n) |
Compute the Riemann zeta function of a value. |
Combinatorics
| Function | Description |
|---|---|
bellNumbers(n) |
Count the number of partitions of a set. |
catalan(n) |
Compute the nth Catalan number. |
composition(n, k) |
Count compositions of n into k parts. |
stirlingS2(n, k) |
Count ways to partition n objects into k non-empty subsets. |
Geometry
| Function | Description |
|---|---|
distance([x1,y1],[x2,y2]) |
Calculate the Euclidean distance between two points. |
Matrix
| Function | Description |
|---|---|
count(x) |
Count the number of elements of a matrix, array, or string. |
det(x) |
Calculate the determinant of a matrix. |
dot(x, y) |
Calculate the dot product of two vectors. |
trace(x) |
Calculate the trace of a square matrix. |
Utilities
| Function | Description |
|---|---|
numeric(x) |
Convert a numeric input to a specific numeric type. |
Source: mathjs.org/docs/reference/functions.html.
Next steps
- To build a new calculated step value, add a Standard Formula process action to the target step and insert references from the operator picker.
- To calculate across table columns, add a Table Formula process action and use aggregated
{table...}references.