ret = nm->mkNode(cur.getKind(), children);
ret = Rewriter::rewrite(ret);
}
- if (!ret.isConst())
- {
- Trace("fd-eval") << "FunDefEvaluator: non-constant subterm " << ret
- << ", FAIL" << std::endl;
- // failed, possibly due to free variable
- return Node::null();
- }
visited[cur] = ret;
}
}
- else if (!curEval.isConst())
+ else if (cur != curEval && !curEval.isConst())
{
Trace("fd-eval-debug") << "from body " << cur << std::endl;
// we had to evaluate our body, which should have a definition now
Assert(it != visited.end());
// our definition is the result of the body
visited[cur] = it->second;
- Assert(it->second.isConst());
}
}
} while (!visit.empty());
std::stack<TNode> visit;
TNode cur;
visit.push(n);
+ TermDbSygus* tds = d_qe->getTermDatabaseSygus();
do {
cur = visit.top();
visit.pop();
}
if (makeEvalFun)
{
- // will make into an application of an evaluation function
- ret = nm->mkNode(DT_SYGUS_EVAL, children);
+ if (!cur.getType().isFunction())
+ {
+ // will make into an application of an evaluation function
+ ret = nm->mkNode(DT_SYGUS_EVAL, children);
+ }
+ else
+ {
+ Assert(children.size() == 1);
+ Node ef = children[0];
+ // Otherwise, we are using the function-to-synthesize itself in a
+ // higher-order setting. We must return the lambda term:
+ // lambda x1...xn. (DT_SYGUS_EVAL ef x1 ... xn)
+ // where ef is the first order variable for the
+ // function-to-synthesize.
+ SygusTypeInfo& ti = tds->getTypeInfo(ef.getType());
+ const std::vector<Node>& vars = ti.getVarList();
+ Assert(!vars.empty());
+ std::vector<Node> vs;
+ for (const Node& v : vars)
+ {
+ vs.push_back(nm->mkBoundVar(v.getType()));
+ }
+ Node lvl = nm->mkNode(BOUND_VAR_LIST, vs);
+ std::vector<Node> eargs;
+ eargs.push_back(ef);
+ eargs.insert(eargs.end(), vs.begin(), vs.end());
+ ret = nm->mkNode(LAMBDA, lvl, nm->mkNode(DT_SYGUS_EVAL, eargs));
+ }
}
else if (childChanged)
{
- ret = NodeManager::currentNM()->mkNode(ret_k, children);
+ ret = nm->mkNode(ret_k, children);
}
visited[cur] = ret;
}
regress1/sygus/large-const-simp.sy
regress1/sygus/let-bug-simp.sy
regress1/sygus/list-head-x.sy
+ regress1/sygus/list_recursor.sy
regress1/sygus/logiccell_help.sy
regress1/sygus/max.sy
regress1/sygus/max2-bv.sy
--- /dev/null
+; EXPECT: unsat
+; COMMAND-LINE: --sygus-out=status --sygus-rec-fun --lang=sygus2 --uf-ho
+
+(set-logic ALL)
+
+(declare-datatype List ((cons (head Int) (tail List)) (nil)))
+
+(define-fun-rec List_rec ((x Int) (y (-> Int List Int Int)) (l List)) Int
+ (ite ((_ is nil) l) x
+ (y (head l) (tail l) (List_rec x y (tail l)))))
+
+(synth-fun f () Int
+ ((I Int))
+ ((I Int (0 1 (+ I I)))))
+
+(synth-fun g ((x Int) (y List) (z Int)) Int
+ ((I Int) (L List))
+ ((I Int (x z (+ I I) (head L) 0 1))
+ (L List (y (tail y)))))
+
+
+(constraint (= (List_rec f g (cons 0 (cons 1 nil))) 2))
+(constraint (= (List_rec f g (cons 0 (cons 0 nil))) 2))
+(constraint (= (List_rec f g (cons 5 (cons 3 (cons 3 (cons 0 nil))))) 4))
+(constraint (= (List_rec f g nil) 0))
+(check-synth)