Definite Clause Deduction

Back to tutorials.

Tutorial Two: Queries

Once you switch to 'Solve' mode, you will be looking at a blank canvas with several buttons near the top of the screen. At the bottom of the screen is the knowledge base from the 'Create' mode and the algorithm which is selected for the search. Below is an example of what the applet will look like:


If you have not already written a knowledge base or loaded a sample one, do so now. Then, click the button marked 'Create New Query'. A new window will open containing a list that allows you to select one of the knowledge base's predicates. This is the frame to help you build a query for the predicate append/3:

Type the terms into the correct boxes, and click 'Add Query'. Then, the atom you have just built will be parsed. This allows you to repeat the above process to create a larger query. If, in subsequent atoms, you reuse variable names from previous atoms, they will be set to be the same variable. For example, if I were to choose member(X,[a,b,c]) and member(X,[c,d]) as my query, the only answer would be X = c, since X is the only constant that is a member of both lists.

Once you click 'OK', you will see a node at the top of the canvas containing your query.

Below is a simplified version of the applet, set up to query 'member(X,[a,b,c]) & member(X,[c,d])'.

To try applying a clause to an atom, click on the node containing it. A window will open allowing you to choose an atom and select a corresponding clause to apply. If the head of the clause successfully unifies with the atom, then a new node will appear.

The atoms of this node will consist of the previous node's remaining atoms as well as the body of the clause that was applied.

If the unification is unsuccessful, you can try a different clause. Once there are no more clauses, that path on the search tree is considered to have failed. Certain atoms do not have associate clauses or facts. Atoms with built-in predicates, for example, or negation as failure atoms, are solved in different ways.

For examples of atoms of that kind and a listing of built-in predicates, see Tutorial Five.

Once the entire query has been solved, you will see a success node shaped like a diamond. Try solving the query below. To reset the search tree, right-click on the canvas and click reset query. Use the pan, zoom, and autoscale tools to keep the nodes visible on the canvas.

AIspace Applet failed to load. Is Java enabled in your browser?

The next tutorial has more information about querying, and gives an overview of the algorithms that can be used to automatically search for the answer.

Back to tutorials.

Valid HTML 4.0 Transitional