Opened 9 years ago
Closed 8 years ago
#14895 closed defect (fixed)
Segfault when exponentiating an integer with I.pyobject()
Reported by:  eviatarbach  Owned by:  burcin 

Priority:  critical  Milestone:  sage6.2 
Component:  symbolics  Keywords:  days57 
Cc:  Merged in:  
Authors:  Ralf Stephan  Reviewers:  Volker Braun 
Report Upstream:  N/A  Work issues:  
Branch:  4a1273f (Commits, GitHub, GitLab)  Commit:  4a1273f25f872da4302978ce4ffc671f89389179 
Dependencies:  Stopgaps: 
Description (last modified by )
Try, for example, 2^I.pyobject()
.
This is a critical issue since any method of a class inheriting from BuiltinFunction
will receive the I pyobject if I is passed as an argument to the function.
This in turn leads to segfaults like:
sage: K.<a> = NumberField(x^2+1) sage: 2^a
or
sage: K.<sqrt2> = QuadraticField(2) sage: 2^sqrt2
Change History (14)
comment:1 Changed 9 years ago by
comment:2 Changed 8 years ago by
 Milestone changed from sage6.1 to sage6.2
comment:3 Changed 8 years ago by
 Description modified (diff)
Pingpong between parent and base.
rings/rational.pyx
(Rational._pow_()
):
if PY_TYPE_CHECK(n, Element): return (<Element>n)._parent(self)**n try: return n.parent()(self)**n
rings/number_field/number_field_element.pyx
(NumberFieldElement._pow_()
):
from sage.symbolic.ring import SR try: res = QQ(base)**exp except TypeError: pass
So which one to fix?
comment:4 Changed 8 years ago by
 Branch set to u/rws/ticket/14895
 Created changed from 07/15/13 23:44:22 to 07/15/13 23:44:22
 Modified changed from 03/02/14 08:55:09 to 03/02/14 08:55:09
comment:5 Changed 8 years ago by
 Commit set to 37381336f7324de5ab98224459be69d1918da3dc
 Status changed from new to needs_review
This passes all tests in rings, and adds some tests. If you change it please keep the tests.
New commits:
3738133  Trac #14895: remove code prone to infinite loops

comment:6 Changed 8 years ago by
comment:7 Changed 8 years ago by
 Commit changed from 37381336f7324de5ab98224459be69d1918da3dc to 29a7db39373dce5c930cf5cbbd5a845321386cec
comment:8 Changed 8 years ago by
 Keywords days57 added
 Reviewers set to Volker Braun
Looks good to me, but can you remove the commentedout block? If you want to know what was there before there is always git. Lots of code has been edited at one point, if everybody would have left commentedout crap around then the source would be really hard to read.
comment:9 Changed 8 years ago by
 Branch changed from u/rws/ticket/14895 to u/rws/ticket/148951
 Commit changed from 29a7db39373dce5c930cf5cbbd5a845321386cec to 17af5a15f01fcefc85bba52f1de00308d83f200d
 Status changed from needs_review to positive_review
New commits:
17af5a1  Trac 14895: remove code prone to infinite loops

comment:10 Changed 8 years ago by
sage t long src/sage/symbolic/expression.pyx ********************************************************************** File "src/sage/symbolic/expression.pyx", line 3207, in sage.symbolic.expression.Expression.__pow__ Failed example: t^(1/2) Expected: 2*sqrt(2) Got: sqrt(8) ********************************************************************** File "src/sage/symbolic/expression.pyx", line 3209, in sage.symbolic.expression.Expression.__pow__ Failed example: (t^2)^(1/4) Expected: 2*4^(1/4) Got: 64^(1/4) **********************************************************************
So that what it was about, we want the simplified symbolic form. We should just try QQ(base)**QQ(exp)
, the QQ.__pow__
method will then find the simplified form.
comment:11 Changed 8 years ago by
 Status changed from positive_review to needs_work
comment:12 Changed 8 years ago by
 Branch changed from u/rws/ticket/148951 to u/rws/ticket/148952
 Commit changed from 17af5a15f01fcefc85bba52f1de00308d83f200d to 0b6149bed7de996d0c12f24380514e992a83f32f
 Status changed from needs_work to needs_review
Indeed, that works, and tests OK long in symbolic/ and rings/ and not long elsewhere.
New commits:
0b6149b  Trac 14895: fix segfault

comment:13 Changed 8 years ago by
 Commit changed from 0b6149bed7de996d0c12f24380514e992a83f32f to 4a1273f25f872da4302978ce4ffc671f89389179
Branch pushed to git repo; I updated commit sha1. New commits:
4a1273f  14895: add doctest

comment:14 Changed 8 years ago by
 Branch changed from u/rws/ticket/148952 to 4a1273f25f872da4302978ce4ffc671f89389179
 Resolution set to fixed
 Status changed from needs_review to closed
Infinite recursion