Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

click to hide/show revision 2
No.2 Revision

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
click to hide/show revision 3
No.3 Revision

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