Skip to content

Commit

Permalink
Misc tweaks... (#1072)
Browse files Browse the repository at this point in the history
(These were noticed in working on event tracing)

`mathics/builtin/numbers/algebra.py`: black changes its autoformatting

`mathics/builtin/numbers/numbertheory.py`: some linting prefers triples
quotes for docstrings

`mathics/core/convert/sympy.py`: use accurate location for singleton
class. This reduces unnecessary sympy imports

`CHANGES.rst`: document recent SetEnvironment addition and
GetEnvironment changes

`test/builtin/numbers/__init__.py`: needed if testing in this directory
is done separately.
  • Loading branch information
rocky authored Aug 20, 2024
1 parent 81499bd commit fce0ddc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
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
Empty file.

0 comments on commit fce0ddc

Please sign in to comment.