CutNotFail

# CutNotFail - X=0 X=1 X=2 backtracking will go on forever...

This preview shows pages 1–5. Sign up to view the full content.

Cut, Not, and Fail York University Department of Computer Science and Engineering York University- CSE 3401- V. Movahedi 1 07_CutNotFail

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Overview Multiple solutions Cut Examples 3 reasons to use Not Fail Problems with using Cut [ref.: Clocksin- Chap. 4] [also Prof. Gunnar Gotshalks ’ slides] York University- CSE 3401- V. Movahedi 2 07_CutNotFail
Multiple Solutions Given a set of facts, e.g. father(mary, george). father(john, george). father(sue, harry). father(george, edward). A query such as :- father(X,Y). can generate multiple solutions (if user prompts with a semicolon): X= mary, Y= george; X= john, Y= george; X= sue, Y=harry; X= george, Y= edward And a query such as :- father(_,X). generates: X= george; X= george; X= harry; X= edward York University- CSE 3401- V. Movahedi 3 07_CutNotFail

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Multiple Solutions (cont.) Example: is_integer(0). is_integer(X):- is_integer(Y), X is Y+1. The query :- is_integer(X). will get infinite number of integers:
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: X=0; X=1; X=2; . ... backtracking will go on forever! • Example: :-member(a, [a,b,a,a,b]). true; true; true; false. Only need to succeed once, waste of time! • In some cases, we need to have control over backtracking! York University- CSE 3401- V. Movahedi 4 07_CutNotFail Library Example • Allow access to basic facilities to clients with overdue books, otherwise allow access to general facilities: facility(Pers, Fac):- book_overdue(Pers, Book), basic_facility(Fac). facility(Pers, Fac):- general_facility(Fac). client(‘A. Jones’). book_overdue (‘A. Jones’, book100). book_overdue (‘A. Jones’, book200). basic_facility(enquiries). general_facility(borrowing). • Go through all clients and find the facilities open to them: :- client(X), facility(X,Y). York University- CSE 3401- V. Movahedi 5 07_CutNotFail C1: C2: C3: C4: C5: C6: C7:...
View Full Document

{[ snackBarMessage ]}

### Page1 / 5

CutNotFail - X=0 X=1 X=2 backtracking will go on forever...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online