# Add alpha-unique-atom: Alpha-Equivalence Deduplication Function#151
Merged
Conversation
… alpha-equivalence deduplication Covers basic duplicates, different functors, nested structures, mixed unique/duplicates, numbers, atoms, empty and single-element lists
Introduced alpha-unique-atom/2 predicate to remove duplicates from a list using alpha-equivalence (=@=/2), preserving order and first occurrence Added supporting predicates for alpha-equivalent set construction Registered alpha-unique-atom as a MeTTa function
patham9
approved these changes
Apr 2, 2026
Collaborator
patham9
left a comment
There was a problem hiding this comment.
Well-done and well-tested! Thank you so much!!
Collaborator
|
While i agree that this is an important function. I would generally prefer such things to be implemented in MeTTa directly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new built-in function,
alpha-unique-atom, to the PeTTa language. Unlike the existingunique-atom, which only removes syntactically identical atoms,alpha-unique-atomdeduplicates atoms using alpha-equivalence (structural equality with variable renaming). This ensures that atoms differing only by variable names are treated as duplicates and only one representative is kept.Problem and reproduction
The current
unique-atomfunction in PeTTa does not consider alpha-equivalence, leading to unexpected duplicates when atoms differ only by variable names. This causes issues in symbolic reasoning and pattern mining tasks, where structurally identical atoms should be considered equal.Example:
Input:
Observed (incorrect) output with unique-atom:
Expected output with alpha-unique-atom:
Root cause
unique-atomonly checks for syntactic equality, not structural (alpha) equivalence. As a result, atoms that are structurally identical but use different variable names are not deduplicated.What I changed
alpha-unique-atomas a new built-in, implemented in Prolog and registered in the PeTTa core.=@=) to compare atoms, ensuring alpha-equivalent atoms are deduplicated.Why this fix
Alpha-equivalence is the correct equality notion for deduplication in symbolic reasoning: two atoms that only differ by the names of their variables are treated as the same pattern, while distinct syntactic patterns are preserved.
Testing & validation
A comprehensive test suite is included, covering:
Example test:
Impact
unique-atomfunction, preserving backward compatibility for projects relying on its current semantics.Related issues
Fixes unique-atom does not remove alpha-equivalent atoms#149