sosy-lab / java-smt

JavaSMT - Unified Java API for SMT solvers.
Apache License 2.0
179 stars 44 forks source link

support for enum types #301

Closed garganti closed 1 year ago

garganti commented 1 year ago

It would be good if java-smt could support enum types (datatypes). An enum type has a name and a set of symbols. Variables can then be declared of that type and basic operations like = and distinctcan be performed on formulas of that variables. Enum types are supported by SMT_LIB format (pag 61 of the language ref manual):

; an enumeration datatype
( declare - datatypes ( ( Color 0) ) (
( ( red ) ( green ) ( blue ) ))
)

Most of the solvers support them natively. For instance Z3, the following command creates a type S with three possible values: (declare-datatypes () ((S A B C))) which has the corresponding java type in the APIs (DatatypeExpr)

Other solvers have similar APIs. For instance yices: type_t yices_new_scalar_type(uint32_t card)

kfriedberger commented 1 year ago

Interesting idea. Enum sort is available in several solvers. We just need to find a common basis for an implementation.

Overall, we could start with a few solvers supporting enumertion logic, and if we know enough about this kind of logic, then extend it to other solvers, based on a sub-set of datatype-logic.

Lets start with collecting some API examples:

Z3:

MathSAT5 (API needs to be updated to 5.6.9 or later, plus see the other issue: https://github.com/sosy-lab/java-smt/issues/290):

Yices (our internal API skipped all scalar types, needs to be updated for enumration types):

CVC4 and CVC5, and other solvers seem to use datatypes for enumeration logic:

Next step: We need to refine that information and test simple examples. :-)

kfriedberger commented 1 year ago

I started with an initial interface, which is quite simple and understandable. We just need to wire the internals for each solver.

baierd commented 1 year ago

I've created a branch for this. Also, @RSoegtrop will take a look.

kfriedberger commented 1 year ago

The new release JavaSMT 4.0.0 contains the requested enumeration theory, at least for some SMT solvers. We would be happy to get feedback or reports if there are any further issues.