summaryrefslogtreecommitdiff
path: root/Qwen2.5-Eval/evaluation/latex2sympy/sandbox
diff options
context:
space:
mode:
Diffstat (limited to 'Qwen2.5-Eval/evaluation/latex2sympy/sandbox')
-rwxr-xr-xQwen2.5-Eval/evaluation/latex2sympy/sandbox/linalg_equations.py10
-rwxr-xr-xQwen2.5-Eval/evaluation/latex2sympy/sandbox/linalg_span.py19
-rwxr-xr-xQwen2.5-Eval/evaluation/latex2sympy/sandbox/matrix.py46
-rwxr-xr-xQwen2.5-Eval/evaluation/latex2sympy/sandbox/matrix_placeholders.py65
-rwxr-xr-xQwen2.5-Eval/evaluation/latex2sympy/sandbox/sandbox.py23
-rwxr-xr-xQwen2.5-Eval/evaluation/latex2sympy/sandbox/sandbox_equality.py75
-rwxr-xr-xQwen2.5-Eval/evaluation/latex2sympy/sandbox/sectan.py51
-rwxr-xr-xQwen2.5-Eval/evaluation/latex2sympy/sandbox/vector.py75
8 files changed, 364 insertions, 0 deletions
diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/linalg_equations.py b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/linalg_equations.py
new file mode 100755
index 0000000..fa65ba7
--- /dev/null
+++ b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/linalg_equations.py
@@ -0,0 +1,10 @@
+from latex2sympy import process_sympy
+import sys
+sys.path.append("..")
+
+# latex = "2\\begin{pmatrix}1&1&1\\\\0&1&1\\\\0&0&1\\end{pmatrix}\\begin{pmatrix}1&1&1\\\\0&1&1\\\\0&0&1\\end{pmatrix}"
+latex = "\\frac{a^{2} \\left(3 \\pi - 4 \\sin{\\left(\\pi \\right)} + \\frac{\\sin{\\left(2 \\pi \\right)}}{2}\\right)}{2}"
+math = process_sympy(latex)
+
+print(type(math))
+print("latex: %s to math: %s" % (latex, math))
diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/linalg_span.py b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/linalg_span.py
new file mode 100755
index 0000000..2839139
--- /dev/null
+++ b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/linalg_span.py
@@ -0,0 +1,19 @@
+from latex2sympy import process_sympy
+import sys
+sys.path.append("..")
+
+latex = "\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix}"
+math = process_sympy(latex)
+print("latex: %s to math: %s" % (latex, math))
+
+latex = "\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix},\\begin{pmatrix}4\\\\3\\\\1\\end{pmatrix}"
+math = process_sympy(latex)
+print("latex: %s to math: %s" % (latex, math))
+
+latex = "[\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix},\\begin{pmatrix}4\\\\3\\\\1\\end{pmatrix}]"
+math = process_sympy(latex)
+print("latex: %s to math: %s" % (latex, math))
+
+latex = "\\left\\{\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix},\\begin{pmatrix}4\\\\3\\\\1\\end{pmatrix}\\right\\}"
+math = process_sympy(latex)
+print("latex: %s to math: %s" % (latex, math))
diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/matrix.py b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/matrix.py
new file mode 100755
index 0000000..9aed3c2
--- /dev/null
+++ b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/matrix.py
@@ -0,0 +1,46 @@
+from latex2sympy import process_sympy
+from sympy import *
+import sys
+sys.path.append("..")
+
+theta = Symbol('theta', real=True)
+
+latex = "\\begin{matrix}1&2\\\\3&4\\end{matrix}"
+math = process_sympy(latex)
+print("latex: %s to math: %s" % (latex, math))
+
+latex = "\\begin{matrix}1&2\\\\3&4\\\\5&6\\end{matrix}"
+math = process_sympy(latex)
+print("latex: %s to math: %s" % (latex, math))
+
+latex = "\\begin{matrix}1&2&3\\\\4&5&6\\\\7&8&9\\end{matrix}"
+math = process_sympy(latex)
+print("latex: %s to math: %s" % (latex, math))
+
+latex = "\\begin{matrix}x^1&x^2&x^3\\\\y^1&y^2&y^3\\\\z^1&z^2&z^3\\end{matrix}"
+math = process_sympy(latex)
+print("latex: %s to math: %s" % (latex, math))
+
+latex = "\\begin{matrix}x\\\\y\\end{matrix}"
+math = process_sympy(latex)
+print("latex: %s to math: %s" % (latex, math))
+
+latex = "2\\cdot\\begin{matrix}x\\\\y\\end{matrix}"
+math = process_sympy(latex)
+print("latex: %s to math: %s" % (latex, math))
+
+latex = "2\\cdot\\begin{matrix}x\\\\y\\end{matrix} + \\begin{matrix}2\\\\3\\end{matrix}"
+math = process_sympy(latex)
+print("latex: %s to math: %s" % (latex, math))
+
+latex = "-2\\begin{matrix}1&2\\\\3&4\\end{matrix}"
+math = process_sympy(latex)
+print("latex: %s to math: %s" % (latex, math))
+
+latex = "2\\cdot\\theta\\begin{matrix}x\\\\y\\end{matrix} + \\begin{matrix}2\\\\3\\end{matrix}"
+math = process_sympy(latex)
+print("latex: %s to math: %s" % (latex, math))
+
+latex = "\\theta\\begin{matrix}1\\\\3\\end{matrix} - \\begin{matrix}-1\\\\2\\end{matrix}"
+math = process_sympy(latex)
+print("latex: %s to math: %s" % (latex, math))
diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/matrix_placeholders.py b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/matrix_placeholders.py
new file mode 100755
index 0000000..79cb672
--- /dev/null
+++ b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/matrix_placeholders.py
@@ -0,0 +1,65 @@
+from latex2sympy import process_sympy
+from sympy import *
+import sys
+import hashlib
+import time
+
+sys.path.append("..")
+
+
+M = Matrix([[1, 2], [3, 4]])
+v = Matrix([1, 2])
+
+# sub settings
+sub_settings_symbols = {}
+sub_settings_symbols[Symbol('M' + hashlib.md5('M'.encode()).hexdigest(), real=True)] = M
+sub_settings_symbols[Symbol('v' + hashlib.md5('v'.encode()).hexdigest(), real=True)] = v
+
+
+# one parameters
+latex = "\\begin{matrix}1&2\\\\3&4\\end{matrix}\\cdot[!v!]"
+equation_sympy_check = MatMul(M, Symbol('v' + hashlib.md5('v'.encode()).hexdigest(), real=True))
+equation_sympy_subs_check = MatMul(M, v)
+# placeholders
+equation_sympy = process_sympy(latex)
+print('latex = %s' % latex)
+print('equation_sympy = %s' % equation_sympy)
+print('equation_sympy_check = %s' % equation_sympy_check)
+print('equation_sympy = %s' % (srepr(equation_sympy)))
+
+equation_sympy_subs = equation_sympy.subs(sub_settings_symbols, evaluate=False)
+print('equation_sympy_subs = %s' % equation_sympy_subs)
+print('equation_sympy_subs_check = %s' % equation_sympy_subs_check)
+
+
+# two parameters
+
+# sub settings
+print('')
+print('============== Two Parameters -> M*v = Matrix*Vector =============')
+sub_settings_symbols = {}
+sub_settings_symbols[Symbol('M' + hashlib.md5('M'.encode()).hexdigest(), commutative=False)] = M
+sub_settings_symbols[Symbol('v' + hashlib.md5('v'.encode()).hexdigest(), commutative=False)] = v
+
+latex = "[!M!]\\cdot[!v!]"
+math_check = Mul(Symbol('M' + hashlib.md5('M'.encode()).hexdigest(), commutative=False), Symbol('v' + hashlib.md5('v'.encode()).hexdigest(), commutative=False))
+# placeholders
+equation_sympy = process_sympy(latex)
+print(latex)
+print(math_check)
+print(equation_sympy)
+print(srepr(equation_sympy))
+
+# performance
+t0 = time.time()
+
+# process_sympy and substitute at the same time
+# Only needed for linalg input
+placeholder_values = {'M': M, 'v': v}
+equation_sympy_subs = process_sympy(latex, variable_values=placeholder_values)
+
+t1 = time.time()
+print('equation with substituted placeholders = %s' % (str(equation_sympy_subs)))
+print('time to process to sympy with placeholders = %s s' % (t1 - t0))
+print('')
+print('============== Two Parameters -> M*v = Matrix*Vector =============')
diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/sandbox.py b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/sandbox.py
new file mode 100755
index 0000000..2c41100
--- /dev/null
+++ b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/sandbox.py
@@ -0,0 +1,23 @@
+from sympy import *
+from latex2sympy import process_sympy
+
+
+# latex = '\\variable{a}^{\\variable{b}}'
+# variables = {'a': process_sympy('658.95998'), 'b': process_sympy('185083.8060')}
+# c_ans_expr = process_sympy(latex, variables)
+# print(c_ans_expr)
+# print(srepr(c_ans_expr))
+# c_ans = c_ans_expr.doit(deep=False).evalf(chop=True)
+# print(c_ans)
+# print(srepr(c_ans))
+
+
+# numeric_responses = ['1', '1.0', '-1', '-1.0', '.5', '-.5', '3x10^3', '3E3', '3,000x10^{-3}', '0.5E-1', '\\frac{1}{3}', '(5\\times 3)^3', '\\sin(1)']
+# for latex in numeric_responses:
+# parsed = process_sympy(latex)
+# print('latex: ', latex)
+# print('sympy: ', parsed)
+# print('is_number: ', parsed.is_number)
+# print('is_Number: ', parsed.is_Number)
+# print('srepr: ', srepr(parsed))
+# print('-----------------------------------------------------')
diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/sandbox_equality.py b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/sandbox_equality.py
new file mode 100755
index 0000000..5e3f444
--- /dev/null
+++ b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/sandbox_equality.py
@@ -0,0 +1,75 @@
+from sympy import *
+from latex2sympy import process_sympy
+
+
+#
+# Equality Testing
+#
+
+answer_sets = [
+ {
+ 'correct_answer': '(x-y)(x+2y)',
+ 'student_answers': [
+ 'x^2+xy-2y^2',
+ '(x-y)(x+2y)',
+ '(x+2y)(x-y)',
+ '(2\\times y+x)(-y+x)',
+ '(y\\cdot 2+x)(-y+x)'
+ ]
+ },
+ {
+ 'correct_answer': '2\\pi \\variable{r}^2',
+ 'student_answers': [
+ '2\\pi \\variable{r}^2',
+ '\\pi 2\\variable{r}^2',
+ '2\\times \\pi \\times \\variable{r}^2',
+ '2\\pi \\variable{r} \\times \\variable{r}'
+ ]
+ },
+ {
+ 'correct_answer': '2x - 3y',
+ 'student_answers': [
+ '-3y + 2x'
+ ]
+ },
+ {
+ 'correct_answer': 'x\\times x',
+ 'student_answers': [
+ 'x\\times x',
+ 'x\\cdot x',
+ 'x^2',
+ '(\\sqrt{x})^{4}'
+ ]
+ },
+ {
+ 'correct_answer': '23e^{-1\\times \\sqrt{t^2}}',
+ 'student_answers': [
+ '23e^{-t}'
+ ]
+ },
+ {
+ 'correct_answer': 'a=x^2+1',
+ 'student_answers': [
+ 'x^2+1=a'
+ ]
+ }
+]
+
+for answer_set in answer_sets:
+ correct_answer = answer_set['correct_answer']
+ correct_answer_parsed = process_sympy(answer_set['correct_answer'])
+ for student_answer in answer_set['student_answers']:
+ student_answer_parsed = process_sympy(student_answer)
+ print('correct_answer (c): ', correct_answer, correct_answer_parsed)
+ print('student_answer (a): ', student_answer, student_answer_parsed)
+ print('')
+ print('Expression Tree (srepr(c) == srepr(a)) =>', srepr(correct_answer_parsed) == srepr(student_answer_parsed))
+ print('srepr(c) =>', srepr(correct_answer_parsed))
+ print('srepr(a) =>', srepr(student_answer_parsed))
+ print('')
+ # print('Structural (c == a) =>', correct_answer_parsed == student_answer_parsed)
+ print('Symbolic (simplify(c - s) == 0) =>', simplify(correct_answer_parsed - student_answer_parsed) == 0)
+ print('simplified =>', simplify(correct_answer_parsed - student_answer_parsed))
+ print('')
+ print('Numeric Substitution (c.equals(s)) =>', correct_answer_parsed.equals(student_answer_parsed))
+ print('-----------------------------------------------------')
diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/sectan.py b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/sectan.py
new file mode 100755
index 0000000..0e0c7aa
--- /dev/null
+++ b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/sectan.py
@@ -0,0 +1,51 @@
+from sympy import *
+import sys
+sys.path.append("..")
+
+# # x^2\cdot \left(3\cdot \tan \left([!a!]\cdot x+[!c!]\right)+[!a!]\cdot x\left(\sec \left([!a!]\cdot x+[!c!]\right)\right)^2\right)
+# latex1 = "x^2\\cdot \\left(3\\cdot \\tan \\left(2\\cdot x+5\\right)+2\\cdot x\\left(\\sec \\left(2\\cdot x+5\\right)\\right)^2\\right)"
+# math1 = process_sympy(latex1)
+# print("latex: %s to math: %s" %(latex1,math1))
+#
+# latex2 = "x^2\\cdot \\left(3\\cdot \\tan \\left(2\\cdot x+5\\right)+2\\cdot x\\left(\\sec \\left(2\\cdot x+5\\right)^2\\right)\\right)"
+# math2 = process_sympy(latex2)
+# print("latex: %s to math: %s" %(latex2,math2))
+#
+# latex3 = "x^2\\cdot \\left(3\\cdot \\tan \\left(2\\cdot x+5\\right)+2\\cdot x\\left(1+\\tan \\left(2\\cdot x+5\\right)^2\\right)\\right)"
+# math3 = process_sympy(latex3)
+# print("latex: %s to math: %s" %(latex3,math3))
+#
+# print(simplify(math1 - math2))
+# print(simplify(math1 - math3))
+
+#
+# latex1 = "\\sec^2(2\\cdot x+5)"
+# math1 = process_sympy(latex1)
+# print("latex: %s to math: %s" %(latex1,math1))
+#
+# latex2 = "1+\\tan^2(2\\cdot x+5)"
+# math2 = process_sympy(latex2)
+# print("latex: %s to math: %s" %(latex2,math2))
+# print(simplify(math1 - math2))
+
+
+x = Symbol('x', real=True)
+y = Symbol('y', real=True)
+
+# BUG: 1 + tan^2(x+1) should be == sec^2(x+1) but isnt
+lhs = (1 + (tan(x + 1))**2)
+rhs = (sec(x + 1))**2
+eq = lhs - rhs
+print(simplify(lhs))
+print(simplify(rhs))
+print(simplify(eq))
+print(simplify(lhs) == simplify(rhs))
+
+# 1 + tan^2(x) == sec^2(x) but isnt
+lhs = (1 + (tan(x))**2)
+rhs = (sec(x))**2
+eq = lhs - rhs
+print(simplify(lhs))
+print(simplify(rhs))
+print(simplify(eq))
+print(simplify(lhs) == simplify(rhs))
diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/vector.py b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/vector.py
new file mode 100755
index 0000000..5b48aee
--- /dev/null
+++ b/Qwen2.5-Eval/evaluation/latex2sympy/sandbox/vector.py
@@ -0,0 +1,75 @@
+import numpy as np
+from sympy import *
+import sys
+sys.path.append("..")
+
+# row column matrix = vector
+v = [1, 2, 3]
+
+# single column matrix = vector
+m = Matrix([1, 2, 3])
+print(m[:, 0])
+
+# a three row and 2 column matrix
+m = Matrix([[1, 2], [3, 4], [5, 6]])
+print(m[:, 0])
+
+# determinant of lin indp system != 0
+m = Matrix([[1, 1], [1, 2]])
+print(m.det())
+
+# determinant of lin dep system = 0
+m = Matrix([[1, 1], [2, 2]])
+print(m.det())
+
+# determinant of lin dep system = 0
+x = Symbol('x')
+y = Symbol('y')
+m = Matrix([[x, y], [x, y]])
+print(m.det())
+# Reduced Row-Echelon Form
+_, ind = m.rref()
+print(len(ind))
+
+# determinant of lin dep system != 0
+m = Matrix([[x, y], [y, x]])
+print(m.det())
+# Reduced Row-Echelon Form
+_, ind = m.rref()
+print(len(ind))
+
+# determinant of lin dep system != 0
+# Reduced Row-Echelon Form
+m = Matrix([[x, x, y], [y, y, y]])
+_, ind = m.rref()
+# Reduced Row-Echelon Form
+print(len(ind))
+
+#==================#
+#===== Numpy ======#
+#==================#
+# http://kitchingroup.cheme.cmu.edu/blog/2013/03/01/Determining-linear-independence-of-a-set-of-vectors/
+# Lin Indp of set of numerical vectors
+TOLERANCE = 1e-14
+v1 = [6, 0, 3, 1, 4, 2]
+v2 = [0, -1, 2, 7, 0, 5]
+v3 = [12, 3, 0, -19, 8, -11]
+
+A = np.row_stack([v1, v2, v3])
+
+U, s, V = np.linalg.svd(A)
+print(s)
+print(np.sum(s > TOLERANCE))
+
+v1 = [1, 1]
+v2 = [4, 4]
+
+A = np.row_stack([v1, v2])
+U, s, V = np.linalg.svd(A)
+print(s)
+print(np.sum(s > TOLERANCE))
+
+
+latex = "\\begin{matrix}1&2\\\\3&4\\end{matrix}"
+# math = process_sympy(latex)
+print("latex: %s to math: %s" % (latex, 1))