GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/uf/theory_uf.cpp Lines: 294 337 87.2 %
Date: 2021-08-01 Branches: 638 1347 47.4 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Morgan Deters, Dejan Jovanovic
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
 * This is the interface to TheoryUF implementations
14
 *
15
 * All implementations of TheoryUF should inherit from this class.
16
 */
17
18
#include "theory/uf/theory_uf.h"
19
20
#include <memory>
21
#include <sstream>
22
23
#include "expr/node_algorithm.h"
24
#include "options/quantifiers_options.h"
25
#include "options/smt_options.h"
26
#include "options/theory_options.h"
27
#include "options/uf_options.h"
28
#include "proof/proof_node_manager.h"
29
#include "smt/logic_exception.h"
30
#include "theory/theory_model.h"
31
#include "theory/type_enumerator.h"
32
#include "theory/uf/cardinality_extension.h"
33
#include "theory/uf/ho_extension.h"
34
#include "theory/uf/theory_uf_rewriter.h"
35
36
using namespace std;
37
38
namespace cvc5 {
39
namespace theory {
40
namespace uf {
41
42
/** Constructs a new instance of TheoryUF w.r.t. the provided context.*/
43
9838
TheoryUF::TheoryUF(context::Context* c,
44
                   context::UserContext* u,
45
                   OutputChannel& out,
46
                   Valuation valuation,
47
                   const LogicInfo& logicInfo,
48
                   ProofNodeManager* pnm,
49
9838
                   std::string instanceName)
50
    : Theory(THEORY_UF, c, u, out, valuation, logicInfo, pnm, instanceName),
51
      d_thss(nullptr),
52
      d_ho(nullptr),
53
      d_functionsTerms(c),
54
      d_symb(u, instanceName),
55
      d_state(c, u, valuation),
56
19676
      d_im(*this, d_state, pnm, "theory::uf::" + instanceName, false),
57
29514
      d_notify(d_im, *this)
58
{
59
9838
  d_true = NodeManager::currentNM()->mkConst( true );
60
  // indicate we are using the default theory state and inference managers
61
9838
  d_theoryState = &d_state;
62
9838
  d_inferManager = &d_im;
63
9838
}
64
65
19676
TheoryUF::~TheoryUF() {
66
19676
}
67
68
9838
TheoryRewriter* TheoryUF::getTheoryRewriter() { return &d_rewriter; }
69
70
3756
ProofRuleChecker* TheoryUF::getProofChecker() { return &d_checker; }
71
72
9838
bool TheoryUF::needsEqualityEngine(EeSetupInfo& esi)
73
{
74
9838
  esi.d_notify = &d_notify;
75
9838
  esi.d_name = d_instanceName + "theory::uf::ee";
76
19676
  if (options::finiteModelFind()
77
9838
      && options::ufssMode() != options::UfssMode::NONE)
78
  {
79
    // need notifications about sorts
80
286
    esi.d_notifyNewClass = true;
81
286
    esi.d_notifyMerge = true;
82
286
    esi.d_notifyDisequal = true;
83
  }
84
9838
  return true;
85
}
86
87
9838
void TheoryUF::finishInit() {
88
9838
  Assert(d_equalityEngine != nullptr);
89
  // combined cardinality constraints are not evaluated in getModelValue
90
9838
  d_valuation.setUnevaluatedKind(kind::COMBINED_CARDINALITY_CONSTRAINT);
91
  // Initialize the cardinality constraints solver if the logic includes UF,
92
  // finite model finding is enabled, and it is not disabled by
93
  // options::ufssMode().
94
19676
  if (options::finiteModelFind()
95
9838
      && options::ufssMode() != options::UfssMode::NONE)
96
  {
97
286
    d_thss.reset(new CardinalityExtension(d_state, d_im, this));
98
  }
99
  // The kinds we are treating as function application in congruence
100
9838
  d_equalityEngine->addFunctionKind(kind::APPLY_UF, false, options::ufHo());
101
9838
  if (options::ufHo())
102
  {
103
187
    d_equalityEngine->addFunctionKind(kind::HO_APPLY);
104
187
    d_ho.reset(new HoExtension(d_state, d_im));
105
  }
106
9838
}
107
108
static Node mkAnd(const std::vector<TNode>& conjunctions) {
109
  Assert(conjunctions.size() > 0);
110
111
  std::set<TNode> all;
112
  all.insert(conjunctions.begin(), conjunctions.end());
113
114
  if (all.size() == 1) {
115
    // All the same, or just one
116
    return conjunctions[0];
117
  }
118
119
  NodeBuilder conjunction(kind::AND);
120
  std::set<TNode>::const_iterator it = all.begin();
121
  std::set<TNode>::const_iterator it_end = all.end();
122
  while (it != it_end) {
123
    conjunction << *it;
124
    ++ it;
125
  }
126
127
  return conjunction;
128
}/* mkAnd() */
129
130
//--------------------------------- standard check
131
132
15392
bool TheoryUF::needsCheckLastEffort()
133
{
134
  // last call effort needed if using finite model finding
135
15392
  return d_thss != nullptr;
136
}
137
138
1080562
void TheoryUF::postCheck(Effort level)
139
{
140
1080562
  if (d_state.isInConflict())
141
  {
142
57916
    return;
143
  }
144
  // check with the cardinality constraints extension
145
1022646
  if (d_thss != nullptr)
146
  {
147
88871
    d_thss->check(level);
148
  }
149
  // check with the higher-order extension at full effort
150
1022646
  if (!d_state.isInConflict() && fullEffort(level))
151
  {
152
68340
    if (options::ufHo())
153
    {
154
1047
      d_ho->check();
155
    }
156
  }
157
}
158
159
2908958
void TheoryUF::notifyFact(TNode atom, bool pol, TNode fact, bool isInternal)
160
{
161
2908958
  if (d_state.isInConflict())
162
  {
163
56942
    return;
164
  }
165
2852016
  if (d_thss != nullptr)
166
  {
167
    bool isDecision =
168
218462
        d_valuation.isSatLiteral(fact) && d_valuation.isDecision(fact);
169
218462
    d_thss->assertNode(fact, isDecision);
170
  }
171
2852016
  switch (atom.getKind())
172
  {
173
2633744
    case kind::EQUAL:
174
    {
175
2633744
      if (options::ufHo() && options::ufHoExt())
176
      {
177
33184
        if (!pol && !d_state.isInConflict() && atom[0].getType().isFunction())
178
        {
179
          // apply extensionality eagerly using the ho extension
180
3725
          d_ho->applyExtensionality(fact);
181
        }
182
      }
183
    }
184
2633744
    break;
185
13655
    case kind::CARDINALITY_CONSTRAINT:
186
    case kind::COMBINED_CARDINALITY_CONSTRAINT:
187
    {
188
13655
      if (d_thss == nullptr)
189
      {
190
        if (!getLogicInfo().hasCardinalityConstraints())
191
        {
192
          std::stringstream ss;
193
          ss << "Cardinality constraint " << atom
194
             << " was asserted, but the logic does not allow it." << std::endl;
195
          ss << "Try using a logic containing \"UFC\"." << std::endl;
196
          throw Exception(ss.str());
197
        }
198
        else
199
        {
200
          // support for cardinality constraints is not enabled, set incomplete
201
          d_im.setIncomplete(IncompleteId::UF_CARD_DISABLED);
202
        }
203
      }
204
    }
205
13655
    break;
206
204617
    default: break;
207
  }
208
}
209
//--------------------------------- end standard check
210
211
463704
TrustNode TheoryUF::ppRewrite(TNode node, std::vector<SkolemLemma>& lems)
212
{
213
927408
  Trace("uf-exp-def") << "TheoryUF::ppRewrite: expanding definition : " << node
214
463704
                      << std::endl;
215
463704
  Kind k = node.getKind();
216
463704
  if (k == kind::HO_APPLY)
217
  {
218
284
    if( !options::ufHo() ){
219
      std::stringstream ss;
220
      ss << "Partial function applications are not supported in default mode, try --uf-ho.";
221
      throw LogicException(ss.str());
222
    }
223
455
    Node ret = d_ho->ppRewrite(node);
224
284
    if (ret != node)
225
    {
226
226
      Trace("uf-exp-def") << "TheoryUF::ppRewrite: higher-order: " << node
227
113
                          << " to " << ret << std::endl;
228
113
      return TrustNode::mkTrustRewrite(node, ret, nullptr);
229
    }
230
  }
231
463420
  else if (k == kind::APPLY_UF)
232
  {
233
    // check for higher-order
234
    // logic exception if higher-order is not enabled
235
86528
    if (isHigherOrderType(node.getOperator().getType()) && !options::ufHo())
236
    {
237
      std::stringstream ss;
238
      ss << "UF received an application whose operator has higher-order type "
239
         << node << ", which is not supported by default, try --uf-ho";
240
      throw LogicException(ss.str());
241
    }
242
  }
243
463591
  return TrustNode::null();
244
}
245
246
376071
void TheoryUF::preRegisterTerm(TNode node)
247
{
248
376071
  Debug("uf") << "TheoryUF::preRegisterTerm(" << node << ")" << std::endl;
249
250
376071
  if (d_thss != NULL) {
251
45022
    d_thss->preRegisterTerm(node);
252
  }
253
254
  // we always use APPLY_UF if not higher-order, HO_APPLY if higher-order
255
  //Assert( node.getKind()!=kind::APPLY_UF || !options::ufHo() );
256
376071
  Assert(node.getKind() != kind::HO_APPLY || options::ufHo());
257
258
376071
  Kind k = node.getKind();
259
376071
  switch (k)
260
  {
261
163554
    case kind::EQUAL:
262
      // Add the trigger for equality
263
163554
      d_equalityEngine->addTriggerPredicate(node);
264
163554
      break;
265
137325
    case kind::APPLY_UF:
266
    case kind::HO_APPLY:
267
    {
268
      // Maybe it's a predicate
269
137325
      if (node.getType().isBoolean())
270
      {
271
        // Get triggered for both equal and dis-equal
272
29481
        d_equalityEngine->addTriggerPredicate(node);
273
      }
274
      else
275
      {
276
        // Function applications/predicates
277
107844
        d_equalityEngine->addTerm(node);
278
      }
279
      // Remember the function and predicate terms
280
137325
      d_functionsTerms.push_back(node);
281
    }
282
137325
    break;
283
3755
  case kind::CARDINALITY_CONSTRAINT:
284
  case kind::COMBINED_CARDINALITY_CONSTRAINT:
285
    //do nothing
286
3755
    break;
287
71437
  default:
288
    // Variables etc
289
71437
    d_equalityEngine->addTerm(node);
290
71437
    break;
291
  }
292
376071
}
293
294
void TheoryUF::explain(TNode literal, Node& exp)
295
{
296
  Debug("uf") << "TheoryUF::explain(" << literal << ")" << std::endl;
297
  std::vector<TNode> assumptions;
298
  // Do the work
299
  bool polarity = literal.getKind() != kind::NOT;
300
  TNode atom = polarity ? literal : literal[0];
301
  if (atom.getKind() == kind::EQUAL)
302
  {
303
    d_equalityEngine->explainEquality(
304
        atom[0], atom[1], polarity, assumptions, nullptr);
305
  }
306
  else
307
  {
308
    d_equalityEngine->explainPredicate(atom, polarity, assumptions, nullptr);
309
  }
310
  exp = mkAnd(assumptions);
311
}
312
313
97955
TrustNode TheoryUF::explain(TNode literal) { return d_im.explainLit(literal); }
314
315
13323
bool TheoryUF::collectModelValues(TheoryModel* m, const std::set<Node>& termSet)
316
{
317
13323
  if( options::ufHo() ){
318
    // must add extensionality disequalities for all pairs of (non-disequal)
319
    // function equivalence classes.
320
398
    if (!d_ho->collectModelInfoHo(m, termSet))
321
    {
322
      Trace("uf") << "Collect model info fail HO" << std::endl;
323
      return false;
324
    }
325
  }
326
327
13323
  Debug("uf") << "UF : finish collectModelInfo " << std::endl;
328
13323
  return true;
329
}
330
331
15189
void TheoryUF::presolve() {
332
  // TimerStat::CodeTimer codeTimer(d_presolveTimer);
333
334
15189
  Debug("uf") << "uf: begin presolve()" << endl;
335
136130
  if(options::ufSymmetryBreaker()) {
336
308
    vector<Node> newClauses;
337
154
    d_symb.apply(newClauses);
338
156
    for(vector<Node>::const_iterator i = newClauses.begin();
339
156
        i != newClauses.end();
340
        ++i) {
341
2
      Debug("uf") << "uf: generating a lemma: " << *i << std::endl;
342
      // no proof generator provided
343
2
      d_im.lemma(*i, InferenceId::UF_BREAK_SYMMETRY);
344
    }
345
  }
346
15189
  if( d_thss ){
347
336
    d_thss->presolve();
348
  }
349
15189
  Debug("uf") << "uf: end presolve()" << endl;
350
15189
}
351
352
105752
void TheoryUF::ppStaticLearn(TNode n, NodeBuilder& learned)
353
{
354
  //TimerStat::CodeTimer codeTimer(d_staticLearningTimer);
355
356
211504
  vector<TNode> workList;
357
105752
  workList.push_back(n);
358
211504
  std::unordered_set<TNode> processed;
359
360
4982480
  while(!workList.empty()) {
361
2438364
    n = workList.back();
362
363
2461723
    if (n.isClosure())
364
    {
365
      // unsafe to go under quantifiers; we might pull bound vars out of scope!
366
23359
      processed.insert(n);
367
23359
      workList.pop_back();
368
23359
      continue;
369
    }
370
371
2415005
    bool unprocessedChildren = false;
372
7925298
    for(TNode::iterator i = n.begin(), iend = n.end(); i != iend; ++i) {
373
5510293
      if(processed.find(*i) == processed.end()) {
374
        // unprocessed child
375
1572157
        workList.push_back(*i);
376
1572157
        unprocessedChildren = true;
377
      }
378
    }
379
380
2415005
    if(unprocessedChildren) {
381
760455
      continue;
382
    }
383
384
1654550
    workList.pop_back();
385
    // has node n been processed in the meantime ?
386
1654550
    if(processed.find(n) != processed.end()) {
387
19995
      continue;
388
    }
389
1634555
    processed.insert(n);
390
391
    // == DIAMONDS ==
392
393
3269110
    Debug("diamonds") << "===================== looking at" << endl
394
1634555
                      << n << endl;
395
396
    // binary OR of binary ANDs of EQUALities
397
4108540
    if(n.getKind() == kind::OR && n.getNumChildren() == 2 &&
398
2095867
       n[0].getKind() == kind::AND && n[0].getNumChildren() == 2 &&
399
1654849
       n[1].getKind() == kind::AND && n[1].getNumChildren() == 2 &&
400
1640745
       (n[0][0].getKind() == kind::EQUAL) &&
401
1637207
       (n[0][1].getKind() == kind::EQUAL) &&
402
4906249
       (n[1][0].getKind() == kind::EQUAL) &&
403
1635847
       (n[1][1].getKind() == kind::EQUAL)) {
404
      // now we have (a = b && c = d) || (e = f && g = h)
405
406
634
      Debug("diamonds") << "has form of a diamond!" << endl;
407
408
      TNode
409
1250
        a = n[0][0][0], b = n[0][0][1],
410
1250
        c = n[0][1][0], d = n[0][1][1],
411
1250
        e = n[1][0][0], f = n[1][0][1],
412
1250
        g = n[1][1][0], h = n[1][1][1];
413
414
      // test that one of {a, b} = one of {c, d}, and make "b" the
415
      // shared node (i.e. put in the form (a = b && b = d))
416
      // note we don't actually care about the shared ones, so the
417
      // "swaps" below are one-sided, ignoring b and c
418
634
      if(a == c) {
419
16
        a = b;
420
618
      } else if(a == d) {
421
442
        a = b;
422
442
        d = c;
423
176
      } else if(b == c) {
424
        // nothing to do
425
52
      } else if(b == d) {
426
20
        d = c;
427
      } else {
428
        // condition not satisfied
429
16
        Debug("diamonds") << "+ A fails" << endl;
430
16
        continue;
431
      }
432
433
618
      Debug("diamonds") << "+ A holds" << endl;
434
435
      // same: one of {e, f} = one of {g, h}, and make "f" the
436
      // shared node (i.e. put in the form (e = f && f = h))
437
618
      if(e == g) {
438
16
        e = f;
439
602
      } else if(e == h) {
440
454
        e = f;
441
454
        h = g;
442
148
      } else if(f == g) {
443
        // nothing to do
444
10
      } else if(f == h) {
445
6
        h = g;
446
      } else {
447
        // condition not satisfied
448
2
        Debug("diamonds") << "+ B fails" << endl;
449
2
        continue;
450
      }
451
452
616
      Debug("diamonds") << "+ B holds" << endl;
453
454
      // now we have (a = b && b = d) || (e = f && f = h)
455
      // test that {a, d} == {e, h}
456
1232
      if( (a == e && d == h) ||
457
          (a == h && d == e) ) {
458
        // learn: n implies a == d
459
616
        Debug("diamonds") << "+ C holds" << endl;
460
1232
        Node newEquality = a.eqNode(d);
461
616
        Debug("diamonds") << "  ==> " << newEquality << endl;
462
616
        learned << n.impNode(newEquality);
463
      } else {
464
        Debug("diamonds") << "+ C fails" << endl;
465
      }
466
    }
467
  }
468
469
105752
  if(options::ufSymmetryBreaker()) {
470
24126
    d_symb.assertFormula(n);
471
  }
472
105752
} /* TheoryUF::ppStaticLearn() */
473
474
4525
EqualityStatus TheoryUF::getEqualityStatus(TNode a, TNode b) {
475
476
  // Check for equality (simplest)
477
4525
  if (d_equalityEngine->areEqual(a, b))
478
  {
479
    // The terms are implied to be equal
480
    return EQUALITY_TRUE;
481
  }
482
483
  // Check for disequality
484
4525
  if (d_equalityEngine->areDisequal(a, b, false))
485
  {
486
    // The terms are implied to be dis-equal
487
    return EQUALITY_FALSE;
488
  }
489
490
  // All other terms we interpret as dis-equal in the model
491
4525
  return EQUALITY_FALSE_IN_MODEL;
492
}
493
494
1304771
bool TheoryUF::areCareDisequal(TNode x, TNode y){
495
1304771
  Assert(d_equalityEngine->hasTerm(x));
496
1304771
  Assert(d_equalityEngine->hasTerm(y));
497
3914313
  if (d_equalityEngine->isTriggerTerm(x, THEORY_UF)
498
3914313
      && d_equalityEngine->isTriggerTerm(y, THEORY_UF))
499
  {
500
    TNode x_shared =
501
1245717
        d_equalityEngine->getTriggerTermRepresentative(x, THEORY_UF);
502
    TNode y_shared =
503
1245717
        d_equalityEngine->getTriggerTermRepresentative(y, THEORY_UF);
504
1013332
    EqualityStatus eqStatus = d_valuation.getEqualityStatus(x_shared, y_shared);
505
1013332
    if( eqStatus==EQUALITY_FALSE_AND_PROPAGATED || eqStatus==EQUALITY_FALSE || eqStatus==EQUALITY_FALSE_IN_MODEL ){
506
780947
      return true;
507
    }
508
  }
509
523824
  return false;
510
}
511
512
429355
void TheoryUF::addCarePairs(const TNodeTrie* t1,
513
                            const TNodeTrie* t2,
514
                            unsigned arity,
515
                            unsigned depth)
516
{
517
429355
  if( depth==arity ){
518
119929
    if( t2!=NULL ){
519
239858
      Node f1 = t1->getData();
520
239858
      Node f2 = t2->getData();
521
119929
      if (!d_equalityEngine->areEqual(f1, f2))
522
      {
523
111117
        Debug("uf::sharing") << "TheoryUf::computeCareGraph(): checking function " << f1 << " and " << f2 << std::endl;
524
222234
        vector< pair<TNode, TNode> > currentPairs;
525
311145
        for (size_t k = 0, nchildren = f1.getNumChildren(); k < nchildren; ++k)
526
        {
527
400056
          TNode x = f1[k];
528
400056
          TNode y = f2[k];
529
200028
          Assert(d_equalityEngine->hasTerm(x));
530
200028
          Assert(d_equalityEngine->hasTerm(y));
531
200028
          Assert(!d_equalityEngine->areDisequal(x, y, false));
532
200028
          Assert(!areCareDisequal(x, y));
533
200028
          if (!d_equalityEngine->areEqual(x, y))
534
          {
535
357996
            if (d_equalityEngine->isTriggerTerm(x, THEORY_UF)
536
357996
                && d_equalityEngine->isTriggerTerm(y, THEORY_UF))
537
            {
538
              TNode x_shared =
539
64356
                  d_equalityEngine->getTriggerTermRepresentative(x, THEORY_UF);
540
              TNode y_shared =
541
64356
                  d_equalityEngine->getTriggerTermRepresentative(y, THEORY_UF);
542
32178
              currentPairs.push_back(make_pair(x_shared, y_shared));
543
            }
544
          }
545
        }
546
143295
        for (unsigned c = 0; c < currentPairs.size(); ++ c) {
547
32178
          Debug("uf::sharing") << "TheoryUf::computeCareGraph(): adding to care-graph" << std::endl;
548
32178
          addCarePair(currentPairs[c].first, currentPairs[c].second);
549
        }
550
      }
551
    }
552
  }else{
553
309426
    if( t2==NULL ){
554
105559
      if( depth<(arity-1) ){
555
        //add care pairs internal to each child
556
132185
        for (const std::pair<const TNode, TNodeTrie>& tt : t1->d_data)
557
        {
558
76173
          addCarePairs(&tt.second, NULL, arity, depth + 1);
559
        }
560
      }
561
      //add care pairs based on each pair of non-disequal arguments
562
453315
      for (std::map<TNode, TNodeTrie>::const_iterator it = t1->d_data.begin();
563
453315
           it != t1->d_data.end();
564
           ++it)
565
      {
566
347756
        std::map<TNode, TNodeTrie>::const_iterator it2 = it;
567
347756
        ++it2;
568
4510652
        for( ; it2 != t1->d_data.end(); ++it2 ){
569
2081448
          if (!d_equalityEngine->areDisequal(it->first, it2->first, false))
570
          {
571
794140
            if( !areCareDisequal(it->first, it2->first) ){
572
231631
              addCarePairs( &it->second, &it2->second, arity, depth+1 );
573
            }
574
          }
575
        }
576
      }
577
    }else{
578
      //add care pairs based on product of indices, non-disequal arguments
579
507748
      for (const std::pair<const TNode, TNodeTrie>& tt1 : t1->d_data)
580
      {
581
628238
        for (const std::pair<const TNode, TNodeTrie>& tt2 : t2->d_data)
582
        {
583
324357
          if (!d_equalityEngine->areDisequal(tt1.first, tt2.first, false))
584
          {
585
310603
            if (!areCareDisequal(tt1.first, tt2.first))
586
            {
587
92165
              addCarePairs(&tt1.second, &tt2.second, arity, depth + 1);
588
            }
589
          }
590
        }
591
      }
592
    }
593
  }
594
429355
}
595
596
21957
void TheoryUF::computeCareGraph() {
597
21957
  if (d_sharedTerms.empty())
598
  {
599
8239
    return;
600
  }
601
  // Use term indexing. We build separate indices for APPLY_UF and HO_APPLY.
602
  // We maintain indices per operator for the former, and indices per
603
  // function type for the latter.
604
27436
  Debug("uf::sharing") << "TheoryUf::computeCareGraph(): Build term indices..."
605
13718
                       << std::endl;
606
27436
  std::map<Node, TNodeTrie> index;
607
27436
  std::map<TypeNode, TNodeTrie> hoIndex;
608
27436
  std::map<Node, size_t> arity;
609
356338
  for (TNode app : d_functionsTerms)
610
  {
611
685240
    std::vector<TNode> reps;
612
342620
    bool has_trigger_arg = false;
613
834426
    for (const Node& j : app)
614
    {
615
491806
      reps.push_back(d_equalityEngine->getRepresentative(j));
616
491806
      if (d_equalityEngine->isTriggerTerm(j, THEORY_UF))
617
      {
618
418898
        has_trigger_arg = true;
619
      }
620
    }
621
342620
    if (has_trigger_arg)
622
    {
623
301072
      if (app.getKind() == kind::APPLY_UF)
624
      {
625
602080
        Node op = app.getOperator();
626
301040
        index[op].addTerm(app, reps);
627
301040
        arity[op] = reps.size();
628
      }
629
      else
630
      {
631
32
        Assert(app.getKind() == kind::HO_APPLY);
632
        // add it to the hoIndex for the function type
633
32
        hoIndex[app[0].getType()].addTerm(app, reps);
634
      }
635
    }
636
  }
637
  // for each index
638
43094
  for (std::pair<const Node, TNodeTrie>& tt : index)
639
  {
640
58752
    Debug("uf::sharing") << "TheoryUf::computeCareGraph(): Process index "
641
29376
                         << tt.first << "..." << std::endl;
642
29376
    Assert(arity.find(tt.first) != arity.end());
643
29376
    addCarePairs(&tt.second, nullptr, arity[tt.first], 0);
644
  }
645
13728
  for (std::pair<const TypeNode, TNodeTrie>& tt : hoIndex)
646
  {
647
20
    Debug("uf::sharing") << "TheoryUf::computeCareGraph(): Process ho index "
648
10
                         << tt.first << "..." << std::endl;
649
    // the arity of HO_APPLY is always two
650
10
    addCarePairs(&tt.second, nullptr, 2, 0);
651
  }
652
27436
  Debug("uf::sharing") << "TheoryUf::computeCareGraph(): finished."
653
13718
                       << std::endl;
654
}/* TheoryUF::computeCareGraph() */
655
656
270703
void TheoryUF::eqNotifyNewClass(TNode t) {
657
270703
  if (d_thss != NULL) {
658
52824
    d_thss->newEqClass(t);
659
  }
660
270703
}
661
662
4169779
void TheoryUF::eqNotifyMerge(TNode t1, TNode t2)
663
{
664
4169779
  if (d_thss != NULL) {
665
282277
    d_thss->merge(t1, t2);
666
  }
667
4169779
}
668
669
783247
void TheoryUF::eqNotifyDisequal(TNode t1, TNode t2, TNode reason) {
670
783247
  if (d_thss != NULL) {
671
21042
    d_thss->assertDisequal(t1, t2, reason);
672
  }
673
783247
}
674
675
86528
bool TheoryUF::isHigherOrderType(TypeNode tn)
676
{
677
86528
  Assert(tn.isFunction());
678
86528
  std::map<TypeNode, bool>::iterator it = d_isHoType.find(tn);
679
86528
  if (it != d_isHoType.end())
680
  {
681
81594
    return it->second;
682
  }
683
4934
  bool ret = false;
684
9868
  const std::vector<TypeNode>& argTypes = tn.getArgTypes();
685
14136
  for (const TypeNode& tnc : argTypes)
686
  {
687
9270
    if (tnc.isFunction())
688
    {
689
68
      ret = true;
690
68
      break;
691
    }
692
  }
693
4934
  d_isHoType[tn] = ret;
694
4934
  return ret;
695
}
696
697
}  // namespace uf
698
}  // namespace theory
699
29280
}  // namespace cvc5