Skip to content

Commit

Permalink
Merge pull request #753 from Mathics3/remove-dup-fns
Browse files Browse the repository at this point in the history
Remove duplicate cancel and sympy_factor...
  • Loading branch information
rocky authored Jan 15, 2023
2 parents 9c34b41 + 7d28466 commit 03c43c0
Showing 1 changed file with 1 addition and 30 deletions.
31 changes: 1 addition & 30 deletions mathics/builtin/numbers/algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,36 +62,7 @@
SymbolTable,
SymbolTanh,
)


def sympy_factor(expr_sympy):
try:
result = sympy.together(expr_sympy)
result = sympy.factor(result)
except sympy.PolynomialError:
return expr_sympy
return result


def cancel(expr):
if expr.has_form("Plus", None):
return Expression(SymbolPlus, *[cancel(element) for element in expr.elements])
else:
try:
result = expr.to_sympy()
if result is None:
return None

# result = sympy.powsimp(result, deep=True)
result = sympy.cancel(result)

# cancel factors out rationals, so we factor them again
result = sympy_factor(result)

return from_sympy(result)
except sympy.PolynomialError:
# e.g. for non-commutative expressions
return expr
from mathics.eval.numbers import cancel, sympy_factor


def expand(expr, numer=True, denom=False, deep=False, **kwargs):
Expand Down

0 comments on commit 03c43c0

Please sign in to comment.