#16719: replace gap.eval with libgap.eval in combinat/combinat.py
-------------------------------------------------+-------------------------
Reporter: rws | Owner:
Type: defect | Status: new
Priority: major | Milestone: sage-6.3
Component: combinatorics | Resolution:
Keywords: gap, bignum, expect, pexpect, | Merged in:
libgap, stirling | Reviewers:
Authors: | Work issues:
Report Upstream: N/A | Commit:
Branch: | Stopgaps:
Dependencies: |
-------------------------------------------------+-------------------------
Changes (by rws):
* keywords: gap, bignum, expect, pexpect, libgap => gap, bignum, expect,
pexpect, libgap, stirling
Old description:
> As first reported in #15625 (comment:7) with `lucas_number1`, the same
> problem is encountered with gap evaluation of Stirling numbers:
> {{{
> sage: stirling_number1(1000,2)
> ---------------------------------------------------------------------------
> TypeError Traceback (most recent call
> last)
> <ipython-input-22-b29f3b3e2003> in <module>()
> ----> 1 stirling_number1(Integer(1000),Integer(2))
>
> /home/ralf/sage/local/lib/python2.7/site-
> packages/sage/combinat/combinat.pyc in stirling_number1(n, k)
> 650 """
> 651 return
> Integer(gap.eval("Stirling1({0},{1})".format(Integer(n),
> --> 652
> Integer(k))))
> 653
> 654
>
> /home/ralf/sage/local/lib/python2.7/site-packages/sage/rings/integer.so
> in sage.rings.integer.Integer.__init__
> (build/cythonized/sage/rings/integer.c:7902)()
>
> TypeError: unable to convert x (=<integer 301...000 (2566 digits)>) to an
> integer
> }}}
> The way to go would be to replace `gap.eval` with `libgap.eval` and it's
> faster, too:
> {{{
> sage: timeit('Integer(gap.eval("Stirling1(100,2)"))')
> 625 loops, best of 3: 419 µs per loop
> sage: timeit('libgap.eval("Stirling1(100,2)").sage()')
> 625 loops, best of 3: 125 µs per loop
> sage: timeit('libgap.eval("Stirling1(1000,2)").sage()')
> 125 loops, best of 3: 6.45 ms per loop
> }}}
> Addendum: even faster would be to use `(n-1)!*H(n-1)` for
> `stirling(n,2)`, dependent on #16671:
> {{{
> sage: harmonic_number(99)*factorial(99)==stirling_number1(100,2)
> True
> sage: timeit('harmonic_number(99)*factorial(99)')
> 625 loops, best of 3: 56.9 µs per loop
> }}}
New description:
As first reported in #15625 (comment:7) with `lucas_number1`, the same
problem is encountered with gap evaluation of Stirling numbers:
{{{
sage: stirling_number1(1000,2)
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
<ipython-input-22-b29f3b3e2003> in <module>()
----> 1 stirling_number1(Integer(1000),Integer(2))
/home/ralf/sage/local/lib/python2.7/site-
packages/sage/combinat/combinat.pyc in stirling_number1(n, k)
650 """
651 return
Integer(gap.eval("Stirling1({0},{1})".format(Integer(n),
--> 652
Integer(k))))
653
654
/home/ralf/sage/local/lib/python2.7/site-packages/sage/rings/integer.so in
sage.rings.integer.Integer.__init__
(build/cythonized/sage/rings/integer.c:7902)()
TypeError: unable to convert x (=<integer 301...000 (2566 digits)>) to an
integer
}}}
The way to go would be to replace `gap.eval` with `libgap.eval` and it's
faster, too:
{{{
sage: timeit('Integer(gap.eval("Stirling1(100,2)"))')
625 loops, best of 3: 419 µs per loop
sage: timeit('libgap.eval("Stirling1(100,2)").sage()')
625 loops, best of 3: 125 µs per loop
sage: timeit('libgap.eval("Stirling1(1000,2)").sage()')
125 loops, best of 3: 6.45 ms per loop
}}}
Addendum: even faster would be to use `(n-1)!*H(n-1)` for `stirling(n,2)`,
dependent on #16671:
{{{
sage: harmonic_number(99)*factorial(99)==stirling_number1(100,2)
True
sage: timeit('harmonic_number(99)*factorial(99)')
625 loops, best of 3: 56.9 µs per loop
sage: timeit('harmonic_number(999)*factorial(999)')
625 loops, best of 3: 119 µs per loop
}}}
--
--
Ticket URL: <http://trac.sagemath.org/ticket/16719#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.