# Beginner's quick chart of Prolog comparison predicates

**URL:** <https://swi-prolog.discourse.group/t/beginners-quick-chart-of-prolog-comparison-predicates/2069>\
**Category:** Nice to know\
**Created:** [March 26, 2020, 1:09pm UTC](https://swi-prolog.discourse.group/t/beginners-quick-chart-of-prolog-comparison-predicates/2069 "2020-03-26T13:09:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dtonhofer](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/dtonhofer/32/902_2.png) [@dtonhofer](https://swi-prolog.discourse.group/u/dtonhofer)\
**Post date:** [March 26, 2020, 1:09pm UTC](https://swi-prolog.discourse.group/t/beginners-quick-chart-of-prolog-comparison-predicates/2069/1 "2020-03-26T13:09:36Z")

</div>

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](https://bit.ly/2Jk4e2o_prolog)

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

With best regards,

– David

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [March 26, 2020, 1:30pm UTC](https://swi-prolog.discourse.group/t/beginners-quick-chart-of-prolog-comparison-predicates/2069/2 "2020-03-26T13:30:01Z")

</div>

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](https://www.google.com/search?q=prolog+double+negation&oq=prolog+double+negation&aqs=chrome..69i57.6599j0j7&sourceid=chrome&ie=UTF-8)) instead of `\+ \+` ([results](https://www.google.com/search?q=%5C%2B+%5C%2B&oq=%5C%2B+%5C%2B&aqs=chrome..69i57j0j46j0l5.5727j0j8&sourceid=chrome&ie=UTF-8)). It was only a few months ago that I really started to [understand](https://occasionallycogent.com/prolog_fundamentals_catchup/index.html) why it is so important. 🙂

* * *

**EDIT**

For

```prolog
-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](http://eu.swi-prolog.org/pldoc/man?section=preddesc).

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [March 26, 2020, 1:44pm UTC](https://swi-prolog.discourse.group/t/beginners-quick-chart-of-prolog-comparison-predicates/2069/3 "2020-03-26T13:44:43Z")

</div>

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](https://www.swi-prolog.org/pldoc/doc_for?object=terms%3Asubsumes_chk/2)
- SWI-Prolog has same\_term/2 as well

Hope I now got all of them …

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [March 29, 2020, 1:52pm UTC](https://swi-prolog.discourse.group/t/beginners-quick-chart-of-prolog-comparison-predicates/2069/4 "2020-03-29T13:52:21Z")

</div>

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](https://www.swi-prolog.org/pldoc/man?predicate=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. 🙂

---

<div class="post-metadata">

**Author:** ![dtonhofer](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/dtonhofer/32/902_2.png) [@dtonhofer](https://swi-prolog.discourse.group/u/dtonhofer)\
**Post date:** [April 5, 2020, 9:25am UTC](https://swi-prolog.discourse.group/t/beginners-quick-chart-of-prolog-comparison-predicates/2069/5 "2020-04-05T09:25:17Z")

</div>

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