Skip to main content
Glama

expand_expression

Expand algebraic expressions including polynomial products, powers, and logarithms. Provides deterministic expansion for coefficient extraction and simplification.

Instructions

    Expand algebraic expression.

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

    DETERMINISTIC: Always expands products and powers (unlike `simplify()`).

    Use cases:
    - Expand polynomial products: (x+1)(x-1) → x²-1
    - Expand powers: (x+a)² → x²+2ax+a²
    - Prepare for coefficient extraction
    - Expand logarithms: log(xy) → log(x)+log(y)

    Args:
        expression: Expression to expand
        deep: Expand recursively into subexpressions (default: True)
        modulus: Modular arithmetic (for finite fields)
        power_base: Expand (x*y)^n → x^n*y^n (default: True)
        power_exp: Expand x^(a+b) → x^a*x^b (default: True)
        mul: Expand products (default: True)
        log: Expand log(xy) → log(x)+log(y) (default: True)
        multinomial: Use multinomial expansion (default: True)
        basic: Apply basic expansion rules (default: True)

    Returns:
        Expanded expression with LaTeX

    Examples:
        # Polynomial expansion
        expand_expression("(x + 1)**2")
        → {"result": "x**2 + 2*x + 1", ...}

        # Product expansion
        expand_expression("(x + y)*(x - y)")
        → {"result": "x**2 - y**2", ...}

        # Exponential expansion
        expand_expression("exp(x + y)")
        → {"result": "exp(x)*exp(y)", ...}

        # Log expansion
        expand_expression("log(x*y)")
        → {"result": "log(x) + log(y)", ...}

        # PK model: Expand dose calculation
        expand_expression("dose/(V1 + V2) * exp(-k*t)")
        → {"result": "dose*exp(-k*t)/(V1 + V2)", ...}

        # Michaelis-Menten expanded
        expand_expression("(V_max*S + V_max*I)/(K_m + S)")
        → {"result": "V_max*S/(K_m + S) + V_max*I/(K_m + S)", ...}
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
logNo
mulNo
deepNo
basicNo
modulusNo
power_expNo
expressionYes
power_baseNo
multinomialNo

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 of behavioral disclosure. It states determinism ('Always expands products and powers'), defines return format ('Expanded expression with LaTeX'), and provides multiple examples that illustrate output transformations. It does not discuss error handling or edge cases, but for a math expansion tool, the behavior is well characterized.

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

Conciseness4/5

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

The description is long but well-structured, using headers (Use cases, Args, Returns, Examples) and code blocks. It front-loads the core purpose and deterministic note before diving into details. The examples are extensive and valuable, though some (like the PK model and Michaelis-Menten) might be considered redundant; still, the organization keeps it readable.

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?

Given 9 parameters, an output schema, and many sibling tools, the description covers purpose, parameters, return format, and usage examples comprehensively. It also gives a comparative hint with simplify. However, it does not address potential limitations (e.g., unsupported expression types) or error conditions, which would make it more complete for an agent to handle edge cases.

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 description coverage is 0%, but the description's 'Args' section meticulously explains each of the 9 parameters, including the meaning of boolean flags (e.g., 'deep: Expand recursively', 'mul: Expand products') and the optional modulus for modular arithmetic. This fully compensates for the schema's lack of descriptions and adds semantic depth beyond the parameter names and types.

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?

The description opens with a specific verb and resource ('Expand algebraic expression') and further clarifies deterministic behavior ('Always expands products and powers unlike simplify()'), which clearly distinguishes it from sibling tools like simplify, factor, and collect. The use cases provide concrete examples of expansion types (polynomial, power, exponential, logarithmic), leaving no ambiguity about the tool's function.

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?

The description includes an explicit 'Use cases' section listing common scenarios (polynomial products, powers, coefficient extraction, logarithms) and contrasts with simplify(), giving clear contextual guidance. However, it does not explicitly mention when not to use this tool or name specific alternatives beyond simplify, leaving some nuance unaddressed.

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