Beginner's quick chart of Prolog comparison predicates

I was continually confused with the Prolog comparison predicates, so I started a little page of notes on this (I’m less confused now). This is work in progress and will be updated as I dig through documentation and examples:

Link to page aliased to prolog_notes/prolog_comparison_predicates.md at master · dtonhofer/prolog_notes · GitHub

As the same questions and confusions continually pop up on Stack Overflow, this could be handy.

With best regards,

– David

2 Likes

It would be nice to see a column with the title Name for those that have names, e.g. \+ \+ as double negation. This way when people want to search for more info they can use the name (results) instead of \+ \+ (results). It was only a few months ago that I really started to understand why it is so important. :slightly_smiling_face:


EDIT

For

-Number is +Expr

When I first read this I thought it meant that that the left side had to be negative and the right had to be positive, then I realized that it was using Notation of Predicate Descriptions.

1 Like

Thanks for writing this up. You might want to maintain this on the wiki part of Discourse?
Some remarks.

  • \+ \+ X = Y can also be \+ X \= Y
  • There is nothing wrong with == and \==. They are used a lot comparing outputs from earlier steps that are known to be ground as well as for meta-analysis of Prolog terms (i.e., reasoning about variables).
  • You forgot the important standard order of terms, @>, etc. and compare/3.
  • You forget variant (=@=)
  • You forgot subsumption subsumes_chk/2
  • SWI-Prolog has same_term/2 as well

Hope I now got all of them …

2 Likes

Since you tied this into questions at StackOverflow and when is an understanding of comparison and unification needed, it occurred to me that this should also include unification of a goal and a head.

In particular are the StackOverflow questions of the type of Why is my predicate not be being called? which would be more correctly stated as Why is my clause of my predicate not being called?. Most of the time the answer is that the OP does not understand that they are not successfully unifying the goal with the head.

If you do choose to add a goal/head unification section, then also hashing for clause selection should be considered.


EDIT

Also need to add unify_with_occurs_check/2 I know there are references in the document, but IMHO it rates more than a reference.

Feel free to ignore. :slightly_smiling_face:

1 Like

Thank you all for the responses. I will update and be back.