# In the ugraphs library the vertices builtin seems strange

**URL:** <https://swi-prolog.discourse.group/t/in-the-ugraphs-library-the-vertices-builtin-seems-strange/9016>\
**Category:** General\
**Created:** [May 17, 2025, 8:23pm UTC](https://swi-prolog.discourse.group/t/in-the-ugraphs-library-the-vertices-builtin-seems-strange/9016 "2025-05-17T20:23:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![feraudy](https://avatars.discourse-cdn.com/v4/letter/f/eb8c5e/32.png) [@feraudy](https://swi-prolog.discourse.group/u/feraudy)\
**Post date:** [May 17, 2025, 8:23pm UTC](https://swi-prolog.discourse.group/t/in-the-ugraphs-library-the-vertices-builtin-seems-strange/9016/1 "2025-05-17T20:23:30Z")

</div>

Consider this:  
?- use\_module(library(ugraphs)).  
true.

?- vertices([1-[3,4]],L).  
L = [1].

I would have expected L to be unified with [1,3,4].  
Are I missing something?

---

<div class="post-metadata">

**Author:** ![feraudy](https://avatars.discourse-cdn.com/v4/letter/f/eb8c5e/32.png) [@feraudy](https://swi-prolog.discourse.group/u/feraudy)\
**Post date:** [May 17, 2025, 8:44pm UTC](https://swi-prolog.discourse.group/t/in-the-ugraphs-library-the-vertices-builtin-seems-strange/9016/2 "2025-05-17T20:44:06Z")

</div>

OK, I am going to answer my own question:  
If I wanted to indicate that 3 and 4 were vertices I should have added the following elements to the first argument of vertices: 3-, 4-.  
The predicate vertices does not check that the list is a “complete” representation of the Ugraph.

---

<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:** [May 18, 2025, 11:54am UTC](https://swi-prolog.discourse.group/t/in-the-ugraphs-library-the-vertices-builtin-seems-strange/9016/3 "2025-05-18T11:54:01Z")

</div>

> [@feraudy](#):
>
> Are I missing something?

Are you aware of Adjacency List?

> **[Adjacency list](https://en.wikipedia.org/wiki/Adjacency_list)**
>
> In graph theory and computer science, an adjacency list is a collection of unordered lists used to represent a finite graph. Each unordered list within an adjacency list describes the set of neighbors of a particular vertex in the graph. This is one of several commonly used representations of graphs for use in computer programs.
> An adjacency list representation for a graph associates each vertex in the graph with the collection of its neighbouring vertices or edges. There are many variations of ...

---

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [May 19, 2025, 9:54am UTC](https://swi-prolog.discourse.group/t/in-the-ugraphs-library-the-vertices-builtin-seems-strange/9016/4 "2025-05-19T09:54:18Z")

</div>

I choose to think that OP is aware of adjacency lists; in fact, they correctly identified that the real issue is that the vertices/2 predicate does not check if the first argument is a proper graph. Just for posterity @feraudy, in practice I have discovered that it is easier to only provide edges instead of a well-formed ugraph, like this:

```prolog
?- vertices_edges_to_ugraph([], [1-3, 1-4], G),
   vertices(G, V).
G = [1-[3, 4], 3-[], 4-[]],
V = [1, 3, 4].

```

As you can see you can leave the “vertices” argument empty and only provide a list of edges. If you don’t have non-connected vertices, of course 😅
