Skip to content

Commit

Permalink
trailing changes (#887)
Browse files Browse the repository at this point in the history
This PR fixes the `RealSign` docstring and removes a trailing
unreachable piece of code in the `eval_Sign` function.
  • Loading branch information
mmatera authored Jul 21, 2023
1 parent ada4a4a commit 7ced55a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 44 deletions.
2 changes: 1 addition & 1 deletion mathics/builtin/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ def test(self, expr) -> bool:
class RealSign(Builtin):
"""
<url>
:Signum:
:Sign function:
https://en.wikipedia.org/wiki/Sign_function</url> (<url>
:WMA link:
https://reference.wolfram.com/language/ref/RealSign.html
Expand Down
43 changes: 0 additions & 43 deletions mathics/eval/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,49 +319,6 @@ def eval_complex_sign(n: BaseElement) -> Optional[BaseElement]:
sign = eval_RealSign(expr)
return sign or eval_complex_sign(expr)

if expr.has_form("Power", 2):
base, exp = expr.elements
if exp.is_zero:
return Integer1
if isinstance(exp, (Integer, Real, Rational)):
sign = eval_Sign(base) or Expression(SymbolSign, base)
return Expression(SymbolPower, sign, exp)
if isinstance(exp, Complex):
sign = eval_Sign(base) or Expression(SymbolSign, base)
return Expression(SymbolPower, sign, exp.real)
if test_arithmetic_expr(exp):
sign = eval_Sign(base) or Expression(SymbolSign, base)
return Expression(SymbolPower, sign, exp)
return None
if expr.get_head() is SymbolTimes:
abs_value = eval_Abs(eval_multiply_numbers(*expr.elements))
if abs_value is Integer1:
return expr
if abs_value is None:
return None
criteria = eval_add_numbers(abs_value, IntegerM1)
if test_zero_arithmetic_expr(criteria, numeric=True):
return expr
return None
if expr.get_head() is SymbolPlus:
abs_value = eval_Abs(eval_add_numbers(*expr.elements))
if abs_value is Integer1:
return expr
if abs_value is None:
return None
criteria = eval_add_numbers(abs_value, IntegerM1)
if test_zero_arithmetic_expr(criteria, numeric=True):
return expr
return None

if test_arithmetic_expr(expr):
if test_zero_arithmetic_expr(expr):
return Integer0
if test_positive_arithmetic_expr(expr):
return Integer1
if test_negative_arithmetic_expr(expr):
return IntegerM1


def eval_mpmath_function(
mpmath_function: Callable, *args: Number, prec: Optional[int] = None
Expand Down

0 comments on commit 7ced55a

Please sign in to comment.