Skip to content

Commit

Permalink
Merge branch 'master' into 2d_print
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatera authored Nov 9, 2024
2 parents baa276e + 94d26c2 commit f91168f
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",
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):
Expand Down

0 comments on commit f91168f

Please sign in to comment.