Z3
 
Loading...
Searching...
No Matches
fp.go
Go to the documentation of this file.
1package z3
2
3/*
4#include "z3.h"
5#include <stdlib.h>
6*/
7import "C"
8import (
9 "unsafe"
10)
11
12// Floating-point operations
13
14// MkFPSort creates a floating-point sort.
15func (c *Context) MkFPSort(ebits, sbits uint) *Sort {
16 return newSort(c, C.Z3_mk_fpa_sort(c.ptr, C.uint(ebits), C.uint(sbits)))
17}
18
19// MkFPSort16 creates a 16-bit floating-point sort.
20func (c *Context) MkFPSort16() *Sort {
21 return newSort(c, C.Z3_mk_fpa_sort_16(c.ptr))
22}
23
24// MkFPSort32 creates a 32-bit floating-point sort (single precision).
25func (c *Context) MkFPSort32() *Sort {
26 return newSort(c, C.Z3_mk_fpa_sort_32(c.ptr))
27}
28
29// MkFPSort64 creates a 64-bit floating-point sort (double precision).
30func (c *Context) MkFPSort64() *Sort {
31 return newSort(c, C.Z3_mk_fpa_sort_64(c.ptr))
32}
33
34// MkFPSort128 creates a 128-bit floating-point sort (quadruple precision).
35func (c *Context) MkFPSort128() *Sort {
36 return newSort(c, C.Z3_mk_fpa_sort_128(c.ptr))
37}
38
39// MkFPRoundingModeSort creates the rounding mode sort.
40func (c *Context) MkFPRoundingModeSort() *Sort {
41 return newSort(c, C.Z3_mk_fpa_rounding_mode_sort(c.ptr))
42}
43
44// MkFPNumeral creates a floating-point numeral from a string.
45func (c *Context) MkFPNumeral(value string, sort *Sort) *Expr {
46 cStr := C.CString(value)
47 defer C.free(unsafe.Pointer(cStr))
48 return newExpr(c, C.Z3_mk_numeral(c.ptr, cStr, sort.ptr))
49}
50
51// MkFPInf creates a floating-point infinity.
52func (c *Context) MkFPInf(sort *Sort, negative bool) *Expr {
53 return newExpr(c, C.Z3_mk_fpa_inf(c.ptr, sort.ptr, C.bool(negative)))
54}
55
56// MkFPNaN creates a floating-point NaN.
57func (c *Context) MkFPNaN(sort *Sort) *Expr {
58 return newExpr(c, C.Z3_mk_fpa_nan(c.ptr, sort.ptr))
59}
60
61// MkFPZero creates a floating-point zero.
62func (c *Context) MkFPZero(sort *Sort, negative bool) *Expr {
63 return newExpr(c, C.Z3_mk_fpa_zero(c.ptr, sort.ptr, C.bool(negative)))
64}
65
66// MkFPAdd creates a floating-point addition.
67func (c *Context) MkFPAdd(rm, lhs, rhs *Expr) *Expr {
68 return newExpr(c, C.Z3_mk_fpa_add(c.ptr, rm.ptr, lhs.ptr, rhs.ptr))
69}
70
71// MkFPSub creates a floating-point subtraction.
72func (c *Context) MkFPSub(rm, lhs, rhs *Expr) *Expr {
73 return newExpr(c, C.Z3_mk_fpa_sub(c.ptr, rm.ptr, lhs.ptr, rhs.ptr))
74}
75
76// MkFPMul creates a floating-point multiplication.
77func (c *Context) MkFPMul(rm, lhs, rhs *Expr) *Expr {
78 return newExpr(c, C.Z3_mk_fpa_mul(c.ptr, rm.ptr, lhs.ptr, rhs.ptr))
79}
80
81// MkFPDiv creates a floating-point division.
82func (c *Context) MkFPDiv(rm, lhs, rhs *Expr) *Expr {
83 return newExpr(c, C.Z3_mk_fpa_div(c.ptr, rm.ptr, lhs.ptr, rhs.ptr))
84}
85
86// MkFPNeg creates a floating-point negation.
87func (c *Context) MkFPNeg(expr *Expr) *Expr {
88 return newExpr(c, C.Z3_mk_fpa_neg(c.ptr, expr.ptr))
89}
90
91// MkFPAbs creates a floating-point absolute value.
92func (c *Context) MkFPAbs(expr *Expr) *Expr {
93 return newExpr(c, C.Z3_mk_fpa_abs(c.ptr, expr.ptr))
94}
95
96// MkFPSqrt creates a floating-point square root.
97func (c *Context) MkFPSqrt(rm, expr *Expr) *Expr {
98 return newExpr(c, C.Z3_mk_fpa_sqrt(c.ptr, rm.ptr, expr.ptr))
99}
100
101// MkFPLT creates a floating-point less-than.
102func (c *Context) MkFPLT(lhs, rhs *Expr) *Expr {
103 return newExpr(c, C.Z3_mk_fpa_lt(c.ptr, lhs.ptr, rhs.ptr))
104}
105
106// MkFPGT creates a floating-point greater-than.
107func (c *Context) MkFPGT(lhs, rhs *Expr) *Expr {
108 return newExpr(c, C.Z3_mk_fpa_gt(c.ptr, lhs.ptr, rhs.ptr))
109}
110
111// MkFPLE creates a floating-point less-than-or-equal.
112func (c *Context) MkFPLE(lhs, rhs *Expr) *Expr {
113 return newExpr(c, C.Z3_mk_fpa_leq(c.ptr, lhs.ptr, rhs.ptr))
114}
115
116// MkFPGE creates a floating-point greater-than-or-equal.
117func (c *Context) MkFPGE(lhs, rhs *Expr) *Expr {
118 return newExpr(c, C.Z3_mk_fpa_geq(c.ptr, lhs.ptr, rhs.ptr))
119}
120
121// MkFPEq creates a floating-point equality.
122func (c *Context) MkFPEq(lhs, rhs *Expr) *Expr {
123 return newExpr(c, C.Z3_mk_fpa_eq(c.ptr, lhs.ptr, rhs.ptr))
124}
125
126// MkFPIsNaN creates a predicate checking if a floating-point number is NaN.
127func (c *Context) MkFPIsNaN(expr *Expr) *Expr {
128 return newExpr(c, C.Z3_mk_fpa_is_nan(c.ptr, expr.ptr))
129}
130
131// MkFPIsInf creates a predicate checking if a floating-point number is infinite.
132func (c *Context) MkFPIsInf(expr *Expr) *Expr {
133 return newExpr(c, C.Z3_mk_fpa_is_infinite(c.ptr, expr.ptr))
134}
135
136// MkFPIsZero creates a predicate checking if a floating-point number is zero.
137func (c *Context) MkFPIsZero(expr *Expr) *Expr {
138 return newExpr(c, C.Z3_mk_fpa_is_zero(c.ptr, expr.ptr))
139}
140
141// MkFPIsNormal creates a predicate checking if a floating-point number is normal.
142func (c *Context) MkFPIsNormal(expr *Expr) *Expr {
143 return newExpr(c, C.Z3_mk_fpa_is_normal(c.ptr, expr.ptr))
144}
145
146// MkFPIsSubnormal creates a predicate checking if a floating-point number is subnormal.
147func (c *Context) MkFPIsSubnormal(expr *Expr) *Expr {
148 return newExpr(c, C.Z3_mk_fpa_is_subnormal(c.ptr, expr.ptr))
149}
150
151// MkFPIsNegative creates a predicate checking if a floating-point number is negative.
152func (c *Context) MkFPIsNegative(expr *Expr) *Expr {
153 return newExpr(c, C.Z3_mk_fpa_is_negative(c.ptr, expr.ptr))
154}
155
156// MkFPIsPositive creates a predicate checking if a floating-point number is positive.
157func (c *Context) MkFPIsPositive(expr *Expr) *Expr {
158 return newExpr(c, C.Z3_mk_fpa_is_positive(c.ptr, expr.ptr))
159}
160
161// MkFPToIEEEBV converts a floating-point number to its IEEE 754 bit-vector representation.
162func (c *Context) MkFPToIEEEBV(expr *Expr) *Expr {
163 return newExpr(c, C.Z3_mk_fpa_to_ieee_bv(c.ptr, expr.ptr))
164}
165
166// MkFPToReal converts a floating-point number to a real number.
167func (c *Context) MkFPToReal(expr *Expr) *Expr {
168 return newExpr(c, C.Z3_mk_fpa_to_real(c.ptr, expr.ptr))
169}
170
171// MkFPRNE creates the round-nearest-ties-to-even rounding mode.
172func (c *Context) MkFPRNE() *Expr {
173 return newExpr(c, C.Z3_mk_fpa_rne(c.ptr))
174}
175
176// MkFPRNA creates the round-nearest-ties-to-away rounding mode.
177func (c *Context) MkFPRNA() *Expr {
178 return newExpr(c, C.Z3_mk_fpa_rna(c.ptr))
179}
180
181// MkFPRTP creates the round-toward-positive rounding mode.
182func (c *Context) MkFPRTP() *Expr {
183 return newExpr(c, C.Z3_mk_fpa_rtp(c.ptr))
184}
185
186// MkFPRTN creates the round-toward-negative rounding mode.
187func (c *Context) MkFPRTN() *Expr {
188 return newExpr(c, C.Z3_mk_fpa_rtn(c.ptr))
189}
190
191// MkFPRTZ creates the round-toward-zero rounding mode.
192func (c *Context) MkFPRTZ() *Expr {
193 return newExpr(c, C.Z3_mk_fpa_rtz(c.ptr))
194}
195
196// MkFPFP creates a floating-point number from a sign bit (1-bit BV), exponent BV, and significand BV.
197func (c *Context) MkFPFP(sgn, exp, sig *Expr) *Expr {
198 return newExpr(c, C.Z3_mk_fpa_fp(c.ptr, sgn.ptr, exp.ptr, sig.ptr))
199}
200
201// MkFPNumeralFloat creates a floating-point numeral from a float32 value.
202func (c *Context) MkFPNumeralFloat(v float32, sort *Sort) *Expr {
203 return newExpr(c, C.Z3_mk_fpa_numeral_float(c.ptr, C.float(v), sort.ptr))
204}
205
206// MkFPNumeralDouble creates a floating-point numeral from a float64 value.
207func (c *Context) MkFPNumeralDouble(v float64, sort *Sort) *Expr {
208 return newExpr(c, C.Z3_mk_fpa_numeral_double(c.ptr, C.double(v), sort.ptr))
209}
210
211// MkFPNumeralInt creates a floating-point numeral from a signed integer.
212func (c *Context) MkFPNumeralInt(v int, sort *Sort) *Expr {
213 return newExpr(c, C.Z3_mk_fpa_numeral_int(c.ptr, C.int(v), sort.ptr))
214}
215
216// MkFPNumeralIntUint creates a floating-point numeral from a sign, signed exponent, and unsigned significand.
217func (c *Context) MkFPNumeralIntUint(sgn bool, exp int, sig uint, sort *Sort) *Expr {
218 return newExpr(c, C.Z3_mk_fpa_numeral_int_uint(c.ptr, C.bool(sgn), C.int(exp), C.uint(sig), sort.ptr))
219}
220
221// MkFPNumeralInt64Uint64 creates a floating-point numeral from a sign, int64 exponent, and uint64 significand.
222func (c *Context) MkFPNumeralInt64Uint64(sgn bool, exp int64, sig uint64, sort *Sort) *Expr {
223 return newExpr(c, C.Z3_mk_fpa_numeral_int64_uint64(c.ptr, C.bool(sgn), C.int64_t(exp), C.uint64_t(sig), sort.ptr))
224}
225
226// MkFPFMA creates a floating-point fused multiply-add: round((t1 * t2) + t3, rm).
227func (c *Context) MkFPFMA(rm, t1, t2, t3 *Expr) *Expr {
228 return newExpr(c, C.Z3_mk_fpa_fma(c.ptr, rm.ptr, t1.ptr, t2.ptr, t3.ptr))
229}
230
231// MkFPRem creates a floating-point remainder.
232func (c *Context) MkFPRem(t1, t2 *Expr) *Expr {
233 return newExpr(c, C.Z3_mk_fpa_rem(c.ptr, t1.ptr, t2.ptr))
234}
235
236// MkFPMin creates the minimum of two floating-point values.
237func (c *Context) MkFPMin(t1, t2 *Expr) *Expr {
238 return newExpr(c, C.Z3_mk_fpa_min(c.ptr, t1.ptr, t2.ptr))
239}
240
241// MkFPMax creates the maximum of two floating-point values.
242func (c *Context) MkFPMax(t1, t2 *Expr) *Expr {
243 return newExpr(c, C.Z3_mk_fpa_max(c.ptr, t1.ptr, t2.ptr))
244}
245
246// MkFPRoundToIntegral creates a floating-point round-to-integral operation.
247func (c *Context) MkFPRoundToIntegral(rm, t *Expr) *Expr {
248 return newExpr(c, C.Z3_mk_fpa_round_to_integral(c.ptr, rm.ptr, t.ptr))
249}
250
251// MkFPToFPBV converts a bit-vector to a floating-point number (reinterpretation of IEEE 754 bits).
252func (c *Context) MkFPToFPBV(bv *Expr, sort *Sort) *Expr {
253 return newExpr(c, C.Z3_mk_fpa_to_fp_bv(c.ptr, bv.ptr, sort.ptr))
254}
255
256// MkFPToFPFloat converts a floating-point number to another floating-point sort with rounding.
257func (c *Context) MkFPToFPFloat(rm, t *Expr, sort *Sort) *Expr {
258 return newExpr(c, C.Z3_mk_fpa_to_fp_float(c.ptr, rm.ptr, t.ptr, sort.ptr))
259}
260
261// MkFPToFPReal converts a real number to a floating-point number with rounding.
262func (c *Context) MkFPToFPReal(rm, t *Expr, sort *Sort) *Expr {
263 return newExpr(c, C.Z3_mk_fpa_to_fp_real(c.ptr, rm.ptr, t.ptr, sort.ptr))
264}
265
266// MkFPToFPSigned converts a signed bit-vector to a floating-point number with rounding.
267func (c *Context) MkFPToFPSigned(rm, t *Expr, sort *Sort) *Expr {
268 return newExpr(c, C.Z3_mk_fpa_to_fp_signed(c.ptr, rm.ptr, t.ptr, sort.ptr))
269}
270
271// MkFPToFPUnsigned converts an unsigned bit-vector to a floating-point number with rounding.
272func (c *Context) MkFPToFPUnsigned(rm, t *Expr, sort *Sort) *Expr {
273 return newExpr(c, C.Z3_mk_fpa_to_fp_unsigned(c.ptr, rm.ptr, t.ptr, sort.ptr))
274}
275
276// MkFPToSBV converts a floating-point number to a signed bit-vector with rounding.
277func (c *Context) MkFPToSBV(rm, t *Expr, sz uint) *Expr {
278 return newExpr(c, C.Z3_mk_fpa_to_sbv(c.ptr, rm.ptr, t.ptr, C.uint(sz)))
279}
280
281// MkFPToUBV converts a floating-point number to an unsigned bit-vector with rounding.
282func (c *Context) MkFPToUBV(rm, t *Expr, sz uint) *Expr {
283 return newExpr(c, C.Z3_mk_fpa_to_ubv(c.ptr, rm.ptr, t.ptr, C.uint(sz)))
284}