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

Investigate inference of loop invariants using merge-nodes functionality #448

Open
ehildenb opened this issue Mar 13, 2024 · 7 comments
Open
Labels
cse engagement enhancement New feature or request

Comments

@ehildenb
Copy link
Member

ehildenb commented Mar 13, 2024

Here #444, we update the merge-nodes functionality to allow specifying loop heads in looping code. Here, we have an example that uses a loop invariant to allow verifying a small piece of code with a simple loop: #369.

The merge-nodes functionality should help us in identifying the loop invariant needed in order to verify such simple loops. We probably can't infer the entire loop invariant, but at least we can make an initial guess ath the correct LHS of the loop to use.

Here, we should:

@qian-hu
Copy link
Contributor

qian-hu commented Mar 20, 2024

  • kontrol show output
  • Result after merging loop heads 13 and 14
  • Result after merging intermediate nodes (with the same K cell as in the original loop invariant) for the first three loops

@ehildenb
Copy link
Member Author

@qian-hu I don't quite see the nodes mentioned in the merges in the KCFG output there. Node 19 appears to be a target node, and node 13 and 14 are on either side of the same branch. Nodes 26 and 31 don't exist. Can we see the original KCFG output as well?

@ehildenb
Copy link
Member Author

Also, what is the process needed to go from the original merged node to the invariant there? What manual steps need to be taken?

@ehildenb
Copy link
Member Author

Another thought is this. The invariant has the form:

rule LOOP => LOOP_ENDED requires LOOP_INVARIANT

The LOOP node is the node we are currently trying to infer by merging a bunch of other nodes which show up in a repeating pattern for the loop. The LOOP_ENDED and LOOP_INVARIANT ones we probably can't infer as automatically.

But every loop should have structure a -branch-> {b, c}, where b is "stepping into the loop", and c is "stepping out of the loop" (because of the loop head condition). In this example, we've collected several b_1, b_2, b_3, ... and merged them to try and discover LHS of the invariant (the LOOP part). We could also consider collecting several c_1, c_2, c_3, ... and merge them to try and discover the RHS of the loop invariant (the LOOP_ENDED part).

@qian-hu
Copy link
Contributor

qian-hu commented Mar 21, 2024

@ehildenb Please refer to the original KCFG here. Additionally, you can find the KCFG output after merging intermediate nodes here.

@qian-hu
Copy link
Contributor

qian-hu commented Mar 28, 2024

I've pushed an update to the foundry_merge_nodes() of foundry.py allowing for the merging nodes belonging to the same loop but with different K cells. Comparing the result of merging nodes with different K cells against those with the same cells yields valuable information about the dependencies. The merged loop nodes now provide additional information regarding requires related to localMem of the LHS.

@palinatolmach
Copy link
Collaborator

Related: runtimeverification/k#4425

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cse engagement enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

4 participants