# Revision history [back]

Instead of symbolic variables, you can define the ai as polynomial indeterminates, as follows:

sage: P_GF2.<X,A0,A1,A2> = PolynomialRing(GF(2))
sage: GF23.<x,a0,a1,a2> = P_GF2.quotient_ring(X^3+X+1)
sage: def f(val):
....:       return val**3
sage: f(a0*+a1*x+a2*x)
x*a0^3*a1^3 + a0^3*a1^3 + x*a0^2*a1^2*a2 + a0^2*a1^2*a2 + x*a0*a1*a2^2 + a0*a1*a2^2 + x*a2^3 + a2^3


By the way, note that the field GF(2^3) is well defined in Sage:

sage: F.<x> = GF(2^3)
sage: F
Finite Field in x of size 2^3
sage: x.minpoly()
x^3 + x + 1
sage: R.<a0,a1,a2> = PolynomialRing(F)
sage: f(a0*+a1*x+a2*x)
(x + 1)*a0^3*a1^3 + (x + 1)*a0^2*a1^2*a2 + (x + 1)*a0*a1*a2^2 + (x + 1)*a2^3


Instead of symbolic variables, you can define the ai as polynomial indeterminates, as follows:

sage: P_GF2.<X,A0,A1,A2> = PolynomialRing(GF(2))
sage: GF23.<x,a0,a1,a2> = P_GF2.quotient_ring(X^3+X+1)
sage: def f(val):
....:       return val**3
sage: f(a0*+a1*x+a2*x)
x*a0^3*a1^3 + a0^3*a1^3 + x*a0^2*a1^2*a2 + a0^2*a1^2*a2 + x*a0*a1*a2^2 + a0*a1*a2^2 + x*a2^3 + a2^3


By the way, note that the field GF(2^3) is well defined in Sage:

sage: F.<x> = GF(2^3)
sage: F
Finite Field in x of size 2^3
sage: x.minpoly()
x^3 + x + 1
sage: R.<a0,a1,a2> = PolynomialRing(F)
sage: f(a0*+a1*x+a2*x)
(x + 1)*a0^3*a1^3 + (x + 1)*a0^2*a1^2*a2 + (x + 1)*a0*a1*a2^2 + (x + 1)*a2^3


EDIT

Note that since you work on a field of characteristic 2, you necessarily have ai + ai = 0:

sage: a0+a0
0


If you want your variables to also satisfy ai^2 = ai, you can just add this condition when you define the quotient ring:

sage: sage: GF23.<x,a0,a1,a2> = P_GF2.quotient_ring([X^3+X+1, A0^2+A0, A1^2+A1, A2^2+A2])
sage: GF23
Quotient of Multivariate Polynomial Ring in X, A0, A1, A2 over Finite Field of size 2 by the ideal (X^3 + X + 1, A0^2 + A0, A1^2 + A1, A2^2 + A2)
sage: a0^2
a0
sage: a0^3+a0
0


Instead of symbolic variables, you can define the ai as polynomial indeterminates, as follows:

sage: P_GF2.<X,A0,A1,A2> = PolynomialRing(GF(2))
sage: GF23.<x,a0,a1,a2> = P_GF2.quotient_ring(X^3+X+1)
sage: def f(val):
....:       return val**3
sage: f(a0*+a1*x+a2*x)
x*a0^3*a1^3 + a0^3*a1^3 + x*a0^2*a1^2*a2 + a0^2*a1^2*a2 + x*a0*a1*a2^2 + a0*a1*a2^2 + x*a2^3 + a2^3


By the way, note that the field GF(2^3) is well defined in Sage:

sage: F.<x> = GF(2^3)
sage: F
Finite Field in x of size 2^3
sage: x.minpoly()
x^3 + x + 1
sage: R.<a0,a1,a2> = PolynomialRing(F)
sage: f(a0*+a1*x+a2*x)
(x + 1)*a0^3*a1^3 + (x + 1)*a0^2*a1^2*a2 + (x + 1)*a0*a1*a2^2 + (x + 1)*a2^3


EDIT

Note that since you work on a field of characteristic 2, you necessarily have ai + ai = 0:

sage: a0+a0
0


If you want your variables to also satisfy ai^2 = ai, you can just add this condition when you define the quotient ring:

sage: sage: GF23.<x,a0,a1,a2> = P_GF2.quotient_ring([X^3+X+1, A0^2+A0, A1^2+A1, A2^2+A2])
sage: GF23
Quotient of Multivariate Polynomial Ring in X, A0, A1, A2 over Finite Field of size 2 by the ideal (X^3 + X + 1, A0^2 + A0, A1^2 + A1, A2^2 + A2)
sage: a0^2
a0
sage: a0^3+a0
0

sage: f(a0*+a1*x+a2*x) x*a0*a1 + a0*a1 + x*a2 + a2