#12142: Speed up PARI finite field operations
---------------------------+-----------------------------------------------
       Reporter:           |         Owner:  AlexGhitza
  johanbosman              |        Status:  positive_review
           Type:           |     Milestone:  sage-5.12
  enhancement              |    Resolution:
       Priority:  major    |     Merged in:
      Component:  basic    |     Reviewers:  Jean-Pierre Flori
  arithmetic               |   Work issues:
       Keywords:           |  Dependencies:  #14817, #14818, #14832, #14833
        Authors:  Peter    |
  Bruin                    |
Report Upstream:  N/A      |
         Branch:           |
       Stopgaps:           |
---------------------------+-----------------------------------------------
Changes (by jdemeyer):

 * milestone:  sage-5.11 => sage-5.12


Old description:

> Let us perform a simple addition of finite field elements that are
> represented using Pari.
> {{{
> sage: F.<a> = GF(3^11)
> sage: x = F.random_element()
> sage: y = F.random_element()
> sage: %timeit x + y
> 625 loops, best of 3: 13.2 µs per loop
> }}}
> Let us now measure how much time the *actual* addition takes:
> {{{
> sage: vx = x._FiniteField_ext_pariElement__value
> sage: vy = y._FiniteField_ext_pariElement__value
> sage: %timeit vx + vy
> 625 loops, best of 3: 4.6 µs per loop
> }}}
> This means two thirds of the execution time is used to wrap a ribbon
> around the result and only one third for the actual addition!
>
> But in fact Pari has a faster implementation for finite fields than this!
> This was already mentioned at http://groups.google.com/group/sage-
> nt/browse_thread/thread/e2dbbc72caeb589a
> {{{
> sage: def pari_ffelt(x): parix=pari(x); return
> parix.lift().subst(parix.variable(), "ffgen((%s).mod)"%parix)
>
> sage: px = pari_ffelt(x)
> sage: py = pari_ffelt(y)
> sage: %timeit px + py
> 625 loops, best of 3: 2.43 µs per loop
> }}}
> For multiplication, we have the following timings:
> {{{
> sage: %timeit x * y
> 625 loops, best of 3: 18.2 µs per loop
> sage: %timeit vx * vy
> 625 loops, best of 3: 8.4 µs per loop
> sage: %timeit px * py
> 625 loops, best of 3: 3.33 µs per loop
> }}}
>
> This ticket implements an interface to PARI's FFELT type for non-prime
> finite fields.  It can be tested by constructing finite fields as
> follows, for ''p'' prime and ''n'' >= 2:
> {{{
> sage: F.<a> = FiniteField(p^n, impl='pari_ffelt')
> }}}
> This implementation should probably become the default for non-prime
> finite fields of characteristic > 2 and cardinality > 2^16^, superseding
> the existing PARI polmod implementation.  This switch is the goal of
> ticket #14888.
>
> Apply:
> * [attachment:trac_12142-FiniteField_pari_ffelt.improved.patch]
> * [attachment:trac_12142-singular_conversion.patch]
> * [attachment:trac_12142-reviewer.patch]
> * [attachment:trac_12142-doctest.patch]
> * [attachment:trac_12142-remove_cinit.patch]

New description:

 Let us perform a simple addition of finite field elements that are
 represented using PARI.
 {{{
 sage: F.<a> = GF(3^11)
 sage: x = F.random_element()
 sage: y = F.random_element()
 sage: %timeit x + y
 625 loops, best of 3: 13.2 µs per loop
 }}}
 Let us now measure how much time the *actual* addition takes:
 {{{
 sage: vx = x._FiniteField_ext_pariElement__value
 sage: vy = y._FiniteField_ext_pariElement__value
 sage: %timeit vx + vy
 625 loops, best of 3: 4.6 µs per loop
 }}}
 This means two thirds of the execution time is used to wrap a ribbon
 around the result and only one third for the actual addition!

 But in fact Pari has a faster implementation for finite fields than this!
 This was already mentioned at http://groups.google.com/group/sage-
 nt/browse_thread/thread/e2dbbc72caeb589a
 {{{
 sage: def pari_ffelt(x): parix=pari(x); return
 parix.lift().subst(parix.variable(), "ffgen((%s).mod)"%parix)

 sage: px = pari_ffelt(x)
 sage: py = pari_ffelt(y)
 sage: %timeit px + py
 625 loops, best of 3: 2.43 µs per loop
 }}}
 For multiplication, we have the following timings:
 {{{
 sage: %timeit x * y
 625 loops, best of 3: 18.2 µs per loop
 sage: %timeit vx * vy
 625 loops, best of 3: 8.4 µs per loop
 sage: %timeit px * py
 625 loops, best of 3: 3.33 µs per loop
 }}}

 This ticket implements an interface to PARI's FFELT type for non-prime
 finite fields.  It can be tested by constructing finite fields as follows,
 for ''p'' prime and ''n'' >= 2:
 {{{
 sage: F.<a> = FiniteField(p^n, impl='pari_ffelt')
 }}}
 This implementation should probably become the default for non-prime
 finite fields of characteristic > 2 and cardinality > 2^16^, superseding
 the existing PARI polmod implementation.  This switch is the goal of
 ticket #14888.

 Apply:
 * [attachment:trac_12142-FiniteField_pari_ffelt.improved.patch]
 * [attachment:trac_12142-singular_conversion.patch]
 * [attachment:trac_12142-reviewer.patch]
 * [attachment:trac_12142-doctest.patch]
 * [attachment:trac_12142-remove_cinit.patch]

--

--
Ticket URL: <http://trac.sagemath.org/ticket/12142#comment:20>
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/groups/opt_out.


Reply via email to