c语言程序编程1500行,ToySMT:用约1500行纯C代码实现的简单SMT解算器

MK85 - toy-level, simple SMT solver under ~3000 SLOC of C++

It's very early sneak preview. It supports only bools and bitvecs. No integers, let alone reals and arrays and tuples and whatnot. Its complexity is comparable to simple LISP interpreter.

However, it can serve as education tool (hopefully). This is also my playground.

It parses input SMT-LIB file (see "tests" and "examples"), constructs digital circuit, which is then converted to CNF form using Tseitin transformations. This is also called "bitblasting".

Stay tuned, it will be evolved.

Requires: flex/bison. In Ubuntu Linux, type "make". It wasn't checked on other OS-es.

Since it's early preview, it was only checked on "tests" and "examples" you can find here. Anything else can fail. Also, error reporting is somewhat user-unfriendly. First, you can check your .smt files using other SMT solver (I used z3, Boolector, STP, Yices, CVC4).

Thanks

Armin Biere patiently helped with my endless boring-to-death questions.

Xenia Galinskaya, for support.

Installation

make

sudo make install (copies python files and .so library to dist-package...)

Non-standard SMT-LIB commands

Aside from SMT-LIB standard, I also added two more commands: (get-all-models) and (count-models) (see "tests").

Non-standard SMT-LIB functions

Name

It was previously named "ToySMT", but then I got to know about existence of another project called toysmt.

Since other SMT-solvers use cryptic acronyms as names, and since the name of Z3 has probably been taken from Z3 computer, I choose a "MK85" name (after Soviet programmable calculator Elektronika MK-85).

History

I've written many SAT examples in Python, based on my Python library (or API): https://github.com/DennisYurichev/SAT_SMT_by_example/blob/master/libs/SAT_lib.py Many SAT Python-based examples has been published in my blog: https://yurichev.com/blog/

And at some point I realised I can do simple SMT-solver, I need only to add parser and keep tabs on variables. This is what I did.

Hence, in order to fully understand MK85, you can first try to understand my SAT Python-based examples.

21-Jan-2018: minimize/maximize using Open-WBO solver

Internals

There are two main structures.

"struct expr" used during parsing.

"struct SMT_var" is a "high level" structure reflecting each SMT variable, which can be bool or bitvector. The structure has linked "SAT_var", which is number of variable on SAT level + width. For boolean, only one SAT variable is used. For bitvector of width w, SMT variable occupies [SAT_var, SAT_var+w-1] SAT variables.

Extreme simplicity

It has no optimizations at all. If it encounters two "(bvadd x y)", two adders would be generated instead of one. Maybe SAT-solver (minisat/picosat in this case) could optimize this out, or maybe not.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值