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

segfault on printing Integral of phi(t) #9057

Closed
cbm755 opened this Issue Feb 26, 2015 · 6 comments

Comments

Projects
None yet
2 participants
@cbm755
Copy link
Contributor

cbm755 commented Feb 26, 2015

In [1]: from sympy import *
In [2]: from sympy.abc import phi, t
In [3]: e0 = Integral(phi(t), (t, 0, 1))

In [4]: pprint(e0)

1        
⌠        
⎮ φ(t) dt
⌡        
0        

In [5]: q = e0 + 2

In [6]: print(q)

Segmentation fault (core dumped)

This causes the test in #8416 / #6134 to fail (segfault)

@cbm755 cbm755 added the printing label Feb 26, 2015

@cbm755

This comment has been minimized.

Copy link
Contributor

cbm755 commented Feb 26, 2015

I've traced this failure to:

e0 = integrate(phi(t),(t,0,1))
e1 = integrate(alpha(t),(t,0,1))
e1.evalf()   # TypeError: can't convert expression to float
e0.evalf()   # segfault

Then further to:

phi = Symbol('phi')
phi(0.5)     # segfault

Evaluating Symbols at Floats seems to misbehave: beta and phi behave differently than alpha. Of course beta is the beta function by default. But it looks like it becomes such again even when overwritten with beta = Symbol('beta').

This looks suspicious and is invoked by evalf:

    155     def __call__(self, *args):
    156         from .function import Function
--> 157         return Function(self.name)(*args)
@cbm755

This comment has been minimized.

Copy link
Contributor

cbm755 commented Feb 26, 2015

Ok, self contained example. Consider:

beta = Symbol('beta')
beta(2)             # output is "beta(2)"
beta(2.5)

But the last one outputs:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-45022b875f5a> in <module>()
----> 1 beta(2.5)

/usr/lib/python2.7/site-packages/sympy/core/symbol.pyc in __call__(self, *args)
    140     def __call__(self, *args):
    141         from .function import Function
--> 142         return Function(self.name)(*args)
    143 
    144     def as_real_imag(self, deep=True, **hints):

/usr/lib/python2.7/site-packages/sympy/core/function.pyc in __new__(cls, *args, **options)
    683     def __new__(cls, *args, **options):
    684         args = list(map(sympify, args))
--> 685         obj = super(AppliedUndef, cls).__new__(cls, *args, **options)
    686         return obj
    687 

/usr/lib/python2.7/site-packages/sympy/core/function.pyc in __new__(cls, *args, **options)
    380         pr2 = min(cls._should_evalf(a) for a in result.args)
    381         if pr2 > 0:
--> 382             return result.evalf(mlib.libmpf.prec_to_dps(pr))
    383         return result
    384 

/usr/lib/python2.7/site-packages/sympy/core/evalf.pyc in evalf(self, n, subs, maxn, chop, strict, quad, verbose)
   1315             options['quad'] = quad
   1316         try:
-> 1317             result = evalf(self, prec + 4, options)
   1318         except NotImplementedError:
   1319             # Fall back to the ordinary evalf

/usr/lib/python2.7/site-packages/sympy/core/evalf.pyc in evalf(x, prec, options)
   1215             if 'subs' in options:
   1216                 x = x.subs(evalf_subs(prec, options['subs']))
-> 1217             re, im = x._eval_evalf(prec).as_real_imag()
   1218             if re.has(re_) or im.has(im_):
   1219                 raise NotImplementedError

/usr/lib/python2.7/site-packages/sympy/core/function.pyc in _eval_evalf(self, prec)
    484 
    485         with mpmath.workprec(prec):
--> 486             v = func(*args)
    487 
    488         return Expr._from_mpmath(v, prec)

TypeError: beta() takes exactly 3 arguments (2 given)
@cbm755

This comment has been minimized.

Copy link
Contributor

cbm755 commented Feb 26, 2015

Maybe this is all just a dupe of #6134? The test isn't valid because it doesn't pass, it just segfaults.

Also, as far as I can tell, this test has been segfaulting for a long time but it does not seem to cause the tests to be marked failing (!)

@asmeurer

This comment has been minimized.

Copy link
Member

asmeurer commented Feb 27, 2015

Unless you are using compiled code or ctypes (SymPy does neither), a segfault is a bug in the Python interpreter. What is your exact sys.version?

@cbm755

This comment has been minimized.

Copy link
Contributor

cbm755 commented Feb 27, 2015

sys.version
Out[4]: '2.7.8 (default, Nov 10 2014, 08:19:18) \n[GCC 4.9.2 20141101 (Red Hat 4.9.2-1)]'
sympy.__version__
Out[5]: '0.7.6'

This is on Fedora 21.

cbm755 added a commit to cbm755/sympy that referenced this issue Feb 27, 2015

pprint: change test to fail instead of segfault
This is sympy#9057.  Just makes the error more obvious and hopefully
causes it to actually fail instead of segfaulting (which should
be a failure but doesn't seem to be (!)

cbm755 added a commit to cbm755/sympy that referenced this issue Feb 27, 2015

pprint: add tests where beta/phi Symbols become Functions
This is sympy#9057.  Just makes the error more obvious and hopefully
causes it to actually fail, in case the segfaulting is specific
to my system.

skirpichev added a commit to skirpichev/diofant that referenced this issue May 31, 2016

skirpichev added a commit to skirpichev/diofant that referenced this issue Nov 2, 2016

Add regression tests & mention closed issues
    close sympy/sympy#3112 (MrvAsympt was added in diofant#6)
    close sympy/sympy#9173 (test was added in 5a510ac)
    close sympy/sympy#9808 (fixed in 09e539b)
    close sympy/sympy#9341 (fixed in af98a00)
    close sympy/sympy#9908 (fixed in cc3fa8d)
    close sympy/sympy#6171 (test added in d278031)
    close sympy/sympy#9276 (diagnose_imports.py removed in ab8c535)
    close sympy/sympy#10201 (fixed in 0d0fc5f)
    close sympy/sympy#9057 (test was added in 8290a0c)
    close sympy/sympy#11159 (test was added in ffb76cb)
    close sympy/sympy#2839 (new AST transformers are used, see diofant#278 and diofant#167)
    close sympy/sympy#11081 (see ed01e16 and bb92329)
    close sympy/sympy#10974 (see 73fc425)
    close sympy/sympy#10806 (test in 539929a)
    close sympy/sympy#10801 (test in 2fe3da5)
    close sympy/sympy#9549 (test in 88bdefa)
    close sympy/sympy#4231 (test was added in fb411d5)
    close sympy/sympy#8634 (see 2fcbb58)
    close sympy/sympy#8481 (see 1ef20d3)
    close sympy/sympy#9956 (fixed in a34735f)
    close sympy/sympy#9747 (see e117c60)
    close sympy/sympy#7853 (see 3e4fbed)
    close sympy/sympy#9634 (see 2be03f5)
    close sympy/sympy#8500 (fixed in diofant#104 and finally in diofant#316)
    close sympy/sympy#9192 (see 9bf622f)
    close sympy/sympy#7130 (see e068fa3)
    close sympy/sympy#8514 (see b2d543b)
    close sympy/sympy#9334 (see 90de625)
    close sympy/sympy#8229 (see 9755b89)
    close sympy/sympy#8061 (see 7054f06)
    close sympy/sympy#7872 (tested in diofant#6)
    close sympy/sympy#3496 (tested in test_log_symbolic)
    close sympy/sympy#2929 (see da7db7a)
    close sympy/sympy#8203 (oo is not a real, see diofant#36)
    close sympy/sympy#7649 (0 is imaginary since diofant#8)
    close sympy/sympy#7256 (fixed in c0a4549)
    close sympy/sympy#6783 (see cb28d63)
    close sympy/sympy#5662 (is_integer issue fixed in 6bfa9f8, there is no is_bounded anymore)
    close sympy/sympy#5295 (fixed with diofant#354)
    close sympy/sympy#4856 (we now have flake/pep tests)
    close sympy/sympy#4555 (flake8 enabled after diofant#214)
    close sympy/sympy#5773 (cmp_to_key removed after diofant#164 and c9acbf0)
    close sympy/sympy#5484 (see above)

    Added regression tests:
    from https://groups.google.com/forum/#!topic/sympy/LkTMQKC_BOw
    fixes sympy/sympy#8825 (probably via diofant#209)
    fixes sympy/sympy#8635
    fixes sympy/sympy#8157
    fixes sympy/sympy#7872
    fixes sympy/sympy#7599
    fixes sympy/sympy#6179
    fixes sympy/sympy#5415
    fixes sympy/sympy#2865
    fixes sympy/sympy#5907
    fixes sympy/sympy#11722

    Closes diofant#347

skirpichev added a commit to skirpichev/diofant that referenced this issue Nov 2, 2016

Add regression tests & mention closed issues
    close sympy/sympy#3112 (MrvAsympt was added in diofant#6)
    close sympy/sympy#9173 (test was added in 5a510ac)
    close sympy/sympy#9808 (fixed in 09e539b)
    close sympy/sympy#9341 (fixed in af98a00)
    close sympy/sympy#9908 (fixed in cc3fa8d)
    close sympy/sympy#6171 (test added in d278031)
    close sympy/sympy#9276 (diagnose_imports.py removed in ab8c535)
    close sympy/sympy#10201 (fixed in 0d0fc5f)
    close sympy/sympy#9057 (test was added in 8290a0c)
    close sympy/sympy#11159 (test was added in ffb76cb)
    close sympy/sympy#2839 (new AST transformers are used, see diofant#278 and diofant#167)
    close sympy/sympy#11081 (see ed01e16 and bb92329)
    close sympy/sympy#10974 (see 73fc425)
    close sympy/sympy#10806 (test in 539929a)
    close sympy/sympy#10801 (test in 2fe3da5)
    close sympy/sympy#9549 (test in 88bdefa)
    close sympy/sympy#4231 (test was added in fb411d5)
    close sympy/sympy#8634 (see 2fcbb58)
    close sympy/sympy#8481 (see 1ef20d3)
    close sympy/sympy#9956 (fixed in a34735f)
    close sympy/sympy#9747 (see e117c60)
    close sympy/sympy#7853 (see 3e4fbed)
    close sympy/sympy#9634 (see 2be03f5)
    close sympy/sympy#8500 (fixed in diofant#104 and finally in diofant#316)
    close sympy/sympy#9192 (see 9bf622f)
    close sympy/sympy#7130 (see e068fa3)
    close sympy/sympy#8514 (see b2d543b)
    close sympy/sympy#9334 (see 90de625)
    close sympy/sympy#8229 (see 9755b89)
    close sympy/sympy#8061 (see 7054f06)
    close sympy/sympy#7872 (tested in diofant#6)
    close sympy/sympy#3496 (tested in test_log_symbolic)
    close sympy/sympy#2929 (see da7db7a)
    close sympy/sympy#8203 (oo is not a real, see diofant#36)
    close sympy/sympy#7649 (0 is imaginary since diofant#8)
    close sympy/sympy#7256 (fixed in c0a4549)
    close sympy/sympy#6783 (see cb28d63)
    close sympy/sympy#5662 (is_integer issue fixed in 6bfa9f8, there is no is_bounded anymore)
    close sympy/sympy#5295 (fixed with diofant#354)
    close sympy/sympy#4856 (we now have flake/pep tests)
    close sympy/sympy#4555 (flake8 enabled after diofant#214)
    close sympy/sympy#5773 (cmp_to_key removed after diofant#164 and c9acbf0)
    close sympy/sympy#5484 (see above)

    Added regression tests:
    from https://groups.google.com/forum/#!topic/sympy/LkTMQKC_BOw
    fixes sympy/sympy#8825 (probably via diofant#209)
    fixes sympy/sympy#8635
    fixes sympy/sympy#8157
    fixes sympy/sympy#7872
    fixes sympy/sympy#7599
    fixes sympy/sympy#6179
    fixes sympy/sympy#5415
    fixes sympy/sympy#2865
    fixes sympy/sympy#5907
    fixes sympy/sympy#11722

    Closes diofant#347
@cbm755

This comment has been minimized.

Copy link
Contributor

cbm755 commented Aug 15, 2018

I cannot reproduce the segfault anymore so I will close this. The underlying cause is fixed by #9064 (which has its own issue number, #3539).

@cbm755 cbm755 closed this Aug 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment