Prolog Beginner: How to unify with arithmentic comparison operators or how to get a set var to range of values?

All modern Prolog systems provide finite domain constraints, which are true relations that can (in contrast to more low-level arithmetic predicates like is/2 and >/2) be used in all directions. In SWI-Prolog.

All modern Prolog systems provide finite domain constraints, which are true relations that can (in contrast to more low-level arithmetic predicates like is/2 and >/2) be used in all directions. In SWI-Prolog: :- use_module(library(clpfd)). Plus(X, Y, Z) :- X,Y ins 0..9, X + Y #= Z.

Results for your examples:? - plus(1,2,3). True.?- plus(1,2,4).

False.?- plus(X,2,3). X = 1.?- plus(1,4,X). X = 5.?- plus(X,Y,Z).

X in 0..9, X+Y#=Z, Y in 0..9, Z in 0..18. Since the predicate can be used in all directions, it does no longer make sense to call it "add/3", as that would imply a direction, but the predicate truly describes when the relation holds and is thus more general.

Add(X,Y,Z) :- Z is X + Y, X You could use var/1 to distinguish the kind of query (var/1 tells you whether a variable's uninstantiated or not), but that sounds like a lot of pain.

Yeah that doesn't work because what you described in your answer. – sixtyfootersdude Jun 5 '10 at 20:35.

Solution: lessThanTen(9). LessThanTen(8). LessThanTen(7).

LessThanTen(6). LessThanTen(5). LessThanTen(4).

LessThanTen(3). LessThanTen(2). LessThanTen(1).

LessThanTen(0). AddSimple( Add1, Add2, Sol) :- lessThanTen(Add1), lessThanTen(Add2), Sol is Add1+Add2.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions