Skip to content

Commit

Permalink
Disable definition introduction if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
mezpusz committed Feb 29, 2024
1 parent 9380fdd commit 7565a92
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
6 changes: 3 additions & 3 deletions Kernel/Signature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,14 +699,14 @@ unsigned Signature::getDiff(){

unsigned Signature::getFnDef(unsigned fn)
{
auto sort = getFunction(fn)->fnType()->result();
ASS(sort.isTerm() && sort.term()->ground());
auto type = getFunction(fn)->fnType();
auto sort = type->result();
bool added = false;
auto name = "$def_"+sort.toString();
unsigned p = addPredicate(name, 2, added);
if (added) {
ALWAYS(_fnDefPreds.insert(p));
OperatorType* ot = OperatorType::getPredicateType({sort, sort});
OperatorType* ot = OperatorType::getPredicateType({sort, sort}, type->numTypeArguments());
Symbol* sym = getPredicate(p);
sym->markProtected();
sym->setType(ot);
Expand Down
49 changes: 38 additions & 11 deletions Parse/SMTLIB2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,11 @@ SMTLIB2::DeclaredSymbol SMTLIB2::declareFunctionOrPredicate(const vstring& name,

// ----------------------------------------------------------------------

bool shouldCreateFunctionDefinition(unsigned fn)
{
return env.options->functionDefinitionRewriting() || env.options->structInduction()==Options::StructuralInductionKind::RECURSION;
}

void SMTLIB2::readDefineFun(const vstring& name, LExprList* iArgs, LExpr* oSort, LExpr* body, const TermStack& typeArgs, bool recursive)
{
if (isAlreadyKnownSymbol(name)) {
Expand Down Expand Up @@ -838,12 +843,23 @@ void SMTLIB2::readDefineFun(const vstring& name, LExprList* iArgs, LExpr* oSort,
Literal* lit;
if (isTrueFun) {
TermList lhs(Term::create(symbIdx,args.size(),args.begin()));
auto p = env.signature->getFnDef(symbIdx);
lit = Literal::create(p, true, { lhs, rhs });
if (shouldCreateFunctionDefinition(symbIdx)) {
auto p = env.signature->getFnDef(symbIdx);
auto defArgs = typeArgs;
defArgs.push(lhs);
defArgs.push(rhs);
lit = Literal::create(p,defArgs.size(),true,false,defArgs.begin());
} else {
lit = Literal::createEquality(true,lhs,rhs,rangeSort);
}
} else {
auto p = env.signature->getBoolDef(symbIdx);
Formula* frm = new AtomicFormula(Literal::create(p,args.size(),true,false,args.begin()));
TermList lhs(Term::createFormula(frm));
if (shouldCreateFunctionDefinition(symbIdx)) {
auto p = env.signature->getBoolDef(symbIdx);
lit = Literal::create(p,args.size(),true,false,args.begin());
} else {
lit = Literal::create(symbIdx,args.size(),true,false,args.begin());
}
TermList lhs(Term::createFormula(new AtomicFormula(lit)));
lit = Literal::createEquality(true, lhs, rhs, rangeSort);
}
Formula* fla = new AtomicFormula(lit);
Expand Down Expand Up @@ -932,13 +948,24 @@ void SMTLIB2::readDefineFunsRec(LExprList* declsExpr, LExprList* defsExpr)
Literal* lit;
if (isTrueFun) {
TermList lhs(Term::create(symbIdx,decl.args.size(),decl.args.begin()));
auto p = env.signature->getFnDef(symbIdx);
lit = Literal::create(p, true, { lhs, rhs });
if (shouldCreateFunctionDefinition(symbIdx)) {
auto p = env.signature->getFnDef(symbIdx);
TermStack defArgs; // no type arguments (yet) in this case
defArgs.push(lhs);
defArgs.push(rhs);
lit = Literal::create(p,defArgs.size(),true,false,defArgs.begin());
} else {
lit = Literal::createEquality(true,lhs,rhs,decl.rangeSort);
}
} else {
auto p = env.signature->getBoolDef(symbIdx);
Formula* frm = new AtomicFormula(Literal::create(p,decl.args.size(),true,false,decl.args.begin()));
TermList lhs(Term::createFormula(frm));
lit = Literal::createEquality(true,lhs,rhs,decl.rangeSort);
if (shouldCreateFunctionDefinition(symbIdx)) {
auto p = env.signature->getBoolDef(symbIdx);
lit = Literal::create(p,decl.args.size(),true,false,decl.args.begin());
} else {
lit = Literal::create(symbIdx,decl.args.size(),true,false,decl.args.begin());
}
TermList lhs(Term::createFormula(new AtomicFormula(lit)));
lit = Literal::createEquality(true, lhs, rhs, decl.rangeSort);
}
Formula* fla = new AtomicFormula(lit);

Expand Down
8 changes: 5 additions & 3 deletions Shell/Preprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,11 @@ void Preprocess::preprocess(Problem& prb)
resolver.apply(prb);
}

auto fnDefHandler = new FunctionDefinitionHandler();
fnDefHandler->preprocess(prb);
prb.addFunctionDefinitionHandler(fnDefHandler);
if (_options.functionDefinitionRewriting() || _options.structInduction()==Options::StructuralInductionKind::RECURSION) {
auto fnDefHandler = new FunctionDefinitionHandler();
fnDefHandler->preprocess(prb);
prb.addFunctionDefinitionHandler(fnDefHandler);
}

if (_options.generalSplitting()) {
if (prb.isHigherOrder() || prb.hasPolymorphicSym()) { // TODO: extend GeneralSplitting to support polymorphism (would higher-order make sense?)
Expand Down

0 comments on commit 7565a92

Please sign in to comment.