potassco / clingo

🤔 A grounder and solver for logic programs.
https://potassco.org/clingo
MIT License
606 stars 81 forks source link

Is it possible to maintain order of literals? #496

Closed ejgroene closed 4 months ago

ejgroene commented 5 months ago

The ASP rules, once thoroughly tested and formally verified in ASP, need to be translated to a simpler boolean logic. I do so by taking the ground form and rewriting that to this simple logic. That works.

However, there is quite a tactical advantage if the boolean expressions have their conditions in the order as they have been written in ASP.

I have created a matching algorithm that restores the order of ground body literals by matching them against the AST order. That works, except for conditional literals. For conditional literals the order is influenced by the order in which the domain fact are defined and other things, like the use of custom functions. I am afraid the order is likely an implementation detail.

Does anyone have experience with order of literals in ground form? Or any hints or suggestions?

rkaminsk commented 5 months ago

There are numerous factors at work that influence the order in which rule instances are output. This also applies to the order of literals in rule bodies or conditions. The only thing the system guarantees is that for the same input it produces the same output.

ejgroene commented 5 months ago

Thank you. As long as it is deterministic, that makes coping easier. I'll see how far I can get.