CBMC
synthesizer_utils.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Utility functions for loop invariant synthesizer.
4 
5 Author: Qinheping Hu
6 
7 \*******************************************************************/
8 
9 #include "synthesizer_utils.h"
10 
12  const invariant_mapt &in_clauses,
13  const invariant_mapt &post_clauses,
14  const invariant_mapt &neg_guards)
15 {
16  // Combine invariant
17  // (in_inv || !guard) && (!guard -> pos_inv) for loops with loop guard
18  // in_inv && pos_inv for loops without loop guard
19  invariant_mapt result;
20  for(const auto &in_clause : in_clauses)
21  {
22  const auto &id = in_clause.first;
23  const auto &it_guard = neg_guards.find(id);
24 
25  // Unconditional loop or failed to get loop guard.
26  if(it_guard == neg_guards.end())
27  {
28  result[id] = and_exprt(in_clause.second, post_clauses.at(id));
29  }
30  // Loops with loop guard.
31  else
32  {
33  result[id] = and_exprt(
34  or_exprt(it_guard->second, in_clause.second),
35  implies_exprt(it_guard->second, post_clauses.at(id)));
36  }
37  }
38  return result;
39 }
Boolean AND.
Definition: std_expr.h:2125
Boolean implication.
Definition: std_expr.h:2188
Boolean OR.
Definition: std_expr.h:2233
invariant_mapt combine_in_and_post_invariant_clauses(const invariant_mapt &in_clauses, const invariant_mapt &post_clauses, const invariant_mapt &neg_guards)
Combine invariant of form (in_inv || !guard) && (!guard -> pos_inv)
std::map< loop_idt, exprt > invariant_mapt
Definition: utils.h:31