# Subsumes\_term/2

**URL:** <https://swi-prolog.discourse.group/t/subsumes-term-2/2709>\
**Category:** Predicate\
**Created:** [July 27, 2020, 9:10pm UTC](https://swi-prolog.discourse.group/t/subsumes-term-2/2709 "2020-07-27T21:10:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [July 27, 2020, 9:10pm UTC](https://swi-prolog.discourse.group/t/subsumes-term-2/2709/1 "2020-07-27T21:10:51Z")

</div>

Dear @jan,

In the recent [commit](https://github.com/SWI-Prolog/swipl-devel/commit/18c7803ebb3023c642702b2e77027c5acb5c5698) to improve listing/1 you wrote a predicate to generalize a term, I was wondering why didn’t you use subsumes\_term/2? Perhaps I am missing something?

---

<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:** [July 27, 2020, 10:35pm UTC](https://swi-prolog.discourse.group/t/subsumes-term-2/2709/2 "2020-07-27T22:35:00Z")

</div>

Have you looked at my personal notes in this [post](https://swi-prolog.discourse.group/t/how-to-disable-specific-multifile-predicates-i-e-portray-cr-a/2703).

---

<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:** [July 28, 2020, 7:23am UTC](https://swi-prolog.discourse.group/t/subsumes-term-2/2709/3 "2020-07-28T07:23:05Z")

</div>

The reason was to fix the @EricGT example listing. Given some head, we should list all clauses that _unify_ with this head. So, the nice thing is that if you have a concrete goal (with some instantiated arguments) and you ask for listing of that goal you only get the matching clauses. We should however not _instantiate_ the clause head using the goal.

The current code generates all clauses and then does unification of the head using double negation to avoid instantiation of the head. Possibly it would have been better to use clause/3 with an instantiated head to get the clause reference and then clause/3 with an instantiated clause reference to get the raw clause. That does the decompilation twice, but exploits clause indexing if there are many clauses. Probably mostly theoretical as predicates that have rules typically have few clauses and predicates with many clauses typically only have facts and you typically just call the predicate to figure out which facts match.

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [July 28, 2020, 2:20pm UTC](https://swi-prolog.discourse.group/t/subsumes-term-2/2709/4 "2020-07-28T14:20:35Z")

</div>

> [@jan](#):
>
> So, the nice thing is that if you have a concrete goal (with some instantiated arguments) and you ask for listing of that goal you only get the matching clauses.

This is very useful, especially for large databases. Thanks!

---

<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:** [July 28, 2020, 2:52pm UTC](https://swi-prolog.discourse.group/t/subsumes-term-2/2709/5 "2020-07-28T14:52:17Z")

</div>

Care to add some details with examples and post it as one of

1. [Nice to know](https://swi-prolog.discourse.group/c/nice-to-know/17)
2. [Useful code](https://swi-prolog.discourse.group/c/useful-code/16)
3. [Wiki](https://swi-prolog.discourse.group/c/wiki/12)

---

<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:** [July 28, 2020, 7:41pm UTC](https://swi-prolog.discourse.group/t/subsumes-term-2/2709/7 "2020-07-28T19:41:14Z")

</div>

Split this topic on July 28, 2020, 7:41pm UTC

A post was split to a new topic: [Listing example](https://swi-prolog.discourse.group/t/listing-example/2712)
