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

WIP: Optimize negation (depends on stratified-aggregation) #38

Merged
merged 15 commits into from
Dec 14, 2023

Conversation

guillembartrina
Copy link
Collaborator

@guillembartrina guillembartrina commented Nov 7, 2023

This PR attempts to optimize the current implementation of stratified negation in carac.

The current implementation is extremely simple but also very wasteful: it keeps the set of all constants appearing anywhere in a fact or a rule; just before performing the n-way join to solve a rule, it computes the "virtual" relation corresponding to the negated atom by constructing a relation containing all possible combinations of constants of length equal to the arity of the negated atom and subtracting the relation from it. Note that this is a source of combinatorial explosion, and often most of the combinations of constants do not even make sense, since they come from other relations.

The optimized version gets rid of the global set of constants and instead of building a relation containing all possible combinations of constants of length the arity of the negated atom, first collects the constants that can appear in each of the arguments by performing a corresponding column intersection of the other relations in the rule that share a variable (at least there is one because the variables appearing in the negated atoms must be guarded), and then builds the relation containing all possible combinations of these collected constants. In this way, it only creates the combinations that "make sense".

For the general use case, the optimization may not be extremely noticeable but it is definitely no worse than the current implementation and also makes some now intractable problems tractable.

In addition, (almost) as a consequence of the new design, this PR also solves the case where we have anonymous variables appearing in negated atoms, which was not handled until now.

@guillembartrina guillembartrina changed the title WIP: Optimize negation WIP: Optimize negation (depends on stratified-aggregation) Nov 7, 2023
@aherlihy aherlihy changed the base branch from main to neg-and-agg December 14, 2023 09:25
@aherlihy aherlihy marked this pull request as ready for review December 14, 2023 09:26
@aherlihy aherlihy merged commit 59f7e69 into aherlihy:neg-and-agg Dec 14, 2023
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants