trueagi-io / hyperon-experimental

OpenCog Hyperon experimental version
https://wiki.opencog.org/w/Hyperon
MIT License
122 stars 43 forks source link

New standard lib operations: union, intersection, subtraction, and unique #698

Closed Adam-Vandervorst closed 1 month ago

Adam-Vandervorst commented 1 month ago

I had to implement a MultiTrie key conversion for grounded types for this to be of any use. I chose the default hasher, this is not the best choice, but it's asymptotically correct for HE's internal representation.

> !(unique (superpose (a a b a)))
[a, b]

> !(subtraction (superpose (a b b c)) (superpose (b c c d)))
[a, b]

> !(intersection (superpose (a b c c)) (superpose (b c c c d)))
[b, c, c]

> !(union (superpose (a b b c)) (superpose (b c c d)))
[a, b, b, c, b, c, c, d]
Adam-Vandervorst commented 1 month ago

@vsbogd thanks for your changes!

For example UniqueOp could have the following implementation:

I believe we should have a similar implementation between unique, collapse, union, etc., so I propose we merge this with the interpret_no_error and redo the "chain evaluation" for these ops in another PR.