2021-11-30 13:06:30 -08:00
|
|
|
Datatypes
|
|
|
|
|
============
|
2022-01-05 12:47:09 -08:00
|
|
|
|
|
|
|
|
Overview
|
|
|
|
|
----------
|
|
|
|
|
|
|
|
|
|
To manipulate instances of a datatype, one must first *declare* the datatype itself.
|
|
|
|
|
Declaration happens in three phases. Let's consider declaring a cons-list of
|
|
|
|
|
integers.
|
|
|
|
|
|
|
|
|
|
First, we initialize the datatype with its *name*
|
|
|
|
|
|
|
|
|
|
>>> IntList = Datatype('IntList')
|
|
|
|
|
|
|
|
|
|
Second, we declare constructors for the datatype, giving the *constructor name*
|
|
|
|
|
and *field names and sorts*. Here is the empty list constructor:
|
|
|
|
|
|
|
|
|
|
>>> IntList.declare('nil', ())
|
|
|
|
|
|
|
|
|
|
Here is the cons constructor:
|
|
|
|
|
|
|
|
|
|
>>> IntList.declare('cons', ('val', IntSort()), ('tail', IntList))
|
|
|
|
|
|
|
|
|
|
Third, after all constructors are declared, we can *create* the datatype,
|
|
|
|
|
finishing its declaration.
|
|
|
|
|
|
|
|
|
|
>>> IntList = IntList.create()
|
|
|
|
|
|
|
|
|
|
Now, one has access to a number of tools for interacting with integer lists.
|
|
|
|
|
|
|
|
|
|
* ``IntList.nil`` refers to the SMT term that is an empty list,
|
|
|
|
|
and ``IntList.cons`` refers to the cons constructor.
|
|
|
|
|
* ``IntList.is_nil`` and ``IntList.is_cons`` are testors (a.k.a.,
|
|
|
|
|
recognizers) for those constructors.
|
|
|
|
|
* ``IntList.val`` and ``IntList.tail`` are selectors (a.k.a. accessors)
|
|
|
|
|
for the cons constructor.
|
|
|
|
|
|
|
|
|
|
If constructor, accessor, or selector names are ambiguous (e.g., if different
|
|
|
|
|
constructors have selectors of the same name), then see the methods on
|
2022-03-03 03:16:09 +01:00
|
|
|
:py:class:`cvc5.pythonic.DatatypeSortRef` to unambiguously access a specific
|
2022-01-05 12:47:09 -08:00
|
|
|
function.
|
|
|
|
|
|
|
|
|
|
To create mutually recursive datatypes, see
|
2022-03-03 03:16:09 +01:00
|
|
|
:py:func:`cvc5.pythonic.CreateDatatypes`.
|
2022-01-05 12:47:09 -08:00
|
|
|
|
|
|
|
|
To create a codataype (e.g., a possibly infinite stream of integers), pass the
|
2022-03-03 03:16:09 +01:00
|
|
|
``isCoDatatype=True`` argument to the :py:class:`cvc5.pythonic.Datatype`
|
2022-01-05 12:47:09 -08:00
|
|
|
constructor.
|
|
|
|
|
|
|
|
|
|
>>> IntStream = Datatype('IntStream', isCoDatatype=True)
|
|
|
|
|
|
|
|
|
|
Declaration Utilities
|
|
|
|
|
---------------------
|
|
|
|
|
|
2022-03-03 03:16:09 +01:00
|
|
|
.. autofunction:: cvc5.pythonic.CreateDatatypes
|
|
|
|
|
.. autofunction:: cvc5.pythonic.TupleSort
|
|
|
|
|
.. autofunction:: cvc5.pythonic.DisjointSum
|
2022-01-05 12:47:09 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
Classes
|
|
|
|
|
------------------------
|
2022-03-03 03:16:09 +01:00
|
|
|
.. autoclass:: cvc5.pythonic.Datatype
|
2022-01-05 12:47:09 -08:00
|
|
|
:members:
|
|
|
|
|
:special-members:
|
2022-03-03 03:16:09 +01:00
|
|
|
.. autoclass:: cvc5.pythonic.DatatypeSortRef
|
2022-01-05 12:47:09 -08:00
|
|
|
:members:
|
|
|
|
|
:special-members:
|
2022-03-03 03:16:09 +01:00
|
|
|
.. autoclass:: cvc5.pythonic.DatatypeConstructorRef
|
2022-01-05 12:47:09 -08:00
|
|
|
:members:
|
|
|
|
|
:special-members:
|
2022-03-03 03:16:09 +01:00
|
|
|
.. autoclass:: cvc5.pythonic.DatatypeSelectorRef
|
2022-01-05 12:47:09 -08:00
|
|
|
:members:
|
|
|
|
|
:special-members:
|
2022-03-03 03:16:09 +01:00
|
|
|
.. autoclass:: cvc5.pythonic.DatatypeRecognizerRef
|
2022-01-05 12:47:09 -08:00
|
|
|
:members:
|
|
|
|
|
:special-members:
|
2022-03-03 03:16:09 +01:00
|
|
|
.. autoclass:: cvc5.pythonic.DatatypeRef
|
2022-01-05 12:47:09 -08:00
|
|
|
:members:
|
|
|
|
|
:special-members:
|