clpq

SWI-Prolog and constraints, library CLP(FD)

懵懂的女人 提交于 2019-12-04 03:31:49
问题 I'm playing around with constraints in (swi) prolog using the clpfd library. I'm trying to identify when one set of constraints encapsulates or subsumes the other, e.g. X<4 encapsulates X<7 as whenever the former is true, the latter is true. This can be easily represented using logical implication. However, I couldn't get the #==> operator to give me the result I wanted, so I resorted to using not(Co1 #/\ #\Co2) where Co1 and Co2 are constraints. This is fine for individual constraints, but I

I'm curious if Logic Programs can do algebra

↘锁芯ラ 提交于 2019-11-29 18:12:08
问题 I read a brief article about Prolog and Logic Programming. I'm curious if Logic Programs can do algebra. Like would you be able to ask what the Variable of X is in the equation 5+X = 7 and get an answer of -2? 回答1: All serious Prolog systems provide constraint logic programming over finite domains, called CLP(FD) for short, with which you can solve many such equations easily. For example, with SICStus Prolog, SWI and Yap: ?- use_module(library(clpfd)). true. ?- 5+X #= 7. X = 2. Apparently,