Z3
 
Loading...
Searching...
No Matches
array.go
Go to the documentation of this file.
1package z3
2
3/*
4#include "z3.h"
5#include <stdlib.h>
6*/
7import "C"
8
9// Array operations and sorts
10
11// MkArraySort creates an array sort.
12func (c *Context) MkArraySort(domain, range_ *Sort) *Sort {
13 return newSort(c, C.Z3_mk_array_sort(c.ptr, domain.ptr, range_.ptr))
14}
15
16// MkSelect creates an array read (select) operation.
17func (c *Context) MkSelect(array, index *Expr) *Expr {
18 return newExpr(c, C.Z3_mk_select(c.ptr, array.ptr, index.ptr))
19}
20
21// MkStore creates an array write (store) operation.
22func (c *Context) MkStore(array, index, value *Expr) *Expr {
23 return newExpr(c, C.Z3_mk_store(c.ptr, array.ptr, index.ptr, value.ptr))
24}
25
26// MkConstArray creates a constant array.
27func (c *Context) MkConstArray(sort *Sort, value *Expr) *Expr {
28 return newExpr(c, C.Z3_mk_const_array(c.ptr, sort.ptr, value.ptr))
29}
30
31// MkSelectN creates a multi-index array read (select) operation.
32func (c *Context) MkSelectN(array *Expr, indices []*Expr) *Expr {
33 idxs := make([]C.Z3_ast, len(indices))
34 for i, idx := range indices {
35 idxs[i] = idx.ptr
36 }
37 var idxsPtr *C.Z3_ast
38 if len(idxs) > 0 {
39 idxsPtr = &idxs[0]
40 }
41 return newExpr(c, C.Z3_mk_select_n(c.ptr, array.ptr, C.uint(len(idxs)), idxsPtr))
42}
43
44// MkStoreN creates a multi-index array write (store) operation.
45func (c *Context) MkStoreN(array *Expr, indices []*Expr, value *Expr) *Expr {
46 idxs := make([]C.Z3_ast, len(indices))
47 for i, idx := range indices {
48 idxs[i] = idx.ptr
49 }
50 var idxsPtr *C.Z3_ast
51 if len(idxs) > 0 {
52 idxsPtr = &idxs[0]
53 }
54 return newExpr(c, C.Z3_mk_store_n(c.ptr, array.ptr, C.uint(len(idxs)), idxsPtr, value.ptr))
55}
56
57// MkArrayDefault returns the default value of an array.
58func (c *Context) MkArrayDefault(array *Expr) *Expr {
59 return newExpr(c, C.Z3_mk_array_default(c.ptr, array.ptr))
60}
61
62// MkArrayExt returns the extensionality witness for two arrays.
63// Two arrays are equal if and only if they are equal on the index returned by MkArrayExt.
64func (c *Context) MkArrayExt(a1, a2 *Expr) *Expr {
65 return newExpr(c, C.Z3_mk_array_ext(c.ptr, a1.ptr, a2.ptr))
66}
67
68// MkAsArray creates an array from a function declaration.
69// The resulting array maps each input to the output of the function.
70func (c *Context) MkAsArray(f *FuncDecl) *Expr {
71 return newExpr(c, C.Z3_mk_as_array(c.ptr, f.ptr))
72}
73
74// MkMap applies a function to the elements of one or more arrays, returning a new array.
75// The function f is applied element-wise to the given arrays.
76func (c *Context) MkMap(f *FuncDecl, arrays ...*Expr) *Expr {
77 cArrays := make([]C.Z3_ast, len(arrays))
78 for i, a := range arrays {
79 cArrays[i] = a.ptr
80 }
81 var cArraysPtr *C.Z3_ast
82 if len(cArrays) > 0 {
83 cArraysPtr = &cArrays[0]
84 }
85 return newExpr(c, C.Z3_mk_map(c.ptr, f.ptr, C.uint(len(arrays)), cArraysPtr))
86}