Skip to content

Speed up PARI finite field operations #12142

@sagetrac-johanbosman

Description

@sagetrac-johanbosman

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 > 216, superseding the existing PARI polmod implementation. This switch is the goal of ticket #14888.

Apply:

Depends on #14817
Depends on #14818
Depends on #14832
Depends on #14833

CC: @koffie @jpflori

Component: basic arithmetic

Author: Peter Bruin

Reviewer: Jean-Pierre Flori

Merged: sage-5.12.beta3

Issue created by migration from https://trac.sagemath.org/ticket/12142

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions