Introduction to
Logic Programming
What
versus
How
 

Lessons References Epilog Sierra Forum


Week 4

By this point in the course, you should be adept at writing simple queries that are both correct and reasonably efficient. Ideally, in Logic Programming, your only concern should be correctness, and efficiency should be left to the interpreter and/or compiler. As it turns out, there are tools that can significantly enhance the efficiency of logic programs (in ways that cannot be done with traditional imperative programs). However, in many cases, it is still necessary for the programmer to take efficiency into account.

This coming week, we start our look at view definitions. View definitions are similar to queries, except that we can name the resulting relations, and we can use them in the definitions of other relations. This capability is convenient, and it increases the expressiveness of our logic programming language. It also increases the complexity of our semantics and our execution algorithms. The upshot is that we will spend the entire week on these topics. Then, next week, we will look at examples of view definitions, and we will begin to get a sense of the power and beauty of Logic Programming.

As with our treatment of queries, this unit of the course will take two weeks, and so the assignments on this material are not due until the Sunday after next. It is okay to take a glance at the assignments, but if you get stuck you might want to wait to finish the assignments until you have read the relevant chapters and/or listened to the corresponding lectures. As always, make use of the Forum if you have any questions.


Week 3

We have now begun our look at queries, but we have not yet finished. We have another week to go before moving on to more interesting topics.

In Lesson 3, we saw precise definitions for the syntax and semantics of queries. If you want to know the answers to a query or the results of executing an update, you just need to think about the instances of the constituent rules and apply the definitions given in the lessons.

Although these definitions are simple and precise mathematically, they are not satisfying from a computational point of view. The number of instances of query rules can be extremely large, even for finite Herbrand universes; and, of course, there are infinitely many instances for infinite Herbrand universes. The good news is that, in many cases, we can get by with much less work.

This week, we look at ways to do these computations without enumerating all instances. In Lesson 5, we introduce the algorithm used by the Epilog / Sierra interpreter in answering queries. The algorithm is guaranteed to produce the same answers as our instance-based semantics but operates much more efficiently. In Lesson 6, we talk about ways we can use knowledge of this algorithm to optimize queries and get answers even more efficiently.

The assignments for this unit are due by midnight this coming Sunday. (1) Note that you will likely have trouble doing Assignment 5 without using some of the optimization techniques discussed in Lesson 6. (2) You may also need to enlarge Sierra's "Unification Limit", as this problem has quite a large search space. (3) Finally, if you are having trouble, you should consider working on a simplified version of the problem before tackling the entire problem. For example, you might start with a two column cryptarithmetic puzzle.


Week 2

By this point, you should have mastered the material in Chapters 1 and 2. From Chapter 1, you should be familiar with the basic idea of Logic Programming - logic programs as runnable specifications. From Chapter 2, you should understand the concept of datasets and some of the issues involved in creating datasets to describe application areas. In fact, you should be more than familiar with this material - ideally, you should be saying to yourself (and others) that, when all is said and done, this stuff is pretty easy. In fact, it *is* easy. But it is also very important, as we use datasets not just for practical purposes but also in defining the semantics of more complex notions to come.

Judging by the discussion on the Forum, it appears that, for some of you, the toughest part of the first assignment set was figuring out how to use the meta-vocabulary of types and predicates and attributes to describe types and predicates and attributes. Most of our work will be closer to the second assignment of the week (describing real world things, like movies), but we wanted you to do assignments 3 and 4 to get you to think explicitly about those concepts.

Week 2 focusses on queries. We add variables and logical operators to our language and show how to use them in writing queries, and we give a formal semantics for queries written within this language. As we shall see, the semantics is simple and very precise. However, it is not very practical from a computational point of view. In Week 3, we will look at more practical algorithms for computing answers, and we will suggest some techniques for optimizing queries that take advantage of these algorithms.

A reminder that we would like you to take advantage of the Forum. If you are confused about something, you might be able to get insight from others. If you have mastered the material, you might be able to help others; and explaining things might help you to understand the material more deeply.


Week 1

Okay. We are on our way! The course begins now. On Tuesday, we will have an introductory presentation on the subject matter of the course and course logistics. On Thursday, we will have our first substantive class.

Your goal this week is to read through and understand the first two chapters of the notes. The first chapter is just an overview, and it is an easy read. That said, you should not shortchange the material. The chapter talks about the main ideas of Logic Programming and how they relate to each other. The second chapter introduces Datasets. Datasets are fundamental to the theory of Logic Programming, and they are important in practical implementation. The concept is simple, but there are some nuances; and we recommend you read the notes carefully and do the exercises.

You should also drop by the Forum to check out what others in the class are saying. There are some subtleties in Logic Programming that you can miss and that can lead to confusion. Engaging in discussion on the Forum is a good way to deal with these subtleties. And, even if you think you understand everything, you might consider using the Forum to help others and thus consolidate your understanding of the issues.

Note that this week's assignments are due by midnight next Sunday. After this, the assignments for each unit will be due every other week.


Course Overview

Logic Programming is a style of programming based on Symbolic Logic. In recent years, there has been increasing interest in Logic Programming due to applications in deductive databases, automated worksheets, Enterprise Management (business rules), Computational Law, and General Game Playing.

This course is an introduction to Logic Programming theory, current technology, and popular applications. Work in the course takes the form of lectures, readings, online exercises, programming assignments, and a term project.

There will be twenty in-person class sessions - on Tuesdays and Thursdays from 1:30 pm - 2:50 pm. See the table below for a summary of the topics of these sessions. Note that you should attend all sessions, as we will occasionally discuss things in class that are not in the notes.

DateTopicLocationTime
April 2 Introduction 370-370 1:30 - 2:50
April 4 Datasets 370-370 1:30 - 2:50

April 9 Queries 370-370 1:30 - 2:50
April 11 Query Examples 370-370 1:30 - 2:50
April 16 Query Evaluation 370-370 1:30 - 2:50
April 18 Query Optimization 370-370 1:30 - 2:50

April 23 Views 370-370 1:30 - 2:50
April 25 View Evaluation 370-370 1:30 - 2:50
April 30 Simple Examples 370-370 1:30 - 2:50
May 2 Lists, Sets, Trees 370-370 1:30 - 2:50

May 7 Operations 370-370 1:30 - 2:50
May 9 Model Management 370-370 1:30 - 2:50
May 14 Reactive Worksheets 370-370 1:30 - 2:50
May 16 Semantic Worksheets 370-370 1:30 - 2:50

May 21 Constraints 370-370 1:30 - 2:50
May 23 Program Synthesis 370-370 1:30 - 2:50
May 28 Advanced Logic Programming 370-370 1:30 - 2:50
May 30 Past Projects 370-370 1:30 - 2:50

June 4 Student Reports 370-370 1:30 - 2:50
June 6 Student Reports 370-370 1:30 - 2:50

All of the course materials are online here. There are links to lessons, additional readings, the Epilog language, the Sierra interactive development environment, and the Ed Forum. Click the tabs at the top of this page to access this content. The Lessons tab is your friend. Use it. And be sure to check this page frequently, as we will be posting periodic updates here.

Note that, as you proceed through the online materials, you may occasionally encounter minor errors or inconsistencies. Apologies in advance for this. We are still working on the course. You may get extra credit for reporting such problems (especially if your reports are not overly irate).


Teaching Staff

Mike Genesereth
Email: genesereth@stanford.edu
Office Hours: Wed 3:00 pm - 4:00 pm
Location: Gates 308
Janelle Cheung
Email: cheung23@stanford.edu
Office Hours: Thursday 6:30pm - 9:30pm
Location: Zoom
Melissa Lee
Email: mlee24@stanford.edu
Office Hours: Wednesday 4:00pm - 7:00pm
Location: Zoom
Sophia Ramsey
Email: sramsey9@stanford.edu
Office Hours: Thursday 3:30pm - 5:00pm
Location: Zoom


Feedback