# Function of symbolic array elements

I want to create a function like this:

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

However, the thing that the function is supposed to return is calculated in an earlier part of the program. Since Sagemath has a problem with symbolic indices, I have previously defined A and B as follows:

```
Nf=5
B =[0 for j in range(Nf+1)]
A =[0 for j in range(Nf+1)]
for j in range(Nf+1):
A[j]=var('a_'+str(j))
B[j]=var('b_'+str(j))
```

The thing that the function should return is calculated in another part of the program. Suppose that it is something like this (evaluated from a separate subroutine):

```
temp=[a_1*b_1, a_0, b_2]
```

So my question is: how do I turn this `temp`

into a function similar to `f`

, and the second question: the matrix element references are replaced by variable names. Even if I define a function for `temp`

as it is, I will have to define a huge number of input variables `f(a_1, b_1, a_0, b_2, ...)`

for the function whereas if I could just replace the variables `a_1`

with `A[1]`

, etc., this would have enabled me to use `f(A,B)`

making the function definition so much more compact. How can I achieve this?