# Spelling of sum(x\*y for (x,y) in zip(xs, ys)), e.g. linear combinations

**URL:** https://discourse.julialang.org/t/spelling-of-sum-x-y-for-x-y-in-zip-xs-ys-e-g-linear-combinations/25379
**Category:** General Usage
**Created:** [June 17, 2019, 8:49pm UTC](https://discourse.julialang.org/t/spelling-of-sum-x-y-for-x-y-in-zip-xs-ys-e-g-linear-combinations/25379 "2019-06-17T20:49:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)
#### Post date: [June 17, 2019, 8:49pm UTC](https://discourse.julialang.org/t/spelling-of-sum-x-y-for-x-y-in-zip-xs-ys-e-g-linear-combinations/25379/1 "2019-06-17T20:49:27Z")

</div>

Is there a good canonical spelling for taking a linear combination, e.g.

```julia
combo(xs, ys) = sum(x*y for (x,y) in zip(xs, ys))
basis = [[1,0], [1,1]]
weights = [0.5, 0.5]

julia> combo(basis, weights)
2-element Array{Float64,1}:
 1.0
 0.5

```

It’s not a `LinearAlgebra.dot`-product, since that is supposed to return a scalar. It’s isomorphic to a matrix-vector product, yes, but what should the spelling of the operation on `basis` and `weights` be to avoid reshaping the `basis` elements into vectors?

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [June 17, 2019, 9:07pm UTC](https://discourse.julialang.org/t/spelling-of-sum-x-y-for-x-y-in-zip-xs-ys-e-g-linear-combinations/25379/2 "2019-06-17T21:07:27Z")

</div>

I don’t know what a canonical spelling is, but this is what comes into my mind seeing the code:

```julia
julia> sum(basis.*weights)
2-element Array{Float64,1}:
 1.0
 0.5

```

is doing the same operation.  
An element wise multiplication is called a

- Hadamard product or
- Schur product or
- entrywise product

The sum operation doesn’t have a name except for the sum of the elements.

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [June 17, 2019, 9:09pm UTC](https://discourse.julialang.org/t/spelling-of-sum-x-y-for-x-y-in-zip-xs-ys-e-g-linear-combinations/25379/3 "2019-06-17T21:09:07Z")

</div>

Ah, I see, its not the same operation…  
Now it is, edited above from `sum.()` to `sum()`

---

<div class="post-metadata">

### Author: ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)
#### Post date: [June 17, 2019, 9:10pm UTC](https://discourse.julialang.org/t/spelling-of-sum-x-y-for-x-y-in-zip-xs-ys-e-g-linear-combinations/25379/4 "2019-06-17T21:10:25Z")

</div>

One solution (in the context that motivated my question) from @tkoolen:

[https://github.com/JuliaRobotics/EnhancedGJK.jl/pull/16/files#diff-f82f70eb0ea9380dfa58b95933dd050eL99](https://github.com/JuliaRobotics/EnhancedGJK.jl/pull/16/files#diff-f82f70eb0ea9380dfa58b95933dd050eL99)

It works on e.g. basis elements which are matrices.

```julia
julia> transpose([10, 20]) * [[1 0; 0 1], [0 1; 0 0]]
2×2 Array{Int64,2}:
 10 20
  0 10

```
