1 /********************* */
4 ** Top contributors (to current version):
5 ** Andrew Reynolds, Kshitij Bansal, Morgan Deters
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2016 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.\endverbatim
12 ** \brief Definitions of SMT2 constants.
14 ** Definitions of SMT2 constants.
16 #include "parser/smt2/smt2.h"
19 #include "expr/type.h"
20 #include "parser/antlr_input.h"
21 #include "parser/parser.h"
22 #include "parser/smt1/smt1.h"
23 #include "parser/smt2/smt2_input.h"
24 #include "smt/command.h"
25 #include "util/bitvector.h"
27 // ANTLR defines these, which is really bad!
34 Smt2::Smt2(ExprManager
* exprManager
, Input
* input
, bool strictMode
, bool parseOnly
) :
35 Parser(exprManager
,input
,strictMode
,parseOnly
),
38 d_unsatCoreNames
.push(std::map
<Expr
, std::string
>());
39 if( !strictModeEnabled() ) {
40 addTheory(Smt2::THEORY_CORE
);
44 void Smt2::setLanguage(InputLanguage lang
) {
45 ((Smt2Input
*) getInput())->setLanguage(lang
);
48 void Smt2::addArithmeticOperators() {
49 Parser::addOperator(kind::PLUS
);
50 Parser::addOperator(kind::MINUS
);
51 Parser::addOperator(kind::UMINUS
);
52 Parser::addOperator(kind::MULT
);
53 Parser::addOperator(kind::LT
);
54 Parser::addOperator(kind::LEQ
);
55 Parser::addOperator(kind::GT
);
56 Parser::addOperator(kind::GEQ
);
59 void Smt2::addBitvectorOperators() {
60 addOperator(kind::BITVECTOR_CONCAT
, "concat");
61 addOperator(kind::BITVECTOR_NOT
, "bvnot");
62 addOperator(kind::BITVECTOR_AND
, "bvand");
63 addOperator(kind::BITVECTOR_OR
, "bvor");
64 addOperator(kind::BITVECTOR_NEG
, "bvneg");
65 addOperator(kind::BITVECTOR_PLUS
, "bvadd");
66 addOperator(kind::BITVECTOR_MULT
, "bvmul");
67 addOperator(kind::BITVECTOR_UDIV
, "bvudiv");
68 addOperator(kind::BITVECTOR_UREM
, "bvurem");
69 addOperator(kind::BITVECTOR_SHL
, "bvshl");
70 addOperator(kind::BITVECTOR_LSHR
, "bvlshr");
71 addOperator(kind::BITVECTOR_ULT
, "bvult");
72 addOperator(kind::BITVECTOR_NAND
, "bvnand");
73 addOperator(kind::BITVECTOR_NOR
, "bvnor");
74 addOperator(kind::BITVECTOR_XOR
, "bvxor");
75 addOperator(kind::BITVECTOR_XNOR
, "bvxnor");
76 addOperator(kind::BITVECTOR_COMP
, "bvcomp");
77 addOperator(kind::BITVECTOR_SUB
, "bvsub");
78 addOperator(kind::BITVECTOR_SDIV
, "bvsdiv");
79 addOperator(kind::BITVECTOR_SREM
, "bvsrem");
80 addOperator(kind::BITVECTOR_SMOD
, "bvsmod");
81 addOperator(kind::BITVECTOR_ASHR
, "bvashr");
82 addOperator(kind::BITVECTOR_ULE
, "bvule");
83 addOperator(kind::BITVECTOR_UGT
, "bvugt");
84 addOperator(kind::BITVECTOR_UGE
, "bvuge");
85 addOperator(kind::BITVECTOR_SLT
, "bvslt");
86 addOperator(kind::BITVECTOR_SLE
, "bvsle");
87 addOperator(kind::BITVECTOR_SGT
, "bvsgt");
88 addOperator(kind::BITVECTOR_SGE
, "bvsge");
89 addOperator(kind::BITVECTOR_REDOR
, "bvredor");
90 addOperator(kind::BITVECTOR_REDAND
, "bvredand");
92 Parser::addOperator(kind::BITVECTOR_BITOF
);
93 Parser::addOperator(kind::BITVECTOR_EXTRACT
);
94 Parser::addOperator(kind::BITVECTOR_REPEAT
);
95 Parser::addOperator(kind::BITVECTOR_ZERO_EXTEND
);
96 Parser::addOperator(kind::BITVECTOR_SIGN_EXTEND
);
97 Parser::addOperator(kind::BITVECTOR_ROTATE_LEFT
);
98 Parser::addOperator(kind::BITVECTOR_ROTATE_RIGHT
);
100 Parser::addOperator(kind::INT_TO_BITVECTOR
);
101 Parser::addOperator(kind::BITVECTOR_TO_NAT
);
104 void Smt2::addStringOperators() {
105 addOperator(kind::STRING_CONCAT
, "str.++");
106 addOperator(kind::STRING_LENGTH
, "str.len");
107 addOperator(kind::STRING_SUBSTR
, "str.substr" );
108 addOperator(kind::STRING_STRCTN
, "str.contains" );
109 addOperator(kind::STRING_CHARAT
, "str.at" );
110 addOperator(kind::STRING_STRIDOF
, "str.indexof" );
111 addOperator(kind::STRING_STRREPL
, "str.replace" );
112 addOperator(kind::STRING_PREFIX
, "str.prefixof" );
113 addOperator(kind::STRING_SUFFIX
, "str.suffixof" );
114 addOperator(kind::STRING_ITOS
, "int.to.str" );
115 addOperator(kind::STRING_STOI
, "str.to.int" );
116 addOperator(kind::STRING_U16TOS
, "u16.to.str" );
117 addOperator(kind::STRING_STOU16
, "str.to.u16" );
118 addOperator(kind::STRING_U32TOS
, "u32.to.str" );
119 addOperator(kind::STRING_STOU32
, "str.to.u32" );
120 addOperator(kind::STRING_IN_REGEXP
, "str.in.re");
121 addOperator(kind::STRING_TO_REGEXP
, "str.to.re");
122 addOperator(kind::REGEXP_CONCAT
, "re.++");
123 addOperator(kind::REGEXP_UNION
, "re.union");
124 addOperator(kind::REGEXP_INTER
, "re.inter");
125 addOperator(kind::REGEXP_STAR
, "re.*");
126 addOperator(kind::REGEXP_PLUS
, "re.+");
127 addOperator(kind::REGEXP_OPT
, "re.opt");
128 addOperator(kind::REGEXP_RANGE
, "re.range");
129 addOperator(kind::REGEXP_LOOP
, "re.loop");
132 void Smt2::addFloatingPointOperators() {
133 addOperator(kind::FLOATINGPOINT_FP
, "fp");
134 addOperator(kind::FLOATINGPOINT_EQ
, "fp.eq");
135 addOperator(kind::FLOATINGPOINT_ABS
, "fp.abs");
136 addOperator(kind::FLOATINGPOINT_NEG
, "fp.neg");
137 addOperator(kind::FLOATINGPOINT_PLUS
, "fp.add");
138 addOperator(kind::FLOATINGPOINT_SUB
, "fp.sub");
139 addOperator(kind::FLOATINGPOINT_MULT
, "fp.mul");
140 addOperator(kind::FLOATINGPOINT_DIV
, "fp.div");
141 addOperator(kind::FLOATINGPOINT_FMA
, "fp.fma");
142 addOperator(kind::FLOATINGPOINT_SQRT
, "fp.sqrt");
143 addOperator(kind::FLOATINGPOINT_REM
, "fp.rem");
144 addOperator(kind::FLOATINGPOINT_RTI
, "fp.roundToIntegral");
145 addOperator(kind::FLOATINGPOINT_MIN
, "fp.min");
146 addOperator(kind::FLOATINGPOINT_MAX
, "fp.max");
147 addOperator(kind::FLOATINGPOINT_LEQ
, "fp.leq");
148 addOperator(kind::FLOATINGPOINT_LT
, "fp.lt");
149 addOperator(kind::FLOATINGPOINT_GEQ
, "fp.geq");
150 addOperator(kind::FLOATINGPOINT_GT
, "fp.gt");
151 addOperator(kind::FLOATINGPOINT_ISN
, "fp.isNormal");
152 addOperator(kind::FLOATINGPOINT_ISSN
, "fp.isSubnormal");
153 addOperator(kind::FLOATINGPOINT_ISZ
, "fp.isZero");
154 addOperator(kind::FLOATINGPOINT_ISINF
, "fp.isInfinite");
155 addOperator(kind::FLOATINGPOINT_ISNAN
, "fp.isNaN");
156 addOperator(kind::FLOATINGPOINT_ISNEG
, "fp.isNegative");
157 addOperator(kind::FLOATINGPOINT_ISPOS
, "fp.isPositive");
158 addOperator(kind::FLOATINGPOINT_TO_REAL
, "fp.to_real");
160 Parser::addOperator(kind::FLOATINGPOINT_TO_FP_IEEE_BITVECTOR
);
161 Parser::addOperator(kind::FLOATINGPOINT_TO_FP_FLOATINGPOINT
);
162 Parser::addOperator(kind::FLOATINGPOINT_TO_FP_REAL
);
163 Parser::addOperator(kind::FLOATINGPOINT_TO_FP_SIGNED_BITVECTOR
);
164 Parser::addOperator(kind::FLOATINGPOINT_TO_FP_UNSIGNED_BITVECTOR
);
165 Parser::addOperator(kind::FLOATINGPOINT_TO_UBV
);
166 Parser::addOperator(kind::FLOATINGPOINT_TO_SBV
);
169 void Smt2::addSepOperators() {
170 addOperator(kind::SEP_STAR
, "sep");
171 addOperator(kind::SEP_PTO
, "pto");
172 addOperator(kind::SEP_WAND
, "wand");
173 addOperator(kind::SEP_EMP
, "emp");
174 Parser::addOperator(kind::SEP_STAR
);
175 Parser::addOperator(kind::SEP_PTO
);
176 Parser::addOperator(kind::SEP_WAND
);
177 Parser::addOperator(kind::SEP_EMP
);
180 void Smt2::addTheory(Theory theory
) {
183 addOperator(kind::SELECT
, "select");
184 addOperator(kind::STORE
, "store");
187 case THEORY_BITVECTORS
:
188 addBitvectorOperators();
192 defineType("Bool", getExprManager()->booleanType());
193 defineVar("true", getExprManager()->mkConst(true));
194 defineVar("false", getExprManager()->mkConst(false));
195 Parser::addOperator(kind::AND
);
196 Parser::addOperator(kind::DISTINCT
);
197 Parser::addOperator(kind::EQUAL
);
198 Parser::addOperator(kind::IFF
);
199 Parser::addOperator(kind::IMPLIES
);
200 Parser::addOperator(kind::ITE
);
201 Parser::addOperator(kind::NOT
);
202 Parser::addOperator(kind::OR
);
203 Parser::addOperator(kind::XOR
);
206 case THEORY_REALS_INTS
:
207 defineType("Real", getExprManager()->realType());
208 Parser::addOperator(kind::DIVISION
);
209 addOperator(kind::TO_INTEGER
, "to_int");
210 addOperator(kind::IS_INTEGER
, "is_int");
211 addOperator(kind::TO_REAL
, "to_real");
212 // falling through on purpose, to add Ints part of Reals_Ints
214 defineType("Int", getExprManager()->integerType());
215 addArithmeticOperators();
216 addOperator(kind::INTS_DIVISION
, "div");
217 addOperator(kind::INTS_MODULUS
, "mod");
218 addOperator(kind::ABS
, "abs");
219 Parser::addOperator(kind::DIVISIBLE
);
223 defineType("Real", getExprManager()->realType());
224 addArithmeticOperators();
225 Parser::addOperator(kind::DIVISION
);
228 case THEORY_QUANTIFIERS
:
232 addOperator(kind::UNION
, "union");
233 addOperator(kind::INTERSECTION
, "intersection");
234 addOperator(kind::SETMINUS
, "setminus");
235 addOperator(kind::SUBSET
, "subset");
236 addOperator(kind::MEMBER
, "member");
237 addOperator(kind::SINGLETON
, "singleton");
238 addOperator(kind::INSERT
, "insert");
239 addOperator(kind::CARD
, "card");
242 case THEORY_DATATYPES
:
243 Parser::addOperator(kind::APPLY_CONSTRUCTOR
);
244 Parser::addOperator(kind::APPLY_TESTER
);
245 Parser::addOperator(kind::APPLY_SELECTOR
);
246 Parser::addOperator(kind::APPLY_SELECTOR_TOTAL
);
250 defineType("String", getExprManager()->stringType());
251 defineType("Int", getExprManager()->integerType());
252 addStringOperators();
256 Parser::addOperator(kind::APPLY_UF
);
260 defineType("RoundingMode", getExprManager()->roundingModeType());
261 defineType("Float16", getExprManager()->mkFloatingPointType(5, 11));
262 defineType("Float32", getExprManager()->mkFloatingPointType(8, 24));
263 defineType("Float64", getExprManager()->mkFloatingPointType(11, 53));
264 defineType("Float128", getExprManager()->mkFloatingPointType(15, 113));
265 addFloatingPointOperators();
273 std::stringstream ss
;
274 ss
<< "internal error: unsupported theory " << theory
;
275 throw ParserException(ss
.str());
279 void Smt2::addOperator(Kind kind
, const std::string
& name
) {
280 Debug("parser") << "Smt2::addOperator( " << kind
<< ", " << name
<< " )"
282 Parser::addOperator(kind
);
283 operatorKindMap
[name
] = kind
;
286 Kind
Smt2::getOperatorKind(const std::string
& name
) const {
287 // precondition: isOperatorEnabled(name)
288 return operatorKindMap
.find(name
)->second
;
291 bool Smt2::isOperatorEnabled(const std::string
& name
) const {
292 return operatorKindMap
.find(name
) != operatorKindMap
.end();
295 bool Smt2::isTheoryEnabled(Theory theory
) const {
298 return d_logic
.isTheoryEnabled(theory::THEORY_ARRAY
);
299 case THEORY_BITVECTORS
:
300 return d_logic
.isTheoryEnabled(theory::THEORY_BV
);
303 case THEORY_DATATYPES
:
304 return d_logic
.isTheoryEnabled(theory::THEORY_DATATYPES
);
306 return d_logic
.isTheoryEnabled(theory::THEORY_ARITH
) &&
307 d_logic
.areIntegersUsed() && ( !d_logic
.areRealsUsed() );
309 return d_logic
.isTheoryEnabled(theory::THEORY_ARITH
) &&
310 ( !d_logic
.areIntegersUsed() ) && d_logic
.areRealsUsed();
311 case THEORY_REALS_INTS
:
312 return d_logic
.isTheoryEnabled(theory::THEORY_ARITH
) &&
313 d_logic
.areIntegersUsed() && d_logic
.areRealsUsed();
314 case THEORY_QUANTIFIERS
:
315 return d_logic
.isQuantified();
317 return d_logic
.isTheoryEnabled(theory::THEORY_SETS
);
319 return d_logic
.isTheoryEnabled(theory::THEORY_STRINGS
);
321 return d_logic
.isTheoryEnabled(theory::THEORY_UF
);
323 return d_logic
.isTheoryEnabled(theory::THEORY_FP
);
325 return d_logic
.isTheoryEnabled(theory::THEORY_SEP
);
327 std::stringstream ss
;
328 ss
<< "internal error: unsupported theory " << theory
;
329 throw ParserException(ss
.str());
333 bool Smt2::logicIsSet() {
339 d_logic
= LogicInfo();
340 operatorKindMap
.clear();
341 d_lastNamedTerm
= std::pair
<Expr
, std::string
>();
342 d_unsatCoreNames
= std::stack
< std::map
<Expr
, std::string
> >();
343 this->Parser::reset();
345 d_unsatCoreNames
.push(std::map
<Expr
, std::string
>());
346 if( !strictModeEnabled() ) {
347 addTheory(Smt2::THEORY_CORE
);
351 void Smt2::resetAssertions() {
352 this->Parser::reset();
355 void Smt2::setLogic(std::string name
) {
357 if(name
== "Arrays") {
359 } else if(name
== "Reals") {
361 } else if(name
== "LIA") {
363 } else if(name
== "LRA") {
365 } else if(name
== "LIRA") {
367 } else if(name
== "BV") {
369 } else if(name
== "SLIA") {
371 } else if(name
== "ALL_SUPPORTED") {
374 std::stringstream ss
;
375 ss
<< "Unknown SyGuS background logic `" << name
<< "'";
376 parseError(ss
.str());
381 if(logicIsForced()) {
382 d_logic
= getForcedLogic();
387 // Core theory belongs to every logic
388 addTheory(THEORY_CORE
);
390 if(d_logic
.isTheoryEnabled(theory::THEORY_UF
)) {
391 addTheory(THEORY_UF
);
394 if(d_logic
.isTheoryEnabled(theory::THEORY_ARITH
)) {
395 if(d_logic
.areIntegersUsed()) {
396 if(d_logic
.areRealsUsed()) {
397 addTheory(THEORY_REALS_INTS
);
399 addTheory(THEORY_INTS
);
401 } else if(d_logic
.areRealsUsed()) {
402 addTheory(THEORY_REALS
);
406 if(d_logic
.isTheoryEnabled(theory::THEORY_ARRAY
)) {
407 addTheory(THEORY_ARRAYS
);
410 if(d_logic
.isTheoryEnabled(theory::THEORY_BV
)) {
411 addTheory(THEORY_BITVECTORS
);
414 if(d_logic
.isTheoryEnabled(theory::THEORY_DATATYPES
)) {
415 addTheory(THEORY_DATATYPES
);
418 if(d_logic
.isTheoryEnabled(theory::THEORY_SETS
)) {
419 addTheory(THEORY_SETS
);
422 if(d_logic
.isTheoryEnabled(theory::THEORY_STRINGS
)) {
423 addTheory(THEORY_STRINGS
);
426 if(d_logic
.isQuantified()) {
427 addTheory(THEORY_QUANTIFIERS
);
430 if (d_logic
.isTheoryEnabled(theory::THEORY_FP
)) {
431 addTheory(THEORY_FP
);
434 if (d_logic
.isTheoryEnabled(theory::THEORY_SEP
)) {
435 addTheory(THEORY_SEP
);
438 }/* Smt2::setLogic() */
440 void Smt2::setInfo(const std::string
& flag
, const SExpr
& sexpr
) {
444 void Smt2::setOption(const std::string
& flag
, const SExpr
& sexpr
) {
448 void Smt2::checkThatLogicIsSet() {
449 if( ! logicIsSet() ) {
450 if(strictModeEnabled()) {
451 parseError("set-logic must appear before this point.");
456 warning("No set-logic command was given before this point.");
457 warning("CVC4 will assume the non-standard ALL_SUPPORTED logic.");
458 warning("Consider setting a stricter logic for (likely) better performance.");
459 warning("To suppress this warning in the future use (set-logic ALL_SUPPORTED).");
461 setLogic("ALL_SUPPORTED");
464 Command
* c
= new SetBenchmarkLogicCommand("ALL_SUPPORTED");
471 /* The include are managed in the lexer but called in the parser */
472 // Inspired by http://www.antlr3.org/api/C/interop.html
474 static bool newInputStream(const std::string
& filename
, pANTLR3_LEXER lexer
) {
475 Debug("parser") << "Including " << filename
<< std::endl
;
476 // Create a new input stream and take advantage of built in stream stacking
477 // in C target runtime.
479 pANTLR3_INPUT_STREAM in
;
480 #ifdef CVC4_ANTLR3_OLD_INPUT_STREAM
481 in
= antlr3AsciiFileStreamNew((pANTLR3_UINT8
) filename
.c_str());
482 #else /* CVC4_ANTLR3_OLD_INPUT_STREAM */
483 in
= antlr3FileStreamNew((pANTLR3_UINT8
) filename
.c_str(), ANTLR3_ENC_8BIT
);
484 #endif /* CVC4_ANTLR3_OLD_INPUT_STREAM */
486 Debug("parser") << "Can't open " << filename
<< std::endl
;
489 // Same thing as the predefined PUSHSTREAM(in);
490 lexer
->pushCharStream(lexer
, in
);
492 //lexer->rec->state->tokenStartCharIndex = -10;
493 //lexer->emit(lexer);
495 // Note that the input stream is not closed when it EOFs, I don't bother
496 // to do it here, but it is up to you to track streams created like this
497 // and destroy them when the whole parse session is complete. Remember that you
498 // don't want to do this until all tokens have been manipulated all the way through
499 // your tree parsers etc as the token does not store the text it just refers
500 // back to the input stream and trying to get the text for it will abort if you
501 // close the input stream too early.
503 //TODO what said before
507 void Smt2::includeFile(const std::string
& filename
) {
508 // security for online version
509 if(!canIncludeFile()) {
510 parseError("include-file feature was disabled for this run.");
514 AntlrInput
* ai
= static_cast<AntlrInput
*>(getInput());
515 pANTLR3_LEXER lexer
= ai
->getAntlr3Lexer();
516 // get the name of the current stream "Does it work inside an include?"
517 const std::string inputName
= ai
->getInputStreamName();
519 // Find the directory of the current input file
521 size_t pos
= inputName
.rfind('/');
522 if(pos
!= std::string::npos
) {
523 path
= std::string(inputName
, 0, pos
+ 1);
525 path
.append(filename
);
526 if(!newInputStream(path
, lexer
)) {
527 parseError("Couldn't open include file `" + path
+ "'");
531 Expr
Smt2::mkSygusVar(const std::string
& name
, const Type
& type
, bool isPrimed
) {
532 Expr e
= mkBoundVar(name
, type
);
533 d_sygusVars
.push_back(e
);
534 d_sygusVarPrimed
[e
] = false;
536 std::stringstream ss
;
538 Expr ep
= mkBoundVar(ss
.str(), type
);
539 d_sygusVars
.push_back(ep
);
540 d_sygusVarPrimed
[ep
] = true;
545 void collectSygusGrammarTypesFor( Type range
, std::vector
< Type
>& types
, std::map
< Type
, std::vector
< DatatypeConstructorArg
> >& sels
){
546 if( !range
.isBoolean() ){
547 if( std::find( types
.begin(), types
.end(), range
)==types
.end() ){
548 Debug("parser-sygus") << "...will make grammar for " << range
<< std::endl
;
549 types
.push_back( range
);
550 if( range
.isDatatype() ){
551 const Datatype
& dt
= ((DatatypeType
)range
).getDatatype();
552 for( unsigned i
=0; i
<dt
.getNumConstructors(); i
++ ){
553 for( unsigned j
=0; j
<dt
[i
].getNumArgs(); j
++ ){
554 Type crange
= ((SelectorType
)dt
[i
][j
].getType()).getRangeType();
555 sels
[crange
].push_back( dt
[i
][j
] );
556 collectSygusGrammarTypesFor( crange
, types
, sels
);
564 void Smt2::mkSygusDefaultGrammar( const Type
& range
, Expr
& bvl
, const std::string
& fun
, std::vector
<CVC4::Datatype
>& datatypes
,
565 std::vector
<Type
>& sorts
, std::vector
< std::vector
<Expr
> >& ops
, std::vector
<Expr
> sygus_vars
, int& startIndex
) {
567 //if( !range.isBoolean() && !range.isInteger() && !range.isBitVector() && !range.isDatatype() ){
568 // parseError("No default grammar for type.");
571 Debug("parser-sygus") << "Construct default grammar for " << fun
<< " " << range
<< std::endl
;
572 std::map
< CVC4::Type
, CVC4::Type
> sygus_to_builtin
;
574 std::vector
< Type
> types
;
575 std::map
< Type
, std::vector
< DatatypeConstructorArg
> > sels
;
576 //types for each of the variables
577 for( unsigned i
=0; i
<sygus_vars
.size(); i
++ ){
578 collectSygusGrammarTypesFor( sygus_vars
[i
].getType(), types
, sels
);
580 //types connected to range
581 collectSygusGrammarTypesFor( range
, types
, sels
);
583 //name of boolean sort
584 std::stringstream ssb
;
585 ssb
<< fun
<< "_Bool";
586 std::string dbname
= ssb
.str();
587 Type unres_bt
= mkUnresolvedType(ssb
.str());
589 std::vector
< Type
> unres_types
;
590 std::map
< Type
, Type
> type_to_unres
;
591 for( unsigned i
=0; i
<types
.size(); i
++ ){
592 std::stringstream ss
;
593 ss
<< fun
<< "_" << types
[i
];
594 std::string dname
= ss
.str();
595 datatypes
.push_back(Datatype(dname
));
596 ops
.push_back(std::vector
<Expr
>());
597 //make unresolved type
598 Type unres_t
= mkUnresolvedType(dname
);
599 unres_types
.push_back(unres_t
);
600 type_to_unres
[types
[i
]] = unres_t
;
601 sygus_to_builtin
[unres_t
] = types
[i
];
603 for( unsigned i
=0; i
<types
.size(); i
++ ){
604 Debug("parser-sygus") << "Make grammar for " << types
[i
] << " " << unres_types
[i
] << std::endl
;
605 std::vector
<std::string
> cnames
;
606 std::vector
<std::vector
<CVC4::Type
> > cargs
;
607 std::vector
<std::string
> unresolved_gterm_sym
;
608 Type unres_t
= unres_types
[i
];
610 for( unsigned j
=0; j
<sygus_vars
.size(); j
++ ){
611 if( sygus_vars
[j
].getType()==types
[i
] ){
612 std::stringstream ss
;
614 Debug("parser-sygus") << "...add for variable " << ss
.str() << std::endl
;
615 ops
[i
].push_back( sygus_vars
[j
] );
616 cnames
.push_back( ss
.str() );
617 cargs
.push_back( std::vector
< CVC4::Type
>() );
621 std::vector
< Expr
> consts
;
622 mkSygusConstantsForType( types
[i
], consts
);
623 for( unsigned j
=0; j
<consts
.size(); j
++ ){
624 std::stringstream ss
;
626 Debug("parser-sygus") << "...add for constant " << ss
.str() << std::endl
;
627 ops
[i
].push_back( consts
[j
] );
628 cnames
.push_back( ss
.str() );
629 cargs
.push_back( std::vector
< CVC4::Type
>() );
632 CVC4::Kind k
= kind::ITE
;
633 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
634 ops
[i
].push_back(getExprManager()->operatorOf(k
));
635 cnames
.push_back( kind::kindToString(k
) );
636 cargs
.push_back( std::vector
< CVC4::Type
>() );
637 cargs
.back().push_back(unres_bt
);
638 cargs
.back().push_back(unres_t
);
639 cargs
.back().push_back(unres_t
);
641 if( types
[i
].isInteger() ){
642 for( unsigned j
=0; j
<2; j
++ ){
643 CVC4::Kind k
= j
==0 ? kind::PLUS
: kind::MINUS
;
644 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
645 ops
[i
].push_back(getExprManager()->operatorOf(k
));
646 cnames
.push_back(kind::kindToString(k
));
647 cargs
.push_back( std::vector
< CVC4::Type
>() );
648 cargs
.back().push_back(unres_t
);
649 cargs
.back().push_back(unres_t
);
651 }else if( types
[i
].isDatatype() ){
652 Debug("parser-sygus") << "...add for constructors" << std::endl
;
653 const Datatype
& dt
= ((DatatypeType
)types
[i
]).getDatatype();
654 for( unsigned k
=0; k
<dt
.getNumConstructors(); k
++ ){
655 Debug("parser-sygus") << "...for " << dt
[k
].getName() << std::endl
;
656 ops
[i
].push_back( dt
[k
].getConstructor() );
657 cnames
.push_back( dt
[k
].getName() );
658 cargs
.push_back( std::vector
< CVC4::Type
>() );
659 for( unsigned j
=0; j
<dt
[k
].getNumArgs(); j
++ ){
660 Type crange
= ((SelectorType
)dt
[k
][j
].getType()).getRangeType();
661 //Assert( type_to_unres.find(crange)!=type_to_unres.end() );
662 cargs
.back().push_back( type_to_unres
[crange
] );
666 std::stringstream sserr
;
667 sserr
<< "No implementation for default Sygus grammar of type " << types
[i
] << std::endl
;
668 warning(sserr
.str());
670 //add for all selectors to this type
671 if( !sels
[types
[i
]].empty() ){
672 Debug("parser-sygus") << "...add for selectors" << std::endl
;
673 for( unsigned j
=0; j
<sels
[types
[i
]].size(); j
++ ){
674 Debug("parser-sygus") << "...for " << sels
[types
[i
]][j
].getName() << std::endl
;
675 Type arg_type
= ((SelectorType
)sels
[types
[i
]][j
].getType()).getDomain();
676 ops
[i
].push_back( sels
[types
[i
]][j
].getSelector() );
677 cnames
.push_back( sels
[types
[i
]][j
].getName() );
678 cargs
.push_back( std::vector
< CVC4::Type
>() );
679 //Assert( type_to_unres.find(arg_type)!=type_to_unres.end() );
680 cargs
.back().push_back( type_to_unres
[arg_type
] );
683 Debug("parser-sygus") << "...make datatype " << datatypes
.back() << std::endl
;
684 datatypes
[i
].setSygus( types
[i
], bvl
, true, true );
685 mkSygusDatatype( datatypes
[i
], ops
[i
], cnames
, cargs
, unresolved_gterm_sym
, sygus_to_builtin
);
686 sorts
.push_back( types
[i
] );
687 //set start index if applicable
688 if( types
[i
]==range
){
694 Type btype
= getExprManager()->booleanType();
695 datatypes
.push_back(Datatype(dbname
));
696 ops
.push_back(std::vector
<Expr
>());
697 std::vector
<std::string
> cnames
;
698 std::vector
<std::vector
<CVC4::Type
> > cargs
;
699 std::vector
<std::string
> unresolved_gterm_sym
;
700 Debug("parser-sygus") << "Make grammar for " << btype
<< " " << datatypes
.back() << std::endl
;
702 for( unsigned i
=0; i
<sygus_vars
.size(); i
++ ){
703 if( sygus_vars
[i
].getType().isBoolean() ){
704 std::stringstream ss
;
706 Debug("parser-sygus") << "...add for variable " << ss
.str() << std::endl
;
707 ops
.back().push_back( sygus_vars
[i
] );
708 cnames
.push_back( ss
.str() );
709 cargs
.push_back( std::vector
< CVC4::Type
>() );
712 //add constants if no variables and no connected types
713 if( ops
.back().empty() && types
.empty() ){
714 std::vector
< Expr
> consts
;
715 mkSygusConstantsForType( btype
, consts
);
716 for( unsigned j
=0; j
<consts
.size(); j
++ ){
717 std::stringstream ss
;
719 Debug("parser-sygus") << "...add for constant " << ss
.str() << std::endl
;
720 ops
.back().push_back( consts
[j
] );
721 cnames
.push_back( ss
.str() );
722 cargs
.push_back( std::vector
< CVC4::Type
>() );
726 for( unsigned i
=0; i
<3; i
++ ){
727 CVC4::Kind k
= i
==0 ? kind::NOT
: ( i
==1 ? kind::AND
: kind::OR
);
728 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
729 ops
.back().push_back(getExprManager()->operatorOf(k
));
730 cnames
.push_back(kind::kindToString(k
));
731 cargs
.push_back( std::vector
< CVC4::Type
>() );
733 cargs
.back().push_back(unres_bt
);
734 }else if( k
==kind::AND
|| k
==kind::OR
){
735 cargs
.back().push_back(unres_bt
);
736 cargs
.back().push_back(unres_bt
);
739 //add predicates for types
740 for( unsigned i
=0; i
<types
.size(); i
++ ){
741 Debug("parser-sygus") << "...add predicates for " << types
[i
] << std::endl
;
742 //add equality per type
743 CVC4::Kind k
= kind::EQUAL
;
744 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
745 ops
.back().push_back(getExprManager()->operatorOf(k
));
746 std::stringstream ss
;
747 ss
<< kind::kindToString(k
) << "_" << types
[i
];
748 cnames
.push_back(ss
.str());
749 cargs
.push_back( std::vector
< CVC4::Type
>() );
750 cargs
.back().push_back(unres_types
[i
]);
751 cargs
.back().push_back(unres_types
[i
]);
752 //type specific predicates
753 if( types
[i
].isInteger() ){
754 CVC4::Kind k
= kind::LEQ
;
755 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
756 ops
.back().push_back(getExprManager()->operatorOf(k
));
757 cnames
.push_back(kind::kindToString(k
));
758 cargs
.push_back( std::vector
< CVC4::Type
>() );
759 cargs
.back().push_back(unres_types
[i
]);
760 cargs
.back().push_back(unres_types
[i
]);
761 }else if( types
[i
].isDatatype() ){
763 Debug("parser-sygus") << "...add for testers" << std::endl
;
764 const Datatype
& dt
= ((DatatypeType
)types
[i
]).getDatatype();
765 for( unsigned k
=0; k
<dt
.getNumConstructors(); k
++ ){
766 Debug("parser-sygus") << "...for " << dt
[k
].getTesterName() << std::endl
;
767 ops
.back().push_back(dt
[k
].getTester());
768 cnames
.push_back(dt
[k
].getTesterName());
769 cargs
.push_back( std::vector
< CVC4::Type
>() );
770 cargs
.back().push_back(unres_types
[i
]);
775 startIndex
= sorts
.size();
777 Debug("parser-sygus") << "...make datatype " << datatypes
.back() << std::endl
;
778 datatypes
.back().setSygus( btype
, bvl
, true, true );
779 mkSygusDatatype( datatypes
.back(), ops
.back(), cnames
, cargs
, unresolved_gterm_sym
, sygus_to_builtin
);
780 sorts
.push_back( btype
);
782 Debug("parser-sygus") << "...finished make default grammar for " << fun
<< " " << range
<< std::endl
;
785 void Smt2::mkSygusConstantsForType( const Type
& type
, std::vector
<CVC4::Expr
>& ops
) {
786 if( type
.isInteger() ){
787 ops
.push_back(getExprManager()->mkConst(Rational(0)));
788 ops
.push_back(getExprManager()->mkConst(Rational(1)));
789 }else if( type
.isBitVector() ){
790 unsigned sz
= ((BitVectorType
)type
).getSize();
791 BitVector
bval0(sz
, (unsigned int)0);
792 ops
.push_back( getExprManager()->mkConst(bval0
) );
793 BitVector
bval1(sz
, (unsigned int)1);
794 ops
.push_back( getExprManager()->mkConst(bval1
) );
795 }else if( type
.isBoolean() ){
796 ops
.push_back(getExprManager()->mkConst(true));
797 ops
.push_back(getExprManager()->mkConst(false));
802 // This method adds N operators to ops[index], N names to cnames[index] and N type argument vectors to cargs[index] (where typically N=1)
803 // This method may also add new elements pairwise into datatypes/sorts/ops/cnames/cargs in the case of non-flat gterms.
804 void Smt2::processSygusGTerm( CVC4::SygusGTerm
& sgt
, int index
,
805 std::vector
< CVC4::Datatype
>& datatypes
,
806 std::vector
< CVC4::Type
>& sorts
,
807 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
808 std::vector
< std::vector
<std::string
> >& cnames
,
809 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
810 std::vector
< bool >& allow_const
,
811 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
,
812 std::vector
<CVC4::Expr
>& sygus_vars
,
813 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
, std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
,
814 CVC4::Type
& ret
, bool isNested
){
815 if( sgt
.d_gterm_type
==SygusGTerm::gterm_op
|| sgt
.d_gterm_type
==SygusGTerm::gterm_let
){
816 Debug("parser-sygus") << "Add " << sgt
.d_expr
<< " to datatype " << index
<< std::endl
;
818 Kind newKind
= kind::UNDEFINED_KIND
;
819 //convert to UMINUS if one child of MINUS
820 if( sgt
.d_children
.size()==1 && sgt
.d_expr
==getExprManager()->operatorOf(kind::MINUS
) ){
821 oldKind
= kind::MINUS
;
822 newKind
= kind::UMINUS
;
824 //convert to IFF if boolean EQUAL
825 if( sgt
.d_expr
==getExprManager()->operatorOf(kind::EQUAL
) ){
826 Type ctn
= sgt
.d_children
[0].d_type
;
827 std::map
< CVC4::Type
, CVC4::Type
>::iterator it
= sygus_to_builtin
.find( ctn
);
828 if( it
!= sygus_to_builtin
.end() && it
->second
.isBoolean() ){
829 oldKind
= kind::EQUAL
;
833 if( newKind
!=kind::UNDEFINED_KIND
){
834 Expr newExpr
= getExprManager()->operatorOf(newKind
);
835 Debug("parser-sygus") << "Replace " << sgt
.d_expr
<< " with " << newExpr
<< std::endl
;
836 sgt
.d_expr
= newExpr
;
837 std::string oldName
= kind::kindToString(oldKind
);
838 std::string newName
= kind::kindToString(newKind
);
840 if((pos
= sgt
.d_name
.find(oldName
, pos
)) != std::string::npos
){
841 sgt
.d_name
.replace(pos
, oldName
.length(), newName
);
844 ops
[index
].push_back( sgt
.d_expr
);
845 cnames
[index
].push_back( sgt
.d_name
);
846 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
847 for( unsigned i
=0; i
<sgt
.d_children
.size(); i
++ ){
848 std::stringstream ss
;
849 ss
<< datatypes
[index
].getName() << "_" << ops
[index
].size() << "_arg_" << i
;
850 std::string sub_dname
= ss
.str();
851 //add datatype for child
853 pushSygusDatatypeDef( null_type
, sub_dname
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
);
854 int sub_dt_index
= datatypes
.size()-1;
857 processSygusGTerm( sgt
.d_children
[i
], sub_dt_index
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
,
858 sygus_vars
, sygus_to_builtin
, sygus_to_builtin_expr
, sub_ret
, true );
859 //process the nested gterm (either pop the last datatype, or flatten the argument)
860 Type tt
= processSygusNestedGTerm( sub_dt_index
, sub_dname
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
,
861 sygus_to_builtin
, sygus_to_builtin_expr
, sub_ret
);
862 cargs
[index
].back().push_back(tt
);
864 //if let, must create operator
865 if( sgt
.d_gterm_type
==SygusGTerm::gterm_let
){
866 processSygusLetConstructor( sgt
.d_let_vars
, index
, datatypes
, sorts
, ops
, cnames
, cargs
,
867 sygus_vars
, sygus_to_builtin
, sygus_to_builtin_expr
);
869 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_constant
){
870 if( sgt
.getNumChildren()!=0 ){
871 parseError("Bad syntax for Sygus Constant.");
873 std::vector
< Expr
> consts
;
874 mkSygusConstantsForType( sgt
.d_type
, consts
);
875 Debug("parser-sygus") << "...made " << consts
.size() << " constants." << std::endl
;
876 for( unsigned i
=0; i
<consts
.size(); i
++ ){
877 std::stringstream ss
;
879 Debug("parser-sygus") << "...add for constant " << ss
.str() << std::endl
;
880 ops
[index
].push_back( consts
[i
] );
881 cnames
[index
].push_back( ss
.str() );
882 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
884 allow_const
[index
] = true;
885 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_variable
|| sgt
.d_gterm_type
==SygusGTerm::gterm_input_variable
){
886 if( sgt
.getNumChildren()!=0 ){
887 parseError("Bad syntax for Sygus Variable.");
889 Debug("parser-sygus") << "...process " << sygus_vars
.size() << " variables." << std::endl
;
890 for( unsigned i
=0; i
<sygus_vars
.size(); i
++ ){
891 if( sygus_vars
[i
].getType()==sgt
.d_type
){
892 std::stringstream ss
;
894 Debug("parser-sygus") << "...add for variable " << ss
.str() << std::endl
;
895 ops
[index
].push_back( sygus_vars
[i
] );
896 cnames
[index
].push_back( ss
.str() );
897 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
900 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_nested_sort
){
902 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_unresolved
){
904 if( isUnresolvedType(sgt
.d_name
) ){
905 ret
= getSort(sgt
.d_name
);
907 //nested, unresolved symbol...fail
908 std::stringstream ss
;
909 ss
<< "Cannot handle nested unresolved symbol " << sgt
.d_name
<< std::endl
;
910 parseError(ss
.str());
913 //will resolve when adding constructors
914 unresolved_gterm_sym
[index
].push_back(sgt
.d_name
);
916 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_ignore
){
921 bool Smt2::pushSygusDatatypeDef( Type t
, std::string
& dname
,
922 std::vector
< CVC4::Datatype
>& datatypes
,
923 std::vector
< CVC4::Type
>& sorts
,
924 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
925 std::vector
< std::vector
<std::string
> >& cnames
,
926 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
927 std::vector
< bool >& allow_const
,
928 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
){
930 datatypes
.push_back(Datatype(dname
));
931 ops
.push_back(std::vector
<Expr
>());
932 cnames
.push_back(std::vector
<std::string
>());
933 cargs
.push_back(std::vector
<std::vector
<CVC4::Type
> >());
934 allow_const
.push_back(false);
935 unresolved_gterm_sym
.push_back(std::vector
< std::string
>());
939 bool Smt2::popSygusDatatypeDef( std::vector
< CVC4::Datatype
>& datatypes
,
940 std::vector
< CVC4::Type
>& sorts
,
941 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
942 std::vector
< std::vector
<std::string
> >& cnames
,
943 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
944 std::vector
< bool >& allow_const
,
945 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
){
947 datatypes
.pop_back();
951 allow_const
.pop_back();
952 unresolved_gterm_sym
.pop_back();
956 Type
Smt2::processSygusNestedGTerm( int sub_dt_index
, std::string
& sub_dname
, std::vector
< CVC4::Datatype
>& datatypes
,
957 std::vector
< CVC4::Type
>& sorts
,
958 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
959 std::vector
< std::vector
<std::string
> >& cnames
,
960 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
961 std::vector
< bool >& allow_const
,
962 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
,
963 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
,
964 std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
, Type sub_ret
) {
966 Debug("parser-sygus") << "Argument is ";
968 //then, it is the datatype we constructed, which should have a single constructor
969 t
= mkUnresolvedType(sub_dname
);
970 Debug("parser-sygus") << "inline flattening of (auxiliary, local) datatype " << t
<< std::endl
;
971 Debug("parser-sygus") << ": to compute type, construct ground term witnessing the grammar, #cons=" << cargs
[sub_dt_index
].size() << std::endl
;
972 if( cargs
[sub_dt_index
].empty() ){
973 parseError(std::string("Internal error : datatype for nested gterm does not have a constructor."));
975 Expr sop
= ops
[sub_dt_index
][0];
977 if( sop
.getKind() != kind::BUILTIN
&& ( sop
.isConst() || cargs
[sub_dt_index
][0].empty() ) ){
978 curr_t
= sop
.getType();
979 Debug("parser-sygus") << ": it is constant/0-arg cons " << sop
<< " with type " << sop
.getType() << ", debug=" << sop
.isConst() << " " << cargs
[sub_dt_index
][0].size() << std::endl
;
980 sygus_to_builtin_expr
[t
] = sop
;
981 //store that term sop has dedicated sygus type t
982 if( d_sygus_bound_var_type
.find( sop
)==d_sygus_bound_var_type
.end() ){
983 d_sygus_bound_var_type
[sop
] = t
;
986 std::vector
< Expr
> children
;
987 if( sop
.getKind() != kind::BUILTIN
){
988 children
.push_back( sop
);
990 for( unsigned i
=0; i
<cargs
[sub_dt_index
][0].size(); i
++ ){
991 std::map
< CVC4::Type
, CVC4::Expr
>::iterator it
= sygus_to_builtin_expr
.find( cargs
[sub_dt_index
][0][i
] );
992 if( it
==sygus_to_builtin_expr
.end() ){
993 if( sygus_to_builtin
.find( cargs
[sub_dt_index
][0][i
] )==sygus_to_builtin
.end() ){
994 std::stringstream ss
;
995 ss
<< "Missing builtin type for type " << cargs
[sub_dt_index
][0][i
] << "!" << std::endl
;
996 ss
<< "Builtin types are currently : " << std::endl
;
997 for( std::map
< CVC4::Type
, CVC4::Type
>::iterator itb
= sygus_to_builtin
.begin(); itb
!= sygus_to_builtin
.end(); ++itb
){
998 ss
<< " " << itb
->first
<< " -> " << itb
->second
<< std::endl
;
1000 parseError(ss
.str());
1002 Type bt
= sygus_to_builtin
[cargs
[sub_dt_index
][0][i
]];
1003 Debug("parser-sygus") << ": child " << i
<< " introduce type elem for " << cargs
[sub_dt_index
][0][i
] << " " << bt
<< std::endl
;
1004 std::stringstream ss
;
1005 ss
<< t
<< "_x_" << i
;
1006 Expr bv
= mkBoundVar(ss
.str(), bt
);
1007 children
.push_back( bv
);
1008 d_sygus_bound_var_type
[bv
] = cargs
[sub_dt_index
][0][i
];
1010 Debug("parser-sygus") << ": child " << i
<< " existing sygus to builtin expr : " << it
->second
<< std::endl
;
1011 children
.push_back( it
->second
);
1014 Kind sk
= sop
.getKind() != kind::BUILTIN
? kind::APPLY
: getExprManager()->operatorToKind(sop
);
1015 Debug("parser-sygus") << ": operator " << sop
<< " with " << sop
.getKind() << " " << sk
<< std::endl
;
1016 Expr e
= getExprManager()->mkExpr( sk
, children
);
1017 Debug("parser-sygus") << ": constructed " << e
<< ", which has type " << e
.getType() << std::endl
;
1018 curr_t
= e
.getType();
1019 sygus_to_builtin_expr
[t
] = e
;
1021 sorts
[sub_dt_index
] = curr_t
;
1022 sygus_to_builtin
[t
] = curr_t
;
1024 Debug("parser-sygus") << "simple argument " << t
<< std::endl
;
1025 Debug("parser-sygus") << "...removing " << datatypes
.back().getName() << std::endl
;
1026 //otherwise, datatype was unecessary
1027 //pop argument datatype definition
1028 popSygusDatatypeDef( datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
);
1033 void Smt2::processSygusLetConstructor( std::vector
< CVC4::Expr
>& let_vars
,
1035 std::vector
< CVC4::Datatype
>& datatypes
,
1036 std::vector
< CVC4::Type
>& sorts
,
1037 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
1038 std::vector
< std::vector
<std::string
> >& cnames
,
1039 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
1040 std::vector
<CVC4::Expr
>& sygus_vars
,
1041 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
,
1042 std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
) {
1043 std::vector
< CVC4::Expr
> let_define_args
;
1045 int dindex
= cargs
[index
].size()-1;
1046 Debug("parser-sygus") << "Process let constructor for datatype " << datatypes
[index
].getName() << ", #subtypes = " << cargs
[index
][dindex
].size() << std::endl
;
1047 for( unsigned i
=0; i
<cargs
[index
][dindex
].size(); i
++ ){
1048 Debug("parser-sygus") << " " << i
<< " : " << cargs
[index
][dindex
][i
] << std::endl
;
1049 if( i
+1==cargs
[index
][dindex
].size() ){
1050 std::map
< CVC4::Type
, CVC4::Expr
>::iterator it
= sygus_to_builtin_expr
.find( cargs
[index
][dindex
][i
] );
1051 if( it
!=sygus_to_builtin_expr
.end() ){
1052 let_body
= it
->second
;
1054 std::stringstream ss
;
1055 ss
<< datatypes
[index
].getName() << "_body";
1056 let_body
= mkBoundVar(ss
.str(), sygus_to_builtin
[cargs
[index
][dindex
][i
]]);
1057 d_sygus_bound_var_type
[let_body
] = cargs
[index
][dindex
][i
];
1061 Debug("parser-sygus") << std::endl
;
1062 Debug("parser-sygus") << "Body is " << let_body
<< std::endl
;
1063 Debug("parser-sygus") << "# let vars = " << let_vars
.size() << std::endl
;
1064 for( unsigned i
=0; i
<let_vars
.size(); i
++ ){
1065 Debug("parser-sygus") << " let var " << i
<< " : " << let_vars
[i
] << " " << let_vars
[i
].getType() << std::endl
;
1066 let_define_args
.push_back( let_vars
[i
] );
1069 Debug("parser-sygus") << "index = " << index << ", start index = " << start_index << ", #Current datatypes = " << datatypes.size() << std::endl;
1070 for( unsigned i=start_index; i<datatypes.size(); i++ ){
1071 Debug("parser-sygus") << " datatype " << i << " : " << datatypes[i].getName() << ", #cons = " << cargs[i].size() << std::endl;
1072 if( !cargs[i].empty() ){
1073 Debug("parser-sygus") << " operator 0 is " << ops[i][0] << std::endl;
1074 Debug("parser-sygus") << " cons 0 has " << cargs[i][0].size() << " sub fields." << std::endl;
1075 for( unsigned j=0; j<cargs[i][0].size(); j++ ){
1076 Type bt = sygus_to_builtin[cargs[i][0][j]];
1077 Debug("parser-sygus") << " cons 0, selector " << j << " : " << cargs[i][0][j] << " " << bt << std::endl;
1082 //last argument is the return, pop
1083 cargs
[index
][dindex
].pop_back();
1084 collectSygusLetArgs( let_body
, cargs
[index
][dindex
], let_define_args
);
1086 Debug("parser-sygus") << "Make define-fun with " << cargs
[index
][dindex
].size() << " arguments..." << std::endl
;
1087 std::vector
<CVC4::Type
> fsorts
;
1088 for( unsigned i
=0; i
<cargs
[index
][dindex
].size(); i
++ ){
1089 Debug("parser-sygus") << " " << i
<< " : " << let_define_args
[i
] << " " << let_define_args
[i
].getType() << " " << cargs
[index
][dindex
][i
] << std::endl
;
1090 fsorts
.push_back(let_define_args
[i
].getType());
1093 Type ft
= getExprManager()->mkFunctionType(fsorts
, let_body
.getType());
1094 std::stringstream ss
;
1095 ss
<< datatypes
[index
].getName() << "_let";
1096 Expr let_func
= mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
1097 d_sygus_defined_funs
.push_back( let_func
);
1098 preemptCommand( new DefineFunctionCommand(ss
.str(), let_func
, let_define_args
, let_body
) );
1100 ops
[index
].pop_back();
1101 ops
[index
].push_back( let_func
);
1102 cnames
[index
].pop_back();
1103 cnames
[index
].push_back(ss
.str());
1105 //mark function as let constructor
1106 d_sygus_let_func_to_vars
[let_func
].insert( d_sygus_let_func_to_vars
[let_func
].end(), let_define_args
.begin(), let_define_args
.end() );
1107 d_sygus_let_func_to_body
[let_func
] = let_body
;
1108 d_sygus_let_func_to_num_input_vars
[let_func
] = let_vars
.size();
1112 void Smt2::collectSygusLetArgs( CVC4::Expr e
, std::vector
< CVC4::Type
>& sygusArgs
, std::vector
< CVC4::Expr
>& builtinArgs
) {
1113 if( e
.getKind()==kind::BOUND_VARIABLE
){
1114 if( std::find( builtinArgs
.begin(), builtinArgs
.end(), e
)==builtinArgs
.end() ){
1115 builtinArgs
.push_back( e
);
1116 sygusArgs
.push_back( d_sygus_bound_var_type
[e
] );
1117 if( d_sygus_bound_var_type
[e
].isNull() ){
1118 std::stringstream ss
;
1119 ss
<< "While constructing body of let gterm, can't map " << e
<< " to sygus type." << std::endl
;
1120 parseError(ss
.str());
1124 for( unsigned i
=0; i
<e
.getNumChildren(); i
++ ){
1125 collectSygusLetArgs( e
[i
], sygusArgs
, builtinArgs
);
1130 void Smt2::setSygusStartIndex( std::string
& fun
, int startIndex
,
1131 std::vector
< CVC4::Datatype
>& datatypes
,
1132 std::vector
< CVC4::Type
>& sorts
,
1133 std::vector
< std::vector
<CVC4::Expr
> >& ops
) {
1135 CVC4::Datatype tmp_dt
= datatypes
[0];
1136 Type tmp_sort
= sorts
[0];
1137 std::vector
< Expr
> tmp_ops
;
1138 tmp_ops
.insert( tmp_ops
.end(), ops
[0].begin(), ops
[0].end() );
1139 datatypes
[0] = datatypes
[startIndex
];
1140 sorts
[0] = sorts
[startIndex
];
1142 ops
[0].insert( ops
[0].end(), ops
[startIndex
].begin(), ops
[startIndex
].end() );
1143 datatypes
[startIndex
] = tmp_dt
;
1144 sorts
[startIndex
] = tmp_sort
;
1145 ops
[startIndex
].clear();
1146 ops
[startIndex
].insert( ops
[startIndex
].begin(), tmp_ops
.begin(), tmp_ops
.end() );
1147 }else if( startIndex
<0 ){
1148 std::stringstream ss
;
1149 ss
<< "warning: no symbol named Start for synth-fun " << fun
<< std::endl
;
1154 void Smt2::defineSygusFuns() {
1155 // only define each one once
1156 while(d_nextSygusFun
< d_sygusFuns
.size()) {
1157 std::pair
<std::string
, Expr
> p
= d_sygusFuns
[d_nextSygusFun
];
1158 std::string fun
= p
.first
;
1159 Debug("parser-sygus") << "Sygus : define fun " << fun
<< std::endl
;
1160 Expr eval
= p
.second
;
1161 FunctionType evalType
= eval
.getType();
1162 std::vector
<Type
> argTypes
= evalType
.getArgTypes();
1163 Type rangeType
= evalType
.getRangeType();
1164 Debug("parser-sygus") << "...eval type : " << evalType
<< ", #args=" << argTypes
.size() << std::endl
;
1166 // first make the function type
1167 std::vector
<Expr
> sygusVars
;
1168 std::vector
<Type
> funType
;
1169 for(size_t j
= 1; j
< argTypes
.size(); ++j
) {
1170 funType
.push_back(argTypes
[j
]);
1171 std::stringstream ss
;
1172 ss
<< fun
<< "_v_" << j
;
1173 sygusVars
.push_back(getExprManager()->mkBoundVar(ss
.str(), argTypes
[j
]));
1176 if( !funType
.empty() ){
1177 funt
= getExprManager()->mkFunctionType(funType
, rangeType
);
1178 Debug("parser-sygus") << "...eval function type : " << funt
<< std::endl
;
1180 // copy the bound vars
1182 std::vector<Expr> sygusVars;
1183 //std::vector<Type> types;
1184 for(size_t i = 0; i < d_sygusVars.size(); ++i) {
1185 std::stringstream ss;
1186 ss << d_sygusVars[i];
1187 Type type = d_sygusVars[i].getType();
1188 sygusVars.push_back(getExprManager()->mkBoundVar(ss.str(), type));
1189 //types.push_back(type);
1191 Debug("parser-sygus") << "...made vars, #vars=" << sygusVars.size() << std::endl;
1194 //Type t = getExprManager()->mkFunctionType(types, rangeType);
1195 //Debug("parser-sygus") << "...function type : " << t << std::endl;
1199 Expr lambda
= mkFunction(fun
, funt
, ExprManager::VAR_FLAG_DEFINED
);
1200 Debug("parser-sygus") << "...made function : " << lambda
<< std::endl
;
1201 std::vector
<Expr
> applyv
;
1202 Expr funbv
= getExprManager()->mkBoundVar(std::string("f") + fun
, argTypes
[0]);
1203 d_sygusFunSymbols
.push_back(funbv
);
1204 applyv
.push_back(eval
);
1205 applyv
.push_back(funbv
);
1206 for(size_t i
= 0; i
< sygusVars
.size(); ++i
) {
1207 applyv
.push_back(sygusVars
[i
]);
1209 Expr apply
= getExprManager()->mkExpr(kind::APPLY_UF
, applyv
);
1210 Debug("parser-sygus") << "...made apply " << apply
<< std::endl
;
1211 Debug("parser-sygus") << "--> Define " << fun
<< " as " << lambda
<< " " << apply
<< std::endl
;
1212 Command
* cmd
= new DefineFunctionCommand(fun
, lambda
, sygusVars
, apply
);
1213 preemptCommand(cmd
);
1219 void Smt2::mkSygusDatatype( CVC4::Datatype
& dt
, std::vector
<CVC4::Expr
>& ops
,
1220 std::vector
<std::string
>& cnames
, std::vector
< std::vector
< CVC4::Type
> >& cargs
,
1221 std::vector
<std::string
>& unresolved_gterm_sym
,
1222 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
) {
1223 Debug("parser-sygus") << "Making sygus datatype " << dt
.getName() << std::endl
;
1224 Debug("parser-sygus") << " add constructors..." << std::endl
;
1225 for( int i
=0; i
<(int)cnames
.size(); i
++ ){
1226 bool is_dup
= false;
1227 bool is_dup_op
= false;
1229 std::vector
< Expr
> let_args
;
1230 unsigned let_num_input_args
= 0;
1231 for( int j
=0; j
<i
; j
++ ){
1232 if( ops
[i
]==ops
[j
] ){
1234 if( cargs
[i
].size()==cargs
[j
].size() ){
1236 for( unsigned k
=0; k
<cargs
[i
].size(); k
++ ){
1237 if( cargs
[i
][k
]!=cargs
[j
][k
] ){
1249 Debug("parser-sygus") << "--> Duplicate gterm : " << ops
[i
] << " at " << i
<< std::endl
;
1250 ops
.erase( ops
.begin() + i
, ops
.begin() + i
+ 1 );
1251 cnames
.erase( cnames
.begin() + i
, cnames
.begin() + i
+ 1 );
1252 cargs
.erase( cargs
.begin() + i
, cargs
.begin() + i
+ 1 );
1254 }else if( is_dup_op
){
1255 Debug("parser-sygus") << "--> Duplicate gterm operator : " << ops
[i
] << " at " << i
<< std::endl
;
1256 //make into define-fun
1257 std::vector
<CVC4::Type
> fsorts
;
1258 for( unsigned j
=0; j
<cargs
[i
].size(); j
++ ){
1259 Type bt
= sygus_to_builtin
[cargs
[i
][j
]];
1260 std::stringstream ss
;
1261 ss
<< dt
.getName() << "_x_" << i
<< "_" << j
;
1262 Expr v
= mkBoundVar(ss
.str(), bt
);
1263 let_args
.push_back( v
);
1264 fsorts
.push_back( bt
);
1265 Debug("parser-sygus") << ": var " << i
<< " " << v
<< " with type " << bt
<< " from " << cargs
[i
][j
] << std::endl
;
1268 std::vector
< Expr
> children
;
1269 if( ops
[i
].getKind() != kind::BUILTIN
){
1270 children
.push_back( ops
[i
] );
1272 children
.insert( children
.end(), let_args
.begin(), let_args
.end() );
1273 Kind sk
= ops
[i
].getKind() != kind::BUILTIN
? kind::APPLY
: getExprManager()->operatorToKind(ops
[i
]);
1274 Debug("parser-sygus") << ": replace " << ops
[i
] << " " << ops
[i
].getKind() << " " << sk
<< std::endl
;
1275 let_body
= getExprManager()->mkExpr( sk
, children
);
1276 Debug("parser-sygus") << ": new body of function is " << let_body
<< std::endl
;
1278 Type ft
= getExprManager()->mkFunctionType(fsorts
, let_body
.getType());
1279 Debug("parser-sygus") << ": function type is " << ft
<< std::endl
;
1280 std::stringstream ss
;
1281 ss
<< dt
.getName() << "_df_" << i
;
1282 //replace operator and name
1283 ops
[i
] = mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
1284 cnames
[i
] = ss
.str();
1285 d_sygus_defined_funs
.push_back( ops
[i
] );
1286 preemptCommand( new DefineFunctionCommand(ss
.str(), ops
[i
], let_args
, let_body
) );
1287 addSygusDatatypeConstructor( dt
, ops
[i
], cnames
[i
], cargs
[i
], let_body
, let_args
, 0 );
1289 std::map
< CVC4::Expr
, CVC4::Expr
>::iterator it
= d_sygus_let_func_to_body
.find( ops
[i
] );
1290 if( it
!=d_sygus_let_func_to_body
.end() ){
1291 let_body
= it
->second
;
1292 let_args
.insert( let_args
.end(), d_sygus_let_func_to_vars
[ops
[i
]].begin(), d_sygus_let_func_to_vars
[ops
[i
]].end() );
1293 let_num_input_args
= d_sygus_let_func_to_num_input_vars
[ops
[i
]];
1295 addSygusDatatypeConstructor( dt
, ops
[i
], cnames
[i
], cargs
[i
], let_body
, let_args
, let_num_input_args
);
1298 Debug("parser-sygus") << " add constructors for unresolved symbols..." << std::endl
;
1299 if( !unresolved_gterm_sym
.empty() ){
1300 std::vector
< Type
> types
;
1301 Debug("parser-sygus") << "...resolve " << unresolved_gterm_sym
.size() << " symbols..." << std::endl
;
1302 for( unsigned i
=0; i
<unresolved_gterm_sym
.size(); i
++ ){
1303 Debug("parser-sygus") << " resolve : " << unresolved_gterm_sym
[i
] << std::endl
;
1304 if( isUnresolvedType(unresolved_gterm_sym
[i
]) ){
1305 Debug("parser-sygus") << " it is an unresolved type." << std::endl
;
1306 Type t
= getSort(unresolved_gterm_sym
[i
]);
1307 if( std::find( types
.begin(), types
.end(), t
)==types
.end() ){
1308 types
.push_back( t
);
1310 Type bt
= dt
.getSygusType();
1311 Debug("parser-sygus") << ": make identity function for " << bt
<< ", argument type " << t
<< std::endl
;
1312 std::stringstream ss
;
1314 Expr let_body
= mkBoundVar(ss
.str(), bt
);
1315 std::vector
< Expr
> let_args
;
1316 let_args
.push_back( let_body
);
1317 //make the identity function
1318 Type ft
= getExprManager()->mkFunctionType(bt
, bt
);
1319 std::stringstream ssid
;
1320 ssid
<< unresolved_gterm_sym
[i
] << "_id";
1321 Expr id_op
= mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
1322 d_sygus_defined_funs
.push_back( id_op
);
1323 preemptCommand( new DefineFunctionCommand(ssid
.str(), id_op
, let_args
, let_body
) );
1324 //make the sygus argument list
1325 std::vector
< Type
> id_carg
;
1326 id_carg
.push_back( t
);
1327 addSygusDatatypeConstructor( dt
, id_op
, unresolved_gterm_sym
[i
], id_carg
, let_body
, let_args
, 0 );
1329 ops
.push_back( id_op
);
1332 Debug("parser-sygus") << " ignore. (likely a free let variable)" << std::endl
;
1339 void Smt2::addSygusDatatypeConstructor( CVC4::Datatype
& dt
, CVC4::Expr op
, std::string
& cname
, std::vector
< CVC4::Type
>& cargs
,
1340 CVC4::Expr
& let_body
, std::vector
< CVC4::Expr
>& let_args
, unsigned let_num_input_args
) {
1341 Debug("parser-sygus") << "--> Add constructor " << cname
<< " to " << dt
.getName() << std::endl
;
1342 if( !let_body
.isNull() ){
1343 Debug("parser-sygus") << " let body = " << let_body
<< ", args = " << let_args
.size() << "," << let_num_input_args
<< std::endl
;
1344 //TODO : remove arguments not occurring in body
1345 //if this is a self identity function, ignore
1346 if( let_args
.size()==0 && let_args
[0]==let_body
){
1347 Debug("parser-sygus") << " identity function " << cargs
[0] << " to " << dt
.getName() << std::endl
;
1351 std::string name
= dt
.getName() + "_" + cname
;
1352 std::string
testerId("is-");
1353 testerId
.append(name
);
1354 checkDeclaration(name
, CHECK_UNDECLARED
, SYM_VARIABLE
);
1355 checkDeclaration(testerId
, CHECK_UNDECLARED
, SYM_VARIABLE
);
1356 CVC4::DatatypeConstructor
c(name
, testerId
);
1357 c
.setSygus( op
, let_body
, let_args
, let_num_input_args
);
1358 for( unsigned j
=0; j
<cargs
.size(); j
++ ){
1359 Debug("parser-sygus-debug") << " arg " << j
<< " : " << cargs
[j
] << std::endl
;
1360 std::stringstream sname
;
1361 sname
<< name
<< "_" << j
;
1362 c
.addArg(sname
.str(), cargs
[j
]);
1364 dt
.addConstructor(c
);
1368 // i is index in datatypes/ops
1369 // j is index is datatype
1370 Expr
Smt2::getSygusAssertion( std::vector
<DatatypeType
>& datatypeTypes
, std::vector
< std::vector
<Expr
> >& ops
,
1371 std::map
<DatatypeType
, Expr
>& evals
, std::vector
<Expr
>& terms
,
1372 Expr eval
, const Datatype
& dt
, size_t i
, size_t j
) {
1373 const DatatypeConstructor
& ctor
= dt
[j
];
1374 Debug("parser-sygus") << "Sygus : process constructor " << j
<< " : " << dt
[j
] << std::endl
;
1375 std::vector
<Expr
> bvs
, extraArgs
;
1376 for(size_t k
= 0; k
< ctor
.getNumArgs(); ++k
) {
1377 std::string vname
= "v_" + ctor
[k
].getName();
1378 Expr bv
= getExprManager()->mkBoundVar(vname
, SelectorType(ctor
[k
].getType()).getRangeType());
1380 extraArgs
.push_back(bv
);
1382 if( !terms
[0].isNull() ){
1383 bvs
.insert(bvs
.end(), terms
[0].begin(), terms
[0].end());
1387 bvl
= getExprManager()->mkExpr(kind::BOUND_VAR_LIST
, bvs
);
1389 Debug("parser-sygus") << "...made bv list " << bvl
<< std::endl
;
1390 std::vector
<Expr
> patv
;
1391 patv
.push_back(eval
);
1392 std::vector
<Expr
> applyv
;
1393 applyv
.push_back(ctor
.getConstructor());
1394 applyv
.insert(applyv
.end(), extraArgs
.begin(), extraArgs
.end());
1395 for(size_t k
= 0; k
< applyv
.size(); ++k
) {
1397 Expr cpatv
= getExprManager()->mkExpr(kind::APPLY_CONSTRUCTOR
, applyv
);
1398 Debug("parser-sygus") << "...made eval ctor apply " << cpatv
<< std::endl
;
1399 patv
.push_back(cpatv
);
1400 if( !terms
[0].isNull() ){
1401 patv
.insert(patv
.end(), terms
[0].begin(), terms
[0].end());
1403 Expr evalApply
= getExprManager()->mkExpr(kind::APPLY_UF
, patv
);
1404 Debug("parser-sygus") << "...made eval apply " << evalApply
<< std::endl
;
1405 std::vector
<Expr
> builtApply
;
1406 for(size_t k
= 0; k
< extraArgs
.size(); ++k
) {
1407 std::vector
<Expr
> patvb
;
1408 patvb
.push_back(evals
[DatatypeType(extraArgs
[k
].getType())]);
1409 patvb
.push_back(extraArgs
[k
]);
1410 if( !terms
[0].isNull() ){
1411 patvb
.insert(patvb
.end(), terms
[0].begin(), terms
[0].end());
1413 Debug("parser-sygus-debug") << "...add to built apply " << evals
[DatatypeType(extraArgs
[k
].getType())] << " " << extraArgs
[k
] << " " << extraArgs
[k
].getType() << std::endl
;
1414 builtApply
.push_back(getExprManager()->mkExpr(kind::APPLY_UF
, patvb
));
1415 Debug("parser-sygus-debug") << "...added " << builtApply
.back() << std::endl
;
1417 for(size_t k
= 0; k
< builtApply
.size(); ++k
) {
1420 Debug("parser-sygus") << "...operator is : " << ops
[i
][j
] << ", type = " << ops
[i
][j
].getType() << ", kind = " << ops
[i
][j
].getKind() << ", is defined = " << isDefinedFunction( ops
[i
][j
] ) << std::endl
;
1421 if( ops
[i
][j
].getKind() != kind::BUILTIN
){
1422 Kind ok
= kind::UNDEFINED_KIND
;
1423 if( isDefinedFunction( ops
[i
][j
] ) || std::find( d_sygus_defined_funs
.begin(), d_sygus_defined_funs
.end(), ops
[i
][j
] )!=d_sygus_defined_funs
.end() ){
1426 Type t
= ops
[i
][j
].getType();
1427 if( t
.isConstructor() ){
1428 ok
= kind::APPLY_CONSTRUCTOR
;
1429 }else if( t
.isSelector() ){
1430 ok
= kind::APPLY_SELECTOR
;
1431 }else if( t
.isTester() ){
1432 ok
= kind::APPLY_TESTER
;
1434 ok
= getExprManager()->operatorToKind( ops
[i
][j
] );
1437 Debug("parser-sygus") << "...processed operator kind : " << ok
<< std::endl
;
1438 if( ok
!=kind::UNDEFINED_KIND
){
1439 builtTerm
= getExprManager()->mkExpr(ok
, ops
[i
][j
], builtApply
);
1441 builtTerm
= ops
[i
][j
];
1444 if( !builtApply
.empty() ){
1445 builtTerm
= getExprManager()->mkExpr(ops
[i
][j
], builtApply
);
1447 builtTerm
= ops
[i
][j
];
1450 Debug("parser-sygus") << "...made built term " << builtTerm
<< std::endl
;
1451 Expr assertion
= getExprManager()->mkExpr(evalApply
.getType().isBoolean() ? kind::IFF
: kind::EQUAL
, evalApply
, builtTerm
);
1452 if( !bvl
.isNull() ){
1453 Expr pattern
= getExprManager()->mkExpr(kind::INST_PATTERN
, evalApply
);
1454 pattern
= getExprManager()->mkExpr(kind::INST_PATTERN_LIST
, pattern
);
1455 assertion
= getExprManager()->mkExpr(kind::FORALL
, bvl
, assertion
, pattern
);
1457 Debug("parser-sygus") << "...made assertion " << assertion
<< std::endl
;
1459 //linearize multiplication if possible
1460 if( builtTerm
.getKind()==kind::MULT
){
1461 for(size_t k
= 0; k
< ctor
.getNumArgs(); ++k
) {
1462 Type at
= SelectorType(ctor
[k
].getType()).getRangeType();
1463 if( at
.isDatatype() ){
1464 DatatypeType atd
= (DatatypeType
)SelectorType(ctor
[k
].getType()).getRangeType();
1465 Debug("parser-sygus") << "Argument " << k
<< " " << atd
<< std::endl
;
1466 std::vector
<DatatypeType
>::iterator itd
= std::find( datatypeTypes
.begin(), datatypeTypes
.end(), atd
);
1467 if( itd
!=datatypeTypes
.end() ){
1468 Debug("parser-sygus2") << "Exists in datatypeTypes." << std::endl
;
1469 unsigned index
= itd
-datatypeTypes
.begin();
1470 Debug("parser-sygus2") << "index = " << index
<< std::endl
;
1471 bool isConst
= true;
1472 for( unsigned cc
= 0; cc
< ops
[index
].size(); cc
++ ){
1473 Debug("parser-sygus2") << "ops[" << cc
<< "]=" << ops
[index
][cc
] << std::endl
;
1474 if( ops
[index
][cc
].getKind() != kind::CONST_RATIONAL
){
1480 Debug("parser-sygus") << "Linearize multiplication " << ctor
<< " based on argument " << k
<< std::endl
;
1481 const Datatype
& atdd
= atd
.getDatatype();
1482 std::vector
<Expr
> assertions
;
1483 std::vector
<Expr
> nbvs
;
1484 for( unsigned a
=0; a
<bvl
.getNumChildren(); a
++ ){
1486 nbvs
.push_back( bvl
[a
] );
1489 Expr nbvl
= getExprManager()->mkExpr( kind::BOUND_VAR_LIST
, nbvs
);
1490 for( unsigned cc
= 0; cc
< ops
[index
].size(); cc
++ ){
1491 //Make new assertion based on partially instantiating existing
1492 applyv
[k
+1] = getExprManager()->mkExpr(kind::APPLY_CONSTRUCTOR
, atdd
[cc
].getConstructor());
1493 Debug("parser-sygus") << "applyv " << applyv
[k
+1] << std::endl
;
1494 cpatv
= getExprManager()->mkExpr(kind::APPLY_CONSTRUCTOR
, applyv
);
1495 Debug("parser-sygus") << "cpatv " << cpatv
<< std::endl
;
1497 evalApply
= getExprManager()->mkExpr(kind::APPLY_UF
, patv
);
1498 Debug("parser-sygus") << "evalApply " << evalApply
<< std::endl
;
1499 builtApply
[k
] = ops
[index
][cc
];
1500 Debug("parser-sygus") << "builtApply " << builtApply
[k
] << std::endl
;
1501 builtTerm
= getExprManager()->mkExpr(ops
[i
][j
], builtApply
);
1502 Debug("parser-sygus") << "builtTerm " << builtTerm
<< std::endl
;
1503 Expr eassertion
= getExprManager()->mkExpr(evalApply
.getType().isBoolean() ? kind::IFF
: kind::EQUAL
, evalApply
, builtTerm
);
1504 Expr epattern
= getExprManager()->mkExpr(kind::INST_PATTERN
, evalApply
);
1505 epattern
= getExprManager()->mkExpr(kind::INST_PATTERN_LIST
, epattern
);
1506 eassertion
= getExprManager()->mkExpr(kind::FORALL
, nbvl
, eassertion
, epattern
);
1507 assertions
.push_back( eassertion
);
1509 assertion
= assertions
.size()==1 ? assertions
[0] : getExprManager()->mkExpr( kind::AND
, assertions
);
1510 Debug("parser-sygus") << "...(linearized) assertion is: " << assertion
<< std::endl
;
1519 const void Smt2::getSygusPrimedVars( std::vector
<Expr
>& vars
, bool isPrimed
) {
1520 for( unsigned i
=0; i
<d_sygusVars
.size(); i
++ ){
1521 Expr v
= d_sygusVars
[i
];
1522 std::map
< Expr
, bool >::iterator it
= d_sygusVarPrimed
.find( v
);
1523 if( it
!=d_sygusVarPrimed
.end() ){
1524 if( it
->second
==isPrimed
){
1525 vars
.push_back( v
);
1528 //should never happen
1533 }/* CVC4::parser namespace */
1534 }/* CVC4 namespace */