Skip to main content

Backtracking and the “Cut”

  • Chapter
Programming in Prolog

Abstract

Let us summarise what we learned in Chapters 1 and 2 about what can happen to a goal:

  1. 1.

    An attempt can be made to satisfy a goal. When we satisfy a goal, we search the database from the top. Two things can happen:

    1. (a)

      A matching fact (or rule head) can be found. In this case, we say the goal has been matched. We mark the place in the database, and instantiate any previously uninstantiated variables that have matched. If we matched against a rule, we shall first have to attempt to satisfy the subgoals introduced by the rule. If the goal succeeds, we then attempt to satisfy the next goal. In our diagrams, this is the goal in the next box below the arrow. If the original goal appears in a conjunction, this will be the goal to its right in the program.

    2. (b)

      No matching fact (or rule head) can be found. In this case, we say the goal has failed. We then attempt to re-satisfy the goal in the box above the arrowhead. If the original goal appears in a conjunction, then this will be the goal on its left in the program.

  2. 2.

    We can attempt to re-satisfy a goal. First of all, we attempt to re-satisfy each of the subgoals in turn, the arrow retreating up the page. If no subgoal can be re-satisfied in a suitable way, we attempt to find an alternative clause for the goal itself. In this case, we must make uninstantiated any variables that became instantiated when the previous clause was chosen. This is what we mean by “undoing” all the work previously done by this goal. Next, we resume searching the database, but we begin the search from where the goal’s place-marker was previously put. As before, this new “backtracked” goal may either succeed or fail, and either step (a) or (b) above would occur.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 74.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 1994 Springer-Verlag Berlin Heidelberg

About this chapter

Cite this chapter

Clocksin, W.F., Mellish, C.S. (1994). Backtracking and the “Cut”. In: Programming in Prolog. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-97596-7_4

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-97596-7_4

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-540-58350-9

  • Online ISBN: 978-3-642-97596-7

  • eBook Packages: Springer Book Archive

Publish with us

Policies and ethics