Let be a definite clause program with rules , where , and let be a conjunctive query over .

  1. Set progress to .
  2. Set currentGoal to .
  3. While the currentGoal is not empty and progress is :
    1. Let be a proposition in the current goal.
    2. If it exists, choose in a rule with the head .
      1. Let be a rule in with the head .
      2. In the current goal, replace for :
    3. Else, set progress to .
  4. If currentGoal is empty and progress is then the output is true, otherwise the output is false.

There are two points of non-determinism:

  • (3.1) When we choose a proposition in the current goal. The choice here does not matter but we must be consistent, i.e. always leftmost or rightmost.
  • (3.2) When we choose a matching rule, this choice does matter. See example 2 for an explanation.