### The Logic of Space Part II

I was checking my access logs and noticed that I was #1 on MSN for "logic of space" which is a bit embarassing since my last post had so little content, so I've decided to make it up to those who end up here.

Venn diagrams are spatial representations of logic. They can be used to reason in boolean logic. A Boolean Algebra can be thought of as a tuple < S,∨,∧,¬,0,1 > where S is a set (a collection of elements), ∨,∧ are binary operators, ¬ is a unary operator, and 0,1 are nullary operators (if you don't know what I'm talking about yet don't worry). We can think of 0,1 as false and true respectively.

In the Diagram above S represents everything in the picture. A and B are subsets of S which we will write A<s meaning that A is a proper subset of S. White in our pictures will always represent things that are not in the set of interest.

When you look at these diagrams you can often make sense of them by replacing the letters A B and S with familiar heirarchical objects. For example take S as Animals, A as mammals and B as animals with legs. The statement A<S can be expressed as "All mammals are also animals". Since it is < (proper subset) and not ≤ the statement also implies that there are animals which are not mammals.

The symbols '∨' and '∧' can be used to produce new sets from subsets of S. '∨' is called 'join', but in our case it can be read as 'or'. '∧' is called 'meet' and can be read as 'and'.

In the above image we see A∨B. This can be read A or B, as in "Animals with legs or Mammals".

The above diagram in light of or Animals example would represent mamals with legs (which of course is just about all mammals excluding pinepeds).

Next we have the unary operator ¬ also called complementation or negation. In our case it gives us set complementation by which we mean ¬A represents all elements that are in the set S but not in the set A. With the animals example ¬A is any animal that is not a mammal which includes birds and reptiles.

With our Animals example we pictorially described the situation 'Not a mammal or not an animal with legs'. This set (¬A)∨(¬B) would have such elements as whales and lizards but would not include dogs.

The DeMorgan's law: '(¬A)∨(¬B)=¬(A∧B)' is true for any A or B in S in a Boolean algebra (but also in other algebras including orthomodular algebras). This law is obeyed by our intuitive notion of inclusion with finite sets. Since ¬ is an involution in Boolean algebra (¬¬x=x; read 'not not x' is equivelent to 'x') we can also derive the dual formula: '(¬A)∧(¬B)=¬(A∨B)'.

Another important concept that will be more central in our next discussion, because complementation/negation is not a fundmental operation in Heyting algebras, is implication. In a Boolean Algebra we can define the symbol → as 'A → B = (¬A) ∨ B'. At first this formula might be a bit difficult to interpret. It does however follow our intuitive notions of implication. If ¬A is true then A is false so B must be true.

All of this discussion so far has been very informal and has been meant as an introduction to the ideas I plan to present next. In the next post I'll talk about the topology of boolean algebras and heyting algebras and how we can think of them pictorially.

### Decidable Equality in Agda

So I've been playing with typing various things in System-F which previously I had left with auxiliary well-formedness conditions. This includes substitutions and contexts, both of which are interesting to have well typed versions of. Since I've been learning Agda, it seemed sensible to carry out this work in that language, as there is nothing like a problem to help you learn a language.

In the course of proving properties, I ran into the age old problem of showing that equivalence is decidable between two objects. In this particular case, I need to be able to show the decidability of equality over types in System F in order to have formation rules for variable contexts. We'd like a context Γ to have (x:A) only if (x:B) does not occur in Γ when (A ≠ B). For us to have statements about whether two types are equal or not, we're going to need to be able to decide if that's true using a terminating procedure.

And so we arrive at our story. In Coq, equality is som…

### Formalisation of Tables in a Dependent Language

I've had an idea kicking about in my head for a while of making query plans explicit in SQL in such a way that one can be assured that the query plan corresponds to the SQL statement desired. The idea is something like a Curry-Howard in a relational setting. One could infer the plan from the SQL, the SQL from the plan, or do a sort of "type-checking" to make sure that the plan corresponds to the SQL.

The devil is always in the details however. When I started looking at the primitives that I would need, it turns out that the low level table joining operations are actually not that far from primitive SQL statement themselves. I decided to go ahead and formalise some of what would be necessary in Agda in order get a better feel for the types of objects I would need and the laws which would be required to demonstrate that a plan corresponded with a statement.

Dependent types are very powerful and give you plenty of rope to hang yourself. It's always something of…

### Plotkin, the LGG and the MGU

Legend has it that a million years ago Plotkin was talking to his professor Popplestone, who said that unification (finding the most general unifier or the MGU) might have an interesting dual, and that Plotkin should find it. It turns out that the dual *is* interesting and it is known as the Least General Generalisation (LGG). Plotkin apparently described both the LGG for terms, and for clauses. I say apparently because I can't find his paper on-line.

The LGG for clauses is more complicated so we'll get back to it after we look at the LGG of terms. We can see how the MGU is related to the LGG by looking at a couple of examples and the above image. We use the prolog convention that function symbols start with lower case, and variables start with uppercase. The image above is organised as a DAG (Directed Acyclic Graph). DAGs are a very important structure in mathematics since DAGs are lattices.

Essentially what we have done is drawn an (incomplete) Hasse diagram f…