Epilog
What
versus
How
 

Introductory Tour of Sierra


1. Introduction

Sierra is a browser-based interactive development environment (IDE) for Epilog. It allows users to view and edit datasets and rulesets. It provides a variety of tools for querying and modifying datasets and rulesets. As changes are made, it automatically updates visible datasets in spreadsheet-like fashion in accordance with the user's rules. It also provides tools for analyzing datasets and rulesets, tools for tracing program execution, and tools for saving and loading files.

This document provides an introductory tour of the main features of Sierra. We show how to load Sierra; we show how to create, view, and edit datasets and rulesets; and we show how to save one's work for later use. We suggest repeating the steps shown here in one's own browser as we proceed through the tour.

This tour presumes the reader is already familiar with Epilog or another logic programming language, such as Prolog. (See http://logicprogramming.stanford.edu for a course on Logic Programming in general and Epilog in particular.)

2. Getting Started

Since Sierra is browser-based, we start by loading a suitable browser. (Sierra runs in Safari, Chrome, Firefox, and other browsers. In our examples here, we use Safari, tough the appearance and interaction are virtually the same in all major browsers.) Once our browser is started, we load Sierra by going to the following URL.

http://epilog.stanford.edu/homepage/sierra.php

This brings up a page that looks like the following.

The command bar across the top provides access to menus concerning files, datasets, channels, rulesets, tools of various sorts, and system settings. We will introduce these menus one by one as we proceed with our tour.

3. Data

Clicking on the Datasets menu, we see two choices - Lambda (the default dataset) and New Dataset (which is used to create additional named datasets). Let's start by clicking on Lambda. This opens a window showing the contents of the dataset named lambda. It is initially empty.

We can add data by typing into the window. Here we have entered the facts p(c,d), p(a,b) and p(b,c). The window is highlighted in red indicating that we have made changes but not yet committed those changes to the database.

Clicking the save button stores the data and removes the highlighting, indicating that the window is showing the current data.

At this point, we can add or delete data or change it in other ways. One useful feature is sorting the data. This can be accomplished by pressing the Sort button. Note that the window is once again highlighted, indicating that the result of the sorting operation has not been saved to the database.

Pressing Save once again commits these changes to the database.

Suppose we edit the data and the result is syntactically illegal, as shown below.

If we try to save the window, we will get an error message like the following, and the database will not be modified.

At this point, we can either repair the problem and try again, or we can click Revert to return to the current state of the dataset in the database, as we have done here.

4. Queries

The Tools menu contains tools for programmatically querying and updating data. If we select the Query tool, we get a window like the one shown here. Note that the window may appear on top of an existing window. To move a window, we click on the title bar of the window and drag to the desired location. If we want to resize a window, we click on the tab in the lower right hand corner and drag to the desired size. Here, we have repositioned the window to the right of lambda.

To form a query, we enter an expression for our desired answer in the Pattern field and we enter our query in the Query field. Here, we are asking for all expressions of the form goal(X,Z) where p(X,Y) & p(Y,Z) is true.

Pressing the Show button evaluates the query and places the results in the query window. In this case, there are just two answers, viz. goal(a,c) and goal(b,d)

In general, queries can have many answers. By default, the Query tool shows only 100 answers, as shown in the count field. We can change this default by editing this field. In the case of expensive queries, it is often desirable to ask for just one result. Once a result or results have been shown, we can get the next batch of answers by clicking the Next button.

The Autorefresh checkbox tells the system whether we want the query to be recomputed automatically in responses to changes in the database and rulebase. Here, we have checked the box, thereby commanding automatic refresh.

Now, let's go back to lambda and add another another fact.

When we press Save, the data is saved and the Query window is automatically updated, as shown here.

Note that it is common for users to have multiple query windows open at the same time and to have their Autorefresh boxes checked. When changes are made to the database, all such boxes are refreshed automatically in spreadsheet style.

5. Updates

The Tools menu also contains tools for programmatically modifying the database. Clicking on the Transform produces a window like the one shown here.

This tool allows us to perform transformations on the database. To specify a transformation, we enter a pattern into the Condition filed and a pattern in the Conclusion field, as shown here.

In executing a transformation, Sierra finds all variable bindings that satisfy the specified condition and, for each, modifies the database in accordance with the instances of the conclusion corresponding tho that variable binding. In this case, we are requesting that Sierra find all facts of the form p(X,Y); and, for each of these, we want it to delete that fact and replace it with a fact of the form p(Y,X), i.e. the same fact with the arguments reversed.

Pressing the Execute button in this case leads to the situation show below. Note that the facts in lambda have been changed as directed. Note also that the query window has been updated to reflect the new data.

The Expand button asks Sierra to display the additions and deletions that would be performed if the transformation were to be executed in the current state. It is extremely useful in debugging to see changes before they are made.

The Expand on Update checkbox directs Sierra to refresh the changes that would be necessary as the database changes. For example, if we were to check this box and click Execute, we would see the database switch back to its original state and display a different set of changes.

Finally, the checkbox labeled Run on Clock Tick allows us to schedule the transformation rule to run whenever the clock ticks. In this case, it would result in the order of arguments of the facts in the dataset oscillating back and forth. This case is not too interesting, but updating on clock tick is often useful in simulating dynamic systems.

6. View Definitions

Views in Logic Programming are effectively named queries. An important benefit of this is composition. Once we have a name for a view, we can use that name in defining other views. Moreover, we can use the name in defining the view itself, i.e. in defining recursive views. View definitions are expressed by adding rules to a ruleset. In Sierra, rulesets are accessed via the Ruleset menu.

Clicking on the Ruleset menu, we see only one choice - Library. This is the default ruleset. (In advanced versions of Sierra, it is possible to manage multiple rulesets, but this feature is not enabled in the basic version shown here.)

Let's start by clicking on Library. This opens a window showing the contents of the ruleset named library. As with the lambda dataset, it is initially empty.

As this is a rule window can enter rules by typing in the window. Here, for example, we have defined the ancestor relation anc in terms of the parent relation p.

As with lambda, we need to click the Save button in order for our definition to be recorded in our ruleset.

Once we have a view defined, we can use it in queries and transforms. We could, for example, open another query window and write a query using anc. However, there is a streamlined tool for this purpose, viz. Compute. Here we have clicked the Compute button and gotten an empty Compute window.

If we enter anc(b,Y) in the query field and press Show, we get a list of all facts in which b appears as the first argument.

As with queries, if we check the Autorefresh box, Sierra will keep the display up to date as we make changes. For example, if we were to add an additional fact to lambda, the answer set would be updated as shown here. (Note that the Query and Transform windows have also been updated.)

As with queries, it is possible to request a specific number of answers to be shown and to step through them using the Next button.

7. Operation Definitions

Operations in Logic Programming are effectively named transformations. As with views, an important benefit of this is composition. Once we have a named operation, we can use that name in defining other operations. Moreover, we can use the name in defining the operation itself, i.e. in defining recursive operations.

Operation definitions are expressed by adding rules to a ruleset, in this case library. Here, for example, we have defined the operation relation purge. On executing purge(X), Sierra eliminates all children of p, all children of children, and so forth.

Once we have an operation defined, we can use it in transforms. We could, for example, open another transform window and write purge as a conclusion. However, once again, there is a streamlined tool for this purpose, viz. Execute. Here we have clicked Execute on the Tool menu and gotten an empty Execute window.

If we enter purge(c) in the query field and press Expand, we see a list of all facts that will be deleted if we execute purge(c). Note that, if executed, these facts would be removed in a single step, i.e. operation execution is an "atomic" action.

As with the Transform tool, we have the option of expansion on update and the option of running on clock tick.

If, at this point, we press the Execute button, Sierra will delete the indicated facts and update all windows accordingly, as shown here.

Though not illustrated by this example, operation definitions are extremely useful as event handlers for interactive user interfaces, e.g. browser-based worksheets.

8. Settings

The Settings menu allows us to control the inference engine inside Sierra.

Clicking Queries brings up an interaction pane that allows us to specify the number of inference steps performed on an individual query before the system terminates its efforts.

Clicking Transitions brings up an interaction pane that allows us to specify the number of depth of recursion in expanding operation definitions.

Clicking Timer brings up a window that allows us to set the timer going. This will run the operations in Transform and Execution windows where we have checked Run on Clock Tick.

9. File Management

The Load option on the File menu allow us to read datasets and rulesets from the local file system and load them into library, lambda, or named datasets. The Save options allows us to write data from any window to the local file system.

The Save Configuration option allows us to save the complete state of Sierra to the local file system, including data, rules, settings, open windows, and so forth. The Load configuration option allows us to load a previously saved configuration file. These operations are extremely useful in developing Logic Programming applications. We can stop work and continue right where we left off on another day. And we can exchange demonstrations by sharing config files with others.

10. Conclusion

In addition to the capabilities described here, Sierra provides tools for manipulating communication channels, which allow flow of information between Sierra and external data sources and that enable collaboration between different incarnations of Sierra running on the same machine or other machines. Unfortunately, the details are a limited complicated, and so we have skipped over the details of these capabilities in this simple introduction.

Finally, it is worth noting that there is an exension of Sierra, known as Halle, which is intended for use in developing interactive, web-based worksheets. In addition to the capabilities described here, Halle provides tools for laying out these worksheets in WYSIYG fashion, displaying those worksheets as windows in a single Sierra-like web page, and interacting with those worksheets while allowing authors to view and edit the underlying data and rules in Sierra-like fashion.



Comments and complaints to genesereth@stanford.edu.