# How to multiply tuples and how to change a format of summation?

If you have a set `A = [ (1,4,7), (2,5,3), (5,4,9), (2,8,7), (8,6,7), (2,3,5) ] `.Is it possible to derive:

``````#1 another set A'  such that A' = 1.2*A
each element of A' is the scaled version of A
``````
``````#2  define a variable like x and a summation like the following

x[1,4,7] + x[2,5,3]+ x[5,4,9]+x[2,8,7]+x[8,6,7]+x[2,3,5] = 5
# not like the following
x[(1,4,7)] + x[(2,5,3)]+ x[(5,4,9)]+x[(2,8,7)]+x[(8,6,7)]+x[(2,3,5)] = 5
``````

The only thing operator I know for this case is `...` but this is not useful either.

``````#with ...
formsum(A,x :: Array{T,2}) where T<: Number =sum([x*[t...] for t in A])

#without ...
formsumf(A,x :: Array{T,2}) where T<: Number = sum(x*Base.splat(hcat)(Base.BroadcastFunction(Base.splat(Base.vect))(A)))

``````

It looks like `CartesianIndex` might be useful to you.

`sum(z->x[CartesianIndex(z)], A)`

To save a step (or rather to do it earlier), you could make `A` an array of `CartesianIndex{3}` rather than 3-tuples.

As for question #1, it’s not pretty but if you want to multiply every element of `A` every tuple by a constant you can use nested broadcasting with carefully placed dots (although it isn’t pretty):
`(.*).(A, 1.2)`
Note that this won’t work if you make `A` an array of `CartesianIndex` like I’d suggested above, at least not for float factors like your `1.2` since `CartesianIndex` only supports integers.

Also, don’t be afraid to write `for` loops in Julia if you can’t figure out how to write something using fancy functions. They aren’t performance traps like in some other languages.