I wish to create a function that uses elements from a list and is used later on. For example, I have an array M=[m1,m2,...,mn], B=[b1,b2,...,bn] M=[m1,m2,...,mn]
, B=[b1,b2,...,bn]
and wish to have a function R(r,u,b)=r+b+u R(r,u,b)=r+b+u
(using the elements from the array B), B
), which I then pass to another function Y(r,u,b,m)=Rbm Y(r,u,b,m)=R*b*m
(using the result from the first function and the values from each array). In other words, if M=[m1,m2] and B=[b1,b2], M=[m1,m2]
and B=[b1,b2]
, I want to be able to have a function R(r,u,b)=[r+b1+u,r+b2+u]and R(r,u,b)=[r+b1+u,r+b2+u]
and then have that Y(r,u,b,m)=Rbm=[(r+b1+u)b1m1,(r+b2+u)b2m2]. Y(r,u,b,m)=R*b*m=[(r+b1+u)*b1*m1,(r+b2+u)*b2*m2]
. Basically, I wish to do what is mentioned in this post: http://ask.sagemath.org/question/8545/apply-a-function-to-a-list/, but with more than one array.
I tried the following
sage: m1,m2,b1,b2,u=var('m1','m2','b1','b2','u')
sage: M=[m1,m2], B=[b1,b2]
sage: R(r,b,u)=[r+b+u for b in B]
sage:R(r,b,u)
(r+b1+u,r+b2+u)
This is all what I want. I then want to take R(r,b,u) in another function: Y(r,b,u,m), so that it gets the result I have above. I can't seem to get a way to run through all the possibilities (I could use a loop, but that ends up getting a bit messy as I go deeper in)