Z3
 
Loading...
Searching...
No Matches
RCFNum.java
Go to the documentation of this file.
1
20package com.microsoft.z3;
21
31public class RCFNum extends Z3Object {
32
39 public RCFNum(Context ctx, String value) {
40 super(ctx, Native.rcfMkRational(ctx.nCtx(), value));
41 }
42
49 public RCFNum(Context ctx, int value) {
50 super(ctx, Native.rcfMkSmallInt(ctx.nCtx(), value));
51 }
52
56 RCFNum(Context ctx, long obj) {
57 super(ctx, obj);
58 }
59
66 public static RCFNum mkPi(Context ctx) {
67 return new RCFNum(ctx, Native.rcfMkPi(ctx.nCtx()));
68 }
69
76 public static RCFNum mkE(Context ctx) {
77 return new RCFNum(ctx, Native.rcfMkE(ctx.nCtx()));
78 }
79
86 public static RCFNum mkInfinitesimal(Context ctx) {
87 return new RCFNum(ctx, Native.rcfMkInfinitesimal(ctx.nCtx()));
88 }
89
100 public static RCFNum[] mkRoots(Context ctx, RCFNum[] coefficients) {
101 if (coefficients == null || coefficients.length == 0) {
102 throw new Z3Exception("Polynomial coefficients cannot be empty");
103 }
104
105 int n = coefficients.length;
106 long[] a = new long[n];
107 long[] roots = new long[n];
108
109 for (int i = 0; i < n; i++) {
110 a[i] = coefficients[i].getNativeObject();
111 }
112
113 int numRoots = Native.rcfMkRoots(ctx.nCtx(), n, a, roots);
114
115 RCFNum[] result = new RCFNum[numRoots];
116 for (int i = 0; i < numRoots; i++) {
117 result[i] = new RCFNum(ctx, roots[i]);
118 }
119
120 return result;
121 }
122
129 public RCFNum add(RCFNum other) {
130 checkContext(other);
131 return new RCFNum(getContext(), Native.rcfAdd(getContext().nCtx(),
132 getNativeObject(),
133 other.getNativeObject()));
134 }
135
142 public RCFNum sub(RCFNum other) {
143 checkContext(other);
144 return new RCFNum(getContext(), Native.rcfSub(getContext().nCtx(),
145 getNativeObject(),
146 other.getNativeObject()));
147 }
148
155 public RCFNum mul(RCFNum other) {
156 checkContext(other);
157 return new RCFNum(getContext(), Native.rcfMul(getContext().nCtx(),
158 getNativeObject(),
159 other.getNativeObject()));
160 }
161
168 public RCFNum div(RCFNum other) {
169 checkContext(other);
170 return new RCFNum(getContext(), Native.rcfDiv(getContext().nCtx(),
171 getNativeObject(),
172 other.getNativeObject()));
173 }
174
180 public RCFNum neg() {
181 return new RCFNum(getContext(), Native.rcfNeg(getContext().nCtx(),
182 getNativeObject()));
183 }
184
190 public RCFNum inv() {
191 return new RCFNum(getContext(), Native.rcfInv(getContext().nCtx(),
192 getNativeObject()));
193 }
194
201 public RCFNum power(int k) {
202 return new RCFNum(getContext(), Native.rcfPower(getContext().nCtx(),
203 getNativeObject(), k));
204 }
205
212 public boolean lt(RCFNum other) {
213 checkContext(other);
214 return Native.rcfLt(getContext().nCtx(), getNativeObject(),
215 other.getNativeObject());
216 }
217
224 public boolean gt(RCFNum other) {
225 checkContext(other);
226 return Native.rcfGt(getContext().nCtx(), getNativeObject(),
227 other.getNativeObject());
228 }
229
236 public boolean le(RCFNum other) {
237 checkContext(other);
238 return Native.rcfLe(getContext().nCtx(), getNativeObject(),
239 other.getNativeObject());
240 }
241
248 public boolean ge(RCFNum other) {
249 checkContext(other);
250 return Native.rcfGe(getContext().nCtx(), getNativeObject(),
251 other.getNativeObject());
252 }
253
260 public boolean eq(RCFNum other) {
261 checkContext(other);
262 return Native.rcfEq(getContext().nCtx(), getNativeObject(),
263 other.getNativeObject());
264 }
265
272 public boolean neq(RCFNum other) {
273 checkContext(other);
274 return Native.rcfNeq(getContext().nCtx(), getNativeObject(),
275 other.getNativeObject());
276 }
277
283 public boolean isRational() {
284 return Native.rcfIsRational(getContext().nCtx(), getNativeObject());
285 }
286
292 public boolean isAlgebraic() {
293 return Native.rcfIsAlgebraic(getContext().nCtx(), getNativeObject());
294 }
295
301 public boolean isInfinitesimal() {
302 return Native.rcfIsInfinitesimal(getContext().nCtx(), getNativeObject());
303 }
304
310 public boolean isTranscendental() {
311 return Native.rcfIsTranscendental(getContext().nCtx(), getNativeObject());
312 }
313
320 public String toString(boolean compact) {
321 return Native.rcfNumToString(getContext().nCtx(), getNativeObject(),
322 compact, false);
323 }
324
330 @Override
331 public String toString() {
332 return toString(false);
333 }
334
341 public String toDecimal(int precision) {
342 return Native.rcfNumToDecimalString(getContext().nCtx(),
343 getNativeObject(), precision);
344 }
345
346 @Override
347 void incRef() {
348 // RCF numerals don't use standard reference counting
349 // They are managed through Z3_rcf_del
350 }
351
352 @Override
353 void addToReferenceQueue() {
354 getContext().getReferenceQueue().storeReference(this, RCFNumRef::new);
355 }
356
357 private static class RCFNumRef extends Z3ReferenceQueue.Reference<RCFNum> {
358
359 private RCFNumRef(RCFNum referent, java.lang.ref.ReferenceQueue<Z3Object> q) {
360 super(referent, q);
361 }
362
363 @Override
364 void decRef(Context ctx, long z3Obj) {
365 Native.rcfDel(ctx.nCtx(), z3Obj);
366 }
367 }
368
369 private void checkContext(RCFNum other) {
370 if (getContext() != other.getContext()) {
371 throw new Z3Exception("RCF numerals from different contexts");
372 }
373 }
374}
RCFNum add(RCFNum other)
Definition RCFNum.java:129
boolean ge(RCFNum other)
Definition RCFNum.java:248
boolean eq(RCFNum other)
Definition RCFNum.java:260
RCFNum mul(RCFNum other)
Definition RCFNum.java:155
static RCFNum mkE(Context ctx)
Definition RCFNum.java:76
RCFNum power(int k)
Definition RCFNum.java:201
boolean lt(RCFNum other)
Definition RCFNum.java:212
static RCFNum mkPi(Context ctx)
Definition RCFNum.java:66
String toString(boolean compact)
Definition RCFNum.java:320
static RCFNum[] mkRoots(Context ctx, RCFNum[] coefficients)
Definition RCFNum.java:100
RCFNum sub(RCFNum other)
Definition RCFNum.java:142
boolean isTranscendental()
Definition RCFNum.java:310
RCFNum(Context ctx, String value)
Definition RCFNum.java:39
boolean le(RCFNum other)
Definition RCFNum.java:236
static RCFNum mkInfinitesimal(Context ctx)
Definition RCFNum.java:86
boolean gt(RCFNum other)
Definition RCFNum.java:224
String toDecimal(int precision)
Definition RCFNum.java:341
RCFNum div(RCFNum other)
Definition RCFNum.java:168
RCFNum(Context ctx, int value)
Definition RCFNum.java:49
boolean neq(RCFNum other)
Definition RCFNum.java:272
boolean isInfinitesimal()
Definition RCFNum.java:301