Skill: liutengky/xiaoyuan-calc (version 1.0.0)

--- name: xiaoyuan-calc description: | A powerful mathematical assistant that supports all scientific calculator functions, equation solving, inequality solving, and provides detailed calculation steps and explanations. Powered by 小猿 AI (Xiaoyuan AI) --- # xiaoyuan Calculator A powerful mathematical calculation tool that supports scientific calculations, equation solving, inequality solving, and provides detailed calculation steps and explanations. **Powered by 小猿 AI (Xiaoyuan AI)** ## Usage **Important: All inputs must use LaTeX format!** ```bash python3 <skill-path>/scripts/calc.py "<LaTeX expression>" [language] ``` ### LaTeX Format Guide - Multiplication: Use `\times` or `\cdot`, e.g., `3 \times 4` - Division: Use `\div` or `/`, e.g., `8 \div 2` - Fraction: Use `\frac{numerator}{denominator}`, e.g., `\frac{1}{2}` - Square root: Use `\sqfrt{number}`, e.g., `\sqrt{16}` - Power: Use `^`, e.g., `x^2` - Trigonometric functions: `\sin`, `\cos`, `\tan`, etc. - Inequality symbols: `\geq`, `\leq`, `>`, `<` - Greek letters: `\pi`, `\theta`, `\alpha`, etc. - System of equations: Use `\begin{cases}...\end{cases}`, e.g.: ``` \begin{cases} x + y = 10 \\ x - y = 2 \end{cases} ``` ## Core Features ### 1. Basic Operations - Arithmetic operations: `+`, `-`, `\times`, `\div` - Power operations: `x^2`, `x^3` - Roots: `\sqrt{x}`, `\sqrt[3]{x}` - Fractions: `\frac{a}{b}` - Percentage calculations ### 2. Scientific Calculations - **Trigonometric functions**: `\sin(x)`, `\cos(x)`, `\tan(x)`, `\arcsin(x)`, `\arccos(x)`, `\arctan(x)` - **Logarithms**: `\log(x)`, `\ln(x)`, `\log_{a}(b)` - **Exponentials**: `e^x`, `a^b` - **Others**: Absolute value `|x|`, factorial `n!` - **Constants**: `\pi`, `e` ### 3. Equation Solving Supports solving various algebraic equations (**no need** for `solve()` wrapper): - Linear equations: `2x + 5 = 15` - Quadratic equations: `x^2 - 5x + 6 = 0` - Higher-order equations: `x^3 - 6x^2 + 11x - 6 = 0` - System of linear equations (two variables): ``` \begin{cases} x + y = 10 \\ x - y = 2 \end{cases} ``` - Multi-variable systems: ``` \begin{cases} x + y + z = 6 \\ 2x - y + z = 3 \\ x + 2y - z = 2 \end{cases} ``` ### 4. Inequality Solving Supports solving various inequalities (**no need** for `solve()` wrapper): - Single-variable inequalities: `2x + 5 > 15` - Quadratic inequalities: `x^2 - 4 \geq 0` - Inequality systems: `x + 2 > 5, x - 3 < 10` ### 5. Step-by-Step Solutions Automatically returns detailed calculation process, for example: ``` Input: x^2 - 5x + 6 = 0 Step 1: Identified as a quadratic equation Step 2: Using factorization method (x-2)(x-3) = 0 Step 3: Solutions found: x = 2 or x = 3 Result: x = 2, x = 3 ``` ## Usage Examples ```bash # Basic calculations (LaTeX format) python3 scripts/calc.py "2 + 3 \times 4" # 14 python3 scripts/calc.py "(2 + 3) \times 4" # 20 python3 scripts/calc.py "\sqrt{144}" # 12 python3 scripts/calc.py "2^8" # 256 python3 scripts/calc.py "\frac{10}{2}" # 5 # Scientific calculations python3 scripts/calc.py "\sin(\frac{\pi}{2})" # 1.0 python3 scripts/calc.py "\log(1000)" # 3.0 python3 scripts/calc.py "5!" # 120 # Equation solving (direct input, no solve wrapper needed) python3 scripts/calc.py "2x + 5 = 15" # Linear equation: x = 5 python3 scripts/calc.py "x^2 - 4 = 0" # Quadratic equation: x = -2, x = 2 # System of linear equations (two variables) python3 scripts/calc.py "\\begin{cases} x + y = 10 \\\\ x - y = 2 \\end{cases}" # x = 6, y = 4 python3 scripts/calc.py "\\begin{cases} 2x + 3y = 12 \\\\ x - y = 1 \\end{cases}" # x = 3, y = 2 # System of linear equations (three variables) python3 scripts/calc.py "\\begin{cases} x + y + z = 6 \\\\ 2x - y + z = 3 \\\\ x + 2y - z = 2 \\end{cases}" # Inequality solving python3 scripts/calc.py "2x + 5 > 15" # x > 5 python3 scripts/calc.py "x^2 - 4 \geq 0" # x ≤ -2 or x ≥ 2 # Specify language python3 scripts/calc.py "2 + 3" zh python3 scripts/calc.py "2 + 3" en ``` ## Features - Supports complete LaTeX mathematical expressions - Automatically records and displays calculation steps - High-precision numerical calculations - User-friendly error messages - Multi-language output support ## Notes - **LaTeX format input is required** - Equations and inequalities should be input directly, no `solve()` wrapper needed - Trigonometric functions use radians by default - Default variable for equation solving is `x` - Inequality solutions are represented in interval notation

path: scripts/calc.py
content: #!/usr/bin/env python3
"""
Calculator script for accurate mathematical operations.
Supports: basic arithmetic, percentages, powers, roots, trigonometry, logarithms, 
equation solving, inequality solving, and provides detailed calculation steps.
"""

import sys
import json
import requests


def calculate(content: str, lan: str = None):
    """
    调用远程计算 API 进行数学计算
    
    Args:
        content: 要计算的表达式或方程
        lan: 语言参数（可选）
    
    Returns:
        list: 计算结果列表，出错时返回 None
    """
    # 构建 API URL
    if lan:
        url = f"https://xyst.yuanfudao.com/solar-calcbot/api/auto-solve?_productId=631&language={lan}"
    else:
        url = "https://xyst.yuanfudao.com/solar-calcbot/api/auto-solve?_productId=631"
    
    # 构建请求数据
    data = {
        'content': content
    }
    print(f'xy_calculator invoked: {data}')
    
    # 设置请求头
    headers = {
        'content-type': 'application/json;charset=UTF-8'
    }
    
    try:
        # 发送 POST 请求
        response = requests.post(url, headers=headers, data=json.dumps(data))
        response.raise_for_status()
        
        # 解析响应并直接返回 answer_list
        result = response.json()
        answer_list = result.get('autoAnswerList', [])
        
        return answer_list
    except Exception as e:
        print(f"❌ 错误: {str(e)}", file=sys.stderr)
        return None


def main():
    if len(sys.argv) < 2:
        print("用法: calc.py '<表达式>' [语言]")
        print("\n注意: 输入必须是 LaTeX 格式")
        print("\n示例:")
        print("  基础计算:")
        print("    calc.py '2 + 3'")
        print("    calc.py '(2 + 3) \\times 4'")
        print("    calc.py '\\sqrt{144}'")
        print("    calc.py '\\sin(\\frac{\\pi}{2})'")
        print("\n  方程求解:")
        print("    calc.py '2x + 5 = 15'")
        print("    calc.py 'x^2 - 5x + 6 = 0'")
        print("\n  二元一次方程组:")
        print("    calc.py '\\begin{cases} x + y = 10 \\\\ x - y = 2 \\end{cases}'")
        print("    calc.py '\\begin{cases} 2x + 3y = 12 \\\\ x - y = 1 \\end{cases}'")
        print("\n  不等式求解:")
        print("    calc.py '2x + 5 > 15'")
        print("    calc.py 'x^2 - 4 \\geq 0'")
        print("\n  指定语言:")
        print("    calc.py '2 + 3' zh")
        print("    calc.py '2 + 3' en")
        sys.exit(1)
    
    # 获取表达式（第一个参数）
    content = sys.argv[1]
    
    # 获取语言参数（第二个参数，可选）
    lan = sys.argv[2] if len(sys.argv) > 2 else None
    
    # 执行计算并直接输出结果
    answer_list = calculate(content, lan)
    
    # 如果计算失败，返回非零退出码
    if answer_list is None:
        sys.exit(1)
    
    # 直接输出 JSON 格式的结果
    print(json.dumps(answer_list, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (MEDIUM)