GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/theory_quantifiers.cpp Lines: 69 73 94.5 %
Date: 2021-09-17 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
9942
TheoryQuantifiers::TheoryQuantifiers(Env& env,
34
                                     OutputChannel& out,
35
9942
                                     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
9942
      d_qengine(nullptr)
43
{
44
  // construct the quantifiers engine
45
19884
  d_qengine.reset(
46
9942
      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
9942
  d_theoryState = &d_qstate;
50
  // use the inference manager as the official inference manager
51
9942
  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
9942
  d_quantEngine = d_qengine.get();
56
57
9942
  if (options::macrosQuant())
58
  {
59
22
    d_qmacros.reset(new QuantifiersMacros(d_qreg));
60
  }
61
9942
}
62
63
19878
TheoryQuantifiers::~TheoryQuantifiers() {
64
19878
}
65
66
9942
TheoryRewriter* TheoryQuantifiers::getTheoryRewriter() { return &d_rewriter; }
67
68
3796
ProofRuleChecker* TheoryQuantifiers::getProofChecker() { return &d_checker; }
69
70
9942
void TheoryQuantifiers::finishInit()
71
{
72
  // quantifiers are not evaluated in getModelValue
73
9942
  d_valuation.setUnevaluatedKind(EXISTS);
74
9942
  d_valuation.setUnevaluatedKind(FORALL);
75
  // witness is used in several instantiation strategies
76
9942
  d_valuation.setUnevaluatedKind(WITNESS);
77
9942
}
78
79
9942
bool TheoryQuantifiers::needsEqualityEngine(EeSetupInfo& esi)
80
{
81
  // use the master equality engine
82
9942
  esi.d_useMaster = true;
83
9942
  return true;
84
}
85
86
31978
void TheoryQuantifiers::preRegisterTerm(TNode n)
87
{
88
31978
  if (n.getKind() != FORALL)
89
  {
90
    return;
91
  }
92
63956
  Debug("quantifiers-prereg")
93
31978
      << "TheoryQuantifiers::preRegisterTerm() " << n << std::endl;
94
  // Preregister the quantified formula.
95
  // This initializes the modules used for handling n in this user context.
96
31979
  getQuantifiersEngine()->preRegisterQuantifier(n);
97
63954
  Debug("quantifiers-prereg")
98
31977
      << "TheoryQuantifiers::preRegisterTerm() done " << n << std::endl;
99
}
100
101
102
15264
void TheoryQuantifiers::presolve() {
103
15264
  Debug("quantifiers-presolve") << "TheoryQuantifiers::presolve()" << std::endl;
104
15264
  if( getQuantifiersEngine() ){
105
8211
    getQuantifiersEngine()->presolve();
106
  }
107
15264
}
108
109
13395
Theory::PPAssertStatus TheoryQuantifiers::ppAssert(
110
    TrustNode tin, TrustSubstitutionMap& outSubstitutions)
111
{
112
13395
  if (d_qmacros != nullptr)
113
  {
114
    bool reqGround =
115
34
        options::macrosQuantMode() != options::MacrosQuantMode::ALL;
116
52
    Node eq = d_qmacros->solve(tin.getProven(), reqGround);
117
34
    if (!eq.isNull())
118
    {
119
      // must be legal
120
16
      if (isLegalElimination(eq[0], eq[1]))
121
      {
122
16
        outSubstitutions.addSubstitution(eq[0], eq[1]);
123
16
        return Theory::PP_ASSERT_STATUS_SOLVED;
124
      }
125
    }
126
  }
127
13379
  return Theory::PP_ASSERT_STATUS_UNSOLVED;
128
}
129
13792
void TheoryQuantifiers::ppNotifyAssertions(
130
    const std::vector<Node>& assertions) {
131
27584
  Trace("quantifiers-presolve")
132
13792
      << "TheoryQuantifiers::ppNotifyAssertions" << std::endl;
133
13792
  if (getQuantifiersEngine()) {
134
8167
    getQuantifiersEngine()->ppNotifyAssertions(assertions);
135
  }
136
13792
}
137
138
13000
bool TheoryQuantifiers::collectModelValues(TheoryModel* m,
139
                                           const std::set<Node>& termSet)
140
{
141
42476
  for(assertions_iterator i = facts_begin(); i != facts_end(); ++i) {
142
29476
    if ((*i).d_assertion.getKind() == NOT)
143
    {
144
8276
      Debug("quantifiers::collectModelInfo")
145
4138
          << "got quant FALSE: " << (*i).d_assertion[0] << std::endl;
146
4138
      if (!m->assertPredicate((*i).d_assertion[0], false))
147
      {
148
        return false;
149
      }
150
    }
151
    else
152
    {
153
50676
      Debug("quantifiers::collectModelInfo")
154
25338
          << "got quant TRUE : " << *i << std::endl;
155
25338
      if (!m->assertPredicate(*i, true))
156
      {
157
        return false;
158
      }
159
    }
160
  }
161
13000
  return true;
162
}
163
164
86952
void TheoryQuantifiers::postCheck(Effort level)
165
{
166
  // call the quantifiers engine to check
167
86952
  getQuantifiersEngine()->check(level);
168
86952
}
169
170
89058
bool TheoryQuantifiers::preNotifyFact(
171
    TNode atom, bool polarity, TNode fact, bool isPrereg, bool isInternal)
172
{
173
89058
  Kind k = atom.getKind();
174
89058
  if (k == FORALL)
175
  {
176
89058
    getQuantifiersEngine()->assertQuantifier(atom, polarity);
177
  }
178
  else
179
  {
180
    Unhandled() << "Unexpected fact " << fact;
181
  }
182
  // don't use equality engine, always return true
183
89058
  return true;
184
}
185
186
}  // namespace quantifiers
187
}  // namespace theory
188
29577
}  // namespace cvc5