#16374: better two_squares, three_squares, four_squares for small input
-------------------------------------+-------------------------------------
       Reporter:  vdelecroix         |        Owner:
           Type:  enhancement        |       Status:  needs_info
       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                 |  f1354e68519feecd5de198c10a532b89ee938a7b
   Dependencies:  #16308             |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by vdelecroix):

 Hi Nathann,

 Thanks for reading it.

 > I added a commit in u/ncohen/16374 which contains some tests and
 comments.

 Great. I also have something important to modify in `three_squares_pyx`
 and `four_squares_pyx`. It is '''much''' faster to first remove a huge
 square and then try to decompose the rest into a sum of less squares. The
 result is not the smallest for lexicographical order but the timings are
 x4 better.

 It seems that you like C function declaration of the form {{{int f(int
 res[3])}}}. It makes the specifications clearer but at compilation the
 results are strictly equivalent.

 > I have two questions to ask though :
 >
 > - Why {{{ii <= n/2}}} and not {{{ii<=jj}}} ?

 Right.

 > - Why a "while" instead of a "if" in the following code ?
 > {{{
 >     j = (<unsigned int> sqrt(<double> n)) + 1 # (rounding is toward
 zero)
 >     while j*j > n:
 >         j -= 1
 > }}}

 I am not sure of the specification (if any) of `sqrt` which deals with
 double... I will try to improve it.

 > Besides, there is a way to avoid many multiplications, and **perhaps**
 it can improve the code a bit (no idea, profiling is the only way `:-P`)

 I thought about it. I am not sure that {{{ii += 2*i + 1}}} is cheaper than
 {{{ii = i*i}}} ? Will have a look.

 Vincent

--
Ticket URL: <http://trac.sagemath.org/ticket/16374#comment:5>
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