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=2
Nf_large=25
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('aa_'+str(j))
B[j]=var('bb_'+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)
then it would have made everything so much easier. What is the solution?