Z3
 
Loading...
Searching...
No Matches
arith.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// Arithmetic operations and sorts
10
11// MkIntSort creates the integer sort.
12func (c *Context) MkIntSort() *Sort {
13 return newSort(c, C.Z3_mk_int_sort(c.ptr))
14}
15
16// MkRealSort creates the real number sort.
17func (c *Context) MkRealSort() *Sort {
18 return newSort(c, C.Z3_mk_real_sort(c.ptr))
19}
20
21// MkInt creates an integer constant from an int.
22func (c *Context) MkInt(value int, sort *Sort) *Expr {
23 return newExpr(c, C.Z3_mk_int(c.ptr, C.int(value), sort.ptr))
24}
25
26// MkInt64 creates an integer constant from an int64.
27func (c *Context) MkInt64(value int64, sort *Sort) *Expr {
28 return newExpr(c, C.Z3_mk_int64(c.ptr, C.int64_t(value), sort.ptr))
29}
30
31// MkReal creates a real constant from numerator and denominator.
32func (c *Context) MkReal(num, den int) *Expr {
33 return newExpr(c, C.Z3_mk_real(c.ptr, C.int(num), C.int(den)))
34}
35
36// MkIntConst creates an integer constant (variable) with the given name.
37func (c *Context) MkIntConst(name string) *Expr {
38 sym := c.MkStringSymbol(name)
39 return c.MkConst(sym, c.MkIntSort())
40}
41
42// MkRealConst creates a real constant (variable) with the given name.
43func (c *Context) MkRealConst(name string) *Expr {
44 sym := c.MkStringSymbol(name)
45 return c.MkConst(sym, c.MkRealSort())
46}
47
48// MkAdd creates an addition.
49func (c *Context) MkAdd(exprs ...*Expr) *Expr {
50 if len(exprs) == 0 {
51 return c.MkInt(0, c.MkIntSort())
52 }
53 if len(exprs) == 1 {
54 return exprs[0]
55 }
56 cExprs := make([]C.Z3_ast, len(exprs))
57 for i, e := range exprs {
58 cExprs[i] = e.ptr
59 }
60 return newExpr(c, C.Z3_mk_add(c.ptr, C.uint(len(exprs)), &cExprs[0]))
61}
62
63// MkSub creates a subtraction.
64func (c *Context) MkSub(exprs ...*Expr) *Expr {
65 if len(exprs) == 0 {
66 return c.MkInt(0, c.MkIntSort())
67 }
68 if len(exprs) == 1 {
69 return newExpr(c, C.Z3_mk_unary_minus(c.ptr, exprs[0].ptr))
70 }
71 cExprs := make([]C.Z3_ast, len(exprs))
72 for i, e := range exprs {
73 cExprs[i] = e.ptr
74 }
75 return newExpr(c, C.Z3_mk_sub(c.ptr, C.uint(len(exprs)), &cExprs[0]))
76}
77
78// MkMul creates a multiplication.
79func (c *Context) MkMul(exprs ...*Expr) *Expr {
80 if len(exprs) == 0 {
81 return c.MkInt(1, c.MkIntSort())
82 }
83 if len(exprs) == 1 {
84 return exprs[0]
85 }
86 cExprs := make([]C.Z3_ast, len(exprs))
87 for i, e := range exprs {
88 cExprs[i] = e.ptr
89 }
90 return newExpr(c, C.Z3_mk_mul(c.ptr, C.uint(len(exprs)), &cExprs[0]))
91}
92
93// MkDiv creates a division.
94func (c *Context) MkDiv(lhs, rhs *Expr) *Expr {
95 return newExpr(c, C.Z3_mk_div(c.ptr, lhs.ptr, rhs.ptr))
96}
97
98// MkMod creates a modulo operation.
99func (c *Context) MkMod(lhs, rhs *Expr) *Expr {
100 return newExpr(c, C.Z3_mk_mod(c.ptr, lhs.ptr, rhs.ptr))
101}
102
103// MkRem creates a remainder operation.
104func (c *Context) MkRem(lhs, rhs *Expr) *Expr {
105 return newExpr(c, C.Z3_mk_rem(c.ptr, lhs.ptr, rhs.ptr))
106}
107
108// MkLt creates a less-than constraint.
109func (c *Context) MkLt(lhs, rhs *Expr) *Expr {
110 return newExpr(c, C.Z3_mk_lt(c.ptr, lhs.ptr, rhs.ptr))
111}
112
113// MkLe creates a less-than-or-equal constraint.
114func (c *Context) MkLe(lhs, rhs *Expr) *Expr {
115 return newExpr(c, C.Z3_mk_le(c.ptr, lhs.ptr, rhs.ptr))
116}
117
118// MkGt creates a greater-than constraint.
119func (c *Context) MkGt(lhs, rhs *Expr) *Expr {
120 return newExpr(c, C.Z3_mk_gt(c.ptr, lhs.ptr, rhs.ptr))
121}
122
123// MkGe creates a greater-than-or-equal constraint.
124func (c *Context) MkGe(lhs, rhs *Expr) *Expr {
125 return newExpr(c, C.Z3_mk_ge(c.ptr, lhs.ptr, rhs.ptr))
126}