Introduction to
Logic Programming

Lessons References Epilog Sierra Forum

Week 10

Last week of the course. Time to finish up your projects and submit your project videos and project reports. See the Project Presentation and Project Report links for information on what to submit. See the Ed post for details on submission. Most important: Keep your videos and reports short. The ideal running time for videos is 5 minutes; and the maximum length is 10 minutes. You should aim for just 2-3 pages for your project reports.

Note that you are also required to do Assignment 5. You need to view all of the submitted videos and provide your evaluation. See the text of Assignment 5 for details on how to evaluate project presentations. We will post details on Ed describing how to access the videos of other teams.

The deadline for submission of your videos is 11:59 pm this Monday, and the deadline for project reports and assignment 5 is 11:59 pm this Wednesday. Once we have evaluated your submissions, we will upload your projects and reports to the Projects page on the course website (the same place as the reports from last year's class).

If, after completing your projects, you want to continue project work beyond the end of the quarter, please let us know, and we can arrange Stanford credit for your efforts. If you are interested in commercial opportunities for applications of Logic Programming in Computational Law, you can get in touch with Abhijeet Mohapatra from Symbium (

Week 9

Heads up! We are changing our plans once again. And this affects you! Based on responses to our survey, it appears that the vast majority of you prefer to present your projects by video recording rather than in person. Under the circumstances, we are contemplating the possibility of having all presentations done in this form. See Ayushi's post on Ed for details on preparing and submitting your presentations.

Note that you are still required to do Assignment 5. You need to view all of the submitted videos and provide your evaluation. See the text of the assignment for details on how to evaluate project presentations. We will post details on how to access the videos early next week.

Week 8

At this point in the course, we have seen all of the basics of Logic Programming - datasets, queries, view definitions, and operation definitions. There is plenty more to learn, e.g. constraint satisfaction, planning, Disjunctive Logic Programming, Existential Logic Programming, Answer Set Programming, Inductive Logic Programming, Theorem Proving, and so forth. In some ways, we have just scratched the surface.

On the other hand, we have covered enough that we can start building practical systems; and it is time to look at some examples. This past week, we saw how Logic Programming can be used in creating interactive webpages, called worksheets. This coming week, we look at some applications in the area of Computational Law. On Tuesday, i will give an overview of Computational Law; and, on Thursday, we will hear from some guests (former students) about commercial applications. (If you are curious about applications or would be interested in doing research or getting a job in this area, you should definitely attend those lectures.)

From this point on, you should be concentrating on your term projects - refining your projects, writing the code, and preparing your presentations. Based on last week's survey, it appears that a few of you would like to do in-class presentations, but the majority of you would prefer to do recorded presentations. As you wish. We would like those of you who listed a preference for in-class presentations to give their presentations on the last day of class (Tuesday May 31). We ask that other teams prepare recorded presentations by the day before that class; and we will make these available to everyone in the class. Note that Assignment 5 calls for every team to evaluate every other team. This means you will all need to attend that last class (to hear the in-class presentations) and you will need to view the videos. The good news is that, with so many people doing videos, we can drop a few classes from the schedule. With the exception of that final session, no more classes after this week.

Week 7

This week, we will look at how Logic Programming can be used in creating interactive webpages, called worksheets. Worksheets nicely combine everything that we have seen thus far, and they make for very nice demonstrations. We recommend (though do not require) that you showcase your term projects using worksheets.

As this is the second week of this unit of the course, the associated assignments are due by the end of the week (Sunday at midnight). You should also be finalizing your term project proposals. After this week, there will be three weeks left in the quarter, and in that time you will need to complete your project, give a brief presentation and demonstration to the class, and submit a final report.

If you are struggling to find or choose a project, see below for links to projects we would like people to try and links to materials associated with projects from previous years.

Connect Four
Evil Games
Logical Splitwise
  NBA Draft
Public Land Usage
Veterans Benefits

Note also that the CS department needs people to maintain the undergraduate and masters program sheets. We would very much like to see groups choose to understand and improve the existing program sheets. Added benefit: possible financial support for updating the actual sheets in the Fall. (If you are a CS student and you want to check out the current system, go to GIN, log in, click on Dashboard, and click on Blank Program Sheets.)

Week 6

This week, we begin our look at dynamic logic programming (DLP). As we shall see, DLP is an extension of traditional logic programing in which we can define not just views of datasets but also operations that transform datasets into other datasets. The good news is that the semantics of operation definitions is much simpler than the semantics of view definitions.

Next week, we will look at the use of dynamic logic programming in creating interactive "worksheets" (which is arguably a "killer app" for DLP).

Since this is the first week of this unit, the assignments on this material are not due until the Sunday after next. That said, you might want to get started early on those assignments. Also, you will need to choose the topic for your term project by the end of next week, so that you will have plenty of time to do the work before the end of the quarter.

Week 5

Phew. Last week was not an easy week for some people. The concepts of stratification and unification are difficult to grasp when they are seen for the first time. The good news is that, with these complexities behind us, the rest of the course is relatively easy. The fun starts now.

This week, we spend all of our time looking at examples. In our first session, we concentrate on simple examples - Kinship and Blocks World and so forth. In our second session, we move on to more complicated examples - lists and trees and sets.

As this is the second week of this unit of the course, the associated assignments are due by the end of the week (at midnight this coming Sunday). If you have not already done so, you should get to work on the assignments. Most are easy, but not all. Most people find the zebra problem to be difficult. For those of you who are breezing through the assignments and yearning for something more challenging, we suggest you take a look at the Tournament example.

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 views. This capability is convenient, and it dramatically 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 just how 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.

Lesson 3 gives 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 exactly 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 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 take advantage of this algorithm in optimizing queries to get answers even more efficiently.

Your solutions to Assignments 2.1 - 2.3 are due by midnight this coming Sunday. (1) Note that you will likely have trouble doing Assignment 2.3 without using some of the optimization techniques discussed in Lesson 6. (2) You may also need to enlarge Sierra's "query depth" on the Settings menu, 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 part 1 of assignment 1.3 (describing real world things, like movies), but we wanted you to do parts 2 and 3 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 some practical algorithms for computing answers, and we will suggest some techniques for optimizing queries that takes advantage of these algorithms.

A reminder that we would like you all to form teams and start working with your teammates - on both the biweekly assignments and on the term project. Also, please 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.

Note for those of you on the waiting list: We believe that we can get you all in without too much trouble. We have asked our admin to send you permission codes to enroll. If you are on the waiting list and you want to enroll and you have not received a permission code by Tussday, please let us know by leaving a private note on Ed.

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 textbook. 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 Sunday night. After this, the assignments for each unit will be due every other week. The "Project" is not due this week. But you should start thinking about what you might want to do. Look at the assignments from last year. And read the suggestions that we will post occasionally on the Forum. We are particularly interested in seeing one or more teams working on program sheets.

Finally, we would like you to form teams and work together throughout the quarter. Ideally three members per team, but four ok and two possible in extreme circumstances. If you have not found teammates after the first class or two, drop by the Forum to find others in need of teammates.

Course Description

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.

All of the course materials are online here. There are links to lessons, additional readings, the Epilog language, the Sierra logic program development environment, some examples, and the the 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.

If you are desperate for a printed version of the course text, click on the image below to purchase a copy from Amazon.

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
Office: Gates 308
Office Hours: Wed 2:00 pm - 3:00 pm
Jacky Lin
Office: Zoom
Office Hours: Sun 5:00 pm - 6:00 pm
Nolan Miranda
Office: Zoom
Office Hours: Tue 3:15 pm - 5:15 pm
Ayushi Tandel
Office: Zoom
Office Hours: Wed 3:30 pm - 4:30 pm

Comments and complaints to