Finite fields have .fetch_int() to decode integers into finite-field elements by reinterpreting the base-p representation as a polynomial:
sage: F.<t> = GF(7^10)
sage: el = F.fetch_int(2424); el
t^4 + 3*t + 2
However, the inverse operation is a bit cumbersome:
sage: el.polynomial().change_ring(ZZ)(el.parent().characteristic())
2424
In this patch, we add an inverse to .fetch_int(), named .to_integer() in resemblance with the Python method int.to_bytes().
For symmetry, we then rename .fetch_int() to .from_integer(): I, for one, could never remember if .fetch_int() refers to "fetching an element from an int" or "fetching this element into an int", so I think the new name makes a lot more sense.
Also, some code cleanup and optimization while we're at it.
CC: @DaveWitteMorris @slel
Component: finite rings
Author: Lorenz Panny
Branch/Commit: 0eabc46
Reviewer: Kwankyu Lee
Issue created by migration from https://trac.sagemath.org/ticket/33941