Reputation: 451
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. Therefore not buy_presents(jim,peter)
should be false, and buy_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 since son(peter,jim)
is in the answer set, not write_letters(peter)
will be false, and write_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?
Upvotes: 2
Views: 282
Reputation: 2840
notice that in classical logic p => q
is equivalent to !q => !p
. it seems that the exercise has been phrased in this second form, so all you have to do is turn it around back to the first form:
If Jim does not buy toys for his children, Jim’s children will not receive toys for Christmas
becomes
If Jim’s children do receive toys for Christmas, then Jim did buy toys for his children
The second rule:
If Jim’s children do not write their Christmas letters, Jim will not buy them toys
becomes
If Jim did buy toys for his children, Jim’s children did write their Christmas letters
so the program would be:
jim_did_buy_toys :- children_do_receive_toys.
children_did_write_their_christmas_letters :- jim_did_buy_toys.
children_do_receive_toys.
Apparently, the exercise's goal was to show that "counterfactual" reasoning of this kind can be encoded by simply "eliminating" any negation with laws of classical logic, avoiding all the hassle of figuring out which kind of negation to use.
Upvotes: 3