A proof is represented as a string in GetProofCommand. The string is generated by the custom ways in which the SMT engine may choose to print the proof, based on proof-format-mode (to be added in subsequent commits).
<< "Cannot get specialized constructor type for non-datatype type "
<< retSort;
CVC4_API_SOLVER_TRY_CATCH_BEGIN;
-
+
NodeManager* nm = d_solver->getNodeManager();
Node ret =
nm->mkNode(kind::APPLY_TYPE_ASCRIPTION,
GetProofCommand::GetProofCommand() {}
void GetProofCommand::invoke(api::Solver* solver, SymbolManager* sm)
{
- Unimplemented() << "Unimplemented get-proof\n";
+ try
+ {
+ d_result = solver->getSmtEngine()->getProof();
+ d_commandStatus = CommandSuccess::instance();
+ }
+ catch (api::CVC4ApiRecoverableException& e)
+ {
+ d_commandStatus = new CommandRecoverableFailure(e.what());
+ }
+ catch (exception& e)
+ {
+ d_commandStatus = new CommandFailure(e.what());
+ }
+}
+
+void GetProofCommand::printResult(std::ostream& out, uint32_t verbosity) const
+{
+ if (ok())
+ {
+ out << d_result;
+ }
+ else
+ {
+ this->Command::printResult(out, verbosity);
+ }
}
Command* GetProofCommand::clone() const
GetProofCommand();
void invoke(api::Solver* solver, SymbolManager* sm) override;
+
+ void printResult(std::ostream& out, uint32_t verbosity = 2) const override;
+
Command* clone() const override;
std::string getCommandName() const override;
void toStream(
int toDepth = -1,
size_t dag = 1,
OutputLanguage language = language::output::LANG_AUTO) const override;
+
+ private:
+ /** the result of the getProof call */
+ std::string d_result;
}; /* class GetProofCommand */
class CVC4_PUBLIC GetInstantiationsCommand : public Command
Trace("smt-proof") << "SmtEngine::setFinalProof(): finished.\n";
}
-void PfManager::printProof(std::shared_ptr<ProofNode> pfn,
+void PfManager::printProof(std::ostream& out,
+ std::shared_ptr<ProofNode> pfn,
Assertions& as,
DefinedFunctionMap& df)
{
std::shared_ptr<ProofNode> fp = getFinalProof(pfn, as, df);
// TODO (proj #37) according to the proof format, post process the proof node
// TODO (proj #37) according to the proof format, print the proof node
- std::ostream& out = *options::out();
out << "(proof\n";
out << *fp;
out << "\n)\n";
PfManager(context::UserContext* u, SmtEngine* smte);
~PfManager();
/**
- * Print the proof on the output channel of the current options in scope.
+ * Print the proof on the given output stream.
*
* The argument pfn is the proof for false in the current context.
*
* function map correspond to equalities of the form (= f (lambda (...) t)),
* which are considered assertions in the final proof.
*/
- void printProof(std::shared_ptr<ProofNode> pfn,
+ void printProof(std::ostream& out,
+ std::shared_ptr<ProofNode> pfn,
Assertions& as,
DefinedFunctionMap& df);
/**
Trace("smt") << "SmtEngine::" << (isEntailmentCheck ? "query" : "checkSat")
<< "(" << assumptions << ") => " << r << endl;
- if (options::dumpProofs() && options::proofNew()
- && r.asSatisfiabilityResult().isSat() == Result::UNSAT)
- {
- printProof();
- }
-
// Check that SAT results generate a model correctly.
if(options::checkModels()) {
if (r.asSatisfiabilityResult().isSat() == Result::SAT)
return getUnsatCoreInternal();
}
-void SmtEngine::printProof()
+std::string SmtEngine::getProof()
{
- if (d_pfManager == nullptr)
+ Trace("smt") << "SMT getProof()\n";
+ SmtScope smts(this);
+ finishInit();
+ if (Dump.isOn("benchmark"))
{
- throw RecoverableModalException("Cannot print proof, no proof manager.");
+ getOutputManager().getPrinter().toStreamCmdGetProof(
+ getOutputManager().getDumpOut());
}
- if (getSmtMode() != SmtMode::UNSAT)
+#if IS_PROOFS_BUILD
+ if (!options::proofNew())
+ {
+ throw ModalException("Cannot get a proof when proof-new option is off.");
+ }
+ if (d_state->getMode() != SmtMode::UNSAT)
{
throw RecoverableModalException(
- "Cannot print proof unless immediately preceded by "
- "UNSAT/ENTAILED.");
+ "Cannot get a proof unless immediately preceded by "
+ "UNSAT/ENTAILED response.");
}
+ // the prop engine has the proof of false
PropEngine* pe = getPropEngine();
Assert(pe != nullptr);
Assert(pe->getProof() != nullptr);
- // the prop engine has the proof of false
- d_pfManager->printProof(pe->getProof(), *d_asserts, *d_definedFunctions);
+ Assert(d_pfManager);
+ std::ostringstream ss;
+ d_pfManager->printProof(ss, pe->getProof(), *d_asserts, *d_definedFunctions);
+ return ss.str();
+#else /* IS_PROOFS_BUILD */
+ throw ModalException("This build of CVC4 doesn't have proof support.");
+#endif /* IS_PROOFS_BUILD */
}
void SmtEngine::printInstantiations( std::ostream& out ) {
*/
UnsatCore getUnsatCore();
+ /**
+ * Get a refutation proof (only if immediately preceded by an UNSAT or
+ * ENTAILED query). Only permitted if CVC4 was built with proof support and
+ * the proof option is on. */
+ std::string getProof();
+
/**
* Get the current set of assertions. Only permitted if the
* SmtEngine is set to operate interactively.