Surely you can achieve that after source transformation. A brief investigation shows that indexing the above for the default first argument indexing which is used for predicates with not many clauses and called with an instantiated first argument is probably not too hard.