Ask Your Question

Revision history [back]

Would something like the following help ?

sage: def f(n): ....: return sum(SR.var('x_{}'.format(k))SR.var('x_{}'.format(k+1)) for k in range(1,n+1)) ....:
sage: f(3) x_1
x_2 + x_2x_3 + x_3x_4

Would something like the following help ?

sage: def f(n):
....:     return sum(SR.var('x_{}'.format(k))SR.var('x_{}'.format(k+1)) sum(SR.var('x_{}'.format(k))*SR.var('x_{}'.format(k+1)) for k in range(1,n+1))
....: 
sage: f(3) x_1
x_2 x_1*x_2 + x_2x_3 x_2*x_3 + x_3x_4

x_3*x_4

Would something like the following help ?

sage: def f(n):
....:     return sum(SR.var('x_{}'.format(k))*SR.var('x_{}'.format(k+1)) for k in range(1,n+1))
....:      sage: f(3)
x_1*x_2 + x_2*x_3 + x_3*x_4