Z3 Prover:等同于 C++ 中的 Python 数据类型 API

Z3 Prover: Equivalent to Python Datatype in the C++ API

C++ 是否有等同于 Python Datatype() API 的方法?

例如在Python中你可以这样做:

>>> List = Datatype('List')
>>> List.declare('cons', ('car', IntSort()), ('cdr', List))
>>> List.declare('nil')
>>> List = List.create()
>>> # List is now a Z3 declaration
>>> List.nil
nil
>>> List.cons(10, List.nil)
cons(10, nil)
>>> List.cons(10, List.nil).sort()
List
>>> cons = List.cons
>>> nil  = List.nil
>>> car  = List.car
>>> cdr  = List.cdr
>>> n = cons(1, cons(0, nil))
>>> n
cons(1, cons(0, nil))
>>> simplify(cdr(n))
cons(0, nil)
>>> simplify(car(n))
1

如何使用 C++ 声明此类代数数据类型API?

是的。一般来说,您可以在 Python API(和其他 API 中执行的所有操作,您也可以在 C/C++ 中执行。您要查找的函数称为 Z3_mk_datatype。参见:

https://z3prover.github.io/api/html/group__capi.html#ga34875df69093aca24de67ae71542b1b0

了解详情。

请注意,C/C++ API 的级别要低得多,因此尽管可以这样做,但我强烈建议您不要使用这些 API,除非您有一个强制你使用 C/C++.

的要求