Cut Not and Fail Cut, Not, and Fail
York University CSE 3401 Vida Movahedi
York University‐ CSE 3401‐ V. Movahedi
1
07_CutNotFail
Cut Not and Fail Cut, Not, and Fail York University CSE 3401 Vida - - PowerPoint PPT Presentation
Cut Not and Fail Cut, Not, and Fail York University CSE 3401 Vida Movahedi 1 York University CSE 3401 V. Movahedi 07_CutNotFail Overview Overview Multiple solutions p Cut Examples p 3 reasons to use Not Fail
York University‐ CSE 3401‐ V. Movahedi
1
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
2
07_CutNotFail
f h ( ) father(mary, george). father(john, george). father(sue, harry). father(george, edward).
X= mary, Y= george; y, g g ; X= john, Y= george; X= sue, Y=harry; X= george, Y= edward
X= george; X= george; X= harry; X harry; X= edward
York University‐ CSE 3401‐ V. Movahedi
3
07_CutNotFail
i i ( ) is_integer(0). is_integer(X):‐ is_integer(Y), X is Y+1. The query :‐ is_integer(X). will get infinite number of integers: X 0 X=0; X=1; X=2; .... backtracking will go on forever!
:‐member(a, [a,b,a,a,b]). true; true; true;
York University‐ CSE 3401‐ V. Movahedi
4
07_CutNotFail
facility(Pers, Fac):‐ book overdue(Pers, Book), basic facility(Fac). facility(Pers, Fac): book_overdue(Pers, Book), basic_facility(Fac). facility(Pers, Fac):‐ general_facility(Fac). client(‘A. Jones’). book_overdue(‘A. Jones’, book100). b k d (‘A J ’ b k200) book_overdue(‘A. Jones’, book200). basic_facility(enquiries). general_facility(borrowing).
:‐ client(X), facility(X,Y). ( ), y( , )
York University‐ CSE 3401‐ V. Movahedi
5
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
6
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
7
07_CutNotFail
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). b i f ili ( i i )
! always succeeds as a goal
basic_facility(enquiries). general_facility(borrowing).
– If you got this far, don’t try resolving with the second rule for facility. – If you got this far, commit to values you have, for example for Book
York University‐ CSE 3401‐ V. Movahedi
8
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
9
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
10
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
11
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
12
07_CutNotFail
sum_to(1,1):‐ ! . sum_to(N, R):‐ N1 is N – 1, sum_to(N1, R1), R is R1 + N R is R1 + N.
:‐ sum_to(1, R).
sum_to(N, 1):‐ N =< 1 , ! . sum_to(N, R):‐ N1 is N – 1, _ sum_to(N1, R1), R is R1 + N.
York University‐ CSE 3401‐ V. Movahedi
13
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
14
07_CutNotFail
C0: intersection ( [] , B , [] ). C1: intersection ( [Ah|At], B, [Ah|Ct]) :‐ member ( Ah B ) ! member ( Ah , B ) , ! , intersection ( At , B , Ct ). C2: intersection ( [Ah|At], B, C) :‐ intersection ( At , B , C ).
York University‐ CSE 3401‐ V. Movahedi
15
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
16
07_CutNotFail
\+((spouse(X,Y), gross_income(Y, Inc), Inc>3000)),
York University‐ CSE 3401‐ V. Movahedi
17
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
18
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
19
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
20
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
21
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
22
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
23
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
24
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
25
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
26
07_CutNotFail
York University‐ CSE 3401‐ V. Movahedi
27
07_CutNotFail