[top] [up] [next]

The execution trace


The execution trace displays the steps the Trinc-Prolog Inference engine takes while proving a goal. It can also show the values of variables at each step. The execution trace is not shown unless a Prolog program is being debugged by stepping through it or if the trace is turned on. The execution trace is turned on if the Trace on button of the main window is pressed, the displaying of the execution trace is turned off if the same button is pressed again (or use the main menu to do this or press the F6 key).

Execution states

Trinc-Prolog can be in any of 10 states while proving a goal, a state implies the next action that Trinc-Prolog will take in proving a goal.

START start of proving a goal
ENTER a (sub)expression is not proven so that (sub)expression is being entered
CALL there is no match for a goal in the set of built-in predicates and operators so a search is started for a predicate in the loaded modules
FIND candidate for a match was found. The result of the match is shown by the next step
MATCH match between a goal and a subject predicate was successfull
MISMATCH match between two predicates failed. The reason for the mismatch is shown in the execution trace
EXIT expression was completely proven and is being exited
FAIL expression could not be proven
REDO another attempt to find a solution for a (sub)goal is started
SOLUTION solution for a top-level goal was found
The execution states

The following screenshots show parts of a trace of the member/2 predicate. The left columns show the explanations of the states and in the right column a part of the member/2 trace is shown in the output window.

A MISMATCH is displayed if two clauses did not match. The next lines display the reason why the match failed. In this example the two atoms 'a' and 'b' are not equal.

FIND means that a candidate for a match was found, a candidate is a clause with the same functor (in this example 'member') and the same arity (=number of arguments, 2 in this example). After the FIND step a match is attempted.

After a successful MATCH the goal and the subject of the match are displayed and the values of variables after the match. This example does not show variables after the match.

CALL means that the prolog interpreter has no built-in predicate or operator that matches the goal so a search for a match is started in the modules currently loaded. The search is started in the active module.

 

    pl_img10.gif (11394 bytes)

 

In this example a solution is found for a goal, after the string SOLUTION the values of the variables are displayed. If the goal contained no variables then only the string 'yes' is displayed.

If a solution was found and the goal (in this example: 'member(X, [b, a]).') contained variables then a REDO is started to find more solutions. After the string REDO the goal is displayed which is being redone.

EXIT means that a (sub)expression was successfully proven and that the interpreter is going up in the execution tree in search for another goal to prove.

    pl_img11.gif (12382 bytes)

 

During the execution of a prolog program a FAIL can occur. A fail means that a clause could not be proven, the interpreter starts or continues with backtracking. After the string FAIL the goal that is being failed is displayed.
In this example a fail is started after a mismatch. The first fail is in the body of a clause, then the complete clause is being failed, then the goal of the last match, etc. Because a match can be redone a REDO is started to find another match.
    pl_img12.gif (12159 bytes)
Configuring the trace output

It is possible to adapt the output of the execution trace. If the menu item Options | Trace is pressed the dialog window below appears. It is possible to select for each of the 10 different states of the Trinc-Prolog inference engine if it is displayed in the execution trace and if the values of variables are also displayed. Per state the color to use for the text can be selected.

pl_img77.gif (7746 bytes)

Usually it is not necessary to see all the states and values of variables, for instance, the 'find' and 'call' states are usually not necessary to understand the execution of the program.

[top] [up] [next]

 

info@trinc-prolog.com