"I don't know; I don't want to know."
Rich Hickey, author of Clojure, in his entertaining presentation Simple Made Easy (2011), which I recommend to all future software engineers.
Abstraction plays a major role in mathematics and software engineering, as it does in every day life.
I remember my little boy, many years ago, riding on my shoulders and pointing at the moon saying "ball". One reaction is to be amused at the child getting it wrong. Another is, to recognize that he understood the abstract concept of "round".
In its nature, the question "What is abstraction?" is a philosphical question that cannot be answered once and for all. Nevertheless, we can try to mathematically formalise abstraction. [1]
In this lecture, I want to explain one powerful way of formalising abstraction mathematically. It was devised in the late 19th century and its usefulness played an important role why set theory was widely adopted by the mathematical community as a foundation of mathematics. It is known as the technique of quotienting by an equivalence relations.
But let us first look at examples of abstraction in software engineering.
At this point, things get really complicated. What looked like a hierarchy in the beginning now turns into a network. For example, we want to design algorithms and solve problems independently of any particular programming language such as Haskell. So we need to find new levels of abstraction. Moreover, the right level of abstraction depends on the problem to be solved …
So we need a wide variety of methods to construct useful levels of abstractions:
One could easily spend a whole semester exploring specific examples and pointing out connections and interdependencies. One overarching theme of these methods is that they should all lead to formal methods and algorithms that can be turned into software tools supporting designers and developers.
After having set the scene, I want to introduce one particular way of construction abstractions, namely abstraction by equivalence relation.
One of the most powerful and simple ways of constructing an abstraction to consider things equal that are different.
To come back to the introductory example, my little boy was not confused about the meaning of "ball" when he pointed to the moon, rather he took the meaning of "ball" to be the set of all objects that are round. Then he used the name of one of the objects in this set as a name for the set itself.
Equivalence relations allow us to formalise this mathematically.
Let me choose an example of colours. We usually pick from the wide range of possible colours a small discrete set. Let me start with a chart that has the following colours:
I imagine I walk through a garden collecting flowers and fruits in a basket. Then I sit down and classify
Object | Colour |
---|---|
dandelion | yellow |
daffodil | yellow |
lemon | yellow |
orange | orange |
rose | red |
poppy | red |
violet | purple |
pansy | purple |
violet | |
blue | |
blue-green | |
green |
Mathematically, this classification is a function
Like all functions, this function induces an equivalence relation on objects.
The dandelion and lemon are equivalent because the are both yellow. Similarly, the rose and the poppy are equivalent. Etc.
Symbolically, we write this as
This relation , the equivalence relation induced by , can be formally defined:
Note that this definition makes sense for any function .
We say that
are the equivalence classes of the equivalence relation .
These equivalence classes can be themselves collected in a set:
This set is called the quotient of the set by the equivalent relation and written in symbolical notation as
The terminology "quotient" will be explained later.
Notice how is an abstraction of . It formalises the idea that as far as our colours are concerned, we cannot distinguish the rose from the poppy: both are red. And as long as this is the only observation available, we cannot make out how they are different. From this more abstract point of view, the rose is equal to the poppy.
Before we apply this methodology to more interesting examples, I want to introduce one more notation. We write
for the equivalence class that contains "rose". That is, . We turn this into a general definition of equivalence class:
is called a represenatitive of the equivalence class .
Notice that
Informally, we can interpret this as a way to make precise in which sense are simultaneously different and equal, depending on whether we take the concrete (on the left) or abstract (on the right) point of view.
Every list of applications of such a wide ranging concept as quotienting by equivalence relations suffers from the fact that no individual example can do justice to the importance of the general concept.
I limit myself to a few examples.
The following should be pretty obvious if you draw a picture.
Exercise: Let be a finite set with elements and let be an equivalence relation on such that each equivalence class has elements. Then has elements.
In group theory, this is known as Lagrange's theorem.
Mathematicians define sets axiomatically. But for finite sets we can also obtain them as equivalence classes of lists and this gives a common way to implement sets algorithmically.
Let us define ≡
as the smallest equivalence relation containing the following for all elements x
and y
and all lists xs
.
x:y:xs ≡ y:x:xs
x:x:xs ≡ x:xs
The first equation says that the order does not matter and the second equation says that duplicates can be eliminated.
Mathematically, this defines a set as an equivalence class of lists.
From a programming point of view, this means that any library that implements operations on lists can serve as a library for sets as long as we make sure to only choose operations that respect the two equations above.
Exercise: Concatenation of lists corresponds to what operation on sets?
One general idea to take from here is that in programming we often need to represent data with detail that is irrelevant to the specification of the problem. In these cases, the points of view of the implementation and the specification, or the concrete and the abstract, are related by an equivalence relation.
What is an integer? An integer is a pair modulo [4]
What is a fraction? An fraction is a pair modulo
What is a real number? An equivalence class of Cauchy sequences. And on it goes.
(Disclaimer: The purpose of this example is only to illustrate some general ideas, not to present some actual results from the field of economics. On the other hand there are writings of 19th century economists that suffer from the fact that at the time quotienting by an equivalence relation was not yet invented.)
Imagine a function
But what if the economy we want to model has no money? Is there another way to define what the price of a good is?
Exercise: Assume that we can observe the relation where are goods and is defined as can be traded for . Assume further that is an equivalence relation. Is there a way to define and the function ?
Let us model time by the integers . Time point 0 is an arbitrarily chosen starting time. The difference between two consecutive integers models one hour in real time. A clock for us is a device that measures hours on a scale of . More formally a clock is an implementation of the function
mapping an integer to the smallest non-negative number such that there is an integer k with .
Exercise: Show that the equivalence relation
satisfies .
Exercise: Explain why the equivalence classes of are also denoted by
The set of all these equivalence classes is also denoted by
I put a few more technicalities in my write-up on
The history of equivalence relation is investigated in
A typical application of these ideas in computer science is to
The notion of an equivalence relation is closely related to
A new mathematical theory of equality that allows us to keep distinct objects distinct and simultaneously treat them as equal is Homotopy Type Theory. My favourite first introduction to the topic is
Some of the greatest advances in mathematics and physics can be understood as answers to what-is questions about geometry (Euclid, Klein), instantaneous change (Newton), numbers (Dedekind), heat (Boltzmann), chaos (Poincare), proof (Hilbert, Gentzen), gravity (Einstein), computation (Church, Turing, Goedel), algebra (Noether), games (von Neumann), probability (Kolmogorov), information (Shannon), concurrency (Milner), causality (Pearl), names (Gabbay and Pitts), equality (Martin-Löf, Voevodsky), etc. ↩︎
The insight that by abstracting from a large number of discrete values to an infinity of continuous values we can actually simplify the mathematics took the genius of a Newton. ↩︎
This is an area I know very little about. I'd guess that one divide this again in several layers of abstractions. ↩︎
As an exercise define arithmetic on these integers. ↩︎