Skip to content

Commit 863fc64

Browse files
Merge pull request sympy#26940 from smichr/heurisch
fixes permutation of types in heurisch
2 parents 5b2c92a + 9ddff22 commit 863fc64

File tree

6 files changed

+58
-28
lines changed

6 files changed

+58
-28
lines changed

.github/workflows/runtests.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,27 +187,27 @@ jobs:
187187
# Test modules with specific dependencies
188188
- run: bin/test_optional_dependencies.py
189189

190-
# -------------------- NumPy nightly ----------------------------- #
190+
# -------------------- Bleeding edge dependencies ----------------- #
191191

192-
numpy-nightly:
192+
bleeding-edge:
193193
needs: code-quality
194-
195-
runs-on: ubuntu-20.04
196-
197-
name: NumPy/SciPy nightly
198-
194+
name: Bleeding edge dependencies
195+
runs-on: ubuntu-24.04
199196
steps:
200197
- uses: actions/checkout@v4
201198
- uses: actions/setup-python@v5
202199
with:
203-
python-version: 3.12
204-
205-
- run: pip install -r requirements-dev.txt
200+
python-version: '3.12'
201+
- run: sudo apt-get update
202+
- run: sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev libflint-dev
203+
- run: pip install git+https://github.com/flintlib/python-flint.git@master
204+
- run: pip install git+https://github.com/aleaxit/gmpy.git@master
205+
- run: pip install git+https://github.com/mpmath/mpmath.git@master
206206
- run: pip install -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
207207
- run: pip install -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple scipy
208-
209-
# Test modules with specific dependencies
210-
- run: bin/test_optional_dependencies.py
208+
- run: pip install -r requirements-dev.txt
209+
- run: pip install .
210+
- run: pytest -n auto
211211

212212
# -------------------- FLINT tests -------------------------------- #
213213

doc/src/modules/sets.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ Elementary Sets
2626
Compound Sets
2727
-------------
2828

29-
.. module:: sympy.sets.sets
30-
:noindex:
31-
3229
.. autoclass:: Union
3330
:members:
3431

sympy/integrals/heurisch.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,15 +504,16 @@ def heurisch(f, x, rewrite=False, hints=None, mappings=None, retries=3,
504504
# optimizing the number of permutations of mapping #
505505
assert mapping[-1][0] == x # if not, find it and correct this comment
506506
unnecessary_permutations = [mapping.pop(-1)]
507-
# only permute types of objects and let the ordering
508-
# of types take care of the order of replacement
507+
# permute types of objects
509508
types = defaultdict(list)
510509
for i in mapping:
511-
types[type(i)].append(i)
510+
e, _ = i
511+
types[type(e)].append(i)
512512
mapping = [types[i] for i in types]
513513
def _iter_mappings():
514514
for i in permutations(mapping):
515-
yield [j for i in i for j in i]
515+
# make the expression of a given type be ordered
516+
yield [j for i in i for j in ordered(i)]
516517
mappings = _iter_mappings()
517518
else:
518519
unnecessary_permutations = unnecessary_permutations or []

sympy/integrals/tests/test_heurisch.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from sympy.integrals.heurisch import components, heurisch, heurisch_wrapper
2020
from sympy.testing.pytest import XFAIL, slow
2121
from sympy.integrals.integrals import integrate
22+
from sympy import S
23+
2224
x, y, z, nu = symbols('x,y,z,nu')
2325
f = Function('f')
2426

@@ -368,6 +370,8 @@ def test_heurisch_complex_erf_issue_26338():
368370

369371
a = exp(-x**2/(2*(2 - I)**2))
370372
assert heurisch(a, x, hints=[]) is None # None, not a wrong soln
373+
a = exp(-r**2/(2*(2 - I)**2))
374+
assert heurisch(a, r, hints=[]) is None
371375
a = sqrt(pi)*erf((1 + I)/2)/2
372376
assert integrate(exp(-I*x**2/2), (x, 0, 1)) == a - I*a
373377

@@ -387,3 +391,29 @@ def test_issue_15498():
387391
integrand = m*m.subs(t, s)**-1*f_vec.subs(aif_eq.lhs, aif_eq.rhs).subs(t, s)
388392
solution = integrate(integrand[0], (s, 0, t))
389393
assert solution is not None # does not hang and takes less than 10 s
394+
395+
396+
@slow
397+
def test_heurisch_issue_26930():
398+
integrand = x**Rational(4, 3)*log(x)
399+
anti = 3*x**(S(7)/3)*log(x)/7 - 9*x**(S(7)/3)/49
400+
assert heurisch(integrand, x) == anti
401+
assert integrate(integrand, x) == anti
402+
assert integrate(integrand, (x, 0, 1)) == -S(9)/49
403+
404+
405+
def test_heurisch_issue_26922():
406+
407+
a, b, x = symbols("a, b, x", real=True, positive=True)
408+
C = symbols("C", real=True)
409+
i1 = -C*x*exp(-a*x**2 - sqrt(b)*x)
410+
i2 = C*x*exp(-a*x**2 + sqrt(b)*x)
411+
i = Integral(i1, x) + Integral(i2, x)
412+
res = (
413+
-C*exp(-a*x**2)*exp(sqrt(b)*x)/(2*a)
414+
+ C*exp(-a*x**2)*exp(-sqrt(b)*x)/(2*a)
415+
+ sqrt(pi)*C*sqrt(b)*exp(b/(4*a))*erf(sqrt(a)*x - sqrt(b)/(2*sqrt(a)))/(4*a**(S(3)/2))
416+
+ sqrt(pi)*C*sqrt(b)*exp(b/(4*a))*erf(sqrt(a)*x + sqrt(b)/(2*sqrt(a)))/(4*a**(S(3)/2))
417+
)
418+
419+
assert i.doit(heurisch=False).expand() == res

sympy/integrals/tests/test_integrals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,8 +1146,8 @@ def test_issue_3940():
11461146
a, b, c, d = symbols('a:d', positive=True)
11471147
assert integrate(exp(-x**2 + I*c*x), x) == \
11481148
-sqrt(pi)*exp(-c**2/4)*erf(I*c/2 - x)/2
1149-
assert integrate(exp(a*x**2 + b*x + c), x) == \
1150-
sqrt(pi)*exp(c - b**2/(4*a))*erfi((2*a*x + b)/(2*sqrt(a)))/(2*sqrt(a))
1149+
assert integrate(exp(a*x**2 + b*x + c), x).equals(
1150+
sqrt(pi)*exp(c - b**2/(4*a))*erfi((2*a*x + b)/(2*sqrt(a)))/(2*sqrt(a)))
11511151

11521152
from sympy.core.function import expand_mul
11531153
from sympy.abc import k

sympy/stats/sampling/tests/test_sample_discrete_rv.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from sympy.core.singleton import S
2-
from sympy.core.symbol import Symbol
2+
#from sympy.core.symbol import Symbol
33
from sympy.external import import_module
4-
from sympy.stats import Geometric, Poisson, Zeta, sample, Skellam, DiscreteRV, Logarithmic, NegativeBinomial, YuleSimon
4+
from sympy.stats import Geometric, Poisson, Zeta, sample, Skellam, Logarithmic, NegativeBinomial, YuleSimon
55
from sympy.testing.pytest import skip, raises, slow
66

77

@@ -27,11 +27,13 @@ def test_sample_numpy():
2727

2828

2929
def test_sample_scipy():
30-
p = S(2)/3
31-
x = Symbol('x', integer=True, positive=True)
32-
pdf = p*(1 - p)**(x - 1) # pdf of Geometric Distribution
30+
#p = S(2)/3
31+
#x = Symbol('x', integer=True, positive=True)
32+
#pdf = p*(1 - p)**(x - 1) # pdf of Geometric Distribution
3333
distribs_scipy = [
34-
DiscreteRV(x, pdf, set=S.Naturals),
34+
# This one fails:
35+
# https://github.com/sympy/sympy/issues/26862
36+
# DiscreteRV(x, pdf, set=S.Naturals),
3537
Geometric('G', 0.5),
3638
Logarithmic('L', 0.5),
3739
NegativeBinomial('N', 5, 0.4),

0 commit comments

Comments
 (0)