Minor cleanup and reorganization related to last commit.
authorajreynol <andrew.j.reynolds@gmail.com>
Thu, 2 Mar 2017 21:24:07 +0000 (15:24 -0600)
committerajreynol <andrew.j.reynolds@gmail.com>
Thu, 2 Mar 2017 21:24:07 +0000 (15:24 -0600)
22 files changed:
src/Makefile.am
src/decision/decision_engine.h
src/decision/decision_strategy.h
src/decision/justification_heuristic.cpp
src/options/Makefile.am
src/options/boolean_term_conversion_mode.cpp [deleted file]
src/options/boolean_term_conversion_mode.h [deleted file]
src/options/options_handler.cpp
src/options/options_handler.h
src/smt/boolean_terms.cpp [deleted file]
src/smt/boolean_terms.h [deleted file]
src/smt/ite_removal.cpp [deleted file]
src/smt/ite_removal.h [deleted file]
src/smt/model_postprocessor.cpp [deleted file]
src/smt/model_postprocessor.h [deleted file]
src/smt/smt_engine.cpp
src/smt/term_formula_removal.cpp [new file with mode: 0644]
src/smt/term_formula_removal.h [new file with mode: 0644]
src/theory/datatypes/theory_datatypes.cpp
src/theory/quantifiers/ceg_instantiator.cpp
src/theory/quantifiers/inst_strategy_cbqi.cpp
src/theory/theory_engine.cpp

index 2ee777afe01a68d472328f20c1d20a363b504a4f..c05065c3524a98f1a68510941f5b3538b7f2533a 100644 (file)
@@ -117,16 +117,14 @@ libcvc4_la_SOURCES = \
        prop/cryptominisat.cpp \
        prop/theory_proxy.cpp \
        prop/theory_proxy.h \
-       smt/boolean_terms.cpp \
-       smt/boolean_terms.h \
        smt/command.cpp \
        smt/command.h \
        smt/command_list.cpp \
        smt/command_list.h \
        smt/dump.cpp \
        smt/dump.h \
-       smt/ite_removal.cpp \
-       smt/ite_removal.h \
+       smt/term_formula_removal.cpp \
+       smt/term_formula_removal.h \
        smt/logic_exception.h \
        smt/logic_request.cpp \
        smt/logic_request.h \
@@ -134,8 +132,6 @@ libcvc4_la_SOURCES = \
        smt/managed_ostreams.h \
        smt/model.cpp \
        smt/model.h \
-       smt/model_postprocessor.cpp \
-       smt/model_postprocessor.h \
        smt/smt_engine.cpp \
        smt/smt_engine.h \
        smt/smt_engine_check_proof.cpp \
index 92d203cb388df66552d56db6e032204522dbec01..66293d7adca1efc7b7d0e56640a95c8a1363974c 100644 (file)
@@ -27,7 +27,7 @@
 #include "prop/cnf_stream.h"
 #include "prop/prop_engine.h"
 #include "prop/sat_solver_types.h"
-#include "smt/ite_removal.h"
+#include "smt/term_formula_removal.h"
 #include "smt/smt_engine_scope.h"
 
 using namespace std;
index 591f018d83181fa07577b49240ed349d66bae018..5c3b01befeff6626dd19eb586659cac9faf9b8fd 100644 (file)
@@ -20,7 +20,7 @@
 #define __CVC4__DECISION__DECISION_STRATEGY_H
 
 #include "prop/sat_solver_types.h"
-#include "smt/ite_removal.h"
+#include "smt/term_formula_removal.h"
 
 namespace CVC4 {
 
index c0d65cbe6e08003d3a31643283fb54339a208612..ded2cad158eac1f9363f35b928c3fbdaf673c55b 100644 (file)
@@ -22,7 +22,7 @@
 #include "expr/node_manager.h"
 #include "options/decision_options.h"
 #include "theory/rewriter.h"
-#include "smt/ite_removal.h"
+#include "smt/term_formula_removal.h"
 #include "smt/smt_statistics_registry.h"
 
 namespace CVC4 {
index 1eb84b45fcd33cac59261ed582083ca27f30ca9d..31330a97c40cfa32664292717ec94632a647b9bf 100644 (file)
@@ -216,8 +216,6 @@ liboptions_la_SOURCES = \
        argument_extender_implementation.h \
        argument_extender.h \
        base_handlers.h \
-       boolean_term_conversion_mode.cpp \
-       boolean_term_conversion_mode.h \
        bv_bitblast_mode.cpp \
        bv_bitblast_mode.h \
        decision_mode.cpp \
diff --git a/src/options/boolean_term_conversion_mode.cpp b/src/options/boolean_term_conversion_mode.cpp
deleted file mode 100644 (file)
index 4fc9b1f..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*********************                                                        */
-/*! \file boolean_term_conversion_mode.cpp
- ** \verbatim
- ** Top contributors (to current version):
- **   Morgan Deters, Tim King
- ** This file is part of the CVC4 project.
- ** Copyright (c) 2009-2016 by the authors listed in the file AUTHORS
- ** in the top-level source directory) and their institutional affiliations.
- ** All rights reserved.  See the file COPYING in the top-level source
- ** directory for licensing information.\endverbatim
- **
- ** \brief [[ Add one-line brief description here ]]
- **
- ** [[ Add lengthier description here ]]
- ** \todo document this file
- **/
-#include "options/boolean_term_conversion_mode.h"
-
-#include <iostream>
-
-namespace CVC4 {
-
-
-}/* CVC4 namespace */
diff --git a/src/options/boolean_term_conversion_mode.h b/src/options/boolean_term_conversion_mode.h
deleted file mode 100644 (file)
index 57e2cca..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*********************                                                        */
-/*! \file boolean_term_conversion_mode.h
- ** \verbatim
- ** Top contributors (to current version):
- **   Morgan Deters, Tim King
- ** This file is part of the CVC4 project.
- ** Copyright (c) 2009-2016 by the authors listed in the file AUTHORS
- ** in the top-level source directory) and their institutional affiliations.
- ** All rights reserved.  See the file COPYING in the top-level source
- ** directory for licensing information.\endverbatim
- **
- ** \brief [[ Add one-line brief description here ]]
- **
- ** [[ Add lengthier description here ]]
- ** \todo document this file
- **/
-
-#include "cvc4_private.h"
-
-#ifndef __CVC4__THEORY__BOOLEANS__BOOLEAN_TERM_CONVERSION_MODE_H
-#define __CVC4__THEORY__BOOLEANS__BOOLEAN_TERM_CONVERSION_MODE_H
-
-#include <iosfwd>
-
-namespace CVC4 {
-namespace theory {
-namespace booleans {
-
-}/* CVC4::theory::booleans namespace */
-}/* CVC4::theory namespace */
-
-}/* CVC4 namespace */
-
-#endif /* __CVC4__THEORY__BOOLEANS__BOOLEAN_TERM_CONVERSION_MODE_H */
index c0aa67cd41bbf7384ae9ce991c9275cb90d29c5f..94bf15540dec5393032b2c3154e07d61afec9757 100644 (file)
@@ -32,7 +32,6 @@
 #include "options/arith_propagation_mode.h"
 #include "options/arith_unate_lemma_mode.h"
 #include "options/base_options.h"
-#include "options/boolean_term_conversion_mode.h"
 #include "options/bv_bitblast_mode.h"
 #include "options/bv_options.h"
 #include "options/decision_mode.h"
index 248f15c985ee3fdd25e7150260c9dbe6f99df7a7..6721eaa2bdab721ac498c3d92747315afa35b022 100644 (file)
@@ -27,7 +27,6 @@
 #include "options/arith_propagation_mode.h"
 #include "options/arith_unate_lemma_mode.h"
 #include "options/base_handlers.h"
-#include "options/boolean_term_conversion_mode.h"
 #include "options/bv_bitblast_mode.h"
 #include "options/decision_mode.h"
 #include "options/language.h"
diff --git a/src/smt/boolean_terms.cpp b/src/smt/boolean_terms.cpp
deleted file mode 100644 (file)
index 4423555..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*********************                                                        */
-/*! \file boolean_terms.cpp
- ** \verbatim
- ** Top contributors (to current version):
- **   Morgan Deters, Andrew Reynolds, Tim King
- ** This file is part of the CVC4 project.
- ** Copyright (c) 2009-2016 by the authors listed in the file AUTHORS
- ** in the top-level source directory) and their institutional affiliations.
- ** All rights reserved.  See the file COPYING in the top-level source
- ** directory for licensing information.\endverbatim
- **
- ** \brief [[ Add one-line brief description here ]]
- **
- ** [[ Add lengthier description here ]]
- ** \todo document this file
- **/
-#include "smt/boolean_terms.h"
-
-#include <algorithm>
-#include <map>
-#include <set>
-#include <stack>
-#include <string>
-
-#include "expr/kind.h"
-#include "expr/node_manager_attributes.h"
-#include "options/boolean_term_conversion_mode.h"
-#include "options/booleans_options.h"
-#include "smt/smt_engine.h"
-#include "theory/theory_engine.h"
-#include "theory/theory_model.h"
-#include "util/ntuple.h"
-
-using namespace std;
-using namespace CVC4::theory;
-using namespace CVC4::theory::booleans;
-
-namespace CVC4 {
-namespace smt {
-
-}/* CVC4::smt namespace */
-}/* CVC4 namespace */
diff --git a/src/smt/boolean_terms.h b/src/smt/boolean_terms.h
deleted file mode 100644 (file)
index 0fb82aa..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*********************                                                        */
-/*! \file boolean_terms.h
- ** \verbatim
- ** Top contributors (to current version):
- **   Morgan Deters, Tim King, Andrew Reynolds
- ** This file is part of the CVC4 project.
- ** Copyright (c) 2009-2016 by the authors listed in the file AUTHORS
- ** in the top-level source directory) and their institutional affiliations.
- ** All rights reserved.  See the file COPYING in the top-level source
- ** directory for licensing information.\endverbatim
- **
- ** \brief [[ Add one-line brief description here ]]
- **
- ** [[ Add lengthier description here ]]
- ** \todo document this file
- **/
-
-#include "cvc4_private.h"
-
-#pragma once
-
-#include "expr/attribute.h"
-#include "expr/node.h"
-#include "util/hash.h"
-#include <map>
-#include <utility>
-
-namespace CVC4 {
-namespace smt {
-
-}/* CVC4::smt namespace */
-}/* CVC4 namespace */
diff --git a/src/smt/ite_removal.cpp b/src/smt/ite_removal.cpp
deleted file mode 100644 (file)
index 0202a5a..0000000
+++ /dev/null
@@ -1,235 +0,0 @@
-/*********************                                                        */
-/*! \file ite_removal.cpp
- ** \verbatim
- ** Top contributors (to current version):
- **   Morgan Deters, Dejan Jovanovic, Tim King
- ** This file is part of the CVC4 project.
- ** Copyright (c) 2009-2016 by the authors listed in the file AUTHORS
- ** in the top-level source directory) and their institutional affiliations.
- ** All rights reserved.  See the file COPYING in the top-level source
- ** directory for licensing information.\endverbatim
- **
- ** \brief Removal of term ITEs
- **
- ** Removal of term ITEs.
- **/
-#include "smt/ite_removal.h"
-
-#include <vector>
-
-#include "options/proof_options.h"
-#include "proof/proof_manager.h"
-#include "theory/ite_utilities.h"
-
-using namespace std;
-
-namespace CVC4 {
-
-RemoveTermFormulas::RemoveTermFormulas(context::UserContext* u)
-  : d_iteCache(u)
-{
-  d_containsVisitor = new theory::ContainsTermITEVisitor();
-}
-
-RemoveTermFormulas::~RemoveTermFormulas(){
-  delete d_containsVisitor;
-}
-
-void RemoveTermFormulas::garbageCollect(){
-  d_containsVisitor->garbageCollect();
-}
-
-theory::ContainsTermITEVisitor* RemoveTermFormulas::getContainsVisitor() {
-  return d_containsVisitor;
-}
-
-size_t RemoveTermFormulas::collectedCacheSizes() const{
-  return d_containsVisitor->cache_size() + d_iteCache.size();
-}
-
-void RemoveTermFormulas::run(std::vector<Node>& output, IteSkolemMap& iteSkolemMap, bool reportDeps)
-{
-  size_t n = output.size();
-  for (unsigned i = 0, i_end = output.size(); i < i_end; ++ i) {
-    // Do this in two steps to avoid Node problems(?)
-    // Appears related to bug 512, splitting this into two lines
-    // fixes the bug on clang on Mac OS
-    Node itesRemoved = run(output[i], output, iteSkolemMap, false, false);
-    // In some calling contexts, not necessary to report dependence information.
-    if (reportDeps &&
-        (options::unsatCores() || options::fewerPreprocessingHoles())) {
-      // new assertions have a dependence on the node
-      PROOF( ProofManager::currentPM()->addDependence(itesRemoved, output[i]); )
-      while(n < output.size()) {
-        PROOF( ProofManager::currentPM()->addDependence(output[n], output[i]); )
-        ++n;
-      }
-    }
-    output[i] = itesRemoved;
-  }
-}
-
-bool RemoveTermFormulas::containsTermITE(TNode e) const {
-  return d_containsVisitor->containsTermITE(e);
-}
-
-Node RemoveTermFormulas::run(TNode node, std::vector<Node>& output,
-                    IteSkolemMap& iteSkolemMap, bool inQuant, bool inTerm) {
-  // Current node
-  Debug("ite") << "removeITEs(" << node << ")" << " " << inQuant << " " << inTerm << endl;
-
-  //if(node.isVar() || node.isConst()){
-  //   (options::biasedITERemoval() && !containsTermITE(node))){
-  //if(node.isVar()){
-  //  return Node(node);
-  //}
-  if( node.getKind()==kind::INST_PATTERN_LIST ){
-    return Node(node);
-  }
-
-  // The result may be cached already
-  int cv = cacheVal( inQuant, inTerm );
-  std::pair<Node, int> cacheKey(node, cv);
-  NodeManager *nodeManager = NodeManager::currentNM();
-  ITECache::const_iterator i = d_iteCache.find(cacheKey);
-  if(i != d_iteCache.end()) {
-    Node cached = (*i).second;
-    Debug("ite") << "removeITEs: in-cache: " << cached << endl;
-    return cached.isNull() ? Node(node) : cached;
-  }
-
-
-  // If an ITE, replace it
-  TypeNode nodeType = node.getType();
-  if(node.getKind() == kind::ITE) {
-    if(!nodeType.isBoolean() && (!inQuant || !node.hasBoundVar())) {
-      Node skolem;
-      // Make the skolem to represent the ITE
-      skolem = nodeManager->mkSkolem("termITE", nodeType, "a variable introduced due to term-level ITE removal");
-
-      // The new assertion
-      Node newAssertion =
-        nodeManager->mkNode(kind::ITE, node[0], skolem.eqNode(node[1]),
-                            skolem.eqNode(node[2]));
-      Debug("ite") << "removeITEs(" << node << ") => " << newAssertion << endl;
-
-      // Attach the skolem
-      d_iteCache.insert(cacheKey, skolem);
-
-      // Remove ITEs from the new assertion, rewrite it and push it to the output
-      newAssertion = run(newAssertion, output, iteSkolemMap, false, false);
-
-      iteSkolemMap[skolem] = output.size();
-      output.push_back(newAssertion);
-
-      // The representation is now the skolem
-      return skolem;
-    }
-  }
-  //if a non-variable Boolean term, replace it
-  if(node.getKind()!=kind::BOOLEAN_TERM_VARIABLE && nodeType.isBoolean() && inTerm && !inQuant ){//(!inQuant || !node.hasBoundVar())){
-    Node skolem;
-    // Make the skolem to represent the Boolean term
-    //skolem = nodeManager->mkSkolem("termBT", nodeType, "a variable introduced due to Boolean term removal");
-    skolem = nodeManager->mkBooleanTermVariable();
-
-    // The new assertion
-    Node newAssertion = skolem.eqNode( node );
-    Debug("ite") << "removeITEs(" << node << ") => " << newAssertion << endl;
-
-    // Attach the skolem
-    d_iteCache.insert(cacheKey, skolem);
-
-    // Remove ITEs from the new assertion, rewrite it and push it to the output
-    newAssertion = run(newAssertion, output, iteSkolemMap, false, false);
-
-    iteSkolemMap[skolem] = output.size();
-    output.push_back(newAssertion);
-
-    // The representation is now the skolem
-    return skolem;
-  }
-  
-  if(node.getKind() == kind::FORALL || node.getKind() == kind::EXISTS) {
-    // Remember if we're inside a quantifier
-    inQuant = true;
-  }else if( theory::kindToTheoryId(node.getKind())!=theory::THEORY_BOOL && 
-            node.getKind()!=kind::EQUAL && node.getKind()!=kind::SEP_STAR && 
-            node.getKind()!=kind::SEP_WAND && node.getKind()!=kind::SEP_LABEL ){
-    // Remember if we're inside a term
-    Debug("ite") << "In term because of " << node << " " << node.getKind() << std::endl;
-    inTerm = true;
-  }
-
-  // If not an ITE, go deep
-  vector<Node> newChildren;
-  bool somethingChanged = false;
-  if(node.getMetaKind() == kind::metakind::PARAMETERIZED) {
-    newChildren.push_back(node.getOperator());
-  }
-  // Remove the ITEs from the children
-  for(TNode::const_iterator it = node.begin(), end = node.end(); it != end; ++it) {
-    Node newChild = run(*it, output, iteSkolemMap, inQuant, inTerm);
-    somethingChanged |= (newChild != *it);
-    newChildren.push_back(newChild);
-  }
-
-  // If changes, we rewrite
-  if(somethingChanged) {
-    Node cached = nodeManager->mkNode(node.getKind(), newChildren);
-    d_iteCache.insert(cacheKey, cached);
-    return cached;
-  } else {
-    d_iteCache.insert(cacheKey, Node::null());
-    return node;
-  }
-}
-
-Node RemoveTermFormulas::replace(TNode node, bool inQuant, bool inTerm) const {
-  //if(node.isVar() || node.isConst()){
-  //   (options::biasedITERemoval() && !containsTermITE(node))){
-  //if(node.isVar()){
-  //  return Node(node);
-  //}
-  if( node.getKind()==kind::INST_PATTERN_LIST ){
-    return Node(node);
-  }
-
-  // Check the cache
-  NodeManager *nodeManager = NodeManager::currentNM();
-  int cv = cacheVal( inQuant, inTerm );
-  ITECache::const_iterator i = d_iteCache.find(make_pair(node, cv));
-  if(i != d_iteCache.end()) {
-    Node cached = (*i).second;
-    return cached.isNull() ? Node(node) : cached;
-  }
-
-  if(node.getKind() == kind::FORALL || node.getKind() == kind::EXISTS) {
-    // Remember if we're inside a quantifier
-    inQuant = true;
-  }else if( theory::kindToTheoryId(node.getKind())!=theory::THEORY_BOOL && node.getKind()!=kind::EQUAL ){
-    // Remember if we're inside a term
-    inTerm = true;
-  }  
-
-  vector<Node> newChildren;
-  bool somethingChanged = false;
-  if(node.getMetaKind() == kind::metakind::PARAMETERIZED) {
-    newChildren.push_back(node.getOperator());
-  }
-  // Replace in children
-  for(TNode::const_iterator it = node.begin(), end = node.end(); it != end; ++it) {
-    Node newChild = replace(*it, inQuant, inTerm);
-    somethingChanged |= (newChild != *it);
-    newChildren.push_back(newChild);
-  }
-
-  // If changes, we rewrite
-  if(somethingChanged) {
-    return nodeManager->mkNode(node.getKind(), newChildren);
-  } else {
-    return node;
-  }
-}
-
-}/* CVC4 namespace */
diff --git a/src/smt/ite_removal.h b/src/smt/ite_removal.h
deleted file mode 100644 (file)
index e629c93..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*********************                                                        */
-/*! \file ite_removal.h
- ** \verbatim
- ** Top contributors (to current version):
- **   Morgan Deters, Dejan Jovanovic, Tim King
- ** This file is part of the CVC4 project.
- ** Copyright (c) 2009-2016 by the authors listed in the file AUTHORS
- ** in the top-level source directory) and their institutional affiliations.
- ** All rights reserved.  See the file COPYING in the top-level source
- ** directory for licensing information.\endverbatim
- **
- ** \brief Removal of term ITEs
- **
- ** Removal of term ITEs.
- **/
-
-#include "cvc4_private.h"
-
-#pragma once
-
-#include <vector>
-
-#include "context/cdinsert_hashmap.h"
-#include "context/context.h"
-#include "expr/node.h"
-#include "smt/dump.h"
-#include "util/bool.h"
-#include "util/hash.h"
-
-namespace CVC4 {
-
-namespace theory {
-  class ContainsTermITEVisitor;
-}/* CVC4::theory namespace */
-
-typedef std::hash_map<Node, unsigned, NodeHashFunction> IteSkolemMap;
-
-class RemoveTermFormulas {
-  typedef context::CDInsertHashMap< std::pair<Node, int>, Node, PairHashFunction<Node, int, NodeHashFunction, BoolHashFunction> > ITECache;
-  ITECache d_iteCache;
-
-  static inline int cacheVal( bool inQuant, bool inTerm ) { return (inQuant ? 1 : 0) + 2*(inTerm ? 1 : 0); }
-public:
-
-  RemoveTermFormulas(context::UserContext* u);
-  ~RemoveTermFormulas();
-
-  /**
-   * Removes the ITE nodes by introducing skolem variables. All
-   * additional assertions are pushed into assertions. iteSkolemMap
-   * contains a map from introduced skolem variables to the index in
-   * assertions containing the new Boolean ite created in conjunction
-   * with that skolem variable.
-   *
-   * With reportDeps true, report reasoning dependences to the proof
-   * manager (for unsat cores).
-   */
-  void run(std::vector<Node>& assertions, IteSkolemMap& iteSkolemMap, bool reportDeps = false);
-
-  /**
-   * Removes the ITE from the node by introducing skolem
-   * variables. All additional assertions are pushed into
-   * assertions. iteSkolemMap contains a map from introduced skolem
-   * variables to the index in assertions containing the new Boolean
-   * ite created in conjunction with that skolem variable.
-   */
-  Node run(TNode node, std::vector<Node>& additionalAssertions,
-           IteSkolemMap& iteSkolemMap, bool inQuant, bool inTerm);
-
-  /**
-   * Substitute under node using pre-existing cache.  Do not remove
-   * any ITEs not seen during previous runs.
-   */
-  Node replace(TNode node, bool inQuant = false, bool inTerm = false) const;
-
-  /** Returns true if e contains a term ite. */
-  bool containsTermITE(TNode e) const;
-
-  /** Returns the collected size of the caches. */
-  size_t collectedCacheSizes() const;
-
-  /** Garbage collects non-context dependent data-structures. */
-  void garbageCollect();
-
-  /** Return the RemoveTermFormulas's containsVisitor. */
-  theory::ContainsTermITEVisitor* getContainsVisitor();
-
-private:
-  theory::ContainsTermITEVisitor* d_containsVisitor;
-
-};/* class RemoveTTE */
-
-}/* CVC4 namespace */
diff --git a/src/smt/model_postprocessor.cpp b/src/smt/model_postprocessor.cpp
deleted file mode 100644 (file)
index 0076b9d..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*********************                                                        */
-/*! \file model_postprocessor.cpp
- ** \verbatim
- ** Top contributors (to current version):
- **   Morgan Deters, Andrew Reynolds, Tim King
- ** This file is part of the CVC4 project.
- ** Copyright (c) 2009-2016 by the authors listed in the file AUTHORS
- ** in the top-level source directory) and their institutional affiliations.
- ** All rights reserved.  See the file COPYING in the top-level source
- ** directory for licensing information.\endverbatim
- **
- ** \brief
- **
- **
- **/
-
-#include "smt/model_postprocessor.h"
-
-#include "expr/node_manager_attributes.h"
-#include "expr/record.h"
-#include "smt/boolean_terms.h"
-
-using namespace std;
-
-namespace CVC4 {
-namespace smt {
-
-
-} /* namespace smt */
-} /* namespace CVC4 */
diff --git a/src/smt/model_postprocessor.h b/src/smt/model_postprocessor.h
deleted file mode 100644 (file)
index a354315..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*********************                                                        */
-/*! \file model_postprocessor.h
- ** \verbatim
- ** Top contributors (to current version):
- **   Morgan Deters, Tim King
- ** This file is part of the CVC4 project.
- ** Copyright (c) 2009-2016 by the authors listed in the file AUTHORS
- ** in the top-level source directory) and their institutional affiliations.
- ** All rights reserved.  See the file COPYING in the top-level source
- ** directory for licensing information.\endverbatim
- **
- ** \brief 
- **
- ** 
- **/
-
-#include "cvc4_private.h"
-
-#ifndef __CVC4__MODEL_POSTPROCESSOR_H
-#define __CVC4__MODEL_POSTPROCESSOR_H
-
-#include "expr/node.h"
-
-namespace CVC4 {
-namespace smt {
-
-
-}/* CVC4::smt namespace */
-}/* CVC4 namespace */
-
-#endif /* __CVC4__MODEL_POSTPROCESSOR_H */
index cefef934554fde3779e462595867317e62af47ff..b94e08fad5ae6333c6724d2cc9626b2e7e5f8fcb 100644 (file)
@@ -46,8 +46,6 @@
 #include "options/arith_options.h"
 #include "options/arrays_options.h"
 #include "options/base_options.h"
-#include "options/boolean_term_conversion_mode.h"
-#include "options/booleans_options.h"
 #include "options/booleans_options.h"
 #include "options/bv_options.h"
 #include "options/datatypes_options.h"
 #include "proof/theory_proof.h"
 #include "proof/unsat_core.h"
 #include "prop/prop_engine.h"
-#include "smt/boolean_terms.h"
 #include "smt/command.h"
 #include "smt/command_list.h"
-#include "smt/ite_removal.h"
+#include "smt/term_formula_removal.h"
 #include "smt/logic_request.h"
 #include "smt/managed_ostreams.h"
-#include "smt/model_postprocessor.h"
 #include "smt/smt_engine_scope.h"
 #include "smt/update_ostream.h"
 #include "smt_util/boolean_simplification.h"
@@ -4469,19 +4465,6 @@ Result SmtEngine::assertFormula(const Expr& ex, bool inUnsatCore) throw(TypeChec
 }/* SmtEngine::assertFormula() */
 
 Node SmtEngine::postprocess(TNode node, TypeNode expectedType) const {
-/*
-  ModelPostprocessor mpost;
-  NodeVisitor<ModelPostprocessor> visitor;
-  Node value = visitor.run(mpost, node);
-  Debug("boolean-terms") << "postproc: got " << value << " expect type " << expectedType << endl;
-  Node realValue = mpost.rewriteAs(value, expectedType);
-  Debug("boolean-terms") << "postproc: realval " << realValue << " expect type " << expectedType << endl;
-  if(options::condenseFunctionValues()) {
-    realValue = Rewriter::rewrite(realValue);
-    Debug("boolean-terms") << "postproc: after rewrite " << realValue << endl;
-  }
-  return realValue;
-  */
   return node;
 }
 
diff --git a/src/smt/term_formula_removal.cpp b/src/smt/term_formula_removal.cpp
new file mode 100644 (file)
index 0000000..3fd333c
--- /dev/null
@@ -0,0 +1,235 @@
+/*********************                                                        */
+/*! \file term_formula_removal.cpp
+ ** \verbatim
+ ** Top contributors (to current version):
+ **   Morgan Deters, Dejan Jovanovic, Tim King
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2016 by the authors listed in the file AUTHORS
+ ** in the top-level source directory) and their institutional affiliations.
+ ** All rights reserved.  See the file COPYING in the top-level source
+ ** directory for licensing information.\endverbatim
+ **
+ ** \brief Removal of term formulas
+ **
+ ** Removal of term formulas.
+ **/
+#include "smt/term_formula_removal.h"
+
+#include <vector>
+
+#include "options/proof_options.h"
+#include "proof/proof_manager.h"
+#include "theory/ite_utilities.h"
+
+using namespace std;
+
+namespace CVC4 {
+
+RemoveTermFormulas::RemoveTermFormulas(context::UserContext* u)
+  : d_iteCache(u)
+{
+  d_containsVisitor = new theory::ContainsTermITEVisitor();
+}
+
+RemoveTermFormulas::~RemoveTermFormulas(){
+  delete d_containsVisitor;
+}
+
+void RemoveTermFormulas::garbageCollect(){
+  d_containsVisitor->garbageCollect();
+}
+
+theory::ContainsTermITEVisitor* RemoveTermFormulas::getContainsVisitor() {
+  return d_containsVisitor;
+}
+
+size_t RemoveTermFormulas::collectedCacheSizes() const{
+  return d_containsVisitor->cache_size() + d_iteCache.size();
+}
+
+void RemoveTermFormulas::run(std::vector<Node>& output, IteSkolemMap& iteSkolemMap, bool reportDeps)
+{
+  size_t n = output.size();
+  for (unsigned i = 0, i_end = output.size(); i < i_end; ++ i) {
+    // Do this in two steps to avoid Node problems(?)
+    // Appears related to bug 512, splitting this into two lines
+    // fixes the bug on clang on Mac OS
+    Node itesRemoved = run(output[i], output, iteSkolemMap, false, false);
+    // In some calling contexts, not necessary to report dependence information.
+    if (reportDeps &&
+        (options::unsatCores() || options::fewerPreprocessingHoles())) {
+      // new assertions have a dependence on the node
+      PROOF( ProofManager::currentPM()->addDependence(itesRemoved, output[i]); )
+      while(n < output.size()) {
+        PROOF( ProofManager::currentPM()->addDependence(output[n], output[i]); )
+        ++n;
+      }
+    }
+    output[i] = itesRemoved;
+  }
+}
+
+bool RemoveTermFormulas::containsTermITE(TNode e) const {
+  return d_containsVisitor->containsTermITE(e);
+}
+
+Node RemoveTermFormulas::run(TNode node, std::vector<Node>& output,
+                    IteSkolemMap& iteSkolemMap, bool inQuant, bool inTerm) {
+  // Current node
+  Debug("ite") << "removeITEs(" << node << ")" << " " << inQuant << " " << inTerm << endl;
+
+  //if(node.isVar() || node.isConst()){
+  //   (options::biasedITERemoval() && !containsTermITE(node))){
+  //if(node.isVar()){
+  //  return Node(node);
+  //}
+  if( node.getKind()==kind::INST_PATTERN_LIST ){
+    return Node(node);
+  }
+
+  // The result may be cached already
+  int cv = cacheVal( inQuant, inTerm );
+  std::pair<Node, int> cacheKey(node, cv);
+  NodeManager *nodeManager = NodeManager::currentNM();
+  ITECache::const_iterator i = d_iteCache.find(cacheKey);
+  if(i != d_iteCache.end()) {
+    Node cached = (*i).second;
+    Debug("ite") << "removeITEs: in-cache: " << cached << endl;
+    return cached.isNull() ? Node(node) : cached;
+  }
+
+
+  // If an ITE, replace it
+  TypeNode nodeType = node.getType();
+  if(node.getKind() == kind::ITE) {
+    if(!nodeType.isBoolean() && (!inQuant || !node.hasBoundVar())) {
+      Node skolem;
+      // Make the skolem to represent the ITE
+      skolem = nodeManager->mkSkolem("termITE", nodeType, "a variable introduced due to term-level ITE removal");
+
+      // The new assertion
+      Node newAssertion =
+        nodeManager->mkNode(kind::ITE, node[0], skolem.eqNode(node[1]),
+                            skolem.eqNode(node[2]));
+      Debug("ite") << "removeITEs(" << node << ") => " << newAssertion << endl;
+
+      // Attach the skolem
+      d_iteCache.insert(cacheKey, skolem);
+
+      // Remove ITEs from the new assertion, rewrite it and push it to the output
+      newAssertion = run(newAssertion, output, iteSkolemMap, false, false);
+
+      iteSkolemMap[skolem] = output.size();
+      output.push_back(newAssertion);
+
+      // The representation is now the skolem
+      return skolem;
+    }
+  }
+  //if a non-variable Boolean term, replace it
+  if(node.getKind()!=kind::BOOLEAN_TERM_VARIABLE && nodeType.isBoolean() && inTerm && !inQuant ){//(!inQuant || !node.hasBoundVar())){
+    Node skolem;
+    // Make the skolem to represent the Boolean term
+    //skolem = nodeManager->mkSkolem("termBT", nodeType, "a variable introduced due to Boolean term removal");
+    skolem = nodeManager->mkBooleanTermVariable();
+
+    // The new assertion
+    Node newAssertion = skolem.eqNode( node );
+    Debug("ite") << "removeITEs(" << node << ") => " << newAssertion << endl;
+
+    // Attach the skolem
+    d_iteCache.insert(cacheKey, skolem);
+
+    // Remove ITEs from the new assertion, rewrite it and push it to the output
+    newAssertion = run(newAssertion, output, iteSkolemMap, false, false);
+
+    iteSkolemMap[skolem] = output.size();
+    output.push_back(newAssertion);
+
+    // The representation is now the skolem
+    return skolem;
+  }
+  
+  if(node.getKind() == kind::FORALL || node.getKind() == kind::EXISTS) {
+    // Remember if we're inside a quantifier
+    inQuant = true;
+  }else if( theory::kindToTheoryId(node.getKind())!=theory::THEORY_BOOL && 
+            node.getKind()!=kind::EQUAL && node.getKind()!=kind::SEP_STAR && 
+            node.getKind()!=kind::SEP_WAND && node.getKind()!=kind::SEP_LABEL ){
+    // Remember if we're inside a term
+    Debug("ite") << "In term because of " << node << " " << node.getKind() << std::endl;
+    inTerm = true;
+  }
+
+  // If not an ITE, go deep
+  vector<Node> newChildren;
+  bool somethingChanged = false;
+  if(node.getMetaKind() == kind::metakind::PARAMETERIZED) {
+    newChildren.push_back(node.getOperator());
+  }
+  // Remove the ITEs from the children
+  for(TNode::const_iterator it = node.begin(), end = node.end(); it != end; ++it) {
+    Node newChild = run(*it, output, iteSkolemMap, inQuant, inTerm);
+    somethingChanged |= (newChild != *it);
+    newChildren.push_back(newChild);
+  }
+
+  // If changes, we rewrite
+  if(somethingChanged) {
+    Node cached = nodeManager->mkNode(node.getKind(), newChildren);
+    d_iteCache.insert(cacheKey, cached);
+    return cached;
+  } else {
+    d_iteCache.insert(cacheKey, Node::null());
+    return node;
+  }
+}
+
+Node RemoveTermFormulas::replace(TNode node, bool inQuant, bool inTerm) const {
+  //if(node.isVar() || node.isConst()){
+  //   (options::biasedITERemoval() && !containsTermITE(node))){
+  //if(node.isVar()){
+  //  return Node(node);
+  //}
+  if( node.getKind()==kind::INST_PATTERN_LIST ){
+    return Node(node);
+  }
+
+  // Check the cache
+  NodeManager *nodeManager = NodeManager::currentNM();
+  int cv = cacheVal( inQuant, inTerm );
+  ITECache::const_iterator i = d_iteCache.find(make_pair(node, cv));
+  if(i != d_iteCache.end()) {
+    Node cached = (*i).second;
+    return cached.isNull() ? Node(node) : cached;
+  }
+
+  if(node.getKind() == kind::FORALL || node.getKind() == kind::EXISTS) {
+    // Remember if we're inside a quantifier
+    inQuant = true;
+  }else if( theory::kindToTheoryId(node.getKind())!=theory::THEORY_BOOL && node.getKind()!=kind::EQUAL ){
+    // Remember if we're inside a term
+    inTerm = true;
+  }  
+
+  vector<Node> newChildren;
+  bool somethingChanged = false;
+  if(node.getMetaKind() == kind::metakind::PARAMETERIZED) {
+    newChildren.push_back(node.getOperator());
+  }
+  // Replace in children
+  for(TNode::const_iterator it = node.begin(), end = node.end(); it != end; ++it) {
+    Node newChild = replace(*it, inQuant, inTerm);
+    somethingChanged |= (newChild != *it);
+    newChildren.push_back(newChild);
+  }
+
+  // If changes, we rewrite
+  if(somethingChanged) {
+    return nodeManager->mkNode(node.getKind(), newChildren);
+  } else {
+    return node;
+  }
+}
+
+}/* CVC4 namespace */
diff --git a/src/smt/term_formula_removal.h b/src/smt/term_formula_removal.h
new file mode 100644 (file)
index 0000000..09991c5
--- /dev/null
@@ -0,0 +1,93 @@
+/*********************                                                        */
+/*! \file term_formula_removal.h
+ ** \verbatim
+ ** Top contributors (to current version):
+ **   Morgan Deters, Dejan Jovanovic, Tim King
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2016 by the authors listed in the file AUTHORS
+ ** in the top-level source directory) and their institutional affiliations.
+ ** All rights reserved.  See the file COPYING in the top-level source
+ ** directory for licensing information.\endverbatim
+ **
+ ** \brief Removal of term formulas
+ **
+ ** Removal of term formulas.
+ **/
+
+#include "cvc4_private.h"
+
+#pragma once
+
+#include <vector>
+
+#include "context/cdinsert_hashmap.h"
+#include "context/context.h"
+#include "expr/node.h"
+#include "smt/dump.h"
+#include "util/bool.h"
+#include "util/hash.h"
+
+namespace CVC4 {
+
+namespace theory {
+  class ContainsTermITEVisitor;
+}/* CVC4::theory namespace */
+
+typedef std::hash_map<Node, unsigned, NodeHashFunction> IteSkolemMap;
+
+class RemoveTermFormulas {
+  typedef context::CDInsertHashMap< std::pair<Node, int>, Node, PairHashFunction<Node, int, NodeHashFunction, BoolHashFunction> > ITECache;
+  ITECache d_iteCache;
+
+  static inline int cacheVal( bool inQuant, bool inTerm ) { return (inQuant ? 1 : 0) + 2*(inTerm ? 1 : 0); }
+public:
+
+  RemoveTermFormulas(context::UserContext* u);
+  ~RemoveTermFormulas();
+
+  /**
+   * Removes the ITE nodes by introducing skolem variables. All
+   * additional assertions are pushed into assertions. iteSkolemMap
+   * contains a map from introduced skolem variables to the index in
+   * assertions containing the new Boolean ite created in conjunction
+   * with that skolem variable.
+   *
+   * With reportDeps true, report reasoning dependences to the proof
+   * manager (for unsat cores).
+   */
+  void run(std::vector<Node>& assertions, IteSkolemMap& iteSkolemMap, bool reportDeps = false);
+
+  /**
+   * Removes the ITE from the node by introducing skolem
+   * variables. All additional assertions are pushed into
+   * assertions. iteSkolemMap contains a map from introduced skolem
+   * variables to the index in assertions containing the new Boolean
+   * ite created in conjunction with that skolem variable.
+   */
+  Node run(TNode node, std::vector<Node>& additionalAssertions,
+           IteSkolemMap& iteSkolemMap, bool inQuant, bool inTerm);
+
+  /**
+   * Substitute under node using pre-existing cache.  Do not remove
+   * any ITEs not seen during previous runs.
+   */
+  Node replace(TNode node, bool inQuant = false, bool inTerm = false) const;
+
+  /** Returns true if e contains a term ite. */
+  bool containsTermITE(TNode e) const;
+
+  /** Returns the collected size of the caches. */
+  size_t collectedCacheSizes() const;
+
+  /** Garbage collects non-context dependent data-structures. */
+  void garbageCollect();
+
+  /** Return the RemoveTermFormulas's containsVisitor. */
+  theory::ContainsTermITEVisitor* getContainsVisitor();
+
+private:
+  theory::ContainsTermITEVisitor* d_containsVisitor;
+
+};/* class RemoveTTE */
+
+}/* CVC4 namespace */
index 8d2e5618f0a152dc6568a370f5e753e94b04af24..b66cb15ff8cf40cc7c660bba35302b1523d3e342 100644 (file)
@@ -23,7 +23,6 @@
 #include "options/datatypes_options.h"
 #include "options/quantifiers_options.h"
 #include "options/smt_options.h"
-#include "smt/boolean_terms.h"
 #include "theory/datatypes/datatypes_rewriter.h"
 #include "theory/datatypes/theory_datatypes_type_rules.h"
 #include "theory/quantifiers_engine.h"
index 3dacfca3a9aaa26349179ed8d88acfb25abdbe6e..adce94b5cb243b5ac2c157c8a7e37079dae44eee 100644 (file)
@@ -16,7 +16,7 @@
 #include "theory/quantifiers/ceg_t_instantiator.h"
 
 #include "options/quantifiers_options.h"
-#include "smt/ite_removal.h"
+#include "smt/term_formula_removal.h"
 #include "theory/quantifiers/first_order_model.h"
 #include "theory/quantifiers/term_database.h"
 #include "theory/quantifiers/quantifiers_rewriter.h"
index 0023f7d0ff39a9f57e6850e278a97e93eb30f14f..1f18377406ca4cf80ed89b54b4d103556404f133 100644 (file)
@@ -14,7 +14,7 @@
 #include "theory/quantifiers/inst_strategy_cbqi.h"
 
 #include "options/quantifiers_options.h"
-#include "smt/ite_removal.h"
+#include "smt/term_formula_removal.h"
 #include "theory/arith/partial_model.h"
 #include "theory/arith/theory_arith.h"
 #include "theory/arith/theory_arith_private.h"
index 7c1b02f471d4b93cebe63cce4a4bf04a31e49670..4054350aa42055581e1ecfbbcab4e2ce6dce310b 100644 (file)
@@ -31,7 +31,7 @@
 #include "proof/lemma_proof.h"
 #include "proof/proof_manager.h"
 #include "proof/theory_proof.h"
-#include "smt/ite_removal.h"
+#include "smt/term_formula_removal.h"
 #include "smt/logic_exception.h"
 #include "smt_util/lemma_output_channel.h"
 #include "smt_util/node_visitor.h"