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 |
|
* Simple symmetry breaking for sygus. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__DATATYPES__SIMPLE_SYM_BREAK_H |
19 |
|
#define CVC5__THEORY__DATATYPES__SIMPLE_SYM_BREAK_H |
20 |
|
|
21 |
|
#include "expr/dtype.h" |
22 |
|
#include "theory/quantifiers/sygus/term_database_sygus.h" |
23 |
|
|
24 |
|
namespace cvc5 { |
25 |
|
namespace theory { |
26 |
|
namespace datatypes { |
27 |
|
|
28 |
|
/** SygusSimpleSymBreak |
29 |
|
* |
30 |
|
* This class implements queries that can be queried statically about sygus |
31 |
|
* grammars, for example, concerning which constructors need not appear at |
32 |
|
* argument positions of others. This is used by the sygus extension of the |
33 |
|
* quantifier-free datatypes procedure for adding symmetry breaking lemmas. |
34 |
|
* We call this class of techniques "simple static symmetry breaking". These |
35 |
|
* techniques have the advantage over "dynamic symmetry breaking" (blocking |
36 |
|
* redundant solutions on demand in datatypes_sygus.h) in that we can design |
37 |
|
* efficient encodings of symmetry breaking constraints, whereas dynamic |
38 |
|
* symmetry breaking may in the worst case block solutions one by one. |
39 |
|
*/ |
40 |
|
class SygusSimpleSymBreak |
41 |
|
{ |
42 |
|
public: |
43 |
|
SygusSimpleSymBreak(quantifiers::TermDbSygus* tds); |
44 |
1231 |
~SygusSimpleSymBreak() {} |
45 |
|
/** consider argument kind |
46 |
|
* |
47 |
|
* This method returns false if the arg^th argument of terms of parent kind |
48 |
|
* pk need not be of kind k. The type tnp is the sygus type of type |
49 |
|
* containing pk, and tn is the sygus type of the arg^th argument of the |
50 |
|
* constructor whose builtin kind is pk. |
51 |
|
* |
52 |
|
* For example, given grammar: |
53 |
|
* A -> A + A | 0 | 1 | x | -A |
54 |
|
* This method will return false for inputs such as: |
55 |
|
* A, A, -, -, 0 (due to cancelling of double unary minus) |
56 |
|
* A, A, +, +, 1 (due to commutativity of addition, we can assume all |
57 |
|
* nested + occurs in the 0^th argument) |
58 |
|
*/ |
59 |
|
bool considerArgKind(TypeNode tn, TypeNode tnp, Kind k, Kind pk, int arg); |
60 |
|
/** consider constant |
61 |
|
* |
62 |
|
* Similar to the above function, this method returns false if the arg^th |
63 |
|
* argument of terms of parent kind pk need not be the constant c. The type |
64 |
|
* tnp is the sygus type of type containing pk, and tn is the sygus type of |
65 |
|
* the arg^th argument of the constructor whose builtin kind is pk. |
66 |
|
* |
67 |
|
* For example, given grammar: |
68 |
|
* A -> B * B | A + A | 0 | 1 | x | -A |
69 |
|
* B -> 0 | x |
70 |
|
* This method will return false for inputs such as: |
71 |
|
* A, A, 0, +, 0 (due to identity of addition with zero) |
72 |
|
* B, A, 0, *, 0 (due to simplification 0*x --> 0, and 0 is generated by A) |
73 |
|
*/ |
74 |
|
bool considerConst(TypeNode tn, TypeNode tnp, Node c, Kind pk, int arg); |
75 |
|
/** solve for argument |
76 |
|
* |
77 |
|
* If this method returns a non-negative integer n, then all terms at |
78 |
|
* the arg^th position of the cindex^th constructor of sygus type tnp need |
79 |
|
* only be of the n^th constructor of that argument. |
80 |
|
* |
81 |
|
* For example, given grammar: |
82 |
|
* A -> A - A | A + A | 0 | 1 | x | y |
83 |
|
* Say solveForArgument(A, 0, 0)=2. This indicates that all terms of the form |
84 |
|
* x1-x2 need only be such that x1 is 0. |
85 |
|
*/ |
86 |
|
int solveForArgument(TypeNode tnp, unsigned cindex, unsigned arg); |
87 |
|
|
88 |
|
private: |
89 |
|
/** Pointer to the sygus term database */ |
90 |
|
quantifiers::TermDbSygus* d_tds; |
91 |
|
/** return the index of the first argument position of c that has type tn */ |
92 |
|
int getFirstArgOccurrence(const DTypeConstructor& c, TypeNode tn); |
93 |
|
/** |
94 |
|
* Helper function for consider const above, pdt is the datatype of the type |
95 |
|
* of tnp. |
96 |
|
*/ |
97 |
|
bool considerConst(const DType& pdt, TypeNode tnp, Node c, Kind pk, int arg); |
98 |
|
}; |
99 |
|
|
100 |
|
} // namespace datatypes |
101 |
|
} // namespace theory |
102 |
|
} // namespace cvc5 |
103 |
|
|
104 |
|
#endif /* CVC5__THEORY__DATATYPES__SIMPLE_SYM_BREAK_H */ |