Skip to main content
Glama

collect_expression

Collect expression terms by specified variables, grouping by powers to simplify polynomials, extract coefficients, and prepare for numerical evaluation.

Instructions

    Collect terms by specified variable(s).

    ═══════════════════════════════════════════════════════════════════════
    🆕 PHASE 1 - NOT IN SYMPY-MCP OR NSFORGE v0.2.3!
    ═══════════════════════════════════════════════════════════════════════

    Groups expression by powers of variable, useful for:
    - Polynomial standard form
    - Coefficient extraction
    - Preparing for numerical evaluation

    Args:
        expression: Expression to collect
        variable: Variable(s) to collect by (string or list)
        evaluate: Evaluate coefficients (default: True)
        exact: Use exact arithmetic (default: False)

    Returns:
        Collected expression with LaTeX

    Examples:
        # Collect by x
        collect_expression("x*y + x - 3 + 2*x**2 - y*x**2 + x**3", "x")
        → {"result": "x**3 + x**2*(2 - y) + x*(y + 1) - 3", ...}

        # Extract polynomial coefficients
        collect_expression("a*x**2 + b*x + c + x**2", "x")
        → {"result": "x**2*(a + 1) + b*x + c", ...}

        # Multiple variables
        collect_expression("x*y + x*z + y*z", ["x", "y"])
        → Groups by x and y powers

        # PK: Collect by exp terms
        collect_expression("A*exp(-alpha*t) + B*exp(-beta*t)", "exp(-alpha*t)")
        → {"result": "A*exp(-alpha*t) + B*exp(-beta*t)", ...}
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exactNo
evaluateNo
variableYes
expressionYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses return format ('Collected expression with LaTeX'), default values for evaluate/exact, and demonstrates handling of single/multiple variables and exponential terms. Lacks explicit error behavior, but adequate for a pure computation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The main purpose is front-loaded, but the description includes decorative box-drawing, emojis, and an irrelevant version note ('PHASE 1 - NOT IN SYMPY-MCP...') that add noise. Examples are useful but the formatting reduces clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers functionality, parameters, return format, and provides multiple examples including edge cases (exp-term collection). Output schema exists but the description still explains the result structure. No error handling mentioned, but sufficient for expected use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema has zero descriptions for its 4 parameters. The description's Args section explains each parameter and examples illustrate types (string, list, expression term). This fully compensates for the schema coverage gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states the tool's function ('Collect terms by specified variable(s)') and describes grouping by powers, with use cases and examples. This distinguishes it from sibling tools like expand_expression or factor_expression.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides explicit use cases (polynomial standard form, coefficient extraction, numerical evaluation) and demonstrates usage with multiple variable types. Does not explicitly exclude alternatives, but context is clear and actionable.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/u9401066/nsforge-mcp'

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