clpfd icon indicating copy to clipboard operation
clpfd copied to clipboard

[SWI-Prolog] - (negative) operator misbehaving in clpfd with set_prolog_flag(clpfd_monotonic, true).

Open LuizFBR opened this issue 10 months ago • 1 comments

The expression ?- #(Y) #= 2, #(X) #= ( (-#(Y)) /\ 1).

returns the following stack trace:

ERROR: Domain error: `clpfd_expression' expected, found `-#(2)'
ERROR: In:
ERROR:   [19] throw(error(domain_error(clpfd_expression,...),_10238))
ERROR:   [16] clpfd:parse_clpfd(-#(2)/\1,_10276) at c:/program files/swipl/library/clp/clpfd.pl:7840
ERROR:   [14] clpfd:clpfd_equal(#(_10322),-#(2)/\1) at c:/program files/swipl/library/clp/clpfd.pl:2846
ERROR:   [11] toplevel_call(user:user: ...) at c:/program files/swipl/boot/toplevel.pl:1317
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
^  Exception: (4) setup_call_cleanup('$toplevel':notrace(call_repl_loop_hook(begin, 0)), '$toplevel':'$query_loop'(0), '$toplevel':notrace(call_repl_loop_hook(end, 0))) ? creep

That's it. This kind of complicates things for me, I'm trying to build a relational random generator in prolog and clpfd seems like the perfect tool for handling arithmetic relations.

LuizFBR avatar Feb 24 '25 15:02 LuizFBR

Thank you for your interest!

We have:

?- atom(-#).
   true.
?- write_canonical(-#(X)).
-#(_471)   true.
?- write_canonical(- #(X)).
-(#(_473))   true.

And thus for example:

?-  #(Y) #= 2, #(X) #= ( (- #(Y))  /\  1).
   Y = 2, X = 0.

Tested with Scryer Prolog.

triska avatar Feb 24 '25 19:02 triska