Where we're headed…

Next section focuses on mathematical tools for describing data — sets, relations, functions, …. These are familiar and very interrelated concepts that we'll delve into in a bit more detail.


Sets

Defining

set and element-of are undefined operations (just as point/line/plane in geometry; in fact "incident on a line" is really same as "element-of"); it all comes down to being able to answer, is a particular element in the set?

How do we describe sets in math and code?

Problems with "…"

(Aside: The On-Line Encyclopedia of Integer Sequences)

Code considerations

When writing a library for sets, what are options on representing the data, and how do they correspond to the previous ideas?

Some ideas to touch on:

Some important relations on sets

Start with some (mostly?) familiar definitions…

A is a subset of B, AB

A is equal to B, A=B

  1. xA iff xB
  2. AB, and BA

A is a proper subset of B, AB

A is a non-trivial subset of B

Comparing equality definitions

Definition (1) is clearly correct -- the sets must have the same members. Definition (2) seems correct (esp. if you're familiar with it already).

Which translates to usable code better?

How to prove (1) and (2) are equivalent? …

Proof: We have to show two things:

Okay, this was written out in great detail, with constant reminders of what was being assumed and what was to be shown. But step back and observe the structure of the proof: showing two parts of "(1) equivalent to (2)" (each of which again further required an "if" and an "only if" direction.)

Code

For our two representation approaches, how to define the following?

Set operations

Many of these should be familiar already.

Note that union/or/addition all look similar; and likewise intersection/and/multiplication. Be careful about taking this too far though, e.g., it's generally not the case that (A-B)∪B = A !

Coding

On your own, consider how to code these for each of the set representations.

Naive Set Theory

Consider the set with the constant-true indicator function: (define (SuperU elt) true). What set is this? Note that not only are 4 and my car elements of SuperU, but so is the entire set ℜ is in SuperU, as well as the three-item set { ∅, black, ℜ }. (That's fine to have sets that contain sets, just as lists can contain lists.) Somewhat disturbingly though, SuperU is itself contained in SuperU! A set containing itself?! A bit dizzying, but we'll let it in the door.

Uh-oh, logician/philosopher Bertrand Russell (around 1900) sees SuperU, and senses he can do something wicked.

First, he suggests SuperB ("Bertrand"), the set of all sets which which contains themselves. The indicator function is even easy to code up: (define (SuperB elt) (element-of? elt elt)). For instance, SuperU is one of the elements of SuperB. (Think of "a book which lists all the books which mention their own title".) This discomfits us, but we don't kick Bertrand out; maybe if we just ignore him he'll go away and stop giving us a headache. [Interesting: does SuperB contain itself? Either answer is consistent, but it tips us off that our set's "easy condition" doesn't seem to fully specify the set.]

Not so lucky: encouraged by this success, Bertie cranks it up a notch, and suggests the set SuperR, of all sets which don't contain themselves. Again the indicator function is easy: (define (SuperR elt) (not (element-of? elt elt))) (Think of "a book which lists all the books which don't mention their own title".) SuperR seems to include relatively normal elements and sets, but our head is pounding more than ever. It's too late, for Bertrand jumps up and cackles as he asks:

Does SuperR contain itself?
"Well", we say, flustered: "Either it contains itself or it doesn't — after all that's all there is to sets: they either contain a given item or not. So, let's see…" "Aaaahhh!" And we are carted away to the asylum, as Bertrand sits in our favorite easy chair, drumming his fingers together, saying "Excellent…"

Indeed, this was very disturbing news to mathematicians around 1900: the concepts of sets, which underlies all of mathematics, has a paradox! Within mathematics, there could be no worse possible catastrophe. This began a program to re-vamp set theory.

Russell's own approach: a "tiered" classifications sets :
sets of atomic elts, sets containing sets of elts, …
It can be finagled to work, but is very unsatisfying.

Used today, when a rigorous foundation needed: a formalization "Axiomatic set theory". But for our purposes, we'll just use "naive set theory" —

Thus we disallow SuperU, even though it has the easiest indicator function of all.

Yes, this is deeply connected to the Halting Problem, discussed at end of the course (though discovered 30 years apart).