Skip to content

Commit

Permalink
Merge pull request #1212 from skirpichev/misc
Browse files Browse the repository at this point in the history
Misc fixes
  • Loading branch information
skirpichev authored Mar 18, 2022
2 parents de99963 + 420106f commit 3568916
Show file tree
Hide file tree
Showing 61 changed files with 373 additions and 646 deletions.
15 changes: 4 additions & 11 deletions diofant/core/relational.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
from .sympify import sympify


__all__ = (
'Rel', 'Eq', 'Ne', 'Lt', 'Le', 'Gt', 'Ge',
'Relational', 'Equality', 'Unequality', 'StrictLessThan', 'LessThan',
'StrictGreaterThan', 'GreaterThan',
)


# Note, see issue sympy/sympy#4986. Ideally, we wouldn't want to subclass both Boolean
# and Expr.

Expand Down Expand Up @@ -50,7 +43,7 @@ class Relational(Boolean, Expr, EvalfMixin):
# ValidRelationOperator - Defined below, because the necessary classes
# have not yet been defined

def __new__(cls, lhs, rhs, rop=None, **assumptions):
def __new__(cls, lhs, rhs=0, rop=None, **assumptions):
# If called by a subclass, do nothing special and pass on to Expr.
if cls is not Relational:
return Expr.__new__(cls, lhs, rhs, **assumptions)
Expand Down Expand Up @@ -280,7 +273,7 @@ class Equality(Relational):

is_Equality = True

def __new__(cls, lhs, rhs, **options): # pylint: disable=signature-differs
def __new__(cls, lhs, rhs=0, **options): # pylint: disable=signature-differs
lhs = sympify(lhs, strict=True)
rhs = sympify(rhs, strict=True)

Expand Down Expand Up @@ -346,7 +339,7 @@ class Unequality(Relational):

rel_op = '!='

def __new__(cls, lhs, rhs, **options): # pylint: disable=signature-differs
def __new__(cls, lhs, rhs=0, **options): # pylint: disable=signature-differs
lhs = sympify(lhs, strict=True)
rhs = sympify(rhs, strict=True)

Expand All @@ -371,7 +364,7 @@ class _Inequality(Relational):
"""

def __new__(cls, lhs, rhs, **options): # pylint: disable=signature-differs
def __new__(cls, lhs, rhs=0, **options): # pylint: disable=signature-differs
lhs = sympify(lhs, strict=True)
rhs = sympify(rhs, strict=True)

Expand Down
10 changes: 0 additions & 10 deletions diofant/functions/combinatorial/factorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from ...core import Dummy, E, Function, Integer, cacheit, oo, zoo
from ...core.function import ArgumentIndexError
from ...core.sympify import sympify


class CombinatorialFunction(Function):
Expand Down Expand Up @@ -80,8 +79,6 @@ def fdiff(self, argindex=1):

@classmethod
def eval(cls, n):
n = sympify(n)

if n.is_Number:
if n is oo:
return oo
Expand Down Expand Up @@ -327,9 +324,6 @@ class RisingFactorial(CombinatorialFunction):

@classmethod
def eval(cls, x, k):
x = sympify(x)
k = sympify(k)

if x == 1:
return factorial(k)
elif k.is_Integer:
Expand Down Expand Up @@ -399,9 +393,6 @@ class FallingFactorial(CombinatorialFunction):

@classmethod
def eval(cls, x, k):
x = sympify(x)
k = sympify(k)

if k.is_Integer:
if k == 0:
return Integer(1)
Expand Down Expand Up @@ -524,7 +515,6 @@ def fdiff(self, argindex=1):

@classmethod
def eval(cls, n, k):
n, k = map(sympify, (n, k))
d = n - k
if d.is_zero or k.is_zero:
return Integer(1)
Expand Down
3 changes: 0 additions & 3 deletions diofant/functions/elementary/exponential.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from ...core import (Add, E, Function, I, Integer, Mul, Pow, expand_log, nan,
oo, pi, zoo)
from ...core.function import ArgumentIndexError, _coeff_isneg
from ...core.sympify import sympify
from ...ntheory import multiplicity, perfect_power
from .miscellaneous import sqrt

Expand Down Expand Up @@ -178,10 +177,8 @@ def inverse(self, argindex=1):
@classmethod
def eval(cls, arg, base=None):
from .complexes import unpolarify
arg = sympify(arg)

if base is not None:
base = sympify(base)
if base == 1:
if arg == 1:
return nan
Expand Down
10 changes: 0 additions & 10 deletions diofant/functions/elementary/hyperbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ def inverse(self, argindex=1):
def eval(cls, arg):
from .trigonometric import sin

arg = sympify(arg)

if arg.is_Number:
if arg in (oo, -oo, 0):
return arg
Expand Down Expand Up @@ -209,7 +207,6 @@ def fdiff(self, argindex=1):
@classmethod
def eval(cls, arg):
from .trigonometric import cos
arg = sympify(arg)

if arg.is_Number:
if arg in (oo, -oo):
Expand Down Expand Up @@ -356,7 +353,6 @@ def inverse(self, argindex=1):
@classmethod
def eval(cls, arg):
from .trigonometric import tan
arg = sympify(arg)

if arg.is_Number:
if arg is oo:
Expand Down Expand Up @@ -485,7 +481,6 @@ def inverse(self, argindex=1):
@classmethod
def eval(cls, arg):
from .trigonometric import cot
arg = sympify(arg)

if arg.is_Number:
if arg is oo:
Expand Down Expand Up @@ -767,7 +762,6 @@ def fdiff(self, argindex=1):
@classmethod
def eval(cls, arg):
from .trigonometric import asin
arg = sympify(arg)

if arg.is_Number:
if arg in (oo, -oo, 0):
Expand Down Expand Up @@ -846,8 +840,6 @@ def fdiff(self, argindex=1):

@classmethod
def eval(cls, arg):
arg = sympify(arg)

if arg.is_Number:
if arg in (oo, -oo):
return oo
Expand Down Expand Up @@ -956,7 +948,6 @@ def fdiff(self, argindex=1):
@classmethod
def eval(cls, arg):
from .trigonometric import atan
arg = sympify(arg)

if arg.is_Number:
if arg == 0:
Expand Down Expand Up @@ -1023,7 +1014,6 @@ def fdiff(self, argindex=1):
@classmethod
def eval(cls, arg):
from .trigonometric import acot
arg = sympify(arg)

if arg.is_Number:
if arg in (oo, -oo):
Expand Down
1 change: 0 additions & 1 deletion diofant/functions/elementary/miscellaneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def sqrt(arg, **kwargs):
* https://en.wikipedia.org/wiki/Principal_value
"""
# arg = sympify(arg) is handled by Pow
return Pow(arg, Rational(1, 2), **kwargs)


Expand Down
1 change: 0 additions & 1 deletion diofant/functions/elementary/piecewise.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class Piecewise(Function):
is_Piecewise = True

def __new__(cls, *args, **options):
# (Try to) sympify args first
newargs = []
for ec in args:
# ec could be a ExprCondPair or a tuple
Expand Down
6 changes: 1 addition & 5 deletions diofant/functions/special/delta_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from ...core import Eq, Function, Integer, Rational, diff
from ...core.function import ArgumentIndexError
from ...core.sympify import sympify
from ...polys.polyerrors import PolynomialError
from ..elementary.complexes import im, sign
from ..elementary.piecewise import Piecewise
Expand Down Expand Up @@ -56,12 +55,10 @@ def fdiff(self, argindex=1):
raise ArgumentIndexError(self, argindex)

@classmethod
def eval(cls, arg, k=0):
k = sympify(k)
def eval(cls, arg, k=Integer(0)):
if not k.is_Integer or k.is_negative:
raise ValueError('Error: the second argument of DiracDelta must be '
f'a non-negative integer, {k} given instead.')
arg = sympify(arg)
if arg.is_nonzero:
return Integer(0)

Expand Down Expand Up @@ -201,7 +198,6 @@ def fdiff(self, argindex=1):

@classmethod
def eval(cls, arg):
arg = sympify(arg)
if im(arg).is_nonzero:
raise ValueError('Function defined only for Real Values. '
f'Complex part: {im(arg)!r} found in {arg!r} .')
Expand Down
4 changes: 0 additions & 4 deletions diofant/functions/special/gamma_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from ...core import (Add, Dummy, EulerGamma, Expr, Function, I, Integer, Pow,
Rational, oo, pi, zoo)
from ...core.function import ArgumentIndexError
from ...core.sympify import sympify
from ..combinatorial.factorials import RisingFactorial, factorial, rf
from ..combinatorial.numbers import bernoulli, harmonic
from ..elementary.exponential import exp, log
Expand Down Expand Up @@ -611,7 +610,6 @@ def _eval_aseries(self, n, args0, x, logx):

@classmethod
def eval(cls, n, z):
n, z = list(map(sympify, (n, z)))
from .. import unpolarify

if n.is_integer:
Expand Down Expand Up @@ -822,8 +820,6 @@ class loggamma(Function):

@classmethod
def eval(cls, z):
z = sympify(z)

if z.is_integer:
if z.is_nonpositive:
return oo
Expand Down
11 changes: 3 additions & 8 deletions diofant/functions/special/spherical_harmonics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from ...core import Dummy, Function, I, pi
from ...core.function import ArgumentIndexError
from ...core.sympify import sympify
from ..combinatorial.factorials import factorial
from ..elementary.complexes import Abs
from ..elementary.exponential import exp
Expand Down Expand Up @@ -133,8 +132,6 @@ class Ynm(Function):

@classmethod
def eval(cls, n, m, theta, phi):
n, m, theta, phi = [sympify(x) for x in (n, m, theta, phi)]

# Handle negative index m and arguments theta, phi
if m.could_extract_minus_sign():
m = -m
Expand Down Expand Up @@ -262,13 +259,11 @@ class Znm(Function):

@classmethod
def eval(cls, n, m, theta, phi):
n, m, th, ph = [sympify(x) for x in (n, m, theta, phi)]

if m.is_positive:
zz = (Ynm(n, m, th, ph) + Ynm_c(n, m, th, ph)) / sqrt(2)
zz = (Ynm(n, m, theta, phi) + Ynm_c(n, m, theta, phi))/sqrt(2)
return zz
elif m.is_zero:
return Ynm(n, m, th, ph)
return Ynm(n, m, theta, phi)
elif m.is_negative:
zz = (Ynm(n, m, th, ph) - Ynm_c(n, m, th, ph)) / (sqrt(2)*I)
zz = (Ynm(n, m, theta, phi) - Ynm_c(n, m, theta, phi))/(sqrt(2)*I)
return zz
17 changes: 5 additions & 12 deletions diofant/functions/special/zeta_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from ...core import (Add, Dummy, E, Function, I, Integer, Rational, expand_mul,
oo, pi, zoo)
from ...core.function import ArgumentIndexError
from ...core.sympify import sympify
from ..combinatorial.numbers import bernoulli, factorial, harmonic
from ..elementary.exponential import exp, exp_polar, log

Expand Down Expand Up @@ -416,17 +415,11 @@ class zeta(Function):
"""

@classmethod
def eval(cls, z, a_=None):
if a_ is None:
z, a = list(map(sympify, (z, 1)))
else:
z, a = list(map(sympify, (z, a_)))

if a.is_Number:
if a == 1 and a_ is not None:
return cls(z)
# TODO Should a == 0 return nan as well?

def eval(cls, z, a=None):
if a == 1:
return cls(z)
elif a is None:
a = Integer(1)
if z.is_Number:
if z is oo:
return Integer(1)
Expand Down
Loading

0 comments on commit 3568916

Please sign in to comment.