Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc tweaks... #1072

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
CHANGES
=======

New Builtins
++++++++++++

* ``SetEnvironment``

Compatibility
-------------

* ``GetEnvironment`` expanded to handle ``[]`` and ``{var1, var2,...}`` forms


7.0.0
-----

Expand Down
24 changes: 15 additions & 9 deletions mathics/builtin/numbers/algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ def unconvert_subexprs(expr):
elements = sub_expr.elements
if target_pat:
elements = [
element
if element.is_free(target_pat, evaluation)
else _expand(element)
(
element
if element.is_free(target_pat, evaluation)
else _expand(element)
)
for element in elements
]
else:
Expand All @@ -248,9 +250,11 @@ def unconvert_subexprs(expr):
elements = sub_expr.elements
if target_pat:
elements = [
element
if element.is_free(target_pat, evaluation)
else _expand(element)
(
element
if element.is_free(target_pat, evaluation)
else _expand(element)
)
for element in elements
]
else:
Expand Down Expand Up @@ -335,9 +339,11 @@ def get_exponents_sorted(expr, var) -> list:
# find exponent of terms multiplied with functions: sin, cos, log, exp, ...
# e.g: x^3 * Sin[x^2] should give 3
muls = [
term.as_coeff_mul(x)[1]
if term.as_coeff_mul(x)[1]
else (sympy.Integer(0),)
(
term.as_coeff_mul(x)[1]
if term.as_coeff_mul(x)[1]
else (sympy.Integer(0),)
)
for term in coeff.as_ordered_terms()
]
expos = [term.as_coeff_exponent(x)[1] for mul in muls for term in mul]
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/numbers/numbertheory.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class PartitionsP(SympyFunction):
)

def eval(self, n, evaluation: Evaluation):
"PartitionsP[n_Integer]"
"""PartitionsP[n_Integer]"""
return super().eval(n, evaluation)


Expand Down
4 changes: 1 addition & 3 deletions mathics/core/convert/sympy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

import sympy
from sympy import Symbol as Sympy_Symbol, false as SympyFalse, true as SympyTrue

# Import the singleton class
from sympy.core.numbers import S
from sympy.core.singleton import S

from mathics.core.atoms import (
MATHICS3_COMPLEX_I,
Expand Down
6 changes: 5 additions & 1 deletion mathics/core/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
# I put this constants here instead of inside `mathics.core.convert.sympy`
# to avoid a circular reference. Maybe they should be in its own module.

sympy_symbol_prefix = "_Mathics_User_"
# Prefix used for Sympy variables.
# We wan t this to be short to keep variable names short.
# In tracing values, long names make output messy.
sympy_symbol_prefix = "_m_"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rocky, in the test it seems you used _mu_ as the prefix

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I am reverting these changes for now, since I forget to update the testing. And the testing isn't catching the change either.

So all of this is more involved. I don't want to hold up other stuff because of these issues. Instead, I'll punt for now.


sympy_slot_prefix = "_Mathics_Slot_"


Expand Down
Empty file.
6 changes: 3 additions & 3 deletions test/core/test_sympy_python_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def compare(self, mathics_expr, sympy_expr, **kwargs):
self.compare_to_mathics(mathics_expr, sympy_expr)

def testSymbol(self):
self.compare(Symbol("Global`x"), sympy.Symbol("_Mathics_User_Global`x"))
self.compare(Symbol("Global`x"), sympy.Symbol("_mg`x"))
self.compare(
Symbol("_Mathics_User_x"),
sympy.Symbol("_Mathics_User_System`_Mathics_User_x"),
Symbol("_mu_x"),
sympy.Symbol("_mu`x"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect that if the conversion routines haven't changed, and the prefix is _m_,
"_Mathics_User_System`_Mathics_User_x" should be now "_m_System`_m_x",
with the prefix both in the symbol name and the context.
In any case, it would be reasonable to put the prefix in the context.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above. Not sure why testing works when it shouldn't. Testing is probably a bit weak then.

The issue of shortening context prefixes will be addressed in a more isolated PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good. Then let's merge this when you feel it is ready.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why the tests are "weak" is that we are not checking the result of the comparison. I will put a fix for this in another PR.

)

def testReal(self):
Expand Down