4 ms·
I'm not sure you can avoid the dependency on the rules order, and having to understand how the Prolog engine works. But I found there is a rather intuitive way
by yaantc 14y ago
I'm not sure you can avoid the dependency on the rules order, and having to understand how the Prolog engine works. But I found there is a rather intuitive way to deal with it: think of the Prolog engine as searching a space of possibilities for a goal (expressed by the rules). Then you must order the rules to narrow the search space as quickly as possible. In other words, try to make the first rules as selective as possible to quickly reduce the search space.
That's how you can get fast Prolog programs. But you have to be careful. It's been a long time since I played with Prolog, but I remember a case where reordering two lines would make the solution reached below 1 second from over 15 minutes. That kind of thing is part of the charm and frustration of Prolog. It can be a nice brain teaser.
- fusiongyro 14y agoI like to think of Prolog as an "intellectual diversion."