#16374: better two_squares, three_squares, four_squares for small input
-------------------------------------+-------------------------------------
Reporter: vdelecroix | Owner:
Type: enhancement | Status: new
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 ncohen):
Hello !
I added a commit in u/ncohen/16374 which contains some tests and comments.
I have two questions to ask though :
- Why {{{ii <= n/2}}} and not {{{ii<=jj}}} ?
- 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
}}}
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`)
{{{
sage: i = 5
sage: ii = i**2
sage: i**2 == ii
True
sage: ii+=2*i+1
sage: i+=1
sage: i**2 == ii
True
}}}
Nathann
--
Ticket URL: <http://trac.sagemath.org/ticket/16374#comment:3>
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.