# Checking if a list of vectors are all identical

**URL:** <https://discourse.julialang.org/t/checking-if-a-list-of-vectors-are-all-identical/110215>\
**Category:** Performance\
**Tags:** arrays\
**Created:** [February 14, 2024, 5:33pm UTC](https://discourse.julialang.org/t/checking-if-a-list-of-vectors-are-all-identical/110215 "2024-02-14T17:33:13Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 14, 2024, 8:58pm UTC](https://discourse.julialang.org/t/checking-if-a-list-of-vectors-are-all-identical/110215/11 "2024-02-14T20:58:17Z")

</div>

> [@rafael.guerra](#):
>
> Thanks Steve. Would something like this be better? `all(isapprox(tᵢ - sᵢ, t[1] - s[1], rtol=1e-3) for (tᵢ, sᵢ) in zip(t,s))`

No, because you are passing only a relative tolerance `rtol`. That means it will still probably fail if `t[1] - s[1]` happens to be nearly zero.

> [@rafael.guerra](#):
>
> (\*edited using: `atol`)

Yes, using `atol` is safer, but requires you to pick a reasonable `atol`, and that depends on the problem because **`atol` is dimensionful**.

For example, suppose your vectors represent positions of stars in the galaxy, with coordinates measured in meters. Then `atol = 1e-3` (1mm) is probably a ridiculously small tolerance. On the other hand, if you are doing atomic physics with distances in meters, where the typical scale is [angstroms](https://en.wikipedia.org/wiki/Angstrom), then `atol = 1e-3` is a ridiculously large tolerance.

> [@Dan](#):
>
> How does: `all(s .+ Ref(mean(t-s)) .≈ t)` look?

This is still likely to fail if any element of `t` happens to be zero or nearly zero.

Note, by the way, that `≈` works perfectly well on arrays, or arrays of arrays (anything with a `norm`), so using `≈` with `all` is generally unnecessary (and more susceptible to scaling problems). You can just do `s .+ Ref(mean(t-s)) ≈ t` (no dot on the `≈`), which is more robust although it will still be problematic if `norm(t) == 0` (maybe that is less likely … but ultimately you should still be thinking about an appropriate problem-dependent `atol`).

---

_[View the full topic](https://discourse.julialang.org/t/checking-if-a-list-of-vectors-are-all-identical/110215)._
