prologanswer-set-programmingnegation-as-failure

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?


Solution

  • 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.)