Expressions used in Data Arithmetic module, grain quantity formulas and in graph function fitting have syntax similar to common programming languages.
All numbers are real (floating point), number literals use standard
notation. Examples of valid numbers:
1
,
.707
,
2.661
,
8.2e-34
.
Function, constant, and variable names start with a letter and
continue with zero or more letters, numbers, or underscores.
Examples of valid identifiers:
pow10
(a function),
Pi
(a constant),
d2_2
(a variable).
The precedence of operations is summarized in following table.
Operation | Associativity | Examples |
---|---|---|
parentheses | N.A. | (x) |
function call and unary operators | right to left | -sqrt 3 |
power operator | right to left | 2^16 |
multiplication, division, and modulo operators | left to right | 9/2 * 8 |
addition and subtraction operators | left to right | 3 - 4 + 5 |
Note -3^2
is 9, that is (-3)^2
,
like in bc, but unlike in Perl or Python.
Available operators and functions are listed in following table.
Operator | Meaning |
---|---|
+ (unary) | no op |
- (unary) | negative value |
~ | negative value (equivalent to - ) |
+ (binary) | addition |
- (binary) | subtraction |
* | multiplication |
/ | division |
% | floating point modulo |
^ | power |
abs | absolute value |
floor | rounding down to nearest integer |
ceil | rounding up to nearest integer |
sqrt | square root |
cbrt | cubic root |
sin | sine function |
cos | cosine function |
tan | tangent function |
asin | arc sine function |
acos | arc cosine function |
atan | arc tangent function |
sinc | cardinal sine function, sine divided by the value |
exp | base-e exponential function |
ln | base-e logarithm function |
log | base-e logarithm function |
pow10 | base-10 exponential function |
log10 | base-10 logarithm function |
pow2 | base-2 exponential function |
log2 | base-2 logarithm function |
spow | signed power function; the result has the same sign as the argument |
sinh | hyperbolic sine function |
cosh | hyperbolic cosine function |
tanh | hyperbolic tangent function |
asinh | inverse hyperbolic sine function |
acosh | inverse hyperbolic cosine function |
atanh | inverse hyperbolic tangent function |
erf | error function (integral of Gaussian from zero) |
erfc | complementary error function (integral of Gaussian to infinity) |
pow | power function, pow(x,y) equals to x^y |
min | minimum of two values |
max | maximum of two values |
step | zero for negative values or zero, one for positive values |
mod | floating point modulo, mod(x,y) equals to x % y |
hypot | Euclidean distance function, hypot(x,y) equals to sqrt(x^2+y^2) |
atan2 | arc tangent function of two variables |
The following functions are available if the system mathematical library provides them:
Operator | Meaning |
---|---|
lGamma | logarithm of Γ function |
Gamma | Γ function |
J0 | Bessel function of first kind and order 0 |
J1 | Bessel function of first kind and order 1 |
Y0 | Bessel function of second kind and order 0 |
Y1 | Bessel function of second kind and order 1 |
Beside that, there are a few peculiarities that may make typing simple expression easier:
Multiplication signs are optional, you can use spaces instead (or nothing, in some
cases). E.g., 3/4 Pi
and 5(4+3)(2+1)
are valid
expressions. However, 3a
is not a valid expression,
3e-4
always means 0.0003
, not
3*e - 4
.
There is no difference between function calls and unary operators, so parentheses can
be often omitted. E.g, sqrt 5
and
hypot hypot 3,4,5
are valid expression. The latter can be
parenthesized as follows: hypot(hypot(3,4),5)
.
Note however, function calls have higher priority than any other operator, thus
sin Pi/2
is the same as (sin Pi)/2
, not
as sin(Pi/2)
.
If in doubt, write out expressions in full form.