triska / clpz

Constraint Logic Programming over Integers

Home Page:https://www.metalevel.at/prolog/clpz

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Goal expansion for (#\=)/2

triska opened this issue · comments

This was raised by @JCumin:

X #\= Y

should become faster for ground X or Y, so that we can write for example:

R #\= N mod D

with acceptable performance.

This is now implemented, to encourage the use of declarative predicates.

@triska Great! I have an off-topic question: what exactly is CLP(Z)? From what I understand this is a reimplementation of CLP(FD) for SICStus, is that right? Is it not compatible with SWI? Does that mean that CLP(FD) for SWI is left as is?

Yes, on all accounts.

You are one of the few people I regret to leave behind with an outdated version of the solver that now ships with SWI-Prolog. I hope that you too will switch to SICStus eventually, so that we can work together on the new implementation.

@triska SICStus is $165 for a personal license, not too mention that it seems you have to pay for updates too. For something that I play with in my free time, and which has free alternatives, that's quite expensive.

May I ask what is the reason you switched to SICStus? (I assume that it has better tools and overall support since it is a commercial product)

(I also don't quite understand one thing: doesn't SICStus already contain a CLP(FD) library?)

If money is the issue, please let me know: I will sponsor your work by sending you a personal SICStus license and updates in the coming years. You can download a free trial copy today. It would be great to make Brachylog portable to other Prolog systems too!

Several factors have caused me to switch to SICStus Prolog. Most important is the potential impact: My plan to establish a more declarative way of teaching and using Prolog is more likely to succeed with SICStus Prolog, since it is closer to people who teach and use Prolog professionally.

With SWI, it looked quite promising initially: Until a few years ago, the CLP(FD) library was prominently mentioned and linked to on the SWI homepage, which helped to spread its adoption among users that were previously not familiar with constraints, and encouraged researchers to read and cite the relevant publications. Now, this is all gone and even replaced by material that does not even link to the library and accompanying documents and publications. I have tolerated this for a few years, and now my patience is over.

Other factors are:

  • social: Development always also depends on others, and researchers who work on or with SICStus Prolog tend to be more interested in constraints.
  • technical: SICStus has the more general interface for attributed variables. It is now known that the SWI interface is not sufficient to express important classes of constraint solvers. See my recent CLP(B) publication for more information.
  • personal: To me, development on SWI-Prolog was fun until a few years ago. After that, several incidents have made it a lot less fun to me. For example, parts of my Prolog teaching material (see The Power of Prolog) were copied without permission and are now prominently featured on the SWI homepage under someone else's name. Unfortunately, the material they illicitly copied is becoming increasingly outdated.

Under ordinary circumstances, each of these factors would by itself have been reason enough for me to stop contributing to SWI-Prolog. In this special case, I held on for a few more years due to several reasons, and now it is time for me to move to a more professional environment again, working on GUPU and SICStus Prolog to spread modern Prolog features among researchers and students. I am still interested in the SSL bindings of SWI-Prolog, and parts of the web infrastructure.

Regarding your question about CLP(FD): Yes, SICStus ships with one of the most advanced and feature-rich CLP(FD) systems, which is available as library(clpfd). Still, there are a few features that are currently unique to CLP(Z):

  • arbitrary size integers in all constraints
  • always terminating propagation
  • monotonic execution mode
  • 100% Prolog implementation, which has several advantages:
    • Concise implementation that can be easily studied and modified.
    • No more segmentation violations and low-level crashes.
    • Portability to systems with a similarly general interface for attributed variables.
    • Advertises Prolog as an implementation language for constraint solvers.

Eventually, CLP(Z) will likely fall back to SICStus-specific CLP(FD) predicates in cases where it is safe.

@triska I see, thank you for the detailed answer.

I would gladly accept a SICStus license, though I am not sure my “toy contributions” make me deserve it!

As for porting Prolog code from SWI-Prolog to SICStus, I assume not much work is required? I recall that some parts of SWI-Prolog are not ISO-compliant while SICStus seems to be, but aside from those details (and from SWI-specific built-in names) I assume most code would work as is?

Perfect! I highly recommend trying SICStus to gather more experience also with porting Prolog applications, and to deepen your Prolog knowledge. As an additional benefit, making Brachylog more portable will enable new usage opportunities and possibly new features.

Most code will probably work as is, but you should use the opportunity to switch to double_quotes set to chars, which will make working with "strings" easier and more portable.

You can download a free evaluation version of SICStus any time. Once you order it, please send me the bill or account number to transfer the money to SICStus so you get your personal permanent copy. To me, it is a good investment: I am looking forward to working with you on CLP(Z) and possibly other SICStus-based projects in the future. And even if that does not happen, it is definitely worth a try since you are helping to make Prolog more popular already with your current work on Brachylog! It's great that you are modest about this, but look at it this way: Without your work, Prolog would not appear at all on Code Golf!

@triska I have downloaded the evaluation version, I will try it out in the next few days/weeks! Though I am a bit hesitant about making you pay that much money from your own pockets in the event that I would want to keep using SICStus; I might just buy it myself.

One quick question that I immediatly have though (one thing I will say about SICStus is that the documentation seems much harder to navigate than SWI-Prolog's site...): why does SICStus REPL wait for user input after a query such as this:

| ?- X = 3.
X = 3 ? 
yes

I can type ; and get a no (though I also have to press enter which is a bit annoying), which makes sense. But it doesn't make any sense that it would even ask me anything, there is obviously no choice point! I don't get any choice point for e.g. member(3, [1,2,3]) so I don't get it.

What am I not understanding here?

Great, take your time to explore SICStus! My offer of course stands, so please let me know and accept the license as a small gift and sign of my appreciation for your contributions to the Prolog community.

Regarding the documentation, SICStus has the way cooler way to navigate: In /doc/info/, the documentation is available as info files! If you open sicstus.info-1 in Emacs and do:

M-x Info-on-current-buffer RET

then you can browse and search it it extremely conveniently within Emacs!

Regarding the toplevel, I wonder that too! Maybe time to test the support channels of SICStus, or better yet, use call_cleanup/2 to detect the determinism and start writing a more convenient toplevel for SICStus that would soon become extremely popular!

commented

@JCumin: w.r.t. SICStus REPL: SICStus uses the more traditional way of interaction, however, one of the main advantages is that new variables are named systematically:

| ?- length(L,3).
L = [_A,_B,_C] ? 

vs. in SWI

?- length(L,3).
L = [_6214, _6220, _6226].

When working with constraints, you will see a lot such variables, so a more compact representation is an advantage.

@UWN I still don't understand why there is a discrepancy between X = 3. and member(3, [1,2,3]).. If one does not ask for any user input after execution I don't see why the other would.

commented

@JCumin: SWI-toplevel detects if a CP is still open. Same can be done with call_cleanup/2. I would love to have a nice new toplevel for SICStus - with false, and nice constraint display. See my SO profile for how the output should look like.