From ca5a5b4392bfbed8cfdbb3b2e7dbaa42ea193007 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Fri, 1 May 2020 18:29:00 +0200 Subject: [PATCH] =?utf8?q?correct=20overeager=20CLP(=E2=84=A4)=20goal=20ex?= =?utf8?q?pansion?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit For instance, consider: t(X) :- X #= 1. We *cannot* expand this to: ?- listing(t/1). t(A) :- ( integer(A) -> A=:=A ; ( var(A) -> true ; true, clpz:clpz_equal(A,A) ) ). Also, a new binding *must not* be dragged outside of disjunctions, since the code may look for example like this: i(X) :- ( X #= 3 ; X #= 4 ). This commit fixes such issues, and still rewrites CLP(ℤ) expressions as far as possible already at compilation time. For example: n(X) :- X #= 1+3. This is now compiled to (note that 1+3 is evaluated to 4): ?- listing(n/1). n(A) :- ( integer(A) -> A=:=4 ; ( var(A) -> A=4 ; B=4, clpz:clpz_equal(A,B) ) ). Ideally, it should be compiled to: n(4). --- src/prolog/lib/clpz.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/prolog/lib/clpz.pl b/src/prolog/lib/clpz.pl index 4725955b..8a9e50b8 100644 --- a/src/prolog/lib/clpz.pl +++ b/src/prolog/lib/clpz.pl @@ -3038,13 +3038,13 @@ expansion_simpler((A0,B0), (A,B)) :- !, expansion_simpler(Var is Expr0, Goal) :- ground(Expr0), !, phrase(expr_conds(Expr0, Expr), Gs), - ( maplist(call, Gs) -> Var is Expr, Goal = true + ( maplist(call, Gs) -> Value is Expr, Goal = (Var = Value) ; Goal = false ). expansion_simpler(Var =:= Expr0, Goal) :- ground(Expr0), !, phrase(expr_conds(Expr0, Expr), Gs), - ( maplist(call, Gs) -> Goal = (Var =:= Expr) + ( maplist(call, Gs) -> Value is Expr, Goal = (Var =:= Value) ; Goal = false ). expansion_simpler(between(L,U,V), Goal) :- maplist(integer, [L,U,V]), !, -- 2.54.0