Programming Languages (CSC-302 98S)
Outline of Class 32: Introduction to Logic Programming and Prolog
Held: Monday, April 20, 1998
- I believe that today is the last brown-bag lunch of the semester.
- The second exam is this Friday. It will cover general functional
programming issues, as well as some details in Haskell and Scheme.
I've prepared a short review
sheet so that you can have a sense of what will be on the exam.
Feel free to ask me questions about the exam in class today and
Wednesday (and outside of class).
- I've graded assignment 5
and have prepared a set of notes
on the assignment. I was particularly unhappy with your answers
to part A. Those of you who haven't handed it in yet may now only do
so on a credit/no-credit basis (and I'd recommend doing so, because
"credit" is a lot more than the zero points you receive otherwise).
You must hand in your answers before the exam, and they should not be
mirrors of the answer key.
- Today we're moving on to logic programming.
- Before we move on, are there any questions about lazy functional I/O,
or were the notes from the previous outline
- Since I've been asked, yes we will have a final. It is scheduled for
Monday, May 11, at 9 a.m. It is likely that we will have one or
two short homeworks before the final so that we can cover both logic
programming and semantics.
- If you haven't done so already, you should read chapter 11 of Louden.
- In the movement from imperative programming to functional programming,
you've seen a corresponding movement from explicit instructions for how
to do things to some factual information with the implicit control.
- E.g., when is an argument to a function evaluated? It depends, in part
on the design of the language and the meaning of "patterns" in the
- The declarative languages take this direction even further. In a
declarative language, a program is a collection of facts or utterances.
Typically, there is then a base statement which is then used with
the program to drive computation.
- Most typically, the facts are given in some logic, the input
to the program is a question, and the logic plus facts are used to
derive answers to the questions.
- You can think of Haskell as being a programming language based on
a simplified logic of equations and functions (e.g., if f(x) = g(y) and
g(y) = z then f(x) = z).
- There are, of course, many other logics.
- Note also that this model of computation applies to some AI techniques,
such as expert systems.
- One of the most common(?) logics is predicate logic, a
logic based on the definition and understanding of predicates,
functions that return true or false.
- What are some typical predicates? It depends on the domain, but here
are some that we'll probably visit.
- X "is an ancestor of" Y.
- L "is a sorted list".
- S "is a sorted version of" L.
- X "is a person".
- X "is mortal".
- How do we define predicates? Traditionally, using some standard
- if-then, if-and-only-if
- and, or, not
- for each (with corresponding variables)
- there exists (with corresponding variables)
- As with functions, we might also list truthful statements.
- For example,
- For all X, if X is a person then X is mortal. (Phrased in
ancient times as "all men are mortal".)
- Socrates is a mortal.