In the ugraphs library the vertices builtin seems strange

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?

1 Like

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.

1 Like

Are you aware of Adjacency List?

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:

?- 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 :sweat_smile: