Union
✖
Union
Details and Options

- If the listi are considered as sets, Union gives their union.
- Union[list1,list2,…] can be input in StandardForm and InputForm as list1⋃list2⋃…. The character ⋃ can be entered as
un
or \[Union].
- The listi must have the same head, but it need not be List.
- Union[list1,…,SameTest->test] applies test to each pair of elements in the listi to determine whether they should be considered the same.
Examples
open allclose allBasic Examples (3)Summary of the most common use cases
Scope (1)Survey of the scope of standard use cases
Generalizations & Extensions (1)Generalized and extended use cases
Options (4)Common values & functionality for each option
SameTest (4)
Use equivalence classes based on absolute value:

https://wolfram.com/xid/0giw0i-gvm

Use equivalence classes based on Floor:

https://wolfram.com/xid/0giw0i-bscbho

Use Total of list elements:

https://wolfram.com/xid/0giw0i-hmxah

Use equality of last and first elements:

https://wolfram.com/xid/0giw0i-dwkrbi

Applications (4)Sample problems that can be solved with this function
Find divisors that occur in any of 10, 12, and 20:

https://wolfram.com/xid/0giw0i-lud

Find all the triples of bits that occur in the binary decomposition of 10!:

https://wolfram.com/xid/0giw0i-qwm

Find the distinct elements in the iteration:

https://wolfram.com/xid/0giw0i-ewu

Find what options are used by a list of functions:

https://wolfram.com/xid/0giw0i-cnsc3w

Properties & Relations (2)Properties of the function, and connections to other functions
Split on the sorted set gives lists of the same elements:

https://wolfram.com/xid/0giw0i-p214s


https://wolfram.com/xid/0giw0i-ckt3x8

The union is equivalent to the first elements of these lists:

https://wolfram.com/xid/0giw0i-bu6xf7

Tally gets the count of identical elements and returns them in the original order:

https://wolfram.com/xid/0giw0i-1pxsf


https://wolfram.com/xid/0giw0i-cpcbue

The union is the sorted list of the elements returned by Tally:

https://wolfram.com/xid/0giw0i-b0uwm7

Possible Issues (1)Common pitfalls and unexpected behavior
For large sets Union may be slow with SameTest since it requires all pairwise comparisons:

https://wolfram.com/xid/0giw0i-b1g60q

https://wolfram.com/xid/0giw0i-b4wxt1

When equivalence class representatives can be found, it may be faster to use Union on these:

https://wolfram.com/xid/0giw0i-ir945y

The results are the same except for the choice of representative:

https://wolfram.com/xid/0giw0i-j7gq7r

Wolfram Research (1988), Union, Wolfram Language function, https://reference.wolfram.com/language/ref/Union.html (updated 1996).
Text
Wolfram Research (1988), Union, Wolfram Language function, https://reference.wolfram.com/language/ref/Union.html (updated 1996).
Wolfram Research (1988), Union, Wolfram Language function, https://reference.wolfram.com/language/ref/Union.html (updated 1996).
CMS
Wolfram Language. 1988. "Union." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 1996. https://reference.wolfram.com/language/ref/Union.html.
Wolfram Language. 1988. "Union." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 1996. https://reference.wolfram.com/language/ref/Union.html.
APA
Wolfram Language. (1988). Union. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Union.html
Wolfram Language. (1988). Union. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Union.html
BibTeX
@misc{reference.wolfram_2025_union, author="Wolfram Research", title="{Union}", year="1996", howpublished="\url{https://reference.wolfram.com/language/ref/Union.html}", note=[Accessed: 16-April-2025
]}
BibLaTeX
@online{reference.wolfram_2025_union, organization={Wolfram Research}, title={Union}, year={1996}, url={https://reference.wolfram.com/language/ref/Union.html}, note=[Accessed: 16-April-2025
]}