Ask Your Question

Revision history [back]

You can use a Pyton dicttionary to define your substitution, and you can define your dictionary with comprehension:

For example, with p=5:

sage: d = {PRz(y[i]):t[i]/2 for i in range(p)}

You get the dictionary:

sage: d
{y_4: 1/2*x_4 + 1/2/x_4,
 y_3: 1/2*x_3 + 1/2/x_3,
 y_2: 1/2*x_2 + 1/2/x_2,
 y_1: 1/2*x_1 + 1/2/x_1,
 y_0: 1/2*x_0 + 1/2/x_0}

Then:

sage: polynomial = PRz.random_element()
sage: polynomial
2*x_0*x_1 - x_2*x_3 - x_1*y_2 - y_1*y_2 + 1/2*y_4

sage: polynomial.subs(d)
2*x_0*x_1 - 1/4*(x_1 + 1/x_1)*(x_2 + 1/x_2) - 1/2*x_1*(x_2 + 1/x_2) - x_2*x_3 + 1/4*x_4 + 1/4/x_4