summaryrefslogtreecommitdiff
path: root/src/preprocessing/passes
diff options
context:
space:
mode:
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>2018-08-16 16:58:06 -0500
committerGitHub <noreply@github.com>2018-08-16 16:58:06 -0500
commit013c1535ea821a42b1aebd0491c85a594f728a70 (patch)
treed9f2e91a52406edf66967faccad550631cd9e4a5 /src/preprocessing/passes
parentb2e2572b41dfeca41c72dc34b46632e04d1e933f (diff)
parent4e62cdade61514f268b96e78e2f82ad12dfcad07 (diff)
Merge branch 'master' into moveKindedmoveKinded
Diffstat (limited to 'src/preprocessing/passes')
-rw-r--r--src/preprocessing/passes/apply_to_const.cpp108
-rw-r--r--src/preprocessing/passes/apply_to_const.h51
-rw-r--r--src/preprocessing/passes/extended_rewriter_pass.cpp42
-rw-r--r--src/preprocessing/passes/extended_rewriter_pass.h43
4 files changed, 244 insertions, 0 deletions
diff --git a/src/preprocessing/passes/apply_to_const.cpp b/src/preprocessing/passes/apply_to_const.cpp
new file mode 100644
index 000000000..bbe4439ec
--- /dev/null
+++ b/src/preprocessing/passes/apply_to_const.cpp
@@ -0,0 +1,108 @@
+/********************* */
+/*! \file apply_to_const.cpp
+ ** \verbatim
+ ** Top contributors (to current version):
+ ** Haniel Barbosa
+ ** 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 ApplyToConst preprocessing pass
+ **
+ ** Rewrites applies to constants
+ **/
+
+#include "preprocessing/passes/apply_to_const.h"
+
+#include "theory/rewriter.h"
+
+namespace CVC4 {
+namespace preprocessing {
+namespace passes {
+
+using namespace CVC4::theory;
+
+ApplyToConst::ApplyToConst(PreprocessingPassContext* preprocContext)
+ : PreprocessingPass(preprocContext, "apply-to-const"){};
+
+Node ApplyToConst::rewriteApplyToConst(TNode n, NodeMap& cache)
+{
+ Trace("rewriteApplyToConst") << "rewriteApplyToConst :: " << n << std::endl;
+
+ if (n.getMetaKind() == kind::metakind::CONSTANT
+ || n.getMetaKind() == kind::metakind::VARIABLE
+ || n.getMetaKind() == kind::metakind::NULLARY_OPERATOR)
+ {
+ return n;
+ }
+
+ if (cache.find(n) != cache.end())
+ {
+ Trace("rewriteApplyToConst") << "in cache :: " << cache[n] << std::endl;
+ return cache[n];
+ }
+
+ if (n.getKind() == kind::APPLY_UF)
+ {
+ if (n.getNumChildren() == 1 && n[0].isConst() && n[0].getType().isInteger())
+ {
+ stringstream ss;
+ ss << n.getOperator() << "_";
+ if (n[0].getConst<Rational>() < 0)
+ {
+ ss << "m" << -n[0].getConst<Rational>();
+ }
+ else
+ {
+ ss << n[0];
+ }
+ Node newvar =
+ NodeManager::currentNM()->mkSkolem(ss.str(),
+ n.getType(),
+ "rewriteApplyToConst skolem",
+ NodeManager::SKOLEM_EXACT_NAME);
+ cache[n] = newvar;
+ Trace("rewriteApplyToConst") << "made :: " << newvar << std::endl;
+ return newvar;
+ }
+ stringstream ss;
+ ss << "The rewrite-apply-to-const preprocessor is currently limited;\n"
+ << "it only works if all function symbols are unary and with Integer\n"
+ << "domain, and all applications are to integer values.\n"
+ << "Found application: " << n;
+ Unhandled(ss.str());
+ }
+
+ NodeBuilder<> builder(n.getKind());
+ if (n.getMetaKind() == kind::metakind::PARAMETERIZED)
+ {
+ builder << n.getOperator();
+ }
+ for (unsigned i = 0; i < n.getNumChildren(); ++i)
+ {
+ builder << rewriteApplyToConst(n[i], cache);
+ }
+ Node rewr = builder;
+ cache[n] = rewr;
+ Trace("rewriteApplyToConst") << "built :: " << rewr << std::endl;
+ return rewr;
+}
+
+PreprocessingPassResult ApplyToConst::applyInternal(
+ AssertionPipeline* assertionsToPreprocess)
+{
+ NodeMap cache;
+ for (unsigned i = 0, size = assertionsToPreprocess->size(); i < size; ++i)
+ {
+ assertionsToPreprocess->replace(i,
+ Rewriter::rewrite(rewriteApplyToConst(
+ (*assertionsToPreprocess)[i], cache)));
+ }
+ return PreprocessingPassResult::NO_CONFLICT;
+}
+
+} // namespace passes
+} // namespace preprocessing
+} // namespace CVC4
diff --git a/src/preprocessing/passes/apply_to_const.h b/src/preprocessing/passes/apply_to_const.h
new file mode 100644
index 000000000..9d5072023
--- /dev/null
+++ b/src/preprocessing/passes/apply_to_const.h
@@ -0,0 +1,51 @@
+/********************* */
+/*! \file apply_to_const.h
+ ** \verbatim
+ ** Top contributors (to current version):
+ ** Haniel Barbosa
+ ** 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 ApplyToConst preprocessing pass
+ **
+ ** Rewrites applies to constants
+ **/
+
+#include "cvc4_private.h"
+
+#ifndef __CVC4__PREPROCESSING__PASSES__APPLY_TO_CONST_H
+#define __CVC4__PREPROCESSING__PASSES__APPLY_TO_CONST_H
+
+#include <unordered_map>
+
+#include "expr/node.h"
+#include "preprocessing/preprocessing_pass.h"
+#include "preprocessing/preprocessing_pass_context.h"
+
+namespace CVC4 {
+namespace preprocessing {
+namespace passes {
+
+using NodeMap = std::unordered_map<Node, Node, NodeHashFunction>;
+
+class ApplyToConst : public PreprocessingPass
+{
+ public:
+ ApplyToConst(PreprocessingPassContext* preprocContext);
+
+ protected:
+ PreprocessingPassResult applyInternal(
+ AssertionPipeline* assertionsToPreprocess) override;
+
+ private:
+ Node rewriteApplyToConst(TNode n, NodeMap& cache);
+};
+
+} // namespace passes
+} // namespace preprocessing
+} // namespace CVC4
+
+#endif /* __CVC4__PREPROCESSING__PASSES__APPLY_TO_CONST_H */
diff --git a/src/preprocessing/passes/extended_rewriter_pass.cpp b/src/preprocessing/passes/extended_rewriter_pass.cpp
new file mode 100644
index 000000000..572aaed7a
--- /dev/null
+++ b/src/preprocessing/passes/extended_rewriter_pass.cpp
@@ -0,0 +1,42 @@
+/********************* */
+/*! \file extended_rewriter_pass.cpp
+ ** \verbatim
+ ** Top contributors (to current version):
+ ** Haniel Barbosa
+ ** 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 ExtRewPre preprocessing pass
+ **
+ ** Applies the extended rewriter to assertions
+ **/
+
+#include "preprocessing/passes/extended_rewriter_pass.h"
+
+#include "theory/quantifiers/extended_rewrite.h"
+
+namespace CVC4 {
+namespace preprocessing {
+namespace passes {
+
+ExtRewPre::ExtRewPre(PreprocessingPassContext* preprocContext)
+ : PreprocessingPass(preprocContext, "ext-rew-pre"){};
+
+PreprocessingPassResult ExtRewPre::applyInternal(
+ AssertionPipeline* assertionsToPreprocess)
+{
+ theory::quantifiers::ExtendedRewriter extr(options::extRewPrepAgg());
+ for (unsigned i = 0, size = assertionsToPreprocess->size(); i < size; ++i)
+ {
+ assertionsToPreprocess->replace(
+ i, extr.extendedRewrite((*assertionsToPreprocess)[i]));
+ }
+ return PreprocessingPassResult::NO_CONFLICT;
+}
+
+} // namespace passes
+} // namespace preprocessing
+} // namespace CVC4
diff --git a/src/preprocessing/passes/extended_rewriter_pass.h b/src/preprocessing/passes/extended_rewriter_pass.h
new file mode 100644
index 000000000..f604a1af5
--- /dev/null
+++ b/src/preprocessing/passes/extended_rewriter_pass.h
@@ -0,0 +1,43 @@
+/********************* */
+/*! \file extended_rewriter_pass.h
+ ** \verbatim
+ ** Top contributors (to current version):
+ ** Haniel Barbosa
+ ** 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 ExtRewPre preprocessing pass
+ **
+ ** Applies the extended rewriter to assertions
+ **/
+
+#include "cvc4_private.h"
+
+#ifndef __CVC4__PREPROCESSING__PASSES__EXTENDED_REWRITER_PASS_H
+#define __CVC4__PREPROCESSING__PASSES__EXTENDED_REWRITER_PASS_H
+
+#include "preprocessing/preprocessing_pass.h"
+#include "preprocessing/preprocessing_pass_context.h"
+
+namespace CVC4 {
+namespace preprocessing {
+namespace passes {
+
+class ExtRewPre : public PreprocessingPass
+{
+ public:
+ ExtRewPre(PreprocessingPassContext* preprocContext);
+
+ protected:
+ PreprocessingPassResult applyInternal(
+ AssertionPipeline* assertionsToPreprocess) override;
+};
+
+} // namespace passes
+} // namespace preprocessing
+} // namespace CVC4
+
+#endif /* __CVC4__PREPROCESSING__PASSES__EXTENDED_REWRITER_PASS_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback