Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make accessing coefficients of finite-field elements easier #33748

Closed
yyyyx4 opened this issue Apr 23, 2022 · 9 comments
Closed

make accessing coefficients of finite-field elements easier #33748

yyyyx4 opened this issue Apr 23, 2022 · 9 comments

Comments

@yyyyx4
Copy link
Member

yyyyx4 commented Apr 23, 2022

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

@yyyyx4 yyyyx4 added this to the sage-9.7 milestone Apr 23, 2022
@tscrim
Copy link
Collaborator

tscrim commented Apr 25, 2022

Reviewer: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Apr 25, 2022

comment:2

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.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 25, 2022

Changed commit from d3f8af6 to 372464b

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 25, 2022

Branch pushed to git repo; I updated commit sha1. New commits:

372464bfix doc syntax

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 25, 2022

Branch pushed to git repo; I updated commit sha1. New commits:

121d0abadd .__iter__() method to finite-field elements

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 25, 2022

Changed commit from 372464b to 121d0ab

@yyyyx4
Copy link
Member Author

yyyyx4 commented Apr 25, 2022

comment:5

Thanks — indeed, .__iter__() is significantly faster than the fallback through .__getitem__().

@tscrim
Copy link
Collaborator

tscrim commented Apr 25, 2022

comment:6

Thanks. LGTM.

@vbraun
Copy link
Member

vbraun commented May 22, 2022

Changed branch from public/access_finite_field_element_coefficients to 121d0ab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants