/// The syntax both Mathematics tools read, described for the model.
/// </summary>
internalconststringSYNTAX="Plain syntax, not LaTeX: + - * / ^ and ! for the factorial, with every multiplication written as *, e.g., 2*pi*x. Functions take their arguments in parentheses: sqrt, exp, ln, log(x) to base 10, log(b, x) to base b, sin, cos, tan, arcsin, arccos, arctan, sinh, cosh, tanh, abs, floor, ceil, gamma, binomial(n, k), gcd(a, b), lcm(a, b), erf. Constants are pi, e, and i; infinity is +oo or -oo. A definite integral is integral(f, x, a, b), a limit limit(f, x, a), and a sum sum(f, k, a, b) over the integers k from a to b. A sum is computed only in closed form, such as for powers of k; any other sum has to be written out term by term. Not-equal is written <>, and | is not an operator.";
DescriptionForLLM="Evaluate a mathematical expression locally, exactly where possible: fractions stay exact, and a decimal carries only the digits the computation vouches for. Definite integrals, also over infinite intervals, are integrated numerically. An expression with one '=' is an equation, whose two sides are evaluated and compared.",
Parameters=ToolParameterSchemaBuilder.Create()
.RequiredString(EXPRESSION_ARGUMENT,$"The expression, without variables except those bound by an integral or a limit. {SYNTAX} Example: integral(x^3/(e^x - 1), x, 0, +oo) = pi^4/15")
.OptionalInteger(DIGITS_ARGUMENT,$"Optional: how many significant digits the decimal should have, from 1 to {MathLimits.MAX_DIGITS}. Fewer come back when the computation cannot vouch for more, e.g., about 14 after a numerical integration. Leave it out to get {DEFAULT_DIGITS}.")
publicstringGetDescription()=>TA("Lets the AI calculate exactly instead of guessing digits, e.g., fractions, roots, or integrals, and check an equation. Everything is computed on your computer.");
vardigits=ToolArgumentReader.ReadOptionalPositiveInt(arguments,DIGITS_ARGUMENT,$"to get {DEFAULT_DIGITS} significant digits");
if(digitsisnull)
returnDEFAULT_DIGITS;
if(digits>MathLimits.MAX_DIGITS)
thrownewArgumentException($"Argument '{DIGITS_ARGUMENT}' must be at most {MathLimits.MAX_DIGITS}, but was {digits}. Leave it out to get {DEFAULT_DIGITS} significant digits.");
returndigits.Value;
}
/// <summary>
/// Evaluates the expression, or both sides of an equation, and writes the result for the model.