This issue involves implementing the subtraction function in MeTTa, which should take non-deterministic results from two lists and return the elements of the first list that are not present in the second. The goal is to handle lists of various types, including numbers, symbols, nested structures, and mixed types, while ensuring correct behavior across all scenarios.
Task Description
Implement the subtraction Function:
The subtraction function should take two non-deterministic inputs, evaluate their difference, and return a non-deterministic output containing only the elements present in the first list but not in the second.
A new file named subtraction_test.metta should be added to the tests/baseline_compat/hyperon-mettalog_sanity directory.
Include the Following Test Cases:
;; Test basic subtraction functionality
;; This checks that the subtraction of (a b c c) from (b c c c d) is correctly evaluated as (a).
!(assertEqual
(subtraction (superpose (a b c c)) (superpose (b c c c d)))
(superpose (a))
)
;; Test subtraction with `unique` applied outside
;; Here, `unique` is applied after the subtraction, ensuring duplicates are removed, resulting in (a).
!(assertEqual
(unique (subtraction (superpose (a a b c)) (superpose (b c c d))))
(superpose (a))
)
;; Test subtraction with `unique` applied inside
;; In this test, `unique` is applied to each input set before performing the subtraction, also resulting in (a).
!(assertEqual
(subtraction (unique (superpose (a a b c))) (unique (superpose (b c c d))))
(superpose (a))
)
;; Test equivalence of applying `unique` inside and outside of subtraction
;; This ensures that applying `unique` either inside or outside of the subtraction yields the same result.
!(assertEqual
(unique (subtraction (superpose (a a b c)) (superpose (b c c d))))
(subtraction (unique (superpose (a a b c))) (unique (superpose (b c c d))))
)
Run and Verify:
Once the test cases are in place, ensure they run correctly within the MeTTa test suite.
Expected Outcome
The subtraction function should correctly handle non-deterministic input, returning non-deterministic results that represent the difference between the provided lists. The function should work correctly with lists of varying types, including duplicates, symbols, nested lists, and mixed types. The tests should confirm that the function behaves as expected across these scenarios, ensuring consistency with MeTTa's non-deterministic evaluation principles.
This issue involves implementing the
subtraction
function in MeTTa, which should take non-deterministic results from two lists and return the elements of the first list that are not present in the second. The goal is to handle lists of various types, including numbers, symbols, nested structures, and mixed types, while ensuring correct behavior across all scenarios.Task Description
Implement the
subtraction
Function:subtraction
function should take two non-deterministic inputs, evaluate their difference, and return a non-deterministic output containing only the elements present in the first list but not in the second.Example behavior:
Create the Test File:
subtraction_test.metta
should be added to thetests/baseline_compat/hyperon-mettalog_sanity
directory.Include the Following Test Cases:
Run and Verify:
Expected Outcome
The
subtraction
function should correctly handle non-deterministic input, returning non-deterministic results that represent the difference between the provided lists. The function should work correctly with lists of varying types, including duplicates, symbols, nested lists, and mixed types. The tests should confirm that the function behaves as expected across these scenarios, ensuring consistency with MeTTa's non-deterministic evaluation principles.