#16424: is_triangular_number() speed up
-------------------------------+----------------------------
Reporter: rws | Owner:
Type: enhancement | Status: new
Priority: minor | Milestone: sage-6.3
Component: quadratic forms | Keywords:
Merged in: | Authors:
Reviewers: | Report Upstream: N/A
Work issues: | Branch:
Commit: | Dependencies:
Stopgaps: |
-------------------------------+----------------------------
The name implies a boolean return value (contrary to the implementation),
and used that way the function is way too slow:
{{{
sage: timeit('l=[n for n in range(1000) if is_square(8*(n)+1)]')
625 loops, best of 3: 909 µs per loop
sage: timeit('l=[n for n in range(1000) if is_triangular_number(n)]')
5 loops, best of 3: 200 ms per loop
sage: timeit('l=[n for n in range(1000) if is_square(8*(n)+1)]')
625 loops, best of 3: 903 µs per loop
sage: timeit('l=[n for n in range(1000) if is_triangular_number(n)]')
5 loops, best of 3: 195 ms per loop
}}}
The reason is that the simple boolean test used above is not performed
before the more involved computation of the index.
--
Ticket URL: <http://trac.sagemath.org/ticket/16424>
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.