diff options
| author | Yuren Hao <yurenh2@timan108.cs.illinois.edu> | 2025-09-04 22:16:22 -0500 |
|---|---|---|
| committer | Yuren Hao <yurenh2@timan108.cs.illinois.edu> | 2025-09-04 22:16:22 -0500 |
| commit | fc6d57ffb8d5ddb5820fcc00b5491a585c259ebc (patch) | |
| tree | e9841f93a353e2107225cfc721d1ce57c0e594dc /Qwen2.5-Eval/evaluation/latex2sympy/tests | |
Initial commit
Diffstat (limited to 'Qwen2.5-Eval/evaluation/latex2sympy/tests')
24 files changed, 1469 insertions, 0 deletions
diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/__init__.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/__init__.py new file mode 100755 index 0000000..e69de29 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/__init__.py diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/abs_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/abs_test.py new file mode 100755 index 0000000..37d130c --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/abs_test.py @@ -0,0 +1,19 @@ +from .context import assert_equal, get_simple_examples +import pytest +from sympy import Abs + +examples = get_simple_examples(Abs) + +delimiter_pairs = { + '|': '|', + '\\vert': '\\vert', + '\\lvert': '\\rvert' +} + + +@pytest.mark.parametrize('input, output, symbolically', examples) +def test_abs(input, output, symbolically): + for left, right in delimiter_pairs.items(): + assert_equal("{left}{input}{right}".format(left=left, right=right, input=input), output, symbolically=symbolically) + assert_equal("\\left{left}{input}\\right{right}".format(left=left, right=right, input=input), output, symbolically=symbolically) + assert_equal("\\mleft{left}{input}\\mright{right}".format(left=left, right=right, input=input), output, symbolically=symbolically) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/all_bad_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/all_bad_test.py new file mode 100755 index 0000000..b136313 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/all_bad_test.py @@ -0,0 +1,70 @@ +from .context import assert_equal, process_sympy +import pytest + + +def pytest_generate_tests(metafunc): + metafunc.parametrize('s', metafunc.cls.BAD_STRINGS) + + +class TestAllBad(object): + # These bad latex strings should raise an exception when parsed + BAD_STRINGS = [ + "(", + ")", + # "a / b /", + "\\frac{d}{dx}", + "(\\frac{d}{dx})" + "\\sqrt{}", + "\\sqrt", + "{", + "}", + # "1.1.1", + "\\mathit{TEST}" + "\\frac{2}{}", + "\\frac{}{2}", + "\\int", + # "1 +", + # "a +", + "!", + "!0", + "_", + "^", + # "a // b", + # "a \\cdot \\cdot b", + # "a \\div \\div b", + "a\\mod \\begin{matrix}b\\end{matrix}" + "|", + "||x|", + "\\lfloor x", + "\\lfloor a \\rceil", + "\\operatorname{floor}(12.3, 123.4)", + "()", + "((((((((((((((((()))))))))))))))))", + "-", + "\\frac{d}{dx} + \\frac{d}{dt}", + # "f()", + # "f(,", + # "f(x,,y)", + # "f(x,y,", + "\\sin^x", + "\\cos^2", + # "\\cos 1 \\cos", + # "\\gcd(3)", + # "\\lcm(2)", + "@", "#", "$", "%", "&", "*", + "\\", + "~", + "\\frac{(2 + x}{1 - x)}", + "\\lim_{\\pi \\to 3} a", + # because mix of COMMA and SEMICOLON + "\\left\\{\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix},\\begin{pmatrix}4\\\\3\\\\1\\end{pmatrix};\\begin{pmatrix}1\\\\1\\\\1\\end{pmatrix}\\right\\}", + # percentages without numbers before-hand + "a\\%", + "\\%100", + # dollar signs without numbers after + "\\$" + ] + + def test_bad_string(self, s): + with pytest.raises(Exception): + process_sympy(s) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/all_good_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/all_good_test.py new file mode 100755 index 0000000..6d8aa1d --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/all_good_test.py @@ -0,0 +1,284 @@ +from .context import assert_equal, process_sympy, _Add, _Mul, _Pow +import pytest +import hashlib +from sympy import ( + E, I, oo, pi, sqrt, root, Symbol, Add, Mul, Pow, Abs, factorial, log, Eq, Ne, S, Rational, Integer, UnevaluatedExpr, + sin, cos, tan, sinh, cosh, tanh, asin, acos, atan, asinh, acosh, atanh, + csc, sec, Sum, Product, Limit, Integral, Derivative, + LessThan, StrictLessThan, GreaterThan, StrictGreaterThan, + exp, binomial, Matrix, MatMul, MatAdd, + Mod, gcd, lcm, floor, ceiling, Max, Min +) + +x = Symbol('x', real=True) +y = Symbol('y', real=True) +z = Symbol('z', real=True) +a = Symbol('a', real=True) +b = Symbol('b', real=True) +c = Symbol('c', real=True) +f = Symbol('f', real=True) +t = Symbol('t', real=True) +k = Symbol('k', real=True) +n = Symbol('n', real=True) +theta = Symbol('theta', real=True) + +# shorthand definitions + + +def _Abs(a): + return Abs(a, evaluate=False) + + +def _factorial(a): + return factorial(a, evaluate=False) + + +def _log(a, b): + return log(a, b, evaluate=False) + + +def pytest_generate_tests(metafunc): + metafunc.parametrize('s, eq', metafunc.cls.GOOD_PAIRS) + + +class TestAllGood(object): + # These latex strings should parse to the corresponding SymPy expression + GOOD_PAIRS = [ + ("0", 0), + ("1", 1), + ("-3.14", -3.14), + ("5-3", _Add(5, -3)), + ("(-7.13)(1.5)", _Mul(Rational('-7.13'), Rational('1.5'))), + ("\\left(-7.13\\right)\\left(1.5\\right)", _Mul(Rational('-7.13'), Rational('1.5'))), + ("x", x), + ("2x", 2 * x), + ("x^2", x**2), + ("x^{3 + 1}", x**_Add(3, 1)), + ("x^{\\left\\{3 + 1\\right\\}}", x**_Add(3, 1)), + ("-3y + 2x", _Add(_Mul(2, x), Mul(-1, 3, y, evaluate=False))), + ("-c", -c), + ("a \\cdot b", a * b), + ("a / b", a / b), + ("a \\div b", a / b), + ("a + b", a + b), + ("a + b - a", Add(a, b, _Mul(-1, a), evaluate=False)), + ("a^2 + b^2 = c^2", Eq(a**2 + b**2, c**2)), + ("a^2 + b^2 != 2c^2", Ne(a**2 + b**2, 2 * c**2)), + ("a\\mod b", Mod(a, b)), + ("\\sin \\theta", sin(theta)), + ("\\sin(\\theta)", sin(theta)), + ("\\sin\\left(\\theta\\right)", sin(theta)), + ("\\sin^{-1} a", asin(a)), + ("\\sin a \\cos b", _Mul(sin(a), cos(b))), + ("\\sin \\cos \\theta", sin(cos(theta))), + ("\\sin(\\cos \\theta)", sin(cos(theta))), + ("\\arcsin(a)", asin(a)), + ("\\arccos(a)", acos(a)), + ("\\arctan(a)", atan(a)), + ("\\sinh(a)", sinh(a)), + ("\\cosh(a)", cosh(a)), + ("\\tanh(a)", tanh(a)), + ("\\sinh^{-1}(a)", asinh(a)), + ("\\cosh^{-1}(a)", acosh(a)), + ("\\tanh^{-1}(a)", atanh(a)), + ("\\arcsinh(a)", asinh(a)), + ("\\arccosh(a)", acosh(a)), + ("\\arctanh(a)", atanh(a)), + ("\\arsinh(a)", asinh(a)), + ("\\arcosh(a)", acosh(a)), + ("\\artanh(a)", atanh(a)), + ("\\operatorname{arcsinh}(a)", asinh(a)), + ("\\operatorname{arccosh}(a)", acosh(a)), + ("\\operatorname{arctanh}(a)", atanh(a)), + ("\\operatorname{arsinh}(a)", asinh(a)), + ("\\operatorname{arcosh}(a)", acosh(a)), + ("\\operatorname{artanh}(a)", atanh(a)), + ("\\operatorname{gcd}(a, b)", UnevaluatedExpr(gcd(a, b))), + ("\\operatorname{lcm}(a, b)", UnevaluatedExpr(lcm(a, b))), + ("\\operatorname{gcd}(a,b)", UnevaluatedExpr(gcd(a, b))), + ("\\operatorname{lcm}(a,b)", UnevaluatedExpr(lcm(a, b))), + ("\\operatorname{floor}(a)", floor(a)), + ("\\operatorname{ceil}(b)", ceiling(b)), + ("\\cos^2(x)", cos(x)**2), + ("\\cos(x)^2", cos(x)**2), + ("\\gcd(a, b)", UnevaluatedExpr(gcd(a, b))), + ("\\lcm(a, b)", UnevaluatedExpr(lcm(a, b))), + ("\\gcd(a,b)", UnevaluatedExpr(gcd(a, b))), + ("\\lcm(a,b)", UnevaluatedExpr(lcm(a, b))), + ("\\floor(a)", floor(a)), + ("\\ceil(b)", ceiling(b)), + ("\\max(a, b)", Max(a, b)), + ("\\min(a, b)", Min(a, b)), + ("\\frac{a}{b}", a / b), + ("\\frac{a + b}{c}", _Mul(a + b, _Pow(c, -1))), + ("\\frac{7}{3}", _Mul(7, _Pow(3, -1))), + ("(\\csc x)(\\sec y)", csc(x) * sec(y)), + ("\\lim_{x \\to 3} a", Limit(a, x, 3)), + ("\\lim_{x \\rightarrow 3} a", Limit(a, x, 3)), + ("\\lim_{x \\Rightarrow 3} a", Limit(a, x, 3)), + ("\\lim_{x \\longrightarrow 3} a", Limit(a, x, 3)), + ("\\lim_{x \\Longrightarrow 3} a", Limit(a, x, 3)), + ("\\lim_{x \\to 3^{+}} a", Limit(a, x, 3, dir='+')), + ("\\lim_{x \\to 3^{-}} a", Limit(a, x, 3, dir='-')), + ("\\infty", oo), + ("\\infty\\%", oo), + ("\\$\\infty", oo), + ("-\\infty", -oo), + ("-\\infty\\%", -oo), + ("-\\$\\infty", -oo), + ("\\lim_{x \\to \\infty} \\frac{1}{x}", Limit(_Mul(1, _Pow(x, -1)), x, oo)), + ("\\frac{d}{dx} x", Derivative(x, x)), + ("\\frac{d}{dt} x", Derivative(x, t)), + # ("f(x)", f(x)), + # ("f(x, y)", f(x, y)), + # ("f(x, y, z)", f(x, y, z)), + # ("\\frac{d f(x)}{dx}", Derivative(f(x), x)), + # ("\\frac{d\\theta(x)}{dx}", Derivative(theta(x), x)), + ("|x|", _Abs(x)), + ("\\left|x\\right|", _Abs(x)), + ("||x||", _Abs(Abs(x))), + ("|x||y|", _Abs(x) * _Abs(y)), + ("||x||y||", _Abs(_Abs(x) * _Abs(y))), + ("\\lfloor x\\rfloor", floor(x)), + ("\\lceil y\\rceil", ceiling(y)), + ("\\pi^{|xy|}", pi**_Abs(x * y)), + ("\\frac{\\pi}{3}", _Mul(pi, _Pow(3, -1))), + ("\\sin{\\frac{\\pi}{2}}", sin(_Mul(pi, _Pow(2, -1)), evaluate=False)), + ("a+bI", a + I * b), + ("e^{I\\pi}", -1), + ("\\int x dx", Integral(x, x)), + ("\\int x d\\theta", Integral(x, theta)), + ("\\int (x^2 - y)dx", Integral(x**2 - y, x)), + ("\\int x + a dx", Integral(_Add(x, a), x)), + ("\\int da", Integral(1, a)), + ("\\int_0^7 dx", Integral(1, (x, 0, 7))), + ("\\int_a^b x dx", Integral(x, (x, a, b))), + ("\\int^b_a x dx", Integral(x, (x, a, b))), + ("\\int_{a}^b x dx", Integral(x, (x, a, b))), + ("\\int^{b}_a x dx", Integral(x, (x, a, b))), + ("\\int_{a}^{b} x dx", Integral(x, (x, a, b))), + ("\\int_{ }^{}x dx", Integral(x, x)), + ("\\int^{ }_{ }x dx", Integral(x, x)), + ("\\int^{b}_{a} x dx", Integral(x, (x, a, b))), + # ("\\int_{f(a)}^{f(b)} f(z) dz", Integral(f(z), (z, f(a), f(b)))), + ("\\int (x+a)", Integral(_Add(x, a), x)), + ("\\int a + b + c dx", Integral(Add(a, b, c, evaluate=False), x)), + ("\\int \\frac{dz}{z}", Integral(Pow(z, -1), z)), + ("\\int \\frac{3 dz}{z}", Integral(3 * Pow(z, -1), z)), + ("\\int \\frac{1}{x} dx", Integral(Pow(x, -1), x)), + ("\\int \\frac{1}{a} + \\frac{1}{b} dx", Integral(_Add(_Pow(a, -1), Pow(b, -1)), x)), + ("\\int \\frac{3 \\cdot d\\theta}{\\theta}", Integral(3 * _Pow(theta, -1), theta)), + ("\\int \\frac{1}{x} + 1 dx", Integral(_Add(_Pow(x, -1), 1), x)), + ("x_0", Symbol('x_0', real=True)), + ("x_{1}", Symbol('x_1', real=True)), + ("x_a", Symbol('x_a', real=True)), + ("x_{b}", Symbol('x_b', real=True)), + ("h_\\theta", Symbol('h_{\\theta}', real=True)), + ("h_\\theta ", Symbol('h_{\\theta}', real=True)), + ("h_{\\theta}", Symbol('h_{\\theta}', real=True)), + # ("h_{\\theta}(x_0, x_1)", Symbol('h_{theta}', real=True)(Symbol('x_{0}', real=True), Symbol('x_{1}', real=True))), + ("x!", _factorial(x)), + ("100!", _factorial(100)), + ("\\theta!", _factorial(theta)), + ("(x + 1)!", _factorial(_Add(x, 1))), + ("\\left(x + 1\\right)!", _factorial(_Add(x, 1))), + ("(x!)!", _factorial(_factorial(x))), + ("x!!!", _factorial(_factorial(_factorial(x)))), + ("5!7!", _Mul(_factorial(5), _factorial(7))), + ("\\sqrt{x}", sqrt(x)), + ("\\sqrt{x + b}", sqrt(_Add(x, b))), + ("\\sqrt[3]{\\sin x}", root(sin(x), 3)), + ("\\sqrt[y]{\\sin x}", root(sin(x), y)), + ("\\sqrt[\\theta]{\\sin x}", root(sin(x), theta)), + ("x < y", StrictLessThan(x, y)), + ("x \\leq y", LessThan(x, y)), + ("x > y", StrictGreaterThan(x, y)), + ("x \\geq y", GreaterThan(x, y)), + ("\\sum_{k = 1}^{3} c", Sum(c, (k, 1, 3))), + ("\\sum_{k = 1}^3 c", Sum(c, (k, 1, 3))), + ("\\sum^{3}_{k = 1} c", Sum(c, (k, 1, 3))), + ("\\sum^3_{k = 1} c", Sum(c, (k, 1, 3))), + ("\\sum_{k = 1}^{10} k^2", Sum(k**2, (k, 1, 10))), + ("\\sum_{n = 0}^{\\infty} \\frac{1}{n!}", Sum(_Pow(_factorial(n), -1), (n, 0, oo))), + ("\\prod_{a = b}^{c} x", Product(x, (a, b, c))), + ("\\prod_{a = b}^c x", Product(x, (a, b, c))), + ("\\prod^{c}_{a = b} x", Product(x, (a, b, c))), + ("\\prod^c_{a = b} x", Product(x, (a, b, c))), + ("\\ln x", _log(x, E)), + ("\\ln xy", _log(x * y, E)), + ("\\log x", _log(x, 10)), + ("\\log xy", _log(x * y, 10)), + # ("\\log_2 x", _log(x, 2)), + ("\\log_{2} x", _log(x, 2)), + # ("\\log_a x", _log(x, a)), + ("\\log_{a} x", _log(x, a)), + ("\\log_{11} x", _log(x, 11)), + ("\\log_{a^2} x", _log(x, _Pow(a, 2))), + ("[x]", x), + ("[a + b]", _Add(a, b)), + ("\\frac{d}{dx} [ \\tan x ]", Derivative(tan(x), x)), + ("2\\overline{x}", 2 * Symbol('xbar', real=True)), + ("2\\overline{x}_n", 2 * Symbol('xbar_n', real=True)), + ("\\frac{x}{\\overline{x}_n}", x / Symbol('xbar_n', real=True)), + ("\\frac{\\sin(x)}{\\overline{x}_n}", sin(Symbol('x', real=True)) / Symbol('xbar_n', real=True)), + ("2\\bar{x}", 2 * Symbol('xbar', real=True)), + ("2\\bar{x}_n", 2 * Symbol('xbar_n', real=True)), + ("\\sin\\left(\\theta\\right) \\cdot4", sin(theta) * 4), + ("\\ln\\left(\\theta\\right)", _log(theta, E)), + ("\\ln\\left(x-\\theta\\right)", _log(x - theta, E)), + ("\\ln\\left(\\left(x-\\theta\\right)\\right)", _log(x - theta, E)), + ("\\ln\\left(\\left[x-\\theta\\right]\\right)", _log(x - theta, E)), + ("\\ln\\left(\\left\\{x-\\theta\\right\\}\\right)", _log(x - theta, E)), + ("\\ln\\left(\\left|x-\\theta\\right|\\right)", _log(_Abs(x - theta), E)), + ("\\frac{1}{2}xy(x+y)", Mul(_Pow(2, -1), x, y, (x + y), evaluate=False)), + ("\\frac{1}{2}\\theta(x+y)", Mul(_Pow(2, -1), theta, (x + y), evaluate=False)), + ("1-f(x)", 1 - f * x), + + ("\\begin{matrix}1&2\\\\3&4\\end{matrix}", Matrix([[1, 2], [3, 4]])), + ("\\begin{matrix}x&x^2\\\\\\sqrt{x}&x\\end{matrix}", Matrix([[x, x**2], [_Pow(x, S.Half), x]])), + ("\\begin{matrix}\\sqrt{x}\\\\\\sin(\\theta)\\end{matrix}", Matrix([_Pow(x, S.Half), sin(theta)])), + ("\\begin{pmatrix}1&2\\\\3&4\\end{pmatrix}", Matrix([[1, 2], [3, 4]])), + ("\\begin{bmatrix}1&2\\\\3&4\\end{bmatrix}", Matrix([[1, 2], [3, 4]])), + + # scientific notation + ("2.5\\times 10^2", 250), + ("1,500\\times 10^{-1}", 150), + + # e notation + ("2.5E2", 250), + ("1,500E-1", 150), + + # multiplication without cmd + ("2x2y", Mul(2, x, 2, y, evaluate=False)), + ("2x2", Mul(2, x, 2, evaluate=False)), + ("x2", x * 2), + + # lin alg processing + ("\\theta\\begin{matrix}1&2\\\\3&4\\end{matrix}", MatMul(theta, Matrix([[1, 2], [3, 4]]), evaluate=False)), + ("\\theta\\begin{matrix}1\\\\3\\end{matrix} - \\begin{matrix}-1\\\\2\\end{matrix}", MatAdd(MatMul(theta, Matrix([[1], [3]]), evaluate=False), MatMul(-1, Matrix([[-1], [2]]), evaluate=False), evaluate=False)), + ("\\theta\\begin{matrix}1&0\\\\0&1\\end{matrix}*\\begin{matrix}3\\\\-2\\end{matrix}", MatMul(theta, Matrix([[1, 0], [0, 1]]), Matrix([3, -2]), evaluate=False)), + ("\\frac{1}{9}\\theta\\begin{matrix}1&2\\\\3&4\\end{matrix}", MatMul(Pow(9, -1, evaluate=False), theta, Matrix([[1, 2], [3, 4]]), evaluate=False)), + ("\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix},\\begin{pmatrix}4\\\\3\\\\1\\end{pmatrix}", [Matrix([1, 2, 3]), Matrix([4, 3, 1])]), + ("\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix};\\begin{pmatrix}4\\\\3\\\\1\\end{pmatrix}", [Matrix([1, 2, 3]), Matrix([4, 3, 1])]), + ("\\left\\{\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix},\\begin{pmatrix}4\\\\3\\\\1\\end{pmatrix}\\right\\}", [Matrix([1, 2, 3]), Matrix([4, 3, 1])]), + ("\\left\\{\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix},\\begin{pmatrix}4\\\\3\\\\1\\end{pmatrix},\\begin{pmatrix}1\\\\1\\\\1\\end{pmatrix}\\right\\}", [Matrix([1, 2, 3]), Matrix([4, 3, 1]), Matrix([1, 1, 1])]), + ("\\left\\{\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix}\\right\\}", Matrix([1, 2, 3])), + ("\\left{\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix}\\right}", Matrix([1, 2, 3])), + ("{\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix}}", Matrix([1, 2, 3])), + + # us dollars + ("\\$1,000.00", 1000), + ("\\$543.21", 543.21), + ("\\$0.009", 0.009), + + # percentages + ("100\\%", 1), + ("1.5\\%", 0.015), + ("0.05\\%", 0.0005), + + # empty set + ("\\emptyset", S.EmptySet) + ] + + def test_good_pair(self, s, eq): + assert_equal(s, eq) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/atom_expr_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/atom_expr_test.py new file mode 100755 index 0000000..23b69b4 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/atom_expr_test.py @@ -0,0 +1,58 @@ +from .context import assert_equal +import pytest +from sympy import Symbol, Integer, Pow + +# label, text, symbol_text +symbols = [ + ('letter', 'x', 'x'), + ('greek letter', '\\lambda', 'lambda'), + ('greek letter w/ space', '\\alpha ', 'alpha'), + ('accented letter', '\\overline{x}', 'xbar') +] + +subscripts = [ + ('2'), + ('{23}'), + ('i'), + ('{ij}'), + ('{i,j}'), + ('{good}'), + ('{x^2}') +] + +examples = [] +for symbol in symbols: + for subscript in subscripts: + examples.append(tuple(list(symbol) + [subscript])) + + +@pytest.mark.parametrize('label, text, symbol_text, subscript', examples) +def test_with_supexpr(label, text, symbol_text, subscript): + assert_equal(text + '^2', Pow(Symbol(symbol_text, real=True), Integer(2))) + + +@pytest.mark.parametrize('label, text, symbol_text, subscript', examples) +def test_with_subexpr(label, text, symbol_text, subscript): + assert_equal(text + '_' + subscript, Symbol(symbol_text + '_' + subscript, real=True)) + + +@pytest.mark.parametrize('label, text, symbol_text, subscript', examples) +def test_with_subexpr_before_supexpr(label, text, symbol_text, subscript): + assert_equal(text + '_' + subscript + '^2', Pow(Symbol(symbol_text + '_' + subscript, real=True), Integer(2))) + + +@pytest.mark.parametrize('label, text, symbol_text, subscript', examples) +def test_with_subexpr_before_supexpr_with_braces(label, text, symbol_text, subscript): + wrapped_subscript = subscript if '{' in subscript else '{' + subscript + '}' + assert_equal(text + '_' + wrapped_subscript + '^{2}', Pow(Symbol(symbol_text + '_' + subscript, real=True), Integer(2))) + + +@pytest.mark.parametrize('label, text, symbol_text, subscript', examples) +def test_with_supexpr_before_subexpr(label, text, symbol_text, subscript): + assert_equal(text + '^2_' + subscript, Pow(Symbol(symbol_text + '_' + subscript, real=True), Integer(2))) + + +@pytest.mark.parametrize('label, text, symbol_text, subscript', examples) +def test_with_supexpr_before_subexpr_with_braces(label, text, symbol_text, subscript): + wrapped_subscript = subscript if '{' in subscript else '{' + subscript + '}' + assert_equal(text + '^{2}_' + wrapped_subscript, Pow(Symbol(symbol_text + '_' + subscript, real=True), Integer(2))) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/binomial_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/binomial_test.py new file mode 100755 index 0000000..2fec010 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/binomial_test.py @@ -0,0 +1,36 @@ +from .context import assert_equal, _Add, _Mul, _Pow +import pytest +from sympy import binomial, Symbol + +x = Symbol('x', real=True) +y = Symbol('y', real=True) +theta = Symbol('theta', real=True) +gamma = Symbol('gamma', real=True) + + +def test_binomial_numeric(): + assert_equal("\\binom{16}{2}", binomial(16, 2)) + + +def test_binomial_symbols(): + assert_equal("\\binom{x}{y}", binomial(x, y)) + + +def test_binomial_greek_symbols(): + assert_equal("\\binom{\\theta}{\\gamma}", binomial(theta, gamma)) + + +def test_binomial_expr(): + assert_equal("\\binom{16+2}{\\frac{4}{2}}", binomial(_Add(16, 2), _Mul(4, _Pow(2, -1)), evaluate=False)) + + +def test_choose_numeric(): + assert_equal("\\choose{16}{2}", binomial(16, 2)) + + +def test_choose_symbols(): + assert_equal("\\choose{x}{y}", binomial(x, y)) + + +def test_choose_greek_symbols(): + assert_equal("\\choose{\\theta}{\\gamma}", binomial(theta, gamma)) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/ceil_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/ceil_test.py new file mode 100755 index 0000000..f4c419c --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/ceil_test.py @@ -0,0 +1,29 @@ +from .context import assert_equal, get_simple_examples +import pytest +from sympy import ceiling + +examples = get_simple_examples(ceiling) + + +@pytest.mark.parametrize('input, output, symbolically', examples) +def test_ceil_func(input, output, symbolically): + assert_equal("\\ceil({input})".format(input=input), output, symbolically=symbolically) + + +@pytest.mark.parametrize('input, output, symbolically', examples) +def test_ceil_operatorname(input, output, symbolically): + assert_equal("\\operatorname{{ceil}}({input})".format(input=input), output, symbolically=symbolically) + + +@pytest.mark.parametrize('input, output, symbolically', examples) +def test_ceil_cmd(input, output, symbolically): + assert_equal("\\lceil {input}\\rceil".format(input=input), output, symbolically=symbolically) + assert_equal("\\left\\lceil {input}\\right\\rceil".format(input=input), output, symbolically=symbolically) + assert_equal("\\mleft\\lceil {input}\\mright\\rceil".format(input=input), output, symbolically=symbolically) + + +@pytest.mark.parametrize('input, output, symbolically', examples) +def test_ceil_corners(input, output, symbolically): + assert_equal("\\ulcorner {input}\\urcorner".format(input=input), output, symbolically=symbolically) + assert_equal("\\left\\ulcorner {input}\\right\\urcorner".format(input=input), output, symbolically=symbolically) + assert_equal("\\mleft\\ulcorner {input}\\mright\\urcorner".format(input=input), output, symbolically=symbolically) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/complex_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/complex_test.py new file mode 100755 index 0000000..2197141 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/complex_test.py @@ -0,0 +1,21 @@ +from .context import assert_equal +import pytest +from sympy import Sum, I, Symbol, Integer + +a = Symbol('a', real=True) +b = Symbol('b', real=True) +i = Symbol('i', real=True) +n = Symbol('n', real=True) +x = Symbol('x', real=True) + + +def test_complex(): + assert_equal("a+Ib", a + I * b) + + +def test_complex_e(): + assert_equal("e^{I\\pi}", Integer(-1)) + + +def test_complex_sum(): + assert_equal("\\sum_{i=0}^{n} i \\cdot x", Sum(i * x, (i, 0, n))) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/context.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/context.py new file mode 100755 index 0000000..f48cfd3 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/context.py @@ -0,0 +1,84 @@ +from sympy import simplify, srepr, Add, Mul, Pow, Rational, pi, sqrt, Symbol +from latex2sympy.latex2sympy2 import latex2sympy as process_sympy +import sys +import os +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) + +x = Symbol('x', real=True) +y = Symbol('y', real=True) + +# shorthand definitions + + +def _Add(a, b): + return Add(a, b, evaluate=False) + + +def _Mul(a, b): + return Mul(a, b, evaluate=False) + + +def _Pow(a, b): + return Pow(a, b, evaluate=False) + + +def get_simple_examples(func): + ''' + Returns an array of tuples, containing the string `input`, sympy `output` using the provided sympy `func`, and `symbolically` boolean + for calling `compare`. + ''' + return [ + ("1.1", func(1.1), False), + ("6.9", func(6.9), False), + ("3.5", func(3.5), False), + ("8", func(8), False), + ("0", func(0), False), + ("290348E32", func(Rational('290348E32')), False), + ("1237.293894239480234", func(Rational('1237.293894239480234')), False), + ("8623.4592104E-2", func(Rational('8623.4592104E-2')), False), + ("\\pi ", func(pi), False), + ("\\sqrt{100}", func(sqrt(100)), False), + ("12,123.4", func(Rational('12123.4')), False), + ("-9.4", func(-9.4), False), + ("-35.9825", func(-35.9825), False), + ("-\\sqrt{5}", func(-sqrt(5)), False), + ("-324E-3", func(Rational('-324E-3')), False), + ("-0.23", func(-0.23), False), + ("\\frac{1}{2}", func(Rational('1/2')), False), + ("\\frac{6}{2}", func(Rational('6/2')), False), + ("\\frac{9}{5}", func(Rational('9/5')), False), + ("\\frac{-42}{6}", func(Rational('-42/6')), False), + ("-\\frac{325}{3}", func(Rational('-325/3')), False), + ("\\frac{\\pi }{2}", func(pi / 2), False), + ("(1+6)/3", func(Rational(1 + 6, 3)), False), + ("1+6/3", func(1 + Rational('6/3')), False), + ("7*4/5", func(7 * 4 / 5), False), + ("15-2.3", func(15 - Rational('2.3')), False), + ("x", func(x), True), + ("x + y", func(x + y), True), + ("\\frac{9x}{4}", func(9 * x / 4), True), + ("y\\pi", func(y * pi), True), + ("2y-y-y", func(2 * y - y - y), True) + ] + + +def compare(actual, expected, symbolically=False): + if symbolically: + assert simplify(actual - expected) == 0 + else: + actual_exp_tree = srepr(actual) + expected_exp_tree = srepr(expected) + try: + assert actual_exp_tree == expected_exp_tree + except Exception: + if isinstance(actual, int) or isinstance(actual, float) or actual.is_number and isinstance(expected, int) or isinstance(expected, float) or expected.is_number: + assert actual == expected or actual - expected == 0 or simplify(actual - expected) == 0 + else: + print('expected_exp_tree = ', expected_exp_tree) + print('actual exp tree = ', actual_exp_tree) + raise + + +def assert_equal(latex, expr, variable_values={}, symbolically=False): + parsed = process_sympy(latex, variable_values) + compare(parsed, expr, symbolically) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/exp_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/exp_test.py new file mode 100755 index 0000000..1ef20c6 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/exp_test.py @@ -0,0 +1,57 @@ +from .context import assert_equal +import pytest +from sympy import exp, sin, Symbol, E + +x = Symbol('x', real=True) +y = Symbol('y', real=True) + + +def test_exp_letter(): + assert_equal("e", E) + assert_equal("e", exp(1)) + + +def test_exp_func(): + assert_equal("\\exp(3)", exp(3)) + + +def test_exp_func_no_delim(): + assert_equal("\\exp3", exp(3)) + + +def test_exp_command_symbol(): + assert_equal("\\exponentialE", E) + assert_equal("\\exponentialE", exp(1)) + + +def test_exp_command_symbol_expression(): + assert_equal("\\exponentialE^{3}", exp(3)) + + +def test_exp_command_symbol_multiplied(): + ''' + \\exponentialE is NOT a function, so using the following notation equates to multiplication + ''' + assert_equal("\\exponentialE (3)", E * 3) + assert_equal("\\exponentialE \\left( 3\\right)", E * 3) + assert_equal("\\exponentialE \\times 3", E * 3) + + +def test_exp_numeric(): + assert_equal("e^3", exp(3)) + + +def test_exp_symbol(): + assert_equal("e^x", exp(x)) + + +def test_exp_symbol_expr(): + assert_equal("e^{x+y}", exp(x + y)) + + +def test_exp_symbol_expr_group(): + assert_equal("e^{(x+y)}", exp(x + y)) + + +def test_exp_expr(): + assert_equal("\\sin(x)*e^x", sin(x) * exp(x)) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/floor_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/floor_test.py new file mode 100755 index 0000000..3961782 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/floor_test.py @@ -0,0 +1,29 @@ +from .context import assert_equal, get_simple_examples +import pytest +from sympy import floor + +examples = get_simple_examples(floor) + + +@pytest.mark.parametrize('input, output, symbolically', examples) +def test_floor_func(input, output, symbolically): + assert_equal("\\floor({input})".format(input=input), output, symbolically=symbolically) + + +@pytest.mark.parametrize('input, output, symbolically', examples) +def test_floor_operatorname(input, output, symbolically): + assert_equal("\\operatorname{{floor}}({input})".format(input=input), output, symbolically=symbolically) + + +@pytest.mark.parametrize('input, output, symbolically', examples) +def test_floor_cmd(input, output, symbolically): + assert_equal("\\lfloor {input}\\rfloor".format(input=input), output, symbolically=symbolically) + assert_equal("\\left\\lfloor {input}\\right\\rfloor".format(input=input), output, symbolically=symbolically) + assert_equal("\\mleft\\lfloor {input}\\mright\\rfloor".format(input=input), output, symbolically=symbolically) + + +@pytest.mark.parametrize('input, output, symbolically', examples) +def test_floor_corners(input, output, symbolically): + assert_equal("\\llcorner {input}\\lrcorner".format(input=input), output, symbolically=symbolically) + assert_equal("\\left\\llcorner {input}\\right\\lrcorner".format(input=input), output, symbolically=symbolically) + assert_equal("\\mleft\\llcorner {input}\\mright\\lrcorner".format(input=input), output, symbolically=symbolically) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/gcd_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/gcd_test.py new file mode 100755 index 0000000..a45a215 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/gcd_test.py @@ -0,0 +1,161 @@ +from .context import assert_equal +import pytest +from sympy import Symbol, Rational, UnevaluatedExpr, gcd, igcd, sqrt, pi + +x = Symbol('x', real=True) +y = Symbol('y', real=True) +z = Symbol('z', real=True) + + +def test_gcd_usual(): + assert_equal("\\gcd(18, 3)", gcd(18, 3)) + assert_equal("\\gcd(3, 18)", gcd(3, 18)) + assert_equal("\\gcd(2, 2)", gcd(2, 2)) + assert_equal("\\gcd(0, 21)", UnevaluatedExpr(gcd(0, 21))) + assert_equal("\\gcd(21, 0)", UnevaluatedExpr(gcd(21, 0))) + assert_equal("\\gcd(0, 0)", UnevaluatedExpr(gcd(0, 0))) + assert_equal("\\gcd(6128, 24)", gcd(6128, 24)) + assert_equal("\\gcd(24, 6128)", gcd(24, 6128)) + assert_equal("\\gcd(1E20, 1000000)", gcd(Rational('1E20'), 1000000)) + assert_equal("\\gcd(128*10^32, 1)", gcd(Rational('128E32'), 1)) + + assert_equal("\\operatorname{gcd}(18, 3)", gcd(18, 3)) + assert_equal("\\operatorname{gcd}(3, 18)", gcd(3, 18)) + assert_equal("\\operatorname{gcd}(2, 2)", gcd(2, 2)) + assert_equal("\\operatorname{gcd}(0, 21)", UnevaluatedExpr(gcd(0, 21))) + assert_equal("\\operatorname{gcd}(21, 0)", UnevaluatedExpr(gcd(21, 0))) + assert_equal("\\operatorname{gcd}(0, 0)", UnevaluatedExpr(gcd(0, 0))) + assert_equal("\\operatorname{gcd}(6128, 24)", gcd(6128, 24)) + assert_equal("\\operatorname{gcd}(24, 6128)", gcd(24, 6128)) + assert_equal("\\operatorname{gcd}(1E20, 1000000)", gcd(Rational('1E20'), 1000000)) + assert_equal("\\operatorname{gcd}(128*10^32, 1)", gcd(Rational('128E32'), 1)) + + +def test_gcd_negative(): + assert_equal("\\gcd(-12, 4)", gcd(-12, 4)) + assert_equal("\\gcd(219, -9)", gcd(219, -9)) + assert_equal("\\gcd(-8, -64)", gcd(-8, -64)) + assert_equal("\\gcd(-5, -5)", gcd(-5, -5)) + assert_equal("\\gcd(-1, 182033)", gcd(-1, 182033)) + assert_equal("\\gcd(25, -6125)", gcd(25, -6125)) + assert_equal("\\gcd(243, -2.9543127E21)", gcd(243, Rational('-2.9543127E21'))) + + assert_equal("\\operatorname{gcd}(-12, 4)", gcd(-12, 4)) + assert_equal("\\operatorname{gcd}(219, -9)", gcd(219, -9)) + assert_equal("\\operatorname{gcd}(-8, -64)", gcd(-8, -64)) + assert_equal("\\operatorname{gcd}(-5, -5)", gcd(-5, -5)) + assert_equal("\\operatorname{gcd}(-1, 182033)", gcd(-1, 182033)) + assert_equal("\\operatorname{gcd}(25, -6125)", gcd(25, -6125)) + assert_equal("\\operatorname{gcd}(243, -2.9543127E21)", gcd(243, Rational('-2.9543127E21'))) + + +def test_gcd_float(): + assert_equal("\\gcd(2.4, 3.6)", gcd(Rational('2.4'), Rational('3.6'))) + assert_equal("\\gcd(3.6, 2.4)", gcd(Rational('3.6'), Rational('2.4'))) + assert_equal("\\gcd(\\pi, 3)", gcd(pi, 3)) + assert_equal("\\gcd(618, 1.5)", gcd(618, Rational('1.5'))) + assert_equal("\\gcd(-1.5, 618)", gcd(Rational('-1.5'), 618)) + assert_equal("\\gcd(0.42, 2)", gcd(Rational('0.42'), 2)) + assert_equal("\\gcd(1.43E-13, 21)", gcd(Rational('1.43E-13'), 21)) + assert_equal("\\gcd(21, -143E-13)", gcd(21, Rational('-143E-13'))) + assert_equal("\\gcd(9.80655, 9.80655)", gcd(Rational('9.80655'), Rational('9.80655'))) + assert_equal("\\gcd(0.0000923423, -8341.234802909)", gcd(Rational('0.0000923423'), Rational('-8341.234802909'))) + assert_equal("\\gcd(\\sqrt{5}, \\sqrt{2})", gcd(sqrt(5), sqrt(2))) + + assert_equal("\\operatorname{gcd}(2.4, 3.6)", gcd(Rational('2.4'), Rational('3.6'))) + assert_equal("\\operatorname{gcd}(3.6, 2.4)", gcd(Rational('3.6'), Rational('2.4'))) + assert_equal("\\operatorname{gcd}(\\pi, 3)", gcd(pi, 3)) + assert_equal("\\operatorname{gcd}(618, 1.5)", gcd(618, Rational('1.5'))) + assert_equal("\\operatorname{gcd}(-1.5, 618)", gcd(Rational('-1.5'), 618)) + assert_equal("\\operatorname{gcd}(0.42, 2)", gcd(Rational('0.42'), 2)) + assert_equal("\\operatorname{gcd}(1.43E-13, 21)", gcd(Rational('1.43E-13'), 21)) + assert_equal("\\operatorname{gcd}(21, -143E-13)", gcd(21, Rational('-143E-13'))) + assert_equal("\\operatorname{gcd}(9.80655, 9.80655)", gcd(Rational('9.80655'), Rational('9.80655'))) + assert_equal("\\operatorname{gcd}(0.0000923423, -8341.234802909)", gcd(Rational('0.0000923423'), Rational('-8341.234802909'))) + assert_equal("\\operatorname{gcd}(\\sqrt{5}, \\sqrt{2})", gcd(sqrt(5), sqrt(2))) + + +def test_gcd_fraction(): + assert_equal("\\gcd(1/2, 3)", gcd(Rational('1/2'), 3)) + assert_equal("\\gcd(3, 1/2)", gcd(3, Rational('1/2'))) + assert_equal("\\gcd(6/2, 3)", gcd(Rational('6/2'), 3)) + assert_equal("\\gcd(1/10, 1/10)", gcd(Rational('1/10'), Rational('1/10'))) + assert_equal("\\gcd(42, 42/6)", gcd(42, Rational('42/6'))) + assert_equal("\\gcd(10000000/10, 10000)", gcd(Rational('10000000/10'), 10000)) + + assert_equal("\\operatorname{gcd}(1/2, 3)", gcd(Rational('1/2'), 3)) + assert_equal("\\operatorname{gcd}(3, 1/2)", gcd(3, Rational('1/2'))) + assert_equal("\\operatorname{gcd}(6/2, 3)", gcd(Rational('6/2'), 3)) + assert_equal("\\operatorname{gcd}(1/10, 1/10)", gcd(Rational('1/10'), Rational('1/10'))) + assert_equal("\\operatorname{gcd}(42, 42/6)", gcd(42, Rational('42/6'))) + assert_equal("\\operatorname{gcd}(10000000/10, 10000)", gcd(Rational('10000000/10'), 10000)) + + +def test_gcd_expr(): + assert_equal("\\gcd(1+1, 8)", gcd(1 + 1, 8)) + assert_equal("920*\\gcd(9, 12*4/2)", 920 * gcd(9, 12 * Rational('4/2'))) + assert_equal("\\gcd(32-128, 10)*22", gcd(32 - 128, 10) * 22) + assert_equal("\\sqrt{\\gcd(1.25E24, 1E12)}", sqrt(gcd(Rational('1.25E24'), Rational('1E12')))) + assert_equal("\\gcd(92.0, 000+2)", gcd(Rational('92.0'), 000 + 2)) + + assert_equal("\\operatorname{gcd}(1+1, 8)", gcd(1 + 1, 8)) + assert_equal("920*\\operatorname{gcd}(9, 12*4/2)", 920 * gcd(9, 12 * Rational('4/2'))) + assert_equal("\\operatorname{gcd}(32-128, 10)*22", gcd(32 - 128, 10) * 22) + assert_equal("\\sqrt{\\operatorname{gcd}(1.25E24, 1E12)}", sqrt(gcd(Rational('1.25E24'), Rational('1E12')))) + assert_equal("\\operatorname{gcd}(92.0, 000+2)", gcd(Rational('92.0'), 000 + 2)) + + +def test_gcd_symbol(): + assert_equal("\\gcd(x, y)", gcd(x, y), symbolically=True) + assert_equal("\\gcd(y, -x)", gcd(y, -x), symbolically=True) + assert_equal("\\gcd(2y, x)", gcd(2 * y, x), symbolically=True) + assert_equal("\\gcd(125, 50x)", gcd(125, 50 * x), symbolically=True) + assert_equal("\\gcd(x + 76, \\sqrt{x} * 4)", gcd(x + 76, sqrt(x) * 4), symbolically=True) + assert_equal("\\gcd(y, y)", gcd(y, y), symbolically=True) + assert_equal("y + \\gcd(0.4x, 8/3) / 2", y + gcd(Rational('0.4') * x, Rational('8/3')) / 2, symbolically=True) + assert_equal("6.673E-11 * (\\gcd(8.85418782E-12, 9x) + 4) / 8y", Rational('6.673E-11') * (gcd(Rational('8.85418782E-12'), 9 * x) + 4) / (8 * y), symbolically=True) + + assert_equal("\\operatorname{gcd}(x, y)", gcd(x, y), symbolically=True) + assert_equal("\\operatorname{gcd}(y, -x)", gcd(y, -x), symbolically=True) + assert_equal("\\operatorname{gcd}(2y, x)", gcd(2 * y, x), symbolically=True) + assert_equal("\\operatorname{gcd}(125, 50x)", gcd(125, 50 * x), symbolically=True) + assert_equal("\\operatorname{gcd}(x + 76, \\sqrt{x} * 4)", gcd(x + 76, sqrt(x) * 4), symbolically=True) + assert_equal("\\operatorname{gcd}(y, y)", gcd(y, y), symbolically=True) + assert_equal("y + \\operatorname{gcd}(0.4x, 8/3) / 2", y + gcd(Rational('0.4') * x, Rational('8/3')) / 2, symbolically=True) + assert_equal("6.673E-11 * (\\operatorname{gcd}(8.85418782E-12, 9x) + 4) / 8y", Rational('6.673E-11') * (gcd(Rational('8.85418782E-12'), 9 * x) + 4) / (8 * y), symbolically=True) + + +def test_multiple_parameters(): + assert_equal("\\gcd(830,450)", gcd(830, 450)) + assert_equal("\\gcd(6,321,429)", igcd(6, 321, 429)) + assert_equal("\\gcd(14,2324)", gcd(14, 2324)) + assert_equal("\\gcd(3, 6, 2)", igcd(3, 6, 2)) + assert_equal("\\gcd(144, 2988, 37116)", igcd(144, 2988, 37116)) + assert_equal("\\gcd(144,2988, 37116,18, 72)", igcd(144, 2988, 37116, 18, 72)) + assert_equal("\\gcd(144, 2988, 37116, 18, 72, 12, 6)", igcd(144, 2988, 37116, 18, 72, 12, 6)) + assert_equal("\\gcd(32)", gcd(32, 32)) + assert_equal("\\gcd(-8, 4,-2)", gcd(-8, gcd(4, -2))) + assert_equal("\\gcd(x, y,z)", gcd(x, gcd(y, z)), symbolically=True) + assert_equal("\\gcd(6*4,48, 3)", igcd(6 * 4, 48, 3)) + assert_equal("\\gcd(6*4,48,3)", igcd(6 * 4, 48, 3)) + assert_equal("\\gcd(2.4,3.6, 0.6)", gcd(Rational('2.4'), gcd(Rational('3.6'), Rational('0.6')))) + assert_equal("\\gcd(2.4,3.6,0.6)", gcd(Rational('2.4'), gcd(Rational('3.6'), Rational('0.6')))) + assert_equal("\\gcd(\\sqrt{3},\\sqrt{2}, \\sqrt{100})", gcd(sqrt(3), gcd(sqrt(2), sqrt(100)))) + assert_equal("\\gcd(1E12, 1E6,1E3, 10)", igcd(Rational('1E12'), Rational('1E6'), Rational('1E3'), 10)) + + assert_equal("\\operatorname{gcd}(830,450)", gcd(830, 450)) + assert_equal("\\operatorname{gcd}(6,321,429)", igcd(6, 321, 429)) + assert_equal("\\operatorname{gcd}(14,2324)", gcd(14, 2324)) + assert_equal("\\operatorname{gcd}(3, 6, 2)", igcd(3, 6, 2)) + assert_equal("\\operatorname{gcd}(144, 2988, 37116)", igcd(144, 2988, 37116)) + assert_equal("\\operatorname{gcd}(144,2988, 37116,18, 72)", igcd(144, 2988, 37116, 18, 72)) + assert_equal("\\operatorname{gcd}(144, 2988, 37116, 18, 72, 12, 6)", igcd(144, 2988, 37116, 18, 72, 12, 6)) + assert_equal("\\operatorname{gcd}(32)", gcd(32, 32)) + assert_equal("\\operatorname{gcd}(-8, 4,-2)", gcd(-8, gcd(4, -2))) + assert_equal("\\operatorname{gcd}(x, y,z)", gcd(x, gcd(y, z)), symbolically=True) + assert_equal("\\operatorname{gcd}(6*4,48, 3)", igcd(6 * 4, 48, 3)) + assert_equal("\\operatorname{gcd}(6*4,48,3)", igcd(6 * 4, 48, 3)) + assert_equal("\\operatorname{gcd}(2.4,3.6, 0.6)", gcd(Rational('2.4'), gcd(Rational('3.6'), Rational('0.6')))) + assert_equal("\\operatorname{gcd}(2.4,3.6,0.6)", gcd(Rational('2.4'), gcd(Rational('3.6'), Rational('0.6')))) + assert_equal("\\operatorname{gcd}(\\sqrt{3},\\sqrt{2}, \\sqrt{100})", gcd(sqrt(3), gcd(sqrt(2), sqrt(100)))) + assert_equal("\\operatorname{gcd}(1E12, 1E6,1E3, 10)", igcd(Rational('1E12'), Rational('1E6'), Rational('1E3'), 10)) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/greek_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/greek_test.py new file mode 100755 index 0000000..1e23a0d --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/greek_test.py @@ -0,0 +1,19 @@ +from .context import assert_equal +import pytest +from sympy import Symbol + +epsilon_upper = Symbol('char"000190', real=True) +epsilon_lower = Symbol('epsilon', real=True) +varepsilon = Symbol('varepsilon', real=True) + + +def test_greek_epsilon(): + assert_equal("\\epsilon", epsilon_lower) + + +def test_greek_epsilon_upper(): + assert_equal('\\char"000190', epsilon_upper) + + +def test_greek_varepsilon(): + assert_equal('\\varepsilon', varepsilon) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/grouping_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/grouping_test.py new file mode 100755 index 0000000..139f3f1 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/grouping_test.py @@ -0,0 +1,52 @@ +from .context import assert_equal, _Pow, _Add, _Mul +import pytest +from sympy import Integral, sin, Symbol, Mul, Integer, Pow +from latex2sympy.latex2sympy2 import latex2sympy as process_sympy + +a = Symbol('a', real=True) +b = Symbol('b', real=True) +x = Symbol('x', real=True) +theta = Symbol('theta', real=True) + + +func_arg_examples = [ + ('\\int ', 'x dx', Integral(x, x)), + ('\\sin', '\\theta ', sin(theta)) +] + +example_groups = [ + ('1+2', '3-4', _Mul(_Add(1, 2), _Add(3, _Mul(-1, 4)))) +] + +modifiable_delimiter_pairs = { + '(': ')', + '\\lgroup': '\\rgroup', + '\\{': '\\}', + '\\lbrace': '\\rbrace', + '[': ']', + '\\lbrack': '\\rbrack', +} + + +@pytest.mark.parametrize('func, args, output', func_arg_examples) +def test_func_arg_groupings(func, args, output): + # none + assert_equal("{func} {args}".format(func=func, args=args), output) + # normal brace (not modifiable) + assert_equal("{func}{{{args}}}".format(func=func, args=args), output) + # rest of delimiters, with modifications + for left, right in modifiable_delimiter_pairs.items(): + assert_equal("{func}{left}{args}{right}".format(left=left, right=right, func=func, args=args), output) + assert_equal("{func}\\left{left}{args}\\right{right}".format(left=left, right=right, func=func, args=args), output) + assert_equal("{func}\\mleft{left}{args}\\mright{right}".format(left=left, right=right, func=func, args=args), output) + + +@pytest.mark.parametrize('group1, group2, output', example_groups) +def test_delimiter_groupings(group1, group2, output): + # normal brace (not modifiable) + assert_equal("{{{group1}}}{{{group2}}}".format(group1=group1, group2=group2), output) + # rest of delimiters, with modifications + for left, right in modifiable_delimiter_pairs.items(): + assert_equal("{left}{group1}{right}{left}{group2}{right}".format(left=left, right=right, group1=group1, group2=group2), output) + assert_equal("\\left{left}{group1}\\right{right}\\left{left}{group2}\\right{right}".format(left=left, right=right, group1=group1, group2=group2), output) + assert_equal("\\mleft{left}{group1}\\mright{right}\\mleft{left}{group2}\\mright{right}".format(left=left, right=right, group1=group1, group2=group2), output) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/lcm_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/lcm_test.py new file mode 100755 index 0000000..1e10ce5 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/lcm_test.py @@ -0,0 +1,161 @@ +from .context import assert_equal +import pytest +from sympy import Symbol, Rational, UnevaluatedExpr, lcm, ilcm, sqrt, pi + +x = Symbol('x', real=True) +y = Symbol('y', real=True) +z = Symbol('z', real=True) + + +def test_lcm_usual(): + assert_equal("\\lcm(6, 4)", lcm(6, 4)) + assert_equal("\\lcm(4, 6)", lcm(4, 6)) + assert_equal("\\lcm(2, 2)", lcm(2, 2)) + assert_equal("\\lcm(0, 21)", UnevaluatedExpr(lcm(0, 21))) + assert_equal("\\lcm(21, 0)", UnevaluatedExpr(lcm(21, 0))) + assert_equal("\\lcm(0, 0)", UnevaluatedExpr(lcm(0, 0))) + assert_equal("\\lcm(9, 21)", lcm(9, 21)) + assert_equal("\\lcm(6128, 24)", lcm(6128, 24)) + assert_equal("\\lcm(24, 6128)", lcm(24, 6128)) + assert_equal("\\lcm(1E20, 1000000)", lcm(Rational('1E20'), 1000000)) + assert_equal("\\lcm(128*10^32, 1)", lcm(Rational('128E32'), 1)) + + assert_equal("\\operatorname{lcm}(6, 4)", lcm(6, 4)) + assert_equal("\\operatorname{lcm}(4, 6)", lcm(4, 6)) + assert_equal("\\operatorname{lcm}(2, 2)", lcm(2, 2)) + assert_equal("\\operatorname{lcm}(0, 21)", UnevaluatedExpr(lcm(0, 21))) + assert_equal("\\operatorname{lcm}(21, 0)", UnevaluatedExpr(lcm(21, 0))) + assert_equal("\\operatorname{lcm}(0, 0)", UnevaluatedExpr(lcm(0, 0))) + assert_equal("\\operatorname{lcm}(9, 21)", lcm(9, 21)) + assert_equal("\\operatorname{lcm}(6128, 24)", lcm(6128, 24)) + assert_equal("\\operatorname{lcm}(24, 6128)", lcm(24, 6128)) + assert_equal("\\operatorname{lcm}(1E20, 1000000)", lcm(Rational('1E20'), 1000000)) + assert_equal("\\operatorname{lcm}(128*10^32, 1)", lcm(Rational('128E32'), 1)) + + +def test_lcm_negative(): + assert_equal("\\lcm(-12, 4)", lcm(-12, 4)) + assert_equal("\\lcm(219, -9)", lcm(219, -9)) + assert_equal("\\lcm(-8, -12)", lcm(-8, -12)) + assert_equal("\\lcm(-5, -5)", lcm(-5, -5)) + assert_equal("\\lcm(-1, 182033)", lcm(-1, 182033)) + assert_equal("\\lcm(25, -30)", lcm(25, -30)) + assert_equal("\\lcm(243, -2.9543127E21)", lcm(243, Rational('-2.9543127E21'))) + + assert_equal("\\operatorname{lcm}(-12, 4)", lcm(-12, 4)) + assert_equal("\\operatorname{lcm}(219, -9)", lcm(219, -9)) + assert_equal("\\operatorname{lcm}(-8, -12)", lcm(-8, -12)) + assert_equal("\\operatorname{lcm}(-5, -5)", lcm(-5, -5)) + assert_equal("\\operatorname{lcm}(-1, 182033)", lcm(-1, 182033)) + assert_equal("\\operatorname{lcm}(25, -30)", lcm(25, -30)) + assert_equal("\\operatorname{lcm}(243, -2.9543127E21)", lcm(243, Rational('-2.9543127E21'))) + + +def test_lcm_float(): + assert_equal("\\lcm(2.4, 3.6)", lcm(Rational('2.4'), Rational('3.6'))) + assert_equal("\\lcm(3.6, 2.4)", lcm(Rational('3.6'), Rational('2.4'))) + assert_equal("\\lcm(\\pi, 3)", lcm(pi, 3)) + assert_equal("\\lcm(618, 1.5)", lcm(618, Rational('1.5'))) + assert_equal("\\lcm(-1.5, 618)", lcm(Rational('-1.5'), 618)) + assert_equal("\\lcm(0.42, 2)", lcm(Rational('0.42'), 2)) + assert_equal("\\lcm(1.43E-13, 21)", lcm(Rational('1.43E-13'), 21)) + assert_equal("\\lcm(21, -143E-13)", lcm(21, Rational('-143E-13'))) + assert_equal("\\lcm(9.80655, 9.80655)", lcm(Rational('9.80655'), Rational('9.80655'))) + assert_equal("\\lcm(0.0000923423, -8341.234802909)", lcm(Rational('0.0000923423'), Rational('-8341.234802909'))) + assert_equal("\\lcm(\\sqrt{5}, \\sqrt{2})", lcm(sqrt(5), sqrt(2))) + + assert_equal("\\operatorname{lcm}(2.4, 3.6)", lcm(Rational('2.4'), Rational('3.6'))) + assert_equal("\\operatorname{lcm}(3.6, 2.4)", lcm(Rational('3.6'), Rational('2.4'))) + assert_equal("\\operatorname{lcm}(\\pi, 3)", lcm(pi, 3)) + assert_equal("\\operatorname{lcm}(618, 1.5)", lcm(618, Rational('1.5'))) + assert_equal("\\operatorname{lcm}(-1.5, 618)", lcm(Rational('-1.5'), 618)) + assert_equal("\\operatorname{lcm}(0.42, 2)", lcm(Rational('0.42'), 2)) + assert_equal("\\operatorname{lcm}(1.43E-13, 21)", lcm(Rational('1.43E-13'), 21)) + assert_equal("\\operatorname{lcm}(21, -143E-13)", lcm(21, Rational('-143E-13'))) + assert_equal("\\operatorname{lcm}(9.80655, 9.80655)", lcm(Rational('9.80655'), Rational('9.80655'))) + assert_equal("\\operatorname{lcm}(0.0000923423, -8341.234802909)", lcm(Rational('0.0000923423'), Rational('-8341.234802909'))) + assert_equal("\\operatorname{lcm}(\\sqrt{5}, \\sqrt{2})", lcm(sqrt(5), sqrt(2))) + + +def test_lcm_fraction(): + assert_equal("\\lcm(1/2, 3)", lcm(Rational('1/2'), 3)) + assert_equal("\\lcm(3, 1/2)", lcm(3, Rational('1/2'))) + assert_equal("\\lcm(6/2, 3)", lcm(Rational('6/2'), 3)) + assert_equal("\\lcm(1/10, 1/10)", lcm(Rational('1/10'), Rational('1/10'))) + assert_equal("\\lcm(42, 42/6)", lcm(42, Rational('42/6'))) + assert_equal("\\lcm(10000000/10, 10000)", lcm(Rational('10000000/10'), 10000)) + + assert_equal("\\operatorname{lcm}(1/2, 3)", lcm(Rational('1/2'), 3)) + assert_equal("\\operatorname{lcm}(3, 1/2)", lcm(3, Rational('1/2'))) + assert_equal("\\operatorname{lcm}(6/2, 3)", lcm(Rational('6/2'), 3)) + assert_equal("\\operatorname{lcm}(1/10, 1/10)", lcm(Rational('1/10'), Rational('1/10'))) + assert_equal("\\operatorname{lcm}(42, 42/6)", lcm(42, Rational('42/6'))) + assert_equal("\\operatorname{lcm}(10000000/10, 10000)", lcm(Rational('10000000/10'), 10000)) + + +def test_lcm_expr(): + assert_equal("\\lcm(1+1, 8)", lcm(1 + 1, 8)) + assert_equal("920*\\lcm(9, 12*4/2)", 920 * lcm(9, 12 * Rational('4/2'))) + assert_equal("\\lcm(32-128, 10)*22", lcm(32 - 128, 10) * 22) + assert_equal("\\sqrt{\\lcm(1.25E24, 1E12)}", sqrt(lcm(Rational('1.25E24'), Rational('1E12')))) + assert_equal("\\lcm(92.0, 000+2)", lcm(Rational('92.0'), 000 + 2)) + + assert_equal("\\operatorname{lcm}(1+1, 8)", lcm(1 + 1, 8)) + assert_equal("920*\\operatorname{lcm}(9, 12*4/2)", 920 * lcm(9, 12 * Rational('4/2'))) + assert_equal("\\operatorname{lcm}(32-128, 10)*22", lcm(32 - 128, 10) * 22) + assert_equal("\\sqrt{\\operatorname{lcm}(1.25E24, 1E12)}", sqrt(lcm(Rational('1.25E24'), Rational('1E12')))) + assert_equal("\\operatorname{lcm}(92.0, 000+2)", lcm(Rational('92.0'), 000 + 2)) + + +def test_lcm_symbol(): + assert_equal("\\lcm(x, y)", lcm(x, y), symbolically=True) + assert_equal("\\lcm(y, -x)", lcm(y, -x), symbolically=True) + assert_equal("\\lcm(2y, x)", lcm(2 * y, x), symbolically=True) + assert_equal("\\lcm(125, 50x)", lcm(125, 50 * x), symbolically=True) + assert_equal("\\lcm(x + 76, \\sqrt{x} * 4)", lcm(x + 76, sqrt(x) * 4), symbolically=True) + assert_equal("\\lcm(y, y)", lcm(y, y), symbolically=True) + assert_equal("y + \\lcm(0.4x, 8/3) / 2", y + lcm(Rational('0.4') * x, Rational('8/3')) / 2, symbolically=True) + assert_equal("6.673E-11 * (\\lcm(8.85418782E-12, 9x) + 4) / 8y", Rational('6.673E-11') * (lcm(Rational('8.85418782E-12'), 9 * x) + 4) / (8 * y), symbolically=True) + + assert_equal("\\operatorname{lcm}(x, y)", lcm(x, y), symbolically=True) + assert_equal("\\operatorname{lcm}(y, -x)", lcm(y, -x), symbolically=True) + assert_equal("\\operatorname{lcm}(2y, x)", lcm(2 * y, x), symbolically=True) + assert_equal("\\operatorname{lcm}(125, 50x)", lcm(125, 50 * x), symbolically=True) + assert_equal("\\operatorname{lcm}(x + 76, \\sqrt{x} * 4)", lcm(x + 76, sqrt(x) * 4), symbolically=True) + assert_equal("\\operatorname{lcm}(y, y)", lcm(y, y), symbolically=True) + assert_equal("y + \\operatorname{lcm}(0.4x, 8/3) / 2", y + lcm(Rational('0.4') * x, Rational('8/3')) / 2, symbolically=True) + assert_equal("6.673E-11 * (\\operatorname{lcm}(8.85418782E-12, 9x) + 4) / 8y", Rational('6.673E-11') * (lcm(Rational('8.85418782E-12'), 9 * x) + 4) / (8 * y), symbolically=True) + + +def test_multiple_parameters(): + assert_equal("\\lcm(830,450)", lcm(830, 450)) + assert_equal("\\lcm(6,321,429)", ilcm(6, 321, 429)) + assert_equal("\\lcm(14,2324)", lcm(14, 2324)) + assert_equal("\\lcm(3, 6, 2)", ilcm(3, 6, 2)) + assert_equal("\\lcm(8, 9, 21)", ilcm(8, 9, 21)) + assert_equal("\\lcm(144, 2988, 37116)", ilcm(144, 2988, 37116)) + assert_equal("\\lcm(144,2988,37116,18,72)", ilcm(144, 2988, 37116, 18, 72)) + assert_equal("\\lcm(144, 2988, 37116, 18, 72, 12, 6)", ilcm(144, 2988, 37116, 18, 72, 12, 6)) + assert_equal("\\lcm(32)", lcm(32, 32)) + assert_equal("\\lcm(-8, 4, -2)", lcm(-8, lcm(4, -2))) + assert_equal("\\lcm(x, y, z)", lcm(x, lcm(y, z)), symbolically=True) + assert_equal("\\lcm(6*4, 48, 3)", ilcm(6 * 4, 48, 3)) + assert_equal("\\lcm(2.4, 3.6, 0.6)", lcm(Rational('2.4'), lcm(Rational('3.6'), Rational('0.6')))) + assert_equal("\\lcm(\\sqrt{3}, \\sqrt{2},\\sqrt{100})", lcm(sqrt(3), lcm(sqrt(2), sqrt(100)))) + assert_equal("\\lcm(1E12, 1E6, 1E3, 10)", ilcm(Rational('1E12'), Rational('1E6'), Rational('1E3'), 10)) + + assert_equal("\\operatorname{lcm}(830,450)", lcm(830, 450)) + assert_equal("\\operatorname{lcm}(6,321,429)", ilcm(6, 321, 429)) + assert_equal("\\operatorname{lcm}(14,2324)", lcm(14, 2324)) + assert_equal("\\operatorname{lcm}(3, 6, 2)", ilcm(3, 6, 2)) + assert_equal("\\operatorname{lcm}(8, 9, 21)", ilcm(8, 9, 21)) + assert_equal("\\operatorname{lcm}(144, 2988, 37116)", ilcm(144, 2988, 37116)) + assert_equal("\\operatorname{lcm}(144,2988,37116,18,72)", ilcm(144, 2988, 37116, 18, 72)) + assert_equal("\\operatorname{lcm}(144, 2988, 37116, 18, 72, 12, 6)", ilcm(144, 2988, 37116, 18, 72, 12, 6)) + assert_equal("\\operatorname{lcm}(32)", lcm(32, 32)) + assert_equal("\\operatorname{lcm}(-8, 4, -2)", lcm(-8, lcm(4, -2))) + assert_equal("\\operatorname{lcm}(x, y, z)", lcm(x, lcm(y, z)), symbolically=True) + assert_equal("\\operatorname{lcm}(6*4,48, 3)", ilcm(6 * 4, 48, 3)) + assert_equal("\\operatorname{lcm}(2.4, 3.6,0.6)", lcm(Rational('2.4'), lcm(Rational('3.6'), Rational('0.6')))) + assert_equal("\\operatorname{lcm}(\\sqrt{3}, \\sqrt{2},\\sqrt{100})", lcm(sqrt(3), lcm(sqrt(2), sqrt(100)))) + assert_equal("\\operatorname{lcm}(1E12,1E6, 1E3, 10)", ilcm(Rational('1E12'), Rational('1E6'), Rational('1E3'), 10)) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/left_right_cdot_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/left_right_cdot_test.py new file mode 100755 index 0000000..5533b59 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/left_right_cdot_test.py @@ -0,0 +1,9 @@ +from .context import assert_equal +import pytest +from sympy import sin, Symbol + +x = Symbol('x', real=True) + + +def test_left_right_cdot(): + assert_equal("\\sin\\left(x\\right)\\cdot x", sin(x) * x) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/linalg_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/linalg_test.py new file mode 100755 index 0000000..d6dea56 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/linalg_test.py @@ -0,0 +1,15 @@ +from .context import assert_equal +import pytest +from sympy import MatMul, Matrix + + +def test_linalg_placeholder(): + assert_equal("\\begin{pmatrix}1&2\\\\3&4\\end{pmatrix}\\cdot\\variable{v}", MatMul(Matrix([[1, 2], [3, 4]]), Matrix([1, 2])), {'v': Matrix([1, 2])}) + + +def test_linalg_placeholder_multiple(): + assert_equal("\\variable{M}\\cdot\\variable{v}", MatMul(Matrix([[1, 2], [3, 4]]), Matrix([1, 2])), {'M': Matrix([[1, 2], [3, 4]]), 'v': Matrix([1, 2])}) + + +def test_linalg_placeholder_multiple_mul(): + assert_equal("\\begin{pmatrix}3&-1\\end{pmatrix}\\cdot\\variable{M}\\cdot\\variable{v}", MatMul(Matrix([[3, -1]]), Matrix([[1, 2], [3, 4]]), Matrix([1, 2])), {'M': Matrix([[1, 2], [3, 4]]), 'v': Matrix([1, 2])}) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/max_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/max_test.py new file mode 100755 index 0000000..d359c69 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/max_test.py @@ -0,0 +1,79 @@ +from .context import assert_equal +import pytest +from sympy import Symbol, Rational, Float, Max, sqrt, exp, pi, nsimplify + +x = Symbol('x', real=True) +y = Symbol('y', real=True) +z = Symbol('z', real=True) + + +def test_max_usual(): + assert_equal("\\max(1, 5)", Max(1, 5)) + assert_equal("\\max(12, 4)", Max(12, 4)) + assert_equal("\\max(109, 120)", Max(109, 120)) + assert_equal("\\max(3, 3)", Max(3, 3)) + assert_equal("\\max(0, 0)", Max(0, 0)) + assert_equal("\\max(1)", Max(1)) + assert_equal("\\max(1092198374, 290348E32)", Max(1092198374, Rational('290348E32'))) + assert_equal("\\max(5, 2, 17, 4)", Max(5, 2, 17, 4)) + + +def test_max_negative(): + assert_equal("\\max(-9, 4)", Max(-9, 4)) + assert_equal("\\max(4, -9)", Max(4, -9)) + assert_equal("\\max(-7)", Max(-7)) + assert_equal("\\max(-2, -2)", Max(-2, -2)) + assert_equal("\\max(-324E-3, -58)", Max(Rational('-324E-3'), -58)) + assert_equal("\\max(-1, 0, 1, -37, 42)", Max(-1, 0, 1, -37, 42)) + + +def test_max_float(): + assert_equal("\\max(\\pi, 3)", Max(pi, 3)) + assert_equal("\\max(1234.56789, 1234.5678901)", Max(Rational('1234.56789'), Rational('1234.5678901'))) + assert_equal("\\max(12.4, 9.5)", Max(12.4, 9.5)) + assert_equal("\\max(6, 6.2)", Max(6, 6.2)) + assert_equal("\\max(-98.7)", Max(-98.7)) + assert_equal("\\max(7.1, 9)", Max(7.1, 9)) + assert_equal("\\max(-21E-12, 0.00005)", Max(nsimplify(Rational('-21E-12')), Rational('0.00005')), symbolically=True) + assert_equal("\\max(\\sqrt{3}, 0, 1)", Max(sqrt(3), 0, 1)) + + +def test_max_fraction(): + assert_equal("\\max(1/2, 1/4)", Max(Rational('1/2'), Rational('1/4'))) + assert_equal("\\max(6/2, 3)", Max(Rational('6/2'), 3)) + assert_equal("\\max(2/4, 1/2)", Max(Rational('2/4'), Rational('1/2'))) + assert_equal("\\max(-12/5, 6.4)", Max(Rational('-12/5'), Rational('6.4'))) + assert_equal("\\max(1/10)", Max(Rational('1/10'))) + assert_equal("\\max(1.5, \\pi/2)", Max(Rational('1.5'), pi / 2, evaluate=False)) + assert_equal("\\max(-4/3, -2/1, 0/9, -3)", Max(Rational('-4/3'), Rational('-2/1'), Rational('0/9'), -3)) + + +def test_max_expr(): + assert_equal("\\max((1+6)/3, 7)", Max(Rational(1 + 6, 3), 7)) + assert_equal("\\max(58*9)", Max(58 * 9)) + assert_equal("\\max(1+6/3, -5)", Max(1 + Rational('6/3'), -5)) + assert_equal("\\max(7*4/5, 092) * 2", Max(7 * 4 / 5, 92) * 2) + assert_equal("38+\\max(13, 15-2.3)", 38 + Max(13, 15 - Rational('2.3'))) + assert_equal("\\sqrt{\\max(99.9999999999999, 100)}", sqrt(Max(Rational('99.9999999999999'), 100))) + assert_equal("\\max(274/(5+2), \\exp(12.4), 1.4E2)", Max(Rational(274, 5 + 2), exp(Rational('12.4')), Rational('1.4E2'))) + + +def test_max_symbol(): + assert_equal("\\max(x)", Max(x), symbolically=True) + assert_equal("\\max(x, y)", Max(x, y), symbolically=True) + assert_equal("\\max(y, x)", Max(y, x), symbolically=True) + assert_equal("\\max(x+y, y+x)", Max(x + y, y + x), symbolically=True) + assert_equal("\\max(9x/4, z)", Max(9 * x / 4, z), symbolically=True) + assert_equal("\\max(y\\pi, 9)", Max(y * pi, 9), symbolically=True) + assert_equal("\\max(2y-y, y + 1)", Max(2 * y - y, y + 1), symbolically=True) + assert_equal("\\max(z, y, x)", Max(z, y, x), symbolically=True) + + +def test_max_multiarg(): + assert_equal("\\max(1,2)", Max(1, 2)) + assert_equal("\\max(9,876,543)", Max(9, 876, 543)) + assert_equal("\\max(x, y,z)", Max(x, y, z), symbolically=True) + assert_equal("\\max(5.8,7.4, 2.2,-10)", Max(Rational('5.8'), Rational('7.4'), Rational('2.2'), -10)) + assert_equal("\\max(\\pi,12E2,84,\\sqrt{5},12/5)", Max(pi, Rational('12E2'), 84, sqrt(5), Rational('12/5'))) + assert_equal("\\max(823,51)", Max(823, 51)) + assert_equal("\\max(72*4,23, 9)", Max(72 * 4, 23, 9)) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/min_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/min_test.py new file mode 100755 index 0000000..f60a5cd --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/min_test.py @@ -0,0 +1,79 @@ +from .context import assert_equal +import pytest +from sympy import Symbol, Rational, Float, Min, sqrt, exp, pi, nsimplify + +x = Symbol('x', real=True) +y = Symbol('y', real=True) +z = Symbol('z', real=True) + + +def test_min_usual(): + assert_equal("\\min(1, 5)", Min(1, 5)) + assert_equal("\\min(12, 4)", Min(12, 4)) + assert_equal("\\min(109, 120)", Min(109, 120)) + assert_equal("\\min(3, 3)", Min(3, 3)) + assert_equal("\\min(0, 0)", Min(0, 0)) + assert_equal("\\min(1)", Min(1)) + assert_equal("\\min(1092198374, 290348E32)", Min(1092198374, Rational('290348E32'))) + assert_equal("\\min(5, 2, 17, 4)", Min(5, 2, 17, 4)) + + +def test_min_negative(): + assert_equal("\\min(-9, 4)", Min(-9, 4)) + assert_equal("\\min(4, -9)", Min(4, -9)) + assert_equal("\\min(-7)", Min(-7)) + assert_equal("\\min(-2, -2)", Min(-2, -2)) + assert_equal("\\min(-324E-3, -58)", Min(Rational('-324E-3'), -58)) + assert_equal("\\min(-1, 0, 1, -37, 42)", Min(-1, 0, 1, -37, 42)) + + +def test_min_float(): + assert_equal("\\min(\\pi, 3)", Min(pi, 3)) + assert_equal("\\min(1234.56789, 1234.5678901)", Min(Rational('1234.56789'), Rational('1234.5678901'))) + assert_equal("\\min(12.4, 9.5)", Min(12.4, 9.5)) + assert_equal("\\min(6, 6.2)", Min(6, 6.2)) + assert_equal("\\min(-98.7)", Min(-98.7)) + assert_equal("\\min(7.1, 9)", Min(7.1, 9)) + assert_equal("\\min(-21E-12, 0.00005)", Min(nsimplify(Rational('-21E-12')), Rational('0.00005')), symbolically=True) + assert_equal("\\min(\\sqrt{3}, 0, 1)", Min(sqrt(3), 0, 1)) + + +def test_min_fraction(): + assert_equal("\\min(1/2, 1/4)", Min(Rational('1/2'), Rational('1/4'))) + assert_equal("\\min(6/2, 3)", Min(Rational('6/2'), 3)) + assert_equal("\\min(2/4, 1/2)", Min(Rational('2/4'), Rational('1/2'))) + assert_equal("\\min(-12/5, 6.4)", Min(Rational('-12/5'), Rational('6.4'))) + assert_equal("\\min(1/10)", Min(Rational('1/10'))) + assert_equal("\\min(1.5, \\pi/2)", Min(Rational('1.5'), pi / 2, evaluate=False)) + assert_equal("\\min(-4/3, -2/1, 0/9, -3)", Min(Rational('-4/3'), Rational('-2/1'), Rational('0/9'), -3)) + + +def test_min_expr(): + assert_equal("\\min((1+6)/3, 7)", Min(Rational(1 + 6, 3), 7)) + assert_equal("\\min(58*9)", Min(58 * 9)) + assert_equal("\\min(1+6/3, -5)", Min(1 + Rational('6/3'), -5)) + assert_equal("\\min(7*4/5, 092) * 2", Min(7 * 4 / 5, 92) * 2) + assert_equal("38+\\min(13, 15-2.3)", 38 + Min(13, 15 - Rational('2.3'))) + assert_equal("\\sqrt{\\min(99.9999999999999, 100)}", sqrt(Min(Rational('99.9999999999999'), 100))) + assert_equal("\\min(274/(5+2), \\exp(12.4), 1.4E2)", Min(Rational(274, 5 + 2), exp(Rational('12.4')), Rational('1.4E2'))) + + +def test_min_symbol(): + assert_equal("\\min(x)", Min(x), symbolically=True) + assert_equal("\\min(x, y)", Min(x, y), symbolically=True) + assert_equal("\\min(y, x)", Min(y, x), symbolically=True) + assert_equal("\\min(x+y, y+x)", Min(x + y, y + x), symbolically=True) + assert_equal("\\min(9x/4, z)", Min(9 * x / 4, z), symbolically=True) + assert_equal("\\min(y\\pi, 9)", Min(y * pi, 9), symbolically=True) + assert_equal("\\min(2y-y, y + 1)", Min(2 * y - y, y + 1), symbolically=True) + assert_equal("\\min(z, y, x)", Min(z, y, x), symbolically=True) + + +def test_min_multiarg(): + assert_equal("\\min(1,2)", Min(1, 2)) + assert_equal("\\min(9,876,543)", Min(9, 876, 543)) + assert_equal("\\min(x, y,z)", Min(x, y, z), symbolically=True) + assert_equal("\\min(5.8,7.4, 2.2,-10)", Min(Rational('5.8'), Rational('7.4'), Rational('2.2'), -10)) + assert_equal("\\min(\\pi,12E2,84,\\sqrt{5},12/5)", Min(pi, Rational('12E2'), 84, sqrt(5), Rational('12/5'))) + assert_equal("\\min(823,51)", Min(823, 51)) + assert_equal("\\min(72*4,23, 9)", Min(72 * 4, 23, 9)) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/mod_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/mod_test.py new file mode 100755 index 0000000..972fe7a --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/mod_test.py @@ -0,0 +1,70 @@ +from .context import assert_equal +import pytest +from sympy import Symbol, Rational, Mod, sqrt, nsimplify, pi, GoldenRatio +from sympy.physics.units import hbar + +x = Symbol('x', real=True) +y = Symbol('y', real=True) + + +def test_mod_usual(): + assert_equal("128\\mod 3", Mod(128, 3)) + assert_equal("7\\mod 128", Mod(7, 128)) + assert_equal("5\\mod 10", Mod(5, 10)) + assert_equal("5\\mod 5", Mod(5, 5)) + assert_equal("3\\mod 2", Mod(3, 2)) + assert_equal("0 \\mod 6", Mod(0, 6)) + assert_equal("6109\\mod 28", Mod(6109, 28)) + assert_equal("4000000000\\mod 28791", Mod(4000000000, 28791)) + assert_equal("128*10^300\\mod 876123", Mod(Rational('128E300'), 876123)) + assert_equal("876,123\\mod 128E300)", Mod(876123, Rational('128E300'))) + + +def test_mod_negative(): + assert_equal("-1\\mod 2", Mod(-1, 2)) + assert_equal("-3\\mod 3", Mod(-3, 3)) + assert_equal("-12\\mod -12", Mod(-12, -12)) + assert_equal("-128\\mod 4", Mod(-128, 4)) + assert_equal("9\\mod -213", Mod(9, -213)) + assert_equal("123123\\mod -541", Mod(123123, -541)) + assert_equal("-123123\\mod 541", Mod(-123123, 541)) + assert_equal("-97E34\\mod 7", Mod(Rational('-97E34'), 7)) + + +def test_mod_fraction(): + assert_equal("1/2\\mod 3", Mod(Rational(1, 2), 3)) + assert_equal("6/2\\mod 3", Mod(Rational(6, 2), 3)) + assert_equal("-14/2\\mod 5", Mod(Rational(-14, 2), 5)) + assert_equal("123\\mod (42/6)", Mod(123, Rational(42, 6))) + assert_equal("431\\mod (2/123)", Mod(431, Rational(2, 123))) + assert_equal("5/5\\mod (5/5)", Mod(Rational(5, 5), Rational(5, 5))) + assert_equal("849/-21\\mod (092/2)", Mod(Rational(849, -21), Rational(92, 2))) + assert_equal("13*10^9\\mod (21/-2)", Mod(13E9, Rational(21, -2))) + + +def test_mod_float(): + assert_equal("0.41\\mod 2", Mod(Rational('0.41'), 2)) + assert_equal("143E-13\\mod 21", Mod(Rational('143E-13'), 21)) + assert_equal("-9.80665\\mod 9.80665", Mod(-9.80665, 9.80665)) + assert_equal("0.0000923423\\mod -8341.234802909", nsimplify(Mod(0.0000923423, -8341.234802909))) + assert_equal("\\sqrt{5}\\mod \\sqrt{2}", Mod(sqrt(5), sqrt(2))) + assert_equal("987\\mod \\pi", Mod(987, pi)) + assert_equal("\\pi\\mod ((1+\\sqrt{5})/2)", Mod(pi, nsimplify(GoldenRatio)), symbolically=True) + assert_equal("1234\\mod 1E-29", Mod(1234, Rational('1E-29'), evaluate=False)) + + +def test_mod_expr(): + assert_equal("1+1\\mod 2", 1 + Mod(1, 2)) + assert_equal("876123\\mod 128\\times 10^300", Mod(876123, 128) * 1E300) + assert_equal("141\\mod 9/3", Rational(Mod(141, 9) / 3)) + assert_equal("872 / (12\\mod 9 * 4) * 2", Rational(2 * 872, (Mod(12, 9) * 4))) + assert_equal("1E-32 * (1E29\\mod 74)", Rational('1E-32') * Mod(Rational('1E29'), 74)) + assert_equal("299,792,458\\mod 9.81", Mod(299792458, Rational('9.81'))) + + +def test_mod_symbol(): + assert_equal("x\\mod y", Mod(x, y)) + assert_equal("2x\\mod y", Mod(2 * x, y)) + assert_equal("y + 3\\mod 2 / 4", y + Rational(Mod(3, 2), 4), symbolically=True) + assert_equal("0.5x * 2 + \\sqrt{x}\\mod 8y", 0.5 * x * 2 + Mod(sqrt(x), 8 * y), symbolically=True) + assert_equal("6.673E-11 * ((8.85418782E-12\\mod 9x) + 4) / 2y", Rational('6.673E-11') * (Mod(Rational('8.85418782E-12'), 9 * x) + 4) / (2 * y), symbolically=True) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/overline_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/overline_test.py new file mode 100755 index 0000000..a75103e --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/overline_test.py @@ -0,0 +1,9 @@ +from .context import assert_equal +import pytest +from sympy import sin, Symbol + +x = Symbol('x', real=True) + + +def test_overline(): + assert_equal("\\frac{\\sin(x)}{\\overline{x}_n}", sin(x) / Symbol('xbar_n', real=True)) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/pi_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/pi_test.py new file mode 100755 index 0000000..050190d --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/pi_test.py @@ -0,0 +1,15 @@ +from .context import assert_equal, _Mul, _Pow +import pytest +from sympy import pi, Symbol, acos, cos + + +def test_pi_frac(): + assert_equal("\\frac{\\pi}{3}", _Mul(pi, _Pow(3, -1))) + + +def test_pi_nested(): + assert_equal("\\arccos{\\cos{\\frac{\\pi}{3}}}", acos(cos(_Mul(pi, _Pow(3, -1)), evaluate=False), evaluate=False)) + + +def test_pi_arccos(): + assert_equal("\\arccos{-1}", pi, symbolically=True) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/trig_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/trig_test.py new file mode 100755 index 0000000..4689ea5 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/trig_test.py @@ -0,0 +1,21 @@ +from .context import assert_equal +import pytest +from sympy import asinh, Symbol + +# x = Symbol('x', real=True); + +# latex = "\\sinh(x)" +# math = process_sympy(latex) +# print("latex: %s to math: %s" %(latex,math)) +# +# latex = "\\arcsinh(x)" +# math = process_sympy(latex) +# print("latex: %s to math: %s" %(latex,math)) +# +# latex = "\\arsinh(x)" +# math = process_sympy(latex) +# print("latex: %s to math: %s" %(latex,math)) + + +def test_arcsinh(): + assert_equal("\\operatorname{arcsinh}\\left(1\\right)", asinh(1, evaluate=False)) diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/variable_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/variable_test.py new file mode 100755 index 0000000..9fc13c7 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/variable_test.py @@ -0,0 +1,92 @@ +from .context import assert_equal +import pytest +import hashlib +from sympy import UnevaluatedExpr, Symbol, Mul, Pow, Max, Min, gcd, lcm, floor, ceiling + +x = Symbol('x', real=True) +y = Symbol('y', real=True) + + +def test_variable_letter(): + assert_equal("\\variable{x}", Symbol('x' + hashlib.md5('x'.encode()).hexdigest(), real=True)) + + +def test_variable_digit(): + assert_equal("\\variable{1}", Symbol('1' + hashlib.md5('1'.encode()).hexdigest(), real=True)) + + +def test_variable_letter_subscript(): + assert_equal("\\variable{x_y}", Symbol('x_y' + hashlib.md5('x_y'.encode()).hexdigest(), real=True)) + + +def test_variable_letter_comma_subscript(): + assert_equal("\\variable{x_{i,j}}", Symbol('x_{i,j}' + hashlib.md5('x_{i,j}'.encode()).hexdigest(), real=True)) + + +def test_variable_digit_subscript(): + assert_equal("\\variable{x_1}", Symbol('x_1' + hashlib.md5('x_1'.encode()).hexdigest(), real=True)) + + +def test_variable_after_subscript_required(): + with pytest.raises(Exception): + assert_equal("\\variable{x_}", Symbol('x_' + hashlib.md5('x_'.encode()).hexdigest(), real=True)) + + +def test_variable_before_subscript_required(): + with pytest.raises(Exception): + assert_equal("\\variable{_x}", Symbol('_x' + hashlib.md5('_x'.encode()).hexdigest(), real=True)) + + +def test_variable_bad_name(): + with pytest.raises(Exception): + assert_equal("\\variable{\\sin xy}", None) + + +def test_variable_in_expr(): + assert_equal("4\\cdot\\variable{x}", 4 * Symbol('x' + hashlib.md5('x'.encode()).hexdigest(), real=True)) + + +def test_variable_greek_letter(): + assert_equal("\\variable{\\alpha }\\alpha", Symbol('\\alpha ' + hashlib.md5('\\alpha '.encode()).hexdigest(), real=True) * Symbol('alpha', real=True)) + + +def test_variable_greek_letter_subscript(): + assert_equal("\\variable{\\alpha _{\\beta }}\\alpha ", Symbol('\\alpha _{\\beta }' + hashlib.md5('\\alpha _{\\beta }'.encode()).hexdigest(), real=True) * Symbol('alpha', real=True)) + + +def test_variable_bad_unbraced_long_subscript(): + with pytest.raises(Exception): + assert_equal("\\variable{x_yz}", None) + + +def test_variable_bad_unbraced_long_complex_subscript(): + with pytest.raises(Exception): + assert_equal("\\variable{x\\beta 10_y\\alpha 20}", None) + + +def test_variable_braced_subscript(): + assert_equal("\\variable{x\\beta 10_{y\\alpha 20}}", Symbol('x\\beta 10_{y\\alpha 20}' + hashlib.md5('x\\beta 10_{y\\alpha 20}'.encode()).hexdigest(), real=True)) + + +def test_variable_complex_expr(): + assert_equal("4\\cdot\\variable{value1}\\frac{\\variable{value_2}}{\\variable{a}}\\cdot x^2", 4 * Symbol('value1' + hashlib.md5('value1'.encode()).hexdigest(), real=True) * Symbol('value_2' + hashlib.md5('value_2'.encode()).hexdigest(), real=True) / Symbol('a' + hashlib.md5('a'.encode()).hexdigest(), real=True) * x**2) + + +def test_variable_dollars(): + assert_equal("\\$\\variable{x}", Symbol('x' + hashlib.md5('x'.encode()).hexdigest(), real=True)) + + +def test_variable_percentage(): + assert_equal("\\variable{x}\\%", Mul(Symbol('x' + hashlib.md5('x'.encode()).hexdigest(), real=True), Pow(100, -1, evaluate=False), evaluate=False)) + + +def test_variable_single_arg_func(): + assert_equal("\\floor(\\variable{x})", floor(Symbol('x' + hashlib.md5('x'.encode()).hexdigest(), real=True))) + assert_equal("\\ceil(\\variable{x})", ceiling(Symbol('x' + hashlib.md5('x'.encode()).hexdigest(), real=True))) + + +def test_variable_multi_arg_func(): + assert_equal("\\gcd(\\variable{x}, \\variable{y})", UnevaluatedExpr(gcd(Symbol('x' + hashlib.md5('x'.encode()).hexdigest(), real=True), Symbol('y' + hashlib.md5('y'.encode()).hexdigest(), real=True)))) + assert_equal("\\lcm(\\variable{x}, \\variable{y})", UnevaluatedExpr(lcm(Symbol('x' + hashlib.md5('x'.encode()).hexdigest(), real=True), Symbol('y' + hashlib.md5('y'.encode()).hexdigest(), real=True)))) + assert_equal("\\max(\\variable{x}, \\variable{y})", Max(Symbol('x' + hashlib.md5('x'.encode()).hexdigest(), real=True), Symbol('y' + hashlib.md5('y'.encode()).hexdigest(), real=True), evaluate=False)) + assert_equal("\\min(\\variable{x}, \\variable{y})", Min(Symbol('x' + hashlib.md5('x'.encode()).hexdigest(), real=True), Symbol('y' + hashlib.md5('y'.encode()).hexdigest(), real=True), evaluate=False)) |
