Here is the problem to solve:
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.
Now I want to code the information above into rules and facts for clingo to reason whether Jim's children wrote the letters.
The program I write is as follows:
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).
For simplicity, I just assumed that Jim has only one child named peter.
In my own thoughts, the reasoning procedure for the answer set would be:
All facts are in the answer set, i.e.
son(peter,jim)
,receive_toys(peter,jim)
should definitely be in the answer set.Since
receive_toys(peter,jim)
is in the answer set,-receive_presents(peter,jim)
will not be in. Thereforenot buy_presents(jim,peter)
should be false, andbuy_presents(jim,peter)
is in the answer set.Since
buy_presents(jim,peter)
is in the answer set,-buy_presents(jim,peter)
is false. And sinceson(peter,jim)
is in the answer set,not write_letters(peter)
will be false, andwrite_letters(peter)
will be in the answer set.
So I think the answer should be {son(peter,jim)
,receive_toys(peter,jim)
,buy_presents(jim,peter)
,write_letters(peter)
}
And thus we can conclude peter did wrote the letter.
But when running this in clingo, I get the following info:
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
I kind of think that clingo require that every atom operation be defined in the rule first. But here I just want to reason if peter wrote the letter so I cannot self define "if xxx, then peter write the letter" because that just become me myself doing the reasoning part.
How to solve this kind of problem in Answer Set Programming?