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
== "ALL_SUPPORTED") {
356 std::stringstream ss
;
357 ss
<< "Unknown SyGuS background logic `" << name
<< "'";
358 parseError(ss
.str());
363 if(logicIsForced()) {
364 d_logic
= getForcedLogic();
369 // Core theory belongs to every logic
370 addTheory(THEORY_CORE
);
372 if(d_logic
.isTheoryEnabled(theory::THEORY_UF
)) {
373 addTheory(THEORY_UF
);
376 if(d_logic
.isTheoryEnabled(theory::THEORY_ARITH
)) {
377 if(d_logic
.areIntegersUsed()) {
378 if(d_logic
.areRealsUsed()) {
379 addTheory(THEORY_REALS_INTS
);
381 addTheory(THEORY_INTS
);
383 } else if(d_logic
.areRealsUsed()) {
384 addTheory(THEORY_REALS
);
388 if(d_logic
.isTheoryEnabled(theory::THEORY_ARRAY
)) {
389 addTheory(THEORY_ARRAYS
);
392 if(d_logic
.isTheoryEnabled(theory::THEORY_BV
)) {
393 addTheory(THEORY_BITVECTORS
);
396 if(d_logic
.isTheoryEnabled(theory::THEORY_DATATYPES
)) {
397 addTheory(THEORY_DATATYPES
);
400 if(d_logic
.isTheoryEnabled(theory::THEORY_SETS
)) {
401 addTheory(THEORY_SETS
);
404 if(d_logic
.isTheoryEnabled(theory::THEORY_STRINGS
)) {
405 addTheory(THEORY_STRINGS
);
408 if(d_logic
.isQuantified()) {
409 addTheory(THEORY_QUANTIFIERS
);
412 if (d_logic
.isTheoryEnabled(theory::THEORY_FP
)) {
413 addTheory(THEORY_FP
);
416 }/* Smt2::setLogic() */
418 void Smt2::setInfo(const std::string
& flag
, const SExpr
& sexpr
) {
422 void Smt2::setOption(const std::string
& flag
, const SExpr
& sexpr
) {
426 void Smt2::checkThatLogicIsSet() {
427 if( ! logicIsSet() ) {
428 if(strictModeEnabled()) {
429 parseError("set-logic must appear before this point.");
434 warning("No set-logic command was given before this point.");
435 warning("CVC4 will assume the non-standard ALL_SUPPORTED logic.");
436 warning("Consider setting a stricter logic for (likely) better performance.");
437 warning("To suppress this warning in the future use (set-logic ALL_SUPPORTED).");
439 setLogic("ALL_SUPPORTED");
442 Command
* c
= new SetBenchmarkLogicCommand("ALL_SUPPORTED");
449 /* The include are managed in the lexer but called in the parser */
450 // Inspired by http://www.antlr3.org/api/C/interop.html
452 static bool newInputStream(const std::string
& filename
, pANTLR3_LEXER lexer
) {
453 Debug("parser") << "Including " << filename
<< std::endl
;
454 // Create a new input stream and take advantage of built in stream stacking
455 // in C target runtime.
457 pANTLR3_INPUT_STREAM in
;
458 #ifdef CVC4_ANTLR3_OLD_INPUT_STREAM
459 in
= antlr3AsciiFileStreamNew((pANTLR3_UINT8
) filename
.c_str());
460 #else /* CVC4_ANTLR3_OLD_INPUT_STREAM */
461 in
= antlr3FileStreamNew((pANTLR3_UINT8
) filename
.c_str(), ANTLR3_ENC_8BIT
);
462 #endif /* CVC4_ANTLR3_OLD_INPUT_STREAM */
464 Debug("parser") << "Can't open " << filename
<< std::endl
;
467 // Same thing as the predefined PUSHSTREAM(in);
468 lexer
->pushCharStream(lexer
, in
);
470 //lexer->rec->state->tokenStartCharIndex = -10;
471 //lexer->emit(lexer);
473 // Note that the input stream is not closed when it EOFs, I don't bother
474 // to do it here, but it is up to you to track streams created like this
475 // and destroy them when the whole parse session is complete. Remember that you
476 // don't want to do this until all tokens have been manipulated all the way through
477 // your tree parsers etc as the token does not store the text it just refers
478 // back to the input stream and trying to get the text for it will abort if you
479 // close the input stream too early.
481 //TODO what said before
485 void Smt2::includeFile(const std::string
& filename
) {
486 // security for online version
487 if(!canIncludeFile()) {
488 parseError("include-file feature was disabled for this run.");
492 AntlrInput
* ai
= static_cast<AntlrInput
*>(getInput());
493 pANTLR3_LEXER lexer
= ai
->getAntlr3Lexer();
494 // get the name of the current stream "Does it work inside an include?"
495 const std::string inputName
= ai
->getInputStreamName();
497 // Find the directory of the current input file
499 size_t pos
= inputName
.rfind('/');
500 if(pos
!= std::string::npos
) {
501 path
= std::string(inputName
, 0, pos
+ 1);
503 path
.append(filename
);
504 if(!newInputStream(path
, lexer
)) {
505 parseError("Couldn't open include file `" + path
+ "'");
509 Expr
Smt2::mkSygusVar(const std::string
& name
, const Type
& type
, bool isPrimed
) {
510 Expr e
= mkBoundVar(name
, type
);
511 d_sygusVars
.push_back(e
);
512 d_sygusVarPrimed
[e
] = false;
514 std::stringstream ss
;
516 Expr ep
= mkBoundVar(ss
.str(), type
);
517 d_sygusVars
.push_back(ep
);
518 d_sygusVarPrimed
[ep
] = true;
523 void collectSygusGrammarTypesFor( Type range
, std::vector
< Type
>& types
, std::map
< Type
, std::vector
< DatatypeConstructorArg
> >& sels
){
524 if( !range
.isBoolean() ){
525 if( std::find( types
.begin(), types
.end(), range
)==types
.end() ){
526 Debug("parser-sygus") << "...will make grammar for " << range
<< std::endl
;
527 types
.push_back( range
);
528 if( range
.isDatatype() ){
529 const Datatype
& dt
= ((DatatypeType
)range
).getDatatype();
530 for( unsigned i
=0; i
<dt
.getNumConstructors(); i
++ ){
531 for( unsigned j
=0; j
<dt
[i
].getNumArgs(); j
++ ){
532 Type crange
= ((SelectorType
)dt
[i
][j
].getType()).getRangeType();
533 sels
[crange
].push_back( dt
[i
][j
] );
534 collectSygusGrammarTypesFor( crange
, types
, sels
);
542 void Smt2::mkSygusDefaultGrammar( const Type
& range
, Expr
& bvl
, const std::string
& fun
, std::vector
<CVC4::Datatype
>& datatypes
,
543 std::vector
<Type
>& sorts
, std::vector
< std::vector
<Expr
> >& ops
, std::vector
<Expr
> sygus_vars
, int& startIndex
) {
545 //if( !range.isBoolean() && !range.isInteger() && !range.isBitVector() && !range.isDatatype() ){
546 // parseError("No default grammar for type.");
549 Debug("parser-sygus") << "Construct default grammar for " << fun
<< " " << range
<< std::endl
;
550 std::map
< CVC4::Type
, CVC4::Type
> sygus_to_builtin
;
552 std::vector
< Type
> types
;
553 std::map
< Type
, std::vector
< DatatypeConstructorArg
> > sels
;
554 //types for each of the variables
555 for( unsigned i
=0; i
<sygus_vars
.size(); i
++ ){
556 collectSygusGrammarTypesFor( sygus_vars
[i
].getType(), types
, sels
);
558 //types connected to range
559 collectSygusGrammarTypesFor( range
, types
, sels
);
561 //name of boolean sort
562 std::stringstream ssb
;
563 ssb
<< fun
<< "_Bool";
564 std::string dbname
= ssb
.str();
565 Type unres_bt
= mkUnresolvedType(ssb
.str());
567 std::vector
< Type
> unres_types
;
568 std::map
< Type
, Type
> type_to_unres
;
569 for( unsigned i
=0; i
<types
.size(); i
++ ){
570 std::stringstream ss
;
571 ss
<< fun
<< "_" << types
[i
];
572 std::string dname
= ss
.str();
573 datatypes
.push_back(Datatype(dname
));
574 ops
.push_back(std::vector
<Expr
>());
575 //make unresolved type
576 Type unres_t
= mkUnresolvedType(dname
);
577 unres_types
.push_back(unres_t
);
578 type_to_unres
[types
[i
]] = unres_t
;
579 sygus_to_builtin
[unres_t
] = types
[i
];
581 for( unsigned i
=0; i
<types
.size(); i
++ ){
582 Debug("parser-sygus") << "Make grammar for " << types
[i
] << " " << unres_types
[i
] << std::endl
;
583 std::vector
<std::string
> cnames
;
584 std::vector
<std::vector
<CVC4::Type
> > cargs
;
585 std::vector
<std::string
> unresolved_gterm_sym
;
586 Type unres_t
= unres_types
[i
];
588 for( unsigned j
=0; j
<sygus_vars
.size(); j
++ ){
589 if( sygus_vars
[j
].getType()==types
[i
] ){
590 std::stringstream ss
;
592 Debug("parser-sygus") << "...add for variable " << ss
.str() << std::endl
;
593 ops
[i
].push_back( sygus_vars
[j
] );
594 cnames
.push_back( ss
.str() );
595 cargs
.push_back( std::vector
< CVC4::Type
>() );
599 std::vector
< Expr
> consts
;
600 mkSygusConstantsForType( types
[i
], consts
);
601 for( unsigned j
=0; j
<consts
.size(); j
++ ){
602 std::stringstream ss
;
604 Debug("parser-sygus") << "...add for constant " << ss
.str() << std::endl
;
605 ops
[i
].push_back( consts
[j
] );
606 cnames
.push_back( ss
.str() );
607 cargs
.push_back( std::vector
< CVC4::Type
>() );
610 CVC4::Kind k
= kind::ITE
;
611 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
612 ops
[i
].push_back(getExprManager()->operatorOf(k
));
613 cnames
.push_back( kind::kindToString(k
) );
614 cargs
.push_back( std::vector
< CVC4::Type
>() );
615 cargs
.back().push_back(unres_bt
);
616 cargs
.back().push_back(unres_t
);
617 cargs
.back().push_back(unres_t
);
619 if( types
[i
].isInteger() ){
620 for( unsigned j
=0; j
<2; j
++ ){
621 CVC4::Kind k
= j
==0 ? kind::PLUS
: kind::MINUS
;
622 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
623 ops
[i
].push_back(getExprManager()->operatorOf(k
));
624 cnames
.push_back(kind::kindToString(k
));
625 cargs
.push_back( std::vector
< CVC4::Type
>() );
626 cargs
.back().push_back(unres_t
);
627 cargs
.back().push_back(unres_t
);
629 }else if( types
[i
].isDatatype() ){
630 Debug("parser-sygus") << "...add for constructors" << std::endl
;
631 const Datatype
& dt
= ((DatatypeType
)types
[i
]).getDatatype();
632 for( unsigned k
=0; k
<dt
.getNumConstructors(); k
++ ){
633 Debug("parser-sygus") << "...for " << dt
[k
].getName() << std::endl
;
634 ops
[i
].push_back( dt
[k
].getConstructor() );
635 cnames
.push_back( dt
[k
].getName() );
636 cargs
.push_back( std::vector
< CVC4::Type
>() );
637 for( unsigned j
=0; j
<dt
[k
].getNumArgs(); j
++ ){
638 Type crange
= ((SelectorType
)dt
[k
][j
].getType()).getRangeType();
639 //Assert( type_to_unres.find(crange)!=type_to_unres.end() );
640 cargs
.back().push_back( type_to_unres
[crange
] );
644 std::stringstream sserr
;
645 sserr
<< "No implementation for default Sygus grammar of type " << types
[i
] << std::endl
;
646 warning(sserr
.str());
648 //add for all selectors to this type
649 if( !sels
[types
[i
]].empty() ){
650 Debug("parser-sygus") << "...add for selectors" << std::endl
;
651 for( unsigned j
=0; j
<sels
[types
[i
]].size(); j
++ ){
652 Debug("parser-sygus") << "...for " << sels
[types
[i
]][j
].getName() << std::endl
;
653 Type arg_type
= ((SelectorType
)sels
[types
[i
]][j
].getType()).getDomain();
654 ops
[i
].push_back( sels
[types
[i
]][j
].getSelector() );
655 cnames
.push_back( sels
[types
[i
]][j
].getName() );
656 cargs
.push_back( std::vector
< CVC4::Type
>() );
657 //Assert( type_to_unres.find(arg_type)!=type_to_unres.end() );
658 cargs
.back().push_back( type_to_unres
[arg_type
] );
661 Debug("parser-sygus") << "...make datatype " << datatypes
.back() << std::endl
;
662 datatypes
[i
].setSygus( types
[i
], bvl
, true, true );
663 mkSygusDatatype( datatypes
[i
], ops
[i
], cnames
, cargs
, unresolved_gterm_sym
, sygus_to_builtin
);
664 sorts
.push_back( types
[i
] );
665 //set start index if applicable
666 if( types
[i
]==range
){
672 Type btype
= getExprManager()->booleanType();
673 datatypes
.push_back(Datatype(dbname
));
674 ops
.push_back(std::vector
<Expr
>());
675 std::vector
<std::string
> cnames
;
676 std::vector
<std::vector
<CVC4::Type
> > cargs
;
677 std::vector
<std::string
> unresolved_gterm_sym
;
678 Debug("parser-sygus") << "Make grammar for " << btype
<< " " << datatypes
.back() << std::endl
;
680 for( unsigned i
=0; i
<sygus_vars
.size(); i
++ ){
681 if( sygus_vars
[i
].getType().isBoolean() ){
682 std::stringstream ss
;
684 Debug("parser-sygus") << "...add for variable " << ss
.str() << std::endl
;
685 ops
.back().push_back( sygus_vars
[i
] );
686 cnames
.push_back( ss
.str() );
687 cargs
.push_back( std::vector
< CVC4::Type
>() );
690 //add constants if no variables and no connected types
691 if( ops
.back().empty() && types
.empty() ){
692 std::vector
< Expr
> consts
;
693 mkSygusConstantsForType( btype
, consts
);
694 for( unsigned j
=0; j
<consts
.size(); j
++ ){
695 std::stringstream ss
;
697 Debug("parser-sygus") << "...add for constant " << ss
.str() << std::endl
;
698 ops
.back().push_back( consts
[j
] );
699 cnames
.push_back( ss
.str() );
700 cargs
.push_back( std::vector
< CVC4::Type
>() );
704 for( unsigned i
=0; i
<3; i
++ ){
705 CVC4::Kind k
= i
==0 ? kind::NOT
: ( i
==1 ? kind::AND
: kind::OR
);
706 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
707 ops
.back().push_back(getExprManager()->operatorOf(k
));
708 cnames
.push_back(kind::kindToString(k
));
709 cargs
.push_back( std::vector
< CVC4::Type
>() );
711 cargs
.back().push_back(unres_bt
);
712 }else if( k
==kind::AND
|| k
==kind::OR
){
713 cargs
.back().push_back(unres_bt
);
714 cargs
.back().push_back(unres_bt
);
717 //add predicates for types
718 for( unsigned i
=0; i
<types
.size(); i
++ ){
719 Debug("parser-sygus") << "...add predicates for " << types
[i
] << std::endl
;
720 //add equality per type
721 CVC4::Kind k
= kind::EQUAL
;
722 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
723 ops
.back().push_back(getExprManager()->operatorOf(k
));
724 std::stringstream ss
;
725 ss
<< kind::kindToString(k
) << "_" << types
[i
];
726 cnames
.push_back(ss
.str());
727 cargs
.push_back( std::vector
< CVC4::Type
>() );
728 cargs
.back().push_back(unres_types
[i
]);
729 cargs
.back().push_back(unres_types
[i
]);
730 //type specific predicates
731 if( types
[i
].isInteger() ){
732 CVC4::Kind k
= kind::LEQ
;
733 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
734 ops
.back().push_back(getExprManager()->operatorOf(k
));
735 cnames
.push_back(kind::kindToString(k
));
736 cargs
.push_back( std::vector
< CVC4::Type
>() );
737 cargs
.back().push_back(unres_types
[i
]);
738 cargs
.back().push_back(unres_types
[i
]);
739 }else if( types
[i
].isDatatype() ){
741 Debug("parser-sygus") << "...add for testers" << std::endl
;
742 const Datatype
& dt
= ((DatatypeType
)types
[i
]).getDatatype();
743 for( unsigned k
=0; k
<dt
.getNumConstructors(); k
++ ){
744 Debug("parser-sygus") << "...for " << dt
[k
].getTesterName() << std::endl
;
745 ops
.back().push_back(dt
[k
].getTester());
746 cnames
.push_back(dt
[k
].getTesterName());
747 cargs
.push_back( std::vector
< CVC4::Type
>() );
748 cargs
.back().push_back(unres_types
[i
]);
753 startIndex
= sorts
.size();
755 Debug("parser-sygus") << "...make datatype " << datatypes
.back() << std::endl
;
756 datatypes
.back().setSygus( btype
, bvl
, true, true );
757 mkSygusDatatype( datatypes
.back(), ops
.back(), cnames
, cargs
, unresolved_gterm_sym
, sygus_to_builtin
);
758 sorts
.push_back( btype
);
760 Debug("parser-sygus") << "...finished make default grammar for " << fun
<< " " << range
<< std::endl
;
763 void Smt2::mkSygusConstantsForType( const Type
& type
, std::vector
<CVC4::Expr
>& ops
) {
764 if( type
.isInteger() ){
765 ops
.push_back(getExprManager()->mkConst(Rational(0)));
766 ops
.push_back(getExprManager()->mkConst(Rational(1)));
767 }else if( type
.isBitVector() ){
768 unsigned sz
= ((BitVectorType
)type
).getSize();
769 BitVector
bval0(sz
, (unsigned int)0);
770 ops
.push_back( getExprManager()->mkConst(bval0
) );
771 BitVector
bval1(sz
, (unsigned int)1);
772 ops
.push_back( getExprManager()->mkConst(bval1
) );
773 }else if( type
.isBoolean() ){
774 ops
.push_back(getExprManager()->mkConst(true));
775 ops
.push_back(getExprManager()->mkConst(false));
780 // 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)
781 // This method may also add new elements pairwise into datatypes/sorts/ops/cnames/cargs in the case of non-flat gterms.
782 void Smt2::processSygusGTerm( CVC4::SygusGTerm
& sgt
, int index
,
783 std::vector
< CVC4::Datatype
>& datatypes
,
784 std::vector
< CVC4::Type
>& sorts
,
785 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
786 std::vector
< std::vector
<std::string
> >& cnames
,
787 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
788 std::vector
< bool >& allow_const
,
789 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
,
790 std::vector
<CVC4::Expr
>& sygus_vars
,
791 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
, std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
,
792 CVC4::Type
& ret
, bool isNested
){
793 if( sgt
.d_gterm_type
==SygusGTerm::gterm_op
|| sgt
.d_gterm_type
==SygusGTerm::gterm_let
){
794 Debug("parser-sygus") << "Add " << sgt
.d_expr
<< " to datatype " << index
<< std::endl
;
796 Kind newKind
= kind::UNDEFINED_KIND
;
797 //convert to UMINUS if one child of MINUS
798 if( sgt
.d_children
.size()==1 && sgt
.d_expr
==getExprManager()->operatorOf(kind::MINUS
) ){
799 oldKind
= kind::MINUS
;
800 newKind
= kind::UMINUS
;
802 //convert to IFF if boolean EQUAL
803 if( sgt
.d_expr
==getExprManager()->operatorOf(kind::EQUAL
) ){
804 Type ctn
= sgt
.d_children
[0].d_type
;
805 std::map
< CVC4::Type
, CVC4::Type
>::iterator it
= sygus_to_builtin
.find( ctn
);
806 if( it
!= sygus_to_builtin
.end() && it
->second
.isBoolean() ){
807 oldKind
= kind::EQUAL
;
811 if( newKind
!=kind::UNDEFINED_KIND
){
812 Expr newExpr
= getExprManager()->operatorOf(newKind
);
813 Debug("parser-sygus") << "Replace " << sgt
.d_expr
<< " with " << newExpr
<< std::endl
;
814 sgt
.d_expr
= newExpr
;
815 std::string oldName
= kind::kindToString(oldKind
);
816 std::string newName
= kind::kindToString(newKind
);
818 if((pos
= sgt
.d_name
.find(oldName
, pos
)) != std::string::npos
){
819 sgt
.d_name
.replace(pos
, oldName
.length(), newName
);
822 ops
[index
].push_back( sgt
.d_expr
);
823 cnames
[index
].push_back( sgt
.d_name
);
824 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
825 for( unsigned i
=0; i
<sgt
.d_children
.size(); i
++ ){
826 std::stringstream ss
;
827 ss
<< datatypes
[index
].getName() << "_" << ops
[index
].size() << "_arg_" << i
;
828 std::string sub_dname
= ss
.str();
829 //add datatype for child
831 pushSygusDatatypeDef( null_type
, sub_dname
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
);
832 int sub_dt_index
= datatypes
.size()-1;
835 processSygusGTerm( sgt
.d_children
[i
], sub_dt_index
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
,
836 sygus_vars
, sygus_to_builtin
, sygus_to_builtin_expr
, sub_ret
, true );
837 //process the nested gterm (either pop the last datatype, or flatten the argument)
838 Type tt
= processSygusNestedGTerm( sub_dt_index
, sub_dname
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
,
839 sygus_to_builtin
, sygus_to_builtin_expr
, sub_ret
);
840 cargs
[index
].back().push_back(tt
);
842 //if let, must create operator
843 if( sgt
.d_gterm_type
==SygusGTerm::gterm_let
){
844 processSygusLetConstructor( sgt
.d_let_vars
, index
, datatypes
, sorts
, ops
, cnames
, cargs
,
845 sygus_vars
, sygus_to_builtin
, sygus_to_builtin_expr
);
847 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_constant
){
848 if( sgt
.getNumChildren()!=0 ){
849 parseError("Bad syntax for Sygus Constant.");
851 std::vector
< Expr
> consts
;
852 mkSygusConstantsForType( sgt
.d_type
, consts
);
853 Debug("parser-sygus") << "...made " << consts
.size() << " constants." << std::endl
;
854 for( unsigned i
=0; i
<consts
.size(); i
++ ){
855 std::stringstream ss
;
857 Debug("parser-sygus") << "...add for constant " << ss
.str() << std::endl
;
858 ops
[index
].push_back( consts
[i
] );
859 cnames
[index
].push_back( ss
.str() );
860 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
862 allow_const
[index
] = true;
863 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_variable
|| sgt
.d_gterm_type
==SygusGTerm::gterm_input_variable
){
864 if( sgt
.getNumChildren()!=0 ){
865 parseError("Bad syntax for Sygus Variable.");
867 Debug("parser-sygus") << "...process " << sygus_vars
.size() << " variables." << std::endl
;
868 for( unsigned i
=0; i
<sygus_vars
.size(); i
++ ){
869 if( sygus_vars
[i
].getType()==sgt
.d_type
){
870 std::stringstream ss
;
872 Debug("parser-sygus") << "...add for variable " << ss
.str() << std::endl
;
873 ops
[index
].push_back( sygus_vars
[i
] );
874 cnames
[index
].push_back( ss
.str() );
875 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
878 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_nested_sort
){
880 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_unresolved
){
882 if( isUnresolvedType(sgt
.d_name
) ){
883 ret
= getSort(sgt
.d_name
);
885 //nested, unresolved symbol...fail
886 std::stringstream ss
;
887 ss
<< "Cannot handle nested unresolved symbol " << sgt
.d_name
<< std::endl
;
888 parseError(ss
.str());
891 //will resolve when adding constructors
892 unresolved_gterm_sym
[index
].push_back(sgt
.d_name
);
894 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_ignore
){
899 bool Smt2::pushSygusDatatypeDef( Type t
, std::string
& dname
,
900 std::vector
< CVC4::Datatype
>& datatypes
,
901 std::vector
< CVC4::Type
>& sorts
,
902 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
903 std::vector
< std::vector
<std::string
> >& cnames
,
904 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
905 std::vector
< bool >& allow_const
,
906 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
){
908 datatypes
.push_back(Datatype(dname
));
909 ops
.push_back(std::vector
<Expr
>());
910 cnames
.push_back(std::vector
<std::string
>());
911 cargs
.push_back(std::vector
<std::vector
<CVC4::Type
> >());
912 allow_const
.push_back(false);
913 unresolved_gterm_sym
.push_back(std::vector
< std::string
>());
917 bool Smt2::popSygusDatatypeDef( std::vector
< CVC4::Datatype
>& datatypes
,
918 std::vector
< CVC4::Type
>& sorts
,
919 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
920 std::vector
< std::vector
<std::string
> >& cnames
,
921 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
922 std::vector
< bool >& allow_const
,
923 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
){
925 datatypes
.pop_back();
929 allow_const
.pop_back();
930 unresolved_gterm_sym
.pop_back();
934 Type
Smt2::processSygusNestedGTerm( int sub_dt_index
, std::string
& sub_dname
, std::vector
< CVC4::Datatype
>& datatypes
,
935 std::vector
< CVC4::Type
>& sorts
,
936 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
937 std::vector
< std::vector
<std::string
> >& cnames
,
938 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
939 std::vector
< bool >& allow_const
,
940 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
,
941 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
,
942 std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
, Type sub_ret
) {
944 Debug("parser-sygus") << "Argument is ";
946 //then, it is the datatype we constructed, which should have a single constructor
947 t
= mkUnresolvedType(sub_dname
);
948 Debug("parser-sygus") << "inline flattening of (auxiliary, local) datatype " << t
<< std::endl
;
949 Debug("parser-sygus") << ": to compute type, construct ground term witnessing the grammar, #cons=" << cargs
[sub_dt_index
].size() << std::endl
;
950 if( cargs
[sub_dt_index
].empty() ){
951 parseError(std::string("Internal error : datatype for nested gterm does not have a constructor."));
953 Expr sop
= ops
[sub_dt_index
][0];
955 if( sop
.getKind() != kind::BUILTIN
&& ( sop
.isConst() || cargs
[sub_dt_index
][0].empty() ) ){
956 curr_t
= sop
.getType();
957 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
;
958 sygus_to_builtin_expr
[t
] = sop
;
959 //store that term sop has dedicated sygus type t
960 if( d_sygus_bound_var_type
.find( sop
)==d_sygus_bound_var_type
.end() ){
961 d_sygus_bound_var_type
[sop
] = t
;
964 std::vector
< Expr
> children
;
965 if( sop
.getKind() != kind::BUILTIN
){
966 children
.push_back( sop
);
968 for( unsigned i
=0; i
<cargs
[sub_dt_index
][0].size(); i
++ ){
969 std::map
< CVC4::Type
, CVC4::Expr
>::iterator it
= sygus_to_builtin_expr
.find( cargs
[sub_dt_index
][0][i
] );
970 if( it
==sygus_to_builtin_expr
.end() ){
971 if( sygus_to_builtin
.find( cargs
[sub_dt_index
][0][i
] )==sygus_to_builtin
.end() ){
972 std::stringstream ss
;
973 ss
<< "Missing builtin type for type " << cargs
[sub_dt_index
][0][i
] << "!" << std::endl
;
974 ss
<< "Builtin types are currently : " << std::endl
;
975 for( std::map
< CVC4::Type
, CVC4::Type
>::iterator itb
= sygus_to_builtin
.begin(); itb
!= sygus_to_builtin
.end(); ++itb
){
976 ss
<< " " << itb
->first
<< " -> " << itb
->second
<< std::endl
;
978 parseError(ss
.str());
980 Type bt
= sygus_to_builtin
[cargs
[sub_dt_index
][0][i
]];
981 Debug("parser-sygus") << ": child " << i
<< " introduce type elem for " << cargs
[sub_dt_index
][0][i
] << " " << bt
<< std::endl
;
982 std::stringstream ss
;
983 ss
<< t
<< "_x_" << i
;
984 Expr bv
= mkBoundVar(ss
.str(), bt
);
985 children
.push_back( bv
);
986 d_sygus_bound_var_type
[bv
] = cargs
[sub_dt_index
][0][i
];
988 Debug("parser-sygus") << ": child " << i
<< " existing sygus to builtin expr : " << it
->second
<< std::endl
;
989 children
.push_back( it
->second
);
992 Kind sk
= sop
.getKind() != kind::BUILTIN
? kind::APPLY
: getExprManager()->operatorToKind(sop
);
993 Debug("parser-sygus") << ": operator " << sop
<< " with " << sop
.getKind() << " " << sk
<< std::endl
;
994 Expr e
= getExprManager()->mkExpr( sk
, children
);
995 Debug("parser-sygus") << ": constructed " << e
<< ", which has type " << e
.getType() << std::endl
;
996 curr_t
= e
.getType();
997 sygus_to_builtin_expr
[t
] = e
;
999 sorts
[sub_dt_index
] = curr_t
;
1000 sygus_to_builtin
[t
] = curr_t
;
1002 Debug("parser-sygus") << "simple argument " << t
<< std::endl
;
1003 Debug("parser-sygus") << "...removing " << datatypes
.back().getName() << std::endl
;
1004 //otherwise, datatype was unecessary
1005 //pop argument datatype definition
1006 popSygusDatatypeDef( datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
);
1011 void Smt2::processSygusLetConstructor( std::vector
< CVC4::Expr
>& let_vars
,
1013 std::vector
< CVC4::Datatype
>& datatypes
,
1014 std::vector
< CVC4::Type
>& sorts
,
1015 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
1016 std::vector
< std::vector
<std::string
> >& cnames
,
1017 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
1018 std::vector
<CVC4::Expr
>& sygus_vars
,
1019 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
,
1020 std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
) {
1021 std::vector
< CVC4::Expr
> let_define_args
;
1023 int dindex
= cargs
[index
].size()-1;
1024 Debug("parser-sygus") << "Process let constructor for datatype " << datatypes
[index
].getName() << ", #subtypes = " << cargs
[index
][dindex
].size() << std::endl
;
1025 for( unsigned i
=0; i
<cargs
[index
][dindex
].size(); i
++ ){
1026 Debug("parser-sygus") << " " << i
<< " : " << cargs
[index
][dindex
][i
] << std::endl
;
1027 if( i
+1==cargs
[index
][dindex
].size() ){
1028 std::map
< CVC4::Type
, CVC4::Expr
>::iterator it
= sygus_to_builtin_expr
.find( cargs
[index
][dindex
][i
] );
1029 if( it
!=sygus_to_builtin_expr
.end() ){
1030 let_body
= it
->second
;
1032 std::stringstream ss
;
1033 ss
<< datatypes
[index
].getName() << "_body";
1034 let_body
= mkBoundVar(ss
.str(), sygus_to_builtin
[cargs
[index
][dindex
][i
]]);
1035 d_sygus_bound_var_type
[let_body
] = cargs
[index
][dindex
][i
];
1039 Debug("parser-sygus") << std::endl
;
1040 Debug("parser-sygus") << "Body is " << let_body
<< std::endl
;
1041 Debug("parser-sygus") << "# let vars = " << let_vars
.size() << std::endl
;
1042 for( unsigned i
=0; i
<let_vars
.size(); i
++ ){
1043 Debug("parser-sygus") << " let var " << i
<< " : " << let_vars
[i
] << " " << let_vars
[i
].getType() << std::endl
;
1044 let_define_args
.push_back( let_vars
[i
] );
1047 Debug("parser-sygus") << "index = " << index << ", start index = " << start_index << ", #Current datatypes = " << datatypes.size() << std::endl;
1048 for( unsigned i=start_index; i<datatypes.size(); i++ ){
1049 Debug("parser-sygus") << " datatype " << i << " : " << datatypes[i].getName() << ", #cons = " << cargs[i].size() << std::endl;
1050 if( !cargs[i].empty() ){
1051 Debug("parser-sygus") << " operator 0 is " << ops[i][0] << std::endl;
1052 Debug("parser-sygus") << " cons 0 has " << cargs[i][0].size() << " sub fields." << std::endl;
1053 for( unsigned j=0; j<cargs[i][0].size(); j++ ){
1054 Type bt = sygus_to_builtin[cargs[i][0][j]];
1055 Debug("parser-sygus") << " cons 0, selector " << j << " : " << cargs[i][0][j] << " " << bt << std::endl;
1060 //last argument is the return, pop
1061 cargs
[index
][dindex
].pop_back();
1062 collectSygusLetArgs( let_body
, cargs
[index
][dindex
], let_define_args
);
1064 Debug("parser-sygus") << "Make define-fun with " << cargs
[index
][dindex
].size() << " arguments..." << std::endl
;
1065 std::vector
<CVC4::Type
> fsorts
;
1066 for( unsigned i
=0; i
<cargs
[index
][dindex
].size(); i
++ ){
1067 Debug("parser-sygus") << " " << i
<< " : " << let_define_args
[i
] << " " << let_define_args
[i
].getType() << " " << cargs
[index
][dindex
][i
] << std::endl
;
1068 fsorts
.push_back(let_define_args
[i
].getType());
1071 Type ft
= getExprManager()->mkFunctionType(fsorts
, let_body
.getType());
1072 std::stringstream ss
;
1073 ss
<< datatypes
[index
].getName() << "_let";
1074 Expr let_func
= mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
1075 d_sygus_defined_funs
.push_back( let_func
);
1076 preemptCommand( new DefineFunctionCommand(ss
.str(), let_func
, let_define_args
, let_body
) );
1078 ops
[index
].pop_back();
1079 ops
[index
].push_back( let_func
);
1080 cnames
[index
].pop_back();
1081 cnames
[index
].push_back(ss
.str());
1083 //mark function as let constructor
1084 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() );
1085 d_sygus_let_func_to_body
[let_func
] = let_body
;
1086 d_sygus_let_func_to_num_input_vars
[let_func
] = let_vars
.size();
1090 void Smt2::collectSygusLetArgs( CVC4::Expr e
, std::vector
< CVC4::Type
>& sygusArgs
, std::vector
< CVC4::Expr
>& builtinArgs
) {
1091 if( e
.getKind()==kind::BOUND_VARIABLE
){
1092 if( std::find( builtinArgs
.begin(), builtinArgs
.end(), e
)==builtinArgs
.end() ){
1093 builtinArgs
.push_back( e
);
1094 sygusArgs
.push_back( d_sygus_bound_var_type
[e
] );
1095 if( d_sygus_bound_var_type
[e
].isNull() ){
1096 std::stringstream ss
;
1097 ss
<< "While constructing body of let gterm, can't map " << e
<< " to sygus type." << std::endl
;
1098 parseError(ss
.str());
1102 for( unsigned i
=0; i
<e
.getNumChildren(); i
++ ){
1103 collectSygusLetArgs( e
[i
], sygusArgs
, builtinArgs
);
1108 void Smt2::setSygusStartIndex( std::string
& fun
, int startIndex
,
1109 std::vector
< CVC4::Datatype
>& datatypes
,
1110 std::vector
< CVC4::Type
>& sorts
,
1111 std::vector
< std::vector
<CVC4::Expr
> >& ops
) {
1113 CVC4::Datatype tmp_dt
= datatypes
[0];
1114 Type tmp_sort
= sorts
[0];
1115 std::vector
< Expr
> tmp_ops
;
1116 tmp_ops
.insert( tmp_ops
.end(), ops
[0].begin(), ops
[0].end() );
1117 datatypes
[0] = datatypes
[startIndex
];
1118 sorts
[0] = sorts
[startIndex
];
1120 ops
[0].insert( ops
[0].end(), ops
[startIndex
].begin(), ops
[startIndex
].end() );
1121 datatypes
[startIndex
] = tmp_dt
;
1122 sorts
[startIndex
] = tmp_sort
;
1123 ops
[startIndex
].clear();
1124 ops
[startIndex
].insert( ops
[startIndex
].begin(), tmp_ops
.begin(), tmp_ops
.end() );
1125 }else if( startIndex
<0 ){
1126 std::stringstream ss
;
1127 ss
<< "warning: no symbol named Start for synth-fun " << fun
<< std::endl
;
1132 void Smt2::defineSygusFuns() {
1133 // only define each one once
1134 while(d_nextSygusFun
< d_sygusFuns
.size()) {
1135 std::pair
<std::string
, Expr
> p
= d_sygusFuns
[d_nextSygusFun
];
1136 std::string fun
= p
.first
;
1137 Debug("parser-sygus") << "Sygus : define fun " << fun
<< std::endl
;
1138 Expr eval
= p
.second
;
1139 FunctionType evalType
= eval
.getType();
1140 std::vector
<Type
> argTypes
= evalType
.getArgTypes();
1141 Type rangeType
= evalType
.getRangeType();
1142 Debug("parser-sygus") << "...eval type : " << evalType
<< ", #args=" << argTypes
.size() << std::endl
;
1144 // first make the function type
1145 std::vector
<Expr
> sygusVars
;
1146 std::vector
<Type
> funType
;
1147 for(size_t j
= 1; j
< argTypes
.size(); ++j
) {
1148 funType
.push_back(argTypes
[j
]);
1149 std::stringstream ss
;
1150 ss
<< fun
<< "_v_" << j
;
1151 sygusVars
.push_back(getExprManager()->mkBoundVar(ss
.str(), argTypes
[j
]));
1154 if( !funType
.empty() ){
1155 funt
= getExprManager()->mkFunctionType(funType
, rangeType
);
1156 Debug("parser-sygus") << "...eval function type : " << funt
<< std::endl
;
1158 // copy the bound vars
1160 std::vector<Expr> sygusVars;
1161 //std::vector<Type> types;
1162 for(size_t i = 0; i < d_sygusVars.size(); ++i) {
1163 std::stringstream ss;
1164 ss << d_sygusVars[i];
1165 Type type = d_sygusVars[i].getType();
1166 sygusVars.push_back(getExprManager()->mkBoundVar(ss.str(), type));
1167 //types.push_back(type);
1169 Debug("parser-sygus") << "...made vars, #vars=" << sygusVars.size() << std::endl;
1172 //Type t = getExprManager()->mkFunctionType(types, rangeType);
1173 //Debug("parser-sygus") << "...function type : " << t << std::endl;
1177 Expr lambda
= mkFunction(fun
, funt
, ExprManager::VAR_FLAG_DEFINED
);
1178 Debug("parser-sygus") << "...made function : " << lambda
<< std::endl
;
1179 std::vector
<Expr
> applyv
;
1180 Expr funbv
= getExprManager()->mkBoundVar(std::string("f") + fun
, argTypes
[0]);
1181 d_sygusFunSymbols
.push_back(funbv
);
1182 applyv
.push_back(eval
);
1183 applyv
.push_back(funbv
);
1184 for(size_t i
= 0; i
< sygusVars
.size(); ++i
) {
1185 applyv
.push_back(sygusVars
[i
]);
1187 Expr apply
= getExprManager()->mkExpr(kind::APPLY_UF
, applyv
);
1188 Debug("parser-sygus") << "...made apply " << apply
<< std::endl
;
1189 Debug("parser-sygus") << "--> Define " << fun
<< " as " << lambda
<< " " << apply
<< std::endl
;
1190 Command
* cmd
= new DefineFunctionCommand(fun
, lambda
, sygusVars
, apply
);
1191 preemptCommand(cmd
);
1197 void Smt2::mkSygusDatatype( CVC4::Datatype
& dt
, std::vector
<CVC4::Expr
>& ops
,
1198 std::vector
<std::string
>& cnames
, std::vector
< std::vector
< CVC4::Type
> >& cargs
,
1199 std::vector
<std::string
>& unresolved_gterm_sym
,
1200 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
) {
1201 Debug("parser-sygus") << "Making sygus datatype " << dt
.getName() << std::endl
;
1202 Debug("parser-sygus") << " add constructors..." << std::endl
;
1203 for( int i
=0; i
<(int)cnames
.size(); i
++ ){
1204 bool is_dup
= false;
1205 bool is_dup_op
= false;
1207 std::vector
< Expr
> let_args
;
1208 unsigned let_num_input_args
= 0;
1209 for( int j
=0; j
<i
; j
++ ){
1210 if( ops
[i
]==ops
[j
] ){
1212 if( cargs
[i
].size()==cargs
[j
].size() ){
1214 for( unsigned k
=0; k
<cargs
[i
].size(); k
++ ){
1215 if( cargs
[i
][k
]!=cargs
[j
][k
] ){
1227 Debug("parser-sygus") << "--> Duplicate gterm : " << ops
[i
] << " at " << i
<< std::endl
;
1228 ops
.erase( ops
.begin() + i
, ops
.begin() + i
+ 1 );
1229 cnames
.erase( cnames
.begin() + i
, cnames
.begin() + i
+ 1 );
1230 cargs
.erase( cargs
.begin() + i
, cargs
.begin() + i
+ 1 );
1232 }else if( is_dup_op
){
1233 Debug("parser-sygus") << "--> Duplicate gterm operator : " << ops
[i
] << " at " << i
<< std::endl
;
1234 //make into define-fun
1235 std::vector
<CVC4::Type
> fsorts
;
1236 for( unsigned j
=0; j
<cargs
[i
].size(); j
++ ){
1237 Type bt
= sygus_to_builtin
[cargs
[i
][j
]];
1238 std::stringstream ss
;
1239 ss
<< dt
.getName() << "_x_" << i
<< "_" << j
;
1240 Expr v
= mkBoundVar(ss
.str(), bt
);
1241 let_args
.push_back( v
);
1242 fsorts
.push_back( bt
);
1243 Debug("parser-sygus") << ": var " << i
<< " " << v
<< " with type " << bt
<< " from " << cargs
[i
][j
] << std::endl
;
1246 std::vector
< Expr
> children
;
1247 if( ops
[i
].getKind() != kind::BUILTIN
){
1248 children
.push_back( ops
[i
] );
1250 children
.insert( children
.end(), let_args
.begin(), let_args
.end() );
1251 Kind sk
= ops
[i
].getKind() != kind::BUILTIN
? kind::APPLY
: getExprManager()->operatorToKind(ops
[i
]);
1252 Debug("parser-sygus") << ": replace " << ops
[i
] << " " << ops
[i
].getKind() << " " << sk
<< std::endl
;
1253 let_body
= getExprManager()->mkExpr( sk
, children
);
1254 Debug("parser-sygus") << ": new body of function is " << let_body
<< std::endl
;
1256 Type ft
= getExprManager()->mkFunctionType(fsorts
, let_body
.getType());
1257 Debug("parser-sygus") << ": function type is " << ft
<< std::endl
;
1258 std::stringstream ss
;
1259 ss
<< dt
.getName() << "_df_" << i
;
1260 //replace operator and name
1261 ops
[i
] = mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
1262 cnames
[i
] = ss
.str();
1263 d_sygus_defined_funs
.push_back( ops
[i
] );
1264 preemptCommand( new DefineFunctionCommand(ss
.str(), ops
[i
], let_args
, let_body
) );
1265 addSygusDatatypeConstructor( dt
, ops
[i
], cnames
[i
], cargs
[i
], let_body
, let_args
, 0 );
1267 std::map
< CVC4::Expr
, CVC4::Expr
>::iterator it
= d_sygus_let_func_to_body
.find( ops
[i
] );
1268 if( it
!=d_sygus_let_func_to_body
.end() ){
1269 let_body
= it
->second
;
1270 let_args
.insert( let_args
.end(), d_sygus_let_func_to_vars
[ops
[i
]].begin(), d_sygus_let_func_to_vars
[ops
[i
]].end() );
1271 let_num_input_args
= d_sygus_let_func_to_num_input_vars
[ops
[i
]];
1273 addSygusDatatypeConstructor( dt
, ops
[i
], cnames
[i
], cargs
[i
], let_body
, let_args
, let_num_input_args
);
1276 Debug("parser-sygus") << " add constructors for unresolved symbols..." << std::endl
;
1277 if( !unresolved_gterm_sym
.empty() ){
1278 std::vector
< Type
> types
;
1279 Debug("parser-sygus") << "...resolve " << unresolved_gterm_sym
.size() << " symbols..." << std::endl
;
1280 for( unsigned i
=0; i
<unresolved_gterm_sym
.size(); i
++ ){
1281 Debug("parser-sygus") << " resolve : " << unresolved_gterm_sym
[i
] << std::endl
;
1282 if( isUnresolvedType(unresolved_gterm_sym
[i
]) ){
1283 Debug("parser-sygus") << " it is an unresolved type." << std::endl
;
1284 Type t
= getSort(unresolved_gterm_sym
[i
]);
1285 if( std::find( types
.begin(), types
.end(), t
)==types
.end() ){
1286 types
.push_back( t
);
1288 Type bt
= dt
.getSygusType();
1289 Debug("parser-sygus") << ": make identity function for " << bt
<< ", argument type " << t
<< std::endl
;
1290 std::stringstream ss
;
1292 Expr let_body
= mkBoundVar(ss
.str(), bt
);
1293 std::vector
< Expr
> let_args
;
1294 let_args
.push_back( let_body
);
1295 //make the identity function
1296 Type ft
= getExprManager()->mkFunctionType(bt
, bt
);
1297 std::stringstream ssid
;
1298 ssid
<< unresolved_gterm_sym
[i
] << "_id";
1299 Expr id_op
= mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
1300 d_sygus_defined_funs
.push_back( id_op
);
1301 preemptCommand( new DefineFunctionCommand(ssid
.str(), id_op
, let_args
, let_body
) );
1302 //make the sygus argument list
1303 std::vector
< Type
> id_carg
;
1304 id_carg
.push_back( t
);
1305 addSygusDatatypeConstructor( dt
, id_op
, unresolved_gterm_sym
[i
], id_carg
, let_body
, let_args
, 0 );
1307 ops
.push_back( id_op
);
1310 Debug("parser-sygus") << " ignore. (likely a free let variable)" << std::endl
;
1317 void Smt2::addSygusDatatypeConstructor( CVC4::Datatype
& dt
, CVC4::Expr op
, std::string
& cname
, std::vector
< CVC4::Type
>& cargs
,
1318 CVC4::Expr
& let_body
, std::vector
< CVC4::Expr
>& let_args
, unsigned let_num_input_args
) {
1319 Debug("parser-sygus") << "--> Add constructor " << cname
<< " to " << dt
.getName() << std::endl
;
1320 if( !let_body
.isNull() ){
1321 Debug("parser-sygus") << " let body = " << let_body
<< ", args = " << let_args
.size() << "," << let_num_input_args
<< std::endl
;
1322 //TODO : remove arguments not occurring in body
1323 //if this is a self identity function, ignore
1324 if( let_args
.size()==0 && let_args
[0]==let_body
){
1325 Debug("parser-sygus") << " identity function " << cargs
[0] << " to " << dt
.getName() << std::endl
;
1329 std::string name
= dt
.getName() + "_" + cname
;
1330 std::string
testerId("is-");
1331 testerId
.append(name
);
1332 checkDeclaration(name
, CHECK_UNDECLARED
, SYM_VARIABLE
);
1333 checkDeclaration(testerId
, CHECK_UNDECLARED
, SYM_VARIABLE
);
1334 CVC4::DatatypeConstructor
c(name
, testerId
);
1335 c
.setSygus( op
, let_body
, let_args
, let_num_input_args
);
1336 for( unsigned j
=0; j
<cargs
.size(); j
++ ){
1337 Debug("parser-sygus-debug") << " arg " << j
<< " : " << cargs
[j
] << std::endl
;
1338 std::stringstream sname
;
1339 sname
<< name
<< "_" << j
;
1340 c
.addArg(sname
.str(), cargs
[j
]);
1342 dt
.addConstructor(c
);
1346 // i is index in datatypes/ops
1347 // j is index is datatype
1348 Expr
Smt2::getSygusAssertion( std::vector
<DatatypeType
>& datatypeTypes
, std::vector
< std::vector
<Expr
> >& ops
,
1349 std::map
<DatatypeType
, Expr
>& evals
, std::vector
<Expr
>& terms
,
1350 Expr eval
, const Datatype
& dt
, size_t i
, size_t j
) {
1351 const DatatypeConstructor
& ctor
= dt
[j
];
1352 Debug("parser-sygus") << "Sygus : process constructor " << j
<< " : " << dt
[j
] << std::endl
;
1353 std::vector
<Expr
> bvs
, extraArgs
;
1354 for(size_t k
= 0; k
< ctor
.getNumArgs(); ++k
) {
1355 std::string vname
= "v_" + ctor
[k
].getName();
1356 Expr bv
= getExprManager()->mkBoundVar(vname
, SelectorType(ctor
[k
].getType()).getRangeType());
1358 extraArgs
.push_back(bv
);
1360 if( !terms
[0].isNull() ){
1361 bvs
.insert(bvs
.end(), terms
[0].begin(), terms
[0].end());
1365 bvl
= getExprManager()->mkExpr(kind::BOUND_VAR_LIST
, bvs
);
1367 Debug("parser-sygus") << "...made bv list " << bvl
<< std::endl
;
1368 std::vector
<Expr
> patv
;
1369 patv
.push_back(eval
);
1370 std::vector
<Expr
> applyv
;
1371 applyv
.push_back(ctor
.getConstructor());
1372 applyv
.insert(applyv
.end(), extraArgs
.begin(), extraArgs
.end());
1373 for(size_t k
= 0; k
< applyv
.size(); ++k
) {
1375 Expr cpatv
= getExprManager()->mkExpr(kind::APPLY_CONSTRUCTOR
, applyv
);
1376 Debug("parser-sygus") << "...made eval ctor apply " << cpatv
<< std::endl
;
1377 patv
.push_back(cpatv
);
1378 if( !terms
[0].isNull() ){
1379 patv
.insert(patv
.end(), terms
[0].begin(), terms
[0].end());
1381 Expr evalApply
= getExprManager()->mkExpr(kind::APPLY_UF
, patv
);
1382 Debug("parser-sygus") << "...made eval apply " << evalApply
<< std::endl
;
1383 std::vector
<Expr
> builtApply
;
1384 for(size_t k
= 0; k
< extraArgs
.size(); ++k
) {
1385 std::vector
<Expr
> patvb
;
1386 patvb
.push_back(evals
[DatatypeType(extraArgs
[k
].getType())]);
1387 patvb
.push_back(extraArgs
[k
]);
1388 if( !terms
[0].isNull() ){
1389 patvb
.insert(patvb
.end(), terms
[0].begin(), terms
[0].end());
1391 Debug("parser-sygus-debug") << "...add to built apply " << evals
[DatatypeType(extraArgs
[k
].getType())] << " " << extraArgs
[k
] << " " << extraArgs
[k
].getType() << std::endl
;
1392 builtApply
.push_back(getExprManager()->mkExpr(kind::APPLY_UF
, patvb
));
1393 Debug("parser-sygus-debug") << "...added " << builtApply
.back() << std::endl
;
1395 for(size_t k
= 0; k
< builtApply
.size(); ++k
) {
1398 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
;
1399 if( ops
[i
][j
].getKind() != kind::BUILTIN
){
1400 Kind ok
= kind::UNDEFINED_KIND
;
1401 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() ){
1404 Type t
= ops
[i
][j
].getType();
1405 if( t
.isConstructor() ){
1406 ok
= kind::APPLY_CONSTRUCTOR
;
1407 }else if( t
.isSelector() ){
1408 ok
= kind::APPLY_SELECTOR
;
1409 }else if( t
.isTester() ){
1410 ok
= kind::APPLY_TESTER
;
1412 ok
= getExprManager()->operatorToKind( ops
[i
][j
] );
1415 Debug("parser-sygus") << "...processed operator kind : " << ok
<< std::endl
;
1416 if( ok
!=kind::UNDEFINED_KIND
){
1417 builtTerm
= getExprManager()->mkExpr(ok
, ops
[i
][j
], builtApply
);
1419 builtTerm
= ops
[i
][j
];
1422 if( !builtApply
.empty() ){
1423 builtTerm
= getExprManager()->mkExpr(ops
[i
][j
], builtApply
);
1425 builtTerm
= ops
[i
][j
];
1428 Debug("parser-sygus") << "...made built term " << builtTerm
<< std::endl
;
1429 Expr assertion
= getExprManager()->mkExpr(evalApply
.getType().isBoolean() ? kind::IFF
: kind::EQUAL
, evalApply
, builtTerm
);
1430 if( !bvl
.isNull() ){
1431 Expr pattern
= getExprManager()->mkExpr(kind::INST_PATTERN
, evalApply
);
1432 pattern
= getExprManager()->mkExpr(kind::INST_PATTERN_LIST
, pattern
);
1433 assertion
= getExprManager()->mkExpr(kind::FORALL
, bvl
, assertion
, pattern
);
1435 Debug("parser-sygus") << "...made assertion " << assertion
<< std::endl
;
1437 //linearize multiplication if possible
1438 if( builtTerm
.getKind()==kind::MULT
){
1439 for(size_t k
= 0; k
< ctor
.getNumArgs(); ++k
) {
1440 Type at
= SelectorType(ctor
[k
].getType()).getRangeType();
1441 if( at
.isDatatype() ){
1442 DatatypeType atd
= (DatatypeType
)SelectorType(ctor
[k
].getType()).getRangeType();
1443 Debug("parser-sygus") << "Argument " << k
<< " " << atd
<< std::endl
;
1444 std::vector
<DatatypeType
>::iterator itd
= std::find( datatypeTypes
.begin(), datatypeTypes
.end(), atd
);
1445 if( itd
!=datatypeTypes
.end() ){
1446 Debug("parser-sygus2") << "Exists in datatypeTypes." << std::endl
;
1447 unsigned index
= itd
-datatypeTypes
.begin();
1448 Debug("parser-sygus2") << "index = " << index
<< std::endl
;
1449 bool isConst
= true;
1450 for( unsigned cc
= 0; cc
< ops
[index
].size(); cc
++ ){
1451 Debug("parser-sygus2") << "ops[" << cc
<< "]=" << ops
[index
][cc
] << std::endl
;
1452 if( ops
[index
][cc
].getKind() != kind::CONST_RATIONAL
){
1458 Debug("parser-sygus") << "Linearize multiplication " << ctor
<< " based on argument " << k
<< std::endl
;
1459 const Datatype
& atdd
= atd
.getDatatype();
1460 std::vector
<Expr
> assertions
;
1461 std::vector
<Expr
> nbvs
;
1462 for( unsigned a
=0; a
<bvl
.getNumChildren(); a
++ ){
1464 nbvs
.push_back( bvl
[a
] );
1467 Expr nbvl
= getExprManager()->mkExpr( kind::BOUND_VAR_LIST
, nbvs
);
1468 for( unsigned cc
= 0; cc
< ops
[index
].size(); cc
++ ){
1469 //Make new assertion based on partially instantiating existing
1470 applyv
[k
+1] = getExprManager()->mkExpr(kind::APPLY_CONSTRUCTOR
, atdd
[cc
].getConstructor());
1471 Debug("parser-sygus") << "applyv " << applyv
[k
+1] << std::endl
;
1472 cpatv
= getExprManager()->mkExpr(kind::APPLY_CONSTRUCTOR
, applyv
);
1473 Debug("parser-sygus") << "cpatv " << cpatv
<< std::endl
;
1475 evalApply
= getExprManager()->mkExpr(kind::APPLY_UF
, patv
);
1476 Debug("parser-sygus") << "evalApply " << evalApply
<< std::endl
;
1477 builtApply
[k
] = ops
[index
][cc
];
1478 Debug("parser-sygus") << "builtApply " << builtApply
[k
] << std::endl
;
1479 builtTerm
= getExprManager()->mkExpr(ops
[i
][j
], builtApply
);
1480 Debug("parser-sygus") << "builtTerm " << builtTerm
<< std::endl
;
1481 Expr eassertion
= getExprManager()->mkExpr(evalApply
.getType().isBoolean() ? kind::IFF
: kind::EQUAL
, evalApply
, builtTerm
);
1482 Expr epattern
= getExprManager()->mkExpr(kind::INST_PATTERN
, evalApply
);
1483 epattern
= getExprManager()->mkExpr(kind::INST_PATTERN_LIST
, epattern
);
1484 eassertion
= getExprManager()->mkExpr(kind::FORALL
, nbvl
, eassertion
, epattern
);
1485 assertions
.push_back( eassertion
);
1487 assertion
= assertions
.size()==1 ? assertions
[0] : getExprManager()->mkExpr( kind::AND
, assertions
);
1488 Debug("parser-sygus") << "...(linearized) assertion is: " << assertion
<< std::endl
;
1497 const void Smt2::getSygusPrimedVars( std::vector
<Expr
>& vars
, bool isPrimed
) {
1498 for( unsigned i
=0; i
<d_sygusVars
.size(); i
++ ){
1499 Expr v
= d_sygusVars
[i
];
1500 std::map
< Expr
, bool >::iterator it
= d_sygusVarPrimed
.find( v
);
1501 if( it
!=d_sygusVarPrimed
.end() ){
1502 if( it
->second
==isPrimed
){
1503 vars
.push_back( v
);
1506 //should never happen
1511 }/* CVC4::parser namespace */
1512 }/* CVC4 namespace */