Commits (5)
......@@ -4254,9 +4254,11 @@ def falling_factorial(x, a):
"""
from sage.symbolic.expression import Expression
x = py_scalar_to_element(x)
if (isinstance(a, (Integer,) + integer_types) or
(isinstance(a, Expression) and
a.is_integer())) and a >= 0:
if ((isinstance(a, (Integer,) + integer_types)
and a >= 0)
or (isinstance(a, Expression)
and a.is_integer()
and (a.is_zero() or a.is_positive()))):
return prod(((x - i) for i in range(a)), z=x.parent().one())
from sage.functions.all import gamma
return gamma(x+1) / gamma(x-a+1)
......@@ -4349,9 +4351,11 @@ def rising_factorial(x, a):
"""
from sage.symbolic.expression import Expression
x = py_scalar_to_element(x)
if (isinstance(a, (Integer,) + integer_types) or
(isinstance(a, Expression) and
a.is_integer())) and a >= 0:
if ((isinstance(a, (Integer,) + integer_types)
and a >= 0)
or (isinstance(a, Expression)
and a.is_integer()
and (a.is_zero() or a.is_positive()))):
return prod(((x + i) for i in range(a)), z=x.parent().one())
from sage.functions.all import gamma
return gamma(x+a) / gamma(x)
......
......@@ -117,7 +117,10 @@ def xsrange(start, end=None, step=1, universe=None, *, coerce=True, bint include
universe = Sequence([start, end, step]).universe()
start, end, step = universe(start), universe(end), universe(step)
if not step:
if hasattr(step, 'is_zero'):
if step.is_zero():
raise ValueError("step argument must not be zero")
elif step == 0:
raise ValueError("step argument must not be zero")
count = (end - start) / step
......
......@@ -1098,7 +1098,8 @@ def minpoly(ex, var='x', algorithm=None, bits=None, degree=None, epsilon=0):
error = abs(g(aa))
if error < expected_error:
# See if we can prove equality exactly
if g(ex).simplify_trig().canonicalize_radical() == 0:
t = g(ex).simplify_trig().canonicalize_radical()
if t.is_zero(simplify=True):
return g
# Otherwise fall back to numerical guess
elif epsilon and error < epsilon:
......
......@@ -4168,7 +4168,7 @@ class FiniteStateMachine(sage.structure.sage_object.SageObject):
sage: F = Transducer([(0, 0, p, 1), (0, 0, q, 0)],
....: on_duplicate_transition=duplicate_transition_add_input)
sage: assume(p + q == 1)
sage: (p + q - 1).is_zero()
sage: (p + q - 1).is_zero(simplify=True)
True
sage: F.is_Markov_chain()
True
......@@ -4190,7 +4190,8 @@ class FiniteStateMachine(sage.structure.sage_object.SageObject):
True
"""
def default_is_zero(expression):
return expression.is_zero()
from sage.symbolic.ring import SR
return SR(expression).is_zero(simplify=True)
 
is_zero_function = default_is_zero
if is_zero is not None:
......
......@@ -3208,11 +3208,15 @@ class Partition(CombinatorialElement):
"""
size = prod(i ** mi * factorial(mi)
for i, mi in six.iteritems(self.to_exp_dict()))
if t or q:
size *= prod((ZZ.one() - q ** j) / (ZZ.one() - t ** j)
for j in self)
return size
if hasattr(t, 'is_zero') and hasattr(q, 'is_zero'):
if t.is_zero() and q.is_zero():
return size
elif t == 0 and q == 0:
return size
return size * prod((ZZ.one() - q ** j) / (ZZ.one() - t ** j)
for j in self)
def aut(self):
r"""
......
......@@ -536,7 +536,7 @@ class Hypergeometric(BuiltinFunction):
sage: hypergeometric([1, -2], [], x).is_terminating()
True
"""
if z == 0:
if z.is_zero():
return True
for aa in a:
if (aa in ZZ) and (aa <= 0):
......
......@@ -2076,9 +2076,9 @@ class Func_laguerre(OrthogonalFunction):
sage: laguerre(1, x)
-x + 1
"""
if n == 0 or x == 0:
if n.is_zero() or x.is_zero():
return ZZ(1)
if n == 1:
if n.is_equal(1):
return ZZ(1) - x
def _pol_laguerre(self, n, x):
......
......@@ -292,7 +292,7 @@ class CoercionPDtoUHP(HyperbolicModelCoercion):
sage: phi.image_coordinates(-I)
0
"""
if x == I:
if (x - I).is_zero():
return infinity
return (x + I)/(Integer(1) + I*x)
......
......@@ -735,7 +735,7 @@ class ChartFunction(AlgebraElement):
"""
curr = self._calc_method._current
if curr == 'SR' :
val = self.expr(curr).is_zero()
val = self.expr(curr).is_zero(simplify=True)
elif curr == 'sympy' :
val = self.expr(curr).is_zero
return not val
......
......@@ -2512,6 +2512,9 @@ class ScalarField(CommutativeAlgebraElement):
True
"""
#if isinstance(number, Expression):
# if number.is_zero(simplify=True):
# return self.parent().zero()
if number == 0:
return self.parent().zero()
result = type(self)(self.parent())
......
......@@ -121,7 +121,7 @@ cdef class Matrix_generic_dense(matrix_dense.Matrix_dense):
self._entries = [zero]*(self._nrows*self._nrows)
for i in range(self._nrows):
self._entries[i+self._ncols*i]=entries
elif entries == zero:
elif entries.is_zero():
self._entries = [zero]*(self._nrows*self._ncols)
else:
raise TypeError("nonzero scalar matrix must be square")
......
......@@ -218,7 +218,7 @@ cdef class Matrix_generic_sparse(matrix_sparse.Matrix_sparse):
if (i < 0 or i >= self._nrows or j < 0 or j >= self._ncols):
raise IndexError("matrix indices {} out of range".format(key))
w = R(x)
if w:
if not w.is_zero():
v[(i,j)] = w
entries = v
else:
......
......@@ -1937,7 +1937,7 @@ class FormsRingElement(six.with_metaclass(
sage: rho = MR.group().rho()
sage: f_rho(rho)
0
7.924...e-10 + 3.216...e-16*I
sage: f_rho(rho + 1e-100) # since rho == rho + 1e-100
0
sage: f_rho(rho + 1e-6)
......@@ -2150,12 +2150,13 @@ class FormsRingElement(six.with_metaclass(
sage: (1/(E2^2-E4))(p) == infinity
True
"""
from sage.symbolic.ring import SR
i = QuadraticField(-1, 'I').gen()
# if tau is a point of HyperbolicPlane then we use it's coordinates in the UHP model
if (tau in HyperbolicPlane()):
tau = tau.to_model('UHP').coordinates()
tau = SR(tau)
if (prec is None):
prec = self.parent().default_prec()
......@@ -2164,18 +2165,18 @@ class FormsRingElement(six.with_metaclass(
# In case the order is known
try:
if (check or\
tau == infinity or\
tau == i or\
tau == self.group().rho() or\
tau == -self.group().rho().conjugate()):
if (check or
tau.is_infinity() or
tau.is_equal(i) or
tau.is_equal(self.group().rho()) or
tau.is_equal(-self.group().rho().conjugate())):
order_tau = self.order_at(tau)
if (order_tau > 0):
return ZZ(0)
elif (order_tau < 0):
return infinity
elif (tau == infinity):
elif tau.is_infinity():
return self.q_expansion(prec=1)[0]
except (TypeError, NotImplementedError):
pass
......
......@@ -3139,7 +3139,7 @@ class HeckeTriangleGroupElement(MatrixGroupElement_generic):
sage: G.U().acton(p) == HyperbolicPlane().UHP().get_point(G.lam()).to_model('PD')
True
"""
from sage.symbolic.expression import Expression
if tau.parent() == self.parent():
return self*tau*self.inverse()
......@@ -3151,15 +3151,26 @@ class HeckeTriangleGroupElement(MatrixGroupElement_generic):
a,b,c,d = self._matrix.list()
if tau == infinity:
if c.is_zero():
if isinstance(tau, Expression):
if tau.is_equal(infinity):
if c.is_zero():
result = infinity
else:
result = a/c
elif (c*tau + d).is_zero():
result = infinity
else:
result = a/c
elif c*tau + d == 0:
result = infinity
result = (a*tau + b) / (c*tau + d)
else:
result = (a*tau + b) / (c*tau + d)
if tau == infinity:
if c.is_zero():
result = infinity
else:
result = a/c
elif c*tau + d == 0:
result = infinity
else:
result = (a*tau + b) / (c*tau + d)
if model is None:
return result
......
......@@ -1128,7 +1128,8 @@ class AsymptoticExpansionGenerators(SageObject):
y, u = SR('y'), SR('u')
one_half = QQ(1)/2
if phi(QQ(0)).is_zero() or phi(u) == phi(0) + u*phi(u).diff(u)(u=0):
if (phi(QQ(0)).is_zero()
or phi(u).is_equal(phi(0) + u*phi(u).diff(u)(u=0), simplify=True)):
raise ValueError('The function phi does not satisfy the requirements')
if tau is None:
......
......@@ -4026,15 +4026,17 @@ def diff_all(f, V, n, ending=[], sub=None, sub_final=None,
# Substitute sub_final into the values of derivs.
for k in derivs:
derivs[k] = subs_all(derivs[k], sub_final)
if rekey:
# Rekey the derivs dictionary by the value of rekey.
F = rekey
if singleton:
# F must be a singleton.
derivs = {diff(F, list(k)): derivs[k] for k in derivs}
else:
# F must be a list.
derivs = {diff(F[k[0]], list(k)[1:]): derivs[k] for k in derivs}
if rekey is None or rekey.is_zero():
return derivs
# Rekey the derivs dictionary by the value of rekey.
F = rekey
if singleton:
# F must be a singleton.
derivs = {diff(F, list(k)): derivs[k] for k in derivs}
else:
# F must be a list.
derivs = {diff(F[k[0]], list(k)[1:]): derivs[k] for k in derivs}
return derivs
......@@ -4127,7 +4129,7 @@ def diff_op(A, B, AB_derivs, V, M, r, N):
diffo = ZZ.zero()
for t in P:
idx = (j, k, l) + diff_seq(V, t)
if product_derivs[idx] != ZZ.zero():
if not product_derivs[idx].is_zero():
MM = ZZ.one()
for (a, b) in t:
MM *= M[a][b]
......
......@@ -900,7 +900,10 @@ def _rpow_(self, base):
sage: _.parent()
Growth Group QQ^n * n^QQ
"""
if base == 0:
if isinstance(base, str) and base == '0':
raise ValueError('%s is not an allowed base for calculating the '
'power to %s.' % (base, self))
if not isinstance(base, str) and base.is_zero():
raise ValueError('%s is not an allowed base for calculating the '
'power to %s.' % (base, self))
......@@ -3083,7 +3086,8 @@ class MonomialGrowthGroup(GenericGrowthGroup):
sage: GrowthGroup('x^QQ')(GrowthGroup('x^ZZ')(1))
1
"""
if data == 1 or data == '1':
from sage.symbolic.ring import SR
if SR(data).is_equal(1) or SR(data).is_equal('1'):
return self.base().zero()
var = repr(self._var_)
if str(data) == var:
......@@ -3094,7 +3098,6 @@ class MonomialGrowthGroup(GenericGrowthGroup):
except AttributeError:
if var not in str(data):
return # this has to end here
from sage.symbolic.ring import SR
return self._convert_(SR(data))
from sage.symbolic.ring import SymbolicRing
......
......@@ -2671,7 +2671,7 @@ class TermWithCoefficient(GenericTerm):
except (ValueError, TypeError):
raise ValueError('%s is not a coefficient in %s.' %
(coefficient, parent))
if coefficient == 0:
if coefficient.is_zero():
raise ZeroCoefficientError(
'Zero coefficient %s is not allowed in %s.' %
(coefficient, parent))
......
......@@ -3194,7 +3194,7 @@ def _findprec(c_1, c_2, c_3, p):
from sage.functions.other import ceil
k = Integer(max(ceil(c_2/c_1), 2))
while True:
if c_1*k - c_2*k.log(p) > c_3:
if (c_1*k - c_2*k.log(p)).n() > c_3:
return k
k += 1
......
......@@ -1999,7 +1999,7 @@ class Sandpile(DiGraph):
else:
ker = self.laplacian().left_kernel().basis()
tau = abs(ker[self._sink_ind])
if tau==1:
if tau.is_equal(1):
easy = True
else:
easy = False
......