Hi Will!
The `split` relation in the code you linked (llmr.scm) is a very similar relation on the domain of multisets. Thank you for sharing!
Regarding another use of `riffleo`: I have been trying to transform an undirected graph into a sequence of nonoverlapping bicliques (complete bipartite subgraphs). This is always possible, since every graph has a maximum independent edge set (which can be thought of as (1, 1)-bicliques). This decomposition into bicliques has an application in graph coloring.
I have found `riffleo` useful for partitioning the vertices of the graph into 3 sets: `left`, `right`, and `rest-v`. Then I can check if there is an edge from every vertex in `left` to every vertex in `right`. Here is the code for that. Hopefully the implicit relations make sense.
(defrel (bicliqueso graph bicliques)
(conde
((== bicliques '()) (empty-grapho graph))
((fresh (v e rest-v rest-e rest-g rest-bicliques left right*rest-v right)
;; A biclique is a pair of vertex sets
(== bicliques `((,left . ,right) . ,rest-bicliques))
(pairo left)
(pairo right)
;; Assume an efficient undirected graph data structure
(verticeso g v)
(verticeso rest-g rest-v)
(edgeso g e)
(edgeso rest-g rest-e)
;; partition the vertices into nonempty `left`, nonempty `right`, and `rest-v`
(riffleo left right*rest-v v)
(riffleo right rest-v right*rest-v)
;; check that every vertex in `left` is connected to every vertex in `right`
(is-bicliqueo left right g)
;; Keep only the edges which have both vertices in `rest-v`
(filtero e rest-v rest-e)
(bicliqueso rest-g rest-bicliques)))))
This ended up being unfeasible since I could not think of a good data structure for representing an undirected graph in miniKanren, and I found it difficult to write `is-bicliqueo`. I ended up porting `riffleo` into Python as `unriffle`.
def unriffle(o: List[T]) -> Iterator[Tuple[List[T], List[T]]:
...
I used that for a while in Python until I figured out a bottom-up way to find all bicliques by constructing a table all_bicliques_of_size[m][n].
TL;DR - `riffleo` can be used to partition a set into n disjoint subsets, which may be useful for detecting bicliques.
Brett