GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/theory_quantifiers.cpp Lines: 69 73 94.5 %
Date: 2021-09-30 Branches: 91 174 52.3 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Morgan Deters, Tim King
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 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.
11
 * ****************************************************************************
12
 *
13
 * Implementation of the theory of quantifiers.
14
 */
15
16
#include "theory/quantifiers/theory_quantifiers.h"
17
18
#include "options/quantifiers_options.h"
19
#include "proof/proof_node_manager.h"
20
#include "theory/quantifiers/quantifiers_macros.h"
21
#include "theory/quantifiers/quantifiers_modules.h"
22
#include "theory/quantifiers/quantifiers_rewriter.h"
23
#include "theory/trust_substitutions.h"
24
#include "theory/valuation.h"
25
26
using namespace cvc5::kind;
27
using namespace cvc5::context;
28
29
namespace cvc5 {
30
namespace theory {
31
namespace quantifiers {
32
33
6278
TheoryQuantifiers::TheoryQuantifiers(Env& env,
34
                                     OutputChannel& out,
35
6278
                                     Valuation valuation)
36
    : Theory(THEORY_QUANTIFIERS, env, out, valuation),
37
      d_rewriter(env.getOptions()),
38
      d_qstate(env, valuation, logicInfo()),
39
      d_qreg(env),
40
      d_treg(env, d_qstate, d_qreg),
41
      d_qim(env, *this, d_qstate, d_qreg, d_treg, d_pnm),
42
6278
      d_qengine(nullptr)
43
{
44
  // construct the quantifiers engine
45
12556
  d_qengine.reset(
46
6278
      new QuantifiersEngine(env, d_qstate, d_qreg, d_treg, d_qim, d_pnm));
47
48
  // indicate we are using the quantifiers theory state object
49
6278
  d_theoryState = &d_qstate;
50
  // use the inference manager as the official inference manager
51
6278
  d_inferManager = &d_qim;
52
  // Set the pointer to the quantifiers engine, which this theory owns. This
53
  // pointer will be retreived by TheoryEngine and set to all theories
54
  // post-construction.
55
6278
  d_quantEngine = d_qengine.get();
56
57
6278
  if (options::macrosQuant())
58
  {
59
10
    d_qmacros.reset(new QuantifiersMacros(d_qreg));
60
  }
61
6278
}
62
63
12550
TheoryQuantifiers::~TheoryQuantifiers() {
64
12550
}
65
66
6278
TheoryRewriter* TheoryQuantifiers::getTheoryRewriter() { return &d_rewriter; }
67
68
143
ProofRuleChecker* TheoryQuantifiers::getProofChecker() { return &d_checker; }
69
70
6278
void TheoryQuantifiers::finishInit()
71
{
72
  // quantifiers are not evaluated in getModelValue
73
6278
  d_valuation.setUnevaluatedKind(EXISTS);
74
6278
  d_valuation.setUnevaluatedKind(FORALL);
75
  // witness is used in several instantiation strategies
76
6278
  d_valuation.setUnevaluatedKind(WITNESS);
77
6278
}
78
79
6278
bool TheoryQuantifiers::needsEqualityEngine(EeSetupInfo& esi)
80
{
81
  // use the master equality engine
82
6278
  esi.d_useMaster = true;
83
6278
  return true;
84
}
85
86
12608
void TheoryQuantifiers::preRegisterTerm(TNode n)
87
{
88
12608
  if (n.getKind() != FORALL)
89
  {
90
    return;
91
  }
92
25216
  Debug("quantifiers-prereg")
93
12608
      << "TheoryQuantifiers::preRegisterTerm() " << n << std::endl;
94
  // Preregister the quantified formula.
95
  // This initializes the modules used for handling n in this user context.
96
12609
  getQuantifiersEngine()->preRegisterQuantifier(n);
97
25214
  Debug("quantifiers-prereg")
98
12607
      << "TheoryQuantifiers::preRegisterTerm() done " << n << std::endl;
99
}
100
101
102
9363
void TheoryQuantifiers::presolve() {
103
9363
  Debug("quantifiers-presolve") << "TheoryQuantifiers::presolve()" << std::endl;
104
9363
  if( getQuantifiersEngine() ){
105
5725
    getQuantifiersEngine()->presolve();
106
  }
107
9363
}
108
109
7986
Theory::PPAssertStatus TheoryQuantifiers::ppAssert(
110
    TrustNode tin, TrustSubstitutionMap& outSubstitutions)
111
{
112
7986
  if (d_qmacros != nullptr)
113
  {
114
    bool reqGround =
115
21
        options::macrosQuantMode() != options::MacrosQuantMode::ALL;
116
31
    Node eq = d_qmacros->solve(tin.getProven(), reqGround);
117
21
    if (!eq.isNull())
118
    {
119
      // must be legal
120
11
      if (isLegalElimination(eq[0], eq[1]))
121
      {
122
11
        outSubstitutions.addSubstitution(eq[0], eq[1]);
123
11
        return Theory::PP_ASSERT_STATUS_SOLVED;
124
      }
125
    }
126
  }
127
7975
  return Theory::PP_ASSERT_STATUS_UNSOLVED;
128
}
129
8541
void TheoryQuantifiers::ppNotifyAssertions(
130
    const std::vector<Node>& assertions) {
131
17082
  Trace("quantifiers-presolve")
132
8541
      << "TheoryQuantifiers::ppNotifyAssertions" << std::endl;
133
8541
  if (getQuantifiersEngine()) {
134
5681
    getQuantifiersEngine()->ppNotifyAssertions(assertions);
135
  }
136
8541
}
137
138
10734
bool TheoryQuantifiers::collectModelValues(TheoryModel* m,
139
                                           const std::set<Node>& termSet)
140
{
141
31397
  for(assertions_iterator i = facts_begin(); i != facts_end(); ++i) {
142
20663
    if ((*i).d_assertion.getKind() == NOT)
143
    {
144
4702
      Debug("quantifiers::collectModelInfo")
145
2351
          << "got quant FALSE: " << (*i).d_assertion[0] << std::endl;
146
2351
      if (!m->assertPredicate((*i).d_assertion[0], false))
147
      {
148
        return false;
149
      }
150
    }
151
    else
152
    {
153
36624
      Debug("quantifiers::collectModelInfo")
154
18312
          << "got quant TRUE : " << *i << std::endl;
155
18312
      if (!m->assertPredicate(*i, true))
156
      {
157
        return false;
158
      }
159
    }
160
  }
161
10734
  return true;
162
}
163
164
39493
void TheoryQuantifiers::postCheck(Effort level)
165
{
166
  // call the quantifiers engine to check
167
39493
  getQuantifiersEngine()->check(level);
168
39493
}
169
170
21052
bool TheoryQuantifiers::preNotifyFact(
171
    TNode atom, bool polarity, TNode fact, bool isPrereg, bool isInternal)
172
{
173
21052
  Kind k = atom.getKind();
174
21052
  if (k == FORALL)
175
  {
176
21052
    getQuantifiersEngine()->assertQuantifier(atom, polarity);
177
  }
178
  else
179
  {
180
    Unhandled() << "Unexpected fact " << fact;
181
  }
182
  // don't use equality engine, always return true
183
21052
  return true;
184
}
185
186
}  // namespace quantifiers
187
}  // namespace theory
188
22755
}  // namespace cvc5