Skip to main content
Glama

darboux_sum

Calculate upper or lower Darboux sums to approximate definite integrals by dividing functions into subintervals. Specify function, limits, and number of intervals for numerical integration.

Instructions

Calculate the Darboux sum of a function

Input Schema

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

Implementation Reference

  • The darbouxSum function is the core handler that computes the Darboux (upper or lower) sum approximation for the definite integral by parsing the expression with mathjs, evaluating at interval endpoints, selecting max/min values based on type, and summing with deltaX.
    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}`; } };
  • Zod schema defining the input parameters (expression, variable, a, b, n, type) and output as number or string (for errors).
    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()]),
  • index.js:304-322 (registration)
    ai.defineTool call that registers the 'darboux_sum' tool with Genkit, including description, schema, and async handler wrapper that delegates to darbouxSum function.
    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); } );

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