Skip to main content

ai12z Copilot: Mathematical Expression Evaluation Agent

example doing a math problem

Overview

The Mathematical Expression Evaluation Agent is an out-of-the-box tool within the ai12z Copilot suite that allows you to perform complex mathematical calculations by evaluating mathematical expressions provided as strings. Utilizing a secure and controlled evaluation mechanism, this agent supports a wide range of mathematical operations, functions, and constants. It simplifies the integration of mathematical computations into your applications, requiring no customization and operating at a minimal cost—a fraction of a penny per use.

Key Features

  • Expression Evaluation: Evaluate mathematical expressions provided as strings, such as "47 + 8 / 9 * 6".
  • Advanced Mathematical Functions: Supports a wide array of mathematical functions, including trigonometric, logarithmic, statistical, and complex number operations.
  • Constants and Variables: Access mathematical constants like π (pi), e (Euler's number), and φ (golden ratio).
  • Easy Integration: As an out-of-the-box agent, it requires no customization and integrates seamlessly with your applications.
  • Cost-Effective: Operates at a minimal cost, making it an economical choice for performing mathematical computations within your projects.

Purpose

The agent is designed to:

  • Simplify Mathematical Computations: Allow developers to perform complex mathematical calculations without implementing the logic themselves.
  • Enhance Application Functionality: Provide users with the ability to input and compute mathematical expressions within your application.
  • Save Time: Eliminate the need for integrating and maintaining separate mathematical libraries or services.

How It Works

  1. Input Parameter: The LLM will pass to the Agent a mathematical expression as a string via the expr parameter.
  2. Evaluation: The expression is evaluated using a controlled set of allowed operators and functions to prevent unauthorized code execution.
  3. Result Delivery: The Agent result is returned as a string, back to the LLM

Supported Operations and Functions

Operators

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)
  • **Exponentiation (^ or **)**
  • Unary Negation (-x)

Mathematical Functions

  • Arithmetic Functions: sqrt, log, log10, log2, ln, exp, abs, factorial, gcd, lcm, perm, comb.
  • Trigonometric Functions: sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, sec, csc, cot.
  • Constants: pi, e, phi.
  • Complex Number Functions: real, imag, phase, polar, conjugate.
  • Statistical Functions: sum, max, min, mean, median, variance, stddev, len, sorted.
  • Linear Algebra Functions: eigvals, eigvecs, matrix_rank, matmul, det, inv, svd, qr.
  • Polynomial Functions: roots, polyval.
  • Fourier Transforms: fft, ifft.
  • Special Functions: gamma, besselj, bessely.
  • Random Number Generation: randint, random, choice, shuffle, normal, poisson, uniform.

Parameters

When invoking the Mathematical Expression Evaluation Agent, you can specify the following parameter:

  • expr (string, required): The mathematical expression to evaluate. For example, "((3 + 4)^2) + (ln(2 * 5)) / (8 + exp(2))^(1/3)".

Enabling the Agent

To enable the Mathematical Expression Evaluation Agent in your ai12z Copilot:

  1. Access the Agent Settings: Log in to your ai12z Copilot dashboard and navigate to the Agents section.
  2. Locate the Agent: Find the Math agent in the list of available agents.
  3. Enable the Agent: Click on the agent and select Enable to activate it for your projects.
  4. Set Parameters: When using the agent, specify the expr parameter as needed for your application.

Usage Example

Evaluating a Mathematical Expression

{
"function": "math_eval_expr",
"parameters": {
"expr": "sqrt(16) + sin(pi / 2) - log(10)"
}
}

In this example, the agent will:

  • Evaluate the expression sqrt(16) + sin(pi / 2) - log(10).
  • Return the result as a string.

Output Example

{
"result": "4.0"
}

Benefits

  • LLM and Math: Traditionly LLM are not great at math, this will likely change as LLM's themselves will have
  • User Engagement: Allow users to input and compute mathematical expressions directly within your application.
  • Time Savings: Reduce development time by utilizing a ready-made solution for mathematical computations.
  • Improved Functionality: Enhance your application with advanced mathematical capabilities without additional overhead.

Limitations

  • Non-Customizable: This is an out-of-the-box agent with fixed functionality and cannot be customized.
  • No Variable Assignments: The agent does not support variable assignments or definitions within expressions.
  • Error Handling: Invalid expressions or unsupported operations will result in an error message being returned.

Error Handling

If an error occurs during the evaluation, the agent will return an error message indicating the type of error to the Log. For example:

{
"error": "Math Error - Unsupported function or invalid usage: <AST node representation>"
}

Support

If you need assistance or have questions about the agent:

  • Documentation: Refer to the ai12z Copilot documentation for more detailed information.
  • Contact Us: Reach out to our support team at support@ai12z.com for personalized help.

By enabling the Mathematical Expression Evaluation Agent, you can seamlessly integrate advanced mathematical computation capabilities into your applications, enhancing user engagement and providing valuable computational tools—all with minimal effort and cost.