Mod operator in Eclipse 
Author Message
 Mod operator in Eclipse

Can sb tell me what the equivalent of the line below in Eclipse?

Sicstus:

X in 1..10, Y #= X mod 3, labeling([],[X]).

The line below doesn't work in eclipse:

X :: [1..10], Y#=X mod 3,labeling([X]).

Thanks in advance,

Nick



Fri, 21 May 2004 17:58:25 GMT  
 Mod operator in Eclipse

Quote:

> Can sb tell me what the equivalent of the line below in Eclipse?

> Sicstus:

> X in 1..10, Y #= X mod 3, labeling([],[X]).

> The line below doesn't work in eclipse:

> X :: [1..10], Y#=X mod 3,labeling([X]).

As noted, there is no `mod' constraint in ECLiPSe.  However, it is
fairly straightforward to transform such a constraint into a normal
linear constraint.

E.g.
    Y #= X mod 3    ->    Y #= X + 3 * K

... with appropriate constraints on X and Y (and maybe K) depending upon
how you want the mod to behave (e.g. you probably want Y to be
restricted to 0..2 in this case).

Note that if your constraint is not `#=' but instead `#\=' or `#>=' or
whatever, then you need a little more care, but in general whenever you
have `X mod A' you can do a similar transformation to get what you want.

Here's an example implementation of a predicate you can use to provide a
mod constraint even when A is a variable.  Note however that it does not
do full arc-consistency: if you want something which propagates more
strongly, you will have to implement it yourself.

    % Y #= X mod A
    % (Assumes A is positive, and Y should be in the range 0..(A-1))
fd_mod(X, A, Y) :-
        Y #>= 0,
        Y #< A,
        Y #= X + A * _K.

Cheers,
Warwick



Fri, 21 May 2004 23:33:17 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. awk's mod operator % question (application: log base2 non-integer result)

2. beginners:Synthesability of mod operator,and division query

3. Mod operator

4. MOD operator

5. Eclipsing Eclipse - Rescheduled

6. Eclipsing Eclipse

7. ECLiPSe 3.5.1 / Parallel ECLiPSe

8. MOD and /MOD with Pygmy Forth

9. SM/REM FM/MOD and UM/MOD on a 32bit cell ix86 Forth

10. Utils.Mod, ET.Mod

11. Mod-2 or Mod-3 for Mac

12. Mod-2 and Mod-3 compiler

 

 
Powered by phpBB® Forum Software