1

I have the following query:

?- Remainder :: 0..8, Qoutient #:: 0..Dividened,
   Dividened #= Qoutient * 9 + Remainder, Dividened = 12.

As you can see I have an integer suspension Qoutient #:: 0..Dividened, and try to clear the value of the Dividend at the end. However, I get the following error:

instantiation fault in Qoutient #:: 0 .. Dividened

So how can I solve the problem in Eclipse CLP?

false
  • 10,264
  • 13
  • 101
  • 209
OmG
  • 18,337
  • 10
  • 57
  • 90
  • I am not sure why you call this a "suspension", you should probably say "variable". – jschimpf Apr 16 '19 at 22:54
  • @jschimpf thanks for your consideration. I thought the `#` sign likes the `$` is used for the suspension. Is n't it? – OmG Apr 17 '19 at 15:01
  • In ECLiPSe, "suspension" has a very narrow technical definition (a handle for a delayed subgoal, see http://eclipseclp.org/doc/bips/kernel/suspensions). Only remotely related to what you are talking about. – jschimpf Apr 17 '19 at 18:26

1 Answers1

2

You could write Quotient#>=0, Quotient#=<Dividend, but there is actually no need to give any a-priori bounds on that variable at all. Simply use

?- Remainder :: 0..8, Dividend #= Quotient * 9 + Remainder, Dividend = 12.
Remainder = 3
Dividend = 12
Quotient = 1
Yes (0.00s cpu)

You may want to generalize this for arbitrary Divisors and package the whole thing into an auxiliary predicate, such as

divmod(Dividend, Divisor, Quotient, Remainder) :-
        0 #=< Remainder, Remainder #=< Divisor-1,
        Dividend #= Quotient*Divisor + Remainder.

Then your query becomes

?- divmod(D, 9, Q, R), D = 12.
D = 12
Q = 1
R = 3
Yes (0.00s cpu)
jschimpf
  • 4,904
  • 11
  • 24