Skip to main content
Glama

darboux_sum

Compute the upper or lower Darboux sum for a function over a specified interval, dividing it into subintervals to approximate the integral.

Instructions

Calculate the Darboux sum of a function

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
aYesLower limit of integration
bYesUpper limit of integration
expressionYesFunction to integrate
nYesNumber of subintervals
typeNoType: upper or lower Darboux sumupper
variableYesVariable of integration

Implementation Reference

  • index.js:304-322 (registration)
    Registration of the 'darboux_sum' tool using ai.defineTool, including name, description, input/output schemas, and handler.
    ai.defineTool( { name: 'darboux_sum', description: 'Calculate the Darboux sum of a function', inputSchema: z.object({ expression: z.string().describe('Function to integrate'), variable: z.string().describe('Variable of integration'), a: z.number().describe('Lower limit of integration'), b: z.number().describe('Upper limit of integration'), n: z.number().describe('Number of subintervals'), type: z.enum(['upper', 'lower']).default('upper') .describe('Type: upper or lower Darboux sum') }), outputSchema: z.union([z.number(), z.string()]), }, async ({ expression, variable, a, b, n, type }) => { return darbouxSum(expression, variable, a, b, n, type); } );
  • The handler function for the darboux_sum tool, which delegates to the darbouxSum helper.
    async ({ expression, variable, a, b, n, type }) => { return darbouxSum(expression, variable, a, b, n, type); }
  • Input and output schema definitions for the darboux_sum tool using Zod.
    inputSchema: z.object({ expression: z.string().describe('Function to integrate'), variable: z.string().describe('Variable of integration'), a: z.number().describe('Lower limit of integration'), b: z.number().describe('Upper limit of integration'), n: z.number().describe('Number of subintervals'), type: z.enum(['upper', 'lower']).default('upper') .describe('Type: upper or lower Darboux sum') }), outputSchema: z.union([z.number(), z.string()]),
  • Helper function implementing the core Darboux (Riemann) sum logic: partitions interval [a,b] into n parts, evaluates expression at endpoints, uses max/min for upper/lower sums.
    const darbouxSum = (expr, variable, a, b, n, type = 'upper') => { try { const deltaX = (b - a) / n; let sum = 0; const node = math.parse(expr); const scope = {}; for (let i = 0; i < n; i++) { const x1 = a + i * deltaX; const x2 = x1 + deltaX; scope[variable] = x1; const y1 = math.evaluate(node, scope); scope[variable] = x2; const y2 = math.evaluate(node, scope); const value = type === 'upper' ? Math.max(y1, y2) : Math.min(y1, y2); sum += value * deltaX; } return sum; } catch (e) { return `Error: ${e.message}`; } };

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nbiish/mcp-calc-tools'

If you have feedback or need assistance with the MCP directory API, please join our Discord server