GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/theory_quantifiers.cpp Lines: 69 73 94.5 %
Date: 2021-09-29 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
6271
TheoryQuantifiers::TheoryQuantifiers(Env& env,
34
                                     OutputChannel& out,
35
6271
                                     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
6271
      d_qengine(nullptr)
43
{
44
  // construct the quantifiers engine
45
12542
  d_qengine.reset(
46
6271
      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
6271
  d_theoryState = &d_qstate;
50
  // use the inference manager as the official inference manager
51
6271
  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
6271
  d_quantEngine = d_qengine.get();
56
57
6271
  if (options::macrosQuant())
58
  {
59
10
    d_qmacros.reset(new QuantifiersMacros(d_qreg));
60
  }
61
6271
}
62
63
12536
TheoryQuantifiers::~TheoryQuantifiers() {
64
12536
}
65
66
6271
TheoryRewriter* TheoryQuantifiers::getTheoryRewriter() { return &d_rewriter; }
67
68
143
ProofRuleChecker* TheoryQuantifiers::getProofChecker() { return &d_checker; }
69
70
6271
void TheoryQuantifiers::finishInit()
71
{
72
  // quantifiers are not evaluated in getModelValue
73
6271
  d_valuation.setUnevaluatedKind(EXISTS);
74
6271
  d_valuation.setUnevaluatedKind(FORALL);
75
  // witness is used in several instantiation strategies
76
6271
  d_valuation.setUnevaluatedKind(WITNESS);
77
6271
}
78
79
6271
bool TheoryQuantifiers::needsEqualityEngine(EeSetupInfo& esi)
80
{
81
  // use the master equality engine
82
6271
  esi.d_useMaster = true;
83
6271
  return true;
84
}
85
86
12580
void TheoryQuantifiers::preRegisterTerm(TNode n)
87
{
88
12580
  if (n.getKind() != FORALL)
89
  {
90
    return;
91
  }
92
25160
  Debug("quantifiers-prereg")
93
12580
      << "TheoryQuantifiers::preRegisterTerm() " << n << std::endl;
94
  // Preregister the quantified formula.
95
  // This initializes the modules used for handling n in this user context.
96
12581
  getQuantifiersEngine()->preRegisterQuantifier(n);
97
25158
  Debug("quantifiers-prereg")
98
12579
      << "TheoryQuantifiers::preRegisterTerm() done " << n << std::endl;
99
}
100
101
102
9354
void TheoryQuantifiers::presolve() {
103
9354
  Debug("quantifiers-presolve") << "TheoryQuantifiers::presolve()" << std::endl;
104
9354
  if( getQuantifiersEngine() ){
105
5716
    getQuantifiersEngine()->presolve();
106
  }
107
9354
}
108
109
7983
Theory::PPAssertStatus TheoryQuantifiers::ppAssert(
110
    TrustNode tin, TrustSubstitutionMap& outSubstitutions)
111
{
112
7983
  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
7972
  return Theory::PP_ASSERT_STATUS_UNSOLVED;
128
}
129
8532
void TheoryQuantifiers::ppNotifyAssertions(
130
    const std::vector<Node>& assertions) {
131
17064
  Trace("quantifiers-presolve")
132
8532
      << "TheoryQuantifiers::ppNotifyAssertions" << std::endl;
133
8532
  if (getQuantifiersEngine()) {
134
5672
    getQuantifiersEngine()->ppNotifyAssertions(assertions);
135
  }
136
8532
}
137
138
10717
bool TheoryQuantifiers::collectModelValues(TheoryModel* m,
139
                                           const std::set<Node>& termSet)
140
{
141
31342
  for(assertions_iterator i = facts_begin(); i != facts_end(); ++i) {
142
20625
    if ((*i).d_assertion.getKind() == NOT)
143
    {
144
4680
      Debug("quantifiers::collectModelInfo")
145
2340
          << "got quant FALSE: " << (*i).d_assertion[0] << std::endl;
146
2340
      if (!m->assertPredicate((*i).d_assertion[0], false))
147
      {
148
        return false;
149
      }
150
    }
151
    else
152
    {
153
36570
      Debug("quantifiers::collectModelInfo")
154
18285
          << "got quant TRUE : " << *i << std::endl;
155
18285
      if (!m->assertPredicate(*i, true))
156
      {
157
        return false;
158
      }
159
    }
160
  }
161
10717
  return true;
162
}
163
164
39105
void TheoryQuantifiers::postCheck(Effort level)
165
{
166
  // call the quantifiers engine to check
167
39105
  getQuantifiersEngine()->check(level);
168
39105
}
169
170
21036
bool TheoryQuantifiers::preNotifyFact(
171
    TNode atom, bool polarity, TNode fact, bool isPrereg, bool isInternal)
172
{
173
21036
  Kind k = atom.getKind();
174
21036
  if (k == FORALL)
175
  {
176
21036
    getQuantifiersEngine()->assertQuantifier(atom, polarity);
177
  }
178
  else
179
  {
180
    Unhandled() << "Unexpected fact " << fact;
181
  }
182
  // don't use equality engine, always return true
183
21036
  return true;
184
}
185
186
}  // namespace quantifiers
187
}  // namespace theory
188
22746
}  // namespace cvc5