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

--preserve-facts does not preserve conditional literals #533

Open
AbdallahS opened this issue Jan 4, 2025 · 4 comments
Open

--preserve-facts does not preserve conditional literals #533

AbdallahS opened this issue Jan 4, 2025 · 4 comments

Comments

@AbdallahS
Copy link

Consider the following input file:

p(a).
p(b).
q(a,c).
q(b,d).
r(c).
r(d).
t(Y) :- r(Y), p(X) : q(X,Y).

I expect grounding while preserving facts to output something like

p(a).
p(b).
q(a,c).
q(b,d).
r(c).
r(d).
t(c) :- r(c), p(a):q(a,c).
t(d) :- r(d), p(b):q(b,d).

instead, I get

p(a).
p(b).
q(a,c).
q(b,d).
r(c).
r(d).
t(c) :- r(c).
t(d) :- r(d).

We can contrast the grounding of t/1 in echo "p(a). p(b). q(a,c). q(b,d). r(c). r(d). t(Y) :- r(Y), p(X) : q(X,Y)." | clingo --text --preserve-facts=all - and in echo "1 {p(a)}. 1 {p(b)}. 1 {q(a,c)}. 1 {q(b,d)}. r(c). r(d). t(Y) :- r(Y), p(X) : q(X,Y)." | clingo --text --preserve-facts=all -.

@rkaminsk
Copy link
Member

rkaminsk commented Jan 4, 2025

Preserve facts (body) only affects facts directly occurring in rule bodies and does not extend to conditions.

If you want to prevent the grounder from applying any simplifications you might want to consider making facts externals.

#external p(a). [true]
#external p(b). [true]
#external q(a,c). [true]
#external q(b,d). [true]
#external r(c). [true]
#external r(d). [true]
t(c) :- r(c), p(a):q(a,c).
t(d) :- r(d), p(b):q(b,d).

@AbdallahS
Copy link
Author

AbdallahS commented Jan 4, 2025

Thank you for the tip with external. It hadn't occurred to me and it is a little bit more elegant than using false-choice rules.

Regarding preserve-facts only affecting facts directly occuring in the body, wouldn't that mean that q/2 would be simplified away but p/1 would be preserved in the example? So that the output could be something like

p(a).
p(b).
q(a,c).
q(b,d).
r(c).
r(d).
t(c) :- r(c), p(a).
t(d) :- r(d), p(b).

@rkaminsk
Copy link
Member

rkaminsk commented Jan 6, 2025

Regarding preserve-facts only affecting facts directly occuring in the body, wouldn't that mean that q/2 would be simplified away but p/1 would be preserved in the example? So that the output could be something like

The feature has been implemented on top of the existing system design. What you describe is certainly possible - just not implemented. I am also not sure whether it is worth to spend any time here. Maybe I'll add an option that treats facts as externals for the next major release...

@AbdallahS
Copy link
Author

An option to treat facts as externals would be perfect for my use-cases (in teaching and in my own debugging). Both these needs can be met with manually writing #external, so this option is certainly low priority.

@rkaminsk rkaminsk added this to the unknown milestone Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants