Some sparse Prolog code I wrote (and sometime used)