#19824: Faster comparison code in (real embedded) number fields
-------------------------------------+-------------------------------------
       Reporter:  vdelecroix         |        Owner:
           Type:  enhancement        |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-7.0
      Component:  number fields      |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Vincent Delecroix  |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/vdelecroix/19824                 |  c9c7133322fe7d762d7fb5c95f5d105c60788f90
   Dependencies:  #19822             |     Stopgaps:
-------------------------------------+-------------------------------------
Changes (by vdelecroix):

 * type:  PLEASE CHANGE => enhancement


Old description:

> Using #19822 we provide a faster comparison code for number field
> elements when a real embedding is defined (see #17830). We obtain `x10`
> speed up. The new code is also `x50` faster than comparisons in `QQbar`
> (with a fixed number field element!!).
>
> 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: %timeit test(a,10)
> 10 loops, best of 3: 51.1 ms per loop
> sage: %timeit test(a,20)
> 10 loops, best of 3: 67 ms per loop
> sage: %timeit test(a,100)
> 10 loops, best of 3: 108 ms per loop
> 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: %timeit test(a,10)
> 100 loops, best of 3: 5.84 ms per loop
> sage: %timeit test(a,20)
> 100 loops, best of 3: 10.2 ms per loop
> sage: %timeit test(a,100)
> 10 loops, best of 3: 33.5 ms per loop
> 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: %timeit test(a,10)
> 10 loops, best of 3: 97.7 ms per loop
> sage: %timeit test(a,20)
> 10 loops, best of 3: 133 ms per loop
> sage: %timeit test(a,100)
> 1 loops, best of 3: 224 ms per loop
> sage: %timeit test(a,200)
> 1 loops, best of 3: 305 ms per loop
> }}}

New description:

 Using #19822 we provide a faster comparison code for number field elements
 when a real embedding is defined (see #17830). We obtain `x10` speed up
 for small elements and `x2` speed up for larger ones. The new code is also
 `x50` faster than comparisons in `QQbar` (with a fixed number field
 element!!).

 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: %timeit test(a,10)
 10 loops, best of 3: 51.1 ms per loop
 sage: %timeit test(a,20)
 10 loops, best of 3: 67 ms per loop
 sage: %timeit test(a,100)
 10 loops, best of 3: 108 ms per loop
 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: %timeit test(a,10)
 100 loops, best of 3: 5.84 ms per loop
 sage: %timeit test(a,20)
 100 loops, best of 3: 10.2 ms per loop
 sage: %timeit test(a,100)
 10 loops, best of 3: 33.5 ms per loop
 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: %timeit test(a,10)
 10 loops, best of 3: 97.7 ms per loop
 sage: %timeit test(a,20)
 10 loops, best of 3: 133 ms per loop
 sage: %timeit test(a,100)
 1 loops, best of 3: 224 ms per loop
 sage: %timeit test(a,200)
 1 loops, best of 3: 305 ms per loop
 }}}

--

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