BayesHive: Expression syntax

Both the nonlinear regression and the dynamical systems model builders require the specification of mathematical expressions: for nonlinear regression models we must specify the relationship between the outcome and predictor variables, and for dynamical systems we must specify the differential equations defining the system. This page describes the syntax used for these expressions.

Literals and identifiers

Literal numeric values are expressed using the normal integer or floating point forms familiar from most programming languages, e.g. 123, 3.14159, 6.02E23 and so on.

Identifiers for variables and parameters in equations should start with a letter (upper or lower case), and are composed of upper or lower case letters, digits and underscores. Some special rules exist governing the rendering of identifiers for display in the model builders. The following table covers the most common possibilities:

Input syntax Rendered form
x, y x, y Single-letter identifiers
age, price age, price Multi-letter identifiers
beta, Psi β, Ψ Greek letters
x_0, beta_age x0, βage Subscripted identifiers

The identifiers t, e, pi are reserved -- they are used to stand for the time variable in dynamical systems, the base of natural logarithms, and the usual constant π. In addition, the identifiers W, W1, W2, etc. are reserved for the representation of Wiener processes in stochastic differential equations.

Arithmetic expressions

The usual arithmetic operators are expressed as + (addition), - (subtraction), * (multiplication), / (division) and ^ (exponentiation) and parentheses are used for expression grouping. Here are some examples:

  • x + 1x+1
  • x - zxz
  • x * (y + 3)x(y+3)
  • 1 / (x + 1)1/(x+1)
  • 3 * x^3 + 2 * x^2 + x - 43x3+2x2+x4

Built-in functions

A number of common mathematical functions are built-in:

Input syntax Rendered form
sin(x), cos(x), tan(x) sinx, cosx, tanx Trigonometric functions
asin(x), acos(x), atan(x) asinx, acosx, atanx Inverse trigonometric functions
exp(x) expx=ex Exponential function
log(x), log10(x) logx, log10x Natural and base-10 logarithms
sqrt(x) x Square root
abs(x) x Absolute value
ceil(x), floor(x) ceil(x), floor(x) Ceiling and floor functions
atan2(x, y) atan2(x,y) Inverse tangent of y/x
min(x, y) min(x,y) Minimum of x and y
max(x, y) max(x,y) Maximum of x and y

Differential equations

In the dynamical systems builder, it is necessary to specify time derivatives of variables in order to define ordinary and stochastic differential equations. A simple example shows how this works: the input m * D^2 x + k * D x + \omega^2 x = A * cos(\Omega * t) results in the following rendered equation


Here, an expression of the form

  • D y represents the first time derivative of y, dy/dt, and
  • D^n y, with n an integer, represents the nth time derivative of y, dny/dtn.

It is important to note that we must write D x and not Dx. The space between the D and the variable name is important: Dx is a single identifer, D x is a derivative.

Wiener terms

In stochastic differential equations, as well as ordinary derivatives, we need to be able to represent Wiener terms (increments of white noise stochastic processes). In order to maintain a consistent syntax between ODEs and SDEs, we adopt a slight abuse of notation, where for a Wiener process Wt, we write D W to formally stand for the derivative of this process, which is itself a white noise process.

This means that the stochastic differential equation


is represented as D x = theta * (mu - x) + sigma * D W and is in fact rendered as


even though, strictly, Wiener processes are not differentiable.

For systems of SDEs requiring multiple Wiener processes, we use the symbols W1, W2, etc., as for example:

D S = mu * S + sqrt(nu) * S * D W1

D nu = kappa * (theta - nu) + xi * sqrt(nu) * D W2

representing the system of SDEs

dSt=μSt+νtStdWt(1) dνt=κ(θνt)+ξνtdWt(2)

Here Wt(1) and Wt(2) are two separate (but possibly correlated) Wiener processes.

Auxiliary functions

In the dynamical systems builder, it is possible to make use of auxiliary functions to simplify the expression of differential equations. If we want to write the system



we can simply introduce the symbol f as a function into an equation, i.e.

m * D^2 x + k * D x + omega^2 * x = f(t)

and then fill in the right hand side of the auxiliary function f in the new field that appears in the builder window.