derivative
Compute the derivative of a mathematical expression with respect to a specified variable. Simplify calculus tasks and solve differentiation problems efficiently.
Instructions
Calculate the derivative of a mathematical expression
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes | Mathematical expression (e.g., "x^2", "e^x", "sin(x)") | |
| variable | No | Variable to differentiate with respect to (default: x) |
Implementation Reference
- index.js:9-17 (handler)Core handler logic for the 'derivative' tool: parses mathematical expression and computes symbolic derivative using mathjs.const derivative = (expr, variable = 'x') => { try { const node = math.parse(expr); const derivativeExpr = math.derivative(node, variable); return derivativeExpr.toString(); } catch (e) { return `Error: ${e.message}`; } };
- index.js:82-88 (schema)Input/output schema for the derivative tool: requires expression string, optional variable, returns string result.name: 'derivative', description: 'Calculate the derivative of a mathematical expression', inputSchema: z.object({ expression: z.string().describe('Mathematical expression (e.g., "x^2", "e^x", "sin(x)")'), variable: z.string().optional().describe('Variable to differentiate with respect to (default: x)') }), outputSchema: z.string(),
- index.js:80-93 (registration)Registration of the 'derivative' tool using ai.defineTool, including schema definition and handler reference.ai.defineTool( { name: 'derivative', description: 'Calculate the derivative of a mathematical expression', inputSchema: z.object({ expression: z.string().describe('Mathematical expression (e.g., "x^2", "e^x", "sin(x)")'), variable: z.string().optional().describe('Variable to differentiate with respect to (default: x)') }), outputSchema: z.string(), }, async ({ expression, variable = 'x' }) => { return derivative(expression, variable); } );