GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/ematching/trigger_term_info.cpp Lines: 42 42 100.0 %
Date: 2021-05-22 Branches: 102 134 76.1 %

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
92539
void TriggerTermInfo::init(Node q, Node n, int reqPol, Node reqPolEq)
28
{
29
92539
  if (d_fv.empty())
30
  {
31
92137
    quantifiers::TermUtil::computeInstConstContainsForQuant(q, n, d_fv);
32
  }
33
92539
  if (d_reqPol == 0)
34
  {
35
92403
    d_reqPol = reqPol;
36
92403
    d_reqPolEq = reqPolEq;
37
  }
38
  else
39
  {
40
    // determined a ground (dis)equality must hold or else q is a tautology?
41
  }
42
92539
  d_weight = getTriggerWeight(n);
43
92539
}
44
45
3293383
bool TriggerTermInfo::isAtomicTrigger(Node n)
46
{
47
3293383
  return isAtomicTriggerKind(n.getKind());
48
}
49
50
11447158
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
3583072
  return k == APPLY_UF || k == SELECT || k == STORE || k == APPLY_CONSTRUCTOR
56
2066720
         || k == APPLY_SELECTOR || k == APPLY_SELECTOR_TOTAL
57
2005745
         || k == APPLY_TESTER || k == UNION || k == INTERSECTION || k == SUBSET
58
1937586
         || k == SETMINUS || k == MEMBER || k == SINGLETON || k == SEP_PTO
59
1903259
         || k == BITVECTOR_TO_NAT || k == INT_TO_BITVECTOR || k == HO_APPLY
60
13341824
         || k == STRING_LENGTH || k == SEQ_NTH;
61
}
62
63
361879
bool TriggerTermInfo::isRelationalTrigger(Node n)
64
{
65
361879
  return isRelationalTriggerKind(n.getKind());
66
}
67
68
361879
bool TriggerTermInfo::isRelationalTriggerKind(Kind k)
69
{
70
361879
  return k == EQUAL || k == GEQ;
71
}
72
73
23679
bool TriggerTermInfo::isSimpleTrigger(Node n)
74
{
75
47358
  Node t = n.getKind() == NOT ? n[0] : n;
76
23679
  if (t.getKind() == EQUAL)
77
  {
78
2981
    if (!quantifiers::TermUtil::hasInstConstAttr(t[1]))
79
    {
80
2963
      t = t[0];
81
    }
82
  }
83
23679
  if (!isAtomicTrigger(t))
84
  {
85
82
    return false;
86
  }
87
59392
  for (const Node& tc : t)
88
  {
89
87984
    if (tc.getKind() != INST_CONSTANT
90
87984
        && quantifiers::TermUtil::hasInstConstAttr(tc))
91
    {
92
8197
      return false;
93
    }
94
  }
95
15400
  if (t.getKind() == HO_APPLY && t[0].getKind() == INST_CONSTANT)
96
  {
97
12
    return false;
98
  }
99
15388
  return true;
100
}
101
102
169721
int32_t TriggerTermInfo::getTriggerWeight(Node n)
103
{
104
169721
  if (n.getKind() == APPLY_UF)
105
  {
106
134062
    return 0;
107
  }
108
35659
  if (isAtomicTrigger(n))
109
  {
110
12466
    return 1;
111
  }
112
23193
  return 2;
113
}
114
115
}  // namespace inst
116
}  // namespace quantifiers
117
}  // namespace theory
118
28194
}  // namespace cvc5