From 39f66e01a3c2be95e511244eb1052b9e868a9a06 Mon Sep 17 00:00:00 2001 From: trevor_hansen Date: Fri, 11 Jun 2010 02:04:18 +0000 Subject: [PATCH] This makes SimplifyTerm idempotent. My hope is that this will reduce the number of times that the toplevel function needs to be called. If a term at the bottom of the graph doesn't map to itself when SimplifyTerm is run, then all the nodes above it will need to be re-created next time SimplifyTerm is called on the graph. This patch adds an assertion function that isn't enabled. git-svn-id: https://stp-fast-prover.svn.sourceforge.net/svnroot/stp-fast-prover/trunk/stp@830 e59a4935-1847-0410-ae03-e826735625c1 --- src/simplifier/simplifier.cpp | 30 +++++++++++++++++++++++++++++- src/simplifier/simplifier.h | 2 ++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/simplifier/simplifier.cpp b/src/simplifier/simplifier.cpp index 100fef0..183adbe 100644 --- a/src/simplifier/simplifier.cpp +++ b/src/simplifier/simplifier.cpp @@ -230,6 +230,31 @@ namespace BEEV return out; } + // I like simplify to have been run on all the nodes. + void Simplifier::checkIfInSimplifyMap(const ASTNode& n, ASTNodeSet visited) + { + if (n.isConstant() || (n.GetKind() == SYMBOL)) + return; + + if (visited.find(n) != visited.end()) + return; + + if (SimplifyMap->find(n) == SimplifyMap->end()) + { + cerr << "not found"; + cerr << n; + assert(false); + } + + for(int i =0; i < n.Degree();i++) + { + checkIfInSimplifyMap(n[i],visited); + } + + visited.insert(n); + } + + // The SimplifyMaps on entry to the topLevel functions may contain // useful entries. E.g. The BVSolver calls SimplifyTerm() ASTNode Simplifier::SimplifyFormula_TopLevel(const ASTNode& b, @@ -238,6 +263,8 @@ namespace BEEV { _bm->GetRunTimes()->start(RunTimes::SimplifyTopLevel); ASTNode out = SimplifyFormula(b, pushNeg, VarConstMap); + ASTNodeSet visited; + //checkIfInSimplifyMap(out,visited); ResetSimplifyMaps(); _bm->GetRunTimes()->stop(RunTimes::SimplifyTopLevel); return out; @@ -351,7 +378,6 @@ namespace BEEV break; } - //memoize UpdateSimplifyMap(b, output, pushNeg, VarConstMap); UpdateSimplifyMap(a, output, pushNeg, VarConstMap); return output; @@ -2665,6 +2691,8 @@ namespace BEEV } assert(!output.IsNull()); + if (inputterm != output) + output = SimplifyTerm(output); //memoize UpdateSimplifyMap(inputterm, output, false, VarConstMap); //cerr << "SimplifyTerm: output" << output << endl; diff --git a/src/simplifier/simplifier.h b/src/simplifier/simplifier.h index 99d431b..928b25c 100644 --- a/src/simplifier/simplifier.h +++ b/src/simplifier/simplifier.h @@ -50,6 +50,8 @@ namespace BEEV STPMgr * _bm; NodeFactory * nf; + + void checkIfInSimplifyMap(const ASTNode& n, ASTNodeSet visited); public: /**************************************************************** -- 2.47.3