44#include <unordered_map>
45#include <unordered_set>
61 operator()(
const std::pair<const DAGNode *, const DAGNode *> &p)
const {
62 return std::hash<const void *>()(p.first) ^
63 std::hash<const void *>()(p.second);
68 bool operator()(
const std::pair<const DAGNode *, const DAGNode *> &p1,
69 const std::pair<const DAGNode *, const DAGNode *> &p2)
const {
70 return p1.first == p2.first && p1.second == p2.second;
77 std::shared_ptr<Sort>
sort;
81 std::vector<std::shared_ptr<DAGNode>>
children;
96 size_t combined_hash = 0;
97 for (
size_t i = 0; i <
children.size(); i++) {
98 size_t child_hash =
children[i]->hashCode();
99 combined_hash ^= child_hash + 0x9e3779b9 + (combined_hash << 6) +
100 (combined_hash >> 2);
214 name = std::to_string(v);
222 name = std::to_string(v);
230 name = v ?
"true" :
"false";
243 else if (n ==
"false") {
247 else if (n ==
"pi") {
255 else if (n ==
"inf") {
259 else if (n ==
"NaN" || n ==
"+NaN" || n ==
"-NaN") {
263 else if (n ==
"epsilon") {
267 else if (n ==
"NULL") {
416 sort->isRoundingMode();
565 (
sort->isInt() ||
sort->isReal())));
928 std::string
rename(
const std::string &new_name) {
929 std::cerr <<
"Warning: rename " <<
name <<
" to " << new_name << std::endl;
1003 std::vector<std::shared_ptr<DAGNode>> res;
1031 std::vector<std::shared_ptr<DAGNode>> res;
1056 std::unordered_set<std::pair<const DAGNode *, const DAGNode *>,
1074 size_t h1 = std::hash<std::string>{}(
sort->toString());
1075 size_t h2 =
static_cast<size_t>(
kind);
1076 size_t h3 =
name.empty() ? 0 : std::hash<std::string>{}(
name);
1083 seed ^= h1 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1084 seed ^= h2 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1085 seed ^= h3 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1086 seed ^= h4 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1087 seed ^= h5 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1089 seed ^= 0x9e3779b9 + (seed << 6) + (seed >> 2);
1107 std::shared_ptr<DAGNode> body,
1108 const std::vector<std::shared_ptr<DAGNode>> ¶ms,
1109 bool is_rec =
false);
1122 std::shared_ptr<DAGNode> body,
1123 const std::vector<std::shared_ptr<DAGNode>> ¶ms,
1124 bool is_rec =
false);
1129 std::unordered_set<std::pair<const DAGNode *, const DAGNode *>,
1133 if (
this == &other) {
1155 auto p = std::make_pair(
this, &other);
1156 if (visited.find(p) != visited.end()) {
1162 for (
size_t i = 0; i <
children.size(); i++) {
1173 return node->hashCode();
1179 const std::shared_ptr<DAGNode> &node2)
const {
1181 if (node1->hashCode() != node2->hashCode()) {
1185 return node1->isEquivalentTo(*node2);
1189std::string
dumpSMTLIB2(
const std::shared_ptr<DAGNode> &node);
1190std::string
dumpFuncDef(
const std::shared_ptr<DAGNode> &node);
1191std::string
dumpFuncRec(
const std::shared_ptr<DAGNode> &node);
1192std::string
dumpFuncDec(
const std::shared_ptr<DAGNode> &node);
1199 std::vector<std::shared_ptr<DAGNode>>
nodes;
1204 std::vector<std::pair<std::shared_ptr<DAGNode>,
size_t>>>,
1213 std::shared_ptr<DAGNode>
getNode(
const size_t index)
const;
1214 size_t getIndex(
const std::shared_ptr<DAGNode> &node)
const;
1215 size_t size()
const;
1218 std::shared_ptr<DAGNode>
1219 createNode(std::shared_ptr<Sort> sort,
NODE_KIND kind, std::string name, std::vector<std::shared_ptr<DAGNode>> children);
1220 std::shared_ptr<DAGNode>
createNode(std::shared_ptr<Sort> sort,
1223 std::shared_ptr<DAGNode>
createNode(std::shared_ptr<Sort> sort,
1225 std::shared_ptr<DAGNode>
createNode(std::shared_ptr<Sort> sort);
1229 std::shared_ptr<DAGNode>
createNode(std::shared_ptr<Sort> sort,
1231 std::shared_ptr<DAGNode>
createNode(std::shared_ptr<Sort> sort,
1233 std::shared_ptr<DAGNode>
createNode(std::shared_ptr<Sort> sort,
1235 std::shared_ptr<DAGNode>
createNode(std::shared_ptr<Sort> sort,
const int &v);
1236 std::shared_ptr<DAGNode>
createNode(std::shared_ptr<Sort> sort,
1238 std::shared_ptr<DAGNode>
createNode(
const std::string &n);
1268 std::make_shared<DAGNode>(
"NULL");
1276 std::make_shared<DAGNode>(
"true");
1278 std::make_shared<DAGNode>(
"false");
1279 inline static const std::shared_ptr<DAGNode>
E_NODE =
1280 std::make_shared<DAGNode>(
"e");
1281 inline static const std::shared_ptr<DAGNode>
PI_NODE =
1282 std::make_shared<DAGNode>(
"pi");
1291 inline static const std::shared_ptr<DAGNode>
NAN_NODE =
1292 std::make_shared<DAGNode>(
"NaN");
1294 std::make_shared<DAGNode>(
"EPSILON");
1338 std::shared_ptr<DAGNode>
bool isStrContains() const
bool isRegAllChar() const
std::vector< std::shared_ptr< DAGNode > > getChildren() const
Get the children of the node.
bool isToFPUnsigned() const
bool isRegComplement() const
bool isStrPrefixof() const
bool isStrSplitRest() const
bool isFPIsNormal() const
bool isStrSplitAtRe() const
void setValue(const Interval &v)
std::string toString() const
bool isStrSplitRestRe() const
std::string children_hash
bool isStrReplaceAll() const
std::size_t hashCode() const
Get the hash code of the node.
bool isDistinctBool() const
bool isNegInfinity() const
std::vector< std::shared_ptr< DAGNode > > getFuncParams() const
Get the parameters of the function.
std::shared_ptr< DAGNode > getFuncBody() const
Get the body of the function.
size_t getFuncParamsSize() const
Get the number of parameters of the function.
std::vector< std::shared_ptr< DAGNode > > children
bool isStrFromInt() const
bool isStrToUpper() const
bool isBVRotRight() const
bool isStrIndexof() const
bool isStrToLower() const
void updateFuncDef(std::shared_ptr< Sort > out_sort, std::shared_ptr< DAGNode > body, const std::vector< std::shared_ptr< DAGNode > > ¶ms, bool is_rec=false)
Update the function definition.
DAGNode(std::shared_ptr< Sort > sort, NODE_KIND kind, std::string name)
std::shared_ptr< Value > value
bool isNegEpsilon() const
DAGNode(NODE_KIND kind, std::string name)
bool isEquivalentTo(const std::shared_ptr< DAGNode > &other) const
Check if the node is equivalent to another node.
DAGNode(std::shared_ptr< Sort > sort, const bool &v)
void setName(const std::string &n)
bool isDtFunApplication() const
bool isStrIsDigit() const
std::string getName() const
Get the name of the node.
bool isStrNumSplitsRe() const
bool isFPRoundToIntegral() const
size_t getChildrenSize() const
Get the number of children of the node.
DAGNode(std::shared_ptr< Sort > sort)
void updateApplyFunc(std::shared_ptr< Sort > out_sort, std::shared_ptr< DAGNode > body, const std::vector< std::shared_ptr< DAGNode > > ¶ms, bool is_rec=false)
Update the function application.
bool isLetBindVar() const
std::shared_ptr< Sort > getSort() const
Get the sort of the node.
std::string getPureName() const
bool isEquivalentTo(const DAGNode &other, std::unordered_set< std::pair< const DAGNode *, const DAGNode * >, PairNodePtrHash, PairNodePtrEqual > &visited) const
bool isLetBindVarList() const
void setValue(const Integer &v)
bool isStrSuffixof() const
std::string rename(const std::string &new_name)
Get the re-named name of the node.
std::shared_ptr< Value > getValue() const
Get the value of the node.
bool isUFApplication() const
void setValue(const double &v)
NODE_KIND getKind() const
Get the kind of the node.
bool isRealNonlinearOp() const
bool isDistinctOther() const
bool isVRoundingMode() const
void replace_children(const std::vector< std::shared_ptr< DAGNode > > &new_children)
DAGNode(std::shared_ptr< Sort > sort, NODE_KIND kind, std::string name, std::vector< std::shared_ptr< DAGNode > > children)
std::shared_ptr< DAGNode > getQuantBody() const
Get the body of the quantifier.
std::shared_ptr< DAGNode > getChild(int i) const
Get the child of the node.
bool isCRoundingMode() const
bool isPosEpsilon() const
size_t getUseCount() const
std::vector< std::shared_ptr< DAGNode > > getQuantVars() const
Get the variables of the quantifier.
DAGNode(std::shared_ptr< Sort > sort, const double &v)
bool operator==(const DAGNode elem)
bool isConstArray() const
bool isFuncApplication() const
bool isTranscendentalOp() const
bool isStrSplitAt() const
void setValue(const Real &v)
DAGNode(std::shared_ptr< Sort > sort, const int &v)
bool operator!=(const DAGNode elem)
bool isStrReplace() const
DAGNode(const DAGNode &other)
bool isStrNumSplits() const
bool isFPIsSubnormal() const
bool isEquivalentTo(const DAGNode &other) const
Check if the node is equivalent to another node.
bool isPosInfinity() const
bool isFuncRecApplication() const
DAGNode(std::shared_ptr< Sort > sort, const Real &v)
bool isAttributeParam() const
bool isStrFromCode() const
void setValue(const int &v)
bool isPlaceholderVar() const
DAGNode(const std::string &n)
DAGNode(std::shared_ptr< Sort > sort, const Integer &v)
std::shared_ptr< Sort > sort
DAGNode(std::shared_ptr< Sort > sort, NODE_KIND kind)
void setValue(std::shared_ptr< Value > v)
Set the value of the node.
std::string toString(int base=10) const
std::string toString() const
static std::shared_ptr< DAGNode > getNaN()
static std::shared_ptr< DAGNode > getRealPosInf()
static const std::shared_ptr< DAGNode > E_NODE
static std::shared_ptr< DAGNode > getFalse()
void initializeStaticNodes()
static const std::shared_ptr< DAGNode > INT_INF_NODE
static const std::shared_ptr< DAGNode > STR_NEG_INF_NODE
std::shared_ptr< DAGNode > createNode()
size_t getIndex(const std::shared_ptr< DAGNode > &node) const
static std::shared_ptr< DAGNode > getIntNegInf()
static const std::shared_ptr< DAGNode > POS_EPSILON_NODE
std::array< std::unordered_map< size_t, std::vector< std::pair< std::shared_ptr< DAGNode >, size_t > > >, NUM_KINDS > node_buckets
static const std::shared_ptr< DAGNode > PI_NODE
static const std::shared_ptr< DAGNode > UNKNOWN_NODE
static const std::shared_ptr< DAGNode > NAN_NODE
static const std::shared_ptr< DAGNode > REAL_INF_NODE
static const std::shared_ptr< DAGNode > STR_POS_INF_NODE
std::vector< std::shared_ptr< DAGNode > > nodes
static const std::shared_ptr< DAGNode > ERROR_NODE
static std::shared_ptr< DAGNode > getNegEpsilon()
static std::shared_ptr< DAGNode > getUnknown()
static std::shared_ptr< DAGNode > getEpsilon()
std::shared_ptr< DAGNode > getNode(const size_t index) const
static std::shared_ptr< DAGNode > getStrInf()
static std::shared_ptr< DAGNode > getIntInf()
static const std::shared_ptr< DAGNode > REAL_NEG_INF_NODE
static const std::shared_ptr< DAGNode > NEG_EPSILON_NODE
static const std::shared_ptr< DAGNode > REAL_POS_INF_NODE
static std::shared_ptr< DAGNode > getRealInf()
static const std::shared_ptr< DAGNode > TRUE_NODE
static std::shared_ptr< DAGNode > getNull()
static std::shared_ptr< DAGNode > getIntPosInf()
static const std::shared_ptr< DAGNode > STR_INF_NODE
static const std::shared_ptr< DAGNode > NULL_NODE
static std::shared_ptr< DAGNode > getPi()
static std::shared_ptr< DAGNode > getPosEpsilon()
static const std::shared_ptr< DAGNode > INT_POS_INF_NODE
static const std::shared_ptr< DAGNode > INT_NEG_INF_NODE
static std::shared_ptr< DAGNode > getStrNegInf()
static std::shared_ptr< DAGNode > getE()
static const std::shared_ptr< DAGNode > EPSILON_NODE
static const std::shared_ptr< DAGNode > FALSE_NODE
std::shared_ptr< DAGNode > insertNodeToBucket(const std::shared_ptr< DAGNode > &node)
static std::shared_ptr< DAGNode > getTrue()
static std::shared_ptr< DAGNode > getRealNegInf()
static std::shared_ptr< DAGNode > getStrPosInf()
static const std::shared_ptr< Sort > STR_SORT
static const std::shared_ptr< Sort > INT_SORT
static const std::shared_ptr< Sort > BOOL_SORT
static const std::shared_ptr< Sort > REAL_SORT
static const std::shared_ptr< Sort > UNKNOWN_SORT
static const std::shared_ptr< Sort > EXT_SORT
static const std::shared_ptr< Sort > NULL_SORT
static bool isReal(const std::string &str)
static bool isString(const std::string &str)
static bool isInt(const std::string &str)
const std::string PRESERVING_LET_BIND_VAR_SUFFIX
std::string dumpFuncDef(const std::shared_ptr< DAGNode > &node)
std::string dumpSMTLIB2(const std::shared_ptr< DAGNode > &root)
std::string dumpFuncDec(const std::shared_ptr< DAGNode > &node)
constexpr size_t NUM_KINDS
@ NT_FP_ROUND_TO_INTEGRAL
std::string dumpFuncRec(const std::shared_ptr< DAGNode > &node)
std::shared_ptr< DAGNode > NodePtr
std::shared_ptr< Value > newValue(const std::string &string_value)
bool operator()(const std::shared_ptr< DAGNode > &node1, const std::shared_ptr< DAGNode > &node2) const
size_t operator()(const std::shared_ptr< DAGNode > &node) const
bool operator()(const std::pair< const DAGNode *, const DAGNode * > &p1, const std::pair< const DAGNode *, const DAGNode * > &p2) const
size_t operator()(const std::pair< const DAGNode *, const DAGNode * > &p) const