}
bool hasFreeVar(TNode n)
+{
+ std::unordered_set<Node, NodeHashFunction> fvs;
+ return getFreeVariables(n, fvs, false);
+}
+
+bool getFreeVariables(TNode n,
+ std::unordered_set<Node, NodeHashFunction>& fvs,
+ bool computeFv)
{
std::unordered_set<TNode, TNodeHashFunction> bound_var;
std::unordered_map<TNode, bool, TNodeHashFunction> visited;
{
if (bound_var.find(cur) == bound_var.end())
{
- return true;
+ if (computeFv)
+ {
+ fvs.insert(cur);
+ }
+ else
+ {
+ return true;
+ }
}
}
else if (isQuant)
visited[cur] = true;
}
} while (!visit.empty());
- return false;
+
+ return !fvs.empty();
}
void getSymbols(TNode n, std::unordered_set<Node, NodeHashFunction>& syms)
*/
bool hasFreeVar(TNode n);
+/**
+ * Get the free variables in n, that is, the subterms of n of kind
+ * BOUND_VARIABLE that are not bound in n, adds these to fvs.
+ * @param n The node under investigation
+ * @param fvs The set which free variables are added to
+ * @param computeFv If this flag is false, then we only return true/false and
+ * do not add to fvs.
+ * @return true iff this node contains a free variable.
+ */
+bool getFreeVariables(TNode n,
+ std::unordered_set<Node, NodeHashFunction>& fvs,
+ bool computeFv = true);
+
/**
* For term n, this function collects the symbols that occur as a subterms
* of n. A symbol is a variable that does not have kind BOUND_VARIABLE.