#16374: better two_squares, three_squares, four_squares for small input
-------------------------------------+-------------------------------------
       Reporter:  vdelecroix         |        Owner:
           Type:  enhancement        |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-6.3
      Component:  number theory      |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Vincent Delecroix  |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/vdelecroix/16374                 |  352e255834a35c951f8bf22a6161df8cef56e51a
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------
Changes (by vdelecroix):

 * status:  needs_work => needs_review


Comment:

 Hi,

 The file is now `sum_of_squares.pyx`.

 I changed the `unsigned int` to `unsigned long` as Jeroen suggested. The
 loss in terms of timing seems to be around 1% (see below). Nevertheless,
 the function makes no sense for very large input as it is much faster to
 called the Python function from `arith` (see also below).

 For the rounding issue with `sqrt`, it uses now `<unsigned long>
 sqrt(<double> n)` and there is an exhaustive test in the doc of the
 function `two_squares_pyx`.

 unsigned int
 {{{
 sage: from sage.rings.sum_of_squares import four_squares_pyx
 sage: timeit("for n in xrange(10000,50000): x = four_squares_pyx(n)")
 25 loops, best of 3: 11 ms per loop
 }}}

 unsigned long
 {{{
 sage: from sage.rings.sum_of_squares import four_squares_pyx
 sage: timeit("for n in xrange(10000,50000): x = four_squares_pyx(n)")
 25 loops, best of 3: 11.3 ms per loop
 }}}

 Very large input
 {{{
 sage: from sage.rings.sum_of_squares import two_squares_pyx
 sage: %timeit two_squares_pyx(2**51+21)
 10 loops, best of 3: 88.1 ms per loop
 sage: %timeit two_squares(2**51+21)
 1000 loops, best of 3: 1.04 ms per loop
 }}}

 Vincent

--
Ticket URL: <http://trac.sagemath.org/ticket/16374#comment:19>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to