# 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);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/ai/components/built-in-smarttools/mathtools.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
