From: Joachim Schimpf (Independent Contractor) <jschimpf_at_cisco.com>

Date: Thu, 05 Apr 2007 00:43:01 +0100

Date: Thu, 05 Apr 2007 00:43:01 +0100

Marconcini Cristina wrote: > Dear All, > > > I would like to submit you a question about the division operator in Eclipse. > I am sorry because It should be trivial, but perhaps > there is something that I haven't seen. > > I need to perform a division with variables and get the integer quotient. > In fact I will need to define a proper predicate like > div_pr(X,2,Y) where X is the dividend and Y the result. > > I have tried this and I have loaded the ic library. > > Yes (0.00s cpu) > ?- Y :: 0 .. 5, X :: 0 .. 5, Y #= X / 2, X #= 1. > No (0.00s cpu) This is correct. The division here is standard division over the reals, and it fails because Y is required to be integral, and there is no integer solution for Y. I guess you mean by "integer quotient" the quotient rounded (down?) to the next integer? You can define that as follows: fdiv(Dividend, Divisor, Quotient, Remainder) :- Remainder #>=0, Remainder #< Divisor, Dividend #= Quotient*Divisor + Remainder. ?- [X, Y] :: 0 .. 5, fdiv(X, 2, Y, R). X = X{0 .. 5} Y = Y{0 .. 2} R = R{[0, 1]} There is 1 delayed goal. Yes (0.00s cpu) ?- [X, Y] :: 0 .. 5, fdiv(X, 2, Y, R), X = 1. X = 1 Y = 0 R = 1 Yes (0.01s cpu) -- JoachimReceived on Thu Apr 05 2007 - 00:43:11 CEST

*
This archive was generated by hypermail 2.2.0
: Thu Feb 02 2012 - 02:31:57 CET
*