summaryrefslogtreecommitdiff
path: root/src/theory/quantifiers/skolemize.h
blob: 412f7a0699bc2c59760ee89d531c327fa15429c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/******************************************************************************
 * Top contributors (to current version):
 *   Andrew Reynolds, Mathias Preiner, Abdalrhman Mohamed
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
 * in the top-level source directory and their institutional affiliations.
 * All rights reserved.  See the file COPYING in the top-level source
 * directory for licensing information.
 * ****************************************************************************
 *
 * Utilities for skolemization.
 */

#include "cvc5_private.h"

#ifndef CVC5__THEORY__QUANTIFIERS__SKOLEMIZE_H
#define CVC5__THEORY__QUANTIFIERS__SKOLEMIZE_H

#include <unordered_map>
#include <unordered_set>

#include "context/cdhashmap.h"
#include "expr/node.h"
#include "expr/type_node.h"
#include "theory/eager_proof_generator.h"
#include "theory/trust_node.h"

namespace cvc5 {

class DTypeConstructor;

namespace theory {
namespace quantifiers {

class QuantifiersState;
class TermRegistry;

/** Skolemization utility
 *
 * This class constructs Skolemization lemmas.
 * Given a quantified formula q = (forall x. P),
 * its skolemization lemma is of the form:
 *   (~ forall x. P ) => ~P * { x -> d_skolem_constants[q] }
 *
 * This class also incorporates techniques for
 * skolemization with "inductive strenghtening", see
 * Section 2 of Reynolds et al., "Induction for SMT
 * Solvers", VMCAI 2015. In the case that x is an inductive
 * datatype or an integer, then we may strengthen the conclusion
 * based on weak well-founded induction. For example, for
 * quantification on lists, a skolemization with inductive
 * strengthening is a lemma of this form:
 *   (~ forall x : List. P( x ) ) =>
 *   ~P( k ) ^ ( is-cons( k ) => P( tail( k ) ) )
 * For the integers it is:
 *   (~ forall x : Int. P( x ) ) =>
 *   ~P( k ) ^ ( x>0 => P( x-1 ) )
 *
 *
 * Inductive strenghtening is not enabled by
 * default and can be enabled by option:
 *   --quant-ind
 */
class Skolemize
{
  typedef context::CDHashMap<Node, Node, NodeHashFunction> NodeNodeMap;

 public:
  Skolemize(QuantifiersState& qs, TermRegistry& tr, ProofNodeManager* pnm);
  ~Skolemize() {}
  /** skolemize quantified formula q
   * If the return value ret of this function is non-null, then ret is a trust
   * node corresponding to a new skolemization lemma we generated for q. These
   * lemmas are constructed once per user-context.
   */
  TrustNode process(Node q);
  /** get skolem constants for quantified formula q */
  bool getSkolemConstants(Node q, std::vector<Node>& skolems);
  /** get the i^th skolem constant for quantified formula q */
  Node getSkolemConstant(Node q, unsigned i);
  /** make skolemized body
   *
   * This returns the skolemized body n of a
   * quantified formula q with inductive strenghtening,
   * where typically n is q[1].
   *
   * The skolem constants/functions we generate by this
   * skolemization are added to sk.
   *
   * The arguments fvTypes and fvs are used if we are
   * performing skolemization within a nested quantified
   * formula. In this case, skolem constants we introduce
   * must be parameterized based on fvTypes and must be
   * applied to fvs.
   *
   * The last two arguments sub and sub_vars are used for
   * to carry the body and indices of other induction
   * variables if a quantified formula to skolemize
   * has multiple induction variables. See page 5
   * of Reynolds et al., VMCAI 2015.
   */
  static Node mkSkolemizedBody(Node q,
                               Node n,
                               std::vector<TypeNode>& fvTypes,
                               std::vector<TNode>& fvs,
                               std::vector<Node>& sk,
                               Node& sub,
                               std::vector<unsigned>& sub_vars);
  /** get the skolemized body for quantified formula q */
  Node getSkolemizedBody(Node q);
  /** is n a variable that we can apply inductive strenghtening to? */
  static bool isInductionTerm(Node n);
  /**
   * Get skolemization vectors, where for each quantified formula that was
   * skolemized, this is the list of skolems that were used to witness the
   * negation of that quantified formula (which is equivalent to an existential
   * one).
   *
   * This is used for the command line option
   *   --dump-instantiations
   * which prints an informal justification of steps taken by the quantifiers
   * module.
   */
  void getSkolemTermVectors(std::map<Node, std::vector<Node> >& sks) const;

 private:
  /** Are proofs enabled? */
  bool isProofEnabled() const;
  /** get self selectors
   * For datatype constructor dtc with type dt,
   * this collects the set of datatype selector applications,
   * applied to term n, whose return type in ntn, and stores
   * them in the vector selfSel.
   */
  static void getSelfSel(const DType& dt,
                         const DTypeConstructor& dc,
                         Node n,
                         TypeNode ntn,
                         std::vector<Node>& selfSel);
  /** Reference to the quantifiers state */
  QuantifiersState& d_qstate;
  /** Reference to the term registry */
  TermRegistry& d_treg;
  /** quantified formulas that have been skolemized */
  NodeNodeMap d_skolemized;
  /** map from quantified formulas to the list of skolem constants */
  std::unordered_map<Node, std::vector<Node>, NodeHashFunction>
      d_skolem_constants;
  /** map from quantified formulas to their skolemized body */
  std::unordered_map<Node, Node, NodeHashFunction> d_skolem_body;
  /** Pointer to the proof node manager */
  ProofNodeManager* d_pnm;
  /** Eager proof generator for skolemization lemmas */
  std::unique_ptr<EagerProofGenerator> d_epg;
};

}  // namespace quantifiers
}  // namespace theory
}  // namespace cvc5

#endif /* CVC5__THEORY__QUANTIFIERS__SKOLEMIZE_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback