GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/ematching/trigger_term_info.cpp Lines: 42 42 100.0 %
Date: 2021-08-14 Branches: 101 132 76.5 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Morgan Deters, Yoni Zohar
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 trigger term info class.
14
 */
15
16
#include "theory/quantifiers/ematching/trigger_term_info.h"
17
18
#include "theory/quantifiers/term_util.h"
19
20
using namespace cvc5::kind;
21
22
namespace cvc5 {
23
namespace theory {
24
namespace quantifiers {
25
namespace inst {
26
27
89095
void TriggerTermInfo::init(Node q, Node n, int reqPol, Node reqPolEq)
28
{
29
89095
  if (d_fv.empty())
30
  {
31
88711
    quantifiers::TermUtil::computeInstConstContainsForQuant(q, n, d_fv);
32
  }
33
89095
  if (d_reqPol == 0)
34
  {
35
88977
    d_reqPol = reqPol;
36
88977
    d_reqPolEq = reqPolEq;
37
  }
38
  else
39
  {
40
    // determined a ground (dis)equality must hold or else q is a tautology?
41
  }
42
89095
  d_weight = getTriggerWeight(n);
43
89095
}
44
45
3311223
bool TriggerTermInfo::isAtomicTrigger(Node n)
46
{
47
3311223
  return isAtomicTriggerKind(n.getKind());
48
}
49
50
9479881
bool TriggerTermInfo::isAtomicTriggerKind(Kind k)
51
{
52
  // we use both APPLY_SELECTOR and APPLY_SELECTOR_TOTAL since this
53
  // method is used both for trigger selection and for ground term registration,
54
  // where these two things require those kinds respectively.
55
3658266
  return k == APPLY_UF || k == SELECT || k == STORE || k == APPLY_CONSTRUCTOR
56
2125277
         || k == APPLY_SELECTOR || k == APPLY_SELECTOR_TOTAL
57
2053713
         || k == APPLY_TESTER || k == UNION || k == INTERSECTION || k == SUBSET
58
1988243
         || k == SETMINUS || k == MEMBER || k == SINGLETON || k == SEP_PTO
59
1953160
         || k == BITVECTOR_TO_NAT || k == INT_TO_BITVECTOR || k == HO_APPLY
60
11412750
         || k == STRING_LENGTH || k == SEQ_NTH;
61
}
62
63
342669
bool TriggerTermInfo::isRelationalTrigger(Node n)
64
{
65
342669
  return isRelationalTriggerKind(n.getKind());
66
}
67
68
342669
bool TriggerTermInfo::isRelationalTriggerKind(Kind k)
69
{
70
342669
  return k == EQUAL || k == GEQ;
71
}
72
73
23276
bool TriggerTermInfo::isSimpleTrigger(Node n)
74
{
75
46552
  Node t = n.getKind() == NOT ? n[0] : n;
76
23276
  if (t.getKind() == EQUAL)
77
  {
78
3018
    if (!quantifiers::TermUtil::hasInstConstAttr(t[1]))
79
    {
80
3000
      t = t[0];
81
    }
82
  }
83
23276
  if (!isAtomicTrigger(t))
84
  {
85
82
    return false;
86
  }
87
58811
  for (const Node& tc : t)
88
  {
89
87014
    if (tc.getKind() != INST_CONSTANT
90
87014
        && quantifiers::TermUtil::hasInstConstAttr(tc))
91
    {
92
7890
      return false;
93
    }
94
  }
95
15304
  if (t.getKind() == HO_APPLY && t[0].getKind() == INST_CONSTANT)
96
  {
97
12
    return false;
98
  }
99
15292
  return true;
100
}
101
102
163557
int32_t TriggerTermInfo::getTriggerWeight(Node n)
103
{
104
163557
  if (n.getKind() == APPLY_UF)
105
  {
106
128215
    return 0;
107
  }
108
35342
  if (isAtomicTrigger(n))
109
  {
110
12865
    return 1;
111
  }
112
22477
  return 2;
113
}
114
115
}  // namespace inst
116
}  // namespace quantifiers
117
}  // namespace theory
118
29340
}  // namespace cvc5