GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/skolemize.h Lines: 1 1 100.0 %
Date: 2021-11-07 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, QuantifiersState& qs, TermRegistry& tr);
73
30536
  ~Skolemize() {}
74
  /** skolemize quantified formula q
75
   * If the return value ret of this function is non-null, then ret is a trust
76
   * node corresponding to a new skolemization lemma we generated for q. These
77
   * lemmas are constructed once per user-context.
78
   */
79
  TrustNode process(Node q);
80
  /** get skolem constants for quantified formula q */
81
  bool getSkolemConstants(Node q, std::vector<Node>& skolems);
82
  /** get the i^th skolem constant for quantified formula q */
83
  Node getSkolemConstant(Node q, unsigned i);
84
  /** make skolemized body
85
   *
86
   * This returns the skolemized body n of a
87
   * quantified formula q with inductive strenghtening,
88
   * where typically n is q[1].
89
   *
90
   * The skolem constants/functions we generate by this
91
   * skolemization are added to sk.
92
   *
93
   * The argument fvs are used if we are
94
   * performing skolemization within a nested quantified
95
   * formula. In this case, skolem constants we introduce
96
   * must be parameterized based on the types of fvs and must be
97
   * applied to fvs.
98
   *
99
   * The last two arguments sub and sub_vars are used for
100
   * to carry the body and indices of other induction
101
   * variables if a quantified formula to skolemize
102
   * has multiple induction variables. See page 5
103
   * of Reynolds et al., VMCAI 2015.
104
   */
105
  static Node mkSkolemizedBody(Node q,
106
                               Node n,
107
                               std::vector<TNode>& fvs,
108
                               std::vector<Node>& sk,
109
                               Node& sub,
110
                               std::vector<unsigned>& sub_vars);
111
  /** get the skolemized body for quantified formula q */
112
  Node getSkolemizedBody(Node q);
113
  /** is n a variable that we can apply inductive strenghtening to? */
114
  static bool isInductionTerm(Node n);
115
  /**
116
   * Get skolemization vectors, where for each quantified formula that was
117
   * skolemized, this is the list of skolems that were used to witness the
118
   * negation of that quantified formula (which is equivalent to an existential
119
   * one).
120
   *
121
   * This is used for the command line option
122
   *   --dump-instantiations
123
   * which prints an informal justification of steps taken by the quantifiers
124
   * module.
125
   */
126
  void getSkolemTermVectors(std::map<Node, std::vector<Node> >& sks) const;
127
128
 private:
129
  /** Are proofs enabled? */
130
  bool isProofEnabled() const;
131
  /** get self selectors
132
   * For datatype constructor dtc with type dt,
133
   * this collects the set of datatype selector applications,
134
   * applied to term n, whose return type in ntn, and stores
135
   * them in the vector selfSel.
136
   */
137
  static void getSelfSel(const DType& dt,
138
                         const DTypeConstructor& dc,
139
                         Node n,
140
                         TypeNode ntn,
141
                         std::vector<Node>& selfSel);
142
  /** Reference to the quantifiers state */
143
  QuantifiersState& d_qstate;
144
  /** Reference to the term registry */
145
  TermRegistry& d_treg;
146
  /** quantified formulas that have been skolemized */
147
  NodeNodeMap d_skolemized;
148
  /** map from quantified formulas to the list of skolem constants */
149
  std::unordered_map<Node, std::vector<Node>> d_skolem_constants;
150
  /** map from quantified formulas to their skolemized body */
151
  std::unordered_map<Node, Node> d_skolem_body;
152
  /** Eager proof generator for skolemization lemmas */
153
  std::unique_ptr<EagerProofGenerator> d_epg;
154
};
155
156
}  // namespace quantifiers
157
}  // namespace theory
158
}  // namespace cvc5
159
160
#endif /* CVC5__THEORY__QUANTIFIERS__SKOLEMIZE_H */