0

I normally construct my search tree by following the common convention:

  • Place Queries or Goals in need of unification inside node boxes.
  • Write down decision points on the edges, where Prolog has assigned an element to a variable.
  • Leaf nodes which are fully satisifed will be an empty box, they represent a solution.
  • Leaf nodes which can not be satisifed and represent failed attempts will have the unfulfilled goal in their box, to make them even more clear I also follow the convention of marking them by placeing a cross symbol below them.

The above way has the nice side effect that it's easy to see the decision points. But what about creating a search tree for something like:

accLen([_|T],A,L)  :-    Anew  is  A+1,  accLen(T,Anew,L).
accLen([],A,A). 

How should the assignment of Anew be represented in the search tree? It's not a decision point, the code has no other option then assigning it 1 plus the current value of A. Do you still place it on the edge, but underline it or something?

0

In my view, an is predicate is not much different from an explicit unification via = or an implicit one via matching of a clause to the input: it causes a variable to be bound. It doesn't leave the interpreter any less choice than X = 3 does, it's just a bit cleverer about how to retrieve the one possible value that must be assigned.

The only thing that is different is that the is cannot succeed until the right hand side is instantiated. If you want to represent this limitation, then you need some special representation, but otherwise I would treat = and is the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.