trueagi-io / hyperon-experimental

MeTTa programming language implementation
https://metta-lang.dev
MIT License
151 stars 49 forks source link

Question about duplication semantics #798

Closed nasser closed 1 week ago

nasser commented 1 week ago

What are the semantics of "duplicate" assertions? If I assert e.g. (is ball red) multiple times I get multiple results when I match on it, which indicates that the individual atoms are not "interned" or deduplicated in any way -- they are fully distinct. But when I remove-atom just once, they all disappear, which would indicate a kind of interning/deduplication.

(is ball red)
(is ball red)
(is ball red)
(is ball red)
(is ball red)

! (match &self (is ball $color) $color)

! (remove-atom &self (is ball red))

! (match &self (is ball $color) $color)
[red, red, red, red, red]
[()]
[]

Can you clarify what is happening?

vsbogd commented 1 week ago

Currently MeTTa doesn't specify this behavior, and it is implementation specific. Other implementation of the space can have different behaviour. As far as I know nobody relies on the current behavior of the default in-memory atomspace in hyperon-experimental. I agree it doesn't look very uniform, but on the other hand it allows doing manual deduplication easily.

I raised #799 to change it to more uniform. If @Necr0x0Der agree we can change this behavior. But I would like to emphasize one more time - you cannot rely on this.

nasser commented 1 week ago

understood -- thank you!

Necr0x0Der commented 1 week ago

Allowing duplicated atoms was supposed as a feature, because there were some use cases for PLN, when one needs to count the number of observed atoms to infer truth values. However, since MeTTa started to be used in more ways, it seems that absence of deduplication became more frequently a nuisance rather than a feature (and when one wants to count the same atoms, it can be done manually). OTOH, duplication can also be useful for probabilistic programming to control probabilities of sampling... Thus, I agree with @vsbogd that we still don't have a firm opinion and specification of this behavior, and it may change. In any case, it is indeed space-specific. I also agree that with duplication, it would be more convenient for remove-atom to remove only one atom.

vsbogd commented 1 week ago

Closing it, @nasser please feel free to reopen if you have further questions on this.