Home/Tools/differentiate

Differentiate

Symbolically differentiate an expression with respect to a variable.

Endpoint: POST /api/v1/differentiate

When to use

Symbolically differentiate to arbitrary integer order (1–10).

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
    },
    "order": {
      "type": "integer",
      "minimum": 1,
      "maximum": 10,
      "default": 1
    }
  },
  "required": [
    "expression",
    "variable"
  ],
  "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": "sin(x) * x^2",
  "variable": "x",
  "order": 1
}

Response

{
  "ok": true,
  "result": {
    "result": "2*sin(x)*x+cos(x)*x^2"
  }
}

curl

curl -X POST https://tools.aieo.se/api/v1/differentiate \
  -H 'Content-Type: application/json' \
  -d '{"expression":"sin(x) * x^2","variable":"x","order":1}'

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": "differentiate",
    "arguments": {
      "expression": "sin(x) * x^2",
      "variable": "x",
      "order": 1
    }
  }
}

Common errors

  • `order` is outside 1–10.
    Zod validation error.
  • 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`.