I’m using: SWI-Prolog version 8.0.3 for x64-win64
Suppose I want Prolog to automatically reorder (some) goals according to a set of rules, such as in an attempt to optimize code. Where would I start? I suspect that altering the source code for SWI-Prolog might yield more efficient results, but also be rather harder, and more likely to break things. Vs, I suspect there’s some predicate or other you could wrap a chunk of code in, which could list variables / reorder goals / selectively evaluate sub-expressions / etc. I don’t know what questions to ask, if the former is the way to go, but if the latter is the way to go, I suspect I’d need predicates to do things such as the following:
- List variables
- Check for choice points
- Evaluate an expression by one step (i.e., replace a predicate’s head with its body, but leave the body untouched, for further examination)
- Check for (and deconstruct) and/or (it looks like
(X,Y) = Expressionand(X;Y) = Expressionmight suffice) - Deconstruct a CLP FD/R/Q expression (they seem more complicated than combinations of and/or)
- Reorder an expression (maybe can be derived from #4)
- Maybe detect order-dependent operations, like cut?
Any help on any of these, or tips in general? (Or, if messing around with SWI-Prolog’s source is likely to be vastly faster, any hints on where to start with that?)