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 |
|
|
30 |
|
namespace cvc5 { |
31 |
|
|
32 |
|
class DTypeConstructor; |
33 |
|
|
34 |
|
namespace theory { |
35 |
|
namespace quantifiers { |
36 |
|
|
37 |
|
class QuantifiersState; |
38 |
|
class TermRegistry; |
39 |
|
|
40 |
|
/** Skolemization utility |
41 |
|
* |
42 |
|
* This class constructs Skolemization lemmas. |
43 |
|
* Given a quantified formula q = (forall x. P), |
44 |
|
* its skolemization lemma is of the form: |
45 |
|
* (~ forall x. P ) => ~P * { x -> d_skolem_constants[q] } |
46 |
|
* |
47 |
|
* This class also incorporates techniques for |
48 |
|
* skolemization with "inductive strenghtening", see |
49 |
|
* Section 2 of Reynolds et al., "Induction for SMT |
50 |
|
* Solvers", VMCAI 2015. In the case that x is an inductive |
51 |
|
* datatype or an integer, then we may strengthen the conclusion |
52 |
|
* based on weak well-founded induction. For example, for |
53 |
|
* quantification on lists, a skolemization with inductive |
54 |
|
* strengthening is a lemma of this form: |
55 |
|
* (~ forall x : List. P( x ) ) => |
56 |
|
* ~P( k ) ^ ( is-cons( k ) => P( tail( k ) ) ) |
57 |
|
* For the integers it is: |
58 |
|
* (~ forall x : Int. P( x ) ) => |
59 |
|
* ~P( k ) ^ ( x>0 => P( x-1 ) ) |
60 |
|
* |
61 |
|
* |
62 |
|
* Inductive strenghtening is not enabled by |
63 |
|
* default and can be enabled by option: |
64 |
|
* --quant-ind |
65 |
|
*/ |
66 |
|
class Skolemize |
67 |
|
{ |
68 |
|
typedef context::CDHashMap<Node, Node> NodeNodeMap; |
69 |
|
|
70 |
|
public: |
71 |
|
Skolemize(QuantifiersState& qs, TermRegistry& tr, ProofNodeManager* pnm); |
72 |
9838 |
~Skolemize() {} |
73 |
|
/** skolemize quantified formula q |
74 |
|
* If the return value ret of this function is non-null, then ret is a trust |
75 |
|
* node corresponding to a new skolemization lemma we generated for q. These |
76 |
|
* lemmas are constructed once per user-context. |
77 |
|
*/ |
78 |
|
TrustNode process(Node q); |
79 |
|
/** get skolem constants for quantified formula q */ |
80 |
|
bool getSkolemConstants(Node q, std::vector<Node>& skolems); |
81 |
|
/** get the i^th skolem constant for quantified formula q */ |
82 |
|
Node getSkolemConstant(Node q, unsigned i); |
83 |
|
/** make skolemized body |
84 |
|
* |
85 |
|
* This returns the skolemized body n of a |
86 |
|
* quantified formula q with inductive strenghtening, |
87 |
|
* where typically n is q[1]. |
88 |
|
* |
89 |
|
* The skolem constants/functions we generate by this |
90 |
|
* skolemization are added to sk. |
91 |
|
* |
92 |
|
* The arguments fvTypes and fvs are used if we are |
93 |
|
* performing skolemization within a nested quantified |
94 |
|
* formula. In this case, skolem constants we introduce |
95 |
|
* must be parameterized based on fvTypes and must be |
96 |
|
* applied to fvs. |
97 |
|
* |
98 |
|
* The last two arguments sub and sub_vars are used for |
99 |
|
* to carry the body and indices of other induction |
100 |
|
* variables if a quantified formula to skolemize |
101 |
|
* has multiple induction variables. See page 5 |
102 |
|
* of Reynolds et al., VMCAI 2015. |
103 |
|
*/ |
104 |
|
static Node mkSkolemizedBody(Node q, |
105 |
|
Node n, |
106 |
|
std::vector<TypeNode>& fvTypes, |
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 |
|
/** Pointer to the proof node manager */ |
153 |
|
ProofNodeManager* d_pnm; |
154 |
|
/** Eager proof generator for skolemization lemmas */ |
155 |
|
std::unique_ptr<EagerProofGenerator> d_epg; |
156 |
|
}; |
157 |
|
|
158 |
|
} // namespace quantifiers |
159 |
|
} // namespace theory |
160 |
|
} // namespace cvc5 |
161 |
|
|
162 |
|
#endif /* CVC5__THEORY__QUANTIFIERS__SKOLEMIZE_H */ |