#10100: Segfault calling change_ring(RR) on a symbolic polynomial
-----------------------------+----------------------------------------------
   Reporter:  davidloeffler  |          Owner:  burcin         
       Type:  defect         |         Status:  positive_review
   Priority:  major          |      Milestone:  sage-4.7.1     
  Component:  symbolics      |       Keywords:                 
Work_issues:                 |       Upstream:  N/A            
   Reviewer:  Volker Braun   |         Author:  Mike Hansen    
     Merged:                 |   Dependencies:                 
-----------------------------+----------------------------------------------
Changes (by vbraun):

  * status:  needs_review => positive_review
  * reviewer:  => Volker Braun
  * milestone:  => sage-4.7.1


Old description:

> The following code seems to crash Sage on some (but not all) systems:
> {{{
> sage: a = var('a')
> sage: R.<x>  = a.parent()[]
> sage: (x - a).change_ring(RR) # boom!
> }}}
>
> This bug was originally spotted when calculating char polys of symbolic
> matrices:
> {{{
> sage: a,b,c= var('a,b,c')
> sage: mprime = matrix([[01,b+1,2],[a+1,2,1],[2,1,c+1]])
> sage: cp = mprime.charpoly()
> sage: cp.real_roots() # boom!
> }}}
> See [http://groups.google.co.uk/group/sage-
> devel/browse_thread/thread/0ea6c973a56191ab/e91868cd98f7fb74 this sage-
> devel thread].

New description:

 The following code seems to crash Sage on some (but not all) systems:
 {{{
 sage: a = var('a')
 sage: R.<x>  = a.parent()[]
 sage: (x - a).change_ring(RR) # boom!
 }}}

 This bug was originally spotted when calculating char polys of symbolic
 matrices:
 {{{
 sage: a,b,c= var('a,b,c')
 sage: mprime = matrix([[01,b+1,2],[a+1,2,1],[2,1,c+1]])
 sage: cp = mprime.charpoly()
 sage: cp.real_roots() # boom!
 }}}
 See [http://groups.google.co.uk/group/sage-
 devel/browse_thread/thread/0ea6c973a56191ab/e91868cd98f7fb74 this sage-
 devel thread].

 Apply [attachment:trac_10100.patch]

--

Comment:

 For the record, the bug is that Python might throw an exception in a loop,
 so there is no guarantee that the whole loop is evaluated. Which is why
 Mike's fix is the correct one, first loop over all values and
 `mpfr_init2()` them, then loop again over all values and set their values.

 It would be nicer to apply RAII and keep resource allocation strictly to
 the `__cinit__()` constructor, but in this case that is challenging
 because the degree of the polynomial must be computed first. Could be done
 by factoring out that part into a factory function. But thats already a
 significant rewrite...

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10100#comment:4>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to