Closed World Assumption

1 / 16

Closed World Assumption - PowerPoint PPT Presentation

Closed World Assumption. Go through some last year exam questions More help on chatbot. Closed World Assumption.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

PowerPoint Slideshow about 'Closed World Assumption' - opa

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Closed World Assumption

Go through some last year exam questions

More help on chatbot

Closed World Assumption

In logic program, we assume that the world is closed in the sense that everything that exists is in the program or can be derived from the program. Accordingly, if something is not in the program (or cannot be derived from it) then it is not true and consequently its negation is true. This deserves special care because we do not normally assume that the world is closed

An Example

?- not human('Mary').

Prolog will probably answer ‘yes’. But this should not be understood as Prolog saying Mary is not human. What Prolog really means to say is: ‘there is not enough information in the program to prove that Mary is human’.

(Note that, in SICStus Prolog, not(G) is written as \+(G) )

Negation as Failure

Q. How is not(Goal) implemented?

A. Prolog does not try to prove this goal directly. Instead, it tries to prove the opposite, and if the opposite cannot be proved then Prolog assume that the not(Goal) succeeds. This is called negation as failure.

Negation as Failure (in code)

not(G):-

call(G), % if G succeeds

!, % then we cut

% backtracking, then

fail. % make not(G) fail.

not(G). % otherwise, not(G)

% succeeds.

Two Control Facilities in Prolog: call(G) and fail
• call(G) – it treats the term G as a goal, executes G as if it appeared textually in its place.

For example - if_then_else(P,Q,R): if P then Q else R

if_then_else(P,Q,R):- call(P), !, call(Q).

if_then_else(P,Q,R):- call(R).

• fail is a goal that always fails.

For example – a ‘fail loop’ to print out all top boy names

find_all:- boy_names(X,Y,1), write((X,Y)), nl, fail.

find_all.

Examples of using not(G)

Assume human('Mary') is NOT defined.

?- not human('Mary').

?- human('Mary'),

!,fail.

Fail(as it is not defined) Succeed

We get a ‘true’.

Assume human('Mary') IS defined.

?- not human('Mary').

?- human('Mary'),

!,fail.

?- !,fail.

?- fail.

We get a ‘false’.

not(G) can’t return results.

?- not human('Mary').

Yes.

?- not human(X).

True. (but there is no answer for X)

Why not?

Issues with Negation as Failure
u_turn(south, north).

u_turn(north, south).

u_turn(east, west).

u_turn(west, east).

no_u_turn(X,Y):-

\+(u_turn(X,Y)).

no_u_turn(south, east).

no_u_turn(south, west).

no_u_turn(north, east).

no_u_turn(north, west).

no_u_turn(east, north).

no_u_turn(east, south).

no_u_turn(west,north).

no_u_turn(west,sorth).

no_u_turn(X, X).

Check these with 2 versions.

? – no_u_turn(south, north).

? – no_u_turn(south,west).

? – no_u_turn(south, X).

9

A Program Given in Past PaperNeed to answer what you get from each query.

likes(fred, hannah).

likes(hannah, fred).

likes(hannah, logic).

likes(hannah, Who):- likes(Who, logic).

likes(father(Who), What):-

likes(Who, What).

?- likes(fred, amy).

?- likes(hannah,X).

?- likes(X,hannah).

Some Past Exam Questions
• Explain what is meant by the closed world assumption.
• Explain what is meant by negation as failure.
• Discuss the relationship between the close world assumption and the negation as failure.
• Discuss how to define dislikes relation by using negation as failure.
• What result is obtained when the goal

?- dislikes(X,Y).

help on chatbot – from lecture 7

From ‘cango’ program’s output, you need to write out a detailed direction. It is very similar to write_list(L), if you just say to east, south, etc.

% give_direction(DirList, DistanceList)

give_direction([],[]):- nl.

give_direction([H1|T1],[H2|T2]):-

write(‘go ’), write(H1), write(‘ ’), write(H2), write(‘ meters, ’), give_direction(T1,T2).

For a more human-like solution, you can say ‘turn left/right’, and indicate which side the room is. You need to use same trick used in ‘cango’: add pre-direction as an extra parameter

Help on Chatbot – from lecture 8

new

pattern_tofm([to, X, from, Y|_], X, Y):-

is_valid_loc(X), is_valid_loc(Y), ! .

pattern_tofm([to,room,X,from,room,Y|_], X, Y):-

is_valid_loc(X), is_valid_loc(Y), ! .

……

pattern_tofm([_|T], X, Y):- % carry on checking

pattern_tofm(T, X, Y).

is_valid_loc(X):-next(X,_,_,_,_).

• For key words searching, the following program is useful: intersect(L1,L2,L3).
• ?- intersect([a,b,c],[c,a,w],L).

L = [a,c]

• watch out the difference from the intersect program given in lecture 8, which is

intersect(L1, L2, X):- member(X, L1), member(X, L2).

Here we only find a common element X

?- intersect([a,b,c],[c,a,w],L). L = [a,c]

How to define this?

intersect( ).

intersect( ):-

intersect( ):-

Files needed forchatbot
• map.pl http://www.cems.uwe.ac.uk/~ryang/prolog/code/map.pl
• A dummy chatbothttp://www.cems.uwe.ac.uk/~ryang/prolog/code/chat.pl