Skip to content

Commit

Permalink
Merge pull request #325 from skirpichev/check-meijerg
Browse files Browse the repository at this point in the history
Add sanity checks for meijerg parameters
  • Loading branch information
skirpichev committed Aug 10, 2016
2 parents f631841 + f09968b commit 1ffddee
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
14 changes: 12 additions & 2 deletions diofant/functions/special/hyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,16 +436,26 @@ def __new__(cls, *args):
if len(args) == 5:
args = [(args[0], args[1]), (args[2], args[3]), args[4]]
if len(args) != 3:
raise TypeError("args must eiter be as, as', bs, bs', z or "
raise TypeError("args must be either as, as', bs, bs', z or "
"as, bs, z")

def tr(p):
if len(p) != 2:
raise TypeError("wrong argument")
return TupleArg(_prep_tuple(p[0]), _prep_tuple(p[1]))

arg0, arg1 = tr(args[0]), tr(args[1])
if Tuple(arg0, arg1).has(S.Infinity, S.ComplexInfinity,
S.NegativeInfinity):
raise ValueError("G-function parameters must be finite")

if any((a - b).is_integer and (a - b).is_positive
for a in arg0[0] for b in arg1[0]):
raise ValueError("no parameter a1, ..., an may differ from "
"any b1, ..., bm by a positive integer")

# TODO should we check convergence conditions?
return Function.__new__(cls, tr(args[0]), tr(args[1]), args[2])
return Function.__new__(cls, arg0, arg1, args[2])

def fdiff(self, argindex=3):
if argindex != 3:
Expand Down
6 changes: 6 additions & 0 deletions diofant/functions/special/tests/test_hyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ def test_meijer():
assert tn(meijerg(Tuple(1, 1), Tuple(), Tuple(1), Tuple(0), z),
log(1 + z), z)

# test exceptions
pytest.raises(ValueError, lambda: meijerg(((3, 1), (2,)),
((oo,), (2, 0)), x))
pytest.raises(ValueError, lambda: meijerg(((3, 1), (2,)),
((1,), (2, 0)), x))

# differentiation
g = meijerg((randcplx(),), (randcplx() + 2*I,), Tuple(),
(randcplx(), randcplx()), z)
Expand Down
11 changes: 8 additions & 3 deletions diofant/integrals/meijerint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,11 @@ def _rewrite_single(f, x, recursive=True):
for fac, g in terms:
r1 = _get_coeff_exp(unpolarify(fac.subs(subs).subs(z, x),
exponents_only=True), x)
g = g.subs(subs).subs(z, x)
try:
g = g.subs(subs).subs(z, x)
except ValueError:
continue

# NOTE these substitutions can in principle introduce oo,
# zoo and other absurdities. It shouldn't matter,
# but better be safe.
Expand All @@ -1477,8 +1481,9 @@ def _rewrite_single(f, x, recursive=True):
return
_debug('Trying recursive Mellin transform method.')
from diofant.integrals.transforms import (mellin_transform,
inverse_mellin_transform, IntegralTransformError,
MellinTransformStripError)
inverse_mellin_transform,
IntegralTransformError,
MellinTransformStripError)
from diofant import oo, nan, zoo, simplify, cancel

def my_imt(F, s, x, strip):
Expand Down
14 changes: 12 additions & 2 deletions diofant/integrals/tests/test_meijerint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from diofant import (meijerg, I, integrate, Integral, oo, gamma, cosh,
hyperexpand, exp, simplify, sqrt, pi, erf, sin, cos,
exp_polar, polygamma, hyper, log, expand_func, Integer,
Rational)
Rational, nan)
from diofant.integrals.meijerint import (_rewrite_single, _rewrite1,
meijerint_indefinite, _inflate_g,
_create_lookup_table, meijerint_definite,
_create_lookup_table,
meijerint_definite,
meijerint_inversion)
from diofant.utilities import default_sort_key
from diofant.utilities.randtest import (verify_numerically,
Expand Down Expand Up @@ -651,3 +652,12 @@ def test_issue_6860():
def test_issue_8368():
assert meijerint_indefinite(cosh(x)*exp(-x*t), x) == (
(-t - 1)*exp(x) + (-t + 1)*exp(-x))*exp(-t*x)/2/(t**2 - 1)


def test_meijerint_indefinite_abs():
# issue sympy/sympy#4311
assert meijerint_indefinite(x*abs(9 - x**2), x) is not nan
# issue sympy/sympy#7165
assert meijerint_indefinite(abs(y - x**2), y) is not nan
# issue sympy/sympy#8733
assert meijerint_indefinite(abs(x + 1), x) is not nan

0 comments on commit 1ffddee

Please sign in to comment.