In Souffle datalog you could use the choice construct:
.decl items(x:symbol, y:symbol)
items("a","b").
items("a","c").
items("b","b").
// choice-domain is key here:
// - couples of (x,y) must be unique
// - seq must be unique
.decl items_with_seq(x:symbol, y:symbol, seq:number) choice-domain (x,y),seq
.output items_with_seq()
.decl items_size(n:number)
items_size(n) :-
n = count: {items(_,_)}.
items_with_seq(x,y,seq) :-
items(x,y),
items_size(n),
seq = range(0,n).
Outputs:
---------------
items_with_seq
x y seq
===============
a b 0
a c 1
b b 2
===============
Alternatively if you only need unique identifiers instead of sequence numbers:
items("a","b").
items("a","c").
items("b","b").
.decl items_with_seq(x:symbol, y:symbol, seq:number) choice-domain (x,y)
.output items_with_seq()
items_with_seq(x,y,autoinc()) :-
items(x,y).