potassco / clingo

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

[Python API] clingo.ast.AST.__str__() unexpected behavior(commas into semicolon) #445

Closed jinulee-v closed 1 year ago

jinulee-v commented 1 year ago

Hi, I am currently working with python bindings of Clingo. There is a major issue regarding the AST.str() function, which intends to convert the AST object into reparsable, reproducible string representation.

Note that ASP code p(X) :- r(X), not q(X) translates to p(X) :- r(X); not q(X) , which is completely different from the best of my knowledge. (comma represents logical AND, while semi-colon represents disjunction) I believe it is a issue in the underlying C library, but I yet have inspected that portion of Clingo and therefore cannot make any suggestions at the moment.

clingo 5.4.0 libclingo 5.4.0 libclasp 3.3.5 python clingo bindings(installed via pip) 5.6.2

image

jinulee-v commented 1 year ago

And if possible, are there any monkey patches/bypasses to obtain a correct string representation?

daveraja commented 1 year ago

AFAIK the representation is correct. From (at least) clingo 5.X, semi-colon in the head represents a disjunction but when used in the body semi-colon is a conjunction.

It allows for disambiguating conditions and literals in rule bodies. For an example look at Example 3.14 (p29) of the Clingo Guide: https://github.com/potassco/guide/releases/tag/v2.2.0

rkaminsk commented 1 year ago

In your example, a , could have been used. However, I decided to always use ; because it never leads to ambiguities. If you pass the rule to clingo, you will see that it accepts the rule just fine.

jinulee-v commented 1 year ago

Thank you all for helpful comments. I must have misunderstood the syntax of Clingo ASP!