1

I have the following statement in prolog (Eclipse CLP):

?-X::1..100,  X/5 #= 2, X = 12.

The result is No.. I want to check that the integer division of X over 5 is equal to 2 or not. If I write the following statement:

?-X::1..100,  X//5 #= 2, X = 12.

I will get the following error:

instantiation fault in //(X{1 .. 100}, 5, _703)

So, the question is how can I check the integer division for the variable X?

OmG
  • 18,337
  • 10
  • 57
  • 90

1 Answers1

0

I assume you are using library(ic), which currently does not directly support flooring or truncating divisions. You can reformulate your condition by introducing a "remainder" variable and using multiplication:

?- X::1..100, Rem::0..4, X #= 5*2 + Rem, X = 13.
X = 13
Rem = 3
Yes (0.00s cpu)
jschimpf
  • 4,904
  • 11
  • 24