Meta domain predicates and addons #469
Replies: 2 comments 3 replies
-
This are actually things I already thought about. The reason why there is no I also thought about sorting. On way to sort in ASP is writing:
My idea was to introduce an aggregate that has the same meaning as the body of the rule defining
If you want to apply it to the domain of a predicate, you would have to write something like
|
Beta Was this translation helpful? Give feedback.
-
I agree that it would be nice to have those features. For now, one hack that works for computing the domain of a predicate is the following. In the example:
just write
I think this even works with recursion. Then, to simplify the |
Beta Was this translation helpful? Give feedback.
-
Proposition Domain Predicate
I think it would be helpful to have a meta domain predicate.
Given the following program (example taken from here)
it can be sometimes hard and cumbersome to compute the domain of a predicate, e.g. the possible value combinations that are used in grounding. (A domain is always an over approximation of the values that actually occur in answer sets)
Computing the domain for
h/3
manually could look like:It would be much nicer to be able to access the information that is already stored in gringo directly with a construct like:
#domain(h/3, X,Y,Z)
so in a logic program you can write something like:Also the manual example shown could be wrong if the instance contains a fact like
h(1,2,3)
. In this case only the#domain
predicate would give the correct combinations.Limitations
Of course this new construct is not allowed to be derived and only to be used in the body and conditions.
Furthermore an error might be raised if it is used in a cyclic definition, although I'm not sure if this is strictly necessary (but could ease implementation):
Proposition Domain Ordering
While the domain predicate can be seen as an ease of life feature, the real advantage would come with additional features that can not be achieved with a manual translation (within the same complexity).
When using chaining rules, sometimes computing and ordering the domain can become the new bottleneck of computation. Given the following example from here
The domain order for the aggregate can be "manually" computed like this:
This is not very efficient and could be improved if the problem knowledge would state that the required domain is continuous. But in the worst case this grounding can be cubic. So it would be nice to have a meta
#order
predicate for the ordering.About the syntax I'm not yet sure, as this predicate needs a lot of information:
foo/2=foo(P,X)
I want an ordering forX
(position 1)foo
, e.g.P
Maybe one way to achieve this could be a syntax like:
(Prev, Next) = #order(foo,P,*)
This would allow for the following program to be written:
which should be superior to all other possibilities currently available for clingo to express this problem.
Limitations
*
should be used inside the predicate, although maybe ordering of tuples could be interesting ?#domain
predicate are in order, as it directly uses its functionalityBeta Was this translation helpful? Give feedback.
All reactions