Representing logical disjunctions in Constraint Handling Rules

夙愿已清 提交于 2019-12-25 06:26:49

问题


I am writing a constraint solver in Prolog that implements a simple logical formula:

"(alive(A) and animal(A)) iff (awake(A) or asleep(A))".

I found one way to implement it in Constraint Handling Rules, but it is much more verbose than the original formula:

:- use_module(library(chr)).

:- chr_constraint is_true/1.
is_true(A) \ is_true(A) <=> true.

is_true(alive(A)),is_true(animal(A)) ==> is_true(awake(A));is_true(asleep(A)).
is_true(awake(A)) ==> is_true(animal(A)),is_true(alive(A)).
is_true(asleep(A)) ==> is_true(animal(A)),is_true(alive(A)).

Would it be possible to implement this formula using a single statement instead of multiple redundant statements?


回答1:


This is not a direct answer to your literal question. However, I would still like to point out an alternative solution altogether: At least in this concrete case, all statements are propositional statements, and so you can model the whole sentence as a Boolean constraint over the propositions.

For example, using CLP(B):

?- sat((Alive_A * Animal_A) =:= (Awake_A + Asleep_A)).

If you now instantiate any of the variables, the constraint solver automatically propagates everything it can. For example:

?- sat((Alive_A * Animal_A) =:= (Awake_A + Asleep_A)),
   Animal_A = 0.
Animal_A = Awake_A, Awake_A = Asleep_A, Asleep_A = 0,
sat(Alive_A=:=Alive_A).

From the fact that Alive_A is still unbound, you can tell that both truth values are still admissible.



来源:https://stackoverflow.com/questions/43837999/representing-logical-disjunctions-in-constraint-handling-rules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!