# MathTools

## Overview

`MathTools` provides a straightforward method for enabling the AI to evaluate mathematical expressions without the need to compile or execute C# code on the server. It leverages Wisej.NET's JavaScript evaluation capabilities by sending an expression to the browser and utilizing JavaScript's `eval()` method to perform the execution.

Here is what the prompt looks like:

{% code overflow="wrap" %}

```ini
#
# MathTools
#
[MathTools]
Evaluates a mathematical expression using JavaScript.

[MathTools.evaluate_expression]
Evaluates the expression.

[MathTools.evaluate_expression.expression]
Expression to evaluate (hint: all math functions are part of the Math class in JavaScript).
```

{% endcode %}

Once the MathTool is made available, the AI can utilize it whenever a complex expression needs to be calculated. For instance, if the AI encounters a scenario where it needs to add totals and compute a percentage while performing its task, it will execute the following command: `MathTools.evaluate_expression("(19883 + 277783 + 6653) * 0.2")`

{% hint style="warning" %}
Remember that while LLMs may seem capable of performing complex calculations, they are not calculators. They remain language-based systems. Asking an LLM to compute a complex expression would be akin to requesting a person to solve it mentally without relying on a calculator or pencil.
{% endhint %}

## Using MathTools

To enable the use of MathTools, simply add it to a SmartHub, SmartAdapter, or SmartPrompt.

```csharp
this.hub1.UseTools(new MathTools());
this.smartDataEntryAdapter1.UseTools(new MathTools());

Console.WriteLine(
    new SmartPrompt()
        .UseTools(new MathTools())
        .AskAsync(endpoint, "What is the square root of ... plus ... minus ...")
        .Result.Text);
```
