简体   繁体   中英

Negation as failure in Prolog and default negation in Answer Set Programming

I'm having an extremely hard time understanding the concept of negation as failure in Prolog compared to default negation in Answer Set Programming. Could someone please explain to me what the difference is?

Sloppyly:

If you don't win the lottery, you need to get a job!

Prolog :

Alright, I'm gonna buy a ticket!

...later...

I guess I need to get a job.

ASP :

Alright, I'm going to find a job (because I don't know that I will will the lottery).

So, "Default Negation" a default no, except known otherwise , while "Negation as Failure" means try first, only then you will know about the failure .

And now in code:

win_lottery :- spend_money_on_ticket,
               fail.  % to actually win.

find_a_job.  % We can do that!

get_money :- win_lottery.
get_money :- not win_lottery, % (or \+)
             find_a_job.

ASP responds with

find_a_job get_money

Prolog will answer get_money with true , but until then it will have done spend_money_on_ticket , which makes you poorer.

(Actually, it will even buy two tickets, on for each clause of get_money . And if it would have won the second time, then get_money wouldn't have succeeded, so the correct Prolog version is:

get_money :- win_lottery,
             !.
get_money :- find_a_job.

But this doesn't use Negation-as-Failure anymore.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM