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

Recursion sub-graph with Aggregates in the Body #62

Open
stephanzwicknagl opened this issue Mar 1, 2024 · 0 comments
Open

Recursion sub-graph with Aggregates in the Body #62

stephanzwicknagl opened this issue Mar 1, 2024 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Milestone

Comments

@stephanzwicknagl
Copy link
Collaborator

stephanzwicknagl commented Mar 1, 2024

How to deal with recursive sub-graphs of rules with aggregates in the body?

Recursion sub-graphs are generated at transformations that have positive recursion, meaning that a rule's dependent also occurs in a non-negated literal in the body of the rule (or an equivalent dependency of multiple rules of a component).

Positive recursion is recognized by using the positive-dependency graph. It is equivalent to the normal dependency graph in the way that it connects dependents and conditions of rules. It only uses conditions that positive conditions to build the graph. A recursion is found if there is a loop or strongly connected component of in the positive-dependency graph.

Positive conditions literals in the body of a rule that are non-negated and do not occur inside an aggregate. The latter is due to the more complex process of determining a condition being positive or negative in combination with aggregates (see below). For a simple, correct solution, the child literals of aggregates in the body of the rule should not be considered positive conditions.

Example without recursion

reached(V) :- reached(U), hc(U,V), not start(V).
  • reached/1 is a dependent of the rule
  • reached/1 is a condition and a positive condition of the rule
  • hc/2 is a condition and a positive condition of the rule
  • start/1 is a condition, but not a positive condition of the rule

The positive-dependency graph contains a loop at this rule due to the positive condition reached/1.

The corresponding recursion justification program for building the sub-graph:

#program iterate(n).
h(n, reached(V), (reached(U), hc(U,V))) :- model(reached(U)), model(hc(U,V)), not model(start(V)), not model(reached(V)).
model(@new()).

Example with recursion 1

reached(V) :- reached(U), 0 < #count{1,U,V: hc(U,V) }.
  • reached/1 is a dependent of the rule
  • reached/1 is a condition and a positive condition of the rule
  • hc/2 is a condition, but not a positive condition of the rule
  • start/1 is a condition, but not a positive condition of the rule

The positive-dependency graph does contain a loop.

The corresponding recursion justification program for building the sub-graph:

#program iterate(n).
h(n, reached(V), (reached(U), hc(U,V))) :- model(reached(U)), 0 < #count{1,U,V: model(hc(U,V))}, not model(reached(V)).
model(@new()).

Example with recursion 2

reached(V) :- 0 < #count{1,U: reached(U)}, hc(U,V), not start(V).
  • reached/1 is a dependent of the rule
  • reached/1 is a condition, but not a positive condition of the rule
  • hc/2 is a condition and a positive condition of the rule
  • start/1 is a condition, but not a positive condition of the rule

The positive-dependency graph does not contain a loop and a sub-graph should not be generated.

Determining positive or negative condition in aggregate

Take for example the rule
a(X) :- b(X), X<=#sum{Y:a(Y)}.

Here, it is not clear whether a positive condition exists with a/1. A positive condition exists for positive numbers Y in a(Y), but a negative condition exists for negative numbers.

How to find out if a literal in an aggregate is a positive condition?

@stephanzwicknagl stephanzwicknagl added documentation Improvements or additions to documentation enhancement New feature or request labels Mar 1, 2024
@stephanzwicknagl stephanzwicknagl self-assigned this Mar 1, 2024
stephanzwicknagl added a commit that referenced this issue Mar 2, 2024
Literals are now added to the positive conditions in the transformer's
visiting process, not later. This way, we know the context of the
literals.

Literals in the body of a rule are only added to the positive conditions
if they are non-negated and do not occur inside an aggregate.

In the reification step, nothing changes, but datatypes are fixed
to work with the tuple of conditions and positive conditions.

Mpve the transformation of intervals to a separate function, as it is
needed at multiple places. Also, it is fixed to work for ShowTerm
statements where the dependent needs to be wrapped in a Symbolic Atom
and Literal first, before checking for intervals.

Removing the visiting of body elements, as it is not necessary anymore.

Contributes: #62
stephanzwicknagl added a commit that referenced this issue Mar 2, 2024
@stephanzwicknagl stephanzwicknagl added documentation Improvements or additions to documentation and removed documentation Improvements or additions to documentation labels Mar 2, 2024
stephanzwicknagl added a commit that referenced this issue Mar 2, 2024
The main change in this commit is the clarification of how viasp deals
with recursive sub-graphs of rules that contain aggregates. This is
described in issue #62.

Refactoring of the justifier program creation. It uses the transformer
architecture to generate justifier rules from more comples rules, e.g.
ones containing aggregates. The wrapping in `model` literals is also
managed in a new transformer.

Fixes to the analyzer and reifier to support collection of positive
conditions. They are now collected in the transformer's visiting
process. This way, we know the context of each literal (e.g. in
aggregate, negated, etc.).

Contributes: #62
stephanzwicknagl added a commit that referenced this issue Mar 2, 2024
@javier-romero javier-romero self-assigned this Jun 25, 2024
@stephanzwicknagl stephanzwicknagl added this to the Up Next milestone Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants