# Fast Formula Evaluation

Like in the “oldie, but goldie” Fractint, an auto-evaluator would be nice in XaoS as well. I.e., when a user enters a formula like

`z=z^2+c`

then XaoS automagically evaluates this formula for each c pixel and draws the image. The main point here is to do this reasonably fast.

For this, the formconv library could help. We have very nice benchmarks of this library soon, for details go to the Real Time Zooming Math Engine (rtzme) web page. However, rtzme is written in C++ (and wxWidgets), it is also possible to extend XaoS capabilities inside the C programming style (so you are not enforced to use C++ and/or rewrite the whole XaoS code into C++).

Here is a sample code which illustrates the technique (cut and pasted from the `test/complex.cpp` file from the formconv library):

```/*
* Demo program which shows the power of the libformconv library.
* Written by Z. Kovacs, modifications by G. Bakos.
* Copyright (C) 2004-2005 Z. Kovacs, G. Bakos.
*/

#include <h/fastcompute.h>

int
main (int argc, char **argv)
{
char myFormula[50];
formula < FastComplexCompute < std::complex < double > > >*f;
complex < double >c;
double i, j, re, im;
strcpy (myFormula, "sinz^2");
f =
formconv_prepare < FastComplexCompute < std::complex < double
> > >(myFormula);
for (i = 0; i < 1; i += 0.3)
{
for (j = 0; j < 1; j += 0.3)
{
c = complex < double >(i, j);
c =
formconv_evaluate < FastComplexCompute < std::complex <
double > > >(f, c);
re = real (c);
im = imag (c);
printf ("%5.3f+%5.3f*I ", re, im);
}
printf ("\n");
}
formconv_free < FastComplexCompute < std::complex < double > > >(f);
}```

The formconv library is also useful for intuitively entered formulas. So the user is allowed to type

`z=sin^2z+c`

`z=cpow(sin(z),2)+c`