1 / 6

excessive backtracking

excessive backtracking. As the inference engine performs unification and resolution, it sometimes backtracks in unwanted ways. mother(sue, sam). mother(sue, mae). mother(mia, sue). mother(kay, jim). mother(kay, max). mother(mia, joe). mother(mia, bob). father(jim, sam).

step
Download Presentation

excessive backtracking

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. excessive backtracking As the inference engine performs unification and resolution, it sometimes backtracks in unwanted ways. mother(sue, sam). mother(sue, mae). mother(mia, sue). mother(kay, jim). mother(kay, max). mother(mia, joe). mother(mia, bob). father(jim, sam). father(jim, mae). father(ed, sue). father(moe, jim). father(moe, max). father(ed, joe). father(ed, bob). child(C, P) :- parent(P, C). parent(P, C) :- mother(P, C). parent(P, C) :- father(P, C). siblings(A,B) :- parent(P,A), parent(P,B), A \= B. Consider the following query: ?-siblings(A,B).

  2. the cut The cut is a device in Prolog for blocking backtracking. Syntax: ! mother(sue, sam). mother(sue, mae). mother(mia, sue). mother(kay, jim). mother(kay, max). mother(mia, joe). mother(mia, bob). father(jim, sam). father(jim, mae). father(ed, sue). father(moe, jim). father(moe, max). father(ed, joe). father(ed, bob). child(C, P) :- parent(P, C). parent(P, C) :- !, mother(P, C). parent(P, C) :- !, father(P, C). siblings(A,B) :- parent(P,A), parent(P,B), A \= B. A cut is a treated like true fact.

  3. Other Prolog-isms SWI Prolog allows an interactive alternative to consult. Syntax: [user] This permits the user to enter facts and rules interactively. (Use ctrl+d to terminate.) ?- [user]. |: equal(X,X). |: <ctrl-d> I/O Syntax: read(X) and write(X) Note that input to read uses |: prompt and terminates with period. ?- write(‘Hi Mom’),X is 3+5, write(X). Comments Syntax: % ?- [user]. |: % any single line comment can be placed here Misc. not (X) ; + - / * // mod ** == \= < > =< >=

  4. note that comas separate consecutive list items denotes first item expr1 and rest of the list expr2. List - Prolog Data Structure Prolog lists are denoted with enclosing [ ] [a, b, c, d] Variables can be used to separate a list: [expr1 | expr2 ]

  5. Example 1 head(List, A) iff A == (car List) Example 2 tail(List, Z) iff Z == (cdr List) Example 3 add(L, A, List2) iff List2 == (cons A L) Anonymous Variables Notation (underscore) _ When a variable’s unified value is unimportant it is better to make it anonymous.

  6. Example 4 cat(A,B,C) iff for lists (A, B and C) C is A concatenated with B Example 5 ith(L,N,A) iff A is the nth item in list L Example 6 min(L,M) iff M is the minimum item from list L . Example 7 sorted(L) iff L is sorted from least to greatest (Note that this can check for sortedness, but not perform a sort.)

More Related