GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/sygus/sygus_enumerator_callback.cpp Lines: 40 40 100.0 %
Date: 2021-09-30 Branches: 65 130 50.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Mathias Preiner
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
 * sygus_enumerator
14
 */
15
16
#include "theory/quantifiers/sygus/sygus_enumerator_callback.h"
17
18
#include "theory/datatypes/sygus_datatype_utils.h"
19
#include "theory/quantifiers/sygus/example_eval_cache.h"
20
#include "theory/quantifiers/sygus/sygus_stats.h"
21
#include "theory/quantifiers/sygus_sampler.h"
22
#include "theory/rewriter.h"
23
24
namespace cvc5 {
25
namespace theory {
26
namespace quantifiers {
27
28
167
SygusEnumeratorCallback::SygusEnumeratorCallback(Node e, SygusStatistics* s)
29
167
    : d_enum(e), d_stats(s)
30
{
31
167
  d_tn = e.getType();
32
167
}
33
34
55282
bool SygusEnumeratorCallback::addTerm(Node n, std::unordered_set<Node>& bterms)
35
{
36
110564
  Node bn = datatypes::utils::sygusToBuiltin(n);
37
110564
  Node bnr = Rewriter::callExtendedRewrite(bn);
38
55282
  if (d_stats != nullptr)
39
  {
40
55282
    ++(d_stats->d_enumTermsRewrite);
41
  }
42
  // call the solver-specific notify term
43
55282
  notifyTermInternal(n, bn, bnr);
44
  // check whether we should keep the term, which is based on the callback,
45
  // and the builtin terms
46
  // First, must be unique up to rewriting
47
55282
  if (bterms.find(bnr) != bterms.end())
48
  {
49
22955
    Trace("sygus-enum-exc") << "Exclude (by rewriting): " << bn << std::endl;
50
22955
    return false;
51
  }
52
  // insert to builtin term cache, regardless of whether it is redundant
53
  // based on the callback
54
32327
  bterms.insert(bnr);
55
  // callback-specific add term
56
32327
  if (!addTermInternal(n, bn, bnr))
57
  {
58
8479
    return false;
59
  }
60
23848
  Trace("sygus-enum-terms") << "tc(" << d_tn << "): term " << bn << std::endl;
61
23848
  return true;
62
}
63
64
167
SygusEnumeratorCallbackDefault::SygusEnumeratorCallbackDefault(
65
    Node e,
66
    SygusStatistics* s,
67
    ExampleEvalCache* eec,
68
    SygusSampler* ssrv,
69
167
    std::ostream* out)
70
167
    : SygusEnumeratorCallback(e, s), d_eec(eec), d_samplerRrV(ssrv), d_out(out)
71
{
72
167
}
73
55282
void SygusEnumeratorCallbackDefault::notifyTermInternal(Node n,
74
                                                        Node bn,
75
                                                        Node bnr)
76
{
77
55282
  if (d_samplerRrV != nullptr)
78
  {
79
1626
    Assert(d_out != nullptr);
80
1626
    d_samplerRrV->checkEquivalent(bn, bnr, *d_out);
81
  }
82
55282
}
83
84
32327
bool SygusEnumeratorCallbackDefault::addTermInternal(Node n, Node bn, Node bnr)
85
{
86
  // if we are doing PBE symmetry breaking
87
32327
  if (d_eec != nullptr)
88
  {
89
14014
    if (d_stats != nullptr)
90
    {
91
14014
      ++(d_stats->d_enumTermsExampleEval);
92
    }
93
    // Is it equivalent under examples?
94
19549
    Node bne = d_eec->addSearchVal(d_tn, bnr);
95
14014
    if (!bne.isNull())
96
    {
97
14014
      if (bnr != bne)
98
      {
99
16958
        Trace("sygus-enum-exc")
100
8479
            << "Exclude (by examples): " << bn << ", since we already have "
101
8479
            << bne << std::endl;
102
8479
        return false;
103
      }
104
    }
105
  }
106
23848
  return true;
107
}
108
109
}  // namespace quantifiers
110
}  // namespace theory
111
22755
}  // namespace cvc5