Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is a possible solution using a dictionary to do all of the substitutions at once.

var('x1,x2,x3')
V=[x1,x2,x3]
s=sum(V)
V_vals=[2,3,4]
s.subs({V[i]:V_vals[i] for i in range(0,3)})

Here is a possible solution using a dictionary to do all of the substitutions at once.

var('x1,x2,x3')
V=[x1,x2,x3]
s=sum(V)
V_vals=[2,3,4]
s.subs({V[i]:V_vals[i] for i in range(0,3)})

For your example, couple this with a map command.

V=[var('x_%d' % i) for i in range(10)]
S=[sum(V),prod(V)]
map(lambda q: q.subs({V[i]:i for i in range(0,len(V))}),S)