#19822: Fast polynomial evaluation fmpz_poly/ZZX with mpfr/mpfi input
-------------------------------------+-------------------------------------
       Reporter:  vdelecroix         |        Owner:
           Type:  enhancement        |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-7.0
      Component:  algebra            |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Vincent Delecroix  |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/vdelecroix/19822                 |  683cd0de16503dc913750fd7c417129409b010c6
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------
Description changed by vdelecroix:

Old description:

> We implement functions that allow fast evaluations of integer polynomials
> with real input:
> - `fmpz_poly_eval_mpfr(mpfr_t res, const fmpz_poly_t poly, const mpfr_t
> a, mpfr_rnd_t rnd)`
> - `fmpz_poly_eval_mpfi(mpfi_t res, const fmpz_poly_t poly, const mpfi_t
> a)`
> - `ZZX_eval_mpfr(mpfr_t res, ZZX_c poly, const mpfr_t a, const mpfr_rnd_t
> rnd)`
> - `ZZX_eval_mpfi(mpfi_t res, ZZX_c poly, const mpfi_t a)`
>
> These functions are integrated in the polynomial code and number field
> element comparisons (when real embedding is defined, see #17830). For the
> latter we win a great `x10` speed up. The new code is also is `x50`
> faster than comparisons in `QQbar`. For the benchmarks, we used the
> following comparison function
> {{{
> def test(a,n):
>     cf = continued_fraction(a)
>     cv1 = a.parent()(cf.convergent(2*n+1))
>     cv2 = a.parent()(cf.convergent(2*n+2))
>     for _ in range(200):
>         assert cv1 > a > cv2
> }}}
> Before
> {{{
> sage: x = polygen(ZZ)
> sage: K.<a> = NumberField(x^3 - 2, embedding=1.26)
> sage: sage: %timeit test(a,10)
> 10 loops, best of 3: 51.1 ms per loop
> sage: sage: %timeit test(a,20)
> 10 loops, best of 3: 67 ms per loop
> sage: sage: %timeit test(a,100)
> 10 loops, best of 3: 108 ms per loop
> sage: sage: %timeit test(a,200)
> 1 loops, best of 3: 154 ms per loop
> }}}
> after
> {{{
> sage: x = polygen(ZZ)
> sage: K.<a> = NumberField(x^3 - 2, embedding=1.26)
> sage: sage: sage: %timeit test(a,10)
> 100 loops, best of 3: 5.84 ms per loop
> sage: sage: sage: %timeit test(a,20)
> 100 loops, best of 3: 10.2 ms per loop
> sage: sage: sage: %timeit test(a,100)
> 10 loops, best of 3: 33.5 ms per loop
> sage: sage: sage: %timeit test(a,200)
> 10 loops, best of 3: 64.8 ms per loop
> }}}
> To be compared with
> {{{
> sage: a = AA(2)**(1/3)
> sage: a.exactify()
> sage: sage: %timeit test(a,10)
> 10 loops, best of 3: 97.7 ms per loop
> sage: sage: %timeit test(a,20)
> 10 loops, best of 3: 133 ms per loop
> sage: sage: %timeit test(a,100)
> 1 loops, best of 3: 224 ms per loop
> sage: sage: %timeit test(a,200)
> 1 loops, best of 3: 305 ms per loop
> }}}

New description:

 We implement functions that allow fast evaluations of integer polynomials
 with real input:
 - `fmpz_poly_eval_mpfr(mpfr_t res, const fmpz_poly_t poly, const mpfr_t a,
 mpfr_rnd_t rnd)`
 - `fmpz_poly_eval_mpfi(mpfi_t res, const fmpz_poly_t poly, const mpfi_t
 a)`
 - `ZZX_eval_mpfr(mpfr_t res, ZZX_c poly, const mpfr_t a, const mpfr_rnd_t
 rnd)`
 - `ZZX_eval_mpfi(mpfi_t res, ZZX_c poly, const mpfi_t a)`

 These functions are integrated in the polynomial code and number field
 element comparisons (when real embedding is defined, see #17830). For the
 latter we win a great `x10` speed up. The new code is also is `x50` faster
 than comparisons in `QQbar`. For the benchmarks, we used the following
 comparison function
 {{{
 def test(a,n):
     cf = continued_fraction(a)
     cv1 = a.parent()(cf.convergent(2*n+1))
     cv2 = a.parent()(cf.convergent(2*n+2))
     for _ in range(200):
         assert cv1 > a > cv2
 }}}
 Before
 {{{
 sage: x = polygen(ZZ)
 sage: K.<a> = NumberField(x^3 - 2, embedding=1.26)
 sage: sage: %timeit test(a,10)
 10 loops, best of 3: 51.1 ms per loop
 sage: sage: %timeit test(a,20)
 10 loops, best of 3: 67 ms per loop
 sage: sage: %timeit test(a,100)
 10 loops, best of 3: 108 ms per loop
 sage: sage: %timeit test(a,200)
 1 loops, best of 3: 154 ms per loop
 }}}
 after
 {{{
 sage: x = polygen(ZZ)
 sage: K.<a> = NumberField(x^3 - 2, embedding=1.26)
 sage: sage: sage: %timeit test(a,10)
 100 loops, best of 3: 5.84 ms per loop
 sage: sage: sage: %timeit test(a,20)
 100 loops, best of 3: 10.2 ms per loop
 sage: sage: sage: %timeit test(a,100)
 10 loops, best of 3: 33.5 ms per loop
 sage: sage: sage: %timeit test(a,200)
 10 loops, best of 3: 64.8 ms per loop
 }}}
 To be compared with
 {{{
 sage: a = AA(2)**(1/3)
 sage: a.exactify()
 sage: sage: %timeit test(a,10)
 10 loops, best of 3: 97.7 ms per loop
 sage: sage: %timeit test(a,20)
 10 loops, best of 3: 133 ms per loop
 sage: sage: %timeit test(a,100)
 1 loops, best of 3: 224 ms per loop
 sage: sage: %timeit test(a,200)
 1 loops, best of 3: 305 ms per loop
 }}}

 See also the following discussion for upstream integrations:

 - [https://groups.google.com/forum/#!topic/flint-devel/WAw4jvBHPyQ thread
 on flint-devel]

--

--
Ticket URL: <http://trac.sagemath.org/ticket/19822#comment:2>
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 https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to