%{
__NOTOC__
In this lecture, Karl uses Prolog notation. I'm going to skip a step and go ahead and start using Twelf, since I've got all this infrastructure set up to incorporate pretty Twelf into web pages. For the purpose of this exercise, this only means that we have to declare types for things and that we write connect a b instead of connect(a,b)
for facts representing a connection from a
to b, and we say D <- A <- B <- C instead of D :- A, B, C for a three-premise rule.
You'll notice there's a box on the upper-right hand corner that calls this page "Literate Twelf." This is related to the idea of [http://www.literateprogramming.com/ Literate Programming] - this wiki page is itself a page of valid Twelf code.
If you'll forgive the ugly illustration, we're interesting in answering questions about rechability on this acyclic graph (we want it to be an acyclic graph!)
-> b <-
/ \
/ \
a---------->c----->d
}%
node : type.
a : node.
b : node.
c : node.
d : node.
connect : node -> node -> type.
reaches : node -> node -> type.
connect/a-b : connect a b.
connect/a-c : connect a c.
connect/c-b : connect c b.
connect/c-d : connect c d.
reach/refl : {X: node} reaches X X.
reach/trans : {X: node} {Y: node} {Z: node} reaches Y Z -> connect X Y -> reaches X Z.
%{
'''NOTE:''' You don't have to write the Π bound things, so you could have used:
reach/refl : reaches X X.
reach/trans : reaches Y Z -> connect X Y -> reaches X Z.
(Twelf assumes you meant to Π-bind capitalized things but were too lazy to write the Π, so it does it for you.
I can ask the engine to ask questions about reachability, which will essentially perform a depth-first search on the graph.
I can confirm that there is one way through the graph from a to
d (the notation %query 1 * isn't important for you to remember, but it means that I want one answer
no matter how many times I try)
|check=decl}%
%query 1 * reaches a d.
%{
...I can ask the engine to verify that there are no paths through the graph from b to a:
|check=decl}%
%query 0 * reaches b a.
%{
...finally, I can use a capital letter (metavariable or substitution variable) Z to ask, what is EVERY path, starting from
a, in the graph? Turns out there are 5 (b can be reached in two different ways):
|check=decl}%
%query 5 * reaches a Z.
%.
= The LF Logical Framework =
== Syntax ==
== Typing Rules ==
=== Kinds ===
Kinds ''K'' classify types ''A''.
=== Types ===
Types ''A'' classify terms ''M'' and are classified by kinds ''K''.
=== Terms ===
Terms ''M'' are classified by types ''A''.