# Mathematical formulas parser

## Overview

Polybench contains a parser for simple mathematical formulas. This parser is used to do basic calculations on variables.Currently, Polybench only supports formulas in the following forms:

*=a + b*

=a - b

=a * b

=a / b

=a - b

=a * b

=a / b

where a and b are either fixed values or variables containing numerical values.

## Details

The Polybench Formula parser works in relation to the**SET_PARAMETER**action (link). In the

*Value*setting for the action a mathematical formula can be written.

A formula is only recognized if it starts with the equal-symbol:

**=**.

Inside the formula you may use fixed numbers and/or variables.

For example, you have a global variable (link) called

*$var$*and it has the value

*10*.

You can now define an action (for example using an Action Button (link)) with following settings:

action:

*SET_PARAMETER*

address:

*$var$*

value:

*=$var$ + 1*

After the action has been executed, $var$ will be

*11*.

### Real numbers vs. Natural numbers

If at least one of the values in the formula is a real number, then the result of the calculation will be displayed as a real number.If all numbers are natural numbers (integers), then the result will be a natural number.

### Result if a value is not a number

If one of the values in te formula is not a number, then of course nothing can be calculated. In that case, the formule is returned without the '=' sign.### Limitations

Currently the formula parser is very limited:- you can only use the four basic math operators +, -, *, and /.

- you cannot use more than one math operator in the formula

- you cannot use brackets, so

*=(1 + 2)*will not return

*3*, but

*(1 + 2)*

We will develop this further in future versions.