Skip to content

Commit

Permalink
ENHANCED: stronger propagation for mod
Browse files Browse the repository at this point in the history
Example:

    | ?- X in 2..3, Y in 4..9, Y mod X #= Z.
    clpz:(Y mod X#=Z),
    clpz:(X in 2..3),
    clpz:(Y in 4..9),
    clpz:(Z in 0..2) ? ;
    no
  • Loading branch information
triska committed Aug 4, 2019
1 parent 62940f5 commit cf8db7e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions clpz.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

Author: Markus Triska
E-mail: triska@metalevel.at
WWW: www.metalevel.at
Copyright (C): 2016, 2017 Markus Triska
WWW: https://www.metalevel.at
Copyright (C): 2016, 2017, 2019 Markus Triska

This library provides CLP(Z):

Expand Down Expand Up @@ -4986,7 +4986,22 @@
)
)
; X == Y -> kill(MState), Z = 0
; true % TODO: propagate more
; { fd_get(X, XD, XPs),
fd_get(Y, YD, _),
fd_get(Z, ZD, ZPs) },
( { domain_infimum(XD, n(XMin)), XMin >= 0,
domain_infimum(YD, n(YMin)), YMin > 0 } ->
{ domain_remove_smaller_than(ZD, 0, ZD1) }
; ZD1 = ZD
),
( { domain_supremum(YD, n(YMax)), YMax > 0 } ->
{ Max is YMax - 1, Min is -Max,
domain_remove_smaller_than(ZD1, Min, ZD2),
domain_remove_greater_than(ZD2, Max, ZD3) }
; ZD3 = ZD1
),
fd_put(Z, ZD3, ZPs)
% TODO: propagate more
).

%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down

0 comments on commit cf8db7e

Please sign in to comment.