Skip to main content
Glama
by apetta

limits_series

Compute limits and generate Taylor/Maclaurin series expansions for mathematical expressions using SymPy. Analyze function behavior at specific points or infinity.

Instructions

Compute limits and series expansions using SymPy.

Examples:

CLASSIC LIMIT: expression="sin(x)/x", variable="x", point=0, operation="limit" Result: limit=1

LIMIT AT INFINITY: expression="1/x", variable="x", point="oo", operation="limit" Result: limit=0

ONE-SIDED LIMIT: expression="1/x", variable="x", point=0, operation="limit", direction="+" Result: limit=+∞ (approaching from right)

REMOVABLE DISCONTINUITY: expression="(x^2-1)/(x-1)", variable="x", point=1, operation="limit" Result: limit=2

MACLAURIN SERIES (at 0): expression="exp(x)", variable="x", point=0, operation="series", order=4 Result: "1 + x + x^2/2 + x^3/6 + O(x^4)"

TAYLOR SERIES (at point): expression="sin(x)", variable="x", point=3.14159, operation="series", order=4 Result: expansion around π

Input Schema

NameRequiredDescriptionDefault
contextNoOptional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification.
output_modeNoOutput format: full (default), compact, minimal, value, or final. See batch_execute tool for details.full
expressionYesMathematical expression to analyse (e.g., 'sin(x)/x', 'exp(x)')
variableYesVariable for limit/expansion (e.g., 'x', 't')
pointYesPoint for limit/expansion (number, 'oo' for infinity, '-oo' for -infinity)
operationNoOperation: limit=compute limit, series=Taylor/Maclaurin expansionlimit
orderNoSeries expansion order (number of terms)
directionNoLimit direction: +=from right, -=from left, +-=both sides+-

Input Schema (JSON Schema)

{ "properties": { "context": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification." }, "direction": { "default": "+-", "description": "Limit direction: +=from right, -=from left, +-=both sides", "enum": [ "+", "-", "+-" ], "type": "string" }, "expression": { "description": "Mathematical expression to analyse (e.g., 'sin(x)/x', 'exp(x)')", "minLength": 1, "type": "string" }, "operation": { "default": "limit", "description": "Operation: limit=compute limit, series=Taylor/Maclaurin expansion", "enum": [ "limit", "series" ], "type": "string" }, "order": { "default": 6, "description": "Series expansion order (number of terms)", "minimum": 1, "type": "integer" }, "output_mode": { "default": "full", "description": "Output format: full (default), compact, minimal, value, or final. See batch_execute tool for details.", "enum": [ "full", "compact", "minimal", "value", "final" ], "type": "string" }, "point": { "anyOf": [ { "type": "number" }, { "type": "string" } ], "description": "Point for limit/expansion (number, 'oo' for infinity, '-oo' for -infinity)" }, "variable": { "description": "Variable for limit/expansion (e.g., 'x', 't')", "minLength": 1, "type": "string" } }, "required": [ "expression", "point", "variable" ], "type": "object" }

Implementation Reference

  • The main handler function for the 'limits_series' tool. Computes limits at points (including infinity and one-sided) and Taylor/Maclaurin series expansions using SymPy's limit and series functions. Formats results with metadata.
    async def limits_series( expression: Annotated[ str, Field( description="Mathematical expression to analyse (e.g., 'sin(x)/x', 'exp(x)')", min_length=1, ), ], variable: Annotated[ str, Field(description="Variable for limit/expansion (e.g., 'x', 't')", min_length=1) ], point: Annotated[ Union[float, str], Field( description="Point for limit/expansion (number, 'oo' for infinity, '-oo' for -infinity)" ), ], operation: Annotated[ Literal["limit", "series"], Field(description="Operation: limit=compute limit, series=Taylor/Maclaurin expansion"), ] = "limit", order: Annotated[int, Field(description="Series expansion order (number of terms)", ge=1)] = 6, direction: Annotated[ Literal["+", "-", "+-"], Field(description="Limit direction: +=from right, -=from left, +-=both sides"), ] = "+-", ) -> str: """Compute limits (lim[x→a]f(x)) and Taylor/Maclaurin series expansions using SymPy. Handles infinity, one-sided limits, removable discontinuities.""" try: expr = sympify(expression) var = Symbol(variable) # Handle infinity if point == "oo" or point == "inf": point_sym = oo elif point == "-oo" or point == "-inf": point_sym = -oo else: point_sym = float(point) if operation == "limit": if direction == "+-": # Two-sided limit result = limit(expr, var, point_sym) else: # One-sided limit result = limit(expr, var, point_sym, direction) # Limit value is the primary result limit_str = str(result) metadata = { "expression": expression, "variable": variable, "point": str(point), "direction": direction, "numeric_value": float(N(result)) if result.is_number else None, } return format_result(limit_str, metadata) elif operation == "series": # Series expansion series_expr = series(expr, var, point_sym, order) # type: ignore[arg-type] series_str = str(series_expr) # Remove O() term for cleaner output series_no_o = series_expr.removeO() # Series string is the primary result metadata = { "expression": expression, "variable": variable, "point": str(point), "order": order, "series_without_O": str(series_no_o), } return format_result(series_str, metadata) else: raise ValueError(f"Unknown operation: {operation}") except Exception as e: raise ValueError( f"Limit/series calculation failed: {str(e)}. " f"Example: expression='sin(x)/x', variable='x', point=0, operation='limit'" )
  • Pydantic schema and tool metadata definition for the limits_series tool, including input parameters with descriptions, examples, and annotations.
    @mcp.tool( name="limits_series", description="""Compute limits and series expansions using SymPy. Examples: CLASSIC LIMIT: expression="sin(x)/x", variable="x", point=0, operation="limit" Result: limit=1 LIMIT AT INFINITY: expression="1/x", variable="x", point="oo", operation="limit" Result: limit=0 ONE-SIDED LIMIT: expression="1/x", variable="x", point=0, operation="limit", direction="+" Result: limit=+∞ (approaching from right) REMOVABLE DISCONTINUITY: expression="(x^2-1)/(x-1)", variable="x", point=1, operation="limit" Result: limit=2 MACLAURIN SERIES (at 0): expression="exp(x)", variable="x", point=0, operation="series", order=4 Result: "1 + x + x^2/2 + x^3/6 + O(x^4)" TAYLOR SERIES (at point): expression="sin(x)", variable="x", point=3.14159, operation="series", order=4 Result: expansion around π""", annotations=ToolAnnotations( title="Limits and Series", readOnlyHint=True, idempotentHint=True, ), )
  • Import of the 'calculus' module which registers the limits_series tool via its @mcp.tool decorator when the server initializes.
    from .tools import array, basic, batch, calculus, financial, linalg, statistics # noqa: E402

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/apetta/vibe-math-mcp'

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