# Sets in Mathematics are immutable but in Computer Science sets are mutable and called “Dynamic Sets” - truth of the statement

While reading the classic text Introduction to Algorithms by Cormen et. al. I came across the following claim:

Sets are as fundamental to computer science as they are to mathematics. Whereas mathematical sets are unchanging, the sets manipulated by algorithms can grow, shrink, or otherwise change over time. We call such sets dynamic.

I felt a bit odd after reading the statement that "set" in Mathematics and in CS are different from the mutable point of view. Now in Mathematics what we deal with are theoretical aspect of things and as such "set" is a theoretical concept and so it is in Theoretical CS. If it is immutable in mathematics then so it is in CS. Mathematics and Theoretical CS are interlinked. So given a graph algorithm which say finds the minimum shortest path between a pair of vertices , we can't say whether it belongs to Mathematics or CS.

Often in algorithms we write statements as :

$$S = S \cup \{a\} \quad \text{view 1}$$

Which seems to sort of change our set $$S$$, but if we look it in this way:

$$S'= S \cup \{a\} \quad \text{view 2}$$

$$S=S'$$

So in the second situation we are not modifying our actual set $$S$$ we are forming a new set $$S'$$ with $$S$$ augmented with $$a$$ and then after that we are making the variable $$S$$ refer to $$S'$$.

What I feel is that the concept of the set being mutable or immutable is solely dependent on the data-structure of representation of the abstract concept of "sets" and since in data-structure the two steps in view $$2$$ are combined and implemented, so they are called dynamic sets.

In short I feel that Dynamic Sets are data-structure implementation of sets and not the abstract sets.

• In mathematics everything is immutable. – Yuval Filmus Jun 23 '20 at 21:45
• I'm not familiar with the book--maybe that the authors are just being sloppy--but in teaching, there can be tradeoffs between what helps students learn and and what is precisely correct. That's true in the classroom, and even moreso in a book, where you can't be sure who your audience is. Maybe the authors just wanted a simple way to introduce mutable "sets". (In class, sometimes I add a little "footnote", saying something like, "When you take the advanced course, you'll learn the truth, but this is good enough for now." I don't teach CS, but precision does matter in my discipline.) – Mars Jun 24 '20 at 0:26