2

与答案集编程中的默认否定相比,我很难将否定的概念理解为 Prolog 中的失败。有人可以向我解释一下有什么区别吗?

4

1 回答 1

1

马虎:

如果你没有中彩票,你需要找份工作!

序言

好,我去买票!

...之后...

我想我需要找份工作。

ASP

好吧,我要去找工作了(因为我不知道我会不会中彩票)。

所以,“Default Negation”是一个默认的no,除非另有说明,而“Negation as Failure”意味着先尝试,只有这样你才会知道失败

现在在代码中:

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 回应

find_a_job get_money

Prolog 会回答get_moneytrue但在那之前它会完成spend_money_on_ticket,这会让你更穷。

(实际上,它甚至会为 的每个子句买两张票get_money。如果它第二次赢了,那么get_money就不会成功,所以正确的 Prolog 版本是:

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

但这不再使用否定作为失败。)

于 2019-03-01T09:47:38.420 回答