elimination/ExistentialEliminator.h
00001 /*
00002  * ExistentialEliminator.h
00003  *
00004  *  Created on: Nov 26, 2011
00005  *      Author: isil
00006  */
00007 
00008 #ifndef EXISTENTIALELIMINATOR_H_
00009 #define EXISTENTIALELIMINATOR_H_
00010 
00011 #include <map>
00012 #include <set>
00013 using namespace std;
00014 
00015 class CNode;
00016 class Term;
00017 class FunctionTerm;
00018 
00019 class ExistentialEliminator {
00020 private:
00021         CNode* c;
00022         Term* elim_t;
00023         CNode* result;
00024         bool overapprox;
00025 
00026         bool simplify;
00027 
00028 
00029         /*
00030          * For each function id, this map contains another map
00031          * from function terms containing x (var to be eliminated)
00032          * to a fresh variable that we will replace this function term with.
00033          */
00034         map<int, map<Term*, Term*> > function_terms_to_vars;
00035 
00036         /*
00037          * Additional terms to eliminate caused by replacing
00038          * function terms with variables
00039          */
00040         set<Term*> new_elim_terms;
00041 
00042         /*
00043          * A map from function identifiers to function terms
00044          * with this identifier.
00045          */
00046         map<int, set<Term*> > function_ids_to_terms;
00047 
00048 
00049 public:
00050         ExistentialEliminator(CNode* c, Term* t, bool overapproximation);
00051         CNode* get_result();
00052         ~ExistentialEliminator();
00053 
00054 private:
00055         CNode* eliminate_existential(CNode* c);
00056 
00057         /*
00058          * Populates the map function_terms_to_vars and new_elim_terms,
00059          * and returns a new constraint where function terms containing elim_t
00060          * are replaced with a fresh variable term.
00061          */
00062         CNode* collect_function_terms_containing_elim_t(CNode* c);
00063 
00064         /*
00065          * Populates the function_ids_to_terms map.
00066          */
00067         void build_map_from_fun_id_to_terms(CNode* c);
00068 
00069 
00070         CNode* get_functional_consistency_axioms();
00071 
00072         /*
00073          * Generates a constraint stating that the arguments of ft1 and ft2 are equal.
00074          */
00075         CNode* args_equal(FunctionTerm* ft1, FunctionTerm* ft2);
00076 
00077         bool contained_in_function_term(CNode* c, Term* t);
00078 
00079         CNode* replace_elim_t_in_function(CNode* c, Term* elim_t);
00080 
00081         CNode* find_disjunctive_equalities(CNode* c, Term* elim_t,
00082                                 bool parent_conjunct);
00083 
00084 };
00085 
00086 #endif /* EXISTENTIALELIMINATOR_H_ */