Opened 4 months ago

Last modified 4 months ago

#28357 new defect

Segmentation fault in pynac when getting real/imag_part of a complex expression

Reported by: embray Owned by:
Priority: major Milestone: sage-wishlist
Component: symbolics Keywords: pynac assume
Cc: rws Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by embray)

From this ask question the following crashes pynac with a stack overflow:

sage: n=var('n')
sage: assume(n, 'integer')
sage: (I^n).real_part()
/home/embray/src/sagemath/sage/local/lib/python2.7/site-packages/cysignals/signals.so(+0x80b5)[0x7f5b6da330b5]
/home/embray/src/sagemath/sage/local/lib/python2.7/site-packages/cysignals/signals.so(+0x8158)[0x7f5b6da33158]
/home/embray/src/sagemath/sage/local/lib/python2.7/site-packages/cysignals/signals.so(+0x96ad)[0x7f5b6da346ad]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x10330)[0x7f5b7cf14330]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZNK5GiNaC7numeric3gcdERKS0_+0x1d)[0x7f594bfdcd7d]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZN5GiNaC3gcdERKNS_7numericES2_+0x9)[0x7f594bfe0e29]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZNK5GiNaC3add15integer_contentEv+0xcc)[0x7f594bfcc80c]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZNK5GiNaC3add5powerERKNS_7numericE+0x37)[0x7f594bf09d97]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZNK5GiNaC5power4evalEi+0x1933)[0x7f594bff6cf3]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZN5GiNaC2ex20construct_from_basicERKNS_5basicE+0x76)[0x7f594bf283a6]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZNK5GiNaC3mul29combine_ex_with_coeff_to_pairERKNS_2exERKNS_7numericE+0xb8)[0x7f594bfbcfb8]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZNK5GiNaC9expairseq12evalchildrenEi+0xa7)[0x7f594bf31df7]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZNK5GiNaC3mul4evalEi+0x36)[0x7f594bfc2d16]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZN5GiNaC2ex20construct_from_basicERKNS_5basicE+0x76)[0x7f594bf283a6]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZNK5GiNaC3add20recombine_pair_to_exERKNS_6expairE+0x5d)[0x7f594bf050bd]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZNK5GiNaC3add4infoEj+0x196)[0x7f594bf05ae6]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZNK5GiNaC5power4evalEi+0x460)[0x7f594bff5820]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZN5GiNaC2ex20construct_from_basicERKNS_5basicE+0x76)[0x7f594bf283a6]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZNK5GiNaC5power4evalEi+0x12e5)[0x7f594bff66a5]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZN5GiNaC2ex20construct_from_basicERKNS_5basicE+0x76)[0x7f594bf283a6]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZNK5GiNaC5power9real_partEv+0x50f)[0x7f594bfef0af]
/home/embray/src/sagemath/sage/local/lib/libpynac.so.18(_ZNK5GiNaC5power9real_partEv+0x51)[0x7f594bfeebf1]
...

followed by an infinite recursion in GiNaC::power::real_part(). It doesn't crash without assume(n, 'integer'), and gives a correct answer:

sage: n=var('n')
sage: (I^n).real_part()
cos(1/2*pi*real_part(n))*e^(-1/2*pi*imag_part(n))

so stipulating that assume(n, 'integer') should set imag_part(n) == 0 and real_part(n) == n and give the correct answer...

Change History (2)

comment:1 Changed 4 months ago by embray

  • Description modified (diff)

comment:2 Changed 4 months ago by embray

  • Cc rws added
Note: See TracTickets for help on using tickets.