Here is a minimal code to define (1) the "polynomial function" $x\to x^2$ as an expression, then substitute for $x$ an element of a finite field, (2) the python function $x\to x^2$, then compute it in an element of a finite field, (3) define the polynomial $x+x^2\in Bbb Z[x]$ as a polynomial with coefficients in $\Bbb Z$, then evaluate it in an element of a finite field, (4) fix a finite field $F$, define the polynomial $x+x^2\in F[x]$, and evaluate it in an element of $F$.

```
F.<a> = GF(32)
print( f"F = {F}" )
oneF = F(1)
# (1)
var('x');
f = x + x^2
# f(oneF) fails, since f is an expression, but the following works...
val = f.polynomial(F)(oneF)
print( f"# (1) f.polynomial(F)(oneF) gives the value {val}" )
# (2)
def f(x):
return x + x^2
val = f(oneF)
print( f"# (2) The python function x -> x^2 gives the value {val}" )
# (3)
R.<x> = PolynomialRing(ZZ)
f = x + x^2
val = f(oneF)
print( f"# (3) the polynomial x + x^2 in ZZ[x] gives the value {val}" )
# (4)
RF.<x> = PolynomialRing(F)
f = x + x^2
val = f(oneF)
print( f"# (4) the polynomial x + x^2 in F[x] gives the value {val}" )
```

(The polynomials over $\Bbb Z$ work in this case, since there is a coercion to finite fields, but polynomials over $\Bbb Q$ do not have it.)

The above prints give:

```
# (1) f.polynomial(F)(oneF) gives the value 0
# (2) The python function x -> x^2 gives the value 0
# (3) the polynomial x + x^2 in ZZ[x] gives the value 0
# (4) the polynomial x + x^2 in F[x] gives the value 0
```

We can also try the same with the value $b = a^4$, where $a$ is the generator of the field $F$.

```
b = a^4
# (1)
var('x');
f = x + x^2
val = f.polynomial(F)(b)
print( f"# (1) f.polynomial(F)(b) gives in b the value {val}" )
# (2)
def f(x): return x + x^2
print( f"# (2) The python function x -> x^2 gives in b the value {f(b)}" )
# (3)
R.<x> = PolynomialRing(ZZ)
f = x + x^2
print( f"# (3) the polynomial x + x^2 in ZZ[x] gives in b the value {f(b)}" )
# (4)
RF.<x> = PolynomialRing(F)
f = x + x^2
print( f"# (4) the polynomial x + x^2 in F[x] gives in b the value {f(b)}" )
```

And indeed:

```
# (1) f.polynomial(F)(b) gives in b the value a^4 + a^3 + a^2 + 1
# (2) The python function x -> x^2 gives in b the value a^4 + a^3 + a^2 + 1
# (3) the polynomial x + x^2 in ZZ[x] gives in b the value a^4 + a^3 + a^2 + 1
# (4) the polynomial x + x^2 in F[x] gives in b the value a^4 + a^3 + a^2 + 1
sage: a^4 + a^8
a^4 + a^3 + a^2 + 1
```