# Mathematica functions for dealing with sets of integers [closed]

What are the convenient Mathematica functions, say $Func1$ and $Func2$, that if one inputs a collection of sets of numbers:

$$\text{{{1,2},{3,2},{4,1},{1,2},{1,2},{4,1}}}$$

(1) $$\text{Func1[{{1,2},{3,2},{4,1},{1,2},{1,2},{4,1}}]={{1,2},{3,2},{4,1}},}$$ outputs a collection of distinct sets of numbers.

(2) $$\text{Func2[{{1,2},{3,2},{4,1},{1,2},{1,2},{4,1}}],}$$ outputs a collection of distinct sets of numbers {{1,2},{3,2},{4,1}}, but also counts the number of such a sets? Namely $Func2$ outputs knowing 3 sets of {1,2}, 1 set of {3,2}, 2 sets of {4,1}}. but with more information that {3,1,2} stands for the number of collection for each sets.

• Next time please post code as copyable code, not as LaTeX. This is so that people can transfer the expressions into their notebooks without re-typing them. – Szabolcs Mar 2 '17 at 18:06
• Use Counts in v10 or Tally in earlier versions. There's also DeleteDuplicates and Union. – Szabolcs Mar 2 '17 at 18:07

$Func1$ can be Union:

In:= Union[{{1, 2}, {3, 2}, {4, 1}, {1, 2}, {1, 2}, {4, 1}}]

Out= {{1, 2}, {3, 2}, {4, 1}}


$Func2$ can be Tally and then Sort:

In:= Tally[{{1, 2}, {3, 2}, {4, 1}, {1, 2}, {1, 2}, {4, 1}}]

Out= {{{1, 2}, 3}, {{3, 2}, 1}, {{4, 1}, 2}}

In:= Sort[Tally[{{1,2},{3,2},{4,1},{1,2},{1,2},{4,1}}]]

Out= {{{1,2},3},{{3,2},1},{{4,1},2}}