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::TRANSPOSE
, "transpose");
228 addOperator(kind::TCLOSURE
, "tclosure");
229 addOperator(kind::JOIN
, "join");
230 addOperator(kind::PRODUCT
, "product");
231 addOperator(kind::SINGLETON
, "singleton");
232 addOperator(kind::INSERT
, "insert");
233 addOperator(kind::CARD
, "card");
236 case THEORY_DATATYPES
:
237 Parser::addOperator(kind::APPLY_CONSTRUCTOR
);
238 Parser::addOperator(kind::APPLY_TESTER
);
239 Parser::addOperator(kind::APPLY_SELECTOR
);
240 Parser::addOperator(kind::APPLY_SELECTOR_TOTAL
);
244 defineType("String", getExprManager()->stringType());
245 defineType("Int", getExprManager()->integerType());
246 addStringOperators();
250 Parser::addOperator(kind::APPLY_UF
);
254 defineType("RoundingMode", getExprManager()->roundingModeType());
255 defineType("Float16", getExprManager()->mkFloatingPointType(5, 11));
256 defineType("Float32", getExprManager()->mkFloatingPointType(8, 24));
257 defineType("Float64", getExprManager()->mkFloatingPointType(11, 53));
258 defineType("Float128", getExprManager()->mkFloatingPointType(15, 113));
259 addFloatingPointOperators();
263 std::stringstream ss
;
264 ss
<< "internal error: unsupported theory " << theory
;
265 throw ParserException(ss
.str());
269 void Smt2::addOperator(Kind kind
, const std::string
& name
) {
270 Debug("parser") << "Smt2::addOperator( " << kind
<< ", " << name
<< " )"
272 Parser::addOperator(kind
);
273 operatorKindMap
[name
] = kind
;
276 Kind
Smt2::getOperatorKind(const std::string
& name
) const {
277 // precondition: isOperatorEnabled(name)
278 return operatorKindMap
.find(name
)->second
;
281 bool Smt2::isOperatorEnabled(const std::string
& name
) const {
282 return operatorKindMap
.find(name
) != operatorKindMap
.end();
285 bool Smt2::isTheoryEnabled(Theory theory
) const {
288 return d_logic
.isTheoryEnabled(theory::THEORY_ARRAY
);
289 case THEORY_BITVECTORS
:
290 return d_logic
.isTheoryEnabled(theory::THEORY_BV
);
293 case THEORY_DATATYPES
:
294 return d_logic
.isTheoryEnabled(theory::THEORY_DATATYPES
);
296 return d_logic
.isTheoryEnabled(theory::THEORY_ARITH
) &&
297 d_logic
.areIntegersUsed() && ( !d_logic
.areRealsUsed() );
299 return d_logic
.isTheoryEnabled(theory::THEORY_ARITH
) &&
300 ( !d_logic
.areIntegersUsed() ) && d_logic
.areRealsUsed();
301 case THEORY_REALS_INTS
:
302 return d_logic
.isTheoryEnabled(theory::THEORY_ARITH
) &&
303 d_logic
.areIntegersUsed() && d_logic
.areRealsUsed();
304 case THEORY_QUANTIFIERS
:
305 return d_logic
.isQuantified();
307 return d_logic
.isTheoryEnabled(theory::THEORY_SETS
);
309 return d_logic
.isTheoryEnabled(theory::THEORY_STRINGS
);
311 return d_logic
.isTheoryEnabled(theory::THEORY_UF
);
313 return d_logic
.isTheoryEnabled(theory::THEORY_FP
);
315 std::stringstream ss
;
316 ss
<< "internal error: unsupported theory " << theory
;
317 throw ParserException(ss
.str());
321 bool Smt2::logicIsSet() {
327 d_logic
= LogicInfo();
328 operatorKindMap
.clear();
329 d_lastNamedTerm
= std::pair
<Expr
, std::string
>();
330 d_unsatCoreNames
= std::stack
< std::map
<Expr
, std::string
> >();
331 this->Parser::reset();
333 d_unsatCoreNames
.push(std::map
<Expr
, std::string
>());
334 if( !strictModeEnabled() ) {
335 addTheory(Smt2::THEORY_CORE
);
339 void Smt2::resetAssertions() {
340 this->Parser::reset();
343 void Smt2::setLogic(std::string name
) {
345 if(name
== "Arrays") {
347 } else if(name
== "Reals") {
349 } else if(name
== "LIA") {
351 } else if(name
== "LRA") {
353 } else if(name
== "LIRA") {
355 } else if(name
== "BV") {
357 } else if(name
== "ALL_SUPPORTED") {
360 std::stringstream ss
;
361 ss
<< "Unknown SyGuS background logic `" << name
<< "'";
362 parseError(ss
.str());
367 if(logicIsForced()) {
368 d_logic
= getForcedLogic();
373 // Core theory belongs to every logic
374 addTheory(THEORY_CORE
);
376 if(d_logic
.isTheoryEnabled(theory::THEORY_UF
)) {
377 addTheory(THEORY_UF
);
380 if(d_logic
.isTheoryEnabled(theory::THEORY_ARITH
)) {
381 if(d_logic
.areIntegersUsed()) {
382 if(d_logic
.areRealsUsed()) {
383 addTheory(THEORY_REALS_INTS
);
385 addTheory(THEORY_INTS
);
387 } else if(d_logic
.areRealsUsed()) {
388 addTheory(THEORY_REALS
);
392 if(d_logic
.isTheoryEnabled(theory::THEORY_ARRAY
)) {
393 addTheory(THEORY_ARRAYS
);
396 if(d_logic
.isTheoryEnabled(theory::THEORY_BV
)) {
397 addTheory(THEORY_BITVECTORS
);
400 if(d_logic
.isTheoryEnabled(theory::THEORY_DATATYPES
)) {
401 addTheory(THEORY_DATATYPES
);
404 if(d_logic
.isTheoryEnabled(theory::THEORY_SETS
)) {
405 addTheory(THEORY_SETS
);
408 if(d_logic
.isTheoryEnabled(theory::THEORY_STRINGS
)) {
409 addTheory(THEORY_STRINGS
);
412 if(d_logic
.isQuantified()) {
413 addTheory(THEORY_QUANTIFIERS
);
416 if (d_logic
.isTheoryEnabled(theory::THEORY_FP
)) {
417 addTheory(THEORY_FP
);
420 }/* Smt2::setLogic() */
422 void Smt2::setInfo(const std::string
& flag
, const SExpr
& sexpr
) {
426 void Smt2::setOption(const std::string
& flag
, const SExpr
& sexpr
) {
430 void Smt2::checkThatLogicIsSet() {
431 if( ! logicIsSet() ) {
432 if(strictModeEnabled()) {
433 parseError("set-logic must appear before this point.");
438 warning("No set-logic command was given before this point.");
439 warning("CVC4 will assume the non-standard ALL_SUPPORTED logic.");
440 warning("Consider setting a stricter logic for (likely) better performance.");
441 warning("To suppress this warning in the future use (set-logic ALL_SUPPORTED).");
443 setLogic("ALL_SUPPORTED");
446 Command
* c
= new SetBenchmarkLogicCommand("ALL_SUPPORTED");
453 /* The include are managed in the lexer but called in the parser */
454 // Inspired by http://www.antlr3.org/api/C/interop.html
456 static bool newInputStream(const std::string
& filename
, pANTLR3_LEXER lexer
) {
457 Debug("parser") << "Including " << filename
<< std::endl
;
458 // Create a new input stream and take advantage of built in stream stacking
459 // in C target runtime.
461 pANTLR3_INPUT_STREAM in
;
462 #ifdef CVC4_ANTLR3_OLD_INPUT_STREAM
463 in
= antlr3AsciiFileStreamNew((pANTLR3_UINT8
) filename
.c_str());
464 #else /* CVC4_ANTLR3_OLD_INPUT_STREAM */
465 in
= antlr3FileStreamNew((pANTLR3_UINT8
) filename
.c_str(), ANTLR3_ENC_8BIT
);
466 #endif /* CVC4_ANTLR3_OLD_INPUT_STREAM */
468 Debug("parser") << "Can't open " << filename
<< std::endl
;
471 // Same thing as the predefined PUSHSTREAM(in);
472 lexer
->pushCharStream(lexer
, in
);
474 //lexer->rec->state->tokenStartCharIndex = -10;
475 //lexer->emit(lexer);
477 // Note that the input stream is not closed when it EOFs, I don't bother
478 // to do it here, but it is up to you to track streams created like this
479 // and destroy them when the whole parse session is complete. Remember that you
480 // don't want to do this until all tokens have been manipulated all the way through
481 // your tree parsers etc as the token does not store the text it just refers
482 // back to the input stream and trying to get the text for it will abort if you
483 // close the input stream too early.
485 //TODO what said before
489 void Smt2::includeFile(const std::string
& filename
) {
490 // security for online version
491 if(!canIncludeFile()) {
492 parseError("include-file feature was disabled for this run.");
496 AntlrInput
* ai
= static_cast<AntlrInput
*>(getInput());
497 pANTLR3_LEXER lexer
= ai
->getAntlr3Lexer();
498 // get the name of the current stream "Does it work inside an include?"
499 const std::string inputName
= ai
->getInputStreamName();
501 // Find the directory of the current input file
503 size_t pos
= inputName
.rfind('/');
504 if(pos
!= std::string::npos
) {
505 path
= std::string(inputName
, 0, pos
+ 1);
507 path
.append(filename
);
508 if(!newInputStream(path
, lexer
)) {
509 parseError("Couldn't open include file `" + path
+ "'");
513 Expr
Smt2::mkSygusVar(const std::string
& name
, const Type
& type
, bool isPrimed
) {
514 Expr e
= mkBoundVar(name
, type
);
515 d_sygusVars
.push_back(e
);
516 d_sygusVarPrimed
[e
] = false;
518 std::stringstream ss
;
520 Expr ep
= mkBoundVar(ss
.str(), type
);
521 d_sygusVars
.push_back(ep
);
522 d_sygusVarPrimed
[ep
] = true;
527 void collectSygusGrammarTypesFor( Type range
, std::vector
< Type
>& types
, std::map
< Type
, std::vector
< DatatypeConstructorArg
> >& sels
){
528 if( !range
.isBoolean() ){
529 if( std::find( types
.begin(), types
.end(), range
)==types
.end() ){
530 Debug("parser-sygus") << "...will make grammar for " << range
<< std::endl
;
531 types
.push_back( range
);
532 if( range
.isDatatype() ){
533 const Datatype
& dt
= ((DatatypeType
)range
).getDatatype();
534 for( unsigned i
=0; i
<dt
.getNumConstructors(); i
++ ){
535 for( unsigned j
=0; j
<dt
[i
].getNumArgs(); j
++ ){
536 Type crange
= ((SelectorType
)dt
[i
][j
].getType()).getRangeType();
537 sels
[crange
].push_back( dt
[i
][j
] );
538 collectSygusGrammarTypesFor( crange
, types
, sels
);
546 void Smt2::mkSygusDefaultGrammar( const Type
& range
, Expr
& bvl
, const std::string
& fun
, std::vector
<CVC4::Datatype
>& datatypes
,
547 std::vector
<Type
>& sorts
, std::vector
< std::vector
<Expr
> >& ops
, std::vector
<Expr
> sygus_vars
, int& startIndex
) {
549 //if( !range.isBoolean() && !range.isInteger() && !range.isBitVector() && !range.isDatatype() ){
550 // parseError("No default grammar for type.");
553 Debug("parser-sygus") << "Construct default grammar for " << fun
<< " " << range
<< std::endl
;
554 std::map
< CVC4::Type
, CVC4::Type
> sygus_to_builtin
;
556 std::vector
< Type
> types
;
557 std::map
< Type
, std::vector
< DatatypeConstructorArg
> > sels
;
558 //types for each of the variables
559 for( unsigned i
=0; i
<sygus_vars
.size(); i
++ ){
560 collectSygusGrammarTypesFor( sygus_vars
[i
].getType(), types
, sels
);
562 //types connected to range
563 collectSygusGrammarTypesFor( range
, types
, sels
);
565 //name of boolean sort
566 std::stringstream ssb
;
567 ssb
<< fun
<< "_Bool";
568 std::string dbname
= ssb
.str();
569 Type unres_bt
= mkUnresolvedType(ssb
.str());
571 std::vector
< Type
> unres_types
;
572 std::map
< Type
, Type
> type_to_unres
;
573 for( unsigned i
=0; i
<types
.size(); i
++ ){
574 std::stringstream ss
;
575 ss
<< fun
<< "_" << types
[i
];
576 std::string dname
= ss
.str();
577 datatypes
.push_back(Datatype(dname
));
578 ops
.push_back(std::vector
<Expr
>());
579 //make unresolved type
580 Type unres_t
= mkUnresolvedType(dname
);
581 unres_types
.push_back(unres_t
);
582 type_to_unres
[types
[i
]] = unres_t
;
583 sygus_to_builtin
[unres_t
] = types
[i
];
585 for( unsigned i
=0; i
<types
.size(); i
++ ){
586 Debug("parser-sygus") << "Make grammar for " << types
[i
] << " " << unres_types
[i
] << std::endl
;
587 std::vector
<std::string
> cnames
;
588 std::vector
<std::vector
<CVC4::Type
> > cargs
;
589 std::vector
<std::string
> unresolved_gterm_sym
;
590 Type unres_t
= unres_types
[i
];
592 for( unsigned j
=0; j
<sygus_vars
.size(); j
++ ){
593 if( sygus_vars
[j
].getType()==types
[i
] ){
594 std::stringstream ss
;
596 Debug("parser-sygus") << "...add for variable " << ss
.str() << std::endl
;
597 ops
[i
].push_back( sygus_vars
[j
] );
598 cnames
.push_back( ss
.str() );
599 cargs
.push_back( std::vector
< CVC4::Type
>() );
603 std::vector
< Expr
> consts
;
604 mkSygusConstantsForType( types
[i
], consts
);
605 for( unsigned j
=0; j
<consts
.size(); j
++ ){
606 std::stringstream ss
;
608 Debug("parser-sygus") << "...add for constant " << ss
.str() << std::endl
;
609 ops
[i
].push_back( consts
[j
] );
610 cnames
.push_back( ss
.str() );
611 cargs
.push_back( std::vector
< CVC4::Type
>() );
614 CVC4::Kind k
= kind::ITE
;
615 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
616 ops
[i
].push_back(getExprManager()->operatorOf(k
));
617 cnames
.push_back( kind::kindToString(k
) );
618 cargs
.push_back( std::vector
< CVC4::Type
>() );
619 cargs
.back().push_back(unres_bt
);
620 cargs
.back().push_back(unres_t
);
621 cargs
.back().push_back(unres_t
);
623 if( types
[i
].isInteger() ){
624 for( unsigned j
=0; j
<2; j
++ ){
625 CVC4::Kind k
= j
==0 ? kind::PLUS
: kind::MINUS
;
626 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
627 ops
[i
].push_back(getExprManager()->operatorOf(k
));
628 cnames
.push_back(kind::kindToString(k
));
629 cargs
.push_back( std::vector
< CVC4::Type
>() );
630 cargs
.back().push_back(unres_t
);
631 cargs
.back().push_back(unres_t
);
633 }else if( types
[i
].isDatatype() ){
634 Debug("parser-sygus") << "...add for constructors" << std::endl
;
635 const Datatype
& dt
= ((DatatypeType
)types
[i
]).getDatatype();
636 for( unsigned k
=0; k
<dt
.getNumConstructors(); k
++ ){
637 Debug("parser-sygus") << "...for " << dt
[k
].getName() << std::endl
;
638 ops
[i
].push_back( dt
[k
].getConstructor() );
639 cnames
.push_back( dt
[k
].getName() );
640 cargs
.push_back( std::vector
< CVC4::Type
>() );
641 for( unsigned j
=0; j
<dt
[k
].getNumArgs(); j
++ ){
642 Type crange
= ((SelectorType
)dt
[k
][j
].getType()).getRangeType();
643 //Assert( type_to_unres.find(crange)!=type_to_unres.end() );
644 cargs
.back().push_back( type_to_unres
[crange
] );
648 std::stringstream sserr
;
649 sserr
<< "No implementation for default Sygus grammar of type " << types
[i
] << std::endl
;
650 warning(sserr
.str());
652 //add for all selectors to this type
653 if( !sels
[types
[i
]].empty() ){
654 Debug("parser-sygus") << "...add for selectors" << std::endl
;
655 for( unsigned j
=0; j
<sels
[types
[i
]].size(); j
++ ){
656 Debug("parser-sygus") << "...for " << sels
[types
[i
]][j
].getName() << std::endl
;
657 Type arg_type
= ((SelectorType
)sels
[types
[i
]][j
].getType()).getDomain();
658 ops
[i
].push_back( sels
[types
[i
]][j
].getSelector() );
659 cnames
.push_back( sels
[types
[i
]][j
].getName() );
660 cargs
.push_back( std::vector
< CVC4::Type
>() );
661 //Assert( type_to_unres.find(arg_type)!=type_to_unres.end() );
662 cargs
.back().push_back( type_to_unres
[arg_type
] );
665 Debug("parser-sygus") << "...make datatype " << datatypes
.back() << std::endl
;
666 datatypes
[i
].setSygus( types
[i
], bvl
, true, true );
667 mkSygusDatatype( datatypes
[i
], ops
[i
], cnames
, cargs
, unresolved_gterm_sym
, sygus_to_builtin
);
668 sorts
.push_back( types
[i
] );
669 //set start index if applicable
670 if( types
[i
]==range
){
676 Type btype
= getExprManager()->booleanType();
677 datatypes
.push_back(Datatype(dbname
));
678 ops
.push_back(std::vector
<Expr
>());
679 std::vector
<std::string
> cnames
;
680 std::vector
<std::vector
<CVC4::Type
> > cargs
;
681 std::vector
<std::string
> unresolved_gterm_sym
;
682 Debug("parser-sygus") << "Make grammar for " << btype
<< " " << datatypes
.back() << std::endl
;
684 for( unsigned i
=0; i
<sygus_vars
.size(); i
++ ){
685 if( sygus_vars
[i
].getType().isBoolean() ){
686 std::stringstream ss
;
688 Debug("parser-sygus") << "...add for variable " << ss
.str() << std::endl
;
689 ops
.back().push_back( sygus_vars
[i
] );
690 cnames
.push_back( ss
.str() );
691 cargs
.push_back( std::vector
< CVC4::Type
>() );
694 //add constants if no variables and no connected types
695 if( ops
.back().empty() && types
.empty() ){
696 std::vector
< Expr
> consts
;
697 mkSygusConstantsForType( btype
, consts
);
698 for( unsigned j
=0; j
<consts
.size(); j
++ ){
699 std::stringstream ss
;
701 Debug("parser-sygus") << "...add for constant " << ss
.str() << std::endl
;
702 ops
.back().push_back( consts
[j
] );
703 cnames
.push_back( ss
.str() );
704 cargs
.push_back( std::vector
< CVC4::Type
>() );
708 for( unsigned i
=0; i
<3; i
++ ){
709 CVC4::Kind k
= i
==0 ? kind::NOT
: ( i
==1 ? kind::AND
: kind::OR
);
710 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
711 ops
.back().push_back(getExprManager()->operatorOf(k
));
712 cnames
.push_back(kind::kindToString(k
));
713 cargs
.push_back( std::vector
< CVC4::Type
>() );
715 cargs
.back().push_back(unres_bt
);
716 }else if( k
==kind::AND
|| k
==kind::OR
){
717 cargs
.back().push_back(unres_bt
);
718 cargs
.back().push_back(unres_bt
);
721 //add predicates for types
722 for( unsigned i
=0; i
<types
.size(); i
++ ){
723 Debug("parser-sygus") << "...add predicates for " << types
[i
] << std::endl
;
724 //add equality per type
725 CVC4::Kind k
= kind::EQUAL
;
726 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
727 ops
.back().push_back(getExprManager()->operatorOf(k
));
728 std::stringstream ss
;
729 ss
<< kind::kindToString(k
) << "_" << types
[i
];
730 cnames
.push_back(ss
.str());
731 cargs
.push_back( std::vector
< CVC4::Type
>() );
732 cargs
.back().push_back(unres_types
[i
]);
733 cargs
.back().push_back(unres_types
[i
]);
734 //type specific predicates
735 if( types
[i
].isInteger() ){
736 CVC4::Kind k
= kind::LEQ
;
737 Debug("parser-sygus") << "...add for " << k
<< std::endl
;
738 ops
.back().push_back(getExprManager()->operatorOf(k
));
739 cnames
.push_back(kind::kindToString(k
));
740 cargs
.push_back( std::vector
< CVC4::Type
>() );
741 cargs
.back().push_back(unres_types
[i
]);
742 cargs
.back().push_back(unres_types
[i
]);
743 }else if( types
[i
].isDatatype() ){
745 Debug("parser-sygus") << "...add for testers" << std::endl
;
746 const Datatype
& dt
= ((DatatypeType
)types
[i
]).getDatatype();
747 for( unsigned k
=0; k
<dt
.getNumConstructors(); k
++ ){
748 Debug("parser-sygus") << "...for " << dt
[k
].getTesterName() << std::endl
;
749 ops
.back().push_back(dt
[k
].getTester());
750 cnames
.push_back(dt
[k
].getTesterName());
751 cargs
.push_back( std::vector
< CVC4::Type
>() );
752 cargs
.back().push_back(unres_types
[i
]);
757 startIndex
= sorts
.size();
759 Debug("parser-sygus") << "...make datatype " << datatypes
.back() << std::endl
;
760 datatypes
.back().setSygus( btype
, bvl
, true, true );
761 mkSygusDatatype( datatypes
.back(), ops
.back(), cnames
, cargs
, unresolved_gterm_sym
, sygus_to_builtin
);
762 sorts
.push_back( btype
);
764 Debug("parser-sygus") << "...finished make default grammar for " << fun
<< " " << range
<< std::endl
;
767 void Smt2::mkSygusConstantsForType( const Type
& type
, std::vector
<CVC4::Expr
>& ops
) {
768 if( type
.isInteger() ){
769 ops
.push_back(getExprManager()->mkConst(Rational(0)));
770 ops
.push_back(getExprManager()->mkConst(Rational(1)));
771 }else if( type
.isBitVector() ){
772 unsigned sz
= ((BitVectorType
)type
).getSize();
773 BitVector
bval0(sz
, (unsigned int)0);
774 ops
.push_back( getExprManager()->mkConst(bval0
) );
775 BitVector
bval1(sz
, (unsigned int)1);
776 ops
.push_back( getExprManager()->mkConst(bval1
) );
777 }else if( type
.isBoolean() ){
778 ops
.push_back(getExprManager()->mkConst(true));
779 ops
.push_back(getExprManager()->mkConst(false));
784 // 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)
785 // This method may also add new elements pairwise into datatypes/sorts/ops/cnames/cargs in the case of non-flat gterms.
786 void Smt2::processSygusGTerm( CVC4::SygusGTerm
& sgt
, int index
,
787 std::vector
< CVC4::Datatype
>& datatypes
,
788 std::vector
< CVC4::Type
>& sorts
,
789 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
790 std::vector
< std::vector
<std::string
> >& cnames
,
791 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
792 std::vector
< bool >& allow_const
,
793 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
,
794 std::vector
<CVC4::Expr
>& sygus_vars
,
795 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
, std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
,
796 CVC4::Type
& ret
, bool isNested
){
797 if( sgt
.d_gterm_type
==SygusGTerm::gterm_op
|| sgt
.d_gterm_type
==SygusGTerm::gterm_let
){
798 Debug("parser-sygus") << "Add " << sgt
.d_expr
<< " to datatype " << index
<< std::endl
;
800 Kind newKind
= kind::UNDEFINED_KIND
;
801 //convert to UMINUS if one child of MINUS
802 if( sgt
.d_children
.size()==1 && sgt
.d_expr
==getExprManager()->operatorOf(kind::MINUS
) ){
803 oldKind
= kind::MINUS
;
804 newKind
= kind::UMINUS
;
806 //convert to IFF if boolean EQUAL
807 if( sgt
.d_expr
==getExprManager()->operatorOf(kind::EQUAL
) ){
808 Type ctn
= sgt
.d_children
[0].d_type
;
809 std::map
< CVC4::Type
, CVC4::Type
>::iterator it
= sygus_to_builtin
.find( ctn
);
810 if( it
!= sygus_to_builtin
.end() && it
->second
.isBoolean() ){
811 oldKind
= kind::EQUAL
;
815 if( newKind
!=kind::UNDEFINED_KIND
){
816 Expr newExpr
= getExprManager()->operatorOf(newKind
);
817 Debug("parser-sygus") << "Replace " << sgt
.d_expr
<< " with " << newExpr
<< std::endl
;
818 sgt
.d_expr
= newExpr
;
819 std::string oldName
= kind::kindToString(oldKind
);
820 std::string newName
= kind::kindToString(newKind
);
822 if((pos
= sgt
.d_name
.find(oldName
, pos
)) != std::string::npos
){
823 sgt
.d_name
.replace(pos
, oldName
.length(), newName
);
826 ops
[index
].push_back( sgt
.d_expr
);
827 cnames
[index
].push_back( sgt
.d_name
);
828 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
829 for( unsigned i
=0; i
<sgt
.d_children
.size(); i
++ ){
830 std::stringstream ss
;
831 ss
<< datatypes
[index
].getName() << "_" << ops
[index
].size() << "_arg_" << i
;
832 std::string sub_dname
= ss
.str();
833 //add datatype for child
835 pushSygusDatatypeDef( null_type
, sub_dname
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
);
836 int sub_dt_index
= datatypes
.size()-1;
839 processSygusGTerm( sgt
.d_children
[i
], sub_dt_index
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
,
840 sygus_vars
, sygus_to_builtin
, sygus_to_builtin_expr
, sub_ret
, true );
841 //process the nested gterm (either pop the last datatype, or flatten the argument)
842 Type tt
= processSygusNestedGTerm( sub_dt_index
, sub_dname
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
,
843 sygus_to_builtin
, sygus_to_builtin_expr
, sub_ret
);
844 cargs
[index
].back().push_back(tt
);
846 //if let, must create operator
847 if( sgt
.d_gterm_type
==SygusGTerm::gterm_let
){
848 processSygusLetConstructor( sgt
.d_let_vars
, index
, datatypes
, sorts
, ops
, cnames
, cargs
,
849 sygus_vars
, sygus_to_builtin
, sygus_to_builtin_expr
);
851 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_constant
){
852 if( sgt
.getNumChildren()!=0 ){
853 parseError("Bad syntax for Sygus Constant.");
855 std::vector
< Expr
> consts
;
856 mkSygusConstantsForType( sgt
.d_type
, consts
);
857 Debug("parser-sygus") << "...made " << consts
.size() << " constants." << std::endl
;
858 for( unsigned i
=0; i
<consts
.size(); i
++ ){
859 std::stringstream ss
;
861 Debug("parser-sygus") << "...add for constant " << ss
.str() << std::endl
;
862 ops
[index
].push_back( consts
[i
] );
863 cnames
[index
].push_back( ss
.str() );
864 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
866 allow_const
[index
] = true;
867 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_variable
|| sgt
.d_gterm_type
==SygusGTerm::gterm_input_variable
){
868 if( sgt
.getNumChildren()!=0 ){
869 parseError("Bad syntax for Sygus Variable.");
871 Debug("parser-sygus") << "...process " << sygus_vars
.size() << " variables." << std::endl
;
872 for( unsigned i
=0; i
<sygus_vars
.size(); i
++ ){
873 if( sygus_vars
[i
].getType()==sgt
.d_type
){
874 std::stringstream ss
;
876 Debug("parser-sygus") << "...add for variable " << ss
.str() << std::endl
;
877 ops
[index
].push_back( sygus_vars
[i
] );
878 cnames
[index
].push_back( ss
.str() );
879 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
882 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_nested_sort
){
884 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_unresolved
){
886 if( isUnresolvedType(sgt
.d_name
) ){
887 ret
= getSort(sgt
.d_name
);
889 //nested, unresolved symbol...fail
890 std::stringstream ss
;
891 ss
<< "Cannot handle nested unresolved symbol " << sgt
.d_name
<< std::endl
;
892 parseError(ss
.str());
895 //will resolve when adding constructors
896 unresolved_gterm_sym
[index
].push_back(sgt
.d_name
);
898 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_ignore
){
903 bool Smt2::pushSygusDatatypeDef( Type t
, std::string
& dname
,
904 std::vector
< CVC4::Datatype
>& datatypes
,
905 std::vector
< CVC4::Type
>& sorts
,
906 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
907 std::vector
< std::vector
<std::string
> >& cnames
,
908 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
909 std::vector
< bool >& allow_const
,
910 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
){
912 datatypes
.push_back(Datatype(dname
));
913 ops
.push_back(std::vector
<Expr
>());
914 cnames
.push_back(std::vector
<std::string
>());
915 cargs
.push_back(std::vector
<std::vector
<CVC4::Type
> >());
916 allow_const
.push_back(false);
917 unresolved_gterm_sym
.push_back(std::vector
< std::string
>());
921 bool Smt2::popSygusDatatypeDef( std::vector
< CVC4::Datatype
>& datatypes
,
922 std::vector
< CVC4::Type
>& sorts
,
923 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
924 std::vector
< std::vector
<std::string
> >& cnames
,
925 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
926 std::vector
< bool >& allow_const
,
927 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
){
929 datatypes
.pop_back();
933 allow_const
.pop_back();
934 unresolved_gterm_sym
.pop_back();
938 Type
Smt2::processSygusNestedGTerm( int sub_dt_index
, std::string
& sub_dname
, std::vector
< CVC4::Datatype
>& datatypes
,
939 std::vector
< CVC4::Type
>& sorts
,
940 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
941 std::vector
< std::vector
<std::string
> >& cnames
,
942 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
943 std::vector
< bool >& allow_const
,
944 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
,
945 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
,
946 std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
, Type sub_ret
) {
948 Debug("parser-sygus") << "Argument is ";
950 //then, it is the datatype we constructed, which should have a single constructor
951 t
= mkUnresolvedType(sub_dname
);
952 Debug("parser-sygus") << "inline flattening of (auxiliary, local) datatype " << t
<< std::endl
;
953 Debug("parser-sygus") << ": to compute type, construct ground term witnessing the grammar, #cons=" << cargs
[sub_dt_index
].size() << std::endl
;
954 if( cargs
[sub_dt_index
].empty() ){
955 parseError(std::string("Internal error : datatype for nested gterm does not have a constructor."));
957 Expr sop
= ops
[sub_dt_index
][0];
959 if( sop
.getKind() != kind::BUILTIN
&& ( sop
.isConst() || cargs
[sub_dt_index
][0].empty() ) ){
960 curr_t
= sop
.getType();
961 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
;
962 sygus_to_builtin_expr
[t
] = sop
;
963 //store that term sop has dedicated sygus type t
964 if( d_sygus_bound_var_type
.find( sop
)==d_sygus_bound_var_type
.end() ){
965 d_sygus_bound_var_type
[sop
] = t
;
968 std::vector
< Expr
> children
;
969 if( sop
.getKind() != kind::BUILTIN
){
970 children
.push_back( sop
);
972 for( unsigned i
=0; i
<cargs
[sub_dt_index
][0].size(); i
++ ){
973 std::map
< CVC4::Type
, CVC4::Expr
>::iterator it
= sygus_to_builtin_expr
.find( cargs
[sub_dt_index
][0][i
] );
974 if( it
==sygus_to_builtin_expr
.end() ){
975 if( sygus_to_builtin
.find( cargs
[sub_dt_index
][0][i
] )==sygus_to_builtin
.end() ){
976 std::stringstream ss
;
977 ss
<< "Missing builtin type for type " << cargs
[sub_dt_index
][0][i
] << "!" << std::endl
;
978 ss
<< "Builtin types are currently : " << std::endl
;
979 for( std::map
< CVC4::Type
, CVC4::Type
>::iterator itb
= sygus_to_builtin
.begin(); itb
!= sygus_to_builtin
.end(); ++itb
){
980 ss
<< " " << itb
->first
<< " -> " << itb
->second
<< std::endl
;
982 parseError(ss
.str());
984 Type bt
= sygus_to_builtin
[cargs
[sub_dt_index
][0][i
]];
985 Debug("parser-sygus") << ": child " << i
<< " introduce type elem for " << cargs
[sub_dt_index
][0][i
] << " " << bt
<< std::endl
;
986 std::stringstream ss
;
987 ss
<< t
<< "_x_" << i
;
988 Expr bv
= mkBoundVar(ss
.str(), bt
);
989 children
.push_back( bv
);
990 d_sygus_bound_var_type
[bv
] = cargs
[sub_dt_index
][0][i
];
992 Debug("parser-sygus") << ": child " << i
<< " existing sygus to builtin expr : " << it
->second
<< std::endl
;
993 children
.push_back( it
->second
);
996 Kind sk
= sop
.getKind() != kind::BUILTIN
? kind::APPLY
: getExprManager()->operatorToKind(sop
);
997 Debug("parser-sygus") << ": operator " << sop
<< " with " << sop
.getKind() << " " << sk
<< std::endl
;
998 Expr e
= getExprManager()->mkExpr( sk
, children
);
999 Debug("parser-sygus") << ": constructed " << e
<< ", which has type " << e
.getType() << std::endl
;
1000 curr_t
= e
.getType();
1001 sygus_to_builtin_expr
[t
] = e
;
1003 sorts
[sub_dt_index
] = curr_t
;
1004 sygus_to_builtin
[t
] = curr_t
;
1006 Debug("parser-sygus") << "simple argument " << t
<< std::endl
;
1007 Debug("parser-sygus") << "...removing " << datatypes
.back().getName() << std::endl
;
1008 //otherwise, datatype was unecessary
1009 //pop argument datatype definition
1010 popSygusDatatypeDef( datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
);
1015 void Smt2::processSygusLetConstructor( std::vector
< CVC4::Expr
>& let_vars
,
1017 std::vector
< CVC4::Datatype
>& datatypes
,
1018 std::vector
< CVC4::Type
>& sorts
,
1019 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
1020 std::vector
< std::vector
<std::string
> >& cnames
,
1021 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
1022 std::vector
<CVC4::Expr
>& sygus_vars
,
1023 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
,
1024 std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
) {
1025 std::vector
< CVC4::Expr
> let_define_args
;
1027 int dindex
= cargs
[index
].size()-1;
1028 Debug("parser-sygus") << "Process let constructor for datatype " << datatypes
[index
].getName() << ", #subtypes = " << cargs
[index
][dindex
].size() << std::endl
;
1029 for( unsigned i
=0; i
<cargs
[index
][dindex
].size(); i
++ ){
1030 Debug("parser-sygus") << " " << i
<< " : " << cargs
[index
][dindex
][i
] << std::endl
;
1031 if( i
+1==cargs
[index
][dindex
].size() ){
1032 std::map
< CVC4::Type
, CVC4::Expr
>::iterator it
= sygus_to_builtin_expr
.find( cargs
[index
][dindex
][i
] );
1033 if( it
!=sygus_to_builtin_expr
.end() ){
1034 let_body
= it
->second
;
1036 std::stringstream ss
;
1037 ss
<< datatypes
[index
].getName() << "_body";
1038 let_body
= mkBoundVar(ss
.str(), sygus_to_builtin
[cargs
[index
][dindex
][i
]]);
1039 d_sygus_bound_var_type
[let_body
] = cargs
[index
][dindex
][i
];
1043 Debug("parser-sygus") << std::endl
;
1044 Debug("parser-sygus") << "Body is " << let_body
<< std::endl
;
1045 Debug("parser-sygus") << "# let vars = " << let_vars
.size() << std::endl
;
1046 for( unsigned i
=0; i
<let_vars
.size(); i
++ ){
1047 Debug("parser-sygus") << " let var " << i
<< " : " << let_vars
[i
] << " " << let_vars
[i
].getType() << std::endl
;
1048 let_define_args
.push_back( let_vars
[i
] );
1051 Debug("parser-sygus") << "index = " << index << ", start index = " << start_index << ", #Current datatypes = " << datatypes.size() << std::endl;
1052 for( unsigned i=start_index; i<datatypes.size(); i++ ){
1053 Debug("parser-sygus") << " datatype " << i << " : " << datatypes[i].getName() << ", #cons = " << cargs[i].size() << std::endl;
1054 if( !cargs[i].empty() ){
1055 Debug("parser-sygus") << " operator 0 is " << ops[i][0] << std::endl;
1056 Debug("parser-sygus") << " cons 0 has " << cargs[i][0].size() << " sub fields." << std::endl;
1057 for( unsigned j=0; j<cargs[i][0].size(); j++ ){
1058 Type bt = sygus_to_builtin[cargs[i][0][j]];
1059 Debug("parser-sygus") << " cons 0, selector " << j << " : " << cargs[i][0][j] << " " << bt << std::endl;
1064 //last argument is the return, pop
1065 cargs
[index
][dindex
].pop_back();
1066 collectSygusLetArgs( let_body
, cargs
[index
][dindex
], let_define_args
);
1068 Debug("parser-sygus") << "Make define-fun with " << cargs
[index
][dindex
].size() << " arguments..." << std::endl
;
1069 std::vector
<CVC4::Type
> fsorts
;
1070 for( unsigned i
=0; i
<cargs
[index
][dindex
].size(); i
++ ){
1071 Debug("parser-sygus") << " " << i
<< " : " << let_define_args
[i
] << " " << let_define_args
[i
].getType() << " " << cargs
[index
][dindex
][i
] << std::endl
;
1072 fsorts
.push_back(let_define_args
[i
].getType());
1075 Type ft
= getExprManager()->mkFunctionType(fsorts
, let_body
.getType());
1076 std::stringstream ss
;
1077 ss
<< datatypes
[index
].getName() << "_let";
1078 Expr let_func
= mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
1079 d_sygus_defined_funs
.push_back( let_func
);
1080 preemptCommand( new DefineFunctionCommand(ss
.str(), let_func
, let_define_args
, let_body
) );
1082 ops
[index
].pop_back();
1083 ops
[index
].push_back( let_func
);
1084 cnames
[index
].pop_back();
1085 cnames
[index
].push_back(ss
.str());
1087 //mark function as let constructor
1088 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() );
1089 d_sygus_let_func_to_body
[let_func
] = let_body
;
1090 d_sygus_let_func_to_num_input_vars
[let_func
] = let_vars
.size();
1094 void Smt2::collectSygusLetArgs( CVC4::Expr e
, std::vector
< CVC4::Type
>& sygusArgs
, std::vector
< CVC4::Expr
>& builtinArgs
) {
1095 if( e
.getKind()==kind::BOUND_VARIABLE
){
1096 if( std::find( builtinArgs
.begin(), builtinArgs
.end(), e
)==builtinArgs
.end() ){
1097 builtinArgs
.push_back( e
);
1098 sygusArgs
.push_back( d_sygus_bound_var_type
[e
] );
1099 if( d_sygus_bound_var_type
[e
].isNull() ){
1100 std::stringstream ss
;
1101 ss
<< "While constructing body of let gterm, can't map " << e
<< " to sygus type." << std::endl
;
1102 parseError(ss
.str());
1106 for( unsigned i
=0; i
<e
.getNumChildren(); i
++ ){
1107 collectSygusLetArgs( e
[i
], sygusArgs
, builtinArgs
);
1112 void Smt2::setSygusStartIndex( std::string
& fun
, int startIndex
,
1113 std::vector
< CVC4::Datatype
>& datatypes
,
1114 std::vector
< CVC4::Type
>& sorts
,
1115 std::vector
< std::vector
<CVC4::Expr
> >& ops
) {
1117 CVC4::Datatype tmp_dt
= datatypes
[0];
1118 Type tmp_sort
= sorts
[0];
1119 std::vector
< Expr
> tmp_ops
;
1120 tmp_ops
.insert( tmp_ops
.end(), ops
[0].begin(), ops
[0].end() );
1121 datatypes
[0] = datatypes
[startIndex
];
1122 sorts
[0] = sorts
[startIndex
];
1124 ops
[0].insert( ops
[0].end(), ops
[startIndex
].begin(), ops
[startIndex
].end() );
1125 datatypes
[startIndex
] = tmp_dt
;
1126 sorts
[startIndex
] = tmp_sort
;
1127 ops
[startIndex
].clear();
1128 ops
[startIndex
].insert( ops
[startIndex
].begin(), tmp_ops
.begin(), tmp_ops
.end() );
1129 }else if( startIndex
<0 ){
1130 std::stringstream ss
;
1131 ss
<< "warning: no symbol named Start for synth-fun " << fun
<< std::endl
;
1136 void Smt2::defineSygusFuns() {
1137 // only define each one once
1138 while(d_nextSygusFun
< d_sygusFuns
.size()) {
1139 std::pair
<std::string
, Expr
> p
= d_sygusFuns
[d_nextSygusFun
];
1140 std::string fun
= p
.first
;
1141 Debug("parser-sygus") << "Sygus : define fun " << fun
<< std::endl
;
1142 Expr eval
= p
.second
;
1143 FunctionType evalType
= eval
.getType();
1144 std::vector
<Type
> argTypes
= evalType
.getArgTypes();
1145 Type rangeType
= evalType
.getRangeType();
1146 Debug("parser-sygus") << "...eval type : " << evalType
<< ", #args=" << argTypes
.size() << std::endl
;
1148 // first make the function type
1149 std::vector
<Expr
> sygusVars
;
1150 std::vector
<Type
> funType
;
1151 for(size_t j
= 1; j
< argTypes
.size(); ++j
) {
1152 funType
.push_back(argTypes
[j
]);
1153 std::stringstream ss
;
1154 ss
<< fun
<< "_v_" << j
;
1155 sygusVars
.push_back(getExprManager()->mkBoundVar(ss
.str(), argTypes
[j
]));
1158 if( !funType
.empty() ){
1159 funt
= getExprManager()->mkFunctionType(funType
, rangeType
);
1160 Debug("parser-sygus") << "...eval function type : " << funt
<< std::endl
;
1162 // copy the bound vars
1164 std::vector<Expr> sygusVars;
1165 //std::vector<Type> types;
1166 for(size_t i = 0; i < d_sygusVars.size(); ++i) {
1167 std::stringstream ss;
1168 ss << d_sygusVars[i];
1169 Type type = d_sygusVars[i].getType();
1170 sygusVars.push_back(getExprManager()->mkBoundVar(ss.str(), type));
1171 //types.push_back(type);
1173 Debug("parser-sygus") << "...made vars, #vars=" << sygusVars.size() << std::endl;
1176 //Type t = getExprManager()->mkFunctionType(types, rangeType);
1177 //Debug("parser-sygus") << "...function type : " << t << std::endl;
1181 Expr lambda
= mkFunction(fun
, funt
, ExprManager::VAR_FLAG_DEFINED
);
1182 Debug("parser-sygus") << "...made function : " << lambda
<< std::endl
;
1183 std::vector
<Expr
> applyv
;
1184 Expr funbv
= getExprManager()->mkBoundVar(std::string("f") + fun
, argTypes
[0]);
1185 d_sygusFunSymbols
.push_back(funbv
);
1186 applyv
.push_back(eval
);
1187 applyv
.push_back(funbv
);
1188 for(size_t i
= 0; i
< sygusVars
.size(); ++i
) {
1189 applyv
.push_back(sygusVars
[i
]);
1191 Expr apply
= getExprManager()->mkExpr(kind::APPLY_UF
, applyv
);
1192 Debug("parser-sygus") << "...made apply " << apply
<< std::endl
;
1193 Debug("parser-sygus") << "--> Define " << fun
<< " as " << lambda
<< " " << apply
<< std::endl
;
1194 Command
* cmd
= new DefineFunctionCommand(fun
, lambda
, sygusVars
, apply
);
1195 preemptCommand(cmd
);
1201 void Smt2::mkSygusDatatype( CVC4::Datatype
& dt
, std::vector
<CVC4::Expr
>& ops
,
1202 std::vector
<std::string
>& cnames
, std::vector
< std::vector
< CVC4::Type
> >& cargs
,
1203 std::vector
<std::string
>& unresolved_gterm_sym
,
1204 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
) {
1205 Debug("parser-sygus") << "Making sygus datatype " << dt
.getName() << std::endl
;
1206 Debug("parser-sygus") << " add constructors..." << std::endl
;
1207 for( int i
=0; i
<(int)cnames
.size(); i
++ ){
1208 bool is_dup
= false;
1209 bool is_dup_op
= false;
1211 std::vector
< Expr
> let_args
;
1212 unsigned let_num_input_args
= 0;
1213 for( int j
=0; j
<i
; j
++ ){
1214 if( ops
[i
]==ops
[j
] ){
1216 if( cargs
[i
].size()==cargs
[j
].size() ){
1218 for( unsigned k
=0; k
<cargs
[i
].size(); k
++ ){
1219 if( cargs
[i
][k
]!=cargs
[j
][k
] ){
1231 Debug("parser-sygus") << "--> Duplicate gterm : " << ops
[i
] << " at " << i
<< std::endl
;
1232 ops
.erase( ops
.begin() + i
, ops
.begin() + i
+ 1 );
1233 cnames
.erase( cnames
.begin() + i
, cnames
.begin() + i
+ 1 );
1234 cargs
.erase( cargs
.begin() + i
, cargs
.begin() + i
+ 1 );
1236 }else if( is_dup_op
){
1237 Debug("parser-sygus") << "--> Duplicate gterm operator : " << ops
[i
] << " at " << i
<< std::endl
;
1238 //make into define-fun
1239 std::vector
<CVC4::Type
> fsorts
;
1240 for( unsigned j
=0; j
<cargs
[i
].size(); j
++ ){
1241 Type bt
= sygus_to_builtin
[cargs
[i
][j
]];
1242 std::stringstream ss
;
1243 ss
<< dt
.getName() << "_x_" << i
<< "_" << j
;
1244 Expr v
= mkBoundVar(ss
.str(), bt
);
1245 let_args
.push_back( v
);
1246 fsorts
.push_back( bt
);
1247 Debug("parser-sygus") << ": var " << i
<< " " << v
<< " with type " << bt
<< " from " << cargs
[i
][j
] << std::endl
;
1250 std::vector
< Expr
> children
;
1251 if( ops
[i
].getKind() != kind::BUILTIN
){
1252 children
.push_back( ops
[i
] );
1254 children
.insert( children
.end(), let_args
.begin(), let_args
.end() );
1255 Kind sk
= ops
[i
].getKind() != kind::BUILTIN
? kind::APPLY
: getExprManager()->operatorToKind(ops
[i
]);
1256 Debug("parser-sygus") << ": replace " << ops
[i
] << " " << ops
[i
].getKind() << " " << sk
<< std::endl
;
1257 let_body
= getExprManager()->mkExpr( sk
, children
);
1258 Debug("parser-sygus") << ": new body of function is " << let_body
<< std::endl
;
1260 Type ft
= getExprManager()->mkFunctionType(fsorts
, let_body
.getType());
1261 Debug("parser-sygus") << ": function type is " << ft
<< std::endl
;
1262 std::stringstream ss
;
1263 ss
<< dt
.getName() << "_df_" << i
;
1264 //replace operator and name
1265 ops
[i
] = mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
1266 cnames
[i
] = ss
.str();
1267 d_sygus_defined_funs
.push_back( ops
[i
] );
1268 preemptCommand( new DefineFunctionCommand(ss
.str(), ops
[i
], let_args
, let_body
) );
1269 addSygusDatatypeConstructor( dt
, ops
[i
], cnames
[i
], cargs
[i
], let_body
, let_args
, 0 );
1271 std::map
< CVC4::Expr
, CVC4::Expr
>::iterator it
= d_sygus_let_func_to_body
.find( ops
[i
] );
1272 if( it
!=d_sygus_let_func_to_body
.end() ){
1273 let_body
= it
->second
;
1274 let_args
.insert( let_args
.end(), d_sygus_let_func_to_vars
[ops
[i
]].begin(), d_sygus_let_func_to_vars
[ops
[i
]].end() );
1275 let_num_input_args
= d_sygus_let_func_to_num_input_vars
[ops
[i
]];
1277 addSygusDatatypeConstructor( dt
, ops
[i
], cnames
[i
], cargs
[i
], let_body
, let_args
, let_num_input_args
);
1280 Debug("parser-sygus") << " add constructors for unresolved symbols..." << std::endl
;
1281 if( !unresolved_gterm_sym
.empty() ){
1282 std::vector
< Type
> types
;
1283 Debug("parser-sygus") << "...resolve " << unresolved_gterm_sym
.size() << " symbols..." << std::endl
;
1284 for( unsigned i
=0; i
<unresolved_gterm_sym
.size(); i
++ ){
1285 Debug("parser-sygus") << " resolve : " << unresolved_gterm_sym
[i
] << std::endl
;
1286 if( isUnresolvedType(unresolved_gterm_sym
[i
]) ){
1287 Debug("parser-sygus") << " it is an unresolved type." << std::endl
;
1288 Type t
= getSort(unresolved_gterm_sym
[i
]);
1289 if( std::find( types
.begin(), types
.end(), t
)==types
.end() ){
1290 types
.push_back( t
);
1292 Type bt
= dt
.getSygusType();
1293 Debug("parser-sygus") << ": make identity function for " << bt
<< ", argument type " << t
<< std::endl
;
1294 std::stringstream ss
;
1296 Expr let_body
= mkBoundVar(ss
.str(), bt
);
1297 std::vector
< Expr
> let_args
;
1298 let_args
.push_back( let_body
);
1299 //make the identity function
1300 Type ft
= getExprManager()->mkFunctionType(bt
, bt
);
1301 std::stringstream ssid
;
1302 ssid
<< unresolved_gterm_sym
[i
] << "_id";
1303 Expr id_op
= mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
1304 d_sygus_defined_funs
.push_back( id_op
);
1305 preemptCommand( new DefineFunctionCommand(ssid
.str(), id_op
, let_args
, let_body
) );
1306 //make the sygus argument list
1307 std::vector
< Type
> id_carg
;
1308 id_carg
.push_back( t
);
1309 addSygusDatatypeConstructor( dt
, id_op
, unresolved_gterm_sym
[i
], id_carg
, let_body
, let_args
, 0 );
1311 ops
.push_back( id_op
);
1314 Debug("parser-sygus") << " ignore. (likely a free let variable)" << std::endl
;
1321 void Smt2::addSygusDatatypeConstructor( CVC4::Datatype
& dt
, CVC4::Expr op
, std::string
& cname
, std::vector
< CVC4::Type
>& cargs
,
1322 CVC4::Expr
& let_body
, std::vector
< CVC4::Expr
>& let_args
, unsigned let_num_input_args
) {
1323 Debug("parser-sygus") << "--> Add constructor " << cname
<< " to " << dt
.getName() << std::endl
;
1324 if( !let_body
.isNull() ){
1325 Debug("parser-sygus") << " let body = " << let_body
<< ", args = " << let_args
.size() << "," << let_num_input_args
<< std::endl
;
1326 //TODO : remove arguments not occurring in body
1327 //if this is a self identity function, ignore
1328 if( let_args
.size()==0 && let_args
[0]==let_body
){
1329 Debug("parser-sygus") << " identity function " << cargs
[0] << " to " << dt
.getName() << std::endl
;
1333 std::string name
= dt
.getName() + "_" + cname
;
1334 std::string
testerId("is-");
1335 testerId
.append(name
);
1336 checkDeclaration(name
, CHECK_UNDECLARED
, SYM_VARIABLE
);
1337 checkDeclaration(testerId
, CHECK_UNDECLARED
, SYM_VARIABLE
);
1338 CVC4::DatatypeConstructor
c(name
, testerId
);
1339 c
.setSygus( op
, let_body
, let_args
, let_num_input_args
);
1340 for( unsigned j
=0; j
<cargs
.size(); j
++ ){
1341 Debug("parser-sygus-debug") << " arg " << j
<< " : " << cargs
[j
] << std::endl
;
1342 std::stringstream sname
;
1343 sname
<< name
<< "_" << j
;
1344 c
.addArg(sname
.str(), cargs
[j
]);
1346 dt
.addConstructor(c
);
1350 // i is index in datatypes/ops
1351 // j is index is datatype
1352 Expr
Smt2::getSygusAssertion( std::vector
<DatatypeType
>& datatypeTypes
, std::vector
< std::vector
<Expr
> >& ops
,
1353 std::map
<DatatypeType
, Expr
>& evals
, std::vector
<Expr
>& terms
,
1354 Expr eval
, const Datatype
& dt
, size_t i
, size_t j
) {
1355 const DatatypeConstructor
& ctor
= dt
[j
];
1356 Debug("parser-sygus") << "Sygus : process constructor " << j
<< " : " << dt
[j
] << std::endl
;
1357 std::vector
<Expr
> bvs
, extraArgs
;
1358 for(size_t k
= 0; k
< ctor
.getNumArgs(); ++k
) {
1359 std::string vname
= "v_" + ctor
[k
].getName();
1360 Expr bv
= getExprManager()->mkBoundVar(vname
, SelectorType(ctor
[k
].getType()).getRangeType());
1362 extraArgs
.push_back(bv
);
1364 if( !terms
[0].isNull() ){
1365 bvs
.insert(bvs
.end(), terms
[0].begin(), terms
[0].end());
1369 bvl
= getExprManager()->mkExpr(kind::BOUND_VAR_LIST
, bvs
);
1371 Debug("parser-sygus") << "...made bv list " << bvl
<< std::endl
;
1372 std::vector
<Expr
> patv
;
1373 patv
.push_back(eval
);
1374 std::vector
<Expr
> applyv
;
1375 applyv
.push_back(ctor
.getConstructor());
1376 applyv
.insert(applyv
.end(), extraArgs
.begin(), extraArgs
.end());
1377 for(size_t k
= 0; k
< applyv
.size(); ++k
) {
1379 Expr cpatv
= getExprManager()->mkExpr(kind::APPLY_CONSTRUCTOR
, applyv
);
1380 Debug("parser-sygus") << "...made eval ctor apply " << cpatv
<< std::endl
;
1381 patv
.push_back(cpatv
);
1382 if( !terms
[0].isNull() ){
1383 patv
.insert(patv
.end(), terms
[0].begin(), terms
[0].end());
1385 Expr evalApply
= getExprManager()->mkExpr(kind::APPLY_UF
, patv
);
1386 Debug("parser-sygus") << "...made eval apply " << evalApply
<< std::endl
;
1387 std::vector
<Expr
> builtApply
;
1388 for(size_t k
= 0; k
< extraArgs
.size(); ++k
) {
1389 std::vector
<Expr
> patvb
;
1390 patvb
.push_back(evals
[DatatypeType(extraArgs
[k
].getType())]);
1391 patvb
.push_back(extraArgs
[k
]);
1392 if( !terms
[0].isNull() ){
1393 patvb
.insert(patvb
.end(), terms
[0].begin(), terms
[0].end());
1395 Debug("parser-sygus-debug") << "...add to built apply " << evals
[DatatypeType(extraArgs
[k
].getType())] << " " << extraArgs
[k
] << " " << extraArgs
[k
].getType() << std::endl
;
1396 builtApply
.push_back(getExprManager()->mkExpr(kind::APPLY_UF
, patvb
));
1397 Debug("parser-sygus-debug") << "...added " << builtApply
.back() << std::endl
;
1399 for(size_t k
= 0; k
< builtApply
.size(); ++k
) {
1402 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
;
1403 if( ops
[i
][j
].getKind() != kind::BUILTIN
){
1404 Kind ok
= kind::UNDEFINED_KIND
;
1405 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() ){
1408 Type t
= ops
[i
][j
].getType();
1409 if( t
.isConstructor() ){
1410 ok
= kind::APPLY_CONSTRUCTOR
;
1411 }else if( t
.isSelector() ){
1412 ok
= kind::APPLY_SELECTOR
;
1413 }else if( t
.isTester() ){
1414 ok
= kind::APPLY_TESTER
;
1416 ok
= getExprManager()->operatorToKind( ops
[i
][j
] );
1419 Debug("parser-sygus") << "...processed operator kind : " << ok
<< std::endl
;
1420 if( ok
!=kind::UNDEFINED_KIND
){
1421 builtTerm
= getExprManager()->mkExpr(ok
, ops
[i
][j
], builtApply
);
1423 builtTerm
= ops
[i
][j
];
1426 if( !builtApply
.empty() ){
1427 builtTerm
= getExprManager()->mkExpr(ops
[i
][j
], builtApply
);
1429 builtTerm
= ops
[i
][j
];
1432 Debug("parser-sygus") << "...made built term " << builtTerm
<< std::endl
;
1433 Expr assertion
= getExprManager()->mkExpr(evalApply
.getType().isBoolean() ? kind::IFF
: kind::EQUAL
, evalApply
, builtTerm
);
1434 if( !bvl
.isNull() ){
1435 Expr pattern
= getExprManager()->mkExpr(kind::INST_PATTERN
, evalApply
);
1436 pattern
= getExprManager()->mkExpr(kind::INST_PATTERN_LIST
, pattern
);
1437 assertion
= getExprManager()->mkExpr(kind::FORALL
, bvl
, assertion
, pattern
);
1439 Debug("parser-sygus") << "...made assertion " << assertion
<< std::endl
;
1441 //linearize multiplication if possible
1442 if( builtTerm
.getKind()==kind::MULT
){
1443 for(size_t k
= 0; k
< ctor
.getNumArgs(); ++k
) {
1444 Type at
= SelectorType(ctor
[k
].getType()).getRangeType();
1445 if( at
.isDatatype() ){
1446 DatatypeType atd
= (DatatypeType
)SelectorType(ctor
[k
].getType()).getRangeType();
1447 Debug("parser-sygus") << "Argument " << k
<< " " << atd
<< std::endl
;
1448 std::vector
<DatatypeType
>::iterator itd
= std::find( datatypeTypes
.begin(), datatypeTypes
.end(), atd
);
1449 if( itd
!=datatypeTypes
.end() ){
1450 Debug("parser-sygus2") << "Exists in datatypeTypes." << std::endl
;
1451 unsigned index
= itd
-datatypeTypes
.begin();
1452 Debug("parser-sygus2") << "index = " << index
<< std::endl
;
1453 bool isConst
= true;
1454 for( unsigned cc
= 0; cc
< ops
[index
].size(); cc
++ ){
1455 Debug("parser-sygus2") << "ops[" << cc
<< "]=" << ops
[index
][cc
] << std::endl
;
1456 if( ops
[index
][cc
].getKind() != kind::CONST_RATIONAL
){
1462 Debug("parser-sygus") << "Linearize multiplication " << ctor
<< " based on argument " << k
<< std::endl
;
1463 const Datatype
& atdd
= atd
.getDatatype();
1464 std::vector
<Expr
> assertions
;
1465 std::vector
<Expr
> nbvs
;
1466 for( unsigned a
=0; a
<bvl
.getNumChildren(); a
++ ){
1468 nbvs
.push_back( bvl
[a
] );
1471 Expr nbvl
= getExprManager()->mkExpr( kind::BOUND_VAR_LIST
, nbvs
);
1472 for( unsigned cc
= 0; cc
< ops
[index
].size(); cc
++ ){
1473 //Make new assertion based on partially instantiating existing
1474 applyv
[k
+1] = getExprManager()->mkExpr(kind::APPLY_CONSTRUCTOR
, atdd
[cc
].getConstructor());
1475 Debug("parser-sygus") << "applyv " << applyv
[k
+1] << std::endl
;
1476 cpatv
= getExprManager()->mkExpr(kind::APPLY_CONSTRUCTOR
, applyv
);
1477 Debug("parser-sygus") << "cpatv " << cpatv
<< std::endl
;
1479 evalApply
= getExprManager()->mkExpr(kind::APPLY_UF
, patv
);
1480 Debug("parser-sygus") << "evalApply " << evalApply
<< std::endl
;
1481 builtApply
[k
] = ops
[index
][cc
];
1482 Debug("parser-sygus") << "builtApply " << builtApply
[k
] << std::endl
;
1483 builtTerm
= getExprManager()->mkExpr(ops
[i
][j
], builtApply
);
1484 Debug("parser-sygus") << "builtTerm " << builtTerm
<< std::endl
;
1485 Expr eassertion
= getExprManager()->mkExpr(evalApply
.getType().isBoolean() ? kind::IFF
: kind::EQUAL
, evalApply
, builtTerm
);
1486 Expr epattern
= getExprManager()->mkExpr(kind::INST_PATTERN
, evalApply
);
1487 epattern
= getExprManager()->mkExpr(kind::INST_PATTERN_LIST
, epattern
);
1488 eassertion
= getExprManager()->mkExpr(kind::FORALL
, nbvl
, eassertion
, epattern
);
1489 assertions
.push_back( eassertion
);
1491 assertion
= assertions
.size()==1 ? assertions
[0] : getExprManager()->mkExpr( kind::AND
, assertions
);
1492 Debug("parser-sygus") << "...(linearized) assertion is: " << assertion
<< std::endl
;
1501 const void Smt2::getSygusPrimedVars( std::vector
<Expr
>& vars
, bool isPrimed
) {
1502 for( unsigned i
=0; i
<d_sygusVars
.size(); i
++ ){
1503 Expr v
= d_sygusVars
[i
];
1504 std::map
< Expr
, bool >::iterator it
= d_sygusVarPrimed
.find( v
);
1505 if( it
!=d_sygusVarPrimed
.end() ){
1506 if( it
->second
==isPrimed
){
1507 vars
.push_back( v
);
1510 //should never happen
1515 }/* CVC4::parser namespace */
1516 }/* CVC4 namespace */