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
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()).
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?
The text was updated successfully, but these errors were encountered:
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
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
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/1
is a dependent of the rulereached/1
is a condition and a positive condition of the rulehc/2
is a condition and a positive condition of the rulestart/1
is a condition, but not a positive condition of the ruleThe 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:
Example with recursion 1
reached/1
is a dependent of the rulereached/1
is a condition and a positive condition of the rulehc/2
is a condition, but not a positive condition of the rulestart/1
is a condition, but not a positive condition of the ruleThe positive-dependency graph does contain a loop.
The corresponding recursion justification program for building the sub-graph:
Example with recursion 2
reached/1
is a dependent of the rulereached/1
is a condition, but not a positive condition of the rulehc/2
is a condition and a positive condition of the rulestart/1
is a condition, but not a positive condition of the ruleThe 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 numbersY
ina(Y)
, but a negative condition exists for negative numbers.How to find out if a literal in an aggregate is a positive condition?
The text was updated successfully, but these errors were encountered: