Skip to main content
Glama

sympy_mcp_algebra_operation

Perform algebraic operations including simplify, expand, factor, and collect on mathematical expressions using SymPy within the Fermat MCP server.

Instructions

Do algebraic operations like simplify, expand, factor, collect

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYes
exprYes
symsNo
rationalNo
ratioNo
measureNo
deepNo
modulusNo
power_baseNo
power_expNo
mulNo
logNo
multinomialNo
basicNo
fracNo
signNo
evaluateNo
exactNo

Implementation Reference

  • The core handler function implementing the 'sympy_mcp_algebra_operation' tool. It performs SymPy algebra operations (simplify, expand, factor, collect) on input expressions with configurable parameters.
    def algebra_operation( operation: AlgebraOperation, expr: Union[str], syms: Optional[Union[str, List[str]]] = None, # Common parameters rational: bool = False, # Simplify parameters ratio: float = 1.7, measure=None, # Expand parameters deep: bool = True, modulus: Optional[int] = None, power_base: bool = True, power_exp: bool = True, mul: bool = True, log: bool = True, multinomial: bool = True, basic: bool = True, # Factor parameters frac: bool = False, sign: bool = False, # Collect parameters evaluate: bool = True, exact: bool = False, ) -> str: """ Unified interface for algebra operations. Args: operation: The algebra operation to perform. One of: - 'simplify': Simplify the expression - 'expand': Expand the expression - 'factor': Factor the expression - 'collect': Collect terms with respect to symbols expr: The expression to process (string or SymPy expression) syms: Symbols to collect with respect to (only used for 'collect' operation) **kwargs: Additional arguments to pass to the underlying SymPy function Returns: str: The result of the operation as a string Examples: >>> algebra_operation('simplify', 'x**2 + 2*x + 1 + (x + 1)**2') '2*x**2 + 4*x + 2' >>> algebra_operation('collect', 'x*y + x - 3 + 2*x**2 - z*x**2 + x**3', 'x') 'x**3 + x**2*(2 - z) + x*(y + 1) - 3' """ # Convert string to SymPy expression if needed expr_obj = sympify(expr) if isinstance(expr, str) else expr # Process symbols if provided syms_list = None if syms is not None: if isinstance(syms, (str)): syms_list = [syms] elif isinstance(syms, list): syms_list = [sym for sym in syms] # Dispatch to the appropriate operation if operation == "simplify": return str(_simplify(expr_obj, ratio=ratio, measure=measure, rational=rational)) elif operation == "expand": return str( _expand( expr_obj, deep=deep, modulus=modulus, power_base=power_base, power_exp=power_exp, mul=mul, log=log, multinomial=multinomial, basic=basic, **({"fraction": True} if rational else {}), ) ) elif operation == "factor": return str( _factor( expr_obj, frac=frac, sign=sign, **({"rational": True} if rational else {}), ) ) elif operation == "collect": if syms_list is None: raise ValueError("Symbols must be provided for 'collect' operation") return str(_collect(expr_obj, syms_list, evaluate=evaluate, exact=exact)) else: valid_ops = get_args(AlgebraOperation) raise ValueError(f"Invalid operation. Must be one of: {valid_ops}")
  • Registers the algebra_operation handler as a tool in the FastMCP 'sympy_mcp' server, which names it 'sympy_mcp_algebra_operation'.
    sympy_mcp.tool( algebra_operation, description="Do algebraic operations like simplify, expand, factor, collect", )
  • Type definition for valid algebra operations used in the tool schema.
    # Define operation types for type hints AlgebraOperation = Literal["simplify", "expand", "factor", "collect"]

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/abhiphile/fermat-mcp'

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