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
);
170 void Smt2::addTheory(Theory theory
) {
173 addOperator(kind::SELECT
, "select");
174 addOperator(kind::STORE
, "store");
177 case THEORY_BITVECTORS
:
178 addBitvectorOperators();
182 defineType("Bool", getExprManager()->booleanType());
183 defineVar("true", getExprManager()->mkConst(true));
184 defineVar("false", getExprManager()->mkConst(false));
185 Parser::addOperator(kind::AND
);
186 Parser::addOperator(kind::DISTINCT
);
187 Parser::addOperator(kind::EQUAL
);
188 Parser::addOperator(kind::IFF
);
189 Parser::addOperator(kind::IMPLIES
);
190 Parser::addOperator(kind::ITE
);
191 Parser::addOperator(kind::NOT
);
192 Parser::addOperator(kind::OR
);
193 Parser::addOperator(kind::XOR
);
196 case THEORY_REALS_INTS
:
197 defineType("Real", getExprManager()->realType());
198 Parser::addOperator(kind::DIVISION
);
199 addOperator(kind::TO_INTEGER
, "to_int");
200 addOperator(kind::IS_INTEGER
, "is_int");
201 addOperator(kind::TO_REAL
, "to_real");
202 // falling through on purpose, to add Ints part of Reals_Ints
204 defineType("Int", getExprManager()->integerType());
205 addArithmeticOperators();
206 addOperator(kind::INTS_DIVISION
, "div");
207 addOperator(kind::INTS_MODULUS
, "mod");
208 addOperator(kind::ABS
, "abs");
209 Parser::addOperator(kind::DIVISIBLE
);
213 defineType("Real", getExprManager()->realType());
214 addArithmeticOperators();
215 Parser::addOperator(kind::DIVISION
);
218 case THEORY_QUANTIFIERS
:
222 addOperator(kind::UNION
, "union");
223 addOperator(kind::INTERSECTION
, "intersection");
224 addOperator(kind::SETMINUS
, "setminus");
225 addOperator(kind::SUBSET
, "subset");
226 addOperator(kind::MEMBER
, "member");
227 addOperator(kind::SINGLETON
, "singleton");
228 addOperator(kind::INSERT
, "insert");
229 addOperator(kind::CARD
, "card");
232 case THEORY_DATATYPES
:
233 Parser::addOperator(kind::APPLY_CONSTRUCTOR
);
234 Parser::addOperator(kind::APPLY_TESTER
);
235 Parser::addOperator(kind::APPLY_SELECTOR
);
236 Parser::addOperator(kind::APPLY_SELECTOR_TOTAL
);
240 defineType("String", getExprManager()->stringType());
241 defineType("Int", getExprManager()->integerType());
242 addStringOperators();
246 Parser::addOperator(kind::APPLY_UF
);
250 defineType("RoundingMode", getExprManager()->roundingModeType());
251 defineType("Float16", getExprManager()->mkFloatingPointType(5, 11));
252 defineType("Float32", getExprManager()->mkFloatingPointType(8, 24));
253 defineType("Float64", getExprManager()->mkFloatingPointType(11, 53));
254 defineType("Float128", getExprManager()->mkFloatingPointType(15, 113));
255 addFloatingPointOperators();
259 std::stringstream ss
;
260 ss
<< "internal error: unsupported theory " << theory
;
261 throw ParserException(ss
.str());
265 void Smt2::addOperator(Kind kind
, const std::string
& name
) {
266 Debug("parser") << "Smt2::addOperator( " << kind
<< ", " << name
<< " )"
268 Parser::addOperator(kind
);
269 operatorKindMap
[name
] = kind
;
272 Kind
Smt2::getOperatorKind(const std::string
& name
) const {
273 // precondition: isOperatorEnabled(name)
274 return operatorKindMap
.find(name
)->second
;
277 bool Smt2::isOperatorEnabled(const std::string
& name
) const {
278 return operatorKindMap
.find(name
) != operatorKindMap
.end();
281 bool Smt2::isTheoryEnabled(Theory theory
) const {
284 return d_logic
.isTheoryEnabled(theory::THEORY_ARRAY
);
285 case THEORY_BITVECTORS
:
286 return d_logic
.isTheoryEnabled(theory::THEORY_BV
);
289 case THEORY_DATATYPES
:
290 return d_logic
.isTheoryEnabled(theory::THEORY_DATATYPES
);
292 return d_logic
.isTheoryEnabled(theory::THEORY_ARITH
) &&
293 d_logic
.areIntegersUsed() && ( !d_logic
.areRealsUsed() );
295 return d_logic
.isTheoryEnabled(theory::THEORY_ARITH
) &&
296 ( !d_logic
.areIntegersUsed() ) && d_logic
.areRealsUsed();
297 case THEORY_REALS_INTS
:
298 return d_logic
.isTheoryEnabled(theory::THEORY_ARITH
) &&
299 d_logic
.areIntegersUsed() && d_logic
.areRealsUsed();
300 case THEORY_QUANTIFIERS
:
301 return d_logic
.isQuantified();
303 return d_logic
.isTheoryEnabled(theory::THEORY_SETS
);
305 return d_logic
.isTheoryEnabled(theory::THEORY_STRINGS
);
307 return d_logic
.isTheoryEnabled(theory::THEORY_UF
);
309 return d_logic
.isTheoryEnabled(theory::THEORY_FP
);
311 std::stringstream ss
;
312 ss
<< "internal error: unsupported theory " << theory
;
313 throw ParserException(ss
.str());
317 bool Smt2::logicIsSet() {
323 d_logic
= LogicInfo();
324 operatorKindMap
.clear();
325 d_lastNamedTerm
= std::pair
<Expr
, std::string
>();
326 d_unsatCoreNames
= std::stack
< std::map
<Expr
, std::string
> >();
327 this->Parser::reset();
329 d_unsatCoreNames
.push(std::map
<Expr
, std::string
>());
330 if( !strictModeEnabled() ) {
331 addTheory(Smt2::THEORY_CORE
);
335 void Smt2::resetAssertions() {
336 this->Parser::reset();
339 void Smt2::setLogic(std::string name
) {
341 if(name
== "Arrays") {
343 } else if(name
== "Reals") {
345 } else if(name
== "LIA") {
347 } else if(name
== "LRA") {
349 } else if(name
== "LIRA") {
351 } else if(name
== "BV") {
353 } else if(name
== "SLIA") {
355 } else if(name
== "ALL_SUPPORTED") {
358 std::stringstream ss
;
359 ss
<< "Unknown SyGuS background logic `" << name
<< "'";
360 parseError(ss
.str());
365 if(logicIsForced()) {
366 d_logic
= getForcedLogic();
371 // Core theory belongs to every logic
372 addTheory(THEORY_CORE
);
374 if(d_logic
.isTheoryEnabled(theory::THEORY_UF
)) {
375 addTheory(THEORY_UF
);
378 if(d_logic
.isTheoryEnabled(theory::THEORY_ARITH
)) {
379 if(d_logic
.areIntegersUsed()) {
380 if(d_logic
.areRealsUsed()) {
381 addTheory(THEORY_REALS_INTS
);
383 addTheory(THEORY_INTS
);
385 } else if(d_logic
.areRealsUsed()) {
386 addTheory(THEORY_REALS
);
390 if(d_logic
.isTheoryEnabled(theory::THEORY_ARRAY
)) {
391 addTheory(THEORY_ARRAYS
);
394 if(d_logic
.isTheoryEnabled(theory::THEORY_BV
)) {
395 addTheory(THEORY_BITVECTORS
);
398 if(d_logic
.isTheoryEnabled(theory::THEORY_DATATYPES
)) {
399 addTheory(THEORY_DATATYPES
);
402 if(d_logic
.isTheoryEnabled(theory::THEORY_SETS
)) {
403 addTheory(THEORY_SETS
);
406 if(d_logic
.isTheoryEnabled(theory::THEORY_STRINGS
)) {
407 addTheory(THEORY_STRINGS
);
410 if(d_logic
.isQuantified()) {
411 addTheory(THEORY_QUANTIFIERS
);
414 if (d_logic
.isTheoryEnabled(theory::THEORY_FP
)) {
415 addTheory(THEORY_FP
);
418 }/* Smt2::setLogic() */
420 void Smt2::setInfo(const std::string
& flag
, const SExpr
& sexpr
) {
424 void Smt2::setOption(const std::string
& flag
, const SExpr
& sexpr
) {
428 void Smt2::checkThatLogicIsSet() {
429 if( ! logicIsSet() ) {
430 if(strictModeEnabled()) {
431 parseError("set-logic must appear before this point.");
436 warning("No set-logic command was given before this point.");
437 warning("CVC4 will assume the non-standard ALL_SUPPORTED logic.");
438 warning("Consider setting a stricter logic for (likely) better performance.");
439 warning("To suppress this warning in the future use (set-logic ALL_SUPPORTED).");
441 setLogic("ALL_SUPPORTED");
444 Command
* c
= new SetBenchmarkLogicCommand("ALL_SUPPORTED");
451 /* The include are managed in the lexer but called in the parser */
452 // Inspired by http://www.antlr3.org/api/C/interop.html
454 static bool newInputStream(const std::string
& filename
, pANTLR3_LEXER lexer
) {
455 Debug("parser") << "Including " << filename
<< std::endl
;
456 // Create a new input stream and take advantage of built in stream stacking
457 // in C target runtime.
459 pANTLR3_INPUT_STREAM in
;
460 #ifdef CVC4_ANTLR3_OLD_INPUT_STREAM
461 in
= antlr3AsciiFileStreamNew((pANTLR3_UINT8
) filename
.c_str());
462 #else /* CVC4_ANTLR3_OLD_INPUT_STREAM */
463 in
= antlr3FileStreamNew((pANTLR3_UINT8
) filename
.c_str(), ANTLR3_ENC_8BIT
);
464 #endif /* CVC4_ANTLR3_OLD_INPUT_STREAM */
466 Debug("parser") << "Can't open " << filename
<< std::endl
;
469 // Same thing as the predefined PUSHSTREAM(in);
470 lexer
->pushCharStream(lexer
, in
);
472 //lexer->rec->state->tokenStartCharIndex = -10;
473 //lexer->emit(lexer);
475 // Note that the input stream is not closed when it EOFs, I don't bother
476 // to do it here, but it is up to you to track streams created like this
477 // and destroy them when the whole parse session is complete. Remember that you
478 // don't want to do this until all tokens have been manipulated all the way through
479 // your tree parsers etc as the token does not store the text it just refers
480 // back to the input stream and trying to get the text for it will abort if you
481 // close the input stream too early.
483 //TODO what said before
487 void Smt2::includeFile(const std::string
& filename
) {
488 // security for online version
489 if(!canIncludeFile()) {
490 parseError("include-file feature was disabled for this run.");
494 AntlrInput
* ai
= static_cast<AntlrInput
*>(getInput());
495 pANTLR3_LEXER lexer
= ai
->getAntlr3Lexer();
496 // get the name of the current stream "Does it work inside an include?"
497 const std::string inputName
= ai
->getInputStreamName();
499 // Find the directory of the current input file
501 size_t pos
= inputName
.rfind('/');
502 if(pos
!= std::string::npos
) {
503 path
= std::string(inputName
, 0, pos
+ 1);
505 path
.append(filename
);
506 if(!newInputStream(path
, lexer
)) {
507 parseError("Couldn't open include file `" + path
+ "'");
511 Expr
Smt2::mkSygusVar(const std::string
& name
, const Type
& type
, bool isPrimed
) {
512 Expr e
= mkBoundVar(name
, type
);
513 d_sygusVars
.push_back(e
);
514 d_sygusVarPrimed
[e
] = false;
516 std::stringstream ss
;
518 Expr ep
= mkBoundVar(ss
.str(), type
);
519 d_sygusVars
.push_back(ep
);
520 d_sygusVarPrimed
[ep
] = true;
525 void collectSygusGrammarTypesFor( Type range
, std::vector
< Type
>& types
, std::map
< Type
, std::vector
< DatatypeConstructorArg
> >& sels
){
526 if( !range
.isBoolean() ){
527 if( std::find( types
.begin(), types
.end(), range
)==types
.end() ){
528 Debug("parser-sygus") << "...will make grammar for " << range
<< std::endl
;
529 types
.push_back( range
);
530 if( range
.isDatatype() ){
531 const Datatype
& dt
= ((DatatypeType
)range
).getDatatype();
532 for( unsigned i
=0; i
<dt
.getNumConstructors(); i
++ ){
533 for( unsigned j
=0; j
<dt
[i
].getNumArgs(); j
++ ){
534 Type crange
= ((SelectorType
)dt
[i
][j
].getType()).getRangeType();
535 sels
[crange
].push_back( dt
[i
][j
] );
536 collectSygusGrammarTypesFor( crange
, types
, sels
);
544 void Smt2::mkSygusDefaultGrammar( const Type
& range
, Expr
& bvl
, const std::string
& fun
, std::vector
<CVC4::Datatype
>& datatypes
,
545 std::vector
<Type
>& sorts
, std::vector
< std::vector
<Expr
> >& ops
, std::vector
<Expr
> sygus_vars
, int& startIndex
) {
547 //if( !range.isBoolean() && !range.isInteger() && !range.isBitVector() && !range.isDatatype() ){
548 // parseError("No default grammar for type.");
551 Debug("parser-sygus") << "Construct default grammar for " << fun
<< " " << range
<< std::endl
;
552 std::map
< CVC4::Type
, CVC4::Type
> sygus_to_builtin
;
554 std::vector
< Type
> types
;
555 std::map
< Type
, std::vector
< DatatypeConstructorArg
> > sels
;
556 //types for each of the variables
557 for( unsigned i
=0; i
<sygus_vars
.size(); i
++ ){
558 collectSygusGrammarTypesFor( sygus_vars
[i
].getType(), types
, sels
);
560 //types connected to range
561 collectSygusGrammarTypesFor( range
, types
, sels
);
563 //name of boolean sort
564 std::stringstream ssb
;
565 ssb
<< fun
<< "_Bool";
566 std::string dbname
= ssb
.str();
567 Type unres_bt
= mkUnresolvedType(ssb
.str());
569 std::vector
< Type
> unres_types
;
570 std::map
< Type
, Type
> type_to_unres
;
571 for( unsigned i
=0; i
<types
.size(); i
++ ){
572 std::stringstream ss
;
573 ss
<< fun
<< "_" << types
[i
];
574 std::string dname
= ss
.str();
575 datatypes
.push_back(Datatype(dname
));
576 ops
.push_back(std::vector
<Expr
>());
577 //make unresolved type
578 Type unres_t
= mkUnresolvedType(dname
);
579 unres_types
.push_back(unres_t
);
580 type_to_unres
[types
[i
]] = unres_t
;
581 sygus_to_builtin
[unres_t
] = types
[i
];
583 for( unsigned i
=0; i
<types
.size(); i
++ ){
584 Debug("parser-sygus") << "Make grammar for " << types
[i
] << " " << unres_types
[i
] << std::endl
;
585 std::vector
<std::string
> cnames
;
586 std::vector
<std::vector
<CVC4::Type
> > cargs
;
587 std::vector
<std::string
> unresolved_gterm_sym
;
588 Type unres_t
= unres_types
[i
];
590 for( unsigned j
=0; j
<sygus_vars
.size(); j
++ ){
591 if( sygus_vars
[j
].getType()==types
[i
] ){
592 std::stringstream ss
;
594 Debug("parser-sygus") << "...add for variable " << ss
.str() << std::endl
;
595 ops
[i
].push_back( sygus_vars
[j
] );
596 cnames
.push_back( ss
.str() );
597 cargs
.push_back( std::vector
< CVC4::Type
>() );
601 std::vector
< Expr
> consts
;
602 mkSygusConstantsForType( types
[i
], consts
);
603 for( unsigned j
=0; j
<consts
.size(); j
++ ){
604 std::stringstream ss
;
606 Debug("parser-sygus") << "...add for constant " << ss
.str() << std::endl
;
607 ops
[i
].push_back( consts
[j
] );
608 cnames
.push_back( ss
.str() );
609 cargs
.push_back( std::vector
< CVC4::Type
>() );
612 CVC4::Kind k
= kind::ITE
;
613 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
614 ops
[i
].push_back(getExprManager()->operatorOf(k
));
615 cnames
.push_back( kind::kindToString(k
) );
616 cargs
.push_back( std::vector
< CVC4::Type
>() );
617 cargs
.back().push_back(unres_bt
);
618 cargs
.back().push_back(unres_t
);
619 cargs
.back().push_back(unres_t
);
621 if( types
[i
].isInteger() ){
622 for( unsigned j
=0; j
<2; j
++ ){
623 CVC4::Kind k
= j
==0 ? kind::PLUS
: kind::MINUS
;
624 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
625 ops
[i
].push_back(getExprManager()->operatorOf(k
));
626 cnames
.push_back(kind::kindToString(k
));
627 cargs
.push_back( std::vector
< CVC4::Type
>() );
628 cargs
.back().push_back(unres_t
);
629 cargs
.back().push_back(unres_t
);
631 }else if( types
[i
].isDatatype() ){
632 Debug("parser-sygus") << "...add for constructors" << std::endl
;
633 const Datatype
& dt
= ((DatatypeType
)types
[i
]).getDatatype();
634 for( unsigned k
=0; k
<dt
.getNumConstructors(); k
++ ){
635 Debug("parser-sygus") << "...for " << dt
[k
].getName() << std::endl
;
636 ops
[i
].push_back( dt
[k
].getConstructor() );
637 cnames
.push_back( dt
[k
].getName() );
638 cargs
.push_back( std::vector
< CVC4::Type
>() );
639 for( unsigned j
=0; j
<dt
[k
].getNumArgs(); j
++ ){
640 Type crange
= ((SelectorType
)dt
[k
][j
].getType()).getRangeType();
641 //Assert( type_to_unres.find(crange)!=type_to_unres.end() );
642 cargs
.back().push_back( type_to_unres
[crange
] );
646 std::stringstream sserr
;
647 sserr
<< "No implementation for default Sygus grammar of type " << types
[i
] << std::endl
;
648 warning(sserr
.str());
650 //add for all selectors to this type
651 if( !sels
[types
[i
]].empty() ){
652 Debug("parser-sygus") << "...add for selectors" << std::endl
;
653 for( unsigned j
=0; j
<sels
[types
[i
]].size(); j
++ ){
654 Debug("parser-sygus") << "...for " << sels
[types
[i
]][j
].getName() << std::endl
;
655 Type arg_type
= ((SelectorType
)sels
[types
[i
]][j
].getType()).getDomain();
656 ops
[i
].push_back( sels
[types
[i
]][j
].getSelector() );
657 cnames
.push_back( sels
[types
[i
]][j
].getName() );
658 cargs
.push_back( std::vector
< CVC4::Type
>() );
659 //Assert( type_to_unres.find(arg_type)!=type_to_unres.end() );
660 cargs
.back().push_back( type_to_unres
[arg_type
] );
663 Debug("parser-sygus") << "...make datatype " << datatypes
.back() << std::endl
;
664 datatypes
[i
].setSygus( types
[i
], bvl
, true, true );
665 mkSygusDatatype( datatypes
[i
], ops
[i
], cnames
, cargs
, unresolved_gterm_sym
, sygus_to_builtin
);
666 sorts
.push_back( types
[i
] );
667 //set start index if applicable
668 if( types
[i
]==range
){
674 Type btype
= getExprManager()->booleanType();
675 datatypes
.push_back(Datatype(dbname
));
676 ops
.push_back(std::vector
<Expr
>());
677 std::vector
<std::string
> cnames
;
678 std::vector
<std::vector
<CVC4::Type
> > cargs
;
679 std::vector
<std::string
> unresolved_gterm_sym
;
680 Debug("parser-sygus") << "Make grammar for " << btype
<< " " << datatypes
.back() << std::endl
;
682 for( unsigned i
=0; i
<sygus_vars
.size(); i
++ ){
683 if( sygus_vars
[i
].getType().isBoolean() ){
684 std::stringstream ss
;
686 Debug("parser-sygus") << "...add for variable " << ss
.str() << std::endl
;
687 ops
.back().push_back( sygus_vars
[i
] );
688 cnames
.push_back( ss
.str() );
689 cargs
.push_back( std::vector
< CVC4::Type
>() );
692 //add constants if no variables and no connected types
693 if( ops
.back().empty() && types
.empty() ){
694 std::vector
< Expr
> consts
;
695 mkSygusConstantsForType( btype
, consts
);
696 for( unsigned j
=0; j
<consts
.size(); j
++ ){
697 std::stringstream ss
;
699 Debug("parser-sygus") << "...add for constant " << ss
.str() << std::endl
;
700 ops
.back().push_back( consts
[j
] );
701 cnames
.push_back( ss
.str() );
702 cargs
.push_back( std::vector
< CVC4::Type
>() );
706 for( unsigned i
=0; i
<3; i
++ ){
707 CVC4::Kind k
= i
==0 ? kind::NOT
: ( i
==1 ? kind::AND
: kind::OR
);
708 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
709 ops
.back().push_back(getExprManager()->operatorOf(k
));
710 cnames
.push_back(kind::kindToString(k
));
711 cargs
.push_back( std::vector
< CVC4::Type
>() );
713 cargs
.back().push_back(unres_bt
);
714 }else if( k
==kind::AND
|| k
==kind::OR
){
715 cargs
.back().push_back(unres_bt
);
716 cargs
.back().push_back(unres_bt
);
719 //add predicates for types
720 for( unsigned i
=0; i
<types
.size(); i
++ ){
721 Debug("parser-sygus") << "...add predicates for " << types
[i
] << std::endl
;
722 //add equality per type
723 CVC4::Kind k
= kind::EQUAL
;
724 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
725 ops
.back().push_back(getExprManager()->operatorOf(k
));
726 std::stringstream ss
;
727 ss
<< kind::kindToString(k
) << "_" << types
[i
];
728 cnames
.push_back(ss
.str());
729 cargs
.push_back( std::vector
< CVC4::Type
>() );
730 cargs
.back().push_back(unres_types
[i
]);
731 cargs
.back().push_back(unres_types
[i
]);
732 //type specific predicates
733 if( types
[i
].isInteger() ){
734 CVC4::Kind k
= kind::LEQ
;
735 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
736 ops
.back().push_back(getExprManager()->operatorOf(k
));
737 cnames
.push_back(kind::kindToString(k
));
738 cargs
.push_back( std::vector
< CVC4::Type
>() );
739 cargs
.back().push_back(unres_types
[i
]);
740 cargs
.back().push_back(unres_types
[i
]);
741 }else if( types
[i
].isDatatype() ){
743 Debug("parser-sygus") << "...add for testers" << std::endl
;
744 const Datatype
& dt
= ((DatatypeType
)types
[i
]).getDatatype();
745 for( unsigned k
=0; k
<dt
.getNumConstructors(); k
++ ){
746 Debug("parser-sygus") << "...for " << dt
[k
].getTesterName() << std::endl
;
747 ops
.back().push_back(dt
[k
].getTester());
748 cnames
.push_back(dt
[k
].getTesterName());
749 cargs
.push_back( std::vector
< CVC4::Type
>() );
750 cargs
.back().push_back(unres_types
[i
]);
755 startIndex
= sorts
.size();
757 Debug("parser-sygus") << "...make datatype " << datatypes
.back() << std::endl
;
758 datatypes
.back().setSygus( btype
, bvl
, true, true );
759 mkSygusDatatype( datatypes
.back(), ops
.back(), cnames
, cargs
, unresolved_gterm_sym
, sygus_to_builtin
);
760 sorts
.push_back( btype
);
762 Debug("parser-sygus") << "...finished make default grammar for " << fun
<< " " << range
<< std::endl
;
765 void Smt2::mkSygusConstantsForType( const Type
& type
, std::vector
<CVC4::Expr
>& ops
) {
766 if( type
.isInteger() ){
767 ops
.push_back(getExprManager()->mkConst(Rational(0)));
768 ops
.push_back(getExprManager()->mkConst(Rational(1)));
769 }else if( type
.isBitVector() ){
770 unsigned sz
= ((BitVectorType
)type
).getSize();
771 BitVector
bval0(sz
, (unsigned int)0);
772 ops
.push_back( getExprManager()->mkConst(bval0
) );
773 BitVector
bval1(sz
, (unsigned int)1);
774 ops
.push_back( getExprManager()->mkConst(bval1
) );
775 }else if( type
.isBoolean() ){
776 ops
.push_back(getExprManager()->mkConst(true));
777 ops
.push_back(getExprManager()->mkConst(false));
782 // 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)
783 // This method may also add new elements pairwise into datatypes/sorts/ops/cnames/cargs in the case of non-flat gterms.
784 void Smt2::processSygusGTerm( CVC4::SygusGTerm
& sgt
, int index
,
785 std::vector
< CVC4::Datatype
>& datatypes
,
786 std::vector
< CVC4::Type
>& sorts
,
787 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
788 std::vector
< std::vector
<std::string
> >& cnames
,
789 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
790 std::vector
< bool >& allow_const
,
791 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
,
792 std::vector
<CVC4::Expr
>& sygus_vars
,
793 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
, std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
,
794 CVC4::Type
& ret
, bool isNested
){
795 if( sgt
.d_gterm_type
==SygusGTerm::gterm_op
|| sgt
.d_gterm_type
==SygusGTerm::gterm_let
){
796 Debug("parser-sygus") << "Add " << sgt
.d_expr
<< " to datatype " << index
<< std::endl
;
798 Kind newKind
= kind::UNDEFINED_KIND
;
799 //convert to UMINUS if one child of MINUS
800 if( sgt
.d_children
.size()==1 && sgt
.d_expr
==getExprManager()->operatorOf(kind::MINUS
) ){
801 oldKind
= kind::MINUS
;
802 newKind
= kind::UMINUS
;
804 //convert to IFF if boolean EQUAL
805 if( sgt
.d_expr
==getExprManager()->operatorOf(kind::EQUAL
) ){
806 Type ctn
= sgt
.d_children
[0].d_type
;
807 std::map
< CVC4::Type
, CVC4::Type
>::iterator it
= sygus_to_builtin
.find( ctn
);
808 if( it
!= sygus_to_builtin
.end() && it
->second
.isBoolean() ){
809 oldKind
= kind::EQUAL
;
813 if( newKind
!=kind::UNDEFINED_KIND
){
814 Expr newExpr
= getExprManager()->operatorOf(newKind
);
815 Debug("parser-sygus") << "Replace " << sgt
.d_expr
<< " with " << newExpr
<< std::endl
;
816 sgt
.d_expr
= newExpr
;
817 std::string oldName
= kind::kindToString(oldKind
);
818 std::string newName
= kind::kindToString(newKind
);
820 if((pos
= sgt
.d_name
.find(oldName
, pos
)) != std::string::npos
){
821 sgt
.d_name
.replace(pos
, oldName
.length(), newName
);
824 ops
[index
].push_back( sgt
.d_expr
);
825 cnames
[index
].push_back( sgt
.d_name
);
826 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
827 for( unsigned i
=0; i
<sgt
.d_children
.size(); i
++ ){
828 std::stringstream ss
;
829 ss
<< datatypes
[index
].getName() << "_" << ops
[index
].size() << "_arg_" << i
;
830 std::string sub_dname
= ss
.str();
831 //add datatype for child
833 pushSygusDatatypeDef( null_type
, sub_dname
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
);
834 int sub_dt_index
= datatypes
.size()-1;
837 processSygusGTerm( sgt
.d_children
[i
], sub_dt_index
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
,
838 sygus_vars
, sygus_to_builtin
, sygus_to_builtin_expr
, sub_ret
, true );
839 //process the nested gterm (either pop the last datatype, or flatten the argument)
840 Type tt
= processSygusNestedGTerm( sub_dt_index
, sub_dname
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
,
841 sygus_to_builtin
, sygus_to_builtin_expr
, sub_ret
);
842 cargs
[index
].back().push_back(tt
);
844 //if let, must create operator
845 if( sgt
.d_gterm_type
==SygusGTerm::gterm_let
){
846 processSygusLetConstructor( sgt
.d_let_vars
, index
, datatypes
, sorts
, ops
, cnames
, cargs
,
847 sygus_vars
, sygus_to_builtin
, sygus_to_builtin_expr
);
849 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_constant
){
850 if( sgt
.getNumChildren()!=0 ){
851 parseError("Bad syntax for Sygus Constant.");
853 std::vector
< Expr
> consts
;
854 mkSygusConstantsForType( sgt
.d_type
, consts
);
855 Debug("parser-sygus") << "...made " << consts
.size() << " constants." << std::endl
;
856 for( unsigned i
=0; i
<consts
.size(); i
++ ){
857 std::stringstream ss
;
859 Debug("parser-sygus") << "...add for constant " << ss
.str() << std::endl
;
860 ops
[index
].push_back( consts
[i
] );
861 cnames
[index
].push_back( ss
.str() );
862 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
864 allow_const
[index
] = true;
865 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_variable
|| sgt
.d_gterm_type
==SygusGTerm::gterm_input_variable
){
866 if( sgt
.getNumChildren()!=0 ){
867 parseError("Bad syntax for Sygus Variable.");
869 Debug("parser-sygus") << "...process " << sygus_vars
.size() << " variables." << std::endl
;
870 for( unsigned i
=0; i
<sygus_vars
.size(); i
++ ){
871 if( sygus_vars
[i
].getType()==sgt
.d_type
){
872 std::stringstream ss
;
874 Debug("parser-sygus") << "...add for variable " << ss
.str() << std::endl
;
875 ops
[index
].push_back( sygus_vars
[i
] );
876 cnames
[index
].push_back( ss
.str() );
877 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
880 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_nested_sort
){
882 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_unresolved
){
884 if( isUnresolvedType(sgt
.d_name
) ){
885 ret
= getSort(sgt
.d_name
);
887 //nested, unresolved symbol...fail
888 std::stringstream ss
;
889 ss
<< "Cannot handle nested unresolved symbol " << sgt
.d_name
<< std::endl
;
890 parseError(ss
.str());
893 //will resolve when adding constructors
894 unresolved_gterm_sym
[index
].push_back(sgt
.d_name
);
896 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_ignore
){
901 bool Smt2::pushSygusDatatypeDef( Type t
, std::string
& dname
,
902 std::vector
< CVC4::Datatype
>& datatypes
,
903 std::vector
< CVC4::Type
>& sorts
,
904 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
905 std::vector
< std::vector
<std::string
> >& cnames
,
906 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
907 std::vector
< bool >& allow_const
,
908 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
){
910 datatypes
.push_back(Datatype(dname
));
911 ops
.push_back(std::vector
<Expr
>());
912 cnames
.push_back(std::vector
<std::string
>());
913 cargs
.push_back(std::vector
<std::vector
<CVC4::Type
> >());
914 allow_const
.push_back(false);
915 unresolved_gterm_sym
.push_back(std::vector
< std::string
>());
919 bool Smt2::popSygusDatatypeDef( std::vector
< CVC4::Datatype
>& datatypes
,
920 std::vector
< CVC4::Type
>& sorts
,
921 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
922 std::vector
< std::vector
<std::string
> >& cnames
,
923 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
924 std::vector
< bool >& allow_const
,
925 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
){
927 datatypes
.pop_back();
931 allow_const
.pop_back();
932 unresolved_gterm_sym
.pop_back();
936 Type
Smt2::processSygusNestedGTerm( int sub_dt_index
, std::string
& sub_dname
, std::vector
< CVC4::Datatype
>& datatypes
,
937 std::vector
< CVC4::Type
>& sorts
,
938 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
939 std::vector
< std::vector
<std::string
> >& cnames
,
940 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
941 std::vector
< bool >& allow_const
,
942 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
,
943 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
,
944 std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
, Type sub_ret
) {
946 Debug("parser-sygus") << "Argument is ";
948 //then, it is the datatype we constructed, which should have a single constructor
949 t
= mkUnresolvedType(sub_dname
);
950 Debug("parser-sygus") << "inline flattening of (auxiliary, local) datatype " << t
<< std::endl
;
951 Debug("parser-sygus") << ": to compute type, construct ground term witnessing the grammar, #cons=" << cargs
[sub_dt_index
].size() << std::endl
;
952 if( cargs
[sub_dt_index
].empty() ){
953 parseError(std::string("Internal error : datatype for nested gterm does not have a constructor."));
955 Expr sop
= ops
[sub_dt_index
][0];
957 if( sop
.getKind() != kind::BUILTIN
&& ( sop
.isConst() || cargs
[sub_dt_index
][0].empty() ) ){
958 curr_t
= sop
.getType();
959 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
;
960 sygus_to_builtin_expr
[t
] = sop
;
961 //store that term sop has dedicated sygus type t
962 if( d_sygus_bound_var_type
.find( sop
)==d_sygus_bound_var_type
.end() ){
963 d_sygus_bound_var_type
[sop
] = t
;
966 std::vector
< Expr
> children
;
967 if( sop
.getKind() != kind::BUILTIN
){
968 children
.push_back( sop
);
970 for( unsigned i
=0; i
<cargs
[sub_dt_index
][0].size(); i
++ ){
971 std::map
< CVC4::Type
, CVC4::Expr
>::iterator it
= sygus_to_builtin_expr
.find( cargs
[sub_dt_index
][0][i
] );
972 if( it
==sygus_to_builtin_expr
.end() ){
973 if( sygus_to_builtin
.find( cargs
[sub_dt_index
][0][i
] )==sygus_to_builtin
.end() ){
974 std::stringstream ss
;
975 ss
<< "Missing builtin type for type " << cargs
[sub_dt_index
][0][i
] << "!" << std::endl
;
976 ss
<< "Builtin types are currently : " << std::endl
;
977 for( std::map
< CVC4::Type
, CVC4::Type
>::iterator itb
= sygus_to_builtin
.begin(); itb
!= sygus_to_builtin
.end(); ++itb
){
978 ss
<< " " << itb
->first
<< " -> " << itb
->second
<< std::endl
;
980 parseError(ss
.str());
982 Type bt
= sygus_to_builtin
[cargs
[sub_dt_index
][0][i
]];
983 Debug("parser-sygus") << ": child " << i
<< " introduce type elem for " << cargs
[sub_dt_index
][0][i
] << " " << bt
<< std::endl
;
984 std::stringstream ss
;
985 ss
<< t
<< "_x_" << i
;
986 Expr bv
= mkBoundVar(ss
.str(), bt
);
987 children
.push_back( bv
);
988 d_sygus_bound_var_type
[bv
] = cargs
[sub_dt_index
][0][i
];
990 Debug("parser-sygus") << ": child " << i
<< " existing sygus to builtin expr : " << it
->second
<< std::endl
;
991 children
.push_back( it
->second
);
994 Kind sk
= sop
.getKind() != kind::BUILTIN
? kind::APPLY
: getExprManager()->operatorToKind(sop
);
995 Debug("parser-sygus") << ": operator " << sop
<< " with " << sop
.getKind() << " " << sk
<< std::endl
;
996 Expr e
= getExprManager()->mkExpr( sk
, children
);
997 Debug("parser-sygus") << ": constructed " << e
<< ", which has type " << e
.getType() << std::endl
;
998 curr_t
= e
.getType();
999 sygus_to_builtin_expr
[t
] = e
;
1001 sorts
[sub_dt_index
] = curr_t
;
1002 sygus_to_builtin
[t
] = curr_t
;
1004 Debug("parser-sygus") << "simple argument " << t
<< std::endl
;
1005 Debug("parser-sygus") << "...removing " << datatypes
.back().getName() << std::endl
;
1006 //otherwise, datatype was unecessary
1007 //pop argument datatype definition
1008 popSygusDatatypeDef( datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
);
1013 void Smt2::processSygusLetConstructor( std::vector
< CVC4::Expr
>& let_vars
,
1015 std::vector
< CVC4::Datatype
>& datatypes
,
1016 std::vector
< CVC4::Type
>& sorts
,
1017 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
1018 std::vector
< std::vector
<std::string
> >& cnames
,
1019 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
1020 std::vector
<CVC4::Expr
>& sygus_vars
,
1021 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
,
1022 std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
) {
1023 std::vector
< CVC4::Expr
> let_define_args
;
1025 int dindex
= cargs
[index
].size()-1;
1026 Debug("parser-sygus") << "Process let constructor for datatype " << datatypes
[index
].getName() << ", #subtypes = " << cargs
[index
][dindex
].size() << std::endl
;
1027 for( unsigned i
=0; i
<cargs
[index
][dindex
].size(); i
++ ){
1028 Debug("parser-sygus") << " " << i
<< " : " << cargs
[index
][dindex
][i
] << std::endl
;
1029 if( i
+1==cargs
[index
][dindex
].size() ){
1030 std::map
< CVC4::Type
, CVC4::Expr
>::iterator it
= sygus_to_builtin_expr
.find( cargs
[index
][dindex
][i
] );
1031 if( it
!=sygus_to_builtin_expr
.end() ){
1032 let_body
= it
->second
;
1034 std::stringstream ss
;
1035 ss
<< datatypes
[index
].getName() << "_body";
1036 let_body
= mkBoundVar(ss
.str(), sygus_to_builtin
[cargs
[index
][dindex
][i
]]);
1037 d_sygus_bound_var_type
[let_body
] = cargs
[index
][dindex
][i
];
1041 Debug("parser-sygus") << std::endl
;
1042 Debug("parser-sygus") << "Body is " << let_body
<< std::endl
;
1043 Debug("parser-sygus") << "# let vars = " << let_vars
.size() << std::endl
;
1044 for( unsigned i
=0; i
<let_vars
.size(); i
++ ){
1045 Debug("parser-sygus") << " let var " << i
<< " : " << let_vars
[i
] << " " << let_vars
[i
].getType() << std::endl
;
1046 let_define_args
.push_back( let_vars
[i
] );
1049 Debug("parser-sygus") << "index = " << index << ", start index = " << start_index << ", #Current datatypes = " << datatypes.size() << std::endl;
1050 for( unsigned i=start_index; i<datatypes.size(); i++ ){
1051 Debug("parser-sygus") << " datatype " << i << " : " << datatypes[i].getName() << ", #cons = " << cargs[i].size() << std::endl;
1052 if( !cargs[i].empty() ){
1053 Debug("parser-sygus") << " operator 0 is " << ops[i][0] << std::endl;
1054 Debug("parser-sygus") << " cons 0 has " << cargs[i][0].size() << " sub fields." << std::endl;
1055 for( unsigned j=0; j<cargs[i][0].size(); j++ ){
1056 Type bt = sygus_to_builtin[cargs[i][0][j]];
1057 Debug("parser-sygus") << " cons 0, selector " << j << " : " << cargs[i][0][j] << " " << bt << std::endl;
1062 //last argument is the return, pop
1063 cargs
[index
][dindex
].pop_back();
1064 collectSygusLetArgs( let_body
, cargs
[index
][dindex
], let_define_args
);
1066 Debug("parser-sygus") << "Make define-fun with " << cargs
[index
][dindex
].size() << " arguments..." << std::endl
;
1067 std::vector
<CVC4::Type
> fsorts
;
1068 for( unsigned i
=0; i
<cargs
[index
][dindex
].size(); i
++ ){
1069 Debug("parser-sygus") << " " << i
<< " : " << let_define_args
[i
] << " " << let_define_args
[i
].getType() << " " << cargs
[index
][dindex
][i
] << std::endl
;
1070 fsorts
.push_back(let_define_args
[i
].getType());
1073 Type ft
= getExprManager()->mkFunctionType(fsorts
, let_body
.getType());
1074 std::stringstream ss
;
1075 ss
<< datatypes
[index
].getName() << "_let";
1076 Expr let_func
= mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
1077 d_sygus_defined_funs
.push_back( let_func
);
1078 preemptCommand( new DefineFunctionCommand(ss
.str(), let_func
, let_define_args
, let_body
) );
1080 ops
[index
].pop_back();
1081 ops
[index
].push_back( let_func
);
1082 cnames
[index
].pop_back();
1083 cnames
[index
].push_back(ss
.str());
1085 //mark function as let constructor
1086 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() );
1087 d_sygus_let_func_to_body
[let_func
] = let_body
;
1088 d_sygus_let_func_to_num_input_vars
[let_func
] = let_vars
.size();
1092 void Smt2::collectSygusLetArgs( CVC4::Expr e
, std::vector
< CVC4::Type
>& sygusArgs
, std::vector
< CVC4::Expr
>& builtinArgs
) {
1093 if( e
.getKind()==kind::BOUND_VARIABLE
){
1094 if( std::find( builtinArgs
.begin(), builtinArgs
.end(), e
)==builtinArgs
.end() ){
1095 builtinArgs
.push_back( e
);
1096 sygusArgs
.push_back( d_sygus_bound_var_type
[e
] );
1097 if( d_sygus_bound_var_type
[e
].isNull() ){
1098 std::stringstream ss
;
1099 ss
<< "While constructing body of let gterm, can't map " << e
<< " to sygus type." << std::endl
;
1100 parseError(ss
.str());
1104 for( unsigned i
=0; i
<e
.getNumChildren(); i
++ ){
1105 collectSygusLetArgs( e
[i
], sygusArgs
, builtinArgs
);
1110 void Smt2::setSygusStartIndex( std::string
& fun
, int startIndex
,
1111 std::vector
< CVC4::Datatype
>& datatypes
,
1112 std::vector
< CVC4::Type
>& sorts
,
1113 std::vector
< std::vector
<CVC4::Expr
> >& ops
) {
1115 CVC4::Datatype tmp_dt
= datatypes
[0];
1116 Type tmp_sort
= sorts
[0];
1117 std::vector
< Expr
> tmp_ops
;
1118 tmp_ops
.insert( tmp_ops
.end(), ops
[0].begin(), ops
[0].end() );
1119 datatypes
[0] = datatypes
[startIndex
];
1120 sorts
[0] = sorts
[startIndex
];
1122 ops
[0].insert( ops
[0].end(), ops
[startIndex
].begin(), ops
[startIndex
].end() );
1123 datatypes
[startIndex
] = tmp_dt
;
1124 sorts
[startIndex
] = tmp_sort
;
1125 ops
[startIndex
].clear();
1126 ops
[startIndex
].insert( ops
[startIndex
].begin(), tmp_ops
.begin(), tmp_ops
.end() );
1127 }else if( startIndex
<0 ){
1128 std::stringstream ss
;
1129 ss
<< "warning: no symbol named Start for synth-fun " << fun
<< std::endl
;
1134 void Smt2::defineSygusFuns() {
1135 // only define each one once
1136 while(d_nextSygusFun
< d_sygusFuns
.size()) {
1137 std::pair
<std::string
, Expr
> p
= d_sygusFuns
[d_nextSygusFun
];
1138 std::string fun
= p
.first
;
1139 Debug("parser-sygus") << "Sygus : define fun " << fun
<< std::endl
;
1140 Expr eval
= p
.second
;
1141 FunctionType evalType
= eval
.getType();
1142 std::vector
<Type
> argTypes
= evalType
.getArgTypes();
1143 Type rangeType
= evalType
.getRangeType();
1144 Debug("parser-sygus") << "...eval type : " << evalType
<< ", #args=" << argTypes
.size() << std::endl
;
1146 // first make the function type
1147 std::vector
<Expr
> sygusVars
;
1148 std::vector
<Type
> funType
;
1149 for(size_t j
= 1; j
< argTypes
.size(); ++j
) {
1150 funType
.push_back(argTypes
[j
]);
1151 std::stringstream ss
;
1152 ss
<< fun
<< "_v_" << j
;
1153 sygusVars
.push_back(getExprManager()->mkBoundVar(ss
.str(), argTypes
[j
]));
1156 if( !funType
.empty() ){
1157 funt
= getExprManager()->mkFunctionType(funType
, rangeType
);
1158 Debug("parser-sygus") << "...eval function type : " << funt
<< std::endl
;
1160 // copy the bound vars
1162 std::vector<Expr> sygusVars;
1163 //std::vector<Type> types;
1164 for(size_t i = 0; i < d_sygusVars.size(); ++i) {
1165 std::stringstream ss;
1166 ss << d_sygusVars[i];
1167 Type type = d_sygusVars[i].getType();
1168 sygusVars.push_back(getExprManager()->mkBoundVar(ss.str(), type));
1169 //types.push_back(type);
1171 Debug("parser-sygus") << "...made vars, #vars=" << sygusVars.size() << std::endl;
1174 //Type t = getExprManager()->mkFunctionType(types, rangeType);
1175 //Debug("parser-sygus") << "...function type : " << t << std::endl;
1179 Expr lambda
= mkFunction(fun
, funt
, ExprManager::VAR_FLAG_DEFINED
);
1180 Debug("parser-sygus") << "...made function : " << lambda
<< std::endl
;
1181 std::vector
<Expr
> applyv
;
1182 Expr funbv
= getExprManager()->mkBoundVar(std::string("f") + fun
, argTypes
[0]);
1183 d_sygusFunSymbols
.push_back(funbv
);
1184 applyv
.push_back(eval
);
1185 applyv
.push_back(funbv
);
1186 for(size_t i
= 0; i
< sygusVars
.size(); ++i
) {
1187 applyv
.push_back(sygusVars
[i
]);
1189 Expr apply
= getExprManager()->mkExpr(kind::APPLY_UF
, applyv
);
1190 Debug("parser-sygus") << "...made apply " << apply
<< std::endl
;
1191 Debug("parser-sygus") << "--> Define " << fun
<< " as " << lambda
<< " " << apply
<< std::endl
;
1192 Command
* cmd
= new DefineFunctionCommand(fun
, lambda
, sygusVars
, apply
);
1193 preemptCommand(cmd
);
1199 void Smt2::mkSygusDatatype( CVC4::Datatype
& dt
, std::vector
<CVC4::Expr
>& ops
,
1200 std::vector
<std::string
>& cnames
, std::vector
< std::vector
< CVC4::Type
> >& cargs
,
1201 std::vector
<std::string
>& unresolved_gterm_sym
,
1202 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
) {
1203 Debug("parser-sygus") << "Making sygus datatype " << dt
.getName() << std::endl
;
1204 Debug("parser-sygus") << " add constructors..." << std::endl
;
1205 for( int i
=0; i
<(int)cnames
.size(); i
++ ){
1206 bool is_dup
= false;
1207 bool is_dup_op
= false;
1209 std::vector
< Expr
> let_args
;
1210 unsigned let_num_input_args
= 0;
1211 for( int j
=0; j
<i
; j
++ ){
1212 if( ops
[i
]==ops
[j
] ){
1214 if( cargs
[i
].size()==cargs
[j
].size() ){
1216 for( unsigned k
=0; k
<cargs
[i
].size(); k
++ ){
1217 if( cargs
[i
][k
]!=cargs
[j
][k
] ){
1229 Debug("parser-sygus") << "--> Duplicate gterm : " << ops
[i
] << " at " << i
<< std::endl
;
1230 ops
.erase( ops
.begin() + i
, ops
.begin() + i
+ 1 );
1231 cnames
.erase( cnames
.begin() + i
, cnames
.begin() + i
+ 1 );
1232 cargs
.erase( cargs
.begin() + i
, cargs
.begin() + i
+ 1 );
1234 }else if( is_dup_op
){
1235 Debug("parser-sygus") << "--> Duplicate gterm operator : " << ops
[i
] << " at " << i
<< std::endl
;
1236 //make into define-fun
1237 std::vector
<CVC4::Type
> fsorts
;
1238 for( unsigned j
=0; j
<cargs
[i
].size(); j
++ ){
1239 Type bt
= sygus_to_builtin
[cargs
[i
][j
]];
1240 std::stringstream ss
;
1241 ss
<< dt
.getName() << "_x_" << i
<< "_" << j
;
1242 Expr v
= mkBoundVar(ss
.str(), bt
);
1243 let_args
.push_back( v
);
1244 fsorts
.push_back( bt
);
1245 Debug("parser-sygus") << ": var " << i
<< " " << v
<< " with type " << bt
<< " from " << cargs
[i
][j
] << std::endl
;
1248 std::vector
< Expr
> children
;
1249 if( ops
[i
].getKind() != kind::BUILTIN
){
1250 children
.push_back( ops
[i
] );
1252 children
.insert( children
.end(), let_args
.begin(), let_args
.end() );
1253 Kind sk
= ops
[i
].getKind() != kind::BUILTIN
? kind::APPLY
: getExprManager()->operatorToKind(ops
[i
]);
1254 Debug("parser-sygus") << ": replace " << ops
[i
] << " " << ops
[i
].getKind() << " " << sk
<< std::endl
;
1255 let_body
= getExprManager()->mkExpr( sk
, children
);
1256 Debug("parser-sygus") << ": new body of function is " << let_body
<< std::endl
;
1258 Type ft
= getExprManager()->mkFunctionType(fsorts
, let_body
.getType());
1259 Debug("parser-sygus") << ": function type is " << ft
<< std::endl
;
1260 std::stringstream ss
;
1261 ss
<< dt
.getName() << "_df_" << i
;
1262 //replace operator and name
1263 ops
[i
] = mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
1264 cnames
[i
] = ss
.str();
1265 d_sygus_defined_funs
.push_back( ops
[i
] );
1266 preemptCommand( new DefineFunctionCommand(ss
.str(), ops
[i
], let_args
, let_body
) );
1267 addSygusDatatypeConstructor( dt
, ops
[i
], cnames
[i
], cargs
[i
], let_body
, let_args
, 0 );
1269 std::map
< CVC4::Expr
, CVC4::Expr
>::iterator it
= d_sygus_let_func_to_body
.find( ops
[i
] );
1270 if( it
!=d_sygus_let_func_to_body
.end() ){
1271 let_body
= it
->second
;
1272 let_args
.insert( let_args
.end(), d_sygus_let_func_to_vars
[ops
[i
]].begin(), d_sygus_let_func_to_vars
[ops
[i
]].end() );
1273 let_num_input_args
= d_sygus_let_func_to_num_input_vars
[ops
[i
]];
1275 addSygusDatatypeConstructor( dt
, ops
[i
], cnames
[i
], cargs
[i
], let_body
, let_args
, let_num_input_args
);
1278 Debug("parser-sygus") << " add constructors for unresolved symbols..." << std::endl
;
1279 if( !unresolved_gterm_sym
.empty() ){
1280 std::vector
< Type
> types
;
1281 Debug("parser-sygus") << "...resolve " << unresolved_gterm_sym
.size() << " symbols..." << std::endl
;
1282 for( unsigned i
=0; i
<unresolved_gterm_sym
.size(); i
++ ){
1283 Debug("parser-sygus") << " resolve : " << unresolved_gterm_sym
[i
] << std::endl
;
1284 if( isUnresolvedType(unresolved_gterm_sym
[i
]) ){
1285 Debug("parser-sygus") << " it is an unresolved type." << std::endl
;
1286 Type t
= getSort(unresolved_gterm_sym
[i
]);
1287 if( std::find( types
.begin(), types
.end(), t
)==types
.end() ){
1288 types
.push_back( t
);
1290 Type bt
= dt
.getSygusType();
1291 Debug("parser-sygus") << ": make identity function for " << bt
<< ", argument type " << t
<< std::endl
;
1292 std::stringstream ss
;
1294 Expr let_body
= mkBoundVar(ss
.str(), bt
);
1295 std::vector
< Expr
> let_args
;
1296 let_args
.push_back( let_body
);
1297 //make the identity function
1298 Type ft
= getExprManager()->mkFunctionType(bt
, bt
);
1299 std::stringstream ssid
;
1300 ssid
<< unresolved_gterm_sym
[i
] << "_id";
1301 Expr id_op
= mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
1302 d_sygus_defined_funs
.push_back( id_op
);
1303 preemptCommand( new DefineFunctionCommand(ssid
.str(), id_op
, let_args
, let_body
) );
1304 //make the sygus argument list
1305 std::vector
< Type
> id_carg
;
1306 id_carg
.push_back( t
);
1307 addSygusDatatypeConstructor( dt
, id_op
, unresolved_gterm_sym
[i
], id_carg
, let_body
, let_args
, 0 );
1309 ops
.push_back( id_op
);
1312 Debug("parser-sygus") << " ignore. (likely a free let variable)" << std::endl
;
1319 void Smt2::addSygusDatatypeConstructor( CVC4::Datatype
& dt
, CVC4::Expr op
, std::string
& cname
, std::vector
< CVC4::Type
>& cargs
,
1320 CVC4::Expr
& let_body
, std::vector
< CVC4::Expr
>& let_args
, unsigned let_num_input_args
) {
1321 Debug("parser-sygus") << "--> Add constructor " << cname
<< " to " << dt
.getName() << std::endl
;
1322 if( !let_body
.isNull() ){
1323 Debug("parser-sygus") << " let body = " << let_body
<< ", args = " << let_args
.size() << "," << let_num_input_args
<< std::endl
;
1324 //TODO : remove arguments not occurring in body
1325 //if this is a self identity function, ignore
1326 if( let_args
.size()==0 && let_args
[0]==let_body
){
1327 Debug("parser-sygus") << " identity function " << cargs
[0] << " to " << dt
.getName() << std::endl
;
1331 std::string name
= dt
.getName() + "_" + cname
;
1332 std::string
testerId("is-");
1333 testerId
.append(name
);
1334 checkDeclaration(name
, CHECK_UNDECLARED
, SYM_VARIABLE
);
1335 checkDeclaration(testerId
, CHECK_UNDECLARED
, SYM_VARIABLE
);
1336 CVC4::DatatypeConstructor
c(name
, testerId
);
1337 c
.setSygus( op
, let_body
, let_args
, let_num_input_args
);
1338 for( unsigned j
=0; j
<cargs
.size(); j
++ ){
1339 Debug("parser-sygus-debug") << " arg " << j
<< " : " << cargs
[j
] << std::endl
;
1340 std::stringstream sname
;
1341 sname
<< name
<< "_" << j
;
1342 c
.addArg(sname
.str(), cargs
[j
]);
1344 dt
.addConstructor(c
);
1348 // i is index in datatypes/ops
1349 // j is index is datatype
1350 Expr
Smt2::getSygusAssertion( std::vector
<DatatypeType
>& datatypeTypes
, std::vector
< std::vector
<Expr
> >& ops
,
1351 std::map
<DatatypeType
, Expr
>& evals
, std::vector
<Expr
>& terms
,
1352 Expr eval
, const Datatype
& dt
, size_t i
, size_t j
) {
1353 const DatatypeConstructor
& ctor
= dt
[j
];
1354 Debug("parser-sygus") << "Sygus : process constructor " << j
<< " : " << dt
[j
] << std::endl
;
1355 std::vector
<Expr
> bvs
, extraArgs
;
1356 for(size_t k
= 0; k
< ctor
.getNumArgs(); ++k
) {
1357 std::string vname
= "v_" + ctor
[k
].getName();
1358 Expr bv
= getExprManager()->mkBoundVar(vname
, SelectorType(ctor
[k
].getType()).getRangeType());
1360 extraArgs
.push_back(bv
);
1362 if( !terms
[0].isNull() ){
1363 bvs
.insert(bvs
.end(), terms
[0].begin(), terms
[0].end());
1367 bvl
= getExprManager()->mkExpr(kind::BOUND_VAR_LIST
, bvs
);
1369 Debug("parser-sygus") << "...made bv list " << bvl
<< std::endl
;
1370 std::vector
<Expr
> patv
;
1371 patv
.push_back(eval
);
1372 std::vector
<Expr
> applyv
;
1373 applyv
.push_back(ctor
.getConstructor());
1374 applyv
.insert(applyv
.end(), extraArgs
.begin(), extraArgs
.end());
1375 for(size_t k
= 0; k
< applyv
.size(); ++k
) {
1377 Expr cpatv
= getExprManager()->mkExpr(kind::APPLY_CONSTRUCTOR
, applyv
);
1378 Debug("parser-sygus") << "...made eval ctor apply " << cpatv
<< std::endl
;
1379 patv
.push_back(cpatv
);
1380 if( !terms
[0].isNull() ){
1381 patv
.insert(patv
.end(), terms
[0].begin(), terms
[0].end());
1383 Expr evalApply
= getExprManager()->mkExpr(kind::APPLY_UF
, patv
);
1384 Debug("parser-sygus") << "...made eval apply " << evalApply
<< std::endl
;
1385 std::vector
<Expr
> builtApply
;
1386 for(size_t k
= 0; k
< extraArgs
.size(); ++k
) {
1387 std::vector
<Expr
> patvb
;
1388 patvb
.push_back(evals
[DatatypeType(extraArgs
[k
].getType())]);
1389 patvb
.push_back(extraArgs
[k
]);
1390 if( !terms
[0].isNull() ){
1391 patvb
.insert(patvb
.end(), terms
[0].begin(), terms
[0].end());
1393 Debug("parser-sygus-debug") << "...add to built apply " << evals
[DatatypeType(extraArgs
[k
].getType())] << " " << extraArgs
[k
] << " " << extraArgs
[k
].getType() << std::endl
;
1394 builtApply
.push_back(getExprManager()->mkExpr(kind::APPLY_UF
, patvb
));
1395 Debug("parser-sygus-debug") << "...added " << builtApply
.back() << std::endl
;
1397 for(size_t k
= 0; k
< builtApply
.size(); ++k
) {
1400 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
;
1401 if( ops
[i
][j
].getKind() != kind::BUILTIN
){
1402 Kind ok
= kind::UNDEFINED_KIND
;
1403 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() ){
1406 Type t
= ops
[i
][j
].getType();
1407 if( t
.isConstructor() ){
1408 ok
= kind::APPLY_CONSTRUCTOR
;
1409 }else if( t
.isSelector() ){
1410 ok
= kind::APPLY_SELECTOR
;
1411 }else if( t
.isTester() ){
1412 ok
= kind::APPLY_TESTER
;
1414 ok
= getExprManager()->operatorToKind( ops
[i
][j
] );
1417 Debug("parser-sygus") << "...processed operator kind : " << ok
<< std::endl
;
1418 if( ok
!=kind::UNDEFINED_KIND
){
1419 builtTerm
= getExprManager()->mkExpr(ok
, ops
[i
][j
], builtApply
);
1421 builtTerm
= ops
[i
][j
];
1424 if( !builtApply
.empty() ){
1425 builtTerm
= getExprManager()->mkExpr(ops
[i
][j
], builtApply
);
1427 builtTerm
= ops
[i
][j
];
1430 Debug("parser-sygus") << "...made built term " << builtTerm
<< std::endl
;
1431 Expr assertion
= getExprManager()->mkExpr(evalApply
.getType().isBoolean() ? kind::IFF
: kind::EQUAL
, evalApply
, builtTerm
);
1432 if( !bvl
.isNull() ){
1433 Expr pattern
= getExprManager()->mkExpr(kind::INST_PATTERN
, evalApply
);
1434 pattern
= getExprManager()->mkExpr(kind::INST_PATTERN_LIST
, pattern
);
1435 assertion
= getExprManager()->mkExpr(kind::FORALL
, bvl
, assertion
, pattern
);
1437 Debug("parser-sygus") << "...made assertion " << assertion
<< std::endl
;
1439 //linearize multiplication if possible
1440 if( builtTerm
.getKind()==kind::MULT
){
1441 for(size_t k
= 0; k
< ctor
.getNumArgs(); ++k
) {
1442 Type at
= SelectorType(ctor
[k
].getType()).getRangeType();
1443 if( at
.isDatatype() ){
1444 DatatypeType atd
= (DatatypeType
)SelectorType(ctor
[k
].getType()).getRangeType();
1445 Debug("parser-sygus") << "Argument " << k
<< " " << atd
<< std::endl
;
1446 std::vector
<DatatypeType
>::iterator itd
= std::find( datatypeTypes
.begin(), datatypeTypes
.end(), atd
);
1447 if( itd
!=datatypeTypes
.end() ){
1448 Debug("parser-sygus2") << "Exists in datatypeTypes." << std::endl
;
1449 unsigned index
= itd
-datatypeTypes
.begin();
1450 Debug("parser-sygus2") << "index = " << index
<< std::endl
;
1451 bool isConst
= true;
1452 for( unsigned cc
= 0; cc
< ops
[index
].size(); cc
++ ){
1453 Debug("parser-sygus2") << "ops[" << cc
<< "]=" << ops
[index
][cc
] << std::endl
;
1454 if( ops
[index
][cc
].getKind() != kind::CONST_RATIONAL
){
1460 Debug("parser-sygus") << "Linearize multiplication " << ctor
<< " based on argument " << k
<< std::endl
;
1461 const Datatype
& atdd
= atd
.getDatatype();
1462 std::vector
<Expr
> assertions
;
1463 std::vector
<Expr
> nbvs
;
1464 for( unsigned a
=0; a
<bvl
.getNumChildren(); a
++ ){
1466 nbvs
.push_back( bvl
[a
] );
1469 Expr nbvl
= getExprManager()->mkExpr( kind::BOUND_VAR_LIST
, nbvs
);
1470 for( unsigned cc
= 0; cc
< ops
[index
].size(); cc
++ ){
1471 //Make new assertion based on partially instantiating existing
1472 applyv
[k
+1] = getExprManager()->mkExpr(kind::APPLY_CONSTRUCTOR
, atdd
[cc
].getConstructor());
1473 Debug("parser-sygus") << "applyv " << applyv
[k
+1] << std::endl
;
1474 cpatv
= getExprManager()->mkExpr(kind::APPLY_CONSTRUCTOR
, applyv
);
1475 Debug("parser-sygus") << "cpatv " << cpatv
<< std::endl
;
1477 evalApply
= getExprManager()->mkExpr(kind::APPLY_UF
, patv
);
1478 Debug("parser-sygus") << "evalApply " << evalApply
<< std::endl
;
1479 builtApply
[k
] = ops
[index
][cc
];
1480 Debug("parser-sygus") << "builtApply " << builtApply
[k
] << std::endl
;
1481 builtTerm
= getExprManager()->mkExpr(ops
[i
][j
], builtApply
);
1482 Debug("parser-sygus") << "builtTerm " << builtTerm
<< std::endl
;
1483 Expr eassertion
= getExprManager()->mkExpr(evalApply
.getType().isBoolean() ? kind::IFF
: kind::EQUAL
, evalApply
, builtTerm
);
1484 Expr epattern
= getExprManager()->mkExpr(kind::INST_PATTERN
, evalApply
);
1485 epattern
= getExprManager()->mkExpr(kind::INST_PATTERN_LIST
, epattern
);
1486 eassertion
= getExprManager()->mkExpr(kind::FORALL
, nbvl
, eassertion
, epattern
);
1487 assertions
.push_back( eassertion
);
1489 assertion
= assertions
.size()==1 ? assertions
[0] : getExprManager()->mkExpr( kind::AND
, assertions
);
1490 Debug("parser-sygus") << "...(linearized) assertion is: " << assertion
<< std::endl
;
1499 const void Smt2::getSygusPrimedVars( std::vector
<Expr
>& vars
, bool isPrimed
) {
1500 for( unsigned i
=0; i
<d_sygusVars
.size(); i
++ ){
1501 Expr v
= d_sygusVars
[i
];
1502 std::map
< Expr
, bool >::iterator it
= d_sygusVarPrimed
.find( v
);
1503 if( it
!=d_sygusVarPrimed
.end() ){
1504 if( it
->second
==isPrimed
){
1505 vars
.push_back( v
);
1508 //should never happen
1513 }/* CVC4::parser namespace */
1514 }/* CVC4 namespace */