Ask Your Question

Revision history [back]

The difference comes from different methods being available depending on the underlying finite field implementation.

The givaro implementation, available only for prime powers less than 2^16, provides a fetch_int method.

Below we illustrate this and propose a fetch_int function to provide the functionality in other cases.

Illustration

sage: p = 13
sage: F.<a> = GF(p^2)
sage: b = F.fetch_int(150)
sage: c = F.fetch_int(97)
sage: b, c, b + c
(11*a + 7, 7*a + 6, 5*a)


sage: pp = 4091
sage: FF.<aa> = GF(pp^2)
sage: FF.fetch_int(150)

sage: type(F)
<class 'sage.rings.finite_rings.finite_field_givaro.FiniteField_givaro_with_category'>
sage: type(FF)
<class 'sage.rings.finite_rings.finite_field_pari_ffelt.FiniteField_pari_ffelt_with_category'>

sage: FF.<aa> = GF(pp^2, impl='givaro')
Traceback (most recent call last)
...
ValueError: q must be < 2^16



sage: F.fetch_int??
...
    Given an integer `n` return a finite field element in ``self``
    which equals `n` under the condition that :meth:`gen()` is set to
    :meth:`characteristic()`.
...

Define fetch_int as a function:

def fetch_int(F, n):
    return FF(n.digits(base=F.characteristic()))

Then use it as follows:

sage: fetch_int(FF, 12275)
3*a + 2
sage: 3*pp + 2
sage: n
12275

Making all finite fields provide fetch_int regardless of the implementation is the object of