Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions mathics/builtin/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def negate(item):
if item.has_form("Times", 1, None):
if isinstance(item.leaves[0], Number):
neg = -item.leaves[0]
if neg.same(Integer(1)):
if neg.sameQ(Integer(1)):
if len(item.leaves) == 1:
return neg
else:
Expand Down Expand Up @@ -375,7 +375,7 @@ def append_last():
else:
number = Integer(0)

if not number.same(Integer(0)):
if not number.sameQ(Integer(0)):
leaves.insert(0, number)

if not leaves:
Expand Down Expand Up @@ -583,7 +583,7 @@ def inverse(item):
item.leaves[1], (Integer, Rational, Real)
):
neg = -item.leaves[1]
if neg.same(Integer(1)):
if neg.sameQ(Integer(1)):
return item.leaves[0]
else:
return Expression("Power", item.leaves[0], neg)
Expand All @@ -603,7 +603,7 @@ def inverse(item):
negative.append(inverse(item))
elif isinstance(item, Rational):
numerator = item.numerator()
if not numerator.same(Integer(1)):
if not numerator.sameQ(Integer(1)):
positive.append(numerator)
negative.append(item.denominator())
else:
Expand Down Expand Up @@ -667,36 +667,36 @@ def apply(self, items, evaluation):
leaves
and item.has_form("Power", 2)
and leaves[-1].has_form("Power", 2)
and item.leaves[0].same(leaves[-1].leaves[0])
and item.leaves[0].sameQ(leaves[-1].leaves[0])
):
leaves[-1] = Expression(
"Power",
leaves[-1].leaves[0],
Expression("Plus", item.leaves[1], leaves[-1].leaves[1]),
)
elif (
leaves and item.has_form("Power", 2) and item.leaves[0].same(leaves[-1])
leaves and item.has_form("Power", 2) and item.leaves[0].sameQ(leaves[-1])
):
leaves[-1] = Expression(
"Power", leaves[-1], Expression("Plus", item.leaves[1], Integer(1))
)
elif (
leaves
and leaves[-1].has_form("Power", 2)
and leaves[-1].leaves[0].same(item)
and leaves[-1].leaves[0].sameQ(item)
):
leaves[-1] = Expression(
"Power", item, Expression("Plus", Integer(1), leaves[-1].leaves[1])
)
elif item.get_head().same(SymbolDirectedInfinity):
elif item.get_head().sameQ(SymbolDirectedInfinity):
infinity_factor = True
if len(item.leaves) > 1:
direction = item.leaves[0]
if isinstance(direction, Number):
numbers.append(direction)
else:
leaves.append(direction)
elif item.same(SymbolInfinity) or item.same(SymbolComplexInfinity):
elif item.sameQ(SymbolInfinity) or item.sameQ(SymbolComplexInfinity):
infinity_factor = True
else:
leaves.append(item)
Expand All @@ -718,13 +718,13 @@ def apply(self, items, evaluation):
else:
number = Integer(1)

if number.same(Integer(1)):
if number.sameQ(Integer(1)):
number = None
elif number.is_zero:
if infinity_factor:
return Symbol("Indeterminate")
return number
elif number.same(Integer(-1)) and leaves and leaves[0].has_form("Plus", None):
elif number.sameQ(Integer(-1)) and leaves and leaves[0].has_form("Plus", None):
leaves[0] = Expression(
leaves[0].get_head(),
*[Expression("Times", Integer(-1), leaf) for leaf in leaves[0].leaves]
Expand Down
5 changes: 3 additions & 2 deletions mathics/builtin/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,9 @@ def get_lookup_name(self):
def get_string_value(self):
return "-@" + self.get_head_name() + "@-"

def same(self, expr):
return expr.same(self)
def sameQ(self, expr) -> bool:
"""Mathics SameQ"""
return expr.sameQ(self)

def is_atom(self):
return False
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def apply(self, f, x, evaluation):
elif not f.is_atom() and len(f.leaves) > 1:

def summand(leaf, index):
if leaf.same(x):
if leaf.sameQ(x):
result = Expression(
Expression(
Expression(
Expand Down
19 changes: 11 additions & 8 deletions mathics/builtin/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from mathics.version import __version__ # noqa used in loading to check consistency.

import itertools
from typing import Optional, Union
from typing import Optional, Union, Any

import sympy

Expand Down Expand Up @@ -63,7 +63,7 @@ class SameQ(BinaryOperator):
def apply(self, lhs, rhs, evaluation):
"lhs_ === rhs_"

if lhs.same(rhs):
if lhs.sameQ(rhs):
return SymbolTrue
else:
return SymbolFalse
Expand All @@ -89,7 +89,7 @@ class UnsameQ(BinaryOperator):
def apply(self, lhs, rhs, evaluation):
"lhs_ =!= rhs_"

if lhs.same(rhs):
if lhs.sameQ(rhs):
return SymbolFalse
else:
return SymbolTrue
Expand Down Expand Up @@ -170,7 +170,7 @@ class ValueQ(Builtin):
def apply(self, expr, evaluation):
"ValueQ[expr_]"
evaluated_expr = expr.evaluate(evaluation)
if expr.same(evaluated_expr):
if expr.sameQ(evaluated_expr):
return SymbolFalse
return SymbolTrue

Expand Down Expand Up @@ -222,8 +222,11 @@ def numerify_args(items, evaluation):
class _EqualityOperator(_InequalityOperator):
"Compares all pairs e.g. a == b == c compares a == b, b == c, and a == c."

def do_compare(self, l1, l2) -> Union[bool, None]:
if l1.same(l2):
def equal2(self, l1: Any, l2: Any) -> Union[bool, None]:
"""
Two-argument Equal[]
"""
if l1.sameQ(l2):
return True
elif l1 == SymbolTrue and l2 == SymbolFalse:
return False
Expand All @@ -235,7 +238,7 @@ def do_compare(self, l1, l2) -> Union[bool, None]:
if len(l1.leaves) != len(l2.leaves):
return False
for item1, item2 in zip(l1.leaves, l2.leaves):
result = self.do_compare(item1, item2)
result = self.equal2(item1, item2)
if not result:
return result
return True
Expand Down Expand Up @@ -305,7 +308,7 @@ def apply_other(self, args, evaluation):
"%(name)s[args___?(!ExactNumberQ[#]&)]"
args = args.get_sequence()
for x, y in itertools.combinations(args, 2):
c = self.do_compare(x, y)
c = self.equal2(x, y)
if c is None:
return
if self._op(c) is False:
Expand Down
7 changes: 4 additions & 3 deletions mathics/builtin/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ def get_sort_key(self, pattern_sort=False):
else:
return hash(self)

def same(self, other):
def sameQ(self, other) -> bool:
"""Mathics SameQ"""
return self is other

def to_python(self, *args, **kwargs):
Expand Down Expand Up @@ -248,9 +249,9 @@ def apply(self, argnames, expr, code, args, evaluation):
for arg in argseq:
if isinstance(arg, Integer):
py_args.append(arg.get_int_value())
elif arg.same(Symbol("True")):
elif arg.sameQ(Symbol("True")):
py_args.append(True)
elif arg.same(Symbol("False")):
elif arg.sameQ(Symbol("False")):
py_args.append(False)
else:
py_args.append(arg.round_to_float(evaluation))
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/compile/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def _gen_Power(self, expr):
return exponent

# E ^ exponent
if leaves[0].same(Symbol('E')) and exponent.type == real_type:
if leaves[0].sameQ(Symbol('E')) and exponent.type == real_type:
return self.call_fp_intr('llvm.exp', [exponent])

# 2 ^ exponent
Expand Down
3 changes: 2 additions & 1 deletion mathics/builtin/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2256,7 +2256,8 @@ def get_sort_key(self, pattern_sort=False):
else:
return hash(self)

def same(self, other):
def sameQ(self, other) -> bool:
"""Mathics SameQ"""
if not isinstance(other, Image):
return False
if self.color_space != other.color_space or self.metadata != other.metadata:
Expand Down
16 changes: 8 additions & 8 deletions mathics/builtin/inout.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def apply_makeboxes(self, items, sep, f, evaluation):
else:
result = []
for index, item in enumerate(items):
if index > 0 and not sep.same(String("")):
if index > 0 and not sep.sameQ(String("")):
result.append(sep)
result.append(MakeBoxes(item, f))
return RowBox(Expression(SymbolList, *result))
Expand Down Expand Up @@ -2294,20 +2294,20 @@ def check_options(self, options, evaluation):

def check_DigitBlock(self, value, evaluation):
py_value = value.get_int_value()
if value.same(Symbol("Infinity")):
if value.sameQ(Symbol("Infinity")):
return [0, 0]
elif py_value is not None and py_value > 0:
return [py_value, py_value]
elif value.has_form("List", 2):
nleft, nright = value.leaves
py_left, py_right = nleft.get_int_value(), nright.get_int_value()
if nleft.same(Symbol("Infinity")):
if nleft.sameQ(Symbol("Infinity")):
nleft = 0
elif py_left is not None and py_left > 0:
nleft = py_left
else:
nleft = None
if nright.same(Symbol("Infinity")):
if nright.sameQ(Symbol("Infinity")):
nright = 0
elif py_right is not None and py_right > 0:
nright = py_right
Expand All @@ -2319,7 +2319,7 @@ def check_DigitBlock(self, value, evaluation):
return evaluation.message(self.get_name(), "dblk", value)

def check_ExponentFunction(self, value, evaluation):
if value.same(Symbol("Automatic")):
if value.sameQ(Symbol("Automatic")):
return self.default_ExponentFunction

def exp_function(x):
Expand All @@ -2328,7 +2328,7 @@ def exp_function(x):
return exp_function

def check_NumberFormat(self, value, evaluation):
if value.same(Symbol("Automatic")):
if value.sameQ(Symbol("Automatic")):
return self.default_NumberFormat

def num_function(man, base, exp, options):
Expand All @@ -2355,9 +2355,9 @@ def check_ExponentStep(self, value, evaluation):
return result

def check_SignPadding(self, value, evaluation):
if value.same(Symbol("True")):
if value.sameQ(Symbol("True")):
return True
elif value.same(Symbol("False")):
elif value.sameQ(Symbol("False")):
return False
return evaluation.message(self.get_name(), "opttf", value)

Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ def _norm_calc(head, u, v, evaluation):
expr_eval = expr.evaluate(evaluation)
finally:
evaluation.quiet_all = old_quiet_all
if expr_eval.same(expr):
if expr_eval.sameQ(expr):
evaluation.message("Norm", "nvm")
return None
else:
Expand Down
Loading