# Dot product of two tuples

**URL:** <https://discourse.julialang.org/t/dot-product-of-two-tuples/6683>\
**Category:** General Usage\
**Created:** [October 25, 2017, 6:37pm UTC](https://discourse.julialang.org/t/dot-product-of-two-tuples/6683 "2017-10-25T18:37:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gasagna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gasagna/32/1275_2.png) [@gasagna](https://discourse.julialang.org/u/gasagna)\
**Post date:** [October 25, 2017, 6:37pm UTC](https://discourse.julialang.org/t/dot-product-of-two-tuples/6683/1 "2017-10-25T18:37:39Z")

</div>

Any particular reason for the dot product of two tuples to be undefined (v0.6)? Similarly for `norm`, or `cross`.

```julia
julia> dot((1, 3, 2), (1, 3, 2))
ERROR: MethodError: no method matching dot(::Tuple{Int64,Int64}, ::Tuple{Int64,Int64})

```

This is potential useful in many applications.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 25, 2017, 7:10pm UTC](https://discourse.julialang.org/t/dot-product-of-two-tuples/6683/2 "2017-10-25T19:10:34Z")

</div>

Use StaticArrays. “Naked” tuples are not really meant for linear algebra stuff, but they do provide a good datastructure to build static arrays on top of, that support linear algebra.

---

<div class="post-metadata">

**Author:** ![gasagna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gasagna/32/1275_2.png) [@gasagna](https://discourse.julialang.org/u/gasagna)\
**Post date:** [October 25, 2017, 7:14pm UTC](https://discourse.julialang.org/t/dot-product-of-two-tuples/6683/3 "2017-10-25T19:14:44Z")

</div>

I do not want to pull this dependency for a single dot product in my code.

I am currently using

```julia
a = (1, 2)
b = (3, 4)
sum(a .* b)

```

which does not incur in any allocation.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 25, 2017, 7:16pm UTC](https://discourse.julialang.org/t/dot-product-of-two-tuples/6683/4 "2017-10-25T19:16:53Z")

</div>

You mentioned `cross` and `norm` so it seemed that you were interested in more things than a single `dot`. Your implementation is efficient for this use case though.

---

<div class="post-metadata">

**Author:** ![gasagna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gasagna/32/1275_2.png) [@gasagna](https://discourse.julialang.org/u/gasagna)\
**Post date:** [October 25, 2017, 7:17pm UTC](https://discourse.julialang.org/t/dot-product-of-two-tuples/6683/5 "2017-10-25T19:17:32Z")

</div>

Yeah, apologies. That was a general comment.

---

<div class="post-metadata">

**Author:** ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)\
**Post date:** [October 25, 2017, 7:28pm UTC](https://discourse.julialang.org/t/dot-product-of-two-tuples/6683/6 "2017-10-25T19:28:37Z")

</div>

FWIW, as a “general” solution you “should” use StaticArrays. It’s a pretty solid package that is backed by the community and excellent developers. I know what you mean by adding dependencies, but really, you’re already depending on huge dependencies by even running Julia, and in this case StaticArrays does exactly what you want. I get what you mean in general, but this is not a random package on some random account. If the philosophy wasn’t to get stuff out of base, I’m pretty sure you’d find this in base.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [October 25, 2017, 7:30pm UTC](https://discourse.julialang.org/t/dot-product-of-two-tuples/6683/7 "2017-10-25T19:30:08Z")

</div>

`StaticArrays` is also pretty self-contained: it only depends on `Compat` – which almost every package depends on. So this is not like depending on some huge package with a bajillion transitive dependencies.
