summaryrefslogtreecommitdiff
path: root/src/preprocessing/passes
diff options
context:
space:
mode:
authoryoni206 <yoni206@users.noreply.github.com>2018-07-17 14:20:46 -0700
committerGitHub <noreply@github.com>2018-07-17 14:20:46 -0700
commit75bbe18a3f8f7b814a7716574fd3619bf69ba85b (patch)
tree9ca8b3d55aa6e7002fba5185004878b6adba3dae /src/preprocessing/passes
parent06440f4ed1f4de8612740dc21b63ac6967404f31 (diff)
Refactor sep-pre-skolem-emp preprocessing pass
Diffstat (limited to 'src/preprocessing/passes')
-rw-r--r--src/preprocessing/passes/sep_skolem_emp.cpp124
-rw-r--r--src/preprocessing/passes/sep_skolem_emp.h42
2 files changed, 166 insertions, 0 deletions
diff --git a/src/preprocessing/passes/sep_skolem_emp.cpp b/src/preprocessing/passes/sep_skolem_emp.cpp
new file mode 100644
index 000000000..d79ec8b93
--- /dev/null
+++ b/src/preprocessing/passes/sep_skolem_emp.cpp
@@ -0,0 +1,124 @@
+/**********************/
+/*! \file sep_skolem_emp.cpp
+ ** \verbatim
+ ** Top contributors (to current version):
+ ** Andrew Reynolds, Mathias Preiner, Yoni Zohar
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2018 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 The sep-pre-skolem-emp preprocessing pass
+ **
+ **/
+
+#include "preprocessing/passes/sep_skolem_emp.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "expr/node.h"
+#include "theory/quantifiers/quant_util.h"
+#include "theory/rewriter.h"
+#include "theory/theory.h"
+
+namespace CVC4 {
+namespace preprocessing {
+namespace passes {
+
+using namespace CVC4::theory;
+
+namespace {
+
+Node preSkolemEmp(Node n,
+ bool pol,
+ std::map<bool, std::map<Node, Node>>& visited)
+{
+ std::map<Node, Node>::iterator it = visited[pol].find(n);
+ if (it == visited[pol].end())
+ {
+ Trace("sep-preprocess") << "Pre-skolem emp " << n << " with pol " << pol
+ << std::endl;
+ Node ret = n;
+ if (n.getKind() == kind::SEP_EMP)
+ {
+ if (!pol)
+ {
+ TypeNode tnx = n[0].getType();
+ TypeNode tny = n[1].getType();
+ Node x = NodeManager::currentNM()->mkSkolem(
+ "ex", tnx, "skolem location for negated emp");
+ Node y = NodeManager::currentNM()->mkSkolem(
+ "ey", tny, "skolem data for negated emp");
+ return NodeManager::currentNM()
+ ->mkNode(kind::SEP_STAR,
+ NodeManager::currentNM()->mkNode(kind::SEP_PTO, x, y),
+ NodeManager::currentNM()->mkConst(true))
+ .negate();
+ }
+ }
+ else if (n.getKind() != kind::FORALL && n.getNumChildren() > 0)
+ {
+ std::vector<Node> children;
+ bool childChanged = false;
+ if (n.getMetaKind() == kind::metakind::PARAMETERIZED)
+ {
+ children.push_back(n.getOperator());
+ }
+ for (unsigned i = 0; i < n.getNumChildren(); i++)
+ {
+ bool newPol, newHasPol;
+ QuantPhaseReq::getPolarity(n, i, true, pol, newHasPol, newPol);
+ Node nc = n[i];
+ if (newHasPol)
+ {
+ nc = preSkolemEmp(n[i], newPol, visited);
+ childChanged = childChanged || nc != n[i];
+ }
+ children.push_back(nc);
+ }
+ if (childChanged)
+ {
+ return NodeManager::currentNM()->mkNode(n.getKind(), children);
+ }
+ }
+ visited[pol][n] = ret;
+ return n;
+ }
+ else
+ {
+ return it->second;
+ }
+}
+
+} // namespace
+
+SepSkolemEmp::SepSkolemEmp(PreprocessingPassContext* preprocContext)
+ : PreprocessingPass(preprocContext, "sep-skolem-emp"){};
+
+PreprocessingPassResult SepSkolemEmp::applyInternal(
+ AssertionPipeline* assertionsToPreprocess)
+{
+ std::map<bool, std::map<Node, Node>> visited;
+ for (unsigned i = 0; i < assertionsToPreprocess->size(); ++i)
+ {
+ Node prev = (*assertionsToPreprocess)[i];
+ bool pol = true;
+ Node next = preSkolemEmp(prev, pol, visited);
+ if (next != prev)
+ {
+ assertionsToPreprocess->replace(i, Rewriter::rewrite(next));
+ Trace("sep-preprocess") << "*** Preprocess sep " << prev << endl;
+ Trace("sep-preprocess") << " ...got " << (*assertionsToPreprocess)[i]
+ << endl;
+ }
+ visited.clear();
+ }
+ return PreprocessingPassResult::NO_CONFLICT;
+}
+
+} // namespace passes
+} // namespace preprocessing
+} // namespace CVC4
diff --git a/src/preprocessing/passes/sep_skolem_emp.h b/src/preprocessing/passes/sep_skolem_emp.h
new file mode 100644
index 000000000..4a3dba6b8
--- /dev/null
+++ b/src/preprocessing/passes/sep_skolem_emp.h
@@ -0,0 +1,42 @@
+/********************* */
+/*! \file sep_skolem_emp.h
+ ** \verbatim
+ ** Top contributors (to current version):
+ ** Andrew Reynolds, Mathias Preiner, Yoni Zohar
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2018 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 The sep-pre-skolem-emp eprocessing pass
+ **
+ **/
+
+#include "cvc4_private.h"
+
+#ifndef __CVC4__PREPROCESSING__PASSES__SEP_SKOLEM_EMP_H
+#define __CVC4__PREPROCESSING__PASSES__SEP_SKOLEM_EMP_H
+
+#include "preprocessing/preprocessing_pass.h"
+#include "preprocessing/preprocessing_pass_context.h"
+
+namespace CVC4 {
+namespace preprocessing {
+namespace passes {
+
+class SepSkolemEmp : public PreprocessingPass
+{
+ public:
+ SepSkolemEmp(PreprocessingPassContext* preprocContext);
+
+ protected:
+ PreprocessingPassResult applyInternal(
+ AssertionPipeline* assertionsToPreprocess) override;
+};
+
+} // namespace passes
+} // namespace preprocessing
+} // namespace CVC4
+
+#endif /* __CVC4__PREPROCESSING__PASSES__SEP_SKOLEM_EMP_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback