summaryrefslogtreecommitdiff
path: root/src/theory/bags/infer_info.cpp
blob: 1244a43ac08d8935b264dac78859ac2c22f4059b (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
/*********************                                                        */
/*! \file infer_info.cpp
 ** \verbatim
 ** Top contributors (to current version):
 **   Mudathir Mohamed
 ** 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 Implementation of inference information utility.
 **/

#include "theory/bags/infer_info.h"

#include "theory/bags/inference_manager.h"

namespace CVC4 {
namespace theory {
namespace bags {

const char* toString(Inference i)
{
  switch (i)
  {
    case Inference::NONE: return "NONE";
    case Inference::BAG_MK_BAG: return "BAG_MK_BAG";
    case Inference::BAG_EQUALITY: return "BAG_EQUALITY";
    case Inference::BAG_DISEQUALITY: return "BAG_DISEQUALITY";
    case Inference::BAG_EMPTY: return "BAG_EMPTY";
    case Inference::BAG_UNION_DISJOINT: return "BAG_UNION_DISJOINT";
    case Inference::BAG_UNION_MAX: return "BAG_UNION_MAX";
    case Inference::BAG_INTERSECTION_MIN: return "BAG_INTERSECTION_MIN";
    case Inference::BAG_DIFFERENCE_SUBTRACT: return "BAG_DIFFERENCE_SUBTRACT";
    case Inference::BAG_DIFFERENCE_REMOVE: return "BAG_DIFFERENCE_REMOVE";
    case Inference::BAG_DUPLICATE_REMOVAL: return "BAG_DUPLICATE_REMOVAL";
    default: return "?";
  }
}

std::ostream& operator<<(std::ostream& out, Inference i)
{
  out << toString(i);
  return out;
}

InferInfo::InferInfo() : d_id(Inference::NONE) {}

bool InferInfo::process(TheoryInferenceManager* im, bool asLemma)
{
  Node lemma = d_conclusion;
  if (d_premises.size() >= 2)
  {
    Node andNode = NodeManager::currentNM()->mkNode(kind::AND, d_premises);
    lemma = andNode.impNode(lemma);
  }
  else if (d_premises.size() == 1)
  {
    lemma = d_premises[0].impNode(lemma);
  }
  if (asLemma)
  {
    TrustNode trustedLemma = TrustNode::mkTrustLemma(lemma, nullptr);
    return im->trustedLemma(trustedLemma);
  }
  Unimplemented();
}

bool InferInfo::isTrivial() const
{
  Assert(!d_conclusion.isNull());
  return d_conclusion.isConst() && d_conclusion.getConst<bool>();
}

bool InferInfo::isConflict() const
{
  Assert(!d_conclusion.isNull());
  return d_conclusion.isConst() && !d_conclusion.getConst<bool>();
}

bool InferInfo::isFact() const
{
  Assert(!d_conclusion.isNull());
  TNode atom =
      d_conclusion.getKind() == kind::NOT ? d_conclusion[0] : d_conclusion;
  return !atom.isConst() && atom.getKind() != kind::OR;
}

Node InferInfo::getPremises() const
{
  // d_noExplain is a subset of d_ant
  NodeManager* nm = NodeManager::currentNM();
  return nm->mkAnd(d_premises);
}

std::ostream& operator<<(std::ostream& out, const InferInfo& ii)
{
  out << "(infer " << ii.d_id << " " << ii.d_conclusion << std::endl;
  if (!ii.d_premises.empty())
  {
    out << " :premise (" << ii.d_premises << ")" << std::endl;
  }

  out << ")";
  return out;
}

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