The new release 8.3.19 of SWI-Prolog introduces single sided unification inside new Picat style rules. This could be a welcome addition to any Prolog system. I was wondering whether we could rewrite Quine algorithm
Prolog implementation of Quine's algorithm
https://\stackoverflow.com/q/63505466/502187
Picat style rules and whether this would work? If yes and if the writing of the Quine algorithm becomes simpler, then SWI-Prolog probably did a great favor to the community by this addition.
Any take on this challenge? SWI-Prolog 8.3.19 is already available from devel.
Whereas normal unification aka two sided unification is in intimate relationship with the builtin (=)/2, there is a similar relationship between pattern matching aka one sided unfication and the builtin (==)/2. These bootstrappings would work:
If we look at the code for Quine algorithm, the take from here, we find a lot of (==)/2 uses. A job that pattern matching could directly do:
So we gave it a try and converted all the rules into pattern matching. The initial var/1 guard is then not anymore needed, and so are the (==)/2 not anymore needed. But we observe that we need more (=)/2 to return function values:
We did a little benchmark and verified 193 propositional logic test cases from Principia. We tested both normal unification and pattern matching. We also compared with a not yet compiled variant of pattern matching, an expansion that uses subsumes/2:
First the expansion via subsumes/2, that doesn't compile pattern matching:
And now the new compiled pattern matching by SWI-Prolog:
I was expecting that the compiled approach shows a tick more bang and not only preservation of the performance of normal unification? But nevertheless this is a good start.
Open source:
Boole's Method from 1847, Prolog Style
https://gist.github.com/jburse/713b6ad2b7e28de89fe51b98be3d0943#file-boole-pl
Boole's Method from 1847, Picat Style
https://gist.github.com/jburse/713b6ad2b7e28de89fe51b98be3d0943#file-boole2-pl
Picat Expansion
https://gist.github.com/jburse/713b6ad2b7e28de89fe51b98be3d0943#file-picat-pl
193 propositional logic test cases from Principia
https://gist.github.com/jburse/713b6ad2b7e28de89fe51b98be3d0943#file-principia-pl