Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to launch a subset query? #165

Open
sunriseXu opened this issue Sep 2, 2021 · 1 comment
Open

how to launch a subset query? #165

sunriseXu opened this issue Sep 2, 2021 · 1 comment

Comments

@sunriseXu
Copy link

sunriseXu commented Sep 2, 2021

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!

@EvgSkv
Copy link
Owner

EvgSkv commented Sep 3, 2021

Hello!

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]);

Let me know if you have further questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants