#6059: [with patch; needs review] speed regresion in hilbert_symbol after #5834
---------------------------+------------------------------------------------
 Reporter:  tornaria       |       Owner:  tornaria  
     Type:  defect         |      Status:  new       
 Priority:  major          |   Milestone:  sage-4.0  
Component:  number theory  |    Keywords:  regression
---------------------------+------------------------------------------------

Comment(by tornaria):

 I screwed it up the first version, because I was trying to avoid overhead.
 The original code, good for integers only (before #5834) was:
 {{{
 a = ZZ(a)
 }}}
 My first version was
 {{{
 a = ZZ(a.numerator() * a.denominator())
 }}}
 which breaks when {{{a}}} is a (python) {{{int}}}. The new version is
 {{{
 a = QQ(a).numerator() * QQ(a).denominator()
 }}}
 which should be safe for all purposes (my first version was in between).

 Indeed, I'm a bit concerned about overhead. Compare the trivial
 {{{
 sage: timeit("hilbert_symbol(1,1,-1)")
 625 loops, best of 3: 10.3 µs per loop
 }}}
 using the original code (only good for integers) vs.
 {{{
 sage: timeit("hilbert_symbol(1,1,-1)")
 625 loops, best of 3: 19.1 µs per loop
 }}}
 with the new code (good for rationals).

 And check out the speed of the actual computation:
 {{{
 sage: a = ZZ.random_element(10^50)
 sage: b = ZZ.random_element(10^50)
 sage: p = next_prime(ZZ.random_element(10^50))
 sage: timeit("pari(a).hilbert(b,p)")
 625 loops, best of 3: 3.13 µs per loop
 }}}

 Is there a standard/suggested way of writing the preamble of a function
 (where parameters are checked, coerced, etc) to minimize overhead in a
 fast path?
 (I guess this is what one buys with a dynamic language... and moving this
 to cython could help if really necessary).

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/6059#comment:2>
Sage <http://sagemath.org/>
Sage - Open Source Mathematical Software: Building the Car Instead of 
Reinventing the Wheel

--~--~---------~--~----~------------~-------~--~----~
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