Thanks. I had this one in my to-read list but lost it. But I don’t think this would help in too general programs.
Unfortunatelly I don’t remember the real example of the issue from the last time I came across this, so this is just an artifficialy created problem to show the point.
The naïve way to define list’s lenght could be like this, which is borrowed from Learn Prolog Now!:
len([],0).
len([_|T],N) :- len(T,X), N is X+1.
It just works, terminates where it should and doesn’t terminate where it shouldn’t and give all the right answers.
Let’s pretend that there is some strange reason, why somebody makes a mistake and write another list/length predicate like this:
len2([],0).
len2([_|T],N) :- len(T,X), (N is X+1; N is X + 2, N = 10000).
All the standard testing doesn’t reveal the mistake because it works just like len/2 except when it stumbles upon a list of length exactly 9999 elements where there are two possible answers. So this predicate is “successfully” tested and after that used in some complex program, where the mistake reveals one day on completely other part of the program with some strange answer from some other predicate.
Now there are several options what to do when there is a mistake discovered.
I can use trace and most of the time switch from declarative world to just procedural to locate this mistake.
I can use failure-slicing if I think there is some non-termination which shouldn’t be. But this is not the case with this example. It terminates where it should be and it doesn’t where it shouldn’t.
I can use declarative debugging - commenting out some of the goals. But this helps with programs which are too specific by making them more general to help locate the mistake.
But I don’t know what method to use (except of trace) to locate the mistake when the program terminates properly, gives all the right answers so it isn’t too specific, but it gives a little bit more answers than would expected, so it is just too general.
And it is not about this exact example, but about overal methodology in cases like this.