-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
integrate((x**8+1)**(-1/2),x) raises _CoeffExpValueError #26571
Labels
Comments
I now realise that the error goes away if I change the exponent to |
It seems to be a bug in In [12]: S(2.0).as_coeff_mul(x)
Out[12]: (1, (2.0,))
In [13]: S(2).as_coeff_mul(x)
Out[13]: (2, ()) |
diff --git a/sympy/core/numbers.py b/sympy/core/numbers.py
index b497a1bedc..2ff6011536 100644
--- a/sympy/core/numbers.py
+++ b/sympy/core/numbers.py
@@ -537,7 +537,7 @@ def __hash__(self):
def is_constant(self, *wrt, **flags):
return True
- def as_coeff_mul(self, *deps, rational=True, **kwargs):
+ def as_coeff_mul(self, *deps, rational=False, **kwargs):
# a -> c*t
if self.is_Rational or not rational:
return self, () |
diff --git a/sympy/core/mul.py b/sympy/core/mul.py
index d93dbde758..23a9ebc5fe 100644
--- a/sympy/core/mul.py
+++ b/sympy/core/mul.py
@@ -2156,8 +2156,12 @@ def _keep_coeff(coeff, factors, clear=True, sign=False):
return coeff
if coeff is S.One:
return factors
- elif coeff is S.NegativeOne and not sign:
+ elif coeff.is_Float and equal_valued(coeff, S.One):
+ return Add(*[coeff*term for term in Add.make_args(factors)])
+ elif not sign and coeff is S.NegativeOne:
return -factors
+ elif not sign and coeff.is_Float and equal_valued(coeff, S.NegativeOne):
+ return Add(*[coeff*term for term in Add.make_args(factors)])
elif factors.is_Add:
if not clear and coeff.is_Rational and coeff.q != 1:
args = [i.as_coeff_Mul() for i in factors.args]
@@ -2191,6 +2195,6 @@ def do(e):
return bottom_up(e, do)
-from .numbers import Rational
+from .numbers import Rational, equal_valued
from .power import Pow
from .add import Add, _unevaluated_Add
diff --git a/sympy/core/numbers.py b/sympy/core/numbers.py
index b497a1bedc..2ff6011536 100644
--- a/sympy/core/numbers.py
+++ b/sympy/core/numbers.py
@@ -537,7 +537,7 @@ def __hash__(self):
def is_constant(self, *wrt, **flags):
return True
- def as_coeff_mul(self, *deps, rational=True, **kwargs):
+ def as_coeff_mul(self, *deps, rational=False, **kwargs):
# a -> c*t
if self.is_Rational or not rational:
return self, ()
diff --git a/sympy/core/tests/test_expr.py b/sympy/core/tests/test_expr.py
index 8299ca312c..e52da8caf3 100644
--- a/sympy/core/tests/test_expr.py
+++ b/sympy/core/tests/test_expr.py
@@ -1250,9 +1250,10 @@ def test_as_coeff_add():
def test_as_coeff_mul():
assert S(2).as_coeff_mul() == (2, ())
- assert S(3.0).as_coeff_mul() == (1, (S(3.0),))
- assert S(-3.0).as_coeff_mul() == (-1, (S(3.0),))
+ assert S(3.0).as_coeff_mul() == (S(3.0), ())
+ assert S(-3.0).as_coeff_mul() == (S(-3.0), ())
assert S(-3.0).as_coeff_mul(rational=False) == (-S(3.0), ())
+ assert S(-3.0).as_coeff_mul(rational=True) == (-1, (S(3.0),))
assert x.as_coeff_mul() == (1, (x,))
assert (-x).as_coeff_mul() == (-1, (x,))
assert (2*x).as_coeff_mul() == (2, (x,))
diff --git a/sympy/holonomic/tests/test_holonomic.py b/sympy/holonomic/tests/test_holonomic.py
index e5069c89a8..991d2c3d85 100644
--- a/sympy/holonomic/tests/test_holonomic.py
+++ b/sympy/holonomic/tests/test_holonomic.py
@@ -624,7 +624,7 @@ def test_to_expr():
q = 1.4*a*x**2
assert p == q
p = (expr_to_holonomic(1.4*x)+expr_to_holonomic(a*x, x)).to_expr()
- q = x*(a + 1.4)
+ q = x*(1.0*a + 1.4)
assert p == q
p = (expr_to_holonomic(1.4*x)+expr_to_holonomic(x)).to_expr()
assert p == 2.4*x |
oscarbenjamin
added
Easy to Fix
This is a good issue for new contributors. Feel free to work on this if no one else has already.
core
integrals.meijerg
and removed
Easy to Fix
This is a good issue for new contributors. Feel free to work on this if no one else has already.
labels
May 7, 2024
oscarbenjamin
added a commit
to oscarbenjamin/sympy
that referenced
this issue
May 7, 2024
integrate((x**8+1)**(-1/2), x)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With sympy version 1.12, this code:
raises a _CoeffExpValueError. The full trace is shown below. Maple gives
x*hypergeom([1/8, 1/2], [9/8], -x^8)
as the value of this integral.The text was updated successfully, but these errors were encountered: