简体   繁体   中英

Getting solver in SMT2 format

I am using the java API for generating code, but I would like to show the user the code in SMT2 format , is there any way to get it from the java API??

lets say I would like that some generated code like this...

(forall ((task Task)) (not (mustPrecede task task)))
(forall ((t1 Task) (t2 Task) (t3 Task))
(=> (and (mustPrecede t1 t2) (mustPrecede t2 t3)) (mustPrecede t1 t3)))

could be parsed into something like this

(declare-fun TaskUser (Task User) Bool)
(declare-fun mustPrecede (Task Task) Bool)
(assert(forall((t Task)) (not (mustPrecede t t))))
(assert(forall((t1 Task)(t2 Task)(t3 Task)) (implies (and (mustPrecede t1 t2)     (mustPrecede t2 t3)) (mustPrecede t1 t3))))
(assert(forall((t Task)(u User)) (TaskUser t u)))

Expressions will be printed in SMT2 syntax if we set the print mode for ASTs to the corresponding option, eg,

ctx.setPrintMode(Z3_PRINT_SMTLIB2_COMPLIANT);

Whenever the .toString() function on an AST or an Expr is called, it will then be SMT2 compliant.

Note that the .toString() functions will only print the expressions themselves, not any declarations that they may depend on. If declarations are needed, it is likely that there is a list of them somewhere in the client code, but if that's not the case, the expressions need to be traversed to find all function declarations that they depend on. The function declarations can be obtained by calling .getFuncDecl() on an Expr.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM