I'm reading up on relations and equivalence classes. The text book only gives mathematical explanation.
If you could give a few good applications of equivalence relations and equivalence classes in computer science that would be great!
I'm reading up on relations and equivalence classes. The text book only gives mathematical explanation.
If you could give a few good applications of equivalence relations and equivalence classes in computer science that would be great!
Following are some examples from machine learning:
(a) $\vec a$ and $\vec b$ have same norm is an equivalence relation on $\Bbb R^d$ and equivalence classes are $d$-dimensional spheres.
(b) $\vec a$ and $\vec b$ lie in same cluster is an equivalence relation and corresponding equivalence classes are clusters of the concerned set.
(c) Two metrics $d_1$ and $d_2$ are said to be equivalent on a set $\Bbb X$ if $A\subset\Bbb X$ is open in $d_1$ iff it is open in $d_2$. Corresponding equivalence classes are collection of equivalent matrices.
(d) Features having same variance is an equivalence on all features. Equivalence classes are parametrized by the distinct variances we have in all the features.
Since you explicitly wanted some CS examples:
Whenever you define an equality notion, you definitely want an equivalence class.
For example, we can say that two strings with letters in $\{a,b,c,d, \}$, e.g. "abcd" and "ab cd", are equivalent iff. they agree upon removing all whitespace. Formally, we define an equivalence $=_{ws}$ (ws for whitespace) on the set of strings $S := \{a,b,c,d, \}^*$ by $$\forall s,t \in S. \quad s =_{ws} t \Leftrightarrow \mathrm{trim}(s) = \mathrm{trim}(t).$$
Check that this is indeed an equivalence relation!
With deterministic finite automata over some fixed alphabet, an equivalence relation could identify two such DFAs iff. they accept the same language.
In lambda calculus you could identify terms which reduce to the same normal form. If you don't know lambda calculus, then just consider the expressions $2+2$ and $8:2$. By evaluating both expressions individually, we get the same "end result" (normal form), namely $4$. The equivalence relation I am speaking of works very similar. So, $2+2$ and $8:2$ would get identified.
Normal forms and evaluation are very important in assisted theorem provers such as Coq. If Coq expects you to enter $4$, you can also enter $2+2$.
In Java if you override the Object.equals method, you must do it in such a way that it represents an equivalence relation. Only that guarantees that a.equals(a) == true, that if (a.equals(b)) is really equivalent in runtime semantics to if (b.equals(a)), and that you don't need to check transitivity.
Say your favorite programming language supports finite lists. How would you now construct a class for finite sets? That's easy: create a new class holding a finite list as a member variable and declare an appropriate equals method as discussed in the point above. Finite sets are nothing else than finite lists modulo the equivalence relation, which ignores order and multiple occurrences.
Generally in math, whenever you have a notion of isomorphism between two mathematical objects, this gives rise to an equivalence relation. If it does not, I wouldn't call it "isomorphism"! In fact, the most general definition of isomorphism, namely the one in category theory, induces an equivalence relation on the objects of that category.