GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/cegqi/inst_strategy_cegqi.cpp Lines: 263 281 93.6 %
Date: 2021-08-17 Branches: 467 976 47.8 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Morgan Deters, Aina Niemetz
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 counterexample-guided quantifier instantiation strategies.
14
 */
15
#include "theory/quantifiers/cegqi/inst_strategy_cegqi.h"
16
17
#include "expr/node_algorithm.h"
18
#include "expr/skolem_manager.h"
19
#include "options/quantifiers_options.h"
20
#include "theory/quantifiers/first_order_model.h"
21
#include "theory/quantifiers/instantiate.h"
22
#include "theory/quantifiers/quantifiers_attributes.h"
23
#include "theory/quantifiers/quantifiers_rewriter.h"
24
#include "theory/quantifiers/term_database.h"
25
#include "theory/quantifiers/term_registry.h"
26
#include "theory/quantifiers/term_util.h"
27
#include "theory/rewriter.h"
28
29
using namespace std;
30
using namespace cvc5::kind;
31
using namespace cvc5::context;
32
33
namespace cvc5 {
34
namespace theory {
35
namespace quantifiers {
36
37
6646
InstRewriterCegqi::InstRewriterCegqi(InstStrategyCegqi* p)
38
6646
    : InstantiationRewriter(), d_parent(p)
39
{
40
6646
}
41
42
131850
TrustNode InstRewriterCegqi::rewriteInstantiation(Node q,
43
                                                  std::vector<Node>& terms,
44
                                                  Node inst,
45
                                                  bool doVts)
46
{
47
131850
  return d_parent->rewriteInstantiation(q, terms, inst, doVts);
48
}
49
50
6646
InstStrategyCegqi::InstStrategyCegqi(QuantifiersState& qs,
51
                                     QuantifiersInferenceManager& qim,
52
                                     QuantifiersRegistry& qr,
53
6646
                                     TermRegistry& tr)
54
    : QuantifiersModule(qs, qim, qr, tr),
55
6646
      d_irew(new InstRewriterCegqi(this)),
56
      d_cbqi_set_quant_inactive(false),
57
      d_incomplete_check(false),
58
6646
      d_added_cbqi_lemma(qs.getUserContext()),
59
6646
      d_vtsCache(new VtsTermCache(qim)),
60
      d_bv_invert(nullptr),
61
      d_small_const_multiplier(
62
13292
          NodeManager::currentNM()->mkConst(Rational(1) / Rational(1000000))),
63
39876
      d_small_const(d_small_const_multiplier)
64
{
65
6646
  d_check_vts_lemma_lc = false;
66
6646
  if (options::cegqiBv())
67
  {
68
    // if doing instantiation for BV, need the inverter class
69
5080
    d_bv_invert.reset(new BvInverter);
70
  }
71
6646
  if (options::cegqiNestedQE())
72
  {
73
30
    d_nestedQe.reset(new NestedQe(qs.getUserContext()));
74
  }
75
6646
}
76
77
13292
InstStrategyCegqi::~InstStrategyCegqi() {}
78
79
76224
bool InstStrategyCegqi::needsCheck(Theory::Effort e)
80
{
81
76224
  return e>=Theory::EFFORT_LAST_CALL;
82
}
83
84
11622
QuantifiersModule::QEffort InstStrategyCegqi::needsModel(Theory::Effort e)
85
{
86
11622
  size_t nquant = d_treg.getModel()->getNumAssertedQuantifiers();
87
45540
  for (size_t i = 0; i < nquant; i++)
88
  {
89
72084
    Node q = d_treg.getModel()->getAssertedQuantifier(i);
90
38166
    if (doCbqi(q))
91
    {
92
4248
      return QEFFORT_STANDARD;
93
    }
94
  }
95
7374
  return QEFFORT_NONE;
96
}
97
98
1774
bool InstStrategyCegqi::registerCbqiLemma(Node q)
99
{
100
1774
  if( !hasAddedCbqiLemma( q ) ){
101
1612
    NodeManager* nm = NodeManager::currentNM();
102
1612
    d_added_cbqi_lemma.insert( q );
103
1612
    Trace("cegqi-debug") << "Do cbqi for " << q << std::endl;
104
    //add cbqi lemma
105
    //get the counterexample literal
106
3224
    Node ceLit = getCounterexampleLiteral(q);
107
3224
    Node ceBody = d_qreg.getInstConstantBody(q);
108
1612
    if( !ceBody.isNull() ){
109
      //add counterexample lemma
110
3224
      Node lem = NodeManager::currentNM()->mkNode( OR, ceLit.negate(), ceBody.negate() );
111
      //require any decision on cel to be phase=true
112
1612
      d_qim.addPendingPhaseRequirement(ceLit, true);
113
1612
      Debug("cegqi-debug") << "Require phase " << ceLit << " = true." << std::endl;
114
      //add counterexample lemma
115
1612
      lem = Rewriter::rewrite( lem );
116
1612
      Trace("cegqi-lemma") << "Counterexample lemma : " << lem << std::endl;
117
1613
      registerCounterexampleLemma( q, lem );
118
119
      //compute dependencies between quantified formulas
120
3222
      std::vector<Node> ics;
121
1611
      TermUtil::computeInstConstContains(q, ics);
122
1611
      d_parent_quant[q].clear();
123
1611
      d_children_quant[q].clear();
124
3222
      std::vector<Node> dep;
125
2055
      for (const Node& ic : ics)
126
      {
127
888
        Node qi = ic.getAttribute(InstConstantAttribute());
128
1332
        if (std::find(d_parent_quant[q].begin(), d_parent_quant[q].end(), qi)
129
1332
            == d_parent_quant[q].end())
130
        {
131
274
          d_parent_quant[q].push_back(qi);
132
274
          d_children_quant[qi].push_back(q);
133
          // may not have added the CEX lemma, but the literal is created by
134
          // the following call regardless. One rare case where this can happen
135
          // is if both sygus-inst and CEGQI are being run in parallel, and
136
          // a parent quantified formula is not handled by CEGQI, but a child
137
          // is.
138
548
          Node qicel = getCounterexampleLiteral(qi);
139
274
          dep.push_back(qi);
140
274
          dep.push_back(qicel);
141
        }
142
      }
143
1611
      if (!dep.empty())
144
      {
145
        // This lemma states that if the child is active, then the parent must
146
        // be asserted, in particular G => Q where G is the CEX literal for the
147
        // child and Q is the parent.
148
380
        Node dep_lemma = nm->mkNode(IMPLIES, ceLit, nm->mkNode(AND, dep));
149
380
        Trace("cegqi-lemma")
150
190
            << "Counterexample dependency lemma : " << dep_lemma << std::endl;
151
190
        d_qim.lemma(dep_lemma, InferenceId::QUANTIFIERS_CEGQI_CEX_DEP);
152
      }
153
154
      //must register all sub-quantifiers of counterexample lemma, register their lemmas
155
3222
      std::vector< Node > quants;
156
1611
      TermUtil::computeQuantContains( lem, quants );
157
1778
      for( unsigned i=0; i<quants.size(); i++ ){
158
167
        if( doCbqi( quants[i] ) ){
159
162
          registerCbqiLemma( quants[i] );
160
        }
161
      }
162
    }
163
    // The decision strategy for this quantified formula ensures that its
164
    // counterexample literal is decided on first. It is user-context dependent.
165
    std::map<Node, std::unique_ptr<DecisionStrategy>>::iterator itds =
166
1611
        d_dstrat.find(q);
167
1611
    DecisionStrategy* dlds = nullptr;
168
1611
    if (itds == d_dstrat.end())
169
    {
170
4833
      d_dstrat[q].reset(new DecisionStrategySingleton("CexLiteral",
171
                                                      ceLit,
172
1611
                                                      d_qstate.getSatContext(),
173
3222
                                                      d_qstate.getValuation()));
174
1611
      dlds = d_dstrat[q].get();
175
    }
176
    else
177
    {
178
      dlds = itds->second.get();
179
    }
180
    // it is appended to the list of strategies
181
1611
    d_qim.getDecisionManager()->registerStrategy(
182
        DecisionManager::STRAT_QUANT_CEGQI_FEASIBLE, dlds);
183
1611
    return true;
184
  }else{
185
162
    return false;
186
  }
187
}
188
189
27685
void InstStrategyCegqi::reset_round(Theory::Effort effort)
190
{
191
27685
  d_cbqi_set_quant_inactive = false;
192
27685
  d_incomplete_check = false;
193
27685
  d_active_quant.clear();
194
  //check if any cbqi lemma has not been added yet
195
27685
  FirstOrderModel* fm = d_treg.getModel();
196
27685
  size_t nquant = fm->getNumAssertedQuantifiers();
197
255779
  for (size_t i = 0; i < nquant; i++)
198
  {
199
456188
    Node q = fm->getAssertedQuantifier(i);
200
    //it is not active if it corresponds to a rewrite rule: we will process in rewrite engine
201
228094
    if( doCbqi( q ) ){
202
9107
      if (fm->isQuantifierActive(q))
203
      {
204
9107
        d_active_quant[q] = true;
205
9107
        Debug("cegqi-debug") << "Check quantified formula " << q << "..." << std::endl;
206
18214
        Node cel = getCounterexampleLiteral(q);
207
        bool value;
208
9107
        if (d_qstate.getValuation().hasSatValue(cel, value))
209
        {
210
9083
          Debug("cegqi-debug") << "...CE Literal has value " << value << std::endl;
211
9083
          if( !value ){
212
1401
            if (d_qstate.getValuation().isDecision(cel))
213
            {
214
              Trace("cegqi-warn") << "CBQI WARNING: Bad decision on CE Literal." << std::endl;
215
            }else{
216
1401
              Trace("cegqi") << "Inactive : " << q << std::endl;
217
1401
              fm->setQuantifierActive(q, false);
218
1401
              d_cbqi_set_quant_inactive = true;
219
1401
              d_active_quant.erase( q );
220
            }
221
          }
222
        }else{
223
24
          Debug("cegqi-debug") << "...CE Literal does not have value " << std::endl;
224
        }
225
      }
226
    }
227
  }
228
229
  //refinement: only consider innermost active quantified formulas
230
27685
  if( options::cegqiInnermost() ){
231
27685
    if( !d_children_quant.empty() && !d_active_quant.empty() ){
232
6533
      Trace("cegqi-debug") << "Find non-innermost quantifiers..." << std::endl;
233
13066
      std::vector< Node > ninner;
234
14219
      for( std::map< Node, bool >::iterator it = d_active_quant.begin(); it != d_active_quant.end(); ++it ){
235
7686
        std::map< Node, std::vector< Node > >::iterator itc = d_children_quant.find( it->first );
236
7686
        if( itc!=d_children_quant.end() ){
237
7944
          for( unsigned j=0; j<itc->second.size(); j++ ){
238
374
            if( d_active_quant.find( itc->second[j] )!=d_active_quant.end() ){
239
112
              Trace("cegqi-debug") << "Do not consider " << it->first << " since it is not innermost (" << itc->second[j] << std::endl;
240
112
              ninner.push_back( it->first );
241
112
              break;
242
            }
243
          }
244
        }
245
      }
246
6533
      Trace("cegqi-debug") << "Found " << ninner.size() << " non-innermost." << std::endl;
247
6645
      for( unsigned i=0; i<ninner.size(); i++ ){
248
112
        Assert(d_active_quant.find(ninner[i]) != d_active_quant.end());
249
112
        d_active_quant.erase( ninner[i] );
250
      }
251
6533
      Assert(!d_active_quant.empty());
252
6533
      Trace("cegqi-debug") << "...done removing." << std::endl;
253
    }
254
  }
255
27685
  d_check_vts_lemma_lc = false;
256
27685
}
257
258
32173
void InstStrategyCegqi::check(Theory::Effort e, QEffort quant_e)
259
{
260
32173
  if (quant_e == QEFFORT_STANDARD)
261
  {
262
11591
    Assert(!d_qstate.isInConflict());
263
11591
    double clSet = 0;
264
11591
    if( Trace.isOn("cegqi-engine") ){
265
      clSet = double(clock())/double(CLOCKS_PER_SEC);
266
      Trace("cegqi-engine") << "---Cbqi Engine Round, effort = " << e << "---" << std::endl;
267
    }
268
11591
    size_t lastWaiting = d_qim.numPendingLemmas();
269
26779
    for( int ee=0; ee<=1; ee++ ){
270
      //for( unsigned i=0; i<d_quantEngine->getModel()->getNumAssertedQuantifiers(); i++ ){
271
      //  Node q = d_quantEngine->getModel()->getAssertedQuantifier( i );
272
      //  if( doCbqi( q ) && d_quantEngine->getModel()->isQuantifierActive( q ) ){
273
24083
      for( std::map< Node, bool >::iterator it = d_active_quant.begin(); it != d_active_quant.end(); ++it ){
274
9796
        Node q = it->first;
275
4898
        Trace("cegqi") << "CBQI : Process quantifier " << q[0] << " at effort " << ee << std::endl;
276
4898
        process(q, e, ee);
277
4898
        if (d_qstate.isInConflict())
278
        {
279
          break;
280
        }
281
      }
282
19185
      if (d_qstate.isInConflict() || d_qim.numPendingLemmas() > lastWaiting)
283
      {
284
3997
        break;
285
      }
286
    }
287
11591
    if( Trace.isOn("cegqi-engine") ){
288
      if (d_qim.numPendingLemmas() > lastWaiting)
289
      {
290
        Trace("cegqi-engine")
291
            << "Added lemmas = " << (d_qim.numPendingLemmas() - lastWaiting)
292
            << std::endl;
293
      }
294
      double clSet2 = double(clock())/double(CLOCKS_PER_SEC);
295
      Trace("cegqi-engine") << "Finished cbqi engine, time = " << (clSet2-clSet) << std::endl;
296
    }
297
  }
298
32173
}
299
300
2680
bool InstStrategyCegqi::checkComplete(IncompleteId& incId)
301
{
302
2680
  if( ( !options::cegqiSat() && d_cbqi_set_quant_inactive ) || d_incomplete_check ){
303
63
    incId = IncompleteId::QUANTIFIERS_CEGQI;
304
63
    return false;
305
  }else{
306
2617
    return true;
307
  }
308
}
309
310
1434
bool InstStrategyCegqi::checkCompleteFor(Node q)
311
{
312
1434
  std::map<Node, CegHandledStatus>::iterator it = d_do_cbqi.find(q);
313
1434
  if( it!=d_do_cbqi.end() ){
314
1434
    return it->second != CEG_UNHANDLED;
315
  }else{
316
    return false;
317
  }
318
}
319
320
23303
void InstStrategyCegqi::checkOwnership(Node q)
321
{
322
23303
  if (d_qreg.getOwner(q) == nullptr && doCbqi(q))
323
  {
324
1630
    if (d_do_cbqi[q] == CEG_HANDLED)
325
    {
326
      //take full ownership of the quantified formula
327
1613
      d_qreg.setOwner(q, this);
328
    }
329
  }
330
23303
}
331
332
23336
void InstStrategyCegqi::preRegisterQuantifier(Node q)
333
{
334
23336
  if (doCbqi(q))
335
  {
336
1630
    if (processNestedQe(q, true))
337
    {
338
      // will process using nested quantifier elimination
339
18
      return;
340
    }
341
    // register the cbqi lemma
342
1613
    if( registerCbqiLemma( q ) ){
343
1449
      Trace("cegqi") << "Registered cbqi lemma for quantifier : " << q << std::endl;
344
    }
345
  }
346
}
347
131850
TrustNode InstStrategyCegqi::rewriteInstantiation(Node q,
348
                                                  std::vector<Node>& terms,
349
                                                  Node inst,
350
                                                  bool doVts)
351
{
352
263700
  Node prevInst = inst;
353
131850
  if (doVts)
354
  {
355
    // do virtual term substitution
356
83
    inst = Rewriter::rewrite(inst);
357
83
    Trace("quant-vts-debug") << "Rewrite vts symbols in " << inst << std::endl;
358
83
    inst = d_vtsCache->rewriteVtsSymbols(inst);
359
83
    Trace("quant-vts-debug") << "...got " << inst << std::endl;
360
  }
361
131850
  if (prevInst != inst)
362
  {
363
    // not proof producing yet
364
83
    return TrustNode::mkTrustRewrite(prevInst, inst, nullptr);
365
  }
366
131767
  return TrustNode::null();
367
}
368
369
6646
InstantiationRewriter* InstStrategyCegqi::getInstRewriter() const
370
{
371
6646
  return d_irew.get();
372
}
373
374
1612
void InstStrategyCegqi::registerCounterexampleLemma(Node q, Node lem)
375
{
376
  // must register with the instantiator
377
  // must explicitly remove ITEs so that we record dependencies
378
3224
  std::vector<Node> ce_vars;
379
4763
  for (size_t i = 0, nics = d_qreg.getNumInstantiationConstants(q); i < nics;
380
       i++)
381
  {
382
3151
    ce_vars.push_back(d_qreg.getInstantiationConstant(q, i));
383
  }
384
  // send the lemma
385
1613
  d_qim.lemma(lem, InferenceId::QUANTIFIERS_CEGQI_CEX);
386
  // get the preprocessed form of the lemma we just sent
387
3222
  std::vector<Node> skolems;
388
3222
  std::vector<Node> skAsserts;
389
  Node ppLem =
390
3222
      d_qstate.getValuation().getPreprocessedTerm(lem, skAsserts, skolems);
391
3222
  std::vector<Node> lemp{ppLem};
392
1611
  lemp.insert(lemp.end(), skAsserts.begin(), skAsserts.end());
393
1611
  ppLem = NodeManager::currentNM()->mkAnd(lemp);
394
3222
  Trace("cegqi-debug") << "Counterexample lemma (post-preprocess): " << ppLem
395
1611
                       << std::endl;
396
3222
  std::vector<Node> auxLems;
397
1611
  CegInstantiator* cinst = getInstantiator(q);
398
1611
  cinst->registerCounterexampleLemma(ppLem, ce_vars, auxLems);
399
1714
  for (size_t i = 0, size = auxLems.size(); i < size; i++)
400
  {
401
206
    Trace("cegqi-debug") << "Auxiliary CE lemma " << i << " : " << auxLems[i]
402
103
                         << std::endl;
403
103
    d_qim.addPendingLemma(auxLems[i], InferenceId::QUANTIFIERS_CEGQI_CEX_AUX);
404
  }
405
1611
}
406
407
313066
bool InstStrategyCegqi::doCbqi(Node q)
408
{
409
313066
  std::map<Node, CegHandledStatus>::iterator it = d_do_cbqi.find(q);
410
313066
  if( it==d_do_cbqi.end() ){
411
23303
    CegHandledStatus ret = CegInstantiator::isCbqiQuant(q);
412
23303
    Trace("cegqi-quant") << "doCbqi " << q << " returned " << ret << std::endl;
413
23303
    d_do_cbqi[q] = ret;
414
23303
    return ret != CEG_UNHANDLED;
415
  }
416
289763
  return it->second != CEG_UNHANDLED;
417
}
418
419
4898
void InstStrategyCegqi::process( Node q, Theory::Effort effort, int e ) {
420
  // If we are doing nested quantifier elimination, check if q was already
421
  // processed.
422
4898
  if (processNestedQe(q, false))
423
  {
424
    // don't need to process this, since it has been reduced
425
26
    return;
426
  }
427
4872
  if( e==0 ){
428
4579
    CegInstantiator * cinst = getInstantiator( q );
429
4579
    Trace("inst-alg") << "-> Run cegqi for " << q << std::endl;
430
4579
    d_curr_quant = q;
431
4579
    if( !cinst->check() ){
432
292
      d_incomplete_check = true;
433
292
      d_check_vts_lemma_lc = true;
434
    }
435
4579
    d_curr_quant = Node::null();
436
293
  }else if( e==1 ){
437
    //minimize the free delta heuristically on demand
438
293
    if( d_check_vts_lemma_lc ){
439
82
      Trace("inst-alg") << "-> Minimize delta heuristic, for " << q << std::endl;
440
82
      d_check_vts_lemma_lc = false;
441
164
      d_small_const = NodeManager::currentNM()->mkNode(
442
82
          MULT, d_small_const, d_small_const_multiplier);
443
82
      d_small_const = Rewriter::rewrite( d_small_const );
444
      //heuristic for now, until we know how to do nested quantification
445
164
      Node delta = d_vtsCache->getVtsDelta(true, false);
446
82
      if( !delta.isNull() ){
447
        Trace("quant-vts-debug") << "Delta lemma for " << d_small_const << std::endl;
448
        Node delta_lem_ub = NodeManager::currentNM()->mkNode( LT, delta, d_small_const );
449
        d_qim.lemma(delta_lem_ub, InferenceId::QUANTIFIERS_CEGQI_VTS_UB_DELTA);
450
      }
451
164
      std::vector< Node > inf;
452
82
      d_vtsCache->getVtsTerms(inf, true, false, false);
453
82
      for( unsigned i=0; i<inf.size(); i++ ){
454
        Trace("quant-vts-debug") << "Infinity lemma for " << inf[i] << " " << d_small_const << std::endl;
455
        Node inf_lem_lb = NodeManager::currentNM()->mkNode( GT, inf[i], NodeManager::currentNM()->mkConst( Rational(1)/d_small_const.getConst<Rational>() ) );
456
        d_qim.lemma(inf_lem_lb, InferenceId::QUANTIFIERS_CEGQI_VTS_LB_INF);
457
      }
458
    }
459
  }
460
}
461
462
10993
Node InstStrategyCegqi::getCounterexampleLiteral(Node q)
463
{
464
10993
  std::map<Node, Node>::iterator it = d_ce_lit.find(q);
465
10993
  if (it != d_ce_lit.end())
466
  {
467
9367
    return it->second;
468
  }
469
1626
  NodeManager * nm = NodeManager::currentNM();
470
1626
  SkolemManager* sm = nm->getSkolemManager();
471
3252
  Node g = sm->mkDummySkolem("g", nm->booleanType());
472
  // ensure that it is a SAT literal
473
3252
  Node ceLit = d_qstate.getValuation().ensureLiteral(g);
474
1626
  d_ce_lit[q] = ceLit;
475
1626
  return ceLit;
476
}
477
478
5794
bool InstStrategyCegqi::doAddInstantiation( std::vector< Node >& subs ) {
479
5794
  Assert(!d_curr_quant.isNull());
480
  // check if we need virtual term substitution (if used delta or infinity)
481
5794
  bool usedVts = d_vtsCache->containsVtsTerm(subs, false);
482
5794
  Instantiate* inst = d_qim.getInstantiate();
483
  //if doing partial quantifier elimination, record the instantiation and set the incomplete flag instead of sending instantiation lemma
484
5794
  if (d_qreg.getQuantAttributes().isQuantElimPartial(d_curr_quant))
485
  {
486
1
    d_cbqi_set_quant_inactive = true;
487
1
    d_incomplete_check = true;
488
1
    inst->recordInstantiation(d_curr_quant, subs, usedVts);
489
1
    return true;
490
  }
491
17379
  else if (inst->addInstantiation(d_curr_quant,
492
                                  subs,
493
                                  InferenceId::QUANTIFIERS_INST_CEGQI,
494
11586
                                  Node::null(),
495
                                  false,
496
                                  usedVts))
497
  {
498
4286
    return true;
499
  }
500
  // this should never happen for monotonic selection strategies
501
1507
  Trace("cegqi-warn") << "WARNING: Existing instantiation" << std::endl;
502
1507
  return false;
503
}
504
505
6190
CegInstantiator * InstStrategyCegqi::getInstantiator( Node q ) {
506
  std::map<Node, std::unique_ptr<CegInstantiator>>::iterator it =
507
6190
      d_cinst.find(q);
508
6190
  if( it==d_cinst.end() ){
509
1611
    d_cinst[q].reset(new CegInstantiator(q, d_qstate, d_treg, this));
510
1611
    return d_cinst[q].get();
511
  }
512
4579
  return it->second.get();
513
}
514
515
1646
VtsTermCache* InstStrategyCegqi::getVtsTermCache() const
516
{
517
1646
  return d_vtsCache.get();
518
}
519
520
1110
BvInverter* InstStrategyCegqi::getBvInverter() const
521
{
522
1110
  return d_bv_invert.get();
523
}
524
525
6528
bool InstStrategyCegqi::processNestedQe(Node q, bool isPreregister)
526
{
527
6528
  if (d_nestedQe != nullptr)
528
  {
529
104
    if (isPreregister)
530
    {
531
      // If at preregister, we are done if we have nested quantification.
532
      // We will process nested quantification.
533
46
      return NestedQe::hasNestedQuantification(q);
534
    }
535
    // if not a preregister, we process, which may trigger quantifier
536
    // elimination in subsolvers.
537
90
    std::vector<Node> lems;
538
58
    if (d_nestedQe->process(q, lems))
539
    {
540
      // add lemmas to process
541
40
      for (const Node& lem : lems)
542
      {
543
14
        d_qim.addPendingLemma(lem, InferenceId::QUANTIFIERS_CEGQI_NESTED_QE);
544
      }
545
      // don't need to process this, since it has been reduced
546
26
      return true;
547
    }
548
  }
549
6456
  return false;
550
}
551
552
}  // namespace quantifiers
553
}  // namespace theory
554
29337
}  // namespace cvc5