GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/sygus/sygus_enumerator_callback.cpp Lines: 40 40 100.0 %
Date: 2021-11-07 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
261
SygusEnumeratorCallback::SygusEnumeratorCallback(Node e, SygusStatistics* s)
29
261
    : d_enum(e), d_stats(s)
30
{
31
261
  d_tn = e.getType();
32
261
}
33
34
76093
bool SygusEnumeratorCallback::addTerm(Node n, std::unordered_set<Node>& bterms)
35
{
36
152186
  Node bn = datatypes::utils::sygusToBuiltin(n);
37
152186
  Node bnr = Rewriter::callExtendedRewrite(bn);
38
76093
  if (d_stats != nullptr)
39
  {
40
76093
    ++(d_stats->d_enumTermsRewrite);
41
  }
42
  // call the solver-specific notify term
43
76093
  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
76093
  if (bterms.find(bnr) != bterms.end())
48
  {
49
32009
    Trace("sygus-enum-exc") << "Exclude (by rewriting): " << bn << std::endl;
50
32009
    return false;
51
  }
52
  // insert to builtin term cache, regardless of whether it is redundant
53
  // based on the callback
54
44084
  bterms.insert(bnr);
55
  // callback-specific add term
56
44084
  if (!addTermInternal(n, bn, bnr))
57
  {
58
14304
    return false;
59
  }
60
29780
  Trace("sygus-enum-terms") << "tc(" << d_tn << "): term " << bn << std::endl;
61
29780
  return true;
62
}
63
64
261
SygusEnumeratorCallbackDefault::SygusEnumeratorCallbackDefault(
65
    Node e,
66
    SygusStatistics* s,
67
    ExampleEvalCache* eec,
68
    SygusSampler* ssrv,
69
261
    std::ostream* out)
70
261
    : SygusEnumeratorCallback(e, s), d_eec(eec), d_samplerRrV(ssrv), d_out(out)
71
{
72
261
}
73
76093
void SygusEnumeratorCallbackDefault::notifyTermInternal(Node n,
74
                                                        Node bn,
75
                                                        Node bnr)
76
{
77
76093
  if (d_samplerRrV != nullptr)
78
  {
79
1626
    Assert(d_out != nullptr);
80
1626
    d_samplerRrV->checkEquivalent(bn, bnr, *d_out);
81
  }
82
76093
}
83
84
44084
bool SygusEnumeratorCallbackDefault::addTermInternal(Node n, Node bn, Node bnr)
85
{
86
  // if we are doing PBE symmetry breaking
87
44084
  if (d_eec != nullptr)
88
  {
89
24018
    if (d_stats != nullptr)
90
    {
91
24018
      ++(d_stats->d_enumTermsExampleEval);
92
    }
93
    // Is it equivalent under examples?
94
33732
    Node bne = d_eec->addSearchVal(d_tn, bnr);
95
24018
    if (!bne.isNull())
96
    {
97
24018
      if (bnr != bne)
98
      {
99
28608
        Trace("sygus-enum-exc")
100
14304
            << "Exclude (by examples): " << bn << ", since we already have "
101
14304
            << bne << std::endl;
102
14304
        return false;
103
      }
104
    }
105
  }
106
29780
  return true;
107
}
108
109
}  // namespace quantifiers
110
}  // namespace theory
111
31137
}  // namespace cvc5