# Set difference calculator

World's simplest set tool
With this online application, you can quickly apply the relative set complement operation on multiple sets (relative complement is also known as set difference). Our implementation of the set difference operation works on both regular sets and multi-sets (sets that allow elements to repeat). The elements of the output set can be sorted alphabetically or alphanumerically, and you can also change the set notation format of the input and output sets. Created by team Browserling.

announcement
a new site!

We just launched a new site – Online List Tools – utilities for working with lists. Check it out!

A link to this tool, including input, options and all chained tools.

Can't convert.

## What is a set difference calculator?

learn more about this tool
This browser-based program performs the set difference operation of two or more sets. Set difference of sets A and B (sometimes called the relative complement of B in A) is a set C that includes all the elements of the first set A that are not included in the second set B. Usually, the difference of sets A and B is denoted as A\B, but sometimes you can find the notation A–B and A~B. Using the set-builder notation, the set difference can be defined as follows: A\B = {x: x ∈ A and x ∉ B}. Unlike the union and intersection operations, which are commutative, the relative complement isn't commutative and the order of sets is important. For example, if A = {1, 2, 3} and B = {2, 3, 4, 5}, then A\B = {1} but B\A = {4, 5}. The complement of three or more sets is calculated in a similar way. For example, {a, b, c, d, e, f} \ {a, b} \ {e, f} = {c, d}. If A ⊆ B (A is a subset of B), then A\B = ∅, and if A and B are disjoint sets (they don't have common elements) then A\B = A and B\A = B. The sets that you want to calculate the difference of must be entered in the input field and there has to be a special marker line that contains three dashes "---" between them. Optionally, you can change this marker line in the options. All input sets should be fully enumerated and written in the Roster set notation format. By default, it's a comma-delimited sequence of elements enclosed in curly braces, such as {2, 3, 4, b, c, d}. Optionally, you can change the Roster set notation format by adjusting the set bracket symbols and the set element delimiter symbol. For example, you can make your input sets look like this: <2; 3> or like this: [2 3]. The result of the difference operation is also a set that you can customize. Moreover, you can sort the elements of the output set alphabetically or numerically. Often, the sets you are working with are multisets. A multiset, compared to a simple set, preserves the multiplicity of its elements. That is, if a certain input element is repeated several times, then the multiset keeps all its copies. With the "Keep Element Copies" option active, the difference of two sets {2, 2, 3, 4} and {3, 4} is be {2, 2} and with this option disabled, the difference is {2}. Setabulous!

## Set difference calculator examples

Click to useComplement Sets of Digit

This example performs the relative complement operation of the set of even digits (E) in the set of all digits (D). In mathematical notation, it finds the set D\E (or D–E). The resulting set contains all the digits of the first set (D) that don't appear in the second set (E). This set, let's call it O, contains only the odd digits (because all even digits were removed). The example separates the input sets by three dashes "---" and adjusts the formatting options to match the input set format by setting the left bracket to "{", the right bracket to "}", and the element separator to "," (comma). It uses the same set format for the output set (difference set).

{1, 2, 3, 4, 5, 6, 7, 8, 9}
---
{2, 4, 6, 8}

{1, 3, 5, 7, 9}

**Required options**

Separate the input sets with
this marker. (Default marker
is three dashes "---".)

Separate the input set
elements with this
character.

Left bracket.
(Open set.)

Right bracket.
(Close set.)

Consider the input sets to be
multisets and preserve the
multiplicity of their elements.

Separate the output set
elements with this
character.

Left bracket.
(Open set.)

Right bracket.
(Close set.)

Print elements in the order
they are in the first set.

Difference of Alphabets

In this example, we calculate the difference between two alphabets. The first alphabet is the Esperanto alphabet and the second alphabet is the English alphabet. As alphabets are just sets of letters, we can run our set difference algorithm on them. All letters in both alphabets are merged together, which means there is no set element separator, so we clear the element separator field in the options. Also, both sets do not have parentheses on the sides, so we also clear the left and right parenthesis fields in the options. The only symbol that we need to specify is the input set delimiter symbol, which in this case is the tilde symbol. In the output, we get a set of those letters that are in Esperanto but not in English. We also invent a new format for the output set that separates letters with a dot, encloses them in square parentheses, and sorts them alphabetically.

abcĉdefgĝhĥijĵklmnoprsŝtuŭvz
~
abcdefghijklmnopqrstuvwxyz

[ĉ.ĝ.ĥ.ĵ.ŝ.ŭ]

**Required options**

Separate the input sets with
this marker. (Default marker
is three dashes "---".)

Separate the input set
elements with this
character.

Left bracket.
(Open set.)

Right bracket.
(Close set.)

Consider the input sets to be
multisets and preserve the
multiplicity of their elements.

Separate the output set
elements with this
character.

Left bracket.
(Open set.)

Right bracket.
(Close set.)

Print elements of the set
difference alphabetically.

Subtract Multisets

In this example, we're working with four multisets (sets that allow multiple instances of the same element) and have activated the "Keep Element Copies" option. We subtract the second, third, and fourth multiset from the first one and find their difference. All multisets are separated by a backslash, and they use an angle bracket format with space-separated elements. The first two multisets are disjoint, so their difference is equal to the first multiset. The third multiset subtracts both "t" letters and the fourth multiset subtracts the number "6". As a result, we get a multiset with five elements, which we sort in numeric order.

<s t s t 20 20 6 5> \ <cat dog cat> \ <a b t t> \ <6 -6 6 -6>

(5; 20; 20; s; s)

**Required options**

Separate the input sets with
this marker. (Default marker
is three dashes "---".)

Separate the input set
elements with this
character.

Left bracket.
(Open set.)

Right bracket.
(Close set.)

Consider the input sets to be
multisets and preserve the
multiplicity of their elements.

Separate the output set
elements with this
character.

Left bracket.
(Open set.)

Right bracket.
(Close set.)

Print elements of the set
difference numerically.

Pro tips
Master online set tools

You can pass input to this tool via

__?input__query argument and it will automatically compute output. Here's how to type it in your browser's address bar. Click to try!
https://onlinesettools.com/find-set-difference

__?input__=%7B1%2C%202%2C%203%2C%204%2C%205%2C%206%2C%207%2C%208%2C%209%7D%0A---%0A%7B2%2C%204%2C%206%2C%208%7D&input-set-separator=---&input-element-separator=%2C%20&input-open-set=%7B&input-close-set=%7D&allow-repetitions=false&output-element-separator=%2C%20&output-open-set=%7B&output-close-set=%7D&do-not-sort=true
All set tools

Quickly find the powerset P(S) of the given set S.

Quickly reverse the order of elements in an ordered set.

Quickly find the number of elements in a set.

Quickly apply the set union operation on two or more sets.

Quickly apply the set intersection operation on two or more sets.

Quickly apply the set difference operation on two or more sets.

Coming soon
These set tools are on the way

Draw a Venn Diagram

Illustrate two or more sets as a Venn diagram.

Find Set Symmetric Difference

Apply the set difference operation on sets A and B.

Find Set Cartesian Product

Apply the set cartesian product operation on sets A and B.

Find All Subsets of a Set

Quickly find all sets that are subsets of set A.

Find All Set Permutations

Generate all permutations of set elements.

Enumerate a Set

Add numbering to all set elements.

Filter a Set

Print set elements that match a filter.

Find Set Elements

Find elements in a set that match certain criteria.

Apply a Function on a Set

Run a function on all elements in a set.

Convert a Multiset to a Set

Convert a set with repeated elements to a standard set.

Convert a Set to a Multiset

Convert a standard set to a multiset with repeated elements.

Convert a Set to a List

Create a list from the given set.

Convert a List to a Set

Create a set from the given list.

Convert a Set to an Array

Create an array from the given set.

Convert an Array to a Set

Create a set from the given array.

Duplicate Set Elements

Repeat set elements multiple times.

Print Duplicate Set Elements

Find all duplicate elements in a set.

Remove Duplicate Set Elements

Delete all duplicate elements from a set (leave unique).

Print Unique Set Elements

Find all unique elements in a set.

Remove Unique Set Elements

Delete all unique elements from a set (leave duplicates).

Remove Empty Set Elements

Delete empty elements (zero-length elements) from a set.

Find Set Depth

Calculate how many levels of subsets a set has.

Flatten a Set

Decrease subset nesting.

Truncate a Set

Remove elements from a set and make it smaller.

Truncate Set Elements

Shorten all set elements to the given length.

Expand a Set

Add elements to a set and make it bigger.

Split a Set

Split a set into a certain number of subsets.

Join Sets

Merge multiple sets together to form one large set.

Slice a Set

Extract an index-based subset from a set.

Partition a Set

Find disjoint subsets of the given set whose union is the same set.

Randomize a Set

Randomly change the order of elements in a set.

Select a Random Set Element

Pick a random element from the given set.

Select a Random Subset

Pick a random subset of the given set.

Generate an Empty Set

Create a set with no elements.

Generate a Digit Set

Create a set that contains digits.

Generate a Number Set

Create a set that contains numbers.

Generate an Integer Set

Create a set that contains integers.

Generate a Decimal Set

Create a set that contains decimal fractions.

Generate a Letter Set

Create a set that contains letters.

Generate a Character Set

Create a set that contains characters.

Generate a Word Set

Create a set that contains words.

Generate a String Set

Create a set that contains strings.

Generate a Text Set

Create a set that contains text.

Generate a Sentence Set

Create a set that contains sentences.

Generate a Random Set

Create a set that contains random elements.

Generate a Custom Set

Create a custom set with custom elements and custom size.

Generate an Infinite Set

Create a set with infinitely many elements.

Generate a Finite Set

Create a set with a finite number of elements.

Change Set Notation

Change the open-set, close-set, and element separator symbols.

Change Set Size

Add or remove set elements to make it a certain size/length.

Destroy a Set

Launch a Zalgo attack on a set and destroy it.

Compare Sets

Find all differences between two or more sets.

Symmetrize a Set

Convert a regular set to a symmetric multi-set.

Color a Set

Add colors to set elements.

Visualize a Set

Create an abstract visualization of a set.

Convert a Set to an Image

Create a downloadable picture from a set.

Print Set Analytics

Analyze a set and print its statistics.

Subscribe!
Never miss an update

Cool!

Notifications
We'll let you know when we add this tool

Cool!