Skip to content

Commit

Permalink
adding a test (#1158)
Browse files Browse the repository at this point in the history
By now, just adding a test for #1156 to see what does the CI
  • Loading branch information
mmatera authored Nov 8, 2024
1 parent 6495274 commit 94d26c2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
16 changes: 9 additions & 7 deletions mathics/eval/numbers/algebra/simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies = [
"requests",
"scipy",
"setuptools",
"sympy>=1.11,<1.14",
"sympy>=1.13,<1.14",
]
license = {text = "GPL"}
name = "Mathics3"
Expand Down
28 changes: 28 additions & 0 deletions test/builtin/numbers/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",

This comment has been minimized.

Copy link
@aravindh-krishnamoorthy

aravindh-krishnamoorthy Nov 10, 2024

Collaborator

This should likely just be eigvals // FullSimplify since the [[1]] is already included in the definition of eigvals above.

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",
),
],

This comment has been minimized.

Copy link
@aravindh-krishnamoorthy

aravindh-krishnamoorthy Nov 10, 2024

Collaborator

Suggest to also add a numerical test:

In[17]:= eigvals /. a[x_, y_] -> x+I*y
Out[17]= 10 - 3 Sqrt[11]

This comment has been minimized.

Copy link
@rocky

rocky Nov 10, 2024

Member

Unless @mmatera feels otherwise, it might be nice to submit a PR for the changes you suggest.

)
def test_private_doctests_linalg(str_expr, msgs, str_expected, fail_msg):
Expand Down

0 comments on commit 94d26c2

Please sign in to comment.