How to restrict values of an argument in Prolog using a series of facts?

夙愿已清 提交于 2021-02-11 06:55:59

问题


I want to restrict the query property(X, use, Y) to values of Y in the list [a,b,c]. c/1 is true for only those values of Y. I thought the following would work, but it doesn't.

c(a).
c(b).
c(c). 

property(X, use, Y).
c(Y).

The following statements yield only false.

     person(1).
     property(1, use, _).

I'm using Problog, but I'm not using any Problog functions here, so I think I am misunderstanding something about unification.

I thought c(Y) would generate the list and Y would be unified across the facts.

Update This does seem to be an Problog-specific issue as the following illustrates.

substance(methadone). 
substance(heroin).

P::property(X,use,nicotine) :-  %doesn't work
    property(X,use,Z),
    substance(Z),
    P is 0.8.

property(X,use,nicotine) :-  %works
    property(X,use,Z),
    substance(Z).

person(1).
substance(Y).
property(1, use, Y).

回答1:


You can write:

property(_X, use, Y) :-
    c(Y).


来源:https://stackoverflow.com/questions/65862141/how-to-restrict-values-of-an-argument-in-prolog-using-a-series-of-facts

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