runtimeverification / haskell-backend

The symbolic execution engine powering the K Framework
BSD 3-Clause "New" or "Revised" License
212 stars 42 forks source link

Reasoning about remainders #3948

Open PetarMax opened 5 months ago

PetarMax commented 5 months ago

As part of exploring CSE in Kontrol, a few issues have come up. Specifically: 1) The backend exhibits spurious branching because it's not able to prove a large remainder (11 branches) UNSAT. An initial investigation with @geo2a revealed that the satisfiability of the remainder is not checked with respect to the current path constraint. The corresponding bug report is attached: it exhibits a 9-way branching when only an 8-way branching is expected). 2) The remainders are not minimised, in the sense that even though some branches have been cut as infeasible, we still get the negation of their constraints in the remainder (in the example, the branching is initially 11-way and then three branches are discarded). 3) The remainder is not propagated back using rule_predicate, which leads to a mischaracterisation of the branching by pyk, and causes an infinite loop in combination with 1).

From what I understand, the remainders are initially of the form #Not ( ... #Or ... ), which is then transformed into #Not (...) #And #Not (...). I believe that there is room for further simplification or minimisation at the #Or stage, perhaps even Z3 could be asked to minimise this before the transformation to #And.

nine-way-branch.tar.gz

geo2a commented 4 months ago

With the georgy/booster-remainders branch, Booster can now apply the rules from the bug report, but it still produces a 9-way (instead of 8-way) branch. I.e. the behaviour is on-par with Kore. I have some thoughts on why this happens and also some wants about the rules. I start with the wants and then describe a possible transformation to the rule format that may help us to prune the remainder.

Format of CSE rules

PetarMax commented 4 months ago

CSE rules are specifically designed to have only symbolic variables on the LHS, with the exception of +Bytes and map concatenation. If you see any other ones, please let me know.

+Bytes are fine, we have an excellent array of rules that does unification on them, which is deterministic. Concatenation of maps is something to be implemented.

In addition, my experience tells me that we should never be introducing additional constraints into the path condition unless absolutely necessary, and this is not necessary for +Bytes and should not be necessary for map concatenation.

PetarMax commented 4 months ago

The remainder condition that we are dealing with is over-approximating because in the path constraints, some symbolic variables are initialised in some of the branches, causing the parameters of function symbols to be computed partially or even the function to be fully evaluated. This issue, I believe, is not related to what's in the structural part.