答案集编程中要推理的未知知识如何表示?
How to represent the unknown knowledge to be reasoned in Answer Set Programming?
这里是要解决的问题:
If Jim does not buy toys for his children, Jim’s children will not receive toys for Christmas. If Jim’s children do not write their Christmas letters, Jim will not buy them toys. Jim’s children do receive toys for Christmas.” Assume that the intended interpretation of this story implies that Jim’s children wrote their Christmas letters.
现在我想将上述信息编码成规则和事实,以便 clingo 推断这些信是否是吉姆的 children 写的。
我写的程序如下:
son(peter,jim).
receive_presents(peter,jim).
-buy_presents(jim,peter) :- son(peter,jim),
not write_letters(peter).
-receive_presents(peter,jim) :- not buy_presents(jim,peter).
为简单起见,我假设吉姆只有一个 child 叫彼得。
在我看来,答案集的推理过程是:
所有事实都在答案集中,即son(peter,jim)
,receive_toys(peter,jim)
肯定应该在答案集中。
由于receive_toys(peter,jim)
在答案集中,-receive_presents(peter,jim)
不会在。因此not buy_presents(jim,peter)
应该是false,而buy_presents(jim,peter)
在答案集。
由于buy_presents(jim,peter)
在答案集中,-buy_presents(jim,peter)
为假。由于 son(peter,jim)
在答案集中,因此 not write_letters(peter)
将为假,而 write_letters(peter)
将在答案集中。
所以我认为答案应该是{son(peter,jim)
,receive_toys(peter,jim)
,buy_presents(jim,peter)
,write_letters(peter)
}
因此我们可以断定这封信确实是彼得写的。
但是当 运行 这在 clingo 中时,我得到以下信息:
clingo version 5.3.0
Reading from jim.lp
jim.lp:4:29-49: info: atom does not occur in any rule head:
write_letters(peter)
jim.lp:5:37-60: info: atom does not occur in any rule head:
buy_presents(jim,peter)
Solving...
UNSATISFIABLE
Models : 0
Calls : 1
Time : 0.001s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)
CPU Time : 0.001s
我有点认为 clingo 要求首先在规则中定义每个原子操作。但在这里我只想推理如果这封信是彼得写的所以我不能自己定义 "if xxx, then peter write the letter" 因为那只是我自己做推理部分。
如何在答案集编程中解决此类问题?
注意在经典逻辑中 p => q
等价于 !q => !p
。练习似乎是用第二种形式来表达的,所以你所要做的就是把它转回第一种形式:
If Jim does not buy toys for his children, Jim’s children will not receive toys for Christmas
变成
If Jim’s children do receive toys for Christmas, then Jim did buy toys for his children
第二条规则:
If Jim’s children do not write their Christmas letters, Jim will not buy them toys
变成
If Jim did buy toys for his children, Jim’s children did write their Christmas letters
所以程序将是:
jim_did_buy_toys :- children_do_receive_toys.
children_did_write_their_christmas_letters :- jim_did_buy_toys.
children_do_receive_toys.
显然,该练习的目的是表明 "counterfactual" 这种推理可以通过简单地 "eliminating" 任何经典逻辑定律的否定来编码,避免弄清楚哪种推理的所有麻烦否定使用。
这里是要解决的问题:
If Jim does not buy toys for his children, Jim’s children will not receive toys for Christmas. If Jim’s children do not write their Christmas letters, Jim will not buy them toys. Jim’s children do receive toys for Christmas.” Assume that the intended interpretation of this story implies that Jim’s children wrote their Christmas letters.
现在我想将上述信息编码成规则和事实,以便 clingo 推断这些信是否是吉姆的 children 写的。
我写的程序如下:
son(peter,jim).
receive_presents(peter,jim).
-buy_presents(jim,peter) :- son(peter,jim),
not write_letters(peter).
-receive_presents(peter,jim) :- not buy_presents(jim,peter).
为简单起见,我假设吉姆只有一个 child 叫彼得。
在我看来,答案集的推理过程是:
所有事实都在答案集中,即
son(peter,jim)
,receive_toys(peter,jim)
肯定应该在答案集中。由于
receive_toys(peter,jim)
在答案集中,-receive_presents(peter,jim)
不会在。因此not buy_presents(jim,peter)
应该是false,而buy_presents(jim,peter)
在答案集。由于
buy_presents(jim,peter)
在答案集中,-buy_presents(jim,peter)
为假。由于son(peter,jim)
在答案集中,因此not write_letters(peter)
将为假,而write_letters(peter)
将在答案集中。
所以我认为答案应该是{son(peter,jim)
,receive_toys(peter,jim)
,buy_presents(jim,peter)
,write_letters(peter)
}
因此我们可以断定这封信确实是彼得写的。
但是当 运行 这在 clingo 中时,我得到以下信息:
clingo version 5.3.0
Reading from jim.lp
jim.lp:4:29-49: info: atom does not occur in any rule head:
write_letters(peter)
jim.lp:5:37-60: info: atom does not occur in any rule head:
buy_presents(jim,peter)
Solving...
UNSATISFIABLE
Models : 0
Calls : 1
Time : 0.001s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)
CPU Time : 0.001s
我有点认为 clingo 要求首先在规则中定义每个原子操作。但在这里我只想推理如果这封信是彼得写的所以我不能自己定义 "if xxx, then peter write the letter" 因为那只是我自己做推理部分。
如何在答案集编程中解决此类问题?
注意在经典逻辑中 p => q
等价于 !q => !p
。练习似乎是用第二种形式来表达的,所以你所要做的就是把它转回第一种形式:
If Jim does not buy toys for his children, Jim’s children will not receive toys for Christmas
变成
If Jim’s children do receive toys for Christmas, then Jim did buy toys for his children
第二条规则:
If Jim’s children do not write their Christmas letters, Jim will not buy them toys
变成
If Jim did buy toys for his children, Jim’s children did write their Christmas letters
所以程序将是:
jim_did_buy_toys :- children_do_receive_toys.
children_did_write_their_christmas_letters :- jim_did_buy_toys.
children_do_receive_toys.
显然,该练习的目的是表明 "counterfactual" 这种推理可以通过简单地 "eliminating" 任何经典逻辑定律的否定来编码,避免弄清楚哪种推理的所有麻烦否定使用。