Ask Your Question

Revision history [back]

I think that you first want to define the base ring $\mathbb{Q}(t)$ and get its generators as

A = ZZ['t'].fraction_field()
t = A.gens()

Assuming that you will work over this base ring, then you can program a function T1 generic enough that works for any $n$

def T1(f):
    B = f.parent()
    x = list(B.gens())
    A = B.base_ring()
    t = A.gen()
    ff = t * f
    for i in range(len(x) - 1):
        xx = x[:]
        xx[i], xx[i+1], = xx[i+1], xx[i]
        g = f(*xx) - f(x)
        quo, rem = g.quo_rem(x[i] - x[i+1])
        assert rem.is_zero()
        ff += (t * x[i] - x[i+1]) * g
    return ff

For example

B = A['z0, z1, z2, z3']
z0, z1, z2 ,z3 = B.gens()
f = (1-t)*z0 + (1+t)*z1 + z2 - t*z3
print(T1(f))

gives me

2*t^2*z0^2 + (-2*t^2 - 2*t)*z0*z1 + (-t^2 + 2*t)*z1^2 + (t^2 + t)*z1*z2 +
(-t^2 - 2*t)*z2^2 + (t^2 + 2*t + 1)*z2*z3 + (-t - 1)*z3^2 + (-t^2 + t)*z0 +
(t^2 + t)*z1 + t*z2 + (-t^2)*z3