Skip to content

Commit

Permalink
Start to reduce/refactor arithmetic ...
Browse files Browse the repository at this point in the history
Remove stuff from mathics.builtin.arithmetic that does not belong there:

* _MPMathFunction -> MPMathFunction and move to mathics.buitin.base
* _MPMathMultiFunction -> MPMathFunction and move to mathics.builtin.base
* Abs, Piecewise, RealAbs, RealSign, Sign moved to numeric to follow WMA
  organization better

The corresponding eval routines will be gone over in another PR. This
one is already large.

Url's gone over to make this not exceed standard line limit.
Note that the formatting has been gone over to follow the existing
pattern that we have been using.

cythonization in mathics.builtin class files removed. It is not
clear this has benefit in modern Pythons, especially in this kind of builtin function
and all of this needs to be retested if not rethought.
  • Loading branch information
rocky committed Jul 24, 2023
1 parent 9b3575d commit 7a1241c
Show file tree
Hide file tree
Showing 18 changed files with 716 additions and 681 deletions.
18 changes: 12 additions & 6 deletions mathics/builtin/arithfns/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
"""
Basic Arithmetic
The functions here are the basic arithmetic operations that you might find on a calculator.
The functions here are the basic arithmetic operations that you might find \
on a calculator.
"""

from mathics.builtin.arithmetic import _MPMathFunction, create_infix
from mathics.builtin.base import BinaryOperator, Builtin, PrefixOperator, SympyFunction
from mathics.builtin.arithmetic import create_infix
from mathics.builtin.base import (
BinaryOperator,
Builtin,
MPMathFunction,
PrefixOperator,
SympyFunction,
)
from mathics.core.atoms import (
Complex,
Integer,
Expand Down Expand Up @@ -387,7 +394,7 @@ def eval(self, items, evaluation):
return eval_Plus(*items_tuple)


class Power(BinaryOperator, _MPMathFunction):
class Power(BinaryOperator, MPMathFunction):
"""
<url>
:Exponentiation:
Expand Down Expand Up @@ -531,7 +538,7 @@ class Power(BinaryOperator, _MPMathFunction):
def eval_check(self, x, y, evaluation):
"Power[x_, y_]"

# Power uses _MPMathFunction but does some error checking first
# Power uses MPMathFunction but does some error checking first
if isinstance(x, Number) and x.is_zero:
if isinstance(y, Number):
y_err = y
Expand Down Expand Up @@ -788,7 +795,6 @@ def inverse(item):
and isinstance(item.elements[1], (Integer, Rational, Real))
and item.elements[1].to_sympy() < 0
): # nopep8

negative.append(inverse(item))
elif isinstance(item, Rational):
numerator = item.numerator()
Expand Down
Loading

0 comments on commit 7a1241c

Please sign in to comment.