summaryrefslogtreecommitdiff
path: root/src/proof/rewrite_proof.cpp
blob: e0b7c171ce1381b815ba87bbc669d0d1ffd3796b (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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*********************                                                        */
/*! \file rewrite_proof.cpp
 ** \verbatim
 ** Top contributors (to current version):
 **   Andres Noetzli
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2020 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 Representation of a rewrite proof
 **/

#include "proof/rewrite_proof.h"

#include "proof_manager.h"
#include "theory/rewriter.h"
#include "theory/rewriter/rules_printer.h"

namespace CVC4 {

RewriteStep::~RewriteStep()
{
  for (size_t i = 0; i < d_subproofs.size(); i++)
  {
    delete d_subproofs[i];
  }
}

void RewriteStep::deleteUncachedChildren()
{
  for (size_t i = 0; i < d_children.size(); i++)
  {
    if (d_children[i] != NULL)
    {
      d_children[i]->deleteUncachedChildren();
      if (!d_children[i]->d_cached_version_used)
      {
        delete d_children[i];
        d_children[i] = NULL;
      }
    }
  }
}

void RewriteStep::print(int tab) const
{
  /*
  for (int j = 0; j < tab; j++)
    std::cout << " ";
  std::cout << d_tag << " > " << d_original << " < " << std::endl;

  for (size_t i = 0; i < d_children.size(); i++) {
    d_children[i]->print(tab + 1);
    std::cout << std::endl;
  }
  */
}

RewriteProof::~RewriteProof()
{
  for (ProofCacheIterator iter = preRewriteCache.begin();
       iter != preRewriteCache.end();
       ++iter)
  {
    if (!iter->second->d_cached_version_used)
    {
      preRewriteCache[iter->first] = NULL;
    }
  }
  /*
  for (ProofCacheIterator iter = postRewriteCache.begin();
       iter != postRewriteCache.end(); ++iter) {
    if (!iter->second->d_cached_version_used) {
      postRewriteCache[iter->first] = NULL;
    }
  }*/

  for (size_t i = 0; i < d_rewrites.size(); i++)
  {
    d_rewrites[i]->deleteUncachedChildren();
    if (!d_rewrites[i]->d_cached_version_used)
    {
      delete d_rewrites[i];
    }
  }

  for (ProofCacheIterator iter = preRewriteCache.begin();
       iter != preRewriteCache.end();
       ++iter)
  {
    if (iter->second != NULL)
    {
      delete iter->second;
    }
  }
  /*
  for (ProofCacheIterator iter = postRewriteCache.begin();
       iter != postRewriteCache.end(); ++iter) {
    if (iter->second != NULL) {
      delete iter->second;
    }
  }*/
}

void RewriteProof::attachSubproofToParent()
{
  RewriteStep* topRewrite = d_rewrites.back();

  // Simplify proof
  if (topRewrite->d_tag == theory::rules::RewriteRule::NONE)
  {
    bool allChildrenRefl = true;
    for (size_t i = 0; i < topRewrite->d_children.size(); i++)
    {
      if (topRewrite->d_children[i]->d_tag != theory::rules::RewriteRule::NONE)
      {
        allChildrenRefl = false;
        break;
      }
    }
    if (allChildrenRefl)
    {
      topRewrite->d_children.clear();
    }
  }
  d_rewrites[d_rewrites.size() - 2]->d_children.push_back(d_rewrites.back());
  d_rewrites.pop_back();
}

RewriteStep* RewriteProof::getRewrite() const
{
  Assert(d_rewrites.size() == 1);
  return d_rewrites[0];
}

void RewriteProof::registerRewrite(theory::rules::RewriteRule tag,
                                   Node rewritten)
{
  RewriteStep* topRewrite = d_rewrites.back();
  d_rewrites.pop_back();
  RewriteStep* newRewrite = new RewriteStep(tag, topRewrite->d_original);
  newRewrite->d_children.push_back(topRewrite);
  newRewrite->d_rewritten = rewritten;
  d_rewrites.push_back(newRewrite);
}

void RewriteProof::registerSwap(const unsigned swap_id1,
                                const unsigned swap_id2)
{
  // Register swap if it does not swap head with head
  if (swap_id1 != swap_id2)
  {
    /*
    RewriteStep *topRewrite = d_rewrites.back();
    d_rewrites.pop_back();
    RewriteStep *newRewrite = new RewriteStep(SWAP, topRewrite->d_original);
    newRewrite->swap_id1 = swap_id1;
    newRewrite->swap_id2 = swap_id2;
    newRewrite->d_children.push_back(topRewrite);
    d_rewrites.push_back(newRewrite);
    */
  }
}

void RewriteProof::replaceRewrite(RewriteStep* rewrite)
{
  // XXX: make sure that this is always safe
  delete d_rewrites.back();
  d_rewrites.back() = rewrite;
}

RewriteStep* RewriteProof::getPreRewriteCache(Node node)
{
  return NULL;  // preRewriteCache[node];
}

RewriteStep* RewriteProof::getPostRewriteCache(Node node)
{
  return NULL;  // postRewriteCache[node];
}

void RewriteProof::setPreRewriteCache(Node node, RewriteStep* rewrite)
{
  preRewriteCache[node] = rewrite;
}

void RewriteProof::setPostRewriteCache(Node node, RewriteStep* rewrite)
{
  postRewriteCache[node] = rewrite;
}

void RewriteProof::printCachedProofs(TheoryProofEngine* tp,
                                     std::ostream& os,
                                     std::ostream& paren,
                                     ProofLetMap& globalLetMap) const
{
  for (ProofCacheIterator iter = preRewriteCache.begin();
       iter != preRewriteCache.end();
       ++iter)
  {
    if (iter->second->d_cached_version_used)
    {
      os << std::endl;
      os << "(@ let" << iter->second->d_id << " ";
      theory::rules::RewriteProofPrinter::printRewriteProof(
          false, tp, iter->second, os, globalLetMap);
      paren << ")";
    }
  }
}

}  // namespace CVC4
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback