]> Repositorios git - scryer-prolog.git/commitdiff
address #995: wrong results for popcount/1
authorMarkus Triska <[email protected]>
Mon, 21 Jun 2021 19:19:37 +0000 (21:19 +0200)
committerMarkus Triska <[email protected]>
Mon, 21 Jun 2021 19:19:37 +0000 (21:19 +0200)
Many thanks to @notoria and @flexoron for very useful test cases!

src/lib/clpz.pl

index 32622f724f563282d7d7d42e39619bfd2e420732..f330b36f7d6347aba1e9ba761ec71a3fcf8befad 100644 (file)
@@ -2959,6 +2959,12 @@ expr_conds(popcount(A0), Count) -->
         expr_conds(A0, A),
         [I is A, arithmetic:popcount(I, Count)].
 
+no_popcount_t(Gs, T) :-
+        (   member(arithmetic:popcount(_, _), Gs) ->
+            T = false
+        ;   T = true
+        ).
+
 clpz_expandable(_ in _).
 clpz_expandable(_ #= _).
 clpz_expandable(_ #>= _).
@@ -2998,14 +3004,16 @@ clpz_expansion(X0 #= Y0, Equal) :-
         phrase(expr_conds(Y0, Y), CsY),
         list_goal(CsX, CondX),
         list_goal(CsY, CondY),
+        no_popcount_t(CsY, YT),
+        no_popcount_t(CsX, XT),
         expansion_simpler(
                 (   CondX ->
-                    (   var(Y) -> Y is X
+                    (   YT, var(Y) -> Y is X
                     ;   CondY -> X =:= Y
                     ;   T is X, clpz:clpz_equal(T, Y0)
                     )
                 ;   CondY ->
-                    (   var(X) -> X is Y
+                    (   XT, var(X) -> X is Y
                     ;   T is Y, clpz:clpz_equal(X0, T)
                     )
                 ;   clpz:clpz_equal(X0, Y0)