**USING ***paceval.* – A SIMPLE CODE EXAMPLE

*paceval.*– A SIMPLE CODE EXAMPLE

## The following example is very simple but it shows you how easy it is to create your own programs with

paceval.You can easily modify this example and create complex mathematical models. These models can contain hundreds of functions and variables. You just use multiplepaceval.-Computation objects in your code. Then, each function could even consist of thousands of characters.

If you want to work with a mathematical function like

i.e. in a computer readable format

** f(x,y) = -sin(x*cos(x))^(1/y)**

using two variables **x** and **y**.

You only have to create a * paceval.*-Computation object with this code for one time:

C++:

**PACEVAL_HANDLE** handle_pacevalComputation = **paceval_CreateComputation**(“-sin(x*cos(x))^(1/y)”, 2, “x y”, false);

###### (see also the paceval. Application programming interface (API)>>)

**paceval_CreateComputation**(…) will create an object that identifies the sub-functions and sub-calculations in the given function and return the handle of the * paceval.*-Computation object. This one-time precompilation including parsing of the function takes time: less than 1 millisecond on a standard processor used for Internet of Things (IoT) and even less on a standard computer.

This might already seem very fast but think of the accumulated time if you had to create an object for any values you would like to calculate results for (maybe thousands if you want to plot the function). Therefore, you can declare the variables by calling **paceval_CreateComputation**(…) once which caches all sub-functions and sub-calculations and creates a small size and speed optimized binary image of the function. Ideally, you just run **paceval_CreateComputation**(…) at the very beginning of your program for all your static mathematical models to speed up future calculations. You get the result for a concrete values of the variables with **paceval_GetComputationResult**(…).

In this example, if you want to get the result for **x = 0.5** and **y = 2** you simply use this code:

C++:

long double valuesVariablesArray[2];

long double ldResult;

valuesVariablesArray[0] = 0.5; //the x-value

valuesVariablesArray[1] = 2; //the y-value

ldResult = **paceval_GetComputationResult**(handle_pacevalComputation, valuesVariablesArray, NULL, NULL);

//ldResult is approximately -0.65180178245228

###### (see also the paceval. Application programming interface (API)>>)

The return value is the result of the calculation. **paceval_GetComputationResult**(…) uses the cached sub-functions and sub-calculations created earlier by **paceval_CreateComputation**(…). The required time for this calculation result is as little as the required time using compiled standard C++ source code (or even less depending on the function).

Below, you will find the corresponding standard C++ source code to the example above:

C++:

long double valuesVariablesArray[2];

long double ldResult;

valuesVariablesArray[0] = 0.5; //the x-value

valuesVariablesArray[1] = 2; //the y-value

ldResult = -1*powl(sinl(valuesVariablesArray[0]*cosl(valuesVariablesArray[0])), 1/valuesVariablesArray[1]);

//ldResult is approximately -0.65180178245228

The obvious advantage of * paceval.* against standard C++ code is the readability of the source code and error handling functionality. In this example, an error would occur in the C++ code if

**y**is set to

**0**or close to

**0**, as the term would be divided by

**0**. The user would not know why the calculation fails.

* paceval.* recognises automatically this error and locates it. For detailed information, just get further information on

**paceval_GetIsError**(…) and

**paceval_GetErrorInformation**(…) in the

*Application programming interface (API)>>. In addition, the maintenance of the mathematical model is easier. You could collect all string representations of the mathematical functions and variables in a central area of the code or a database. Furthermore, the implementation of long functions can easily be handled since*

**pace**val.*sets no limit in the length and number of variables of the function*

**pace**val.*.*The limit is only set by the memory of the underlying system. Just imagine a mathematical model consisting of 50 very complex single functions each with a minimum length of 50.000 characters and 100 variables. You will find these scenarios easily in cars having more than 100 sensors to watch, watchdog applications for sensitive products or stock watch and trading applications.

But, with * paceval.* you can do much more which helps you to interpret your results in a better way. In particular, when you are using a very complex mathematical model consisting of long functions as this will lead to rounding errors which are not handled by standard programming. Here

*is the perfect solution. You can easily enable the Trusted Interval Computation, TINC™. TINC is a*

**pace**val.*specific Interval arithmetic>> optimized for speed.*

**pace**val.In the above example simply do the changes marked in green to use TINC and get the interval covering the real result:

C++:

**PACEVAL_HANDLE** handle_pacevalComputation = **paceval_CreateComputation**(“-sin(x*cos(x))^(1/y)”, 2, “x y”, true);

###### (see also the paceval. Application programming interface (API)>>)

C++:

long double valuesVariablesArray[2];

long double ldResult;

long double minResultInterval;

long double maxResultInterval;

valuesVariablesArray[0] = 0.5; //the x-value

valuesVariablesArray[1] = 2; //the y-value

ldResult = **paceval_GetComputationResult**(handle_pacevalComputation, valuesVariablesArray, &minResultInterval, &maxResultInterval);

// ldResult is approximately -0.65180178245228

// minResultInterval as lower confidence bound is -0.6518017824522809982

// maxResultInterval as upper confidence bound is -0.6518017824522740538