Skip to Content

What happens when you define a set as a filter?

Mathematically speaking, a set is a collection of distinct objects that can be defined in a few different ways. One common way to define a set is by listing all of its elements inside curly braces. For example, the set {1, 2, 3} contains the elements 1, 2, and 3. Another way to define a set is by stating a property or condition that its elements must satisfy – this is known as defining a set by comprehension or as a filter.

Defining Sets by Comprehension

To define a set by comprehension, you provide a description or filtering condition that picks out precisely those objects that you want to be members of the set. For instance, the set of even numbers could be defined as:

{x | x is an integer and x is divisible by 2}

This reads: the set of all x such that x is an integer and x is divisible by 2. The vertical bar “|” can be read as “such that” or “for which.” This definition picks out exactly the elements we want in the set – all integers that are even. Some other examples of defining sets by comprehension:

  • {x | x is a prime number less than 10} = {2, 3, 5, 7}
  • {y | y is a capital city in Europe} = {London, Paris, Rome, …}
  • {z | z is a perfect square less than 100} = {1, 4, 9, 16, 25, 36, 49, 64, 81}

So in summary, defining a set by comprehension provides a concise way to specify the members of a set by stating a condition they must satisfy.

Filtering Existing Sets

Closely related to defining sets by comprehension is the idea of filtering or restricting existing sets. If you start with a set S and want to form a new set containing only those elements from S that satisfy some property, you can achieve this by treating the property as a filter on S.

For example:

  • Let S = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
  • Filter S to contain only the even elements: {x | x is in S and x is even}
  • This filtered set is {2, 4, 6, 8, 10}

Some other examples:

  • Let T = {red, orange, yellow, green, blue, indigo, violet}
  • Filter T to contain just the primary colors: {x | x is in T and x is a primary color}
  • This gives {red, yellow, blue}
  • Let U = {Germany, France, UK, Spain, Italy, Poland, Greece}
  • Filter U to contain only countries using the euro: {y | y is in U and y uses the euro currency}
  • This gives {Germany, France, Spain, Italy}

So in summary, we can filter or restrict any set S by taking just those elements that satisfy a particular property. The filtered set can be defined through set comprehension, providing a concise way to describe the desired set.

Set Operations on Filtered Sets

An important benefit of treating filters as set definitions is that the resulting filtered sets can then be used in all the standard set operations like unions, intersections, differences, etc. For example:

  • Let A = {x | x is a prime number less than 20}
  • Let B = {x | x is an odd number less than 20}
  • Let C = {x | x is a multiple of 3 less than 20}

Then we can find:

  • A union B: {x | x is a prime number or an odd number less than 20}
  • A intersect C: {x | x is a prime number and a multiple of 3 less than 20} = {3}
  • B – C: {x | x is odd and not a multiple of 3 less than 20} = {1, 5, 7, 9, 15, 17, 19}

And so on. Defining sets as filters gives us a lot of flexibility in constructing new sets through set operations.

When Filters Fail to Define Sets

There are some cases where trying to define a set by a filtering condition does not work as intended:

  • The filter condition is unsatisfiable – there are no objects that satisfy it. For example: {x | x is an integer and x > 5 and x
  • The filter condition is ambiguous – it does not uniquely identify the set’s members. For example: {y | y is a prime number}. This does not define a specific set since we haven’t bounded y.
  • The filter relies on undefined terms. For example: {z | z is a florgle}. This tries to define a set using an undefined property.

So in these cases, the filtering conditions fail to properly define sets. The sets end up being empty, ambiguous, or reliant on undefined concepts.

Examples of Defining Sets as Filters

Here are some examples that demonstrate defining sets through filters and set comprehension notation:

Prime Numbers Less than 20

{2, 3, 5, 7, 11, 13, 17, 19}

Can be defined as:

{x | x is a prime number AND x

Multiples of 5 up to 50

{5, 10, 15, 20, 25, 30, 35, 40, 45, 50}

Can be defined as:

{y | y is a multiple of 5 AND y

Vowels in the English Alphabet

{a, e, i, o, u}

Can be defined as:

{z | z is a vowel in the English alphabet}

Even Perfect Squares

{4, 36, 64, 100}

Can be defined as:

{x | x is an even perfect square}

Countries Bordering France

{Germany, Italy, Spain, Switzerland, Belgium, Luxembourg}

Can be defined as:

{y | y is a country that borders France}

So in these examples, we see how set comprehension provides a concise way to define various sets by stating a key property or filter that picks out the desired set elements.

Set Comprehension in Programming Languages

The notion of defining sets through comprehension syntax shows up in many programming languages as well. In languages like Python, JavaScript, Haskell, and others, set comprehension provides a convenient way to initialize sets by filtering elements from other sets or ranges.

For example, in Python:

primes = {x for x in range(2, 20) if is_prime(x)}

multiples_of_3 = {x for x in range(50) if x % 3 == 0}

And in JavaScript:

const vowels = new Set([‘a’, ‘e’, ‘i’, ‘o’, ‘u’].filter(x => isVowel(x)));

const squares = new Set([…Array(10)].map(x => x**2));

This demonstrates how set comprehension syntax can be used to filter and transform sets in a concise, declarative way in code.


Defining sets through comprehension or filters provides a powerful, flexible way to specify set membership. It allows concise definitions of sets based on meeting certain criteria. The resulting filtered sets can be used effectively in set operations like unions, intersections, differences and more. Set comprehensions also translate nicely to syntax in many programming languages. However, care must be taken to avoid filters that are ambiguous, unsatisfiable or rely on undefined terms.

Overall, the ability to define sets as filters is an important mathematical and computational tool for concisely specifying sets and transforming existing sets in useful ways.