This line is the most-proximate cause of your errors:
i := unapply(add(i[k](t)*p^k, k = 0 .. n), t);
Now, I only spent about 1 minute looking at your code. There's certainly something wrong with that line, but I don't want to say (yet) that it's completely wrong---perhaps there is some valid concept that you were trying to express. But note that your equivalent lines s:= ..., e:= ..., and r:= ... do not use the same variable on the left and right sides of the assignment.
You may think that x and x[k] are distinct independent variables---they are not. Assignments made to either will affect the other. But they aren't the same variable either! They are neither completely the same nor completely different. Their situation is somewhat akin to quantum entanglement but asymmetric---the x[k] being a completely dependent "child" of its "parent" x: Erasing x also erases x[k], but erasing x[k] doesn't erase x.
There is a commonly given workaround for this situation, but it doesn't apply in this case. It's to use x__k instead of x[k]. The variables x and x__k are distinct and independent. This workaround doesn't work in this case because k and x__k are also independent.
And there's also a less-mysterious commonly given explanation of the connection between x and x[k] which also doesn't apply in this case: x is a table (akin to an array) and x[k] is an entry (element) of that table. This explanation doesn't apply when x is a procedure, which is what the result of unapply is. In that case, the invocations x(...) and x[...](...) invoke exactly the same procedure. The procedure can detect that it was invoked with the extra [...] if it chooses to check that; but if it doesn't check, then the two invocations do exactly the same thing, which is what is happening in your case.
In other words, in your line
i:= unapply(add(i[k](t)*p^k, k = 0 .. n), t)
the [k] is ultimately ignored because the line makes i into a procedure that doesn't check whether it was invoked with an index (such as ) attached. That doesn't happen with your other similar lines such as
s:= unapply(add(g[k](t)*p^k, k = 0 .. n), t)
because g is just an unassigned variable, not a procedure.