#11257: Avoid a coercion when computing an element to the power of 0
---------------------------+------------------------------------------------
   Reporter:  nborie       |          Owner:  nborie                        
       Type:  enhancement  |         Status:  new                           
   Priority:  major        |      Milestone:  sage-4.7.1                    
  Component:  performance  |       Keywords:  coercion, element, power, zero
Work_issues:               |       Upstream:  N/A                           
   Reviewer:               |         Author:                                
     Merged:               |   Dependencies:                                
---------------------------+------------------------------------------------
 In the generic structure of element, a coercion is called to compute an
 element z to the power of 0 : z^0

 The goal of this ticket is trying to replace all call of Parent(1) by
 Parent.one() to avoid the coercion. (and hope Sage is ready for a such
 change...)

 Before :
 {{{
 sage: K = CyclotomicField(46)
 sage: z = K.gen()
 sage: %prun z^0
          11 function calls in 0.000 CPU seconds

    Ordered by: internal time

    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
         1    0.000    0.000    0.000    0.000
 number_field.py:4871(_coerce_non_number_field_element_in)
         1    0.000    0.000    0.000    0.000 <string>:1(<module>)
         1    0.000    0.000    0.000    0.000
 number_field.py:6702(_element_constructor_)
         1    0.000    0.000    0.000    0.000
 number_field.py:4221(polynomial_ntl)
         4    0.000    0.000    0.000    0.000 {isinstance}
         1    0.000    0.000    0.000    0.000
 number_field.py:4210(absolute_polynomial_ntl)
         1    0.000    0.000    0.000    0.000 gap.py:1299(is_GapElement)
         1    0.000    0.000    0.000    0.000 {method 'disable' of
 '_lsprof.Profiler' objects}

 sage: %prun z^3
          2 function calls in 0.000 CPU seconds

    Ordered by: internal time

    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
         1    0.000    0.000    0.000    0.000 <string>:1(<module>)
         1    0.000    0.000    0.000    0.000 {method 'disable' of
 '_lsprof.Profiler' objects}
 }}}

 And for the speed :
 {{{
 sage: timeit('z^0')
 625 loops, best of 3: 28 µs per loop
 sage: timeit('z^3')
 625 loops, best of 3: 7.78 µs per loop
 }}}

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11257>
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