1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds |
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 |
|
* A cache of skolems for theory of sets. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__SETS__SKOLEM_CACHE_H |
19 |
|
#define CVC5__THEORY__SETS__SKOLEM_CACHE_H |
20 |
|
|
21 |
|
#include <map> |
22 |
|
#include <unordered_set> |
23 |
|
|
24 |
|
#include "expr/node.h" |
25 |
|
|
26 |
|
namespace cvc5 { |
27 |
|
namespace theory { |
28 |
|
namespace sets { |
29 |
|
|
30 |
|
/** |
31 |
|
* A cache of all set skolems generated by the TheorySets class. This |
32 |
|
* cache is used to ensure that duplicate skolems are not generated when |
33 |
|
* possible, and helps identify what skolems were allocated in the current run. |
34 |
|
*/ |
35 |
9853 |
class SkolemCache |
36 |
|
{ |
37 |
|
public: |
38 |
|
SkolemCache(); |
39 |
|
/** Identifiers for skolem types |
40 |
|
* |
41 |
|
* The comments below document the properties of each skolem introduced by |
42 |
|
* inference in the sets solver, where by skolem we mean the fresh |
43 |
|
* set variable that witnesses each of "exists k". |
44 |
|
*/ |
45 |
|
enum SkolemId |
46 |
|
{ |
47 |
|
// exists k. k = a |
48 |
|
SK_PURIFY, |
49 |
|
// a != b => exists k. ( k in a != k in b ) |
50 |
|
SK_DISEQUAL, |
51 |
|
// a in tclosure(b) => exists k1 k2. ( a.1, k1 ) in b ^ ( k2, a.2 ) in b ^ |
52 |
|
// ( k1 = k2 V ( k1, k2 ) in tclosure(b) ) |
53 |
|
SK_TCLOSURE_DOWN1, |
54 |
|
SK_TCLOSURE_DOWN2, |
55 |
|
// (a,b) in join(A,B) => exists k. (a,k) in A ^ (k,b) in B |
56 |
|
// This is cached by the nodes corresponding to (a,b) and join(A,B). |
57 |
|
SK_JOIN, |
58 |
|
}; |
59 |
|
|
60 |
|
/** |
61 |
|
* Makes a skolem of type tn that is cached based on the key (a,b,id). |
62 |
|
* Argument c is the variable name of the skolem. |
63 |
|
*/ |
64 |
|
Node mkTypedSkolemCached( |
65 |
|
TypeNode tn, Node a, Node b, SkolemId id, const char* c); |
66 |
|
/** same as above, cached based on key (a,null,id) */ |
67 |
|
Node mkTypedSkolemCached(TypeNode tn, Node a, SkolemId id, const char* c); |
68 |
|
/** Same as above, but without caching. */ |
69 |
|
Node mkTypedSkolem(TypeNode tn, const char* c); |
70 |
|
/** Returns true if n is a skolem allocated by this class */ |
71 |
|
bool isSkolem(Node n) const; |
72 |
|
|
73 |
|
private: |
74 |
|
/** map from node pairs and identifiers to skolems */ |
75 |
|
std::map<Node, std::map<Node, std::map<SkolemId, Node> > > d_skolemCache; |
76 |
|
/** the set of all skolems we have generated */ |
77 |
|
std::unordered_set<Node> d_allSkolems; |
78 |
|
}; |
79 |
|
|
80 |
|
} // namespace sets |
81 |
|
} // namespace theory |
82 |
|
} // namespace cvc5 |
83 |
|
|
84 |
|
#endif /* CVC5__THEORY__STRINGS__SKOLEM_CACHE_H */ |