You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We need to check membership in the second list for each element in the first list.
Here is the implementation and a test:
@Engine("sqlite");
# Returns 1 if a is subset of b and 0 otherwise.
# To call as a predicate call Constraint(Subset(a, b)).
Subset(a, b) = result :-
result_or_null Min= (e in b :- e in a),
result == Coalesce(result_or_null, 1);
# Testing Subset function.
Test(a, b, Subset(a, b)) :-
(a == [], b == [1,2]) |
(a == [1,2], b == [1,2,3]) |
(a == [1,2,3], b == [1,2]);
hi, do logica have subset function? I want to compare one set to another, and return a boolean value showing whether the two sets are equal or subset?
eg:
SUBSET({ }, { }) = TRUE
SUBSET({ 1, 2, 3 }, { }) = TRUE
SUBSET({ 1, 2 }, { 1, 2 }) = TRUE
SUBSET({ 1, 2, 3 }, { 1, 2 }) = TRUE
SUBSET({ 1, 3, 5 }, { 1, 2 }) = FALSE
many thanks!
The text was updated successfully, but these errors were encountered: