This page may be out of date. Submit any pending changes before refreshing this page.
Hide this message.
Quora uses cookies to improve your experience. Read more

What are the applications of set theory in computer science?

9 Answers
Hans Hyttel
Hans Hyttel, Associate Professor

Naïve set theory (as opposed to axiomatic set theory) is widely used in computer science and is a central part of the underlying mathematical language. Here are some examples that many undergraduate students in computer science will come across.

Data structures should be thought of as implementations of sets with particular focus on efficient implementations of set operations.

In database theory, the notion of a relational database is that of seeing a database as a relation over sets.

In formal language theory, a language is a set of strings and the study of operations on languages is central. Some of these are the usual set operations of intersection, union and complement, while others are particular to sets of strings (language concatenation and Kleene star are well-known operations on languages).

In programming language semantics, semantic domains are sets with structure (typically complete partial orders). And algorithms for solving set constraints are useful in e.g. the study of type inference for programming languages.

Axiomatic set theory becomes useful in certain parts of computability theory and in the study of logic in computer science, but these are not the kinds of topics that undergraduate students are likely to encounter.

Your feedback is private.
Is this answer still relevant and up to date?
Garrett Thomas
Garrett Thomas, CS student at Berkeley
I'd say that depends on what you mean by set theory.
I'm not aware of any applications of set theory in the sense of the Axiom of Choice, different sizes of infinities, etc. But (finite) sets are useful abstract data types whenever you want to keep track of a collection of things and don't care about their order or multiplicity. For this purpose, sets can be implemented as hashtables under the hood so that individual elements can be added or checked for membership in constant time.
As an example, when doing graph traversal, you may want to maintain a set of visited nodes so that you can avoid visiting the same node twice.

EDIT: For more specific applications, take a look at the Examples section of the Wiki page for bloom filters.
Your feedback is private.
Is this answer still relevant and up to date?
Jonas Oberhauser
Jonas Oberhauser, Happy Husband and Computer Scientist

For example, defining a processor and proving its correctness. You begin with small sets like [math]\mathbb{B} = \{ 0, 1 \}[/math] and [math]\mathbb{B}^n[/math], you define maps for binary interpretation

[math]\langle \cdot \rangle : \mathbb{B}^n \rightarrow [ 0 : 2^n - 1][/math]

and two’s complement interpretation

[math][ \cdot ] : \mathbb{B}^n \rightarrow [ -2^{n-1} : 2^{n-1} - 1][/math]

Then you define labeled directed acyclic graphs; a hardware circuit is just one such graph where the labels are the gates, such as [math]\land, \lor, \neg, \oplus[/math].

Then you can define graphs that compute addition of two binary numbers, such as the parallel prefix circuit, and you can prove for input values [math]a,b \in \mathbb{B}^n[/math] and carry-in [math]c_0 \in \mathbb{B}[/math] and the output [math]s \in \mathbb{B}^n[/math] and carry-out [math]c_n \in \mathbb{B}[/math] that the darn thing really adds the numbers, i.e., the two’s complement interpretation of the output+carry is equal to the sum of the two’s complement interpretation of the inputs and the carry bit

[math][ c_n \circ s ] = [ a ] + [ b ] + c_0[/math]

and the same for the binary interpretation

[math]\langle c_n \circ s \rangle = \langle a \rangle + \langle b \rangle + c_0[/math]

At this point with set theory we can understand that the same parallel prefix adder works for both binary numbers and two’s complement numbers, now isn’t that a miracle.

Furthermore, by adding only an inverter and a parallel XOR, you can use the same hardware that is normally used for adding for subtracting, using the congruence

[math]- [ b ] \equiv [ ! b ] + 1 \mod 2^n[/math]

To explain all of this with set theory takes about two double lectures (4 hours) in a first semester lecture (If you’re confused, that’s okay — I haven’t shown you the explanation. You can look it up in a number of standard textbooks on system and hardware architecture, for example, System Architecture - An Ordinary Engineering Discipline | Wolfgang J. Paul | Springer).

There is another way to understand this, which is called experience. In other words, you should understand it with your stomach. The problem is that the stomach is not very good at understanding computer science, whereas the brain is. As a consequence, understanding that the parallel prefix adder works for both binary and two’s complement numbers, and for subtraction of them, takes the stomach years.

And that is why set theory (or in some cases type theory) is applied in computer science.

Guy Birkbeck
Guy Birkbeck, studied Computer Science at University of Western Ontario (1984)

In SOOOOO many ways.

Databases are at the root of most applications. Databases are built to process data in Sets, and the applications that use them negotiates with the databaes in … you gessed it sets.

Many algorithms work on sets. In machine learning, you use a group of results to ‘train’ your model (derive statistics about) that you then attempt to use the algoritm in the ‘real’ world.

Statistics is ALL ABOUT THAT DATA, and stats provide a mathematical description of sets of data.

There are mathematics around the processing of sets (partitioning theory, descrete mathematics, set theory (that IS a real thing)…

Understanding how different algorithms process a set of information is called Big-O notation and describes how well different algorithms process that data. It is how we as computer scientists determine ‘good’ algoritms vs. Not-so-good.

Understanding sets is CRITICAL in computer science. You wont get through first year without being introduced to them.

Joshua Gross
Joshua Gross, Assistant Professor of Computer Science at Blackburn College

Wow. Set theory is one of the areas of mathematics most often applied in CS:

  • Data structures
  • Class-based object-oriented systems
  • Machine learning
  • Databases
  • Pattern matching, and by extension, compilers

None of these things is only set theory, but I think the only branch of mathematics that is more relevant to CS in general is algebra.

David Vandevoorde
David Vandevoorde, Ph.D. Computer Science, Rensselaer Polytechnic Institute

Let me give a non-answer (sorry).

Set theory (particularly Zermelo-Fraenkel set theory and variations) is one approach to a foundational theory for mathematics.

An alternative approach is type theory and that alternative is closely related to type systems, which are more commonly used as a foundation for various computer science disciplines.

So while there are certainly indirect applications of set theory in computer science, it’s not exactly a foundational theory there.

ADDENDUM:

See also Jonas Oberhauser’s observations in the comments. He points out that most of the math in CS is still ultimately derived from set theory (and I agree with that). Also, he points out that the formalization of automata (including Turing machines) is all in terms of sets.

So, while I wanted to point out that not all of formal CS is built on set theory, I should have made it clearer that neither is it all built on type theory (even less so, in fact).