limit
Calculate the limit of a function as it approaches a specific value to analyze mathematical behavior and continuity.
Instructions
Calculate the limit of a function as it approaches a value
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes | Function to evaluate limit | |
| variable | Yes | Variable approaching the limit | |
| approach | Yes | Value the variable approaches |
Implementation Reference
- index.js:335-337 (handler)The handler function passed to ai.defineTool, which destructures inputs and calls the findLimit helper.async ({ expression, variable, approach }) => { return findLimit(expression, variable, approach); }
- index.js:328-333 (schema)Zod schemas defining the input parameters (expression, variable, approach) and output (number or string).inputSchema: z.object({ expression: z.string().describe('Function to evaluate limit'), variable: z.string().describe('Variable approaching the limit'), approach: z.number().describe('Value the variable approaches') }), outputSchema: z.union([z.number(), z.string()]),
- index.js:324-338 (registration)ai.defineTool call that registers the 'limit' tool with name, description, schema, and handler function.ai.defineTool( { name: 'limit', description: 'Calculate the limit of a function as it approaches a value', inputSchema: z.object({ expression: z.string().describe('Function to evaluate limit'), variable: z.string().describe('Variable approaching the limit'), approach: z.number().describe('Value the variable approaches') }), outputSchema: z.union([z.number(), z.string()]), }, async ({ expression, variable, approach }) => { return findLimit(expression, variable, approach); } );
- index.js:279-301 (helper)Supporting function that parses the math expression, evaluates it from left and right of the approach value using mathjs, averages if convergent within epsilon, else returns message or error.const findLimit = (expr, variable, approach) => { try { const node = math.parse(expr); const scope = {}; const epsilon = 1e-10; // Evaluate near the approach point scope[variable] = approach + epsilon; const rightLimit = math.evaluate(node, scope); scope[variable] = approach - epsilon; const leftLimit = math.evaluate(node, scope); // Check if limits from both sides are approximately equal if (Math.abs(rightLimit - leftLimit) < epsilon) { return (rightLimit + leftLimit) / 2; } return 'Limit does not exist'; } catch (e) { return `Error: ${e.message}`; } };