From CVC4
Jump to: navigation, search


To enable CVC4's decision procedure for datatypes, include "DT" in the logic:

 (set-logic QF_UFDT)

Alternatively, use the "ALL_SUPPORTED" logic:

 (set-logic ALL_SUPPORTED)


CVC4 supports the following syntax for declaring mutually recursive blocks of datatypes in *.smt2 input files in the smt lib 2.6 format:

 (declare-datatypes ((D1 n1)...(Dk nk)) 
   (((C1 (S1 T1)....(Si Ti))...(Cj .... ))
    ((....) ... (....)))

where D1...Dk are datatype types, C1...Cj are the constructors for datatype D1, S1....Si are the selectors (or "destructors") of constructor C1, and each T1...Ti is a previously declared type or one of D1...k. The symbols U1...Un are type parameters (fresh symbols). The numbers n1...nk denote the number of type parameters for the datatype, where 0 is used for non-parametric datatypes.

In addition to declaring symbols for constructors and selectors, the above command also adds tester (or "discriminator") indexed symbols of the form (_ is C) for each constructor C, which are unary predicates which evaluate to true iff their argument has top-symbol C.

CVC4 also supports datatypes in its native format [1].


The decision procedure for inductive datatypes can be found here.

Example Declarations

An enumeration:

 (declare-datatypes ((Color 0)) 
   (((Red) (Black))))

A List of Int with "cons" and "nil" as constructors:

 (declare-datatypes ((list 0)) 
   (((cons (head Int) (tail list)) (nil))))

A parametric List of T's:

 (declare-datatypes ((list 1)) 
   ((par (T) ((cons (head T) (tail (list T))) (nil)))))

Mutual recursion:

 (declare-datatypes ((list 0) (tree 0)) 
   (((cons (head tree) (tail list)) (nil))
    ((node (data Int) (children list)))))

A (non-recursive) record type:

 (declare-datatypes ((record 0))
   (((rec (fname String) (lname String) (id Int)))))


 (declare-datatypes ((list 0)) 
   (((cons (head Int) (tail list)) (nil))))
 (declare-fun a () list)
 (declare-fun b () list)
 (assert (and (= (tail a) b) (not ((_ is nil) b)) (> (head b) 0)))
 (declare-datatypes ((record 0))
   (((rec (fname String) (lname String) (id Int)))))
 (declare-const x record)
 (assert (and (= (fname x) "John") (= (lname x) "Smith")))

Parametric Datatypes

Instances of parametric datatypes must have their arguments instantiated with concrete types. For instance, in the example:

 (declare-datatypes ((list 1)) ((par (T) (cons (head T) (tail (list T))) (nil))))

To declare a list of Int, use the command:

 (declare-fun f () (list Int))

Use of constructors that are ambiguously typed must be cast to a concrete type, for instance all occurrences of "nil" for the above datatype must be cast with the syntax:

 (as nil (list Int))


CVC4 also supports co-inductive datatypes, as described here. The syntax for declaring mutually recursive coinductive datatype blocks is identical to inductive datatypes, except that "declare-datatypes" is replaced by "declare-codatatypes". For example, the following declares the type denote streams of Int:

 (declare-codatatypes ((stream 0)) 
   (((cons (head Int) (tail stream)))))