Summation

Symbolic or numeric summation Σ over an index variable across given bounds.

Endpoint: POST /api/v1/sum

When to use

Closed-form or numeric Σ. Bounds may be symbolic (e.g. `n`) for closed-form sums.

Input schema

Validated server-side with Zod. The same schema feeds OpenAPI and the MCP tool list.

{
  "type": "object",
  "properties": {
    "expression": {
      "type": "string",
      "minLength": 1
    },
    "variable": {
      "type": "string",
      "minLength": 1
    },
    "from": {
      "type": "string",
      "minLength": 1,
      "description": "Lower bound (numeric or symbolic)"
    },
    "to": {
      "type": "string",
      "minLength": 1,
      "description": "Upper bound (numeric or symbolic)"
    }
  },
  "required": [
    "expression",
    "variable",
    "from",
    "to"
  ],
  "additionalProperties": false
}

Response shape

All tools return { ok: true, result } on success and { ok: false, error } on failure. The result object contains:

FieldTypeDescription
resultstringResulting expression in nerdamer syntax.

Example

Request

{
  "expression": "k^2",
  "variable": "k",
  "from": "1",
  "to": "n"
}

Response

{
  "ok": true,
  "result": {
    "result": "sum(k^2,k,1,n)"
  }
}

curl

curl -X POST https://tools.aieo.se/api/v1/sum \
  -H 'Content-Type: application/json' \
  -d '{"expression":"k^2","variable":"k","from":"1","to":"n"}'

MCP call (JSON-RPC)

MCP clients call this tool as tools/call against /api/mcp:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "sum",
    "arguments": {
      "expression": "k^2",
      "variable": "k",
      "from": "1",
      "to": "n"
    }
  }
}

Common errors

  • Sum has no closed form with symbolic bounds.
    Returns an unevaluated `sum(…)` placeholder.
  • A required field is missing or has the wrong type.
    Zod validation error, e.g. `Required` or `Expected string, received number`.
  • Nerdamer cannot parse the expression (unbalanced parens, unknown function, stray characters).
    `Unexpected token …` or `… is not a valid expression`.