# How to confirm two sets contain the same vectors in any order?

Say if I have two sets of vectors, for example:

$$v_{1}=((0,0,0),(0,1,0),(0,0,1),(1,1,1))$$

$$v_{2}=((0,1,0),(1,1,1),(0,0,0),(0,0,1))$$

I want to find a way of verifying that both $$v_{1}$$ and $$v_{2}$$ contain the same vectors, regardless of order.

I'm not sure how to do it, below are attempts that did not work:

v1={{0,0,0},{0,1,0},{0,0,1},{1,1,1}}
v2={{0,1,0},{1,1,1},{0,0,0},{0,0,1}}
TrueQ[OrderlessPatternSequence[v1]==OrderlessPatternSequence[v2]]
Equal[Permutations[v1],Permutations[v2]]
Intersection[v1,v2]
• Should the multiplicity of the vectors match as well? If it doesn't matter then Union[v1] === Union[v2] should be okay.
– Syed
Aug 31, 2023 at 10:32
• As in can there be duplicates of the same vector or am I misinterpreting "multiplicity of the vectors"? Aug 31, 2023 at 10:57
• From the examples at OrderlessPatternSequence you can use MatchQ[v1, {OrderlessPatternSequence[Sequence@@v2]}] Aug 31, 2023 at 10:57
• Union will sort as well as delete the duplicates. Yes, you are interpreting it correctly. I guess the ambiguity exists as you used the word set instead of list.
– Syed
Aug 31, 2023 at 10:59
• My understanding is that Mathematica does not have a Set construct but only a List construct. If, however, you use functions intended for sets, such as Union, Intersection, Complement, then these functions will sort (since order does not matter in a set) and will delete duplicates (since a set contains unique elements only).
– Syed
Aug 31, 2023 at 11:25

One way:

Sort@v1==Sort@v2
(* True *)

You might want ContainsExactly:

ContainsExactly[v1, v2]

although it will ignore multiplicities.

### 1.

A slight variation of creidhne's suggestion in comments:

sameOrderlessPatternQ = MatchQ[{OrderlessPatternSequence @@ #}]@#2 &;

sameOrderlessPatternQ[v1, v2]
True

### 2.

InternalComparePatterns @@ (OrderlessPatternSequence @@@ {v1, v2})
"Identical"

### 3.

GeneralUtilitiesEquivalentPatternQ @@ (OrderlessPatternSequence @@@ {v1, v2})
True

### 4.

GeneralUtilities`AllSameBy[Sort] @ {v1, v2}
True

Using SymmetricDifference which came with V 13.1

v1 = {{0, 0, 0}, {0, 1, 0}, {0, 0, 1}, {1, 1, 1}};
v2 = {{0, 1, 0}, {1, 1, 1}, {0, 0, 0}, {0, 0, 1}};

SymmetricDifference[v1, v2] === {}

(* True *)

From the documentation:

"SymmetricDifference[list1, list2] gives the sorted list of elements that are in list1 or list2 but not in both."

If we change the third element of v2 to

v2 = {{0, 1, 0}, {1, 1, 1}, {0, 2, 0}, {0, 0, 1}};

we get

SymmetricDifference[v1, v2]

{{0, 0, 0}, {0, 2, 0}}