University of Jyvaskyla, Scientific Visualization OVi


 
 
 

Main help page | OVi Tutorial | Optimization Methods | Mathematical Expressions
Visualization | The Ovi User Interface

OVi Mathematical Expressions

 

Index 

1. Introduction

2. Syntax of the OVi expressions

2.1. The general format of inputs
2.2. The set of operators
2.3. Operator precedence
2.4. Variable names
3. The basic functions
3.1. Trigonometric functions
3.2. Transcendental functions
3.3. Macros
4. A note on symbolic differentation


1. Introduction

This section of the help pages briefly describes the syntax and operation of the mathematical formulas implemented in the OVi software. The main features of the algebraic system are: The OVi's input parsing and numeric evaluation system is based on the AlgObj v0.4 package, which is a generic object-oriented algebraic system in C++. This package, and its adaptation for the OVi's purposes was made by Markku-Juhani O. Saarinen, mjos@math.jyu.fi.

 This document describes only the most important features of AlgObj.

 On SGI's the system handles all values as 64-bit IEEE "double" floating point numbers. The machine dependant constants are thus:

 

Smallest number above zero: 2.225 * 10-308
Greatest number: 1.7977 * 10308
Average number of significant decimal digits: 15.6
It is not adviced to choose epsilon values smaller than 10-6 in the optimization algorithms.

 


2. Syntax of the OVi expressions

2.1. The general format of inputs

Let us begin with an example of a valid OVi function input:

 

x^2 + sin(x)^2

As you can see the input looks pretty much like some higher level language like Basic or C. This is not a coincidence; we have tried to design the input syntax to follow the "common" rules so that most users (who are usually familiar with at least some programming language) would not even have to refer to help pages like this.

 The above expression assigns the expression

 

x2 + sin2 x

to the default function symbol. You can also excplicitely enter the prefix fx = in the expressions if you want. In any case, whenever the value of x changes, the objective function will change correspondingly.

 

2.2. The set of operators

The set of operators is:

 

+ Addition: a + b
- Substraction (as in a - b) or negation (as in -a )
* Multiplication: a * b
/ Division: a / b
^ Power: a ^ b
= Assignment: a = b
? Conditional: ? ( a, b, c ) D Differentation operator: D(fx, x)
The differentation operator is discussed in the chapter "A note on symbolic differentation".

 This set is pretty much the same as in the C programming language, apart from the adaptation of ^ sign to mean power. There are no exclusive-or or other bit-manipulation operators in OVi.

 The other curiosity is the ? - operator. It has the same principial function as the ? - operator of "C", but the syntax is totally different. It can be used to construct complex conditional or discontinuous expressions. The operation of

? (x, y, z)

is basically the same as of

x < 0 ? y : z

in C. That is; either one of the last two parameters is chosen depending on the sign of the first parameter. You can recursively insert two or more ? -operators. The common discontinuous functions max, min, abs and sgn have been predefined as macros which internally use the ? - operator. See Functions.

 

2.3. Operator precedence

Operator precedence (lowest priority first):

 

1. R1 -> R1 predefined functions: abs(kissa), sin x ..
2. The power operator: 2^x
3. Multiplication and division: x*y, x/y
4. Addition and substraction: x+y, x-y
5. Negation operator: -x
6. Parenthesies: (x)
7. Differentiation operator: D(fx, x)
8. Conditional operators: max(x, y), min(x, y), ?(x, y, z)
9. The equation (assignment) sign: x=y

This means that the operators in group 3 have priority over the groups 4 to 9 but not over groups 1 and 2. The operators within the same group have equal priorities and are interpreted in the input (left to right) order.

 Do not be afraid if this looks complicated; the operator precedence in OVi follows the common grammar school rules. Example:

 

a + b ^ c * d 
is interpreted as
( a + ( (b ^ c ) * d ) )

Of course you are free to use an arbitary number of parenthesies to clear up or override the precedence whenever you want to.

 

2.4. Variable names

The variable names have an unlimited lenght but only the first 32 characters are significant. The variable names are case sensitive; "kiSSa" is not the same as "kissa".

 

- The fist character of a variable name must be one of a..z, A..Z or { _ @ $ # }.
- There can be no spaces within a variable name (this is not Fortran!)
- The characters after the first one can be alphabetic characters, numbers (0..9) or one of { _ @ $ # }.
You do not have to explicitely declare a variable; variables are automatic.
 


3. The basic functions

In this section we list the basic functions supported by OVi. Note that you can leave out the parentheses around the parameter in most cases (see operator precedence). The function names are case sensitive.
 

3.1. Trigonometric functions

sin ( x )
cos ( x )
tan ( x )
arcsin ( x )
arccos ( x )
arctan ( x )
All of the trigonometric functions operate in radians rather than degrees.

 

3.2. Transcendental functions

exp ( x )
ln ( x )
These functions work in natural base (2.7183..). As OVi only operates with real numbers, an attempt of taking a logarithm from a negative number will cause a error message to be displayed.

 

3.3. Macros

sqr ( x )
abs ( x )
sgn ( x )
max ( x, y )
min ( x, y )
All of these functions have been implemented as predefined macros.

 

sqr x returns the square root of x.
abs x returns the absolute value of x.
sgn x returns the sign of x. The sign is -1 for all negative x and +1 othervise.
max (x, y) returns the greater of x and y (parentheses are compulsory).
min (x, y) returns the smaller of x and y (parentheses are compulsory).
Note: max and min only accept exactly two parameters, but there is a way to generalize this: you can write something like max ( max(a, b), c ) to get the greatest of three numbers.

 


4. A note on symbolic differentation

The system is capable of forming a derivate of most functions. In many cases, this is done without explicitly telling the user about this. Care must be taken to use functions which have real derivates at the points needed.

 If the user wishes to enter a function's derivate as a parameters, he can use the D-operator for this. The syntax of the D-operator is:

D(y, x)

This expression will result in a function which has the value of dy/dx. That is, the first parameter is the function to be differentiated and the second parameter is the name of the "reference" variable.