Loop Pre/Post Condition Generation with Exactness Verification#2
Open
flyingapricot wants to merge 5 commits into
Open
Loop Pre/Post Condition Generation with Exactness Verification#2flyingapricot wants to merge 5 commits into
flyingapricot wants to merge 5 commits into
Conversation
… invariant computation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR aims to the
loopinvtool to generate pre- and post-conditions for C loops using Least Fixed Point (LFP) computation, with an exactness verification to classify results as EXACT (EX) or OVER-APPROXIMATE (OX).Feature 1: Loop Pre/Post Conditions in Case Format with Prime Notation
Approach
imptool's intermediate representationimptool to compute the relational LFP (least fixed point) that captures the input-output relationship of each loopa.imptoutput filex= pre-state value (value before loop)x'= post-state value (value after loop)Output Format
Results
while(x<n) x++case { x>=n ens x'=n },case { 1+x<=n ens x'=n }while(x>0) x--case { x<=0 ens x'=0 },case { x>=1 ens x'=0 }while(x<n) x+=2case { true ens x'>=n }Feature 2: EX/OX Exactness Verification
Motivation
LFP computation may use widening to ensure termination, which can result in over-approximations. We need a way to determine if the computed LFP is:
Approach - Semantic Fixed-Point Verification
We verify exactness by checking if
Fsatisfies the fixed-point equation:Where:
F= the computed LFP (relational summary)base= loop exit condition (when loop doesn't execute)step= single iteration effect∘= relational compositionVerification Logic:
Generate a
fixcalcquery that defines:F(x, n, x', n')- the computed LFPbase(x, n, x', n')- base case:x >= n && x' = x && n' = nstep(x, n, x', n')- step relation:x < n && x' = x + 1 && n' = nFcomp(x, n, x', n')- composition:∃x_t, n_t: F(x, n, x_t, n_t) && step(x_t, n_t, x', n')combined-base || FcompCheck bidirectional subset relations:
If both hold, result is EXACT (EX); otherwise OVER-APPROXIMATE (OX)
Results
x+=2) - Presburger arithmetic cannot express parity constraintsSample Output
Testing
Test 1: Simple Loop (test1.c) - EX
Output:
Test 2: Countdown Loop (test3.c) - EX
Output:
Test 3: Tricky Loop (test_tricky.c) - OX
Output:
This loop is OX because Presburger arithmetic cannot express parity constraints (the exact result would be x' = n or x' = n + 1 depending on parity).
Limitations
fixcalconly supports linear integer arithmetic. Non-linear operations (multiplication, modulo) lead to over-approximations.