-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathContext.java
4348 lines (3894 loc) · 134 KB
/
Context.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
Copyright (c) 2012-2014 Microsoft Corporation
Module Name:
Context.java
Abstract:
Author:
@author Christoph Wintersteiger (cwinter) 2012-03-15
Notes:
**/
package com.microsoft.z3;
import static com.microsoft.z3.Constructor.of;
import com.microsoft.z3.enumerations.Z3_ast_print_mode;
import java.util.Map;
/**
* The main interaction with Z3 happens via the Context.
* For applications that spawn an unbounded number of contexts,
* the proper use is within a try-with-resources
* scope so that the Context object gets garbage collected in
* a predictable way. Contexts maintain all data-structures
* related to terms and formulas that are created relative
* to them.
**/
@SuppressWarnings("unchecked")
public class Context implements AutoCloseable {
private long m_ctx;
static final Object creation_lock = new Object();
public Context () {
synchronized (creation_lock) {
m_ctx = Native.mkContextRc(0);
init();
}
}
protected Context (long m_ctx) {
synchronized (creation_lock) {
this.m_ctx = m_ctx;
init();
}
}
/**
* Constructor.
* Remarks:
* The following parameters can be set:
* - proof (Boolean) Enable proof generation
* - debug_ref_count (Boolean) Enable debug support for Z3_ast reference counting
* - trace (Boolean) Tracing support for VCC
* - trace_file_name (String) Trace out file for VCC traces
* - timeout (unsigned) default timeout (in milliseconds) used for solvers
* - well_sorted_check type checker
* - auto_config use heuristics to automatically select solver and configure it
* - model model generation for solvers, this parameter can be overwritten when creating a solver
* - model_validate validate models produced by solvers
* - unsat_core unsat-core generation for solvers, this parameter can be overwritten when creating a solver
* Note that in previous versions of Z3, this constructor was also used to set global and
* module parameters. For this purpose we should now use {@code Global.setParameter}
**/
public Context(Map<String, String> settings) {
synchronized (creation_lock) {
long cfg = Native.mkConfig();
for (Map.Entry<String, String> kv : settings.entrySet()) {
Native.setParamValue(cfg, kv.getKey(), kv.getValue());
}
m_ctx = Native.mkContextRc(cfg);
Native.delConfig(cfg);
init();
}
}
private void init() {
setPrintMode(Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT);
Native.setInternalErrorHandler(m_ctx);
}
/**
* Creates a new symbol using an integer.
* Remarks: Not all integers can be passed to this function.
* The legal range of unsigned integers is 0 to 2^30-1.
**/
public IntSymbol mkSymbol(int i)
{
return new IntSymbol(this, i);
}
/**
* Create a symbol using a string.
**/
public StringSymbol mkSymbol(String name)
{
return new StringSymbol(this, name);
}
/**
* Create an array of symbols.
**/
Symbol[] mkSymbols(String[] names)
{
if (names == null)
return new Symbol[0];
Symbol[] result = new Symbol[names.length];
for (int i = 0; i < names.length; ++i)
result[i] = mkSymbol(names[i]);
return result;
}
private BoolSort m_boolSort = null;
private IntSort m_intSort = null;
private RealSort m_realSort = null;
private SeqSort<CharSort> m_stringSort = null;
/**
* Retrieves the Boolean sort of the context.
**/
public BoolSort getBoolSort()
{
if (m_boolSort == null) {
m_boolSort = new BoolSort(this);
}
return m_boolSort;
}
/**
* Retrieves the Integer sort of the context.
**/
public IntSort getIntSort()
{
if (m_intSort == null) {
m_intSort = new IntSort(this);
}
return m_intSort;
}
/**
* Retrieves the Real sort of the context.
**/
public RealSort getRealSort()
{
if (m_realSort == null) {
m_realSort = new RealSort(this);
}
return m_realSort;
}
/**
* Create a new Boolean sort.
**/
public BoolSort mkBoolSort()
{
return new BoolSort(this);
}
/**
* Creates character sort object.
**/
public CharSort mkCharSort()
{
return new CharSort(this);
}
/**
* Retrieves the String sort of the context.
**/
public SeqSort<CharSort> getStringSort()
{
if (m_stringSort == null) {
m_stringSort = mkStringSort();
}
return m_stringSort;
}
/**
* Create a new uninterpreted sort.
**/
public UninterpretedSort mkUninterpretedSort(Symbol s)
{
checkContextMatch(s);
return new UninterpretedSort(this, s);
}
/**
* Create a new uninterpreted sort.
**/
public UninterpretedSort mkUninterpretedSort(String str)
{
return mkUninterpretedSort(mkSymbol(str));
}
/**
* Create a new integer sort.
**/
public IntSort mkIntSort()
{
return new IntSort(this);
}
/**
* Create a real sort.
**/
public RealSort mkRealSort()
{
return new RealSort(this);
}
/**
* Create a new bit-vector sort.
**/
public BitVecSort mkBitVecSort(int size)
{
return new BitVecSort(this, Native.mkBvSort(nCtx(), size));
}
/**
* Create a new array sort.
**/
public final <D extends Sort, R extends Sort> ArraySort<D, R> mkArraySort(D domain, R range)
{
checkContextMatch(domain);
checkContextMatch(range);
return new ArraySort<>(this, domain, range);
}
/**
* Create a new array sort.
**/
public final <R extends Sort> ArraySort<Sort, R> mkArraySort(Sort[] domains, R range)
{
checkContextMatch(domains);
checkContextMatch(range);
return new ArraySort<>(this, domains, range);
}
/**
* Create a new string sort
**/
public SeqSort<CharSort> mkStringSort()
{
return new SeqSort<>(this, Native.mkStringSort(nCtx()));
}
/**
* Create a new sequence sort
**/
public final <R extends Sort> SeqSort<R> mkSeqSort(R s)
{
return new SeqSort<>(this, Native.mkSeqSort(nCtx(), s.getNativeObject()));
}
/**
* Create a new regular expression sort
**/
public final <R extends Sort> ReSort<R> mkReSort(R s)
{
return new ReSort<>(this, Native.mkReSort(nCtx(), s.getNativeObject()));
}
/**
* Create a new tuple sort.
**/
public TupleSort mkTupleSort(Symbol name, Symbol[] fieldNames,
Sort[] fieldSorts)
{
checkContextMatch(name);
checkContextMatch(fieldNames);
checkContextMatch(fieldSorts);
return new TupleSort(this, name, fieldNames.length, fieldNames,
fieldSorts);
}
/**
* Create a new enumeration sort.
**/
public final <R> EnumSort<R> mkEnumSort(Symbol name, Symbol... enumNames)
{
checkContextMatch(name);
checkContextMatch(enumNames);
return new EnumSort<>(this, name, enumNames);
}
/**
* Create a new enumeration sort.
**/
public final <R> EnumSort<R> mkEnumSort(String name, String... enumNames)
{
return new EnumSort<>(this, mkSymbol(name), mkSymbols(enumNames));
}
/**
* Create a new list sort.
**/
public final <R extends Sort> ListSort<R> mkListSort(Symbol name, R elemSort)
{
checkContextMatch(name);
checkContextMatch(elemSort);
return new ListSort<>(this, name, elemSort);
}
/**
* Create a new list sort.
**/
public final <R extends Sort> ListSort<R> mkListSort(String name, R elemSort)
{
checkContextMatch(elemSort);
return new ListSort<>(this, mkSymbol(name), elemSort);
}
/**
* Create a new finite domain sort.
**/
public final <R> FiniteDomainSort<R> mkFiniteDomainSort(Symbol name, long size)
{
checkContextMatch(name);
return new FiniteDomainSort<>(this, name, size);
}
/**
* Create a new finite domain sort.
**/
public final <R> FiniteDomainSort<R> mkFiniteDomainSort(String name, long size)
{
return new FiniteDomainSort<>(this, mkSymbol(name), size);
}
/**
* Create a datatype constructor.
* @param name constructor name
* @param recognizer name of recognizer function.
* @param fieldNames names of the constructor fields.
* @param sorts field sorts, 0 if the field sort refers to a recursive sort.
* @param sortRefs reference to datatype sort that is an argument to the
* constructor; if the corresponding sort reference is 0, then the value in sort_refs should be
* an index referring to one of the recursive datatypes that is
* declared.
**/
public final <R> Constructor<R> mkConstructor(Symbol name, Symbol recognizer,
Symbol[] fieldNames, Sort[] sorts, int[] sortRefs)
{
return of(this, name, recognizer, fieldNames, sorts, sortRefs);
}
/**
* Create a datatype constructor.
**/
public final <R> Constructor<R> mkConstructor(String name, String recognizer,
String[] fieldNames, Sort[] sorts, int[] sortRefs)
{
return of(this, mkSymbol(name), mkSymbol(recognizer), mkSymbols(fieldNames), sorts, sortRefs);
}
/**
* Create a new datatype sort.
**/
public final <R> DatatypeSort<R> mkDatatypeSort(Symbol name, Constructor<R>[] constructors)
{
checkContextMatch(name);
checkContextMatch(constructors);
return new DatatypeSort<>(this, name, constructors);
}
/**
* Create a new datatype sort.
**/
public final <R> DatatypeSort<R> mkDatatypeSort(String name, Constructor<R>[] constructors)
{
checkContextMatch(constructors);
return new DatatypeSort<>(this, mkSymbol(name), constructors);
}
/**
* Create mutually recursive datatypes.
* @param names names of datatype sorts
* @param c list of constructors, one list per sort.
**/
public DatatypeSort<Object>[] mkDatatypeSorts(Symbol[] names, Constructor<Object>[][] c)
{
checkContextMatch(names);
int n = names.length;
ConstructorList<Object>[] cla = new ConstructorList[n];
long[] n_constr = new long[n];
for (int i = 0; i < n; i++)
{
Constructor<Object>[] constructor = c[i];
checkContextMatch(constructor);
cla[i] = new ConstructorList<>(this, constructor);
n_constr[i] = cla[i].getNativeObject();
}
long[] n_res = new long[n];
Native.mkDatatypes(nCtx(), n, Symbol.arrayToNative(names), n_res,
n_constr);
DatatypeSort<Object>[] res = new DatatypeSort[n];
for (int i = 0; i < n; i++)
res[i] = new DatatypeSort<>(this, n_res[i]);
return res;
}
/**
* Create mutually recursive data-types.
**/
public DatatypeSort<Object>[] mkDatatypeSorts(String[] names, Constructor<Object>[][] c)
{
return mkDatatypeSorts(mkSymbols(names), c);
}
/**
* Update a datatype field at expression t with value v.
* The function performs a record update at t. The field
* that is passed in as argument is updated with value v,
* the remaining fields of t are unchanged.
**/
public final <F extends Sort, R extends Sort> Expr<R> mkUpdateField(FuncDecl<F> field, Expr<R> t, Expr<F> v)
throws Z3Exception
{
return (Expr<R>) Expr.create(this,
Native.datatypeUpdateField
(nCtx(), field.getNativeObject(),
t.getNativeObject(), v.getNativeObject()));
}
/**
* Creates a new function declaration.
**/
public final <R extends Sort> FuncDecl<R> mkFuncDecl(Symbol name, Sort[] domain, R range)
{
checkContextMatch(name);
checkContextMatch(domain);
checkContextMatch(range);
return new FuncDecl<>(this, name, domain, range);
}
public final <R extends Sort> FuncDecl<R> mkPropagateFunction(Symbol name, Sort[] domain, R range)
{
checkContextMatch(name);
checkContextMatch(domain);
checkContextMatch(range);
long f = Native.solverPropagateDeclare(
this.nCtx(),
name.getNativeObject(),
AST.arrayLength(domain),
AST.arrayToNative(domain),
range.getNativeObject());
return new FuncDecl<>(this, f);
}
/**
* Creates a new function declaration.
**/
public final <R extends Sort> FuncDecl<R> mkFuncDecl(Symbol name, Sort domain, R range)
{
checkContextMatch(name);
checkContextMatch(domain);
checkContextMatch(range);
Sort[] q = new Sort[] { domain };
return new FuncDecl<>(this, name, q, range);
}
/**
* Creates a new function declaration.
**/
public final <R extends Sort> FuncDecl<R> mkFuncDecl(String name, Sort[] domain, R range)
{
checkContextMatch(domain);
checkContextMatch(range);
return new FuncDecl<>(this, mkSymbol(name), domain, range);
}
/**
* Creates a new function declaration.
**/
public final <R extends Sort> FuncDecl<R> mkFuncDecl(String name, Sort domain, R range)
{
checkContextMatch(domain);
checkContextMatch(range);
Sort[] q = new Sort[] { domain };
return new FuncDecl<>(this, mkSymbol(name), q, range);
}
/**
* Creates a new recursive function declaration.
**/
public final <R extends Sort> FuncDecl<R> mkRecFuncDecl(Symbol name, Sort[] domain, R range)
{
checkContextMatch(name);
checkContextMatch(domain);
checkContextMatch(range);
return new FuncDecl<>(this, name, domain, range, true);
}
/**
* Bind a definition to a recursive function declaration.
* The function must have previously been created using
* MkRecFuncDecl. The body may contain recursive uses of the function or
* other mutually recursive functions.
*/
public final <R extends Sort> void AddRecDef(FuncDecl<R> f, Expr<?>[] args, Expr<R> body)
{
checkContextMatch(f);
checkContextMatch(args);
checkContextMatch(body);
long[] argsNative = AST.arrayToNative(args);
Native.addRecDef(nCtx(), f.getNativeObject(), args.length, argsNative, body.getNativeObject());
}
/**
* Creates a fresh function declaration with a name prefixed with
* {@code prefix}.
* @see #mkFuncDecl(String,Sort,Sort)
* @see #mkFuncDecl(String,Sort[],Sort)
**/
public final <R extends Sort> FuncDecl<R> mkFreshFuncDecl(String prefix, Sort[] domain, R range)
{
checkContextMatch(domain);
checkContextMatch(range);
return new FuncDecl<>(this, prefix, domain, range);
}
/**
* Creates a new constant function declaration.
**/
public final <R extends Sort> FuncDecl<R> mkConstDecl(Symbol name, R range)
{
checkContextMatch(name);
checkContextMatch(range);
return new FuncDecl<>(this, name, null, range);
}
/**
* Creates a new constant function declaration.
**/
public final <R extends Sort> FuncDecl<R> mkConstDecl(String name, R range)
{
checkContextMatch(range);
return new FuncDecl<>(this, mkSymbol(name), null, range);
}
/**
* Creates a fresh constant function declaration with a name prefixed with
* {@code prefix}.
* @see #mkFuncDecl(String,Sort,Sort)
* @see #mkFuncDecl(String,Sort[],Sort)
**/
public final <R extends Sort> FuncDecl<R> mkFreshConstDecl(String prefix, R range)
{
checkContextMatch(range);
return new FuncDecl<>(this, prefix, null, range);
}
/**
* Creates a new bound variable.
* @param index The de-Bruijn index of the variable
* @param ty The sort of the variable
**/
public final <R extends Sort> Expr<R> mkBound(int index, R ty)
{
return (Expr<R>) Expr.create(this,
Native.mkBound(nCtx(), index, ty.getNativeObject()));
}
/**
* Create a quantifier pattern.
**/
@SafeVarargs
public final Pattern mkPattern(Expr<?>... terms)
{
if (terms.length == 0)
throw new Z3Exception("Cannot create a pattern from zero terms");
long[] termsNative = AST.arrayToNative(terms);
return new Pattern(this, Native.mkPattern(nCtx(), terms.length,
termsNative));
}
/**
* Creates a new Constant of sort {@code range} and named
* {@code name}.
**/
public final <R extends Sort> Expr<R> mkConst(Symbol name, R range)
{
checkContextMatch(name);
checkContextMatch(range);
return (Expr<R>) Expr.create(
this,
Native.mkConst(nCtx(), name.getNativeObject(),
range.getNativeObject()));
}
/**
* Creates a new Constant of sort {@code range} and named
* {@code name}.
**/
public final <R extends Sort> Expr<R> mkConst(String name, R range)
{
return mkConst(mkSymbol(name), range);
}
/**
* Creates a fresh Constant of sort {@code range} and a name
* prefixed with {@code prefix}.
**/
public final <R extends Sort> Expr<R> mkFreshConst(String prefix, R range)
{
checkContextMatch(range);
return (Expr<R>) Expr.create(this,
Native.mkFreshConst(nCtx(), prefix, range.getNativeObject()));
}
/**
* Creates a fresh constant from the FuncDecl {@code f}.
* @param f A decl of a 0-arity function
**/
public final <R extends Sort> Expr<R> mkConst(FuncDecl<R> f)
{
return mkApp(f, (Expr<?>[]) null);
}
/**
* Create a Boolean constant.
**/
public BoolExpr mkBoolConst(Symbol name)
{
return (BoolExpr) mkConst(name, getBoolSort());
}
/**
* Create a Boolean constant.
**/
public BoolExpr mkBoolConst(String name)
{
return (BoolExpr) mkConst(mkSymbol(name), getBoolSort());
}
/**
* Creates an integer constant.
**/
public IntExpr mkIntConst(Symbol name)
{
return (IntExpr) mkConst(name, getIntSort());
}
/**
* Creates an integer constant.
**/
public IntExpr mkIntConst(String name)
{
return (IntExpr) mkConst(name, getIntSort());
}
/**
* Creates a real constant.
**/
public RealExpr mkRealConst(Symbol name)
{
return (RealExpr) mkConst(name, getRealSort());
}
/**
* Creates a real constant.
**/
public RealExpr mkRealConst(String name)
{
return (RealExpr) mkConst(name, getRealSort());
}
/**
* Creates a bit-vector constant.
**/
public BitVecExpr mkBVConst(Symbol name, int size)
{
return (BitVecExpr) mkConst(name, mkBitVecSort(size));
}
/**
* Creates a bit-vector constant.
**/
public BitVecExpr mkBVConst(String name, int size)
{
return (BitVecExpr) mkConst(name, mkBitVecSort(size));
}
/**
* Create a new function application.
**/
@SafeVarargs
public final <R extends Sort> Expr<R> mkApp(FuncDecl<R> f, Expr<?>... args)
{
checkContextMatch(f);
checkContextMatch(args);
return Expr.create(this, f, args);
}
/**
* The true Term.
**/
public BoolExpr mkTrue()
{
return new BoolExpr(this, Native.mkTrue(nCtx()));
}
/**
* The false Term.
**/
public BoolExpr mkFalse()
{
return new BoolExpr(this, Native.mkFalse(nCtx()));
}
/**
* Creates a Boolean value.
**/
public BoolExpr mkBool(boolean value)
{
return value ? mkTrue() : mkFalse();
}
/**
* Creates the equality {@code x = y}
**/
public BoolExpr mkEq(Expr<?> x, Expr<?> y)
{
checkContextMatch(x);
checkContextMatch(y);
return new BoolExpr(this, Native.mkEq(nCtx(), x.getNativeObject(),
y.getNativeObject()));
}
/**
* Creates a {@code distinct} term.
**/
@SafeVarargs
public final BoolExpr mkDistinct(Expr<?>... args)
{
checkContextMatch(args);
return new BoolExpr(this, Native.mkDistinct(nCtx(), args.length,
AST.arrayToNative(args)));
}
/**
* Create an expression representing {@code not(a)}.
**/
public final BoolExpr mkNot(Expr<BoolSort> a)
{
checkContextMatch(a);
return new BoolExpr(this, Native.mkNot(nCtx(), a.getNativeObject()));
}
/**
* Create an expression representing an if-then-else:
* {@code ite(t1, t2, t3)}.
* @param t1 An expression with Boolean sort
* @param t2 An expression
* @param t3 An expression with the same sort as {@code t2}
**/
public final <R extends Sort> Expr<R> mkITE(Expr<BoolSort> t1, Expr<? extends R> t2, Expr<? extends R> t3)
{
checkContextMatch(t1);
checkContextMatch(t2);
checkContextMatch(t3);
return (Expr<R>) Expr.create(this, Native.mkIte(nCtx(), t1.getNativeObject(),
t2.getNativeObject(), t3.getNativeObject()));
}
/**
* Create an expression representing {@code t1 iff t2}.
**/
public BoolExpr mkIff(Expr<BoolSort> t1, Expr<BoolSort> t2)
{
checkContextMatch(t1);
checkContextMatch(t2);
return new BoolExpr(this, Native.mkIff(nCtx(), t1.getNativeObject(),
t2.getNativeObject()));
}
/**
* Create an expression representing {@code t1 -> t2}.
**/
public BoolExpr mkImplies(Expr<BoolSort> t1, Expr<BoolSort> t2)
{
checkContextMatch(t1);
checkContextMatch(t2);
return new BoolExpr(this, Native.mkImplies(nCtx(),
t1.getNativeObject(), t2.getNativeObject()));
}
/**
* Create an expression representing {@code t1 xor t2}.
**/
public BoolExpr mkXor(Expr<BoolSort> t1, Expr<BoolSort> t2)
{
checkContextMatch(t1);
checkContextMatch(t2);
return new BoolExpr(this, Native.mkXor(nCtx(), t1.getNativeObject(),
t2.getNativeObject()));
}
/**
* Create an expression representing {@code t[0] and t[1] and ...}.
**/
@SafeVarargs
public final BoolExpr mkAnd(Expr<BoolSort>... t)
{
checkContextMatch(t);
return new BoolExpr(this, Native.mkAnd(nCtx(), t.length,
AST.arrayToNative(t)));
}
/**
* Create an expression representing {@code t[0] or t[1] or ...}.
**/
@SafeVarargs
public final BoolExpr mkOr(Expr<BoolSort>... t)
{
checkContextMatch(t);
return new BoolExpr(this, Native.mkOr(nCtx(), t.length,
AST.arrayToNative(t)));
}
/**
* Create an expression representing {@code t[0] + t[1] + ...}.
**/
@SafeVarargs
public final <R extends ArithSort> ArithExpr<R> mkAdd(Expr<? extends R>... t)
{
checkContextMatch(t);
return (ArithExpr<R>) Expr.create(this,
Native.mkAdd(nCtx(), t.length, AST.arrayToNative(t)));
}
/**
* Create an expression representing {@code t[0] * t[1] * ...}.
**/
@SafeVarargs
public final <R extends ArithSort> ArithExpr<R> mkMul(Expr<? extends R>... t)
{
checkContextMatch(t);
return (ArithExpr<R>) Expr.create(this,
Native.mkMul(nCtx(), t.length, AST.arrayToNative(t)));
}
/**
* Create an expression representing {@code t[0] - t[1] - ...}.
**/
@SafeVarargs
public final <R extends ArithSort> ArithExpr<R> mkSub(Expr<? extends R>... t)
{
checkContextMatch(t);
return (ArithExpr<R>) Expr.create(this,
Native.mkSub(nCtx(), t.length, AST.arrayToNative(t)));
}
/**
* Create an expression representing {@code -t}.
**/
public final <R extends ArithSort> ArithExpr<R> mkUnaryMinus(Expr<R> t)
{
checkContextMatch(t);
return (ArithExpr<R>) Expr.create(this,
Native.mkUnaryMinus(nCtx(), t.getNativeObject()));
}
/**
* Create an expression representing {@code t1 / t2}.
**/
public final <R extends ArithSort> ArithExpr<R> mkDiv(Expr<? extends R> t1, Expr<? extends R> t2)
{
checkContextMatch(t1);
checkContextMatch(t2);
return (ArithExpr<R>) Expr.create(this, Native.mkDiv(nCtx(),
t1.getNativeObject(), t2.getNativeObject()));
}
/**
* Create an expression representing {@code t1 mod t2}.
* Remarks: The
* arguments must have int type.
**/
public IntExpr mkMod(Expr<IntSort> t1, Expr<IntSort> t2)
{
checkContextMatch(t1);
checkContextMatch(t2);
return new IntExpr(this, Native.mkMod(nCtx(), t1.getNativeObject(),
t2.getNativeObject()));
}
/**
* Create an expression representing {@code t1 rem t2}.
* Remarks: The
* arguments must have int type.
**/
public IntExpr mkRem(Expr<IntSort> t1, Expr<IntSort> t2)
{
checkContextMatch(t1);
checkContextMatch(t2);
return new IntExpr(this, Native.mkRem(nCtx(), t1.getNativeObject(),
t2.getNativeObject()));
}
/**
* Create an expression representing {@code t1 ^ t2}.
**/
public final <R extends ArithSort> ArithExpr<R> mkPower(Expr<? extends R> t1,
Expr<? extends R> t2)
{
checkContextMatch(t1);
checkContextMatch(t2);
return (ArithExpr<R>) Expr.create(
this,
Native.mkPower(nCtx(), t1.getNativeObject(),
t2.getNativeObject()));
}
/**
* Create an expression representing {@code t1 < t2}
**/
public BoolExpr mkLt(Expr<? extends ArithSort> t1, Expr<? extends ArithSort> t2)
{
checkContextMatch(t1);
checkContextMatch(t2);
return new BoolExpr(this, Native.mkLt(nCtx(), t1.getNativeObject(),
t2.getNativeObject()));
}
/**
* Create an expression representing {@code t1 <= t2}
**/
public BoolExpr mkLe(Expr<? extends ArithSort> t1, Expr<? extends ArithSort> t2)
{
checkContextMatch(t1);
checkContextMatch(t2);
return new BoolExpr(this, Native.mkLe(nCtx(), t1.getNativeObject(),
t2.getNativeObject()));
}
/**
* Create an expression representing {@code t1 > t2}
**/
public BoolExpr mkGt(Expr<? extends ArithSort> t1, Expr<? extends ArithSort> t2)
{
checkContextMatch(t1);
checkContextMatch(t2);
return new BoolExpr(this, Native.mkGt(nCtx(), t1.getNativeObject(),
t2.getNativeObject()));
}
/**
* Create an expression representing {@code t1 >= t2}
**/
public BoolExpr mkGe(Expr<? extends ArithSort> t1, Expr<? extends ArithSort> t2)
{
checkContextMatch(t1);
checkContextMatch(t2);
return new BoolExpr(this, Native.mkGe(nCtx(), t1.getNativeObject(),
t2.getNativeObject()));
}
/**
* Coerce an integer to a real.
* Remarks: There is also a converse operation
* exposed. It follows the semantics prescribed by the SMT-LIB standard.
*
* You can take the floor of a real by creating an auxiliary integer Term
* {@code k} and asserting
* {@code MakeInt2Real(k) <= t1 < MkInt2Real(k)+1}. The argument
* must be of integer sort.
**/
public RealExpr mkInt2Real(Expr<IntSort> t)
{
checkContextMatch(t);
return new RealExpr(this,