1 /********************* */
2 /*! \file lfsc_proof_printer.cpp
4 ** Top contributors (to current version):
5 ** Andres Noetzli, Alex Ozdemir, Liana Hadarean
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2019 by the authors listed in the file AUTHORS
8 ** in the top-level source directory) and their institutional affiliations.
9 ** All rights reserved. See the file COPYING in the top-level source
10 ** directory for licensing information.\endverbatim
12 ** \brief Prints proofs in the LFSC format
14 ** Prints proofs in the LFSC format.
17 #include "proof/lfsc_proof_printer.h"
23 #include "prop/bvminisat/core/Solver.h"
24 #include "prop/minisat/core/Solver.h"
29 template <class Solver
>
30 std::string
LFSCProofPrinter::clauseName(TSatProof
<Solver
>* satProof
,
33 std::ostringstream os
;
34 if (satProof
->isInputClause(id
))
36 os
<< ProofManager::getInputClauseName(id
, satProof
->getName());
38 else if (satProof
->isLemmaClause(id
))
40 os
<< ProofManager::getLemmaClauseName(id
, satProof
->getName());
44 os
<< ProofManager::getLearntClauseName(id
, satProof
->getName());
49 template <class Solver
>
50 void LFSCProofPrinter::printResolution(TSatProof
<Solver
>* satProof
,
55 out
<< "(satlem_simplify _ _ _";
58 const ResChain
<Solver
>& res
= satProof
->getResolutionChain(id
);
59 const typename ResChain
<Solver
>::ResSteps
& steps
= res
.getSteps();
61 for (int i
= steps
.size() - 1; i
>= 0; i
--)
64 out
<< (steps
[i
].sign
? "R" : "Q") << " _ _";
67 ClauseId start_id
= res
.getStart();
68 out
<< " " << clauseName(satProof
, start_id
);
70 for (unsigned i
= 0; i
< steps
.size(); i
++)
73 prop::MinisatSatSolver::toSatVariable(var(steps
[i
].lit
));
74 out
<< " " << clauseName(satProof
, steps
[i
].id
) << " "
75 << ProofManager::getVarName(v
, satProof
->getName()) << ")";
78 if (id
== satProof
->getEmptyClauseId())
80 out
<< " (\\ empty empty)";
84 out
<< " (\\ " << clauseName(satProof
, id
) << "\n"; // bind to lemma name
88 template <class Solver
>
89 void LFSCProofPrinter::printAssumptionsResolution(TSatProof
<Solver
>* satProof
,
94 Assert(satProof
->isAssumptionConflict(id
));
95 // print the resolution proving the assumption conflict
96 printResolution(satProof
, id
, out
, paren
);
97 // resolve out assumptions to prove empty clause
98 out
<< "(satlem_simplify _ _ _ ";
99 const std::vector
<typename
Solver::TLit
>& confl
=
100 *(satProof
->getAssumptionConflicts().at(id
));
102 Assert(confl
.size());
104 for (unsigned i
= 0; i
< confl
.size(); ++i
)
106 prop::SatLiteral lit
= toSatLiteral
<Solver
>(confl
[i
]);
108 out
<< (lit
.isNegated() ? "Q" : "R") << " _ _ ";
111 out
<< clauseName(satProof
, id
) << " ";
112 for (int i
= confl
.size() - 1; i
>= 0; --i
)
114 prop::SatLiteral lit
= toSatLiteral
<Solver
>(confl
[i
]);
115 prop::SatVariable v
= lit
.getSatVariable();
116 out
<< "unit" << v
<< " ";
117 out
<< ProofManager::getVarName(v
, satProof
->getName()) << ")";
123 template <class Solver
>
124 void LFSCProofPrinter::printResolutions(TSatProof
<Solver
>* satProof
,
128 Debug("bv-proof") << "; print resolutions" << std::endl
;
129 std::set
<ClauseId
>::iterator it
= satProof
->getSeenLearnt().begin();
130 for (; it
!= satProof
->getSeenLearnt().end(); ++it
)
132 if (*it
!= satProof
->getEmptyClauseId())
134 Debug("bv-proof") << "; print resolution for " << *it
<< std::endl
;
135 printResolution(satProof
, *it
, out
, paren
);
138 Debug("bv-proof") << "; done print resolutions" << std::endl
;
141 template <class Solver
>
142 void LFSCProofPrinter::printResolutionEmptyClause(TSatProof
<Solver
>* satProof
,
146 printResolution(satProof
, satProof
->getEmptyClauseId(), out
, paren
);
149 void LFSCProofPrinter::printSatInputProof(const std::vector
<ClauseId
>& clauses
,
151 const std::string
& namingPrefix
)
153 for (auto i
= clauses
.begin(), end
= clauses
.end(); i
!= end
; ++i
)
155 out
<< "\n (cnfc_proof _ _ _ "
156 << ProofManager::getInputClauseName(*i
, namingPrefix
) << " ";
159 std::fill_n(std::ostream_iterator
<char>(out
), clauses
.size(), ')');
162 void LFSCProofPrinter::printCMapProof(const std::vector
<ClauseId
>& clauses
,
164 const std::string
& namingPrefix
)
166 for (size_t i
= 0, n
= clauses
.size(); i
< n
; ++i
)
168 out
<< "\n (CMapc_proof " << (i
+ 1) << " _ _ _ "
169 << ProofManager::getInputClauseName(clauses
[i
], namingPrefix
) << " ";
171 out
<< "CMapn_proof";
172 std::fill_n(std::ostream_iterator
<char>(out
), clauses
.size(), ')');
175 void LFSCProofPrinter::printSatClause(const prop::SatClause
& clause
,
177 const std::string
& namingPrefix
)
179 for (auto i
= clause
.cbegin(); i
!= clause
.cend(); ++i
)
181 out
<< "(clc " << (i
->isNegated() ? "(neg " : "(pos ")
182 << ProofManager::getVarName(i
->getSatVariable(), namingPrefix
) << ") ";
185 std::fill_n(std::ostream_iterator
<char>(out
), clause
.size(), ')');
188 // Template specializations
189 template void LFSCProofPrinter::printAssumptionsResolution(
190 TSatProof
<CVC4::Minisat::Solver
>* satProof
,
193 std::ostream
& paren
);
194 template void LFSCProofPrinter::printResolutions(
195 TSatProof
<CVC4::Minisat::Solver
>* satProof
,
197 std::ostream
& paren
);
198 template void LFSCProofPrinter::printResolutionEmptyClause(
199 TSatProof
<CVC4::Minisat::Solver
>* satProof
,
201 std::ostream
& paren
);
203 template void LFSCProofPrinter::printAssumptionsResolution(
204 TSatProof
<CVC4::BVMinisat::Solver
>* satProof
,
207 std::ostream
& paren
);
208 template void LFSCProofPrinter::printResolutions(
209 TSatProof
<CVC4::BVMinisat::Solver
>* satProof
,
211 std::ostream
& paren
);
212 template void LFSCProofPrinter::printResolutionEmptyClause(
213 TSatProof
<CVC4::BVMinisat::Solver
>* satProof
,
215 std::ostream
& paren
);