From 94d26c2a23d8d5f84fbdac42dbd9058d0c8831a0 Mon Sep 17 00:00:00 2001 From: Juan Mauricio Matera Date: Fri, 8 Nov 2024 11:34:56 -0300 Subject: [PATCH] adding a test (#1158) By now, just adding a test for #1156 to see what does the CI --- mathics/eval/numbers/algebra/simplify.py | 16 ++++++++------ pyproject.toml | 2 +- test/builtin/numbers/test_linalg.py | 28 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/mathics/eval/numbers/algebra/simplify.py b/mathics/eval/numbers/algebra/simplify.py index b89e369b5..12965698a 100644 --- a/mathics/eval/numbers/algebra/simplify.py +++ b/mathics/eval/numbers/algebra/simplify.py @@ -80,11 +80,13 @@ def _default_complexity_function(x): .to_python() ) - # At this point, ``complexity_function`` is a function that takes a - # sympy expression and returns an integer. - sympy_result = simplify(sympy_expr, measure=complexity_function, doit=False) - sympy_result = sympy_result.doit(roots=False) # Don't expand RootSum - - # and bring it back - result = from_sympy(sympy_result).evaluate(evaluation) + try: + # At this point, ``complexity_function`` is a function that takes a + # sympy expression and returns an integer. + sympy_result = simplify(sympy_expr, measure=complexity_function, doit=False) + sympy_result = sympy_result.doit(roots=False) # Don't expand RootSum + # and bring it back + result = from_sympy(sympy_result).evaluate(evaluation) + except ValueError: + return expr return result diff --git a/pyproject.toml b/pyproject.toml index f6731c766..1f0b28461 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ dependencies = [ "requests", "scipy", "setuptools", - "sympy>=1.11,<1.14", + "sympy>=1.13,<1.14", ] license = {text = "GPL"} name = "Mathics3" diff --git a/test/builtin/numbers/test_linalg.py b/test/builtin/numbers/test_linalg.py index 3494e65e2..0d1a6dd67 100644 --- a/test/builtin/numbers/test_linalg.py +++ b/test/builtin/numbers/test_linalg.py @@ -211,6 +211,34 @@ def test_inverse(str_expr, str_expected, fail_msg, warnings): "SingularValueDecomposition[{1, {2}}]", None, ), + ( + "A = Array[a, {2,2}]; eigvals=Eigenvalues[A.ConjugateTranspose[A]][[1]]", + None, + ( + "-Sqrt[(a[1, 1] Conjugate[a[1, 1]] + a[1, 2] Conjugate[a[1, 2]] " + "+ a[2, 1] Conjugate[a[2, 1]] + a[2, 2] Conjugate[a[2, 2]]) ^ 2 " + "- 4 (a[1, 1] Conjugate[a[1, 1]] + a[1, 2] Conjugate[a[1, 2]]) " + "(a[2, 1] Conjugate[a[2, 1]] + a[2, 2] Conjugate[a[2, 2]]) + 4 " + "(a[1, 1] Conjugate[a[2, 1]] + a[1, 2] Conjugate[a[2, 2]]) " + "(a[2, 1] Conjugate[a[1, 1]] + a[2, 2] Conjugate[a[1, 2]])] / 2 " + "+ a[1, 1] Conjugate[a[1, 1]] / 2 + a[1, 2] Conjugate[a[1, 2]] / 2 " + "+ a[2, 1] Conjugate[a[2, 1]] / 2 + a[2, 2] Conjugate[a[2, 2]] / 2" + ), + None, # "Sympy issue #1156", + ), + ( + "eigvals[[1]] // FullSimplify", + None, + ( + "-Sqrt[(a[1, 1] Conjugate[a[1, 1]] + a[1, 2] Conjugate[a[1, 2]] + " + "a[2, 1] Conjugate[a[2, 1]] + a[2, 2] Conjugate[a[2, 2]]) ^ 2 - " + "4 a[1, 1] a[2, 2] Conjugate[a[1, 1]] Conjugate[a[2, 2]] - " + "4 a[1, 2] a[2, 1] Conjugate[a[1, 2]] Conjugate[a[2, 1]] + " + "4 a[1, 1] a[2, 2] Conjugate[a[1, 2]] Conjugate[a[2, 1]] + " + "4 a[1, 2] a[2, 1] Conjugate[a[1, 1]] Conjugate[a[2, 2]]] / 2" + ), + None, # "Sympy issue #1156", + ), ], ) def test_private_doctests_linalg(str_expr, msgs, str_expected, fail_msg):