GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/skolemize.h Lines: 1 1 100.0 %
Date: 2021-09-18 Branches: 0 0 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Mathias Preiner, Abdalrhman Mohamed
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
 * Utilities for skolemization.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__QUANTIFIERS__SKOLEMIZE_H
19
#define CVC5__THEORY__QUANTIFIERS__SKOLEMIZE_H
20
21
#include <unordered_map>
22
#include <unordered_set>
23
24
#include "context/cdhashmap.h"
25
#include "expr/node.h"
26
#include "expr/type_node.h"
27
#include "proof/eager_proof_generator.h"
28
#include "proof/trust_node.h"
29
#include "smt/env_obj.h"
30
31
namespace cvc5 {
32
33
class DTypeConstructor;
34
35
namespace theory {
36
namespace quantifiers {
37
38
class QuantifiersState;
39
class TermRegistry;
40
41
/** Skolemization utility
42
 *
43
 * This class constructs Skolemization lemmas.
44
 * Given a quantified formula q = (forall x. P),
45
 * its skolemization lemma is of the form:
46
 *   (~ forall x. P ) => ~P * { x -> d_skolem_constants[q] }
47
 *
48
 * This class also incorporates techniques for
49
 * skolemization with "inductive strenghtening", see
50
 * Section 2 of Reynolds et al., "Induction for SMT
51
 * Solvers", VMCAI 2015. In the case that x is an inductive
52
 * datatype or an integer, then we may strengthen the conclusion
53
 * based on weak well-founded induction. For example, for
54
 * quantification on lists, a skolemization with inductive
55
 * strengthening is a lemma of this form:
56
 *   (~ forall x : List. P( x ) ) =>
57
 *   ~P( k ) ^ ( is-cons( k ) => P( tail( k ) ) )
58
 * For the integers it is:
59
 *   (~ forall x : Int. P( x ) ) =>
60
 *   ~P( k ) ^ ( x>0 => P( x-1 ) )
61
 *
62
 *
63
 * Inductive strenghtening is not enabled by
64
 * default and can be enabled by option:
65
 *   --quant-ind
66
 */
67
class Skolemize : protected EnvObj
68
{
69
  typedef context::CDHashMap<Node, Node> NodeNodeMap;
70
71
 public:
72
  Skolemize(Env& env,
73
            QuantifiersState& qs,
74
            TermRegistry& tr,
75
            ProofNodeManager* pnm);
76
19874
  ~Skolemize() {}
77
  /** skolemize quantified formula q
78
   * If the return value ret of this function is non-null, then ret is a trust
79
   * node corresponding to a new skolemization lemma we generated for q. These
80
   * lemmas are constructed once per user-context.
81
   */
82
  TrustNode process(Node q);
83
  /** get skolem constants for quantified formula q */
84
  bool getSkolemConstants(Node q, std::vector<Node>& skolems);
85
  /** get the i^th skolem constant for quantified formula q */
86
  Node getSkolemConstant(Node q, unsigned i);
87
  /** make skolemized body
88
   *
89
   * This returns the skolemized body n of a
90
   * quantified formula q with inductive strenghtening,
91
   * where typically n is q[1].
92
   *
93
   * The skolem constants/functions we generate by this
94
   * skolemization are added to sk.
95
   *
96
   * The argument fvs are used if we are
97
   * performing skolemization within a nested quantified
98
   * formula. In this case, skolem constants we introduce
99
   * must be parameterized based on the types of fvs and must be
100
   * applied to fvs.
101
   *
102
   * The last two arguments sub and sub_vars are used for
103
   * to carry the body and indices of other induction
104
   * variables if a quantified formula to skolemize
105
   * has multiple induction variables. See page 5
106
   * of Reynolds et al., VMCAI 2015.
107
   */
108
  static Node mkSkolemizedBody(Node q,
109
                               Node n,
110
                               std::vector<TNode>& fvs,
111
                               std::vector<Node>& sk,
112
                               Node& sub,
113
                               std::vector<unsigned>& sub_vars);
114
  /** get the skolemized body for quantified formula q */
115
  Node getSkolemizedBody(Node q);
116
  /** is n a variable that we can apply inductive strenghtening to? */
117
  static bool isInductionTerm(Node n);
118
  /**
119
   * Get skolemization vectors, where for each quantified formula that was
120
   * skolemized, this is the list of skolems that were used to witness the
121
   * negation of that quantified formula (which is equivalent to an existential
122
   * one).
123
   *
124
   * This is used for the command line option
125
   *   --dump-instantiations
126
   * which prints an informal justification of steps taken by the quantifiers
127
   * module.
128
   */
129
  void getSkolemTermVectors(std::map<Node, std::vector<Node> >& sks) const;
130
131
 private:
132
  /** Are proofs enabled? */
133
  bool isProofEnabled() const;
134
  /** get self selectors
135
   * For datatype constructor dtc with type dt,
136
   * this collects the set of datatype selector applications,
137
   * applied to term n, whose return type in ntn, and stores
138
   * them in the vector selfSel.
139
   */
140
  static void getSelfSel(const DType& dt,
141
                         const DTypeConstructor& dc,
142
                         Node n,
143
                         TypeNode ntn,
144
                         std::vector<Node>& selfSel);
145
  /** Reference to the quantifiers state */
146
  QuantifiersState& d_qstate;
147
  /** Reference to the term registry */
148
  TermRegistry& d_treg;
149
  /** quantified formulas that have been skolemized */
150
  NodeNodeMap d_skolemized;
151
  /** map from quantified formulas to the list of skolem constants */
152
  std::unordered_map<Node, std::vector<Node>> d_skolem_constants;
153
  /** map from quantified formulas to their skolemized body */
154
  std::unordered_map<Node, Node> d_skolem_body;
155
  /** Pointer to the proof node manager */
156
  ProofNodeManager* d_pnm;
157
  /** Eager proof generator for skolemization lemmas */
158
  std::unique_ptr<EagerProofGenerator> d_epg;
159
};
160
161
}  // namespace quantifiers
162
}  // namespace theory
163
}  // namespace cvc5
164
165
#endif /* CVC5__THEORY__QUANTIFIERS__SKOLEMIZE_H */