# Revision history [back]

How are you defining f? This works for me:

sage: R = GF(2)['y']
sage: R.inject_variables()
Defining y
sage: f = y^2 + y + 1
sage: f(f(y))
y^4 + y + 1

How are you defining f? This works for me:

sage: R = GF(2)['y']
sage: R.inject_variables()
Defining y
sage: f = y^2 + y + 1
sage: f(f(y))
y^4 + y + 1

Edit: if you want to do something like f(y) = y^2 + ny, then you need two variables, and you could make one a polynomial variable, one a symbolic variable. Make sure that the symbolic one comes after the polynomial one, alphabetically:

sage: var('m')
sage: R = QQ['a']
sage: R.inject_variables()
sage: f = a^2 + m*a
sage: f(f(a))
(a^2 + a*z)^2 + (a^2 + a*z)*z
sage: f(f(a)).expand()
a^4 + 2*a^3*z + a^2*z^2 + a^2*z + a*z^2

Then

sage: f(f(f(f(f(a))))).expand()

works, but gives a very long expression.

(You need the polynomial generator to come alphabetically before the symbolic variable because f depends on two variables, and when you call f(3), for example, it chooses to substitute the 3 for the first of the variables. You want to substitute f(a) for a by default, so make sure a comes before m.)

How are you defining f? This works for me:

sage: R = GF(2)['y']
sage: R.inject_variables()
Defining y
sage: f = y^2 + y + 1
sage: f(f(y))
y^4 + y + 1

Edit: if you want to do something like f(y) = y^2 + ny, then you need two variables, and you could make one a polynomial variable, one a symbolic variable. Make sure that the symbolic one comes after the polynomial one, alphabetically:

sage: var('m')
sage: R = QQ['a']
sage: R.inject_variables()
sage: f = a^2 + m*a
sage: f(f(a))
(a^2 + a*z)^2 a*m)^2 + (a^2 + a*z)*z
a*m)*m
sage: f(f(a)).expand()
a^4 + 2*a^3*z + a^2*z^2 + a^2*z + a*z^2
2*a^3*m + a^2*m^2 + a^2*m + a*m^2

Then

sage: f(f(f(f(f(a))))).expand()

works, but gives a very long expression.

(You need the polynomial generator to come alphabetically before the symbolic variable because f depends on two variables, and when you call f(3), for example, it chooses to substitute the 3 for the first of the variables. You want to substitute f(a) for a by default, so make sure a comes before m.)