make accessing coefficients of finite-field elements easier
yyyyx4 opened this issue · 9 comments
This comes up rather frequently:
sage: F.<i> = GF(431^2, modulus=x^2+1)
sage: a = F.random_element() # some computation
sage: coeffs = a.polynomial().padded_list(2) # cumbersome!For number fields, we do have a shorthand:
sage: K.<i> = NumberField(x^2+1)
sage: b = K.random_element() # some computation
sage: coeffs = b.list()This patch adds a .__getitem__() method to the class FinitePolyExtElement, which makes a[i] and list(a) and tuple(a) work as expected.
For compatibility with number-field elements, we also add .list(), which should behave identically to calling list() on the element.
Component: algebra
Author: Lorenz Panny
Branch/Commit: 121d0ab
Reviewer: Travis Scrimshaw
Issue created by migration from https://trac.sagemath.org/ticket/33748
Reviewer: Travis Scrimshaw
Should we also add an __iter__ method too?
While it is not in the built documentation, if this ever gets moved into something public, the `n`th will fail.
Branch pushed to git repo; I updated commit sha1. New commits:
372464b | fix doc syntax |
Branch pushed to git repo; I updated commit sha1. New commits:
121d0ab | add .__iter__() method to finite-field elements |
Thanks — indeed, .__iter__() is significantly faster than the fallback through .__getitem__().
Thanks. LGTM.
Changed branch from public/access_finite_field_element_coefficients to 121d0ab