From: notoria Date: Sun, 25 May 2025 11:39:31 +0000 (+0200) Subject: Strengthened `(mod)/2` in CLP(Z) X-Git-Tag: v0.10.0~43^2 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=4b480a7eab68b4e1dc8d07c36ae7b1645ee073bb;p=scryer-prolog.git Strengthened `(mod)/2` in CLP(Z) ?- 8 #= -1 mod #Y. clpz:(Y in 9..sup), clpz:(-1 mod#Y#=8). % unexpected Expected: Y = 9 ?- 8 #= -12 mod #Y. clpz:(Y in 9..sup), clpz:(-12 mod#Y#=8). % unexpected Expected `Y` with finite domain --- diff --git a/src/lib/clpz.pl b/src/lib/clpz.pl index 0f383094..89019b4f 100644 --- a/src/lib/clpz.pl +++ b/src/lib/clpz.pl @@ -5110,7 +5110,23 @@ run_propagator(pmod(X,Y,Z), MState) --> YU < X, X =< 0 } -> kill(MState), Z =:= X ; { fd_get(Y, _, n(YL), _, _), YL > X, X >= 0 } -> kill(MState), Z =:= X - ; ( Z > 0 -> + ; ( Z > 0, X < 0 -> + { fd_get(Y, YD, YPs), + YMin is Z+1, + YMax is Z-X, + domain_remove_smaller_than(YD, YMin, YD1), + domain_remove_greater_than(YD1, YMax, YD2) }, + fd_put(Y, YD2, YPs) + % queue_goal((Y #> Z, Y #=< Z-X)) + ; Z < 0, X > 0 -> + { fd_get(Y, YD, YPs), + YMax is Z-1, + YMin is Z-X, + domain_remove_greater_than(YD, YMax, YD1), + domain_remove_smaller_than(YD1, YMin, YD2) }, + fd_put(Y, YD2, YPs) + % queue_goal((Y #< Z, Y #>= Z-X)) + ; Z > 0 -> { fd_get(Y, YD, YPs), YMin is Z + 1, domain_remove_smaller_than(YD, YMin, YD1) },