Skip to content

Commit

Permalink
TPA: Refactor check of k-inductive invariant
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Blicha committed May 16, 2022
1 parent 41082d8 commit ed91a8d
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/engine/TPA.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1086,9 +1086,25 @@ PTRef TPABase::kinductiveToInductive(PTRef invariant, unsigned long k) const {
}

bool TPABase::verifyKinductiveInvariant(PTRef fla, unsigned long k) const {
SMTConfig config;
// Base cases:
{
constexpr int trace_level = 1;
TRACE(trace_level, "Verifying k-inductive invariant for k = " << k)
{ // Inductive case:
SMTConfig config;
MainSolver solver(logic, config, "k-induction inductive step checker");
for (unsigned long i = 0; i < k; ++i) {
solver.insertFormula(getNextVersion(fla, i));
solver.insertFormula(getNextVersion(transition, i));
}
solver.insertFormula(logic.mkNot(getNextVersion(fla, k)));
auto res = solver.check();
if (res != s_False) {
std::cerr << "k-induction verification failed; induction step does not hold!" << std::endl;
return false;
}
TRACE(trace_level, "Inductive case succesfully verified")
}
{ // Base cases:
SMTConfig config;
MainSolver solver(logic, config, "k-induction base checker");
solver.insertFormula(init);
for (unsigned long i = 0; i < k; ++i) {
Expand All @@ -1099,22 +1115,12 @@ bool TPABase::verifyKinductiveInvariant(PTRef fla, unsigned long k) const {
std::cerr << "k-induction verification failed; base case " << i << " does not hold!" << std::endl;
return false;
}
TRACE(trace_level, "Base case " << i << " succesfully verified")
solver.pop();
solver.push();
solver.insertFormula(getNextVersion(transition, i));
}
}
// Inductive case:
MainSolver solver(logic, config, "k-induction inductive step checker");
for (unsigned long i = 0; i < k; ++i) {
solver.insertFormula(getNextVersion(fla, i));
solver.insertFormula(getNextVersion(transition, i));
}
solver.insertFormula(logic.mkNot(getNextVersion(fla, k)));
auto res = solver.check();
if (res != s_False) {
std::cerr << "k-induction verification failed; induction step does not hold!" << std::endl;
return false;
}
return true;
}

Expand Down Expand Up @@ -1671,8 +1677,8 @@ PTRef TPASplit::inductiveInvariantFromEqualsTransitionInvariant() const {
stateInvariant = QuantifierElimination(logic).eliminate(stateInvariant, getStateVars(1));
stateInvariant = getNextVersion(stateInvariant, -2);
// std::cout << "State invariant: " << logic.printTerm(stateInvariant) << std::endl;
unsigned long k = 1;
k <<= power;
if (power >= 64) { return PTRef_Undef; } // MB: Cannot shift more than 63 bits
unsigned long k = 1ul << power;
assert(verifyKinductiveInvariant(stateInvariant, k));
// std::cout << "K-inductivness of invariant sucessfully checked for k=" << k << std::endl;
PTRef inductiveInvariant = kinductiveToInductive(stateInvariant, k);
Expand Down

0 comments on commit ed91a8d

Please sign in to comment.