1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Mathias Preiner |
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 |
|
* sygus_grammar_red |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__QUANTIFIERS__SYGUS_GRAMMAR_RED_H |
19 |
|
#define CVC5__THEORY__QUANTIFIERS__SYGUS_GRAMMAR_RED_H |
20 |
|
|
21 |
|
#include <map> |
22 |
|
#include <vector> |
23 |
|
|
24 |
|
#include "expr/node.h" |
25 |
|
|
26 |
|
namespace cvc5 { |
27 |
|
namespace theory { |
28 |
|
namespace quantifiers { |
29 |
|
|
30 |
|
class TermDbSygus; |
31 |
|
|
32 |
|
/** SygusRedundantCons |
33 |
|
* |
34 |
|
* This class computes the subset of indices of the constructors of a sygus type |
35 |
|
* that are redundant. To use this class, first call initialize( qe, tn ), |
36 |
|
* where tn is a sygus tn. Then, use getRedundant and/or isRedundant to get the |
37 |
|
* indicies of the constructors of tn that are redundant. |
38 |
|
*/ |
39 |
|
class SygusRedundantCons |
40 |
|
{ |
41 |
|
public: |
42 |
446 |
SygusRedundantCons() {} |
43 |
446 |
~SygusRedundantCons() {} |
44 |
|
/** register type tn |
45 |
|
* |
46 |
|
* qe : pointer to the quantifiers engine, |
47 |
|
* tn : the (sygus) type to compute redundant constructors for |
48 |
|
*/ |
49 |
|
void initialize(TermDbSygus* tds, TypeNode tn); |
50 |
|
/** Get the indices of the redundant constructors of the register type */ |
51 |
|
void getRedundant(std::vector<unsigned>& indices); |
52 |
|
/** |
53 |
|
* This function returns true if the i^th constructor of the registered type |
54 |
|
* is redundant. |
55 |
|
*/ |
56 |
|
bool isRedundant(unsigned i); |
57 |
|
|
58 |
|
private: |
59 |
|
/** the registered type */ |
60 |
|
TypeNode d_type; |
61 |
|
/** redundant status |
62 |
|
* |
63 |
|
* For each constructor, status indicating whether the constructor is |
64 |
|
* redundant, where: |
65 |
|
* |
66 |
|
* 0 : not redundant, |
67 |
|
* 1 : redundant since another constructor can be used to construct values for |
68 |
|
* this constructor. |
69 |
|
* |
70 |
|
* For example, for grammar: |
71 |
|
* A -> C > B | B < C | not D |
72 |
|
* B -> x | y |
73 |
|
* C -> 0 | 1 | C+C |
74 |
|
* D -> B >= C |
75 |
|
* If A is register with this class, then we store may store { 0, 1, 0 }, |
76 |
|
* noting that the second constructor of A can be simulated with the first. |
77 |
|
* Notice that the third constructor is not considered redundant. |
78 |
|
*/ |
79 |
|
std::vector<int> d_sygus_red_status; |
80 |
|
/** |
81 |
|
* Map from constructor indices to the generic term for that constructor, |
82 |
|
* where the generic term for a constructor is the (canonical) term returned |
83 |
|
* by a call to TermDbSygus::mkGeneric. |
84 |
|
*/ |
85 |
|
std::map<unsigned, Node> d_gen_terms; |
86 |
|
/** |
87 |
|
* Map from the rewritten form of generic terms for constructors of the |
88 |
|
* registered type to their corresponding constructor index. |
89 |
|
*/ |
90 |
|
std::map<Node, unsigned> d_gen_cons; |
91 |
|
/** get generic list |
92 |
|
* |
93 |
|
* This function constructs all well-typed variants of a term of the form |
94 |
|
* op( x1, ..., xn ) |
95 |
|
* where op is the builtin operator for dt[c], and xi = pre[i] for i=1,...,n. |
96 |
|
* |
97 |
|
* It constructs a list of terms of the form g * sigma, where sigma |
98 |
|
* is an automorphism on { x1...xn } such that for all xi -> xj in sigma, |
99 |
|
* the type for arguments i and j of dt[c] are the same. We store this |
100 |
|
* list of terms in terms. |
101 |
|
* |
102 |
|
* This function recurses on the arguments of g, index is the current argument |
103 |
|
* we are processing, and pre stores the current arguments of |
104 |
|
* |
105 |
|
* For example, for a sygus grammar |
106 |
|
* A -> and( A, A, B ) |
107 |
|
* B -> false |
108 |
|
* passing arguments such that g=and( x1, x2, x3 ) to this function will add: |
109 |
|
* and( x1, x2, x3 ) and and( x2, x1, x3 ) |
110 |
|
* to terms. |
111 |
|
*/ |
112 |
|
void getGenericList(TermDbSygus* tds, |
113 |
|
const DType& dt, |
114 |
|
unsigned c, |
115 |
|
unsigned index, |
116 |
|
std::map<int, Node>& pre, |
117 |
|
std::vector<Node>& terms); |
118 |
|
}; |
119 |
|
|
120 |
|
} // namespace quantifiers |
121 |
|
} // namespace theory |
122 |
|
} // namespace cvc5 |
123 |
|
|
124 |
|
#endif /* CVC5__THEORY__QUANTIFIERS__SYGUS_GRAMMAR_RED_H */ |