To install click the Add extension button. That's it.

The source code for the WIKI 2 extension is being checked by specialists of the Mozilla Foundation, Google, and Apple. You could also do it yourself at any point in time.

4,5
Kelly Slayton
Congratulations on this excellent venture… what a great idea!
Alexander Grigorievskiy
I use WIKI 2 every day and almost forgot how the original Wikipedia looks like.
Live Statistics
English Articles
Improved in 24 Hours
Added in 24 Hours
Languages
Recent
Show all languages
What we do. Every page goes through several hundred of perfecting techniques; in live mode. Quite the same Wikipedia. Just better.
.
Leo
Newton
Brights
Milds

Cut (logic programming)

From Wikipedia, the free encyclopedia

The cut, in Prolog, is a goal, written as !, which always succeeds but cannot be backtracked. Cuts can prevent unwanted backtracking, which could add unwanted solutions and/or space/time overhead to a query.

The cut should be used sparingly. While cuts can be inserted into code containing errors, if a test is unnecessary because a cut has guaranteed that it is true, it is good practice to say so in a comment at the appropriate place.[1]

Some programmers call the cut a controversial control facility[2] because it was added for efficiency reasons only and is not a logical formula.

YouTube Encyclopedic

  • 1/3
    Views:
    2 263
    2 230
    1 665
  • Logic Programming - Prolog - برمجة منطقية - Lecture 6 Part 1\2
  • A Subtletly of Prolog's Cut
  • Logic Programming - Prolog - برمجة منطقية - Lecture 6 Part 2\2

Transcription

Types

Green cut

The use of a cut that only improves efficiency is referred to as a green cut. Green cuts are used to make programs more efficient without changing program output. For example:

 gamble(X) :- gotmoney(X),!.
 gamble(X) :- gotcredit(X), \+ gotmoney(X).

This is called a green cut operator. The ! tells the interpreter to stop looking for alternatives; however, if gotmoney(X) fails it will check the second rule. Although checking for gotmoney(X) in the second rule may appear redundant since Prolog's appearance is dependent on gotmoney(X) failing before, otherwise the second rule would not be evaluated in the first place. Adding \+ gotmoney(X) guarantees that the second rule will always work, even if the first rule is removed by accident, changed, or moved after the second one.

Red cut

A cut that is not a green cut is referred to as a red cut, for example:

 gamble(X) :- gotmoney(X),!.
 gamble(X) :- gotcredit(X).

Proper placement of the cut operator and the order of the rules are required to determine their logical meaning. If for any reason the first rule is removed (e.g. by a cut-and-paste accident) or moved after the second one, the second rule will be broken, i.e., it will not guarantee the rule \+ gotmoney(X).

References

  1. ^ Dyckhoff, Roy (1994-05-20). Extensions of Logic Programming: 4th International Workshop, ELP '93, St Andrews, U.K., March 29 - April 1, 1993. Proceedings. Springer Science & Business Media. ISBN 978-3-540-58025-6.
  2. ^ Foundations of Logic Programming, Springer (2012).
This page was last edited on 23 February 2024, at 06:57
Basis of this page is in Wikipedia. Text is available under the CC BY-SA 3.0 Unported License. Non-text media are available under their specified licenses. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. WIKI 2 is an independent company and has no affiliation with Wikimedia Foundation.