From fce0ddc9145a4bc436e365e8a2a642594fd00209 Mon Sep 17 00:00:00 2001 From: "R. Bernstein" Date: Tue, 20 Aug 2024 06:37:32 -0400 Subject: [PATCH] Misc tweaks... (#1072) (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. --- CHANGES.rst | 11 +++++++++++ mathics/builtin/numbers/algebra.py | 24 +++++++++++++++--------- mathics/builtin/numbers/numbertheory.py | 2 +- mathics/core/convert/sympy.py | 4 +--- test/builtin/numbers/__init__.py | 0 5 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 test/builtin/numbers/__init__.py diff --git a/CHANGES.rst b/CHANGES.rst index f0825b123..057e6594b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,17 @@ CHANGES ======= +New Builtins +++++++++++++ + +* ``SetEnvironment`` + +Compatibility +------------- + +* ``GetEnvironment`` expanded to handle ``[]`` and ``{var1, var2,...}`` forms + + 7.0.0 ----- diff --git a/mathics/builtin/numbers/algebra.py b/mathics/builtin/numbers/algebra.py index 0d1b7d741..1a6df8541 100644 --- a/mathics/builtin/numbers/algebra.py +++ b/mathics/builtin/numbers/algebra.py @@ -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: @@ -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: @@ -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] diff --git a/mathics/builtin/numbers/numbertheory.py b/mathics/builtin/numbers/numbertheory.py index f718af00a..b227a77cf 100644 --- a/mathics/builtin/numbers/numbertheory.py +++ b/mathics/builtin/numbers/numbertheory.py @@ -508,7 +508,7 @@ class PartitionsP(SympyFunction): ) def eval(self, n, evaluation: Evaluation): - "PartitionsP[n_Integer]" + """PartitionsP[n_Integer]""" return super().eval(n, evaluation) diff --git a/mathics/core/convert/sympy.py b/mathics/core/convert/sympy.py index be34c247e..27cb5253c 100644 --- a/mathics/core/convert/sympy.py +++ b/mathics/core/convert/sympy.py @@ -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, diff --git a/test/builtin/numbers/__init__.py b/test/builtin/numbers/__init__.py new file mode 100644 index 000000000..e69de29bb