summaryrefslogtreecommitdiff
path: root/src/proof/lfsc_proof_printer.cpp
blob: e1fa3acdb17170c77b6d3caa9e2a7197ba2886d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*********************                                                        */
/*! \file lfsc_proof_printer.cpp
 ** \verbatim
 ** Top contributors (to current version):
 **   Andres Noetzli
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2018 by the authors listed in the file AUTHORS
 ** in the top-level source directory) and their institutional affiliations.
 ** All rights reserved.  See the file COPYING in the top-level source
 ** directory for licensing information.\endverbatim
 **
 ** \brief Prints proofs in the LFSC format
 **
 ** Prints proofs in the LFSC format.
 **/

#include "proof/lfsc_proof_printer.h"

#include <iostream>

#include "prop/bvminisat/core/Solver.h"
#include "prop/minisat/core/Solver.h"

namespace CVC4 {
namespace proof {

template <class Solver>
std::string LFSCProofPrinter::clauseName(TSatProof<Solver>* satProof,
                                         ClauseId id)
{
  std::ostringstream os;
  if (satProof->isInputClause(id))
  {
    os << ProofManager::getInputClauseName(id, satProof->getName());
  }
  else if (satProof->isLemmaClause(id))
  {
    os << ProofManager::getLemmaClauseName(id, satProof->getName());
  }
  else
  {
    os << ProofManager::getLearntClauseName(id, satProof->getName());
  }
  return os.str();
}

template <class Solver>
void LFSCProofPrinter::printResolution(TSatProof<Solver>* satProof,
                                       ClauseId id,
                                       std::ostream& out,
                                       std::ostream& paren)
{
  out << "(satlem_simplify _ _ _";
  paren << ")";

  const ResChain<Solver>& res = satProof->getResolutionChain(id);
  const typename ResChain<Solver>::ResSteps& steps = res.getSteps();

  for (int i = steps.size() - 1; i >= 0; i--)
  {
    out << " (";
    out << (steps[i].sign ? "R" : "Q") << " _ _";
  }

  ClauseId start_id = res.getStart();
  out << " " << clauseName(satProof, start_id);

  for (unsigned i = 0; i < steps.size(); i++)
  {
    prop::SatVariable v =
        prop::MinisatSatSolver::toSatVariable(var(steps[i].lit));
    out << " " << clauseName(satProof, steps[i].id) << " "
        << ProofManager::getVarName(v, satProof->getName()) << ")";
  }

  if (id == satProof->getEmptyClauseId())
  {
    out << " (\\ empty empty)";
    return;
  }

  out << " (\\ " << clauseName(satProof, id) << "\n";  // bind to lemma name
  paren << ")";
}

template <class Solver>
void LFSCProofPrinter::printAssumptionsResolution(TSatProof<Solver>* satProof,
                                                  ClauseId id,
                                                  std::ostream& out,
                                                  std::ostream& paren)
{
  Assert(satProof->isAssumptionConflict(id));
  // print the resolution proving the assumption conflict
  printResolution(satProof, id, out, paren);
  // resolve out assumptions to prove empty clause
  out << "(satlem_simplify _ _ _ ";
  const std::vector<typename Solver::TLit>& confl =
      *(satProof->getAssumptionConflicts().at(id));

  Assert(confl.size());

  for (unsigned i = 0; i < confl.size(); ++i)
  {
    prop::SatLiteral lit = toSatLiteral<Solver>(confl[i]);
    out << "(";
    out << (lit.isNegated() ? "Q" : "R") << " _ _ ";
  }

  out << clauseName(satProof, id) << " ";
  for (int i = confl.size() - 1; i >= 0; --i)
  {
    prop::SatLiteral lit = toSatLiteral<Solver>(confl[i]);
    prop::SatVariable v = lit.getSatVariable();
    out << "unit" << v << " ";
    out << ProofManager::getVarName(v, satProof->getName()) << ")";
  }
  out << "(\\ e e)\n";
  paren << ")";
}

template <class Solver>
void LFSCProofPrinter::printResolutions(TSatProof<Solver>* satProof,
                                        std::ostream& out,
                                        std::ostream& paren)
{
  Debug("bv-proof") << "; print resolutions" << std::endl;
  std::set<ClauseId>::iterator it = satProof->getSeenLearnt().begin();
  for (; it != satProof->getSeenLearnt().end(); ++it)
  {
    if (*it != satProof->getEmptyClauseId())
    {
      Debug("bv-proof") << "; print resolution for " << *it << std::endl;
      printResolution(satProof, *it, out, paren);
    }
  }
  Debug("bv-proof") << "; done print resolutions" << std::endl;
}

template <class Solver>
void LFSCProofPrinter::printResolutionEmptyClause(TSatProof<Solver>* satProof,
                                                  std::ostream& out,
                                                  std::ostream& paren)
{
  printResolution(satProof, satProof->getEmptyClauseId(), out, paren);
}

// Template specializations
template void LFSCProofPrinter::printAssumptionsResolution(
    TSatProof<CVC4::Minisat::Solver>* satProof,
    ClauseId id,
    std::ostream& out,
    std::ostream& paren);
template void LFSCProofPrinter::printResolutions(
    TSatProof<CVC4::Minisat::Solver>* satProof,
    std::ostream& out,
    std::ostream& paren);
template void LFSCProofPrinter::printResolutionEmptyClause(
    TSatProof<CVC4::Minisat::Solver>* satProof,
    std::ostream& out,
    std::ostream& paren);

template void LFSCProofPrinter::printAssumptionsResolution(
    TSatProof<CVC4::BVMinisat::Solver>* satProof,
    ClauseId id,
    std::ostream& out,
    std::ostream& paren);
template void LFSCProofPrinter::printResolutions(
    TSatProof<CVC4::BVMinisat::Solver>* satProof,
    std::ostream& out,
    std::ostream& paren);
template void LFSCProofPrinter::printResolutionEmptyClause(
    TSatProof<CVC4::BVMinisat::Solver>* satProof,
    std::ostream& out,
    std::ostream& paren);
}  // namespace proof
}  // namespace CVC4
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback