Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

First of all, you can condense your code a little bit by writing

A=[SR.var('a_'+str(j)) for j in range(Nf+1)]

etc. With this version you do not have the side-effect of a_0 being bound, so your only way of spelling the variable name is A[0].

If you just write

def temp(A,B):
    return [A[1]*B[1],A[0],B[2]]

you have what you describe.

Perhaps you mean that you have a symbolic expression S in the variable occurring in A,B and you want to substitute values for them; say lists a,b and you want to make the substitutions A[0]=a[0], A[1]=a[1] etc. It should be possible to do the following

def evaluate_at(S,a,b):
    return S(dict(zip(A,a)+zip(B,b)))

In that case, with

L=[A[1]*B[1],A[0],B[2]]

your function temp should probably be

def temp(a,b):
    return [evaluate_at(S,a,b) for S in L]