# Inspecting calculation process

*** If you found the software useful donation is something you might consider ðŸ™‚ ***

## JAVA code

### Case 1: Setting the verbose mode

```import org.mariuszgromada.math.mxparser.*;
...
Function f = new Function("f(x) = x^2");
Expression e = new Expression("f(2)+(2+3)^2", f);
e.setDescription("Example - verbose mode");
e.setVerboseMode();

mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate());
```
```[mXparser-v.2.3.1]
[Example - verbose mode][f(2)+(2+3)^2]
[Example - verbose mode][f(2)+(2+3)^2] Starting ...
[Example - verbose mode][f(2)+(2+3)^2] Parsing (1, 3)  ---> ( 2.0 )  ...  ---> f 2.0 + ( 2.0 + 3.0 ) ^ 2.0  ...  done
[Example - verbose mode][f(2)+(2+3)^2] Parsing (0, 1)  ---> f 2.0  ...
[f(x) ][ x^2]
[f(x) ][ x^2] Starting ...
[f(x) ][ x^2] x = 2.0
[f(x) ][ x^2] Parsing (0, 2)  ---> 2.0 ^ 2.0  ...  ---> 4.0  ...  done
[f(x) ][ x^2] Calculated value: 4.0
[f(x) ][ x^2] Exiting

---> 4.0 + ( 2.0 + 3.0 ) ^ 2.0  ...  done
[Example - verbose mode][f(2)+(2+3)^2] Parsing (2, 6)  ---> ( 2.0 + 3.0 )  ...  ---> 4.0 + ( 5.0 ) ^ 2.0  ...  done
[Example - verbose mode][f(2)+(2+3)^2] Parsing (2, 4)  ---> ( 5.0 )  ...  ---> 4.0 + 5.0 ^ 2.0  ...  done
[Example - verbose mode][f(2)+(2+3)^2] Parsing (0, 4)  ---> 4.0 + 5.0 ^ 2.0  ...  ---> 4.0 + 25.0  ...  done
[Example - verbose mode][f(2)+(2+3)^2] Parsing (0, 2)  ---> 4.0 + 25.0  ...  ---> 29.0  ...  done
[Example - verbose mode][f(2)+(2+3)^2] Calculated value: 29.0
[Example - verbose mode][f(2)+(2+3)^2] Exiting

Res: f(2)+(2+3)^2 = 29.0
[mXparser-v.2.3.1]
```

### Case 2: Syntax checking

```import org.mariuszgromada.math.mxparser.*;
...

/* Function and expression definition */
Function fib = new Function("fib(n) = if( n>1, fib(n-1)+fib(n-2), if(n > 0, 1, 0) )");
Expression e = new Expression("fib(10) + 20/sin(x)", fib);

/* 1st trial of syntax checking. */
mXparser.consolePrintln("1st trial of syntax checking.");
e.checkSyntax();
mXparser.consolePrintln(e.getErrorMessage());

/* Definition modification */
Argument x = new Argument("x = 2");

/* 2nd trial of syntax checking. */
mXparser.consolePrintln("2nd trial of syntax checking.");
e.checkSyntax();
mXparser.consolePrintln(e.getErrorMessage());
```
```[mXparser-v.2.3.1] 1st trial of syntax checking.
[mXparser-v.2.3.1] [fib(10) + 20/sin(x)] checking ...
[fib(10) + 20/sin(x)] (fib, 0) checking user defined function ...
[fib(10) + 20/sin(x)] -> [fib] = [ if( n>1, fib(n-1)+fib(n-2), if(n > 0, 1, 0) )] checking ...
[fib(10) + 20/sin(x)] -> [fib] = [ if( n>1, fib(n-1)+fib(n-2), if(n > 0, 1, 0) )] no errors.
[fib(10) + 20/sin(x)] (x, 9) invalid <TOKEN>.
[fib(10) + 20/sin(x)] errors were found.

[mXparser-v.2.3.1] 2nd trial of syntax checking.
[mXparser-v.2.3.1] [fib(10) + 20/sin(x)] checking ...
[fib(10) + 20/sin(x)] (fib, 0) checking user defined function ...
[fib(10) + 20/sin(x)] -> [fib] = [ if( n>1, fib(n-1)+fib(n-2), if(n > 0, 1, 0) )] already checked - no errors!
[fib(10) + 20/sin(x)] no errors.

[mXparser-v.2.3.1]
```

### Case 3: Lexical syntax checking

```import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("fun(1,2)+3");
mXparser.consolePrintln("checkSyntax    = " + e.checkSyntax());
mXparser.consolePrintln(e.getErrorMessage());
mXparser.consolePrintln("checkLexSyntax = " + e.checkLexSyntax());
```
```[mXparser-v.4.0.0] checkSyntax    = false
[mXparser-v.4.0.0] [fun(1,2)+3] checking ...
[fun(1,2)+3] (fun, 0) invalid <TOKEN>.
[fun(1,2)+3] errors were found.

[mXparser-v.4.0.0] checkLexSyntax = true
```

### Case 4: Getting computing time

```import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("sum(i, 1, 1000000, 1)");
mXparser.consolePrintln("Res : " + e.getExpressionString() + " = " + e.calculate());
mXparser.consolePrintln("Computing time = " + e.getComputingTime() + " s.");
```
```Res : sum(i, 1, 1000000, 1) = 1000000.0
Computing time = 0.372 s.
```

*** If you found the software useful donation is something you might consider ðŸ™‚ ***

Best regards,