Stream: Elpi users & devs

Topic: Backtracking & CHR


view this post on Zulip Enzo Crance (Apr 11 2023 at 15:17):

Hello. I am wondering whether backtracking also applies to the constraint store. I have the mental model that the constraint store is by design independent from Prolog's tree-like execution, i.e. if a branch adds constraints to the store that happen to trigger constraint rules deleting constraints or adding new constraints, and this branch eventually fails, then even when backtracking to another branch, the store is left in this modified state. Am I wrong?

view this post on Zulip Enrico Tassi (Apr 11 2023 at 19:52):

Yes you are wrong, constraints are backtracked too.

view this post on Zulip Enrico Tassi (Apr 11 2023 at 20:38):

In the example about even/odd here: https://github.com/gares/mlws18/blob/master/slides.pdf the constraint store is modified "under a not", hence you clearly want to restore the previous state which was not not-satisfiable.

view this post on Zulip Enzo Crance (Apr 12 2023 at 07:11):

Enrico Tassi said:

Yes you are wrong, constraints are backtracked too.

Great, I needed this feature :rofl: thanks for the answer!

view this post on Zulip Enrico Tassi (Apr 12 2023 at 08:39):

The only hack I have to make something survive backtracking is the safe thing:
https://github.com/LPCIC/elpi/blob/master/src/builtin.elpi#L472-L483

view this post on Zulip Enrico Tassi (Apr 12 2023 at 08:41):

But it is very limited. Maybe if you explain a bit more in details what you want to do I can provide better guidance.

view this post on Zulip Enzo Crance (Apr 12 2023 at 09:00):

To make it clear: I needed constraints to backtrack as well :wink: so everything is fine. But thanks for the pointer to safe in case I need something to persist :+1:

view this post on Zulip Enrico Tassi (Apr 12 2023 at 09:01):

Ah ok, now it makes way more sense ;-)


Last updated: Oct 13 2024 at 01:02 UTC