analyze_formula
Analyzes mathematical properties of formulas, including domain, range, and critical points, to support mathematical visualization and computation.
Instructions
Analyzes mathematical properties of a formula (domain, range, critical points).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| formula | Yes | ||
| analysis_type | No | basic |
Implementation Reference
- src/main.py:173-197 (handler)The @mcp.tool()-decorated handler function that implements the core logic of 'analyze_formula'. It parses the formula with sympy, computes domain, range (for detailed), or critical points based on analysis_type, and returns formatted results.@mcp.tool() def analyze_formula(formula: str, analysis_type: AnalysisType = "basic") -> str: """Analyzes mathematical properties of a formula (domain, range, critical points).""" try: x = sympy.symbols('x') expr = sympy.sympify(formula) results = [f"Analysis for '{formula}' ('{analysis_type}' type):"] if analysis_type == "basic" or analysis_type == "detailed": domain = continuous_domain(expr, x, sympy.S.Reals) results.append(f"- Domain: {domain}") if analysis_type == "detailed": f_range = function_range(expr, x, domain) results.append(f"- Range: {f_range}") if analysis_type == "critical_points": derivative = sympy.diff(expr, x) results.append(f"- Derivative: {derivative}") critical_points = sympy.solveset(derivative, x, domain=sympy.S.Reals) if not critical_points: results.append("- Critical Points: None found.") else: results.append(f"- Critical Points: {critical_points}") return "\n".join(results) except Exception as e: return f"Error analyzing formula '{formula}'. Details: {e}"
- src/main.py:33-33 (schema)AnalysisType Literal type definition used for the analysis_type parameter in the tool's input schema, specifying 'basic', 'detailed', or 'critical_points'.AnalysisType = Literal["basic", "detailed", "critical_points"]