limit
Calculate the limit of a function as a variable approaches a specific value. Ideal for analyzing mathematical behavior and solving calculus problems.
Instructions
Calculate the limit of a function as it approaches a value
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| approach | Yes | Value the variable approaches | |
| expression | Yes | Function to evaluate limit | |
| variable | Yes | Variable approaching the limit |
Implementation Reference
- index.js:324-338 (registration)Registration of the 'limit' MCP tool using ai.defineTool, specifying name, description, input/output schemas, and handler function that delegates to findLimit.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:328-333 (schema)Input schema defines parameters: expression (string), variable (string), approach (number). Output schema is union of 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:279-301 (handler)Core handler logic: parses the expression, evaluates it at points epsilon away from the approach value from both sides, averages if they match within epsilon, else reports limit does not exist 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}`; } };