Ask Your Question

asking real part of a function crash the kernel

asked 2019-08-15 09:22:32 +0200

ortollj gravatar image

updated 2019-08-15 15:02:21 +0200

Iguananaut gravatar image


SageMath 8.8 notebook OS=W10

asking the real part of this function systematically crash the kernel with the message :

The kernel appears to have died. It will restart automatically.

a_n=1/20*(1/2*sqrt(5) + 1/2)^n*(11*sqrt(5) + 25) - 1/20*(-1/2*sqrt(5) + 1/2)^n*(11*sqrt(5) - 25) - 1/12*(1/2*I*sqrt(3) + 1/2)^n*(I*sqrt(3) + 3) - 1/12*(-1/2*I*sqrt(3) + 1/2)^n*(-I*sqrt(3) + 3)
edit retag flag offensive close merge delete


this function for n>= 0 has no imaginary part

for i in (0..12) :
ortollj gravatar imageortollj ( 2019-08-15 09:31:35 +0200 )edit

Have you tried it at the command prompt? In general it's good to isolate a problem from the specific environment in which it occurred, if possible.

Iguananaut gravatar imageIguananaut ( 2019-08-15 14:58:28 +0200 )edit

I tried it too, and I just had time to see segmentation fault and the command window crashed.

ortollj gravatar imageortollj ( 2019-08-15 17:20:20 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-08-15 15:02:58 +0200

Iguananaut gravatar image

updated 2019-08-15 15:34:36 +0200

I got

sage: n=var('n')
sage: assume(n>=0)
sage: assume(n,'integer')
sage: a_n=1/20*(1/2*sqrt(5) + 1/2)^n*(11*sqrt(5) + 25) - 1/20*(-1/2*sqrt(5) + 1/2)^n*(11*sqrt(5) - 25) - 1/12*
....: (1/2*I*sqrt(3) + 1/2)^n*(I*sqrt(3) + 3) - 1/12*(-1/2*I*sqrt(3) + 1/2)^n*(-I*sqrt(3) + 3)
sage: a_n.real_part()
Unhandled SIGSEGV: A segmentation fault occurred.
This probably occurred because a *compiled* module has a bug
in it and is not properly wrapped with sig_on(), sig_off().
Python will now terminate.
Segmentation fault (core dumped)

Will update my answer as I find out more, but obviously a segfault shouldn't happen here.

Confirmed on Linux and Windows. The segfault is coming from pynac. It seems to be specifically the assume(n, 'integer') part that does it. Without that it doesn't crash.

I spent a few minutes trying to narrow this down to a simpler example and got this

sage: n=var('n')
sage: assume(n, 'integer')
sage: (I^n).real_part()

It appears to go into an infinite recursion and eventually overflow the stack in


The correct answer for $ \mathfrak{Re}[i^n] $ should be $ \cos\left(\frac{\pi n}{2}\right) $ but I guess it's not that clever, and it certainly shouldn't crash...

If I don't stipulate that $ n \in \mathbb{Z} $ then it does give the correct answer, sort of...

sage: n=var('n')
sage: (I^n).real_part()

This is now tracked at

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-08-15 09:22:32 +0200

Seen: 214 times

Last updated: Aug 15 '19