COMP 3007 Lecture Notes - Lecture 21: Backtracking, Birdwatching

47 views3 pages

Document Summary

Use cut: cut commits the system to every choice it has made since it chose the rule, reason for cuts, 1. Faster execution, don"t spend time satisfying goals that can"t or don"t need to be satisfied: 2. Fewer backtrack points need to be considered, therefore less memory required. Confirmation of choice of rule: tell prolog it has found appropriate rule for a goal. e. g. , if you get this far, don"t try the other rules. sum_one_to(n,r). The sum of numbers from 1 to n is r. X = 15; false. sum_one_to(1,1):- !. sum_one_to(n, result):- Result is result1 + n: both rules are ok for sum_one_to(1,x). However, we do not want to use the second rule if n = 1: must tell prolog not to evaluate the second rule if the number n is 1. We do this by adding a cut: better solution would be to handle 0 or negative numbers: sum_one_to(n,1) :- n =< 1, !. sum_one_to(n, result) :-

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers