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
| Name | Required | Description | Default |
|---|---|---|---|
| context | No | Optional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification. | |
| output_mode | No | Output format: full (default), compact, minimal, value, or final. See batch_execute tool for details. | full |
| expression | Yes | Mathematical expression to analyse (e.g., 'sin(x)/x', 'exp(x)') | |
| variable | Yes | Variable for limit/expansion (e.g., 'x', 't') | |
| point | Yes | Point for limit/expansion (number, 'oo' for infinity, '-oo' for -infinity) | |
| operation | No | Operation: limit=compute limit, series=Taylor/Maclaurin expansion | limit |
| order | No | Series expansion order (number of terms) | |
| direction | No | Limit direction: +=from right, -=from left, +-=both sides | +- |
Input Schema (JSON Schema)
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, ), )
- src/vibe_math_mcp/server.py:693-693 (registration)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