4 ms·
It doesn't scale that well because integers are their own, opaque thing in Prolog, and the is predicate is unidirectional. However, there's no inherent reason t
by wizzwizz4 2y ago
It doesn't scale that well because integers are their own, opaque thing in Prolog, and the is predicate is unidirectional. However, there's no inherent reason this has to be the case: you can construct your own representation of the integers from the Peano axioms, and recover bidirectionality of addition. (You'll want to be using some typed variant of Prolog with the "unary tree of units" optimisation, otherwise integers take O(n) space in memory, but it's possible in the language.) Prolog works how it does, because it's (mostly) backwards-compatible with a facts database used for symbolic AI research, where all atoms were opaque.
- lmkg 2y agoCheck out the CLP(ℤ) library by Markus Triska, who is also the author of Scryer Prolog. It defines new comparison predicates that lets you use bidirectional logical programming on standard integers with standard math operations. https://github.com/triska/clpz https://github.com/triska/clpz
- dsabanin 2y agoMarkus is not the author of Scryer Prolog, Mark Thom is.
- ahoka 2y ago“you can construct your own representation of the integers from the Peano axioms” This is how the Idris prelude defines nat, the type of natural numbers (with some magic making it actually fast). I think that’s very cool.
- rscho 2y agoThere are many ways to recover relational behaviour. Libs such as clp(fd) (superseded by clp(Z)), clp(BNR) and others.
- Avshalom 2y agoBNR notably works with real numbers and non linear constraints.
- coliveira 2y agoModern Prolog libraries have handled the issues of unidirectional integer predicates, so the old ways of handling numeric values is not relevant for most problems.
- jfmc 2y agoMany times the algorithm that you are implementing requires a precise data flow that is not reversible, so using traditional arithmetic (is/2) is better for catching errors. On the other hand CLP(FD) is not new at all (it is very popular for constraint programming).
- rscho 2y agoWhy would it be better for error handling? If you'll be using unidirectional flow only, then the point is moot. But using clp is arguably better IMO, allowing type and range checks while allowing relational execution.