How to transform a series of scalar variables to a vector variable? [closed]

Say a function is set:

a := Sum[b[i], {i, 8}]

As can be seen that b[i] is a scalar variable.

Now I want to transform the scalar variables of b[i] to a vector variable t:={b, b, b, b, b, b, b, b}, and it can be used in the function mentioned above.

And more, t should be able to replace by specific vector, say {1,2,3,4,5,6,7,8}, which can be substituted into a, and get the desired result 36.

And that means b->1 b->2 b->3 b->4 b->5 b->6 b->7 b->8, and they can be substituted into a, so a=Sum[i,{i,8}]=36. But it is done in one step, something like this {b, b, b, b, b, b, b, b}->{1,2,3,4,5,6,7,8}. How should I accomplish such a procedure?

closed as unclear what you're asking by Jens, m_goldberg, Itai Seggev, yohbs, MarcoBJul 26 '17 at 5:11

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Do you just want to create a function a[b_]:=Total@b and then evaluate a[{1,2,3,4}]? – Edmund Jul 25 '17 at 1:00
• No, I need transform scalar variables b[i] to a vector variable {b, b, b, b, b, b, b, b}. And it can be replaced by another vector with the same length. NOT just summation.@Edmund – Robin_Lyn Jul 25 '17 at 1:13
• Maybe you're looking for Indexed? Using it we get: a = Sum[Indexed[t, i], {i, 8}] (* Indexed[t, {1}] + Indexed[t, {2}] + Indexed[t, {3}] + Indexed[t, {4}] + Indexed[t, {5}] + Indexed[t, {6}] + Indexed[t, {7}] + Indexed[t, {8}] *), then we can do: a /. t -> Range@8 (* 36 *). – jkuczm Jul 25 '17 at 11:30
• When defining a function, you should specify what variables it depends on. Do you know about Total? How is your function different from it? – Jens Jul 25 '17 at 15:13

I am not sure if I understand you correctly, but this may help. To convert a into a list (or "vector") you can use Apply, i.e.

t = List@@a
(* {b, b, b, b, b, b, b, b} *)

You can substitute values into a using

a /. Thread[t -> {1, 2, 3, 4, 5, 6, 7, 8}]
(* 36 *)

Following up your comment. I am still unsure what you are trying to achieve. As others have suggested, Total is pretty much the thing that does what your a may be supposed to do. You could write

a[vec_] := Total[vec]

and

t = {b, b, b, b, b, b, b, b};

Then

a[t]
(* b + b + b + b + b + b + b + b *)

and

a[{1, 2, 3, 4, 5, 6, 7, 8}]
(* 36 *)
• It does solve the problem mentioned above, but not the way I want. Thanks anyway! – Robin_Lyn Jul 25 '17 at 11:04
• I am afraid I do not understand what you are looking for, then. Why do you specify a := Sum... in this way, as an assignment without any variables? – JEM_Mosig Jul 25 '17 at 21:07
• Thank you for your help. I have found a alternate way to achieve what I am looking for. – Robin_Lyn Jul 26 '17 at 1:44

Make a list:

c = Table[b[i], {i, 8}];

a[c_List] := blah-blah
• Thank you for your help. The List created should be able to be assigned to a specific vector and substituted into function a – Robin_Lyn Jul 25 '17 at 0:46