GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/api/cpp/cvc5.h Lines: 24 28 85.7 %
Date: 2021-11-05 Branches: 3 6 50.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Aina Niemetz, Andrew Reynolds, Abdalrhman Mohamed
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * The cvc5 C++ API.
14
 */
15
16
#include "cvc5_export.h"
17
18
#ifndef CVC5__API__CVC5_H
19
#define CVC5__API__CVC5_H
20
21
#include <map>
22
#include <memory>
23
#include <optional>
24
#include <set>
25
#include <sstream>
26
#include <string>
27
#include <unordered_map>
28
#include <unordered_set>
29
#include <variant>
30
#include <vector>
31
32
#include "api/cpp/cvc5_kind.h"
33
34
namespace cvc5 {
35
36
#ifndef DOXYGEN_SKIP
37
template <bool ref_count>
38
class NodeTemplate;
39
typedef NodeTemplate<true> Node;
40
#endif
41
42
class Command;
43
class DType;
44
class DTypeConstructor;
45
class DTypeSelector;
46
class NodeManager;
47
class SolverEngine;
48
class TypeNode;
49
class Options;
50
class Random;
51
class Result;
52
class StatisticsRegistry;
53
54
namespace main {
55
class CommandExecutor;
56
}
57
58
namespace api {
59
60
class Solver;
61
class Statistics;
62
struct APIStatistics;
63
64
/* -------------------------------------------------------------------------- */
65
/* Exception                                                                  */
66
/* -------------------------------------------------------------------------- */
67
68
/**
69
 * Base class for all API exceptions.
70
 * If thrown, all API objects may be in an unsafe state.
71
 */
72
1392
class CVC5_EXPORT CVC5ApiException : public std::exception
73
{
74
 public:
75
  /**
76
   * Construct with message from a string.
77
   * @param str The error message.
78
   */
79
1392
  CVC5ApiException(const std::string& str) : d_msg(str) {}
80
  /**
81
   * Construct with message from a string stream.
82
   * @param stream The error message.
83
   */
84
  CVC5ApiException(const std::stringstream& stream) : d_msg(stream.str()) {}
85
  /**
86
   * Retrieve the message from this exception.
87
   * @return The error message.
88
   */
89
  const std::string& getMessage() const { return d_msg; }
90
  /**
91
   * Retrieve the message as a C-style array.
92
   * @return The error message.
93
   */
94
74
  const char* what() const noexcept override { return d_msg.c_str(); }
95
96
 private:
97
  /** The stored error message. */
98
  std::string d_msg;
99
};
100
101
/**
102
 * A recoverable API exception.
103
 * If thrown, API objects can still be used.
104
 */
105
84
class CVC5_EXPORT CVC5ApiRecoverableException : public CVC5ApiException
106
{
107
 public:
108
  /**
109
   * Construct with message from a string.
110
   * @param str The error message.
111
   */
112
84
  CVC5ApiRecoverableException(const std::string& str) : CVC5ApiException(str) {}
113
  /**
114
   * Construct with message from a string stream.
115
   * @param stream The error message.
116
   */
117
  CVC5ApiRecoverableException(const std::stringstream& stream)
118
      : CVC5ApiException(stream.str())
119
  {
120
  }
121
};
122
123
/**
124
 * An option-related API exception.
125
 * If thrown, API objects can still be used.
126
 */
127
5
class CVC5_EXPORT CVC5ApiOptionException : public CVC5ApiRecoverableException
128
{
129
 public:
130
  /**
131
   * Construct with message from a string.
132
   * @param str The error message.
133
   */
134
5
  CVC5ApiOptionException(const std::string& str)
135
5
      : CVC5ApiRecoverableException(str)
136
  {
137
5
  }
138
  /**
139
   * Construct with message from a string stream.
140
   * @param stream The error message.
141
   */
142
  CVC5ApiOptionException(const std::stringstream& stream)
143
      : CVC5ApiRecoverableException(stream.str())
144
  {
145
  }
146
};
147
148
/* -------------------------------------------------------------------------- */
149
/* Result                                                                     */
150
/* -------------------------------------------------------------------------- */
151
152
/**
153
 * Encapsulation of a three-valued solver result, with explanations.
154
 */
155
356284
class CVC5_EXPORT Result
156
{
157
  friend class Solver;
158
159
 public:
160
  enum UnknownExplanation
161
  {
162
    REQUIRES_FULL_CHECK,
163
    INCOMPLETE,
164
    TIMEOUT,
165
    RESOURCEOUT,
166
    MEMOUT,
167
    INTERRUPTED,
168
    NO_STATUS,
169
    UNSUPPORTED,
170
    OTHER,
171
    UNKNOWN_REASON
172
  };
173
174
  /** Constructor. */
175
  Result();
176
177
  /**
178
   * Return true if Result is empty, i.e., a nullary Result, and not an actual
179
   * result returned from a checkSat() (and friends) query.
180
   */
181
  bool isNull() const;
182
183
  /**
184
   * Return true if query was a satisfiable checkSat() or checkSatAssuming()
185
   * query.
186
   */
187
  bool isSat() const;
188
189
  /**
190
   * Return true if query was an unsatisfiable checkSat() or
191
   * checkSatAssuming() query.
192
   */
193
  bool isUnsat() const;
194
195
  /**
196
   * Return true if query was a checkSat() or checkSatAssuming() query and
197
   * cvc5 was not able to determine (un)satisfiability.
198
   */
199
  bool isSatUnknown() const;
200
201
  /**
202
   * Return true if corresponding query was an entailed checkEntailed() query.
203
   */
204
  bool isEntailed() const;
205
206
  /**
207
   * Return true if corresponding query was a checkEntailed() query that is
208
   * not entailed.
209
   */
210
  bool isNotEntailed() const;
211
212
  /**
213
   * Return true if query was a checkEntailed() query and cvc5 was not able to
214
   * determine if it is entailed.
215
   */
216
  bool isEntailmentUnknown() const;
217
218
  /**
219
   * Operator overloading for equality of two results.
220
   * @param r the result to compare to for equality
221
   * @return true if the results are equal
222
   */
223
  bool operator==(const Result& r) const;
224
225
  /**
226
   * Operator overloading for disequality of two results.
227
   * @param r the result to compare to for disequality
228
   * @return true if the results are disequal
229
   */
230
  bool operator!=(const Result& r) const;
231
232
  /**
233
   * @return an explanation for an unknown query result.
234
   */
235
  UnknownExplanation getUnknownExplanation() const;
236
237
  /**
238
   * @return a string representation of this result.
239
   */
240
  std::string toString() const;
241
242
 private:
243
  /**
244
   * Constructor.
245
   * @param r the internal result that is to be wrapped by this result
246
   * @return the Result
247
   */
248
  Result(const cvc5::Result& r);
249
250
  /**
251
   * The interal result wrapped by this result.
252
   * Note: This is a shared_ptr rather than a unique_ptr since cvc5::Result is
253
   *       not ref counted.
254
   */
255
  std::shared_ptr<cvc5::Result> d_result;
256
};
257
258
/**
259
 * Serialize a Result to given stream.
260
 * @param out the output stream
261
 * @param r the result to be serialized to the given output stream
262
 * @return the output stream
263
 */
264
std::ostream& operator<<(std::ostream& out, const Result& r) CVC5_EXPORT;
265
266
/**
267
 * Serialize an UnknownExplanation to given stream.
268
 * @param out the output stream
269
 * @param e the explanation to be serialized to the given output stream
270
 * @return the output stream
271
 */
272
std::ostream& operator<<(std::ostream& out,
273
                         enum Result::UnknownExplanation e) CVC5_EXPORT;
274
275
/* -------------------------------------------------------------------------- */
276
/* Sort                                                                       */
277
/* -------------------------------------------------------------------------- */
278
279
class Datatype;
280
281
/**
282
 * The sort of a cvc5 term.
283
 */
284
6607996
class CVC5_EXPORT Sort
285
{
286
  friend class cvc5::Command;
287
  friend class DatatypeConstructor;
288
  friend class DatatypeConstructorDecl;
289
  friend class DatatypeSelector;
290
  friend class DatatypeDecl;
291
  friend class Op;
292
  friend class Solver;
293
  friend class Grammar;
294
  friend struct std::hash<Sort>;
295
  friend class Term;
296
297
 public:
298
  /**
299
   * Constructor.
300
   */
301
  Sort();
302
303
  /**
304
   * Destructor.
305
   */
306
  ~Sort();
307
308
  /**
309
   * Comparison for structural equality.
310
   * @param s the sort to compare to
311
   * @return true if the sorts are equal
312
   */
313
  bool operator==(const Sort& s) const;
314
315
  /**
316
   * Comparison for structural disequality.
317
   * @param s the sort to compare to
318
   * @return true if the sorts are not equal
319
   */
320
  bool operator!=(const Sort& s) const;
321
322
  /**
323
   * Comparison for ordering on sorts.
324
   * @param s the sort to compare to
325
   * @return true if this sort is less than s
326
   */
327
  bool operator<(const Sort& s) const;
328
329
  /**
330
   * Comparison for ordering on sorts.
331
   * @param s the sort to compare to
332
   * @return true if this sort is greater than s
333
   */
334
  bool operator>(const Sort& s) const;
335
336
  /**
337
   * Comparison for ordering on sorts.
338
   * @param s the sort to compare to
339
   * @return true if this sort is less than or equal to s
340
   */
341
  bool operator<=(const Sort& s) const;
342
343
  /**
344
   * Comparison for ordering on sorts.
345
   * @param s the sort to compare to
346
   * @return true if this sort is greater than or equal to s
347
   */
348
  bool operator>=(const Sort& s) const;
349
350
  /**
351
   * @return true if this Sort is a null sort.
352
   */
353
  bool isNull() const;
354
355
  /**
356
   * Is this a Boolean sort?
357
   * @return true if the sort is the Boolean sort
358
   */
359
  bool isBoolean() const;
360
361
  /**
362
   * Is this a integer sort?
363
   * @return true if the sort is the integer sort
364
   */
365
  bool isInteger() const;
366
367
  /**
368
   * Is this a real sort?
369
   * @return true if the sort is the real sort
370
   */
371
  bool isReal() const;
372
373
  /**
374
   * Is this a string sort?
375
   * @return true if the sort is the string sort
376
   */
377
  bool isString() const;
378
379
  /**
380
   * Is this a regexp sort?
381
   * @return true if the sort is the regexp sort
382
   */
383
  bool isRegExp() const;
384
385
  /**
386
   * Is this a rounding mode sort?
387
   * @return true if the sort is the rounding mode sort
388
   */
389
  bool isRoundingMode() const;
390
391
  /**
392
   * Is this a bit-vector sort?
393
   * @return true if the sort is a bit-vector sort
394
   */
395
  bool isBitVector() const;
396
397
  /**
398
   * Is this a floating-point sort?
399
   * @return true if the sort is a floating-point sort
400
   */
401
  bool isFloatingPoint() const;
402
403
  /**
404
   * Is this a datatype sort?
405
   * @return true if the sort is a datatype sort
406
   */
407
  bool isDatatype() const;
408
409
  /**
410
   * Is this a parametric datatype sort?
411
   * @return true if the sort is a parametric datatype sort
412
   */
413
  bool isParametricDatatype() const;
414
415
  /**
416
   * Is this a constructor sort?
417
   * @return true if the sort is a constructor sort
418
   */
419
  bool isConstructor() const;
420
421
  /**
422
   * Is this a selector sort?
423
   * @return true if the sort is a selector sort
424
   */
425
  bool isSelector() const;
426
427
  /**
428
   * Is this a tester sort?
429
   * @return true if the sort is a tester sort
430
   */
431
  bool isTester() const;
432
  /**
433
   * Is this a datatype updater sort?
434
   * @return true if the sort is a datatype updater sort
435
   */
436
  bool isUpdater() const;
437
  /**
438
   * Is this a function sort?
439
   * @return true if the sort is a function sort
440
   */
441
  bool isFunction() const;
442
443
  /**
444
   * Is this a predicate sort?
445
   * That is, is this a function sort mapping to Boolean? All predicate
446
   * sorts are also function sorts.
447
   * @return true if the sort is a predicate sort
448
   */
449
  bool isPredicate() const;
450
451
  /**
452
   * Is this a tuple sort?
453
   * @return true if the sort is a tuple sort
454
   */
455
  bool isTuple() const;
456
457
  /**
458
   * Is this a record sort?
459
   * @return true if the sort is a record sort
460
   */
461
  bool isRecord() const;
462
463
  /**
464
   * Is this an array sort?
465
   * @return true if the sort is an array sort
466
   */
467
  bool isArray() const;
468
469
  /**
470
   * Is this a Set sort?
471
   * @return true if the sort is a Set sort
472
   */
473
  bool isSet() const;
474
475
  /**
476
   * Is this a Bag sort?
477
   * @return true if the sort is a Bag sort
478
   */
479
  bool isBag() const;
480
481
  /**
482
   * Is this a Sequence sort?
483
   * @return true if the sort is a Sequence sort
484
   */
485
  bool isSequence() const;
486
487
  /**
488
   * Is this an uninterpreted sort?
489
   * @return true if this is an uninterpreted sort
490
   */
491
  bool isUninterpretedSort() const;
492
493
  /**
494
   * Is this a sort constructor kind?
495
   * @return true if this is a sort constructor kind
496
   */
497
  bool isSortConstructor() const;
498
499
  /**
500
   * Is this a first-class sort?
501
   * First-class sorts are sorts for which:
502
   * 1. we handle equalities between terms of that type, and
503
   * 2. they are allowed to be parameters of parametric sorts (e.g. index or
504
   * element sorts of arrays).
505
   *
506
   * Examples of sorts that are not first-class include sort constructor sorts
507
   * and regular expression sorts.
508
   *
509
   * @return true if this is a first-class sort
510
   */
511
  bool isFirstClass() const;
512
513
  /**
514
   * Is this a function-LIKE sort?
515
   *
516
   * Anything function-like except arrays (e.g., datatype selectors) is
517
   * considered a function here. Function-like terms can not be the argument
518
   * or return value for any term that is function-like.
519
   * This is mainly to avoid higher order.
520
   *
521
   * Note that arrays are explicitly not considered function-like here.
522
   *
523
   * @return true if this is a function-like sort
524
   */
525
  bool isFunctionLike() const;
526
527
  /**
528
   * Is this sort a subsort of the given sort?
529
   * @return true if this sort is a subsort of s
530
   */
531
  bool isSubsortOf(const Sort& s) const;
532
533
  /**
534
   * Is this sort comparable to the given sort (i.e., do they share
535
   * a common ancestor in the subsort tree)?
536
   * @return true if this sort is comparable to s
537
   */
538
  bool isComparableTo(const Sort& s) const;
539
540
  /**
541
   * @return the underlying datatype of a datatype sort
542
   */
543
  Datatype getDatatype() const;
544
545
  /**
546
   * Instantiate a parameterized datatype/sort sort.
547
   * Create sorts parameter with Solver::mkParamSort().
548
   * @param params the list of sort parameters to instantiate with
549
   */
550
  Sort instantiate(const std::vector<Sort>& params) const;
551
552
  /**
553
   * Substitution of Sorts.
554
   * @param sort the subsort to be substituted within this sort.
555
   * @param replacement the sort replacing the substituted subsort.
556
   */
557
  Sort substitute(const Sort& sort, const Sort& replacement) const;
558
559
  /**
560
   * Simultaneous substitution of Sorts.
561
   * @param sorts the subsorts to be substituted within this sort.
562
   * @param replacements the sort replacing the substituted subsorts.
563
   */
564
  Sort substitute(const std::vector<Sort>& sorts,
565
                  const std::vector<Sort>& replacements) const;
566
567
  /**
568
   * Output a string representation of this sort to a given stream.
569
   * @param out the output stream
570
   */
571
  void toStream(std::ostream& out) const;
572
573
  /**
574
   * @return a string representation of this sort
575
   */
576
  std::string toString() const;
577
578
  /* Constructor sort ------------------------------------------------------- */
579
580
  /**
581
   * @return the arity of a constructor sort
582
   */
583
  size_t getConstructorArity() const;
584
585
  /**
586
   * @return the domain sorts of a constructor sort
587
   */
588
  std::vector<Sort> getConstructorDomainSorts() const;
589
590
  /**
591
   * @return the codomain sort of a constructor sort
592
   */
593
  Sort getConstructorCodomainSort() const;
594
595
  /* Selector sort ------------------------------------------------------- */
596
597
  /**
598
   * @return the domain sort of a selector sort
599
   */
600
  Sort getSelectorDomainSort() const;
601
602
  /**
603
   * @return the codomain sort of a selector sort
604
   */
605
  Sort getSelectorCodomainSort() const;
606
607
  /* Tester sort ------------------------------------------------------- */
608
609
  /**
610
   * @return the domain sort of a tester sort
611
   */
612
  Sort getTesterDomainSort() const;
613
614
  /**
615
   * @return the codomain sort of a tester sort, which is the Boolean sort
616
   */
617
  Sort getTesterCodomainSort() const;
618
619
  /* Function sort ------------------------------------------------------- */
620
621
  /**
622
   * @return the arity of a function sort
623
   */
624
  size_t getFunctionArity() const;
625
626
  /**
627
   * @return the domain sorts of a function sort
628
   */
629
  std::vector<Sort> getFunctionDomainSorts() const;
630
631
  /**
632
   * @return the codomain sort of a function sort
633
   */
634
  Sort getFunctionCodomainSort() const;
635
636
  /* Array sort ---------------------------------------------------------- */
637
638
  /**
639
   * @return the array index sort of an array sort
640
   */
641
  Sort getArrayIndexSort() const;
642
643
  /**
644
   * @return the array element sort of an array sort
645
   */
646
  Sort getArrayElementSort() const;
647
648
  /* Set sort ------------------------------------------------------------ */
649
650
  /**
651
   * @return the element sort of a set sort
652
   */
653
  Sort getSetElementSort() const;
654
655
  /* Bag sort ------------------------------------------------------------ */
656
657
  /**
658
   * @return the element sort of a bag sort
659
   */
660
  Sort getBagElementSort() const;
661
662
  /* Sequence sort ------------------------------------------------------- */
663
664
  /**
665
   * @return the element sort of a sequence sort
666
   */
667
  Sort getSequenceElementSort() const;
668
669
  /* Uninterpreted sort -------------------------------------------------- */
670
671
  /**
672
   * @return the name of an uninterpreted sort
673
   */
674
  std::string getUninterpretedSortName() const;
675
676
  /**
677
   * @return true if an uninterpreted sort is parameterized
678
   */
679
  bool isUninterpretedSortParameterized() const;
680
681
  /**
682
   * @return the parameter sorts of an uninterpreted sort
683
   */
684
  std::vector<Sort> getUninterpretedSortParamSorts() const;
685
686
  /* Sort constructor sort ----------------------------------------------- */
687
688
  /**
689
   * @return the name of a sort constructor sort
690
   */
691
  std::string getSortConstructorName() const;
692
693
  /**
694
   * @return the arity of a sort constructor sort
695
   */
696
  size_t getSortConstructorArity() const;
697
698
  /* Bit-vector sort ----------------------------------------------------- */
699
700
  /**
701
   * @return the bit-width of the bit-vector sort
702
   */
703
  uint32_t getBitVectorSize() const;
704
705
  /* Floating-point sort ------------------------------------------------- */
706
707
  /**
708
   * @return the bit-width of the exponent of the floating-point sort
709
   */
710
  uint32_t getFloatingPointExponentSize() const;
711
712
  /**
713
   * @return the width of the significand of the floating-point sort
714
   */
715
  uint32_t getFloatingPointSignificandSize() const;
716
717
  /* Datatype sort ------------------------------------------------------- */
718
719
  /**
720
   * @return the parameter sorts of a datatype sort
721
   */
722
  std::vector<Sort> getDatatypeParamSorts() const;
723
724
  /**
725
   * @return the arity of a datatype sort
726
   */
727
  size_t getDatatypeArity() const;
728
729
  /* Tuple sort ---------------------------------------------------------- */
730
731
  /**
732
   * @return the length of a tuple sort
733
   */
734
  size_t getTupleLength() const;
735
736
  /**
737
   * @return the element sorts of a tuple sort
738
   */
739
  std::vector<Sort> getTupleSorts() const;
740
741
 private:
742
  /** @return the internal wrapped TypeNode of this sort. */
743
  const cvc5::TypeNode& getTypeNode(void) const;
744
745
  /** Helper to convert a set of Sorts to internal TypeNodes. */
746
  std::set<TypeNode> static sortSetToTypeNodes(const std::set<Sort>& sorts);
747
  /** Helper to convert a vector of Sorts to internal TypeNodes. */
748
  std::vector<TypeNode> static sortVectorToTypeNodes(
749
      const std::vector<Sort>& sorts);
750
  /** Helper to convert a vector of internal TypeNodes to Sorts. */
751
  std::vector<Sort> static typeNodeVectorToSorts(
752
      const Solver* slv, const std::vector<TypeNode>& types);
753
754
  /**
755
   * Constructor.
756
   * @param slv the associated solver object
757
   * @param t the internal type that is to be wrapped by this sort
758
   * @return the Sort
759
   */
760
  Sort(const Solver* slv, const cvc5::TypeNode& t);
761
762
  /**
763
   * Helper for isNull checks. This prevents calling an API function with
764
   * CVC5_API_CHECK_NOT_NULL
765
   */
766
  bool isNullHelper() const;
767
768
  /**
769
   * The associated solver object.
770
   */
771
  const Solver* d_solver;
772
773
  /**
774
   * The internal type wrapped by this sort.
775
   * Note: This is a shared_ptr rather than a unique_ptr to avoid overhead due
776
   *       to memory allocation (cvc5::Type is already ref counted, so this
777
   *       could be a unique_ptr instead).
778
   */
779
  std::shared_ptr<cvc5::TypeNode> d_type;
780
};
781
782
/**
783
 * Serialize a sort to given stream.
784
 * @param out the output stream
785
 * @param s the sort to be serialized to the given output stream
786
 * @return the output stream
787
 */
788
std::ostream& operator<<(std::ostream& out, const Sort& s) CVC5_EXPORT;
789
790
}  // namespace api
791
}  // namespace cvc5
792
793
namespace std {
794
795
/**
796
 * Hash function for Sorts.
797
 */
798
template <>
799
struct CVC5_EXPORT hash<cvc5::api::Sort>
800
{
801
  size_t operator()(const cvc5::api::Sort& s) const;
802
};
803
804
}  // namespace std
805
806
namespace cvc5::api {
807
808
/* -------------------------------------------------------------------------- */
809
/* Op                                                                     */
810
/* -------------------------------------------------------------------------- */
811
812
class Term;
813
814
/**
815
 * A cvc5 operator.
816
 * An operator is a term that represents certain operators, instantiated
817
 * with its required parameters, e.g., a term of kind BITVECTOR_EXTRACT.
818
 */
819
337063
class CVC5_EXPORT Op
820
{
821
  friend class Solver;
822
  friend class Term;
823
  friend struct std::hash<Op>;
824
825
 public:
826
  /**
827
   * Constructor.
828
   */
829
  Op();
830
831
  /**
832
   * Destructor.
833
   */
834
  ~Op();
835
836
  /**
837
   * Syntactic equality operator.
838
   * Return true if both operators are syntactically identical.
839
   * Both operators must belong to the same solver object.
840
   * @param t the operator to compare to for equality
841
   * @return true if the operators are equal
842
   */
843
  bool operator==(const Op& t) const;
844
845
  /**
846
   * Syntactic disequality operator.
847
   * Return true if both operators differ syntactically.
848
   * Both terms must belong to the same solver object.
849
   * @param t the operator to compare to for disequality
850
   * @return true if operators are disequal
851
   */
852
  bool operator!=(const Op& t) const;
853
854
  /**
855
   * @return the kind of this operator
856
   */
857
  Kind getKind() const;
858
859
  /**
860
   * @return true if this operator is a null term
861
   */
862
  bool isNull() const;
863
864
  /**
865
   * @return true iff this operator is indexed
866
   */
867
  bool isIndexed() const;
868
869
  /**
870
   * @return the number of indices of this op
871
   */
872
  size_t getNumIndices() const;
873
874
  /**
875
   * Get the index at position i.
876
   * @param i the position of the index to return
877
   * @return the index at position i
878
   */
879
880
  Term operator[](size_t i) const;
881
882
  /**
883
   * Get the indices used to create this Op.
884
   * Supports the following template arguments:
885
   *   - string
886
   *   - Kind
887
   *   - uint32_t
888
   *   - pair<uint32_t, uint32_t>
889
   * Check the Op Kind with getKind() to determine which argument to use.
890
   * @return the indices used to create this Op
891
   */
892
  template <typename T>
893
  T getIndices() const;
894
895
  /**
896
   * @return a string representation of this operator
897
   */
898
  std::string toString() const;
899
900
 private:
901
  /**
902
   * Constructor for a single kind (non-indexed operator).
903
   * @param slv the associated solver object
904
   * @param k the kind of this Op
905
   */
906
  Op(const Solver* slv, const Kind k);
907
908
  /**
909
   * Constructor.
910
   * @param slv the associated solver object
911
   * @param k the kind of this Op
912
   * @param n the internal node that is to be wrapped by this term
913
   * @return the Term
914
   */
915
  Op(const Solver* slv, const Kind k, const cvc5::Node& n);
916
917
  /**
918
   * Helper for isNull checks. This prevents calling an API function with
919
   * CVC5_API_CHECK_NOT_NULL
920
   */
921
  bool isNullHelper() const;
922
923
  /**
924
   * Note: An indexed operator has a non-null internal node, d_node
925
   * Note 2: We use a helper method to avoid having API functions call
926
   *         other API functions (we need to call this internally)
927
   * @return true iff this Op is indexed
928
   */
929
  bool isIndexedHelper() const;
930
931
  /**
932
   * Helper for getNumIndices
933
   * @return the number of indices of this op
934
   */
935
  size_t getNumIndicesHelper() const;
936
937
  /**
938
   * Helper for operator[](size_t index).
939
   * @param index position of the index. Should be less than getNumIndicesHelper().
940
   * @return the index at position index
941
   */
942
  Term getIndexHelper(size_t index) const;
943
944
  /**
945
   * The associated solver object.
946
   */
947
  const Solver* d_solver;
948
949
  /** The kind of this operator. */
950
  Kind d_kind;
951
952
  /**
953
   * The internal node wrapped by this operator.
954
   * Note: This is a shared_ptr rather than a unique_ptr to avoid overhead due
955
   *       to memory allocation (cvc5::Node is already ref counted, so this
956
   *       could be a unique_ptr instead).
957
   */
958
  std::shared_ptr<cvc5::Node> d_node;
959
};
960
961
/**
962
 * Serialize an operator to given stream.
963
 * @param out the output stream
964
 * @param t the operator to be serialized to the given output stream
965
 * @return the output stream
966
 */
967
std::ostream& operator<<(std::ostream& out, const Op& t) CVC5_EXPORT;
968
969
}  // namespace cvc5::api
970
971
namespace std {
972
/**
973
 * Hash function for Ops.
974
 */
975
template <>
976
struct CVC5_EXPORT hash<cvc5::api::Op>
977
{
978
  size_t operator()(const cvc5::api::Op& t) const;
979
};
980
}  // namespace std
981
982
namespace cvc5::api {
983
/* -------------------------------------------------------------------------- */
984
/* Term                                                                       */
985
/* -------------------------------------------------------------------------- */
986
987
/**
988
 * A cvc5 Term.
989
 */
990
37586760
class CVC5_EXPORT Term
991
{
992
  friend class cvc5::Command;
993
  friend class Datatype;
994
  friend class DatatypeConstructor;
995
  friend class DatatypeSelector;
996
  friend class Solver;
997
  friend class Grammar;
998
  friend struct std::hash<Term>;
999
1000
 public:
1001
  /**
1002
   * Constructor for a null term.
1003
   */
1004
  Term();
1005
1006
  /**
1007
   * Destructor.
1008
   */
1009
  ~Term();
1010
1011
  /**
1012
   * Syntactic equality operator.
1013
   * Return true if both terms are syntactically identical.
1014
   * Both terms must belong to the same solver object.
1015
   * @param t the term to compare to for equality
1016
   * @return true if the terms are equal
1017
   */
1018
  bool operator==(const Term& t) const;
1019
1020
  /**
1021
   * Syntactic disequality operator.
1022
   * Return true if both terms differ syntactically.
1023
   * Both terms must belong to the same solver object.
1024
   * @param t the term to compare to for disequality
1025
   * @return true if terms are disequal
1026
   */
1027
  bool operator!=(const Term& t) const;
1028
1029
  /**
1030
   * Comparison for ordering on terms by their id.
1031
   * @param t the term to compare to
1032
   * @return true if this term is less than t
1033
   */
1034
  bool operator<(const Term& t) const;
1035
1036
  /**
1037
   * Comparison for ordering on terms by their id.
1038
   * @param t the term to compare to
1039
   * @return true if this term is greater than t
1040
   */
1041
  bool operator>(const Term& t) const;
1042
1043
  /**
1044
   * Comparison for ordering on terms by their id.
1045
   * @param t the term to compare to
1046
   * @return true if this term is less than or equal to t
1047
   */
1048
  bool operator<=(const Term& t) const;
1049
1050
  /**
1051
   * Comparison for ordering on terms by their id.
1052
   * @param t the term to compare to
1053
   * @return true if this term is greater than or equal to t
1054
   */
1055
  bool operator>=(const Term& t) const;
1056
1057
  /** @return the number of children of this term  */
1058
  size_t getNumChildren() const;
1059
1060
  /**
1061
   * Get the child term at a given index.
1062
   * @param index the index of the child term to return
1063
   * @return the child term with the given index
1064
   */
1065
  Term operator[](size_t index) const;
1066
1067
  /**
1068
   * @return the id of this term
1069
   */
1070
  uint64_t getId() const;
1071
1072
  /**
1073
   * @return the kind of this term
1074
   */
1075
  Kind getKind() const;
1076
1077
  /**
1078
   * @return the sort of this term
1079
   */
1080
  Sort getSort() const;
1081
1082
  /**
1083
   * @return the result of replacing 'term' by 'replacement' in this term
1084
   */
1085
  Term substitute(const Term& term, const Term& replacement) const;
1086
1087
  /**
1088
   * @return the result of simultaneously replacing 'terms' by 'replacements'
1089
   * in this term
1090
   */
1091
  Term substitute(const std::vector<Term>& terms,
1092
                  const std::vector<Term>& replacements) const;
1093
1094
  /**
1095
   * @return true iff this term has an operator
1096
   */
1097
  bool hasOp() const;
1098
1099
  /**
1100
   * @return the Op used to create this term
1101
   * Note: This is safe to call when hasOp() returns true.
1102
   */
1103
  Op getOp() const;
1104
1105
  /**
1106
   * @return true if this Term is a null term
1107
   */
1108
  bool isNull() const;
1109
1110
  /**
1111
   * Boolean negation.
1112
   * @return the Boolean negation of this term
1113
   */
1114
  Term notTerm() const;
1115
1116
  /**
1117
   * Boolean and.
1118
   * @param t a Boolean term
1119
   * @return the conjunction of this term and the given term
1120
   */
1121
  Term andTerm(const Term& t) const;
1122
1123
  /**
1124
   * Boolean or.
1125
   * @param t a Boolean term
1126
   * @return the disjunction of this term and the given term
1127
   */
1128
  Term orTerm(const Term& t) const;
1129
1130
  /**
1131
   * Boolean exclusive or.
1132
   * @param t a Boolean term
1133
   * @return the exclusive disjunction of this term and the given term
1134
   */
1135
  Term xorTerm(const Term& t) const;
1136
1137
  /**
1138
   * Equality.
1139
   * @param t a Boolean term
1140
   * @return the Boolean equivalence of this term and the given term
1141
   */
1142
  Term eqTerm(const Term& t) const;
1143
1144
  /**
1145
   * Boolean implication.
1146
   * @param t a Boolean term
1147
   * @return the implication of this term and the given term
1148
   */
1149
  Term impTerm(const Term& t) const;
1150
1151
  /**
1152
   * If-then-else with this term as the Boolean condition.
1153
   * @param then_t the 'then' term
1154
   * @param else_t the 'else' term
1155
   * @return the if-then-else term with this term as the Boolean condition
1156
   */
1157
  Term iteTerm(const Term& then_t, const Term& else_t) const;
1158
1159
  /**
1160
   * @return a string representation of this term
1161
   */
1162
  std::string toString() const;
1163
1164
  /**
1165
   * Iterator for the children of a Term.
1166
   * Note: This treats uninterpreted functions as Term just like any other term
1167
   *       for example, the term f(x, y) will have Kind APPLY_UF and three
1168
   *       children: f, x, and y
1169
   */
1170
897
  class CVC5_EXPORT const_iterator
1171
  {
1172
    friend class Term;
1173
1174
   public:
1175
    /* The following types are required by trait std::iterator_traits */
1176
1177
    /** Iterator tag */
1178
    using iterator_category = std::forward_iterator_tag;
1179
1180
    /** The type of the item */
1181
    using value_type = Term;
1182
1183
    /** The pointer type of the item */
1184
    using pointer = const Term*;
1185
1186
    /** The reference type of the item */
1187
    using reference = const Term&;
1188
1189
    /** The type returned when two iterators are subtracted */
1190
    using difference_type = std::ptrdiff_t;
1191
1192
    /* End of std::iterator_traits required types */
1193
1194
    /**
1195
     * Null Constructor.
1196
     */
1197
    const_iterator();
1198
1199
    /**
1200
     * Constructor
1201
     * @param slv the associated solver object
1202
     * @param e a shared pointer to the node that we're iterating over
1203
     * @param p the position of the iterator (e.g. which child it's on)
1204
     */
1205
    const_iterator(const Solver* slv,
1206
                   const std::shared_ptr<cvc5::Node>& e,
1207
                   uint32_t p);
1208
1209
    /**
1210
     * Copy constructor.
1211
     */
1212
    const_iterator(const const_iterator& it);
1213
1214
    /**
1215
     * Assignment operator.
1216
     * @param it the iterator to assign to
1217
     * @return the reference to the iterator after assignment
1218
     */
1219
    const_iterator& operator=(const const_iterator& it);
1220
1221
    /**
1222
     * Equality operator.
1223
     * @param it the iterator to compare to for equality
1224
     * @return true if the iterators are equal
1225
     */
1226
    bool operator==(const const_iterator& it) const;
1227
1228
    /**
1229
     * Disequality operator.
1230
     * @param it the iterator to compare to for disequality
1231
     * @return true if the iterators are disequal
1232
     */
1233
    bool operator!=(const const_iterator& it) const;
1234
1235
    /**
1236
     * Increment operator (prefix).
1237
     * @return a reference to the iterator after incrementing by one
1238
     */
1239
    const_iterator& operator++();
1240
1241
    /**
1242
     * Increment operator (postfix).
1243
     * @return a reference to the iterator after incrementing by one
1244
     */
1245
    const_iterator operator++(int);
1246
1247
    /**
1248
     * Dereference operator.
1249
     * @return the term this iterator points to
1250
     */
1251
    Term operator*() const;
1252
1253
   private:
1254
    /**
1255
     * The associated solver object.
1256
     */
1257
    const Solver* d_solver;
1258
    /** The original node to be iterated over. */
1259
    std::shared_ptr<cvc5::Node> d_origNode;
1260
    /** Keeps track of the iteration position. */
1261
    uint32_t d_pos;
1262
  };
1263
1264
  /**
1265
   * @return an iterator to the first child of this Term
1266
   */
1267
  const_iterator begin() const;
1268
1269
  /**
1270
   * @return an iterator to one-off-the-last child of this Term
1271
   */
1272
  const_iterator end() const;
1273
1274
  /**
1275
   * @return true if the term is an integer value that fits within int32_t.
1276
   */
1277
  bool isInt32Value() const;
1278
  /**
1279
   * Asserts isInt32Value().
1280
   * @return the integer term as a int32_t.
1281
   */
1282
  int32_t getInt32Value() const;
1283
  /**
1284
   * @return true if the term is an integer value that fits within uint32_t.
1285
   */
1286
  bool isUInt32Value() const;
1287
  /**
1288
   * Asserts isUInt32Value().
1289
   * @return the integer term as a uint32_t.
1290
   */
1291
  uint32_t getUInt32Value() const;
1292
  /**
1293
   * @return true if the term is an integer value that fits within int64_t.
1294
   */
1295
  bool isInt64Value() const;
1296
  /**
1297
   * Asserts isInt64Value().
1298
   * @return the integer term as a int64_t.
1299
   */
1300
  int64_t getInt64Value() const;
1301
  /**
1302
   * @return true if the term is an integer value that fits within uint64_t.
1303
   */
1304
  bool isUInt64Value() const;
1305
  /**
1306
   * Asserts isUInt64Value().
1307
   * @return the integer term as a uint64_t.
1308
   */
1309
  uint64_t getUInt64Value() const;
1310
  /**
1311
   * @return true if the term is an integer value.
1312
   */
1313
  bool isIntegerValue() const;
1314
  /**
1315
   * Asserts isIntegerValue().
1316
   * @return the integer term in (decimal) string representation.
1317
   */
1318
  std::string getIntegerValue() const;
1319
1320
  /**
1321
   * @return true if the term is a string value.
1322
   */
1323
  bool isStringValue() const;
1324
  /**
1325
   * Note: This method is not to be confused with toString() which returns
1326
   * the term in some string representation, whatever data it may hold. Asserts
1327
   * isStringValue().
1328
   * @return the string term as a native string value.
1329
   */
1330
  std::wstring getStringValue() const;
1331
1332
  /**
1333
   * @return true if the term is a rational value whose numerator and
1334
   * denominator fit within int32_t and uint32_t, respectively.
1335
   */
1336
  bool isReal32Value() const;
1337
  /**
1338
   * Asserts isReal32Value().
1339
   * @return the representation of a rational value as a pair of its numerator
1340
   * and denominator.
1341
   */
1342
  std::pair<int32_t, uint32_t> getReal32Value() const;
1343
  /**
1344
   * @return true if the term is a rational value whose numerator and
1345
   * denominator fit within int64_t and uint64_t, respectively.
1346
   */
1347
  bool isReal64Value() const;
1348
  /**
1349
   * Asserts isReal64Value().
1350
   * @return the representation of a rational value as a pair of its numerator
1351
   * and denominator.
1352
   */
1353
  std::pair<int64_t, uint64_t> getReal64Value() const;
1354
  /**
1355
   * @return true if the term is a rational value.
1356
   *
1357
   * Note that a term of kind PI is not considered to be a real value.
1358
   */
1359
  bool isRealValue() const;
1360
  /**
1361
   * Asserts isRealValue().
1362
   * @return the representation of a rational value as a (rational) string.
1363
   */
1364
  std::string getRealValue() const;
1365
1366
  /**
1367
   * @return true if the term is a constant array.
1368
   */
1369
  bool isConstArray() const;
1370
  /**
1371
   * Asserts isConstArray().
1372
   * @return the base (element stored at all indices) of a constant array
1373
   */
1374
  Term getConstArrayBase() const;
1375
1376
  /**
1377
   * @return true if the term is a Boolean value.
1378
   */
1379
  bool isBooleanValue() const;
1380
  /**
1381
   * Asserts isBooleanValue().
1382
   * @return the representation of a Boolean value as a native Boolean value.
1383
   */
1384
  bool getBooleanValue() const;
1385
1386
  /**
1387
   * @return true if the term is a bit-vector value.
1388
   */
1389
  bool isBitVectorValue() const;
1390
  /**
1391
   * Asserts isBitVectorValue().
1392
   * @return the representation of a bit-vector value in string representation.
1393
   * Supported bases are 2 (bit string), 10 (decimal string) or 16 (hexadecimal
1394
   * string).
1395
   */
1396
  std::string getBitVectorValue(uint32_t base = 2) const;
1397
1398
  /**
1399
   * @return true if the term is an abstract value.
1400
   */
1401
  bool isAbstractValue() const;
1402
  /**
1403
   * Asserts isAbstractValue().
1404
   * @return the representation of an abstract value as a string.
1405
   */
1406
  std::string getAbstractValue() const;
1407
1408
  /**
1409
   * @return true if the term is a tuple value.
1410
   */
1411
  bool isTupleValue() const;
1412
  /**
1413
   * Asserts isTupleValue().
1414
   * @return the representation of a tuple value as a vector of terms.
1415
   */
1416
  std::vector<Term> getTupleValue() const;
1417
1418
  /**
1419
   * @return true if the term is the floating-point value for positive zero.
1420
   */
1421
  bool isFloatingPointPosZero() const;
1422
  /**
1423
   * @return true if the term is the floating-point value for negative zero.
1424
   */
1425
  bool isFloatingPointNegZero() const;
1426
  /**
1427
   * @return true if the term is the floating-point value for positive
1428
   * infinity.
1429
   */
1430
  bool isFloatingPointPosInf() const;
1431
  /**
1432
   * @return true if the term is the floating-point value for negative
1433
   * infinity.
1434
   */
1435
  bool isFloatingPointNegInf() const;
1436
  /**
1437
   * @return true if the term is the floating-point value for not a number.
1438
   */
1439
  bool isFloatingPointNaN() const;
1440
  /**
1441
   * @return true if the term is a floating-point value.
1442
   */
1443
  bool isFloatingPointValue() const;
1444
  /**
1445
   * Asserts isFloatingPointValue().
1446
   * @return the representation of a floating-point value as a tuple of the
1447
   * exponent width, the significand width and a bit-vector value.
1448
   */
1449
  std::tuple<uint32_t, uint32_t, Term> getFloatingPointValue() const;
1450
1451
  /**
1452
   * @return true if the term is a set value.
1453
   *
1454
   * A term is a set value if it is considered to be a (canonical) constant set
1455
   * value.  A canonical set value is one whose AST is:
1456
   * ```
1457
   *   (union (singleton c1) ... (union (singleton c_{n-1}) (singleton c_n))))
1458
   * ```
1459
   * where `c1 ... cn` are values ordered by id such that `c1 > ... > cn` (see
1460
   * also @ref Term::operator>(const Term&) const).
1461
   *
1462
   * Note that a universe set term (kind UNIVERSE_SET) is not considered to be
1463
   * a set value.
1464
   */
1465
  bool isSetValue() const;
1466
  /**
1467
   * Asserts isSetValue().
1468
   * @return the representation of a set value as a set of terms.
1469
   */
1470
  std::set<Term> getSetValue() const;
1471
1472
  /**
1473
   * @return true if the term is a sequence value.
1474
   */
1475
  bool isSequenceValue() const;
1476
  /**
1477
   * Asserts isSequenceValue().
1478
   * Note that it is usually necessary for sequences to call
1479
   * `Solver::simplify()` to turn a sequence that is constructed by, e.g.,
1480
   * concatenation of unit sequences, into a sequence value.
1481
   * @return the representation of a sequence value as a vector of terms.
1482
   */
1483
  std::vector<Term> getSequenceValue() const;
1484
1485
  /**
1486
   * @return true if the term is a value from an uninterpreted sort.
1487
   */
1488
  bool isUninterpretedValue() const;
1489
  /**
1490
  bool @return() const;
1491
   * Asserts isUninterpretedValue().
1492
   * @return the representation of an uninterpreted value as a pair of its
1493
  sort and its
1494
   * index.
1495
   */
1496
  std::pair<Sort, int32_t> getUninterpretedValue() const;
1497
1498
 protected:
1499
  /**
1500
   * The associated solver object.
1501
   */
1502
  const Solver* d_solver;
1503
1504
 private:
1505
  /** Helper to convert a vector of Terms to internal Nodes. */
1506
  std::vector<Node> static termVectorToNodes(const std::vector<Term>& terms);
1507
1508
  /** Helper method to collect all elements of a set. */
1509
  static void collectSet(std::set<Term>& set,
1510
                         const cvc5::Node& node,
1511
                         const Solver* slv);
1512
  /** Helper method to collect all elements of a sequence. */
1513
  static void collectSequence(std::vector<Term>& seq,
1514
                              const cvc5::Node& node,
1515
                              const Solver* slv);
1516
1517
  /**
1518
   * Constructor.
1519
   * @param slv the associated solver object
1520
   * @param n the internal node that is to be wrapped by this term
1521
   * @return the Term
1522
   */
1523
  Term(const Solver* slv, const cvc5::Node& n);
1524
1525
  /** @return the internal wrapped Node of this term. */
1526
  const cvc5::Node& getNode(void) const;
1527
1528
  /**
1529
   * Helper for isNull checks. This prevents calling an API function with
1530
   * CVC5_API_CHECK_NOT_NULL
1531
   */
1532
  bool isNullHelper() const;
1533
1534
  /**
1535
   * Helper function that returns the kind of the term, which takes into
1536
   * account special cases of the conversion for internal to external kinds.
1537
   * @return the kind of this term
1538
   */
1539
  Kind getKindHelper() const;
1540
1541
  /**
1542
   * @return true if the current term is a constant integer that is casted into
1543
   * real using the operator CAST_TO_REAL, and returns false otherwise
1544
   */
1545
  bool isCastedReal() const;
1546
  /**
1547
   * The internal node wrapped by this term.
1548
   * Note: This is a shared_ptr rather than a unique_ptr to avoid overhead due
1549
   *       to memory allocation (cvc5::Node is already ref counted, so this
1550
   *       could be a unique_ptr instead).
1551
   */
1552
  std::shared_ptr<cvc5::Node> d_node;
1553
};
1554
1555
/**
1556
 * Serialize a term to given stream.
1557
 * @param out the output stream
1558
 * @param t the term to be serialized to the given output stream
1559
 * @return the output stream
1560
 */
1561
std::ostream& operator<<(std::ostream& out, const Term& t) CVC5_EXPORT;
1562
1563
/**
1564
 * Serialize a vector of terms to given stream.
1565
 * @param out the output stream
1566
 * @param vector the vector of terms to be serialized to the given stream
1567
 * @return the output stream
1568
 */
1569
std::ostream& operator<<(std::ostream& out,
1570
                         const std::vector<Term>& vector) CVC5_EXPORT;
1571
1572
/**
1573
 * Serialize a set of terms to the given stream.
1574
 * @param out the output stream
1575
 * @param set the set of terms to be serialized to the given stream
1576
 * @return the output stream
1577
 */
1578
std::ostream& operator<<(std::ostream& out,
1579
                         const std::set<Term>& set) CVC5_EXPORT;
1580
1581
/**
1582
 * Serialize an unordered_set of terms to the given stream.
1583
 *
1584
 * @param out the output stream
1585
 * @param unordered_set the set of terms to be serialized to the given stream
1586
 * @return the output stream
1587
 */
1588
std::ostream& operator<<(std::ostream& out,
1589
                         const std::unordered_set<Term>& unordered_set)
1590
    CVC5_EXPORT;
1591
1592
/**
1593
 * Serialize a map of terms to the given stream.
1594
 *
1595
 * @param out the output stream
1596
 * @param map the map of terms to be serialized to the given stream
1597
 * @return the output stream
1598
 */
1599
template <typename V>
1600
std::ostream& operator<<(std::ostream& out,
1601
                         const std::map<Term, V>& map) CVC5_EXPORT;
1602
1603
/**
1604
 * Serialize an unordered_map of terms to the given stream.
1605
 *
1606
 * @param out the output stream
1607
 * @param unordered_map the map of terms to be serialized to the given stream
1608
 * @return the output stream
1609
 */
1610
template <typename V>
1611
std::ostream& operator<<(std::ostream& out,
1612
                         const std::unordered_map<Term, V>& unordered_map)
1613
    CVC5_EXPORT;
1614
1615
}  // namespace cvc5::api
1616
1617
namespace std {
1618
/**
1619
 * Hash function for Terms.
1620
 */
1621
template <>
1622
struct CVC5_EXPORT hash<cvc5::api::Term>
1623
{
1624
  size_t operator()(const cvc5::api::Term& t) const;
1625
};
1626
}  // namespace std
1627
1628
namespace cvc5::api {
1629
1630
/* -------------------------------------------------------------------------- */
1631
/* Datatypes                                                                  */
1632
/* -------------------------------------------------------------------------- */
1633
1634
class DatatypeConstructorIterator;
1635
class DatatypeIterator;
1636
1637
/**
1638
 * A cvc5 datatype constructor declaration.
1639
 */
1640
22
class CVC5_EXPORT DatatypeConstructorDecl
1641
{
1642
  friend class DatatypeDecl;
1643
  friend class Solver;
1644
1645
 public:
1646
  /** Constructor.  */
1647
  DatatypeConstructorDecl();
1648
1649
  /**
1650
   * Destructor.
1651
   */
1652
  ~DatatypeConstructorDecl();
1653
1654
  /**
1655
   * Add datatype selector declaration.
1656
   * @param name the name of the datatype selector declaration to add
1657
   * @param sort the range sort of the datatype selector declaration to add
1658
   */
1659
  void addSelector(const std::string& name, const Sort& sort);
1660
  /**
1661
   * Add datatype selector declaration whose range type is the datatype itself.
1662
   * @param name the name of the datatype selector declaration to add
1663
   */
1664
  void addSelectorSelf(const std::string& name);
1665
1666
  /**
1667
   * @return true if this DatatypeConstructorDecl is a null declaration.
1668
   */
1669
  bool isNull() const;
1670
1671
  /**
1672
   * @return a string representation of this datatype constructor declaration
1673
   */
1674
  std::string toString() const;
1675
1676
 private:
1677
  /**
1678
   * Constructor.
1679
   * @param slv the associated solver object
1680
   * @param name the name of the datatype constructor
1681
   * @return the DatatypeConstructorDecl
1682
   */
1683
  DatatypeConstructorDecl(const Solver* slv, const std::string& name);
1684
1685
  /**
1686
   * Helper for isNull checks. This prevents calling an API function with
1687
   * CVC5_API_CHECK_NOT_NULL
1688
   */
1689
  bool isNullHelper() const;
1690
1691
  /**
1692
   * The associated solver object.
1693
   */
1694
  const Solver* d_solver;
1695
1696
  /**
1697
   * The internal (intermediate) datatype constructor wrapped by this
1698
   * datatype constructor declaration.
1699
   * Note: This is a shared_ptr rather than a unique_ptr since
1700
   *       cvc5::DTypeConstructor is not ref counted.
1701
   */
1702
  std::shared_ptr<cvc5::DTypeConstructor> d_ctor;
1703
};
1704
1705
class Solver;
1706
1707
/**
1708
 * A cvc5 datatype declaration.
1709
 */
1710
2036
class CVC5_EXPORT DatatypeDecl
1711
{
1712
  friend class DatatypeConstructorArg;
1713
  friend class Solver;
1714
  friend class Grammar;
1715
1716
 public:
1717
  /** Constructor.  */
1718
  DatatypeDecl();
1719
1720
  /**
1721
   * Destructor.
1722
   */
1723
  ~DatatypeDecl();
1724
1725
  /**
1726
   * Add datatype constructor declaration.
1727
   * @param ctor the datatype constructor declaration to add
1728
   */
1729
  void addConstructor(const DatatypeConstructorDecl& ctor);
1730
1731
  /** Get the number of constructors (so far) for this Datatype declaration. */
1732
  size_t getNumConstructors() const;
1733
1734
  /** Is this Datatype declaration parametric? */
1735
  bool isParametric() const;
1736
1737
  /**
1738
   * @return true if this DatatypeDecl is a null object
1739
   */
1740
  bool isNull() const;
1741
1742
  /**
1743
   * @return a string representation of this datatype declaration
1744
   */
1745
  std::string toString() const;
1746
1747
  /** @return the name of this datatype declaration. */
1748
  std::string getName() const;
1749
1750
 private:
1751
  /**
1752
   * Constructor.
1753
   * @param slv the associated solver object
1754
   * @param name the name of the datatype
1755
   * @param isCoDatatype true if a codatatype is to be constructed
1756
   * @return the DatatypeDecl
1757
   */
1758
  DatatypeDecl(const Solver* slv,
1759
               const std::string& name,
1760
               bool isCoDatatype = false);
1761
1762
  /**
1763
   * Constructor for parameterized datatype declaration.
1764
   * Create sorts parameter with Solver::mkParamSort().
1765
   * @param slv the associated solver object
1766
   * @param name the name of the datatype
1767
   * @param param the sort parameter
1768
   * @param isCoDatatype true if a codatatype is to be constructed
1769
   */
1770
  DatatypeDecl(const Solver* slv,
1771
               const std::string& name,
1772
               const Sort& param,
1773
               bool isCoDatatype = false);
1774
1775
  /**
1776
   * Constructor for parameterized datatype declaration.
1777
   * Create sorts parameter with Solver::mkParamSort().
1778
   * @param slv the associated solver object
1779
   * @param name the name of the datatype
1780
   * @param params a list of sort parameters
1781
   * @param isCoDatatype true if a codatatype is to be constructed
1782
   */
1783
  DatatypeDecl(const Solver* slv,
1784
               const std::string& name,
1785
               const std::vector<Sort>& params,
1786
               bool isCoDatatype = false);
1787
1788
  /** @return the internal wrapped Dtype of this datatype declaration. */
1789
  cvc5::DType& getDatatype(void) const;
1790
1791
  /**
1792
   * Helper for isNull checks. This prevents calling an API function with
1793
   * CVC5_API_CHECK_NOT_NULL
1794
   */
1795
  bool isNullHelper() const;
1796
1797
  /**
1798
   * The associated solver object.
1799
   */
1800
  const Solver* d_solver;
1801
1802
  /**
1803
   * The internal (intermediate) datatype wrapped by this datatype
1804
   * declaration.
1805
   * Note: This is a shared_ptr rather than a unique_ptr since cvc5::DType is
1806
   *       not ref counted.
1807
   */
1808
  std::shared_ptr<cvc5::DType> d_dtype;
1809
};
1810
1811
/**
1812
 * A cvc5 datatype selector.
1813
 */
1814
2
class CVC5_EXPORT DatatypeSelector
1815
{
1816
  friend class Datatype;
1817
  friend class DatatypeConstructor;
1818
  friend class Solver;
1819
1820
 public:
1821
  /**
1822
   * Constructor.
1823
   */
1824
  DatatypeSelector();
1825
1826
  /**
1827
   * Destructor.
1828
   */
1829
  ~DatatypeSelector();
1830
1831
  /** @return the name of this Datatype selector. */
1832
  std::string getName() const;
1833
1834
  /**
1835
   * Get the selector operator of this datatype selector.
1836
   * @return the selector term
1837
   */
1838
  Term getSelectorTerm() const;
1839
1840
  /**
1841
   * Get the updater operator of this datatype selector.
1842
   * @return the updater term
1843
   */
1844
  Term getUpdaterTerm() const;
1845
1846
  /** @return the range sort of this selector. */
1847
  Sort getRangeSort() const;
1848
1849
  /**
1850
   * @return true if this DatatypeSelector is a null object
1851
   */
1852
  bool isNull() const;
1853
1854
  /**
1855
   * @return a string representation of this datatype selector
1856
   */
1857
  std::string toString() const;
1858
1859
 private:
1860
  /**
1861
   * Constructor.
1862
   * @param slv the associated solver object
1863
   * @param stor the internal datatype selector to be wrapped
1864
   * @return the DatatypeSelector
1865
   */
1866
  DatatypeSelector(const Solver* slv, const cvc5::DTypeSelector& stor);
1867
1868
  /**
1869
   * Helper for isNull checks. This prevents calling an API function with
1870
   * CVC5_API_CHECK_NOT_NULL
1871
   */
1872
  bool isNullHelper() const;
1873
1874
  /**
1875
   * The associated solver object.
1876
   */
1877
  const Solver* d_solver;
1878
1879
  /**
1880
   * The internal datatype selector wrapped by this datatype selector.
1881
   * Note: This is a shared_ptr rather than a unique_ptr since cvc5::DType is
1882
   *       not ref counted.
1883
   */
1884
  std::shared_ptr<cvc5::DTypeSelector> d_stor;
1885
};
1886
1887
/**
1888
 * A cvc5 datatype constructor.
1889
 */
1890
2
class CVC5_EXPORT DatatypeConstructor
1891
{
1892
  friend class Datatype;
1893
  friend class Solver;
1894
1895
 public:
1896
  /**
1897
   * Constructor.
1898
   */
1899
  DatatypeConstructor();
1900
1901
  /**
1902
   * Destructor.
1903
   */
1904
  ~DatatypeConstructor();
1905
1906
  /** @return the name of this Datatype constructor. */
1907
  std::string getName() const;
1908
1909
  /**
1910
   * Get the constructor operator of this datatype constructor.
1911
   * @return the constructor term
1912
   */
1913
  Term getConstructorTerm() const;
1914
1915
  /**
1916
   * Get the constructor operator of this datatype constructor whose return
1917
   * type is retSort. This method is intended to be used on constructors of
1918
   * parametric datatypes and can be seen as returning the constructor
1919
   * term that has been explicitly cast to the given sort.
1920
   *
1921
   * This method is required for constructors of parametric datatypes whose
1922
   * return type cannot be determined by type inference. For example, given:
1923
   *   (declare-datatype List (par (T) ((nil) (cons (head T) (tail (List T))))))
1924
   * The type of nil terms need to be provided by the user. In SMT version 2.6,
1925
   * this is done via the syntax for qualified identifiers:
1926
   *   (as nil (List Int))
1927
   * This method is equivalent of applying the above, where this
1928
   * DatatypeConstructor is the one corresponding to nil, and retSort is
1929
   * (List Int).
1930
   *
1931
   * Furthermore note that the returned constructor term t is an operator,
1932
   * while Solver::mkTerm(APPLY_CONSTRUCTOR, t) is used to construct the above
1933
   * (nullary) application of nil.
1934
   *
1935
   * @param retSort the desired return sort of the constructor
1936
   * @return the constructor term
1937
   */
1938
  Term getSpecializedConstructorTerm(const Sort& retSort) const;
1939
1940
  /**
1941
   * Get the tester operator of this datatype constructor.
1942
   * @return the tester operator
1943
   */
1944
  Term getTesterTerm() const;
1945
1946
  /**
1947
   * @return the number of selectors (so far) of this Datatype constructor.
1948
   */
1949
  size_t getNumSelectors() const;
1950
1951
  /** @return the i^th DatatypeSelector. */
1952
  DatatypeSelector operator[](size_t index) const;
1953
  /**
1954
   * Get the datatype selector with the given name.
1955
   * This is a linear search through the selectors, so in case of
1956
   * multiple, similarly-named selectors, the first is returned.
1957
   * @param name the name of the datatype selector
1958
   * @return the first datatype selector with the given name
1959
   */
1960
  DatatypeSelector operator[](const std::string& name) const;
1961
  DatatypeSelector getSelector(const std::string& name) const;
1962
1963
  /**
1964
   * Get the term representation of the datatype selector with the given name.
1965
   * This is a linear search through the arguments, so in case of multiple,
1966
   * similarly-named arguments, the selector for the first is returned.
1967
   * @param name the name of the datatype selector
1968
   * @return a term representing the datatype selector with the given name
1969
   */
1970
  Term getSelectorTerm(const std::string& name) const;
1971
1972
  /**
1973
   * @return true if this DatatypeConstructor is a null object
1974
   */
1975
  bool isNull() const;
1976
1977
  /**
1978
   * @return a string representation of this datatype constructor
1979
   */
1980
  std::string toString() const;
1981
1982
  /**
1983
   * Iterator for the selectors of a datatype constructor.
1984
   */
1985
  class const_iterator
1986
  {
1987
    friend class DatatypeConstructor;  // to access constructor
1988
1989
   public:
1990
    /* The following types are required by trait std::iterator_traits */
1991
1992
    /** Iterator tag */
1993
    using iterator_category = std::forward_iterator_tag;
1994
1995
    /** The type of the item */
1996
    using value_type = DatatypeConstructor;
1997
1998
    /** The pointer type of the item */
1999
    using pointer = const DatatypeConstructor*;
2000
2001
    /** The reference type of the item */
2002
    using reference = const DatatypeConstructor&;
2003
2004
    /** The type returned when two iterators are subtracted */
2005
    using difference_type = std::ptrdiff_t;
2006
2007
    /* End of std::iterator_traits required types */
2008
2009
    /** Nullary constructor (required for Cython). */
2010
    const_iterator();
2011
2012
    /**
2013
     * Assignment operator.
2014
     * @param it the iterator to assign to
2015
     * @return the reference to the iterator after assignment
2016
     */
2017
    const_iterator& operator=(const const_iterator& it);
2018
2019
    /**
2020
     * Equality operator.
2021
     * @param it the iterator to compare to for equality
2022
     * @return true if the iterators are equal
2023
     */
2024
    bool operator==(const const_iterator& it) const;
2025
2026
    /**
2027
     * Disequality operator.
2028
     * @param it the iterator to compare to for disequality
2029
     * @return true if the iterators are disequal
2030
     */
2031
    bool operator!=(const const_iterator& it) const;
2032
2033
    /**
2034
     * Increment operator (prefix).
2035
     * @return a reference to the iterator after incrementing by one
2036
     */
2037
    const_iterator& operator++();
2038
2039
    /**
2040
     * Increment operator (postfix).
2041
     * @return a reference to the iterator after incrementing by one
2042
     */
2043
    const_iterator operator++(int);
2044
2045
    /**
2046
     * Dereference operator.
2047
     * @return a reference to the selector this iterator points to
2048
     */
2049
    const DatatypeSelector& operator*() const;
2050
2051
    /**
2052
     * Dereference operator.
2053
     * @return a pointer to the selector this iterator points to
2054
     */
2055
    const DatatypeSelector* operator->() const;
2056
2057
   private:
2058
    /**
2059
     * Constructor.
2060
     * @param slv the associated Solver object
2061
     * @param ctor the internal datatype constructor to iterate over
2062
     * @param begin true if this is a begin() iterator
2063
     */
2064
    const_iterator(const Solver* slv,
2065
                   const cvc5::DTypeConstructor& ctor,
2066
                   bool begin);
2067
2068
    /**
2069
     * The associated solver object.
2070
     */
2071
    const Solver* d_solver;
2072
2073
    /**
2074
     * A pointer to the list of selectors of the internal datatype
2075
     * constructor to iterate over.
2076
     * This pointer is maintained for operators == and != only.
2077
     */
2078
    const void* d_int_stors;
2079
2080
    /** The list of datatype selector (wrappers) to iterate over. */
2081
    std::vector<DatatypeSelector> d_stors;
2082
2083
    /** The current index of the iterator. */
2084
    size_t d_idx;
2085
  };
2086
2087
  /**
2088
   * @return an iterator to the first selector of this constructor
2089
   */
2090
  const_iterator begin() const;
2091
2092
  /**
2093
   * @return an iterator to one-off-the-last selector of this constructor
2094
   */
2095
  const_iterator end() const;
2096
2097
 private:
2098
  /**
2099
   * Constructor.
2100
   * @param slv the associated solver instance
2101
   * @param ctor the internal datatype constructor to be wrapped
2102
   * @return the DatatypeConstructor
2103
   */
2104
  DatatypeConstructor(const Solver* slv, const cvc5::DTypeConstructor& ctor);
2105
2106
  /**
2107
   * Return selector for name.
2108
   * @param name The name of selector to find
2109
   * @return the selector object for the name
2110
   */
2111
  DatatypeSelector getSelectorForName(const std::string& name) const;
2112
2113
  /**
2114
   * Helper for isNull checks. This prevents calling an API function with
2115
   * CVC5_API_CHECK_NOT_NULL
2116
   */
2117
  bool isNullHelper() const;
2118
2119
  /**
2120
   * The associated solver object.
2121
   */
2122
  const Solver* d_solver;
2123
2124
  /**
2125
   * The internal datatype constructor wrapped by this datatype constructor.
2126
   * Note: This is a shared_ptr rather than a unique_ptr since cvc5::DType is
2127
   *       not ref counted.
2128
   */
2129
  std::shared_ptr<cvc5::DTypeConstructor> d_ctor;
2130
};
2131
2132
/**
2133
 * A cvc5 datatype.
2134
 */
2135
2
class CVC5_EXPORT Datatype
2136
{
2137
  friend class Solver;
2138
  friend class Sort;
2139
2140
 public:
2141
  /** Constructor. */
2142
  Datatype();
2143
2144
  /**
2145
   * Destructor.
2146
   */
2147
  ~Datatype();
2148
2149
  /**
2150
   * Get the datatype constructor at a given index.
2151
   * @param idx the index of the datatype constructor to return
2152
   * @return the datatype constructor with the given index
2153
   */
2154
  DatatypeConstructor operator[](size_t idx) const;
2155
2156
  /**
2157
   * Get the datatype constructor with the given name.
2158
   * This is a linear search through the constructors, so in case of multiple,
2159
   * similarly-named constructors, the first is returned.
2160
   * @param name the name of the datatype constructor
2161
   * @return the datatype constructor with the given name
2162
   */
2163
  DatatypeConstructor operator[](const std::string& name) const;
2164
  DatatypeConstructor getConstructor(const std::string& name) const;
2165
2166
  /**
2167
   * Get a term representing the datatype constructor with the given name.
2168
   * This is a linear search through the constructors, so in case of multiple,
2169
   * similarly-named constructors, the
2170
   * first is returned.
2171
   */
2172
  Term getConstructorTerm(const std::string& name) const;
2173
2174
  /**
2175
   * Get the datatype constructor with the given name.
2176
   * This is a linear search through the constructors and their selectors, so
2177
   * in case of multiple, similarly-named selectors, the first is returned.
2178
   * @param name the name of the datatype selector
2179
   * @return the datatype selector with the given name
2180
   */
2181
  DatatypeSelector getSelector(const std::string& name) const;
2182
2183
  /** @return the name of this Datatype. */
2184
  std::string getName() const;
2185
2186
  /** @return the number of constructors for this Datatype. */
2187
  size_t getNumConstructors() const;
2188
2189
  /** @return true if this datatype is parametric */
2190
  bool isParametric() const;
2191
2192
  /** @return true if this datatype corresponds to a co-datatype */
2193
  bool isCodatatype() const;
2194
2195
  /** @return true if this datatype corresponds to a tuple */
2196
  bool isTuple() const;
2197
2198
  /** @return true if this datatype corresponds to a record */
2199
  bool isRecord() const;
2200
2201
  /** @return true if this datatype is finite */
2202
  bool isFinite() const;
2203
2204
  /**
2205
   * Is this datatype well-founded? If this datatype is not a codatatype,
2206
   * this returns false if there are no values of this datatype that are of
2207
   * finite size.
2208
   *
2209
   * @return true if this datatype is well-founded
2210
   */
2211
  bool isWellFounded() const;
2212
2213
  /**
2214
   * Does this datatype have nested recursion? This method returns false if a
2215
   * value of this datatype includes a subterm of its type that is nested
2216
   * beneath a non-datatype type constructor. For example, a datatype
2217
   * T containing a constructor having a selector with range type (Set T) has
2218
   * nested recursion.
2219
   *
2220
   * @return true if this datatype has nested recursion
2221
   */
2222
  bool hasNestedRecursion() const;
2223
2224
  /**
2225
   * @return true if this Datatype is a null object
2226
   */
2227
  bool isNull() const;
2228
2229
  /**
2230
   * @return a string representation of this datatype
2231
   */
2232
  std::string toString() const;
2233
2234
  /**
2235
   * Iterator for the constructors of a datatype.
2236
   */
2237
  class const_iterator
2238
  {
2239
    friend class Datatype;  // to access constructor
2240
2241
   public:
2242
    /* The following types are required by trait std::iterator_traits */
2243
2244
    /** Iterator tag */
2245
    using iterator_category = std::forward_iterator_tag;
2246
2247
    /** The type of the item */
2248
    using value_type = Datatype;
2249
2250
    /** The pointer type of the item */
2251
    using pointer = const Datatype*;
2252
2253
    /** The reference type of the item */
2254
    using reference = const Datatype&;
2255
2256
    /** The type returned when two iterators are subtracted */
2257
    using difference_type = std::ptrdiff_t;
2258
2259
    /* End of std::iterator_traits required types */
2260
2261
    /** Nullary constructor (required for Cython). */
2262
    const_iterator();
2263
2264
    /**
2265
     * Assignment operator.
2266
     * @param it the iterator to assign to
2267
     * @return the reference to the iterator after assignment
2268
     */
2269
    const_iterator& operator=(const const_iterator& it);
2270
2271
    /**
2272
     * Equality operator.
2273
     * @param it the iterator to compare to for equality
2274
     * @return true if the iterators are equal
2275
     */
2276
    bool operator==(const const_iterator& it) const;
2277
2278
    /**
2279
     * Disequality operator.
2280
     * @param it the iterator to compare to for disequality
2281
     * @return true if the iterators are disequal
2282
     */
2283
    bool operator!=(const const_iterator& it) const;
2284
2285
    /**
2286
     * Increment operator (prefix).
2287
     * @return a reference to the iterator after incrementing by one
2288
     */
2289
    const_iterator& operator++();
2290
2291
    /**
2292
     * Increment operator (postfix).
2293
     * @return a reference to the iterator after incrementing by one
2294
     */
2295
    const_iterator operator++(int);
2296
2297
    /**
2298
     * Dereference operator.
2299
     * @return a reference to the constructor this iterator points to
2300
     */
2301
    const DatatypeConstructor& operator*() const;
2302
2303
    /**
2304
     * Dereference operator.
2305
     * @return a pointer to the constructor this iterator points to
2306
     */
2307
    const DatatypeConstructor* operator->() const;
2308
2309
   private:
2310
    /**
2311
     * Constructor.
2312
     * @param slv the associated Solver object
2313
     * @param dtype the internal datatype to iterate over
2314
     * @param begin true if this is a begin() iterator
2315
     */
2316
    const_iterator(const Solver* slv, const cvc5::DType& dtype, bool begin);
2317
2318
    /**
2319
     * The associated solver object.
2320
     */
2321
    const Solver* d_solver;
2322
2323
    /**
2324
     * A pointer to the list of constructors of the internal datatype
2325
     * to iterate over.
2326
     * This pointer is maintained for operators == and != only.
2327
     */
2328
    const void* d_int_ctors;
2329
2330
    /** The list of datatype constructor (wrappers) to iterate over. */
2331
    std::vector<DatatypeConstructor> d_ctors;
2332
2333
    /** The current index of the iterator. */
2334
    size_t d_idx;
2335
  };
2336
2337
  /**
2338
   * @return an iterator to the first constructor of this datatype
2339
   */
2340
  const_iterator begin() const;
2341
2342
  /**
2343
   * @return an iterator to one-off-the-last constructor of this datatype
2344
   */
2345
  const_iterator end() const;
2346
2347
 private:
2348
  /**
2349
   * Constructor.
2350
   * @param slv the associated solver instance
2351
   * @param dtype the internal datatype to be wrapped
2352
   * @return the Datatype
2353
   */
2354
  Datatype(const Solver* slv, const cvc5::DType& dtype);
2355
2356
  /**
2357
   * Return constructor for name.
2358
   * @param name The name of constructor to find
2359
   * @return the constructor object for the name
2360
   */
2361
  DatatypeConstructor getConstructorForName(const std::string& name) const;
2362
2363
  /**
2364
   * Return selector for name.
2365
   * @param name The name of selector to find
2366
   * @return the selector object for the name
2367
   */
2368
  DatatypeSelector getSelectorForName(const std::string& name) const;
2369
2370
  /**
2371
   * Helper for isNull checks. This prevents calling an API function with
2372
   * CVC5_API_CHECK_NOT_NULL
2373
   */
2374
  bool isNullHelper() const;
2375
2376
  /**
2377
   * The associated solver object.
2378
   */
2379
  const Solver* d_solver;
2380
2381
  /**
2382
   * The internal datatype wrapped by this datatype.
2383
   * Note: This is a shared_ptr rather than a unique_ptr since cvc5::DType is
2384
   *       not ref counted.
2385
   */
2386
  std::shared_ptr<cvc5::DType> d_dtype;
2387
};
2388
2389
/**
2390
 * Serialize a datatype declaration to given stream.
2391
 * @param out the output stream
2392
 * @param dtdecl the datatype declaration to be serialized to the given stream
2393
 * @return the output stream
2394
 */
2395
std::ostream& operator<<(std::ostream& out,
2396
                         const DatatypeDecl& dtdecl) CVC5_EXPORT;
2397
2398
/**
2399
 * Serialize a datatype constructor declaration to given stream.
2400
 * @param out the output stream
2401
 * @param ctordecl the datatype constructor declaration to be serialized
2402
 * @return the output stream
2403
 */
2404
std::ostream& operator<<(std::ostream& out,
2405
                         const DatatypeConstructorDecl& ctordecl) CVC5_EXPORT;
2406
2407
/**
2408
 * Serialize a vector of datatype constructor declarations to given stream.
2409
 * @param out the output stream
2410
 * @param vector the vector of datatype constructor declarations to be
2411
 * serialized to the given stream
2412
 * @return the output stream
2413
 */
2414
std::ostream& operator<<(std::ostream& out,
2415
                         const std::vector<DatatypeConstructorDecl>& vector)
2416
    CVC5_EXPORT;
2417
2418
/**
2419
 * Serialize a datatype to given stream.
2420
 * @param out the output stream
2421
 * @param dtype the datatype to be serialized to given stream
2422
 * @return the output stream
2423
 */
2424
std::ostream& operator<<(std::ostream& out, const Datatype& dtype) CVC5_EXPORT;
2425
2426
/**
2427
 * Serialize a datatype constructor to given stream.
2428
 * @param out the output stream
2429
 * @param ctor the datatype constructor to be serialized to given stream
2430
 * @return the output stream
2431
 */
2432
std::ostream& operator<<(std::ostream& out,
2433
                         const DatatypeConstructor& ctor) CVC5_EXPORT;
2434
2435
/**
2436
 * Serialize a datatype selector to given stream.
2437
 * @param out the output stream
2438
 * @param stor the datatype selector to be serialized to given stream
2439
 * @return the output stream
2440
 */
2441
std::ostream& operator<<(std::ostream& out,
2442
                         const DatatypeSelector& stor) CVC5_EXPORT;
2443
2444
/* -------------------------------------------------------------------------- */
2445
/* Grammar                                                                    */
2446
/* -------------------------------------------------------------------------- */
2447
2448
/**
2449
 * A Sygus Grammar.
2450
 */
2451
315
class CVC5_EXPORT Grammar
2452
{
2453
  friend class cvc5::Command;
2454
  friend class Solver;
2455
2456
 public:
2457
  /**
2458
   * Add \p rule to the set of rules corresponding to \p ntSymbol.
2459
   * @param ntSymbol the non-terminal to which the rule is added
2460
   * @param rule the rule to add
2461
   */
2462
  void addRule(const Term& ntSymbol, const Term& rule);
2463
2464
  /**
2465
   * Add \p rules to the set of rules corresponding to \p ntSymbol.
2466
   * @param ntSymbol the non-terminal to which the rules are added
2467
   * @param rules the rules to add
2468
   */
2469
  void addRules(const Term& ntSymbol, const std::vector<Term>& rules);
2470
2471
  /**
2472
   * Allow \p ntSymbol to be an arbitrary constant.
2473
   * @param ntSymbol the non-terminal allowed to be any constant
2474
   */
2475
  void addAnyConstant(const Term& ntSymbol);
2476
2477
  /**
2478
   * Allow \p ntSymbol to be any input variable to corresponding
2479
   * synth-fun/synth-inv with the same sort as \p ntSymbol.
2480
   * @param ntSymbol the non-terminal allowed to be any input variable
2481
   */
2482
  void addAnyVariable(const Term& ntSymbol);
2483
2484
  /**
2485
   * @return a string representation of this grammar.
2486
   */
2487
  std::string toString() const;
2488
2489
  /**
2490
   * Nullary constructor. Needed for the Cython API.
2491
   */
2492
  Grammar();
2493
2494
 private:
2495
  /**
2496
   * Constructor.
2497
   * @param slv the solver that created this grammar
2498
   * @param sygusVars the input variables to synth-fun/synth-var
2499
   * @param ntSymbols the non-terminals of this grammar
2500
   */
2501
  Grammar(const Solver* slv,
2502
          const std::vector<Term>& sygusVars,
2503
          const std::vector<Term>& ntSymbols);
2504
2505
  /**
2506
   * @return the resolved datatype of the Start symbol of the grammar
2507
   */
2508
  Sort resolve();
2509
2510
  /**
2511
   * Adds a constructor to sygus datatype <dt> whose sygus operator is <term>.
2512
   *
2513
   * \p ntsToUnres contains a mapping from non-terminal symbols to the
2514
   * unresolved sorts they correspond to. This map indicates how the argument
2515
   * <term> should be interpreted (instances of symbols from the domain of
2516
   * \p ntsToUnres correspond to constructor arguments).
2517
   *
2518
   * The sygus operator that is actually added to <dt> corresponds to replacing
2519
   * each occurrence of non-terminal symbols from the domain of \p ntsToUnres
2520
   * with bound variables via purifySygusGTerm, and binding these variables
2521
   * via a lambda.
2522
   *
2523
   * @param dt the non-terminal's datatype to which a constructor is added
2524
   * @param term the sygus operator of the constructor
2525
   * @param ntsToUnres mapping from non-terminals to their unresolved sorts
2526
   */
2527
  void addSygusConstructorTerm(
2528
      DatatypeDecl& dt,
2529
      const Term& term,
2530
      const std::unordered_map<Term, Sort>& ntsToUnres) const;
2531
2532
  /**
2533
   * Purify SyGuS grammar term.
2534
   *
2535
   * This returns a term where all occurrences of non-terminal symbols (those
2536
   * in the domain of \p ntsToUnres) are replaced by fresh variables. For
2537
   * each variable replaced in this way, we add the fresh variable it is
2538
   * replaced with to \p args, and the unresolved sorts corresponding to the
2539
   * non-terminal symbol to \p cargs (constructor args). In other words,
2540
   * \p args contains the free variables in the term returned by this method
2541
   * (which should be bound by a lambda), and \p cargs contains the sorts of
2542
   * the arguments of the sygus constructor.
2543
   *
2544
   * @param term the term to purify
2545
   * @param args the free variables in the term returned by this method
2546
   * @param cargs the sorts of the arguments of the sygus constructor
2547
   * @param ntsToUnres mapping from non-terminals to their unresolved sorts
2548
   * @return the purfied term
2549
   */
2550
  Term purifySygusGTerm(const Term& term,
2551
                        std::vector<Term>& args,
2552
                        std::vector<Sort>& cargs,
2553
                        const std::unordered_map<Term, Sort>& ntsToUnres) const;
2554
2555
  /**
2556
   * This adds constructors to \p dt for sygus variables in \p d_sygusVars
2557
   * whose sort is argument \p sort. This method should be called when the
2558
   * sygus grammar term (Variable sort) is encountered.
2559
   *
2560
   * @param dt the non-terminal's datatype to which the constructors are added
2561
   * @param sort the sort of the sygus variables to add
2562
   */
2563
  void addSygusConstructorVariables(DatatypeDecl& dt, const Sort& sort) const;
2564
2565
  /**
2566
   * Check if \p rule contains variables that are neither parameters of
2567
   * the corresponding synthFun/synthInv nor non-terminals.
2568
   * @param rule the non-terminal allowed to be any constant
2569
   * @return true if \p rule contains free variables and false otherwise
2570
   */
2571
  bool containsFreeVariables(const Term& rule) const;
2572
2573
  /** The solver that created this grammar. */
2574
  const Solver* d_solver;
2575
  /** Input variables to the corresponding function/invariant to synthesize.*/
2576
  std::vector<Term> d_sygusVars;
2577
  /** The non-terminal symbols of this grammar. */
2578
  std::vector<Term> d_ntSyms;
2579
  /** The mapping from non-terminal symbols to their production terms. */
2580
  std::unordered_map<Term, std::vector<Term>> d_ntsToTerms;
2581
  /** The set of non-terminals that can be arbitrary constants. */
2582
  std::unordered_set<Term> d_allowConst;
2583
  /** The set of non-terminals that can be sygus variables. */
2584
  std::unordered_set<Term> d_allowVars;
2585
  /** Did we call resolve() before? */
2586
  bool d_isResolved;
2587
};
2588
2589
/**
2590
 * Serialize a grammar to given stream.
2591
 * @param out the output stream
2592
 * @param g the grammar to be serialized to the given output stream
2593
 * @return the output stream
2594
 */
2595
std::ostream& operator<<(std::ostream& out, const Grammar& g) CVC5_EXPORT;
2596
2597
/* -------------------------------------------------------------------------- */
2598
/* Rounding Mode for Floating-Points                                          */
2599
/* -------------------------------------------------------------------------- */
2600
2601
/**
2602
 * Rounding modes for floating-point numbers.
2603
 *
2604
 * For many floating-point operations, infinitely precise results may not be
2605
 * representable with the number of available bits. Thus, the results are
2606
 * rounded in a certain way to one of the representable floating-point numbers.
2607
 *
2608
 * \verbatim embed:rst:leading-asterisk
2609
 * These rounding modes directly follow the SMT-LIB theory for floating-point
2610
 * arithmetic, which in turn is based on IEEE Standard 754 :cite:`IEEE754`.
2611
 * The rounding modes are specified in Sections 4.3.1 and 4.3.2 of the IEEE
2612
 * Standard 754.
2613
 * \endverbatim
2614
 */
2615
enum RoundingMode
2616
{
2617
  /**
2618
   * Round to the nearest even number.
2619
   * If the two nearest floating-point numbers bracketing an unrepresentable
2620
   * infinitely precise result are equally near, the one with an even least
2621
   * significant digit will be delivered.
2622
   */
2623
  ROUND_NEAREST_TIES_TO_EVEN,
2624
  /**
2625
   * Round towards positive infinity (+oo).
2626
   * The result shall be the format’s floating-point number (possibly +oo)
2627
   * closest to and no less than the infinitely precise result.
2628
   */
2629
  ROUND_TOWARD_POSITIVE,
2630
  /**
2631
   * Round towards negative infinity (-oo).
2632
   * The result shall be the format’s floating-point number (possibly -oo)
2633
   * closest to and no less than the infinitely precise result.
2634
   */
2635
  ROUND_TOWARD_NEGATIVE,
2636
  /**
2637
   * Round towards zero.
2638
   * The result shall be the format’s floating-point number closest to and no
2639
   * greater in magnitude than the infinitely precise result.
2640
   */
2641
  ROUND_TOWARD_ZERO,
2642
  /**
2643
   * Round to the nearest number away from zero.
2644
   * If the two nearest floating-point numbers bracketing an unrepresentable
2645
   * infinitely precise result are equally near, the one with larger magnitude
2646
   * will be selected.
2647
   */
2648
  ROUND_NEAREST_TIES_TO_AWAY,
2649
};
2650
2651
}  // namespace cvc5::api
2652
2653
namespace std {
2654
2655
/**
2656
 * Hash function for RoundingModes.
2657
 */
2658
template <>
2659
struct CVC5_EXPORT hash<cvc5::api::RoundingMode>
2660
{
2661
  size_t operator()(cvc5::api::RoundingMode rm) const;
2662
};
2663
}  // namespace std
2664
namespace cvc5::api {
2665
2666
/* -------------------------------------------------------------------------- */
2667
/* Options                                                                    */
2668
/* -------------------------------------------------------------------------- */
2669
2670
/**
2671
 * Provides access to options that can not be communicated via the regular
2672
 * getOption() or getOptionInfo() methods. This class does not store the options
2673
 * itself, but only acts as a wrapper to the solver object. It can thus no
2674
 * longer be used after the solver object has been destroyed.
2675
 */
2676
class CVC5_EXPORT DriverOptions
2677
{
2678
  friend class Solver;
2679
2680
 public:
2681
  /** Access the solvers input stream */
2682
  std::istream& in() const;
2683
  /** Access the solvers error output stream */
2684
  std::ostream& err() const;
2685
  /** Access the solvers output stream */
2686
  std::ostream& out() const;
2687
2688
 private:
2689
  DriverOptions(const Solver& solver);
2690
  const Solver& d_solver;
2691
};
2692
2693
/**
2694
 * Holds some description about a particular option, including its name, its
2695
 * aliases, whether the option was explicitly set by the user, and information
2696
 * concerning its value. The `valueInfo` member holds any of the following
2697
 * alternatives:
2698
 * - VoidInfo if the option holds no value (or the value has no native type)
2699
 * - ValueInfo<T> if the option is of type bool or std::string, holds the
2700
 *   current value and the default value.
2701
 * - NumberInfo<T> if the option is of type int64_t, uint64_t or double, holds
2702
 *   the current and default value, as well as the minimum and maximum.
2703
 * - ModeInfo if the option is a mode option, holds the current and default
2704
 *   values, as well as a list of valid modes.
2705
 * Additionally, this class provides convenience functions to obtain the
2706
 * current value of an option in a type-safe manner using boolValue(),
2707
 * stringValue(), intValue(), uintValue() and doubleValue(). They assert that
2708
 * the option has the respective type and return the current value.
2709
 */
2710
2032098
struct CVC5_EXPORT OptionInfo
2711
{
2712
  /** Has no value information */
2713
  struct VoidInfo {};
2714
  /** Has the current and the default value */
2715
  template <typename T>
2716
20170
  struct ValueInfo
2717
  {
2718
    T defaultValue;
2719
    T currentValue;
2720
  };
2721
  /** Default value, current value, minimum and maximum of a numeric value */
2722
  template <typename T>
2723
249012
  struct NumberInfo
2724
  {
2725
    T defaultValue;
2726
    T currentValue;
2727
    std::optional<T> minimum;
2728
    std::optional<T> maximum;
2729
  };
2730
  /** Default value, current value and choices of a mode option */
2731
10
  struct ModeInfo
2732
  {
2733
    std::string defaultValue;
2734
    std::string currentValue;
2735
    std::vector<std::string> modes;
2736
  };
2737
2738
  /** The option name */
2739
  std::string name;
2740
  /** The option name aliases */
2741
  std::vector<std::string> aliases;
2742
  /** Whether the option was explicitly set by the user */
2743
  bool setByUser;
2744
  /** The option value information */
2745
  std::variant<VoidInfo,
2746
               ValueInfo<bool>,
2747
               ValueInfo<std::string>,
2748
               NumberInfo<int64_t>,
2749
               NumberInfo<uint64_t>,
2750
               NumberInfo<double>,
2751
               ModeInfo>
2752
      valueInfo;
2753
  /** Obtain the current value as a bool. Asserts that valueInfo holds a bool.
2754
   */
2755
  bool boolValue() const;
2756
  /** Obtain the current value as a string. Asserts that valueInfo holds a
2757
   * string. */
2758
  std::string stringValue() const;
2759
  /** Obtain the current value as as int. Asserts that valueInfo holds an int.
2760
   */
2761
  int64_t intValue() const;
2762
  /** Obtain the current value as a uint. Asserts that valueInfo holds a uint.
2763
   */
2764
  uint64_t uintValue() const;
2765
  /** Obtain the current value as a double. Asserts that valueInfo holds a
2766
   * double. */
2767
  double doubleValue() const;
2768
};
2769
2770
/**
2771
 * Print a `OptionInfo` object to an ``std::ostream``.
2772
 */
2773
std::ostream& operator<<(std::ostream& os, const OptionInfo& oi) CVC5_EXPORT;
2774
2775
/* -------------------------------------------------------------------------- */
2776
/* Statistics                                                                 */
2777
/* -------------------------------------------------------------------------- */
2778
2779
/**
2780
 * Represents a snapshot of a single statistic value.
2781
 * A value can be of type `int64_t`, `double`, `std::string` or a histogram
2782
 * (`std::map<std::string, uint64_t>`).
2783
 * The value type can be queried (using `isInt()`, `isDouble()`, etc.) and
2784
 * the stored value can be accessed (using `getInt()`, `getDouble()`, etc.).
2785
 * It is possible to query whether this statistic is an expert statistic by
2786
 * `isExpert()` and whether its value is the default value by `isDefault()`.
2787
 */
2788
class CVC5_EXPORT Stat
2789
{
2790
  struct StatData;
2791
2792
 public:
2793
  friend class Statistics;
2794
  friend std::ostream& operator<<(std::ostream& os, const Stat& sv);
2795
  /** Representation of a histogram: maps names to frequencies. */
2796
  using HistogramData = std::map<std::string, uint64_t>;
2797
  /** Can only be obtained from a `Statistics` object. */
2798
  Stat() = delete;
2799
  /** Copy constructor */
2800
  Stat(const Stat& s);
2801
  /** Destructor */
2802
  ~Stat();
2803
  /** Copy assignment */
2804
  Stat& operator=(const Stat& s);
2805
2806
  /**
2807
   * Is this value intended for experts only?
2808
   * @return Whether this is an expert statistic.
2809
   */
2810
  bool isExpert() const;
2811
  /**
2812
   * Does this value hold the default value?
2813
   * @return Whether this is a defaulted statistic.
2814
   */
2815
  bool isDefault() const;
2816
2817
  /**
2818
   * Is this value an integer?
2819
   * @return Whether the value is an integer.
2820
   */
2821
  bool isInt() const;
2822
  /**
2823
   * Return the integer value.
2824
   * @return The integer value.
2825
   */
2826
  int64_t getInt() const;
2827
  /**
2828
   * Is this value a double?
2829
   * @return Whether the value is a double.
2830
   */
2831
  bool isDouble() const;
2832
  /**
2833
   * Return the double value.
2834
   * @return The double value.
2835
   */
2836
  double getDouble() const;
2837
  /**
2838
   * Is this value a string?
2839
   * @return Whether the value is a string.
2840
   */
2841
  bool isString() const;
2842
  /**
2843
   * Return the string value.
2844
   * @return The string value.
2845
   */
2846
  const std::string& getString() const;
2847
  /**
2848
   * Is this value a histogram?
2849
   * @return Whether the value is a histogram.
2850
   */
2851
  bool isHistogram() const;
2852
  /**
2853
   * Return the histogram value.
2854
   * @return The histogram value.
2855
   */
2856
  const HistogramData& getHistogram() const;
2857
2858
 private:
2859
  Stat(bool expert, bool def, StatData&& sd);
2860
  /** Whether this statistic is only meant for experts */
2861
  bool d_expert;
2862
  /** Whether this statistic has the default value */
2863
  bool d_default;
2864
  std::unique_ptr<StatData> d_data;
2865
};
2866
2867
/**
2868
 * Print a `Stat` object to an ``std::ostream``.
2869
 */
2870
std::ostream& operator<<(std::ostream& os, const Stat& sv) CVC5_EXPORT;
2871
2872
/**
2873
 * Represents a snapshot of the solver statistics.
2874
 * Once obtained, an instance of this class is independent of the `Solver`
2875
 * object: it will not change when the solvers internal statistics do, it
2876
 * will not be invalidated if the solver is destroyed.
2877
 * Iterating on this class (via `begin()` and `end()`) shows only public
2878
 * statistics that have been changed. By passing appropriate flags to
2879
 * `begin()`, statistics that are expert, defaulted, or both, can be
2880
 * included as well. A single statistic value is represented as `Stat`.
2881
 */
2882
class CVC5_EXPORT Statistics
2883
{
2884
 public:
2885
  friend class Solver;
2886
  /** How the statistics are stored internally. */
2887
  using BaseType = std::map<std::string, Stat>;
2888
2889
  /** Custom iterator to hide certain statistics from regular iteration */
2890
  class CVC5_EXPORT iterator
2891
  {
2892
   public:
2893
    friend class Statistics;
2894
    BaseType::const_reference operator*() const;
2895
    BaseType::const_pointer operator->() const;
2896
    iterator& operator++();
2897
    iterator operator++(int);
2898
    iterator& operator--();
2899
    iterator operator--(int);
2900
    bool operator==(const iterator& rhs) const;
2901
    bool operator!=(const iterator& rhs) const;
2902
2903
   private:
2904
    iterator(BaseType::const_iterator it,
2905
             const BaseType& base,
2906
             bool expert,
2907
             bool defaulted);
2908
    bool isVisible() const;
2909
    BaseType::const_iterator d_it;
2910
    const BaseType* d_base;
2911
    bool d_showExpert = false;
2912
    bool d_showDefault = false;
2913
  };
2914
2915
  /**
2916
   * Retrieve the statistic with the given name.
2917
   * Asserts that a statistic with the given name actually exists and throws
2918
   * a `CVC5ApiRecoverableException` if it does not.
2919
   * @param name Name of the statistic.
2920
   * @return The statistic with the given name.
2921
   */
2922
  const Stat& get(const std::string& name);
2923
  /**
2924
   * Begin iteration over the statistics values.
2925
   * By default, only entries that are public (non-expert) and have been set
2926
   * are visible while the others are skipped.
2927
   * @param expert If set to true, expert statistics are shown as well.
2928
   * @param defaulted If set to true, defaulted statistics are shown as well.
2929
   */
2930
  iterator begin(bool expert = false, bool defaulted = false) const;
2931
  /** End iteration */
2932
  iterator end() const;
2933
2934
 private:
2935
  Statistics() = default;
2936
  Statistics(const StatisticsRegistry& reg);
2937
  /** Internal data */
2938
  BaseType d_stats;
2939
};
2940
std::ostream& operator<<(std::ostream& out,
2941
                         const Statistics& stats) CVC5_EXPORT;
2942
2943
/* -------------------------------------------------------------------------- */
2944
/* Solver                                                                     */
2945
/* -------------------------------------------------------------------------- */
2946
2947
/**
2948
 * A cvc5 solver.
2949
 */
2950
class CVC5_EXPORT Solver
2951
{
2952
  friend class Datatype;
2953
  friend class DatatypeDecl;
2954
  friend class DatatypeConstructor;
2955
  friend class DatatypeConstructorDecl;
2956
  friend class DatatypeSelector;
2957
  friend class DriverOptions;
2958
  friend class Grammar;
2959
  friend class Op;
2960
  friend class cvc5::Command;
2961
  friend class cvc5::main::CommandExecutor;
2962
  friend class Sort;
2963
  friend class Term;
2964
2965
 private:
2966
  /*
2967
   * Constructs a solver with the given original options. This should only be
2968
   * used internally when the Solver is reset.
2969
   */
2970
  Solver(std::unique_ptr<Options>&& original);
2971
2972
 public:
2973
  /* .................................................................... */
2974
  /* Constructors/Destructors                                             */
2975
  /* .................................................................... */
2976
2977
  /**
2978
   * Constructor.
2979
   * @return the Solver
2980
   */
2981
  Solver();
2982
2983
  /**
2984
   * Destructor.
2985
   */
2986
  ~Solver();
2987
2988
  /**
2989
   * Disallow copy/assignment.
2990
   */
2991
  Solver(const Solver&) = delete;
2992
  Solver& operator=(const Solver&) = delete;
2993
2994
  /* .................................................................... */
2995
  /* Sorts Handling                                                       */
2996
  /* .................................................................... */
2997
2998
  /**
2999
   * @return sort null
3000
   */
3001
  Sort getNullSort() const;
3002
3003
  /**
3004
   * @return sort Boolean
3005
   */
3006
  Sort getBooleanSort() const;
3007
3008
  /**
3009
   * @return sort Integer (in cvc5, Integer is a subtype of Real)
3010
   */
3011
  Sort getIntegerSort() const;
3012
3013
  /**
3014
   * @return sort Real
3015
   */
3016
  Sort getRealSort() const;
3017
3018
  /**
3019
   * @return sort RegExp
3020
   */
3021
  Sort getRegExpSort() const;
3022
3023
  /**
3024
   * @return sort RoundingMode
3025
   */
3026
  Sort getRoundingModeSort() const;
3027
3028
  /**
3029
   * @return sort String
3030
   */
3031
  Sort getStringSort() const;
3032
3033
  /**
3034
   * Create an array sort.
3035
   * @param indexSort the array index sort
3036
   * @param elemSort the array element sort
3037
   * @return the array sort
3038
   */
3039
  Sort mkArraySort(const Sort& indexSort, const Sort& elemSort) const;
3040
3041
  /**
3042
   * Create a bit-vector sort.
3043
   * @param size the bit-width of the bit-vector sort
3044
   * @return the bit-vector sort
3045
   */
3046
  Sort mkBitVectorSort(uint32_t size) const;
3047
3048
  /**
3049
   * Create a floating-point sort.
3050
   * @param exp the bit-width of the exponent of the floating-point sort.
3051
   * @param sig the bit-width of the significand of the floating-point sort.
3052
   */
3053
  Sort mkFloatingPointSort(uint32_t exp, uint32_t sig) const;
3054
3055
  /**
3056
   * Create a datatype sort.
3057
   * @param dtypedecl the datatype declaration from which the sort is created
3058
   * @return the datatype sort
3059
   */
3060
  Sort mkDatatypeSort(const DatatypeDecl& dtypedecl) const;
3061
3062
  /**
3063
   * Create a vector of datatype sorts. The names of the datatype declarations
3064
   * must be distinct.
3065
   *
3066
   * @param dtypedecls the datatype declarations from which the sort is created
3067
   * @return the datatype sorts
3068
   */
3069
  std::vector<Sort> mkDatatypeSorts(
3070
      const std::vector<DatatypeDecl>& dtypedecls) const;
3071
3072
  /**
3073
   * Create a vector of datatype sorts using unresolved sorts. The names of
3074
   * the datatype declarations in dtypedecls must be distinct.
3075
   *
3076
   * This method is called when the DatatypeDecl objects dtypedecls have been
3077
   * built using "unresolved" sorts.
3078
   *
3079
   * We associate each sort in unresolvedSorts with exactly one datatype from
3080
   * dtypedecls. In particular, it must have the same name as exactly one
3081
   * datatype declaration in dtypedecls.
3082
   *
3083
   * When constructing datatypes, unresolved sorts are replaced by the datatype
3084
   * sort constructed for the datatype declaration it is associated with.
3085
   *
3086
   * @param dtypedecls the datatype declarations from which the sort is created
3087
   * @param unresolvedSorts the list of unresolved sorts
3088
   * @return the datatype sorts
3089
   */
3090
  std::vector<Sort> mkDatatypeSorts(
3091
      const std::vector<DatatypeDecl>& dtypedecls,
3092
      const std::set<Sort>& unresolvedSorts) const;
3093
3094
  /**
3095
   * Create function sort.
3096
   * @param domain the sort of the function argument
3097
   * @param codomain the sort of the function return value
3098
   * @return the function sort
3099
   */
3100
  Sort mkFunctionSort(const Sort& domain, const Sort& codomain) const;
3101
3102
  /**
3103
   * Create function sort.
3104
   * @param sorts the sort of the function arguments
3105
   * @param codomain the sort of the function return value
3106
   * @return the function sort
3107
   */
3108
  Sort mkFunctionSort(const std::vector<Sort>& sorts,
3109
                      const Sort& codomain) const;
3110
3111
  /**
3112
   * Create a sort parameter.
3113
   * @param symbol the name of the sort
3114
   * @return the sort parameter
3115
   */
3116
  Sort mkParamSort(const std::string& symbol) const;
3117
3118
  /**
3119
   * Create a predicate sort.
3120
   * @param sorts the list of sorts of the predicate
3121
   * @return the predicate sort
3122
   */
3123
  Sort mkPredicateSort(const std::vector<Sort>& sorts) const;
3124
3125
  /**
3126
   * Create a record sort
3127
   * @param fields the list of fields of the record
3128
   * @return the record sort
3129
   */
3130
  Sort mkRecordSort(
3131
      const std::vector<std::pair<std::string, Sort>>& fields) const;
3132
3133
  /**
3134
   * Create a set sort.
3135
   * @param elemSort the sort of the set elements
3136
   * @return the set sort
3137
   */
3138
  Sort mkSetSort(const Sort& elemSort) const;
3139
3140
  /**
3141
   * Create a bag sort.
3142
   * @param elemSort the sort of the bag elements
3143
   * @return the bag sort
3144
   */
3145
  Sort mkBagSort(const Sort& elemSort) const;
3146
3147
  /**
3148
   * Create a sequence sort.
3149
   * @param elemSort the sort of the sequence elements
3150
   * @return the sequence sort
3151
   */
3152
  Sort mkSequenceSort(const Sort& elemSort) const;
3153
3154
  /**
3155
   * Create an uninterpreted sort.
3156
   * @param symbol the name of the sort
3157
   * @return the uninterpreted sort
3158
   */
3159
  Sort mkUninterpretedSort(const std::string& symbol) const;
3160
3161
  /**
3162
   * Create a sort constructor sort.
3163
   * @param symbol the symbol of the sort
3164
   * @param arity the arity of the sort
3165
   * @return the sort constructor sort
3166
   */
3167
  Sort mkSortConstructorSort(const std::string& symbol, size_t arity) const;
3168
3169
  /**
3170
   * Create a tuple sort.
3171
   * @param sorts of the elements of the tuple
3172
   * @return the tuple sort
3173
   */
3174
  Sort mkTupleSort(const std::vector<Sort>& sorts) const;
3175
3176
  /* .................................................................... */
3177
  /* Create Terms                                                         */
3178
  /* .................................................................... */
3179
3180
  /**
3181
   * Create 0-ary term of given kind.
3182
   * @param kind the kind of the term
3183
   * @return the Term
3184
   */
3185
  Term mkTerm(Kind kind) const;
3186
3187
  /**
3188
   * Create a unary term of given kind.
3189
   * @param kind the kind of the term
3190
   * @param child the child of the term
3191
   * @return the Term
3192
   */
3193
  Term mkTerm(Kind kind, const Term& child) const;
3194
3195
  /**
3196
   * Create binary term of given kind.
3197
   * @param kind the kind of the term
3198
   * @param child1 the first child of the term
3199
   * @param child2 the second child of the term
3200
   * @return the Term
3201
   */
3202
  Term mkTerm(Kind kind, const Term& child1, const Term& child2) const;
3203
3204
  /**
3205
   * Create ternary term of given kind.
3206
   * @param kind the kind of the term
3207
   * @param child1 the first child of the term
3208
   * @param child2 the second child of the term
3209
   * @param child3 the third child of the term
3210
   * @return the Term
3211
   */
3212
  Term mkTerm(Kind kind,
3213
              const Term& child1,
3214
              const Term& child2,
3215
              const Term& child3) const;
3216
3217
  /**
3218
   * Create n-ary term of given kind.
3219
   * @param kind the kind of the term
3220
   * @param children the children of the term
3221
   * @return the Term
3222
   */
3223
  Term mkTerm(Kind kind, const std::vector<Term>& children) const;
3224
3225
  /**
3226
   * Create nullary term of given kind from a given operator.
3227
   * Create operators with mkOp().
3228
   * @param op the operator
3229
   * @return the Term
3230
   */
3231
  Term mkTerm(const Op& op) const;
3232
3233
  /**
3234
   * Create unary term of given kind from a given operator.
3235
   * Create operators with mkOp().
3236
   * @param op the operator
3237
   * @param child the child of the term
3238
   * @return the Term
3239
   */
3240
  Term mkTerm(const Op& op, const Term& child) const;
3241
3242
  /**
3243
   * Create binary term of given kind from a given operator.
3244
   * Create operators with mkOp().
3245
   * @param op the operator
3246
   * @param child1 the first child of the term
3247
   * @param child2 the second child of the term
3248
   * @return the Term
3249
   */
3250
  Term mkTerm(const Op& op, const Term& child1, const Term& child2) const;
3251
3252
  /**
3253
   * Create ternary term of given kind from a given operator.
3254
   * Create operators with mkOp().
3255
   * @param op the operator
3256
   * @param child1 the first child of the term
3257
   * @param child2 the second child of the term
3258
   * @param child3 the third child of the term
3259
   * @return the Term
3260
   */
3261
  Term mkTerm(const Op& op,
3262
              const Term& child1,
3263
              const Term& child2,
3264
              const Term& child3) const;
3265
3266
  /**
3267
   * Create n-ary term of given kind from a given operator.
3268
   * Create operators with mkOp().
3269
   * @param op the operator
3270
   * @param children the children of the term
3271
   * @return the Term
3272
   */
3273
  Term mkTerm(const Op& op, const std::vector<Term>& children) const;
3274
3275
  /**
3276
   * Create a tuple term. Terms are automatically converted if sorts are
3277
   * compatible.
3278
   * @param sorts The sorts of the elements in the tuple
3279
   * @param terms The elements in the tuple
3280
   * @return the tuple Term
3281
   */
3282
  Term mkTuple(const std::vector<Sort>& sorts,
3283
               const std::vector<Term>& terms) const;
3284
3285
  /* .................................................................... */
3286
  /* Create Operators                                                     */
3287
  /* .................................................................... */
3288
3289
  /**
3290
   * Create an operator for a builtin Kind
3291
   * The Kind may not be the Kind for an indexed operator
3292
   *   (e.g. BITVECTOR_EXTRACT)
3293
   * Note: in this case, the Op simply wraps the Kind.
3294
   * The Kind can be used in mkTerm directly without
3295
   *   creating an op first.
3296
   * @param kind the kind to wrap
3297
   */
3298
  Op mkOp(Kind kind) const;
3299
3300
  /**
3301
   * Create operator of kind:
3302
   *   - DIVISIBLE (to support arbitrary precision integers)
3303
   * See enum Kind for a description of the parameters.
3304
   * @param kind the kind of the operator
3305
   * @param arg the string argument to this operator
3306
   */
3307
  Op mkOp(Kind kind, const std::string& arg) const;
3308
3309
  /**
3310
   * Create operator of kind:
3311
   *   - DIVISIBLE
3312
   *   - BITVECTOR_REPEAT
3313
   *   - BITVECTOR_ZERO_EXTEND
3314
   *   - BITVECTOR_SIGN_EXTEND
3315
   *   - BITVECTOR_ROTATE_LEFT
3316
   *   - BITVECTOR_ROTATE_RIGHT
3317
   *   - INT_TO_BITVECTOR
3318
   *   - FLOATINGPOINT_TO_UBV
3319
   *   - FLOATINGPOINT_TO_UBV_TOTAL
3320
   *   - FLOATINGPOINT_TO_SBV
3321
   *   - FLOATINGPOINT_TO_SBV_TOTAL
3322
   *   - TUPLE_UPDATE
3323
   * See enum Kind for a description of the parameters.
3324
   * @param kind the kind of the operator
3325
   * @param arg the uint32_t argument to this operator
3326
   */
3327
  Op mkOp(Kind kind, uint32_t arg) const;
3328
3329
  /**
3330
   * Create operator of Kind:
3331
   *   - BITVECTOR_EXTRACT
3332
   *   - FLOATINGPOINT_TO_FP_IEEE_BITVECTOR
3333
   *   - FLOATINGPOINT_TO_FP_FLOATINGPOINT
3334
   *   - FLOATINGPOINT_TO_FP_REAL
3335
   *   - FLOATINGPOINT_TO_FP_SIGNED_BITVECTOR
3336
   *   - FLOATINGPOINT_TO_FP_UNSIGNED_BITVECTOR
3337
   *   - FLOATINGPOINT_TO_FP_GENERIC
3338
   * See enum Kind for a description of the parameters.
3339
   * @param kind the kind of the operator
3340
   * @param arg1 the first uint32_t argument to this operator
3341
   * @param arg2 the second uint32_t argument to this operator
3342
   */
3343
  Op mkOp(Kind kind, uint32_t arg1, uint32_t arg2) const;
3344
3345
  /**
3346
   * Create operator of Kind:
3347
   *   - TUPLE_PROJECT
3348
   * See enum Kind for a description of the parameters.
3349
   * @param kind the kind of the operator
3350
   * @param args the arguments (indices) of the operator
3351
   */
3352
  Op mkOp(Kind kind, const std::vector<uint32_t>& args) const;
3353
3354
  /* .................................................................... */
3355
  /* Create Constants                                                     */
3356
  /* .................................................................... */
3357
3358
  /**
3359
   * Create a Boolean true constant.
3360
   * @return the true constant
3361
   */
3362
  Term mkTrue() const;
3363
3364
  /**
3365
   * Create a Boolean false constant.
3366
   * @return the false constant
3367
   */
3368
  Term mkFalse() const;
3369
3370
  /**
3371
   * Create a Boolean constant.
3372
   * @return the Boolean constant
3373
   * @param val the value of the constant
3374
   */
3375
  Term mkBoolean(bool val) const;
3376
3377
  /**
3378
   * Create a constant representing the number Pi.
3379
   * @return a constant representing Pi
3380
   */
3381
  Term mkPi() const;
3382
  /**
3383
   * Create an integer constant from a string.
3384
   * @param s the string representation of the constant, may represent an
3385
   *          integer (e.g., "123").
3386
   * @return a constant of sort Integer assuming 's' represents an integer)
3387
   */
3388
  Term mkInteger(const std::string& s) const;
3389
3390
  /**
3391
   * Create an integer constant from a c++ int.
3392
   * @param val the value of the constant
3393
   * @return a constant of sort Integer
3394
   */
3395
  Term mkInteger(int64_t val) const;
3396
3397
  /**
3398
   * Create a real constant from a string.
3399
   * @param s the string representation of the constant, may represent an
3400
   *          integer (e.g., "123") or real constant (e.g., "12.34" or "12/34").
3401
   * @return a constant of sort Real
3402
   */
3403
  Term mkReal(const std::string& s) const;
3404
3405
  /**
3406
   * Create a real constant from an integer.
3407
   * @param val the value of the constant
3408
   * @return a constant of sort Integer
3409
   */
3410
  Term mkReal(int64_t val) const;
3411
3412
  /**
3413
   * Create a real constant from a rational.
3414
   * @param num the value of the numerator
3415
   * @param den the value of the denominator
3416
   * @return a constant of sort Real
3417
   */
3418
  Term mkReal(int64_t num, int64_t den) const;
3419
3420
  /**
3421
   * Create a regular expression empty term.
3422
   * @return the empty term
3423
   */
3424
  Term mkRegexpEmpty() const;
3425
3426
  /**
3427
   * Create a regular expression sigma term.
3428
   * @return the sigma term
3429
   */
3430
  Term mkRegexpSigma() const;
3431
3432
  /**
3433
   * Create a constant representing an empty set of the given sort.
3434
   * @param sort the sort of the set elements.
3435
   * @return the empty set constant
3436
   */
3437
  Term mkEmptySet(const Sort& sort) const;
3438
3439
  /**
3440
   * Create a constant representing an empty bag of the given sort.
3441
   * @param sort the sort of the bag elements.
3442
   * @return the empty bag constant
3443
   */
3444
  Term mkEmptyBag(const Sort& sort) const;
3445
3446
  /**
3447
   * Create a separation logic empty term.
3448
   * @return the separation logic empty term
3449
   */
3450
  Term mkSepEmp() const;
3451
3452
  /**
3453
   * Create a separation logic nil term.
3454
   * @param sort the sort of the nil term
3455
   * @return the separation logic nil term
3456
   */
3457
  Term mkSepNil(const Sort& sort) const;
3458
3459
  /**
3460
   * Create a String constant from a `std::string` which may contain SMT-LIB
3461
   * compatible escape sequences like `\u1234` to encode unicode characters.
3462
   * @param s the string this constant represents
3463
   * @param useEscSequences determines whether escape sequences in `s` should
3464
   * be converted to the corresponding unicode character
3465
   * @return the String constant
3466
   */
3467
  Term mkString(const std::string& s, bool useEscSequences = false) const;
3468
3469
  /**
3470
   * Create a String constant from a `std::wstring`.
3471
   * This method does not support escape sequences as `std::wstring` already
3472
   * supports unicode characters.
3473
   * @param s the string this constant represents
3474
   * @return the String constant
3475
   */
3476
  Term mkString(const std::wstring& s) const;
3477
3478
  /**
3479
   * Create an empty sequence of the given element sort.
3480
   * @param sort The element sort of the sequence.
3481
   * @return the empty sequence with given element sort.
3482
   */
3483
  Term mkEmptySequence(const Sort& sort) const;
3484
3485
  /**
3486
   * Create a universe set of the given sort.
3487
   * @param sort the sort of the set elements
3488
   * @return the universe set constant
3489
   */
3490
  Term mkUniverseSet(const Sort& sort) const;
3491
3492
  /**
3493
   * Create a bit-vector constant of given size and value.
3494
   *
3495
   * Note: The given value must fit into a bit-vector of the given size.
3496
   *
3497
   * @param size the bit-width of the bit-vector sort
3498
   * @param val the value of the constant
3499
   * @return the bit-vector constant
3500
   */
3501
  Term mkBitVector(uint32_t size, uint64_t val = 0) const;
3502
3503
  /**
3504
   * Create a bit-vector constant of a given bit-width from a given string of
3505
   * base 2, 10 or 16.
3506
   *
3507
   * Note: The given value must fit into a bit-vector of the given size.
3508
   *
3509
   * @param size the bit-width of the constant
3510
   * @param s the string representation of the constant
3511
   * @param base the base of the string representation (2, 10, or 16)
3512
   * @return the bit-vector constant
3513
   */
3514
  Term mkBitVector(uint32_t size, const std::string& s, uint32_t base) const;
3515
3516
  /**
3517
   * Create a constant array with the provided constant value stored at every
3518
   * index
3519
   * @param sort the sort of the constant array (must be an array sort)
3520
   * @param val the constant value to store (must match the sort's element sort)
3521
   * @return the constant array term
3522
   */
3523
  Term mkConstArray(const Sort& sort, const Term& val) const;
3524
3525
  /**
3526
   * Create a positive infinity floating-point constant.
3527
   * @param exp Number of bits in the exponent
3528
   * @param sig Number of bits in the significand
3529
   * @return the floating-point constant
3530
   */
3531
  Term mkPosInf(uint32_t exp, uint32_t sig) const;
3532
3533
  /**
3534
   * Create a negative infinity floating-point constant.
3535
   * @param exp Number of bits in the exponent
3536
   * @param sig Number of bits in the significand
3537
   * @return the floating-point constant
3538
   */
3539
  Term mkNegInf(uint32_t exp, uint32_t sig) const;
3540
3541
  /**
3542
   * Create a not-a-number (NaN) floating-point constant.
3543
   * @param exp Number of bits in the exponent
3544
   * @param sig Number of bits in the significand
3545
   * @return the floating-point constant
3546
   */
3547
  Term mkNaN(uint32_t exp, uint32_t sig) const;
3548
3549
  /**
3550
   * Create a positive zero (+0.0) floating-point constant.
3551
   * @param exp Number of bits in the exponent
3552
   * @param sig Number of bits in the significand
3553
   * @return the floating-point constant
3554
   */
3555
  Term mkPosZero(uint32_t exp, uint32_t sig) const;
3556
3557
  /**
3558
   * Create a negative zero (-0.0) floating-point constant.
3559
   * @param exp Number of bits in the exponent
3560
   * @param sig Number of bits in the significand
3561
   * @return the floating-point constant
3562
   */
3563
  Term mkNegZero(uint32_t exp, uint32_t sig) const;
3564
3565
  /**
3566
   * Create a roundingmode constant.
3567
   * @param rm the floating point rounding mode this constant represents
3568
   */
3569
  Term mkRoundingMode(RoundingMode rm) const;
3570
3571
  /**
3572
   * Create uninterpreted constant.
3573
   * @param sort Sort of the constant
3574
   * @param index Index of the constant
3575
   */
3576
  Term mkUninterpretedConst(const Sort& sort, int32_t index) const;
3577
3578
  /**
3579
   * Create an abstract value constant.
3580
   * The given index needs to be a positive integer in base 10.
3581
   * @param index Index of the abstract value
3582
   */
3583
  Term mkAbstractValue(const std::string& index) const;
3584
3585
  /**
3586
   * Create an abstract value constant.
3587
   * The given index needs to be positive.
3588
   * @param index Index of the abstract value
3589
   */
3590
  Term mkAbstractValue(uint64_t index) const;
3591
3592
  /**
3593
   * Create a floating-point constant.
3594
   * @param exp Size of the exponent
3595
   * @param sig Size of the significand
3596
   * @param val Value of the floating-point constant as a bit-vector term
3597
   */
3598
  Term mkFloatingPoint(uint32_t exp, uint32_t sig, Term val) const;
3599
3600
  /**
3601
   * Create a cardinality constraint for an uninterpreted sort.
3602
   * @param sort the sort the cardinality constraint is for
3603
   * @param upperBound the upper bound on the cardinality of the sort
3604
   * @return the cardinality constraint
3605
   */
3606
  Term mkCardinalityConstraint(const Sort& sort, uint32_t upperBound) const;
3607
3608
  /* .................................................................... */
3609
  /* Create Variables                                                     */
3610
  /* .................................................................... */
3611
3612
  /**
3613
   * Create (first-order) constant (0-arity function symbol).
3614
   * SMT-LIB:
3615
   * \verbatim
3616
   *   ( declare-const <symbol> <sort> )
3617
   *   ( declare-fun <symbol> ( ) <sort> )
3618
   * \endverbatim
3619
   *
3620
   * @param sort the sort of the constant
3621
   * @param symbol the name of the constant
3622
   * @return the first-order constant
3623
   */
3624
  Term mkConst(const Sort& sort, const std::string& symbol) const;
3625
  /**
3626
   * Create (first-order) constant (0-arity function symbol), with a default
3627
   * symbol name.
3628
   *
3629
   * @param sort the sort of the constant
3630
   * @return the first-order constant
3631
   */
3632
  Term mkConst(const Sort& sort) const;
3633
3634
  /**
3635
   * Create a bound variable to be used in a binder (i.e. a quantifier, a
3636
   * lambda, or a witness binder).
3637
   * @param sort the sort of the variable
3638
   * @param symbol the name of the variable
3639
   * @return the variable
3640
   */
3641
  Term mkVar(const Sort& sort, const std::string& symbol = std::string()) const;
3642
3643
  /* .................................................................... */
3644
  /* Create datatype constructor declarations                             */
3645
  /* .................................................................... */
3646
3647
  DatatypeConstructorDecl mkDatatypeConstructorDecl(const std::string& name);
3648
3649
  /* .................................................................... */
3650
  /* Create datatype declarations                                         */
3651
  /* .................................................................... */
3652
3653
  /**
3654
   * Create a datatype declaration.
3655
   * @param name the name of the datatype
3656
   * @param isCoDatatype true if a codatatype is to be constructed
3657
   * @return the DatatypeDecl
3658
   */
3659
  DatatypeDecl mkDatatypeDecl(const std::string& name,
3660
                              bool isCoDatatype = false);
3661
3662
  /**
3663
   * Create a datatype declaration.
3664
   * Create sorts parameter with Solver::mkParamSort().
3665
   * @param name the name of the datatype
3666
   * @param param the sort parameter
3667
   * @param isCoDatatype true if a codatatype is to be constructed
3668
   * @return the DatatypeDecl
3669
   */
3670
  DatatypeDecl mkDatatypeDecl(const std::string& name,
3671
                              Sort param,
3672
                              bool isCoDatatype = false);
3673
3674
  /**
3675
   * Create a datatype declaration.
3676
   * Create sorts parameter with Solver::mkParamSort().
3677
   * @param name the name of the datatype
3678
   * @param params a list of sort parameters
3679
   * @param isCoDatatype true if a codatatype is to be constructed
3680
   * @return the DatatypeDecl
3681
   */
3682
  DatatypeDecl mkDatatypeDecl(const std::string& name,
3683
                              const std::vector<Sort>& params,
3684
                              bool isCoDatatype = false);
3685
3686
  /* .................................................................... */
3687
  /* Formula Handling                                                     */
3688
  /* .................................................................... */
3689
3690
  /**
3691
   * Simplify a formula without doing "much" work.  Does not involve
3692
   * the SAT Engine in the simplification, but uses the current
3693
   * definitions, assertions, and the current partial model, if one
3694
   * has been constructed.  It also involves theory normalization.
3695
   * @param t the formula to simplify
3696
   * @return the simplified formula
3697
   */
3698
  Term simplify(const Term& t);
3699
3700
  /**
3701
   * Assert a formula.
3702
   * SMT-LIB:
3703
   * \verbatim
3704
   *   ( assert <term> )
3705
   * \endverbatim
3706
   * @param term the formula to assert
3707
   */
3708
  void assertFormula(const Term& term) const;
3709
3710
  /**
3711
   * Check satisfiability.
3712
   * SMT-LIB:
3713
   * \verbatim
3714
   *   ( check-sat )
3715
   * \endverbatim
3716
   * @return the result of the satisfiability check.
3717
   */
3718
  Result checkSat() const;
3719
3720
  /**
3721
   * Check satisfiability assuming the given formula.
3722
   * SMT-LIB:
3723
   * \verbatim
3724
   *   ( check-sat-assuming ( <prop_literal> ) )
3725
   * \endverbatim
3726
   * @param assumption the formula to assume
3727
   * @return the result of the satisfiability check.
3728
   */
3729
  Result checkSatAssuming(const Term& assumption) const;
3730
3731
  /**
3732
   * Check satisfiability assuming the given formulas.
3733
   * SMT-LIB:
3734
   * \verbatim
3735
   *   ( check-sat-assuming ( <prop_literal>+ ) )
3736
   * \endverbatim
3737
   * @param assumptions the formulas to assume
3738
   * @return the result of the satisfiability check.
3739
   */
3740
  Result checkSatAssuming(const std::vector<Term>& assumptions) const;
3741
3742
  /**
3743
   * Check entailment of the given formula w.r.t. the current set of assertions.
3744
   * @param term the formula to check entailment for
3745
   * @return the result of the entailment check.
3746
   */
3747
  Result checkEntailed(const Term& term) const;
3748
3749
  /**
3750
   * Check entailment of the given set of given formulas w.r.t. the current
3751
   * set of assertions.
3752
   * @param terms the terms to check entailment for
3753
   * @return the result of the entailmentcheck.
3754
   */
3755
  Result checkEntailed(const std::vector<Term>& terms) const;
3756
3757
  /**
3758
   * Create datatype sort.
3759
   * SMT-LIB:
3760
   * \verbatim
3761
   *   ( declare-datatype <symbol> <datatype_decl> )
3762
   * \endverbatim
3763
   * @param symbol the name of the datatype sort
3764
   * @param ctors the constructor declarations of the datatype sort
3765
   * @return the datatype sort
3766
   */
3767
  Sort declareDatatype(const std::string& symbol,
3768
                       const std::vector<DatatypeConstructorDecl>& ctors) const;
3769
3770
  /**
3771
   * Declare n-ary function symbol.
3772
   * SMT-LIB:
3773
   * \verbatim
3774
   *   ( declare-fun <symbol> ( <sort>* ) <sort> )
3775
   * \endverbatim
3776
   * @param symbol the name of the function
3777
   * @param sorts the sorts of the parameters to this function
3778
   * @param sort the sort of the return value of this function
3779
   * @return the function
3780
   */
3781
  Term declareFun(const std::string& symbol,
3782
                  const std::vector<Sort>& sorts,
3783
                  const Sort& sort) const;
3784
3785
  /**
3786
   * Declare uninterpreted sort.
3787
   * SMT-LIB:
3788
   * \verbatim
3789
   *   ( declare-sort <symbol> <numeral> )
3790
   * \endverbatim
3791
   * @param symbol the name of the sort
3792
   * @param arity the arity of the sort
3793
   * @return the sort
3794
   */
3795
  Sort declareSort(const std::string& symbol, uint32_t arity) const;
3796
3797
  /**
3798
   * Define n-ary function.
3799
   * SMT-LIB:
3800
   * \verbatim
3801
   *   ( define-fun <function_def> )
3802
   * \endverbatim
3803
   * @param symbol the name of the function
3804
   * @param bound_vars the parameters to this function
3805
   * @param sort the sort of the return value of this function
3806
   * @param term the function body
3807
   * @param global determines whether this definition is global (i.e. persists
3808
   *               when popping the context)
3809
   * @return the function
3810
   */
3811
  Term defineFun(const std::string& symbol,
3812
                 const std::vector<Term>& bound_vars,
3813
                 const Sort& sort,
3814
                 const Term& term,
3815
                 bool global = false) const;
3816
3817
  /**
3818
   * Define recursive function.
3819
   * SMT-LIB:
3820
   * \verbatim
3821
   * ( define-fun-rec <function_def> )
3822
   * \endverbatim
3823
   * @param symbol the name of the function
3824
   * @param bound_vars the parameters to this function
3825
   * @param sort the sort of the return value of this function
3826
   * @param term the function body
3827
   * @param global determines whether this definition is global (i.e. persists
3828
   *               when popping the context)
3829
   * @return the function
3830
   */
3831
  Term defineFunRec(const std::string& symbol,
3832
                    const std::vector<Term>& bound_vars,
3833
                    const Sort& sort,
3834
                    const Term& term,
3835
                    bool global = false) const;
3836
3837
  /**
3838
   * Define recursive function.
3839
   * SMT-LIB:
3840
   * \verbatim
3841
   * ( define-fun-rec <function_def> )
3842
   * \endverbatim
3843
   * Create parameter 'fun' with mkConst().
3844
   * @param fun the sorted function
3845
   * @param bound_vars the parameters to this function
3846
   * @param term the function body
3847
   * @param global determines whether this definition is global (i.e. persists
3848
   *               when popping the context)
3849
   * @return the function
3850
   */
3851
  Term defineFunRec(const Term& fun,
3852
                    const std::vector<Term>& bound_vars,
3853
                    const Term& term,
3854
                    bool global = false) const;
3855
3856
  /**
3857
   * Define recursive functions.
3858
   * SMT-LIB:
3859
   * \verbatim
3860
   *   ( define-funs-rec ( <function_decl>^{n+1} ) ( <term>^{n+1} ) )
3861
   * \endverbatim
3862
   * Create elements of parameter 'funs' with mkConst().
3863
   * @param funs the sorted functions
3864
   * @param bound_vars the list of parameters to the functions
3865
   * @param terms the list of function bodies of the functions
3866
   * @param global determines whether this definition is global (i.e. persists
3867
   *               when popping the context)
3868
   * @return the function
3869
   */
3870
  void defineFunsRec(const std::vector<Term>& funs,
3871
                     const std::vector<std::vector<Term>>& bound_vars,
3872
                     const std::vector<Term>& terms,
3873
                     bool global = false) const;
3874
3875
  /**
3876
   * Echo a given string to the given output stream.
3877
   * SMT-LIB:
3878
   * \verbatim
3879
   * ( echo <std::string> )
3880
   * \endverbatim
3881
   * @param out the output stream
3882
   * @param str the string to echo
3883
   */
3884
  void echo(std::ostream& out, const std::string& str) const;
3885
3886
  /**
3887
   * Get the list of asserted formulas.
3888
   * SMT-LIB:
3889
   * \verbatim
3890
   * ( get-assertions )
3891
   * \endverbatim
3892
   * @return the list of asserted formulas
3893
   */
3894
  std::vector<Term> getAssertions() const;
3895
3896
  /**
3897
   * Get info from the solver.
3898
   * SMT-LIB: \verbatim( get-info <info_flag> )\endverbatim
3899
   * @return the info
3900
   */
3901
  std::string getInfo(const std::string& flag) const;
3902
3903
  /**
3904
   * Get the value of a given option.
3905
   * SMT-LIB:
3906
   * \verbatim
3907
   * ( get-option <keyword> )
3908
   * \endverbatim
3909
   * @param option the option for which the value is queried
3910
   * @return a string representation of the option value
3911
   */
3912
  std::string getOption(const std::string& option) const;
3913
3914
  /**
3915
   * Get all option names that can be used with `setOption`, `getOption` and
3916
   * `getOptionInfo`.
3917
   * @return all option names
3918
   */
3919
  std::vector<std::string> getOptionNames() const;
3920
3921
  /**
3922
   * Get some information about the given option. Check the `OptionInfo` class
3923
   * for more details on which information is available.
3924
   * @return information about the given option
3925
   */
3926
  OptionInfo getOptionInfo(const std::string& option) const;
3927
3928
  /**
3929
   * Get the driver options, which provide access to options that can not be
3930
   * communicated properly via getOption() and getOptionInfo().
3931
   * @return a DriverOptions object.
3932
   */
3933
  DriverOptions getDriverOptions() const;
3934
3935
  /**
3936
   * Get the set of unsat ("failed") assumptions.
3937
   * SMT-LIB:
3938
   * \verbatim
3939
   * ( get-unsat-assumptions )
3940
   * \endverbatim
3941
   * Requires to enable option 'produce-unsat-assumptions'.
3942
   * @return the set of unsat assumptions.
3943
   */
3944
  std::vector<Term> getUnsatAssumptions() const;
3945
3946
  /**
3947
   * Get the unsatisfiable core.
3948
   * SMT-LIB:
3949
   * \verbatim
3950
   * ( get-unsat-core )
3951
   * \endverbatim
3952
   * Requires to enable option 'produce-unsat-cores'.
3953
   * @return a set of terms representing the unsatisfiable core
3954
   */
3955
  std::vector<Term> getUnsatCore() const;
3956
3957
  /**
3958
   * Get a difficulty estimate for an asserted formula. This method is
3959
   * intended to be called immediately after any response to a checkSat.
3960
   *
3961
   * @return a map from (a subset of) the input assertions to a real value that
3962
   * is an estimate of how difficult each assertion was to solve. Unmentioned
3963
   * assertions can be assumed to have zero difficulty.
3964
   */
3965
  std::map<Term, Term> getDifficulty() const;
3966
3967
  /**
3968
   * Get the refutation proof
3969
   * SMT-LIB:
3970
   * \verbatim
3971
   * ( get-proof )
3972
   * \endverbatim
3973
   * Requires to enable option 'produce-proofs'.
3974
   * @return a string representing the proof, according to the value of
3975
   * proof-format-mode.
3976
   */
3977
  std::string getProof() const;
3978
3979
  /**
3980
   * Get the value of the given term in the current model.
3981
   * SMT-LIB:
3982
   * \verbatim
3983
   * ( get-value ( <term> ) )
3984
   * \endverbatim
3985
   * @param term the term for which the value is queried
3986
   * @return the value of the given term
3987
   */
3988
  Term getValue(const Term& term) const;
3989
3990
  /**
3991
   * Get the values of the given terms in the current model.
3992
   * SMT-LIB:
3993
   * \verbatim
3994
   * ( get-value ( <term>+ ) )
3995
   * \endverbatim
3996
   * @param terms the terms for which the value is queried
3997
   * @return the values of the given terms
3998
   */
3999
  std::vector<Term> getValue(const std::vector<Term>& terms) const;
4000
4001
  /**
4002
   * Get the domain elements of uninterpreted sort s in the current model. The
4003
   * current model interprets s as the finite sort whose domain elements are
4004
   * given in the return value of this method.
4005
   *
4006
   * @param s The uninterpreted sort in question
4007
   * @return the domain elements of s in the current model
4008
   */
4009
  std::vector<Term> getModelDomainElements(const Sort& s) const;
4010
4011
  /**
4012
   * This returns false if the model value of free constant v was not essential
4013
   * for showing the satisfiability of the last call to checkSat using the
4014
   * current model. This method will only return false (for any v) if
4015
   * the model-cores option has been set.
4016
   *
4017
   * @param v The term in question
4018
   * @return true if v is a model core symbol
4019
   */
4020
  bool isModelCoreSymbol(const Term& v) const;
4021
4022
  /**
4023
   * Get the model
4024
   * SMT-LIB:
4025
   * \verbatim
4026
   * ( get-model )
4027
   * \endverbatim
4028
   * Requires to enable option 'produce-models'.
4029
   * @param sorts The list of uninterpreted sorts that should be printed in the
4030
   * model.
4031
   * @param vars The list of free constants that should be printed in the
4032
   * model. A subset of these may be printed based on isModelCoreSymbol.
4033
   * @return a string representing the model.
4034
   */
4035
  std::string getModel(const std::vector<Sort>& sorts,
4036
                       const std::vector<Term>& vars) const;
4037
4038
  /**
4039
   * Do quantifier elimination.
4040
   * SMT-LIB:
4041
   * \verbatim
4042
   * ( get-qe <q> )
4043
   * \endverbatim
4044
   * Requires a logic that supports quantifier elimination. Currently, the only
4045
   * logics supported by quantifier elimination is LRA and LIA.
4046
   * @param q a quantified formula of the form:
4047
   *   Q x1...xn. P( x1...xn, y1...yn )
4048
   * where P( x1...xn, y1...yn ) is a quantifier-free formula
4049
   * @return a formula ret such that, given the current set of formulas A
4050
   * asserted to this solver:
4051
   *   - ( A ^ q ) and ( A ^ ret ) are equivalent
4052
   *   - ret is quantifier-free formula containing only free variables in
4053
   *     y1...yn.
4054
   */
4055
  Term getQuantifierElimination(const Term& q) const;
4056
4057
  /**
4058
   * Do partial quantifier elimination, which can be used for incrementally
4059
   * computing the result of a quantifier elimination.
4060
   * SMT-LIB:
4061
   * \verbatim
4062
   * ( get-qe-disjunct <q> )
4063
   * \endverbatim
4064
   * Requires a logic that supports quantifier elimination. Currently, the only
4065
   * logics supported by quantifier elimination is LRA and LIA.
4066
   * @param q a quantified formula of the form:
4067
   *   Q x1...xn. P( x1...xn, y1...yn )
4068
   * where P( x1...xn, y1...yn ) is a quantifier-free formula
4069
   * @return a formula ret such that, given the current set of formulas A
4070
   * asserted to this solver:
4071
   *   - (A ^ q) => (A ^ ret) if Q is forall or (A ^ ret) => (A ^ q) if Q is
4072
   *     exists,
4073
   *   - ret is quantifier-free formula containing only free variables in
4074
   *     y1...yn,
4075
   *   - If Q is exists, let A^Q_n be the formula
4076
   *       A ^ ~ret^Q_1 ^ ... ^ ~ret^Q_n
4077
   *     where for each i=1,...n, formula ret^Q_i is the result of calling
4078
   *     getQuantifierEliminationDisjunct for q with the set of assertions
4079
   *     A^Q_{i-1}. Similarly, if Q is forall, then let A^Q_n be
4080
   *       A ^ ret^Q_1 ^ ... ^ ret^Q_n
4081
   *     where ret^Q_i is the same as above. In either case, we have
4082
   *     that ret^Q_j will eventually be true or false, for some finite j.
4083
   */
4084
  Term getQuantifierEliminationDisjunct(const Term& q) const;
4085
4086
  /**
4087
   * When using separation logic, this sets the location sort and the
4088
   * datatype sort to the given ones. This method should be invoked exactly
4089
   * once, before any separation logic constraints are provided.
4090
   * @param locSort The location sort of the heap
4091
   * @param dataSort The data sort of the heap
4092
   */
4093
  void declareSepHeap(const Sort& locSort, const Sort& dataSort) const;
4094
4095
  /**
4096
   * When using separation logic, obtain the term for the heap.
4097
   * @return The term for the heap
4098
   */
4099
  Term getValueSepHeap() const;
4100
4101
  /**
4102
   * When using separation logic, obtain the term for nil.
4103
   * @return The term for nil
4104
   */
4105
  Term getValueSepNil() const;
4106
4107
  /**
4108
   * Declare a symbolic pool of terms with the given initial value.
4109
   * SMT-LIB:
4110
   * \verbatim
4111
   * ( declare-pool <symbol> <sort> ( <term>* ) )
4112
   * \endverbatim
4113
   * @param symbol The name of the pool
4114
   * @param sort The sort of the elements of the pool.
4115
   * @param initValue The initial value of the pool
4116
   */
4117
  Term declarePool(const std::string& symbol,
4118
                   const Sort& sort,
4119
                   const std::vector<Term>& initValue) const;
4120
  /**
4121
   * Pop (a) level(s) from the assertion stack.
4122
   * SMT-LIB:
4123
   * \verbatim
4124
   * ( pop <numeral> )
4125
   * \endverbatim
4126
   * @param nscopes the number of levels to pop
4127
   */
4128
  void pop(uint32_t nscopes = 1) const;
4129
4130
  /**
4131
   * Get an interpolant
4132
   * SMT-LIB:
4133
   * \verbatim
4134
   * ( get-interpol <conj> )
4135
   * \endverbatim
4136
   * Requires to enable option 'produce-interpols'.
4137
   * @param conj the conjecture term
4138
   * @param output a Term I such that A->I and I->B are valid, where A is the
4139
   *        current set of assertions and B is given in the input by conj.
4140
   * @return true if it gets I successfully, false otherwise.
4141
   */
4142
  bool getInterpolant(const Term& conj, Term& output) const;
4143
4144
  /**
4145
   * Get an interpolant
4146
   * SMT-LIB:
4147
   * \verbatim
4148
   * ( get-interpol <conj> <g> )
4149
   * \endverbatim
4150
   * Requires to enable option 'produce-interpols'.
4151
   * @param conj the conjecture term
4152
   * @param grammar the grammar for the interpolant I
4153
   * @param output a Term I such that A->I and I->B are valid, where A is the
4154
   *        current set of assertions and B is given in the input by conj.
4155
   * @return true if it gets I successfully, false otherwise.
4156
   */
4157
  bool getInterpolant(const Term& conj, Grammar& grammar, Term& output) const;
4158
4159
  /**
4160
   * Get an abduct.
4161
   * SMT-LIB:
4162
   * \verbatim
4163
   * ( get-abduct <conj> )
4164
   * \endverbatim
4165
   * Requires enabling option 'produce-abducts'
4166
   * @param conj the conjecture term
4167
   * @param output a term C such that A^C is satisfiable, and A^~B^C is
4168
   *        unsatisfiable, where A is the current set of assertions and B is
4169
   *        given in the input by conj
4170
   * @return true if it gets C successfully, false otherwise
4171
   */
4172
  bool getAbduct(const Term& conj, Term& output) const;
4173
4174
  /**
4175
   * Get an abduct.
4176
   * SMT-LIB:
4177
   * \verbatim
4178
   * ( get-abduct <conj> <g> )
4179
   * \endverbatim
4180
   * Requires enabling option 'produce-abducts'
4181
   * @param conj the conjecture term
4182
   * @param grammar the grammar for the abduct C
4183
   * @param output a term C such that A^C is satisfiable, and A^~B^C is
4184
   *        unsatisfiable, where A is the current set of assertions and B is
4185
   *        given in the input by conj
4186
   * @return true if it gets C successfully, false otherwise
4187
   */
4188
  bool getAbduct(const Term& conj, Grammar& grammar, Term& output) const;
4189
4190
  /**
4191
   * Block the current model. Can be called only if immediately preceded by a
4192
   * SAT or INVALID query.
4193
   * SMT-LIB:
4194
   * \verbatim
4195
   * ( block-model )
4196
   * \endverbatim
4197
   * Requires enabling 'produce-models' option and setting 'block-models' option
4198
   * to a mode other than "none".
4199
   */
4200
  void blockModel() const;
4201
4202
  /**
4203
   * Block the current model values of (at least) the values in terms. Can be
4204
   * called only if immediately preceded by a SAT or NOT_ENTAILED query.
4205
   * SMT-LIB:
4206
   * \verbatim
4207
   * ( block-model-values ( <terms>+ ) )
4208
   * \endverbatim
4209
   * Requires enabling 'produce-models' option and setting 'block-models' option
4210
   * to a mode other than "none".
4211
   */
4212
  void blockModelValues(const std::vector<Term>& terms) const;
4213
4214
  /**
4215
   * Print all instantiations made by the quantifiers module.
4216
   * @param out the output stream
4217
   */
4218
  void printInstantiations(std::ostream& out) const;
4219
4220
  /**
4221
   * Push (a) level(s) to the assertion stack.
4222
   * SMT-LIB:
4223
   * \verbatim
4224
   * ( push <numeral> )
4225
   * \endverbatim
4226
   * @param nscopes the number of levels to push
4227
   */
4228
  void push(uint32_t nscopes = 1) const;
4229
4230
  /**
4231
   * Remove all assertions.
4232
   * SMT-LIB:
4233
   * \verbatim
4234
   * ( reset-assertions )
4235
   * \endverbatim
4236
   */
4237
  void resetAssertions() const;
4238
4239
  /**
4240
   * Set info.
4241
   * SMT-LIB:
4242
   * \verbatim
4243
   * ( set-info <attribute> )
4244
   * \endverbatim
4245
   * @param keyword the info flag
4246
   * @param value the value of the info flag
4247
   */
4248
  void setInfo(const std::string& keyword, const std::string& value) const;
4249
4250
  /**
4251
   * Set logic.
4252
   * SMT-LIB:
4253
   * \verbatim
4254
   * ( set-logic <symbol> )
4255
   * \endverbatim
4256
   * @param logic the logic to set
4257
   */
4258
  void setLogic(const std::string& logic) const;
4259
4260
  /**
4261
   * Set option.
4262
   * SMT-LIB:
4263
   * \verbatim
4264
   *   ( set-option <option> )
4265
   * \endverbatim
4266
   * @param option the option name
4267
   * @param value the option value
4268
   */
4269
  void setOption(const std::string& option, const std::string& value) const;
4270
4271
  /**
4272
   * If needed, convert this term to a given sort. Note that the sort of the
4273
   * term must be convertible into the target sort. Currently only Int to Real
4274
   * conversions are supported.
4275
   * @param t the term
4276
   * @param s the target sort
4277
   * @return the term wrapped into a sort conversion if needed
4278
   */
4279
  Term ensureTermSort(const Term& t, const Sort& s) const;
4280
4281
  /**
4282
   * Append \p symbol to the current list of universal variables.
4283
   * SyGuS v2:
4284
   * \verbatim
4285
   *   ( declare-var <symbol> <sort> )
4286
   * \endverbatim
4287
   * @param sort the sort of the universal variable
4288
   * @param symbol the name of the universal variable
4289
   * @return the universal variable
4290
   */
4291
  Term mkSygusVar(const Sort& sort,
4292
                  const std::string& symbol = std::string()) const;
4293
4294
  /**
4295
   * Create a Sygus grammar. The first non-terminal is treated as the starting
4296
   * non-terminal, so the order of non-terminals matters.
4297
   *
4298
   * @param boundVars the parameters to corresponding synth-fun/synth-inv
4299
   * @param ntSymbols the pre-declaration of the non-terminal symbols
4300
   * @return the grammar
4301
   */
4302
  Grammar mkSygusGrammar(const std::vector<Term>& boundVars,
4303
                         const std::vector<Term>& ntSymbols) const;
4304
4305
  /**
4306
   * Synthesize n-ary function.
4307
   * SyGuS v2:
4308
   * \verbatim
4309
   *   ( synth-fun <symbol> ( <boundVars>* ) <sort> )
4310
   * \endverbatim
4311
   * @param symbol the name of the function
4312
   * @param boundVars the parameters to this function
4313
   * @param sort the sort of the return value of this function
4314
   * @return the function
4315
   */
4316
  Term synthFun(const std::string& symbol,
4317
                const std::vector<Term>& boundVars,
4318
                const Sort& sort) const;
4319
4320
  /**
4321
   * Synthesize n-ary function following specified syntactic constraints.
4322
   * SyGuS v2:
4323
   * \verbatim
4324
   *   ( synth-fun <symbol> ( <boundVars>* ) <sort> <g> )
4325
   * \endverbatim
4326
   * @param symbol the name of the function
4327
   * @param boundVars the parameters to this function
4328
   * @param sort the sort of the return value of this function
4329
   * @param grammar the syntactic constraints
4330
   * @return the function
4331
   */
4332
  Term synthFun(const std::string& symbol,
4333
                const std::vector<Term>& boundVars,
4334
                Sort sort,
4335
                Grammar& grammar) const;
4336
4337
  /**
4338
   * Synthesize invariant.
4339
   * SyGuS v2:
4340
   * \verbatim
4341
   *   ( synth-inv <symbol> ( <boundVars>* ) )
4342
   * \endverbatim
4343
   * @param symbol the name of the invariant
4344
   * @param boundVars the parameters to this invariant
4345
   * @return the invariant
4346
   */
4347
  Term synthInv(const std::string& symbol,
4348
                const std::vector<Term>& boundVars) const;
4349
4350
  /**
4351
   * Synthesize invariant following specified syntactic constraints.
4352
   * SyGuS v2:
4353
   * \verbatim
4354
   *   ( synth-inv <symbol> ( <boundVars>* ) <g> )
4355
   * \endverbatim
4356
   * @param symbol the name of the invariant
4357
   * @param boundVars the parameters to this invariant
4358
   * @param grammar the syntactic constraints
4359
   * @return the invariant
4360
   */
4361
  Term synthInv(const std::string& symbol,
4362
                const std::vector<Term>& boundVars,
4363
                Grammar& grammar) const;
4364
4365
  /**
4366
   * Add a forumla to the set of Sygus constraints.
4367
   * SyGuS v2:
4368
   * \verbatim
4369
   *   ( constraint <term> )
4370
   * \endverbatim
4371
   * @param term the formula to add as a constraint
4372
   */
4373
  void addSygusConstraint(const Term& term) const;
4374
4375
  /**
4376
   * Add a forumla to the set of Sygus assumptions.
4377
   * SyGuS v2:
4378
   * \verbatim
4379
   *   ( assume <term> )
4380
   * \endverbatim
4381
   * @param term the formula to add as an assumption
4382
   */
4383
  void addSygusAssume(const Term& term) const;
4384
4385
  /**
4386
   * Add a set of Sygus constraints to the current state that correspond to an
4387
   * invariant synthesis problem.
4388
   * SyGuS v2:
4389
   * \verbatim
4390
   *   ( inv-constraint <inv> <pre> <trans> <post> )
4391
   * \endverbatim
4392
   * @param inv the function-to-synthesize
4393
   * @param pre the pre-condition
4394
   * @param trans the transition relation
4395
   * @param post the post-condition
4396
   */
4397
  void addSygusInvConstraint(Term inv, Term pre, Term trans, Term post) const;
4398
4399
  /**
4400
   * Try to find a solution for the synthesis conjecture corresponding to the
4401
   * current list of functions-to-synthesize, universal variables and
4402
   * constraints.
4403
   * SyGuS v2:
4404
   * \verbatim
4405
   *   ( check-synth )
4406
   * \endverbatim
4407
   * @return the result of the synthesis conjecture.
4408
   */
4409
  Result checkSynth() const;
4410
4411
  /**
4412
   * Get the synthesis solution of the given term. This method should be called
4413
   * immediately after the solver answers unsat for sygus input.
4414
   * @param term the term for which the synthesis solution is queried
4415
   * @return the synthesis solution of the given term
4416
   */
4417
  Term getSynthSolution(Term term) const;
4418
4419
  /**
4420
   * Get the synthesis solutions of the given terms. This method should be
4421
   * called immediately after the solver answers unsat for sygus input.
4422
   * @param terms the terms for which the synthesis solutions is queried
4423
   * @return the synthesis solutions of the given terms
4424
   */
4425
  std::vector<Term> getSynthSolutions(const std::vector<Term>& terms) const;
4426
4427
  /**
4428
   * Returns a snapshot of the current state of the statistic values of this
4429
   * solver. The returned object is completely decoupled from the solver and
4430
   * will not change when the solver is used again.
4431
   */
4432
  Statistics getStatistics() const;
4433
4434
  /**
4435
   * Whether the output stream for the given tag is enabled. Tags can be enabled
4436
   * with the `output` option (and `-o <tag>` on the command line). Raises an
4437
   * exception when an invalid tag is given.
4438
   */
4439
  bool isOutputOn(const std::string& tag) const;
4440
4441
  /**
4442
   * Returns an output stream for the given tag. Tags can be enabled with the
4443
   * `output` option (and `-o <tag>` on the command line). Raises an exception
4444
   * when an invalid tag is given.
4445
   */
4446
  std::ostream& getOutput(const std::string& tag) const;
4447
4448
 private:
4449
  /** @return the node manager of this solver */
4450
  NodeManager* getNodeManager(void) const;
4451
  /** Reset the API statistics */
4452
  void resetStatistics();
4453
4454
  /**
4455
   * Print the statistics to the given file descriptor, suitable for usage in
4456
   * signal handlers.
4457
   */
4458
  void printStatisticsSafe(int fd) const;
4459
4460
  /** Helper to check for API misuse in mkOp functions. */
4461
  void checkMkTerm(Kind kind, uint32_t nchildren) const;
4462
  /** Helper for mk-functions that call d_nodeMgr->mkConst(). */
4463
  template <typename T>
4464
  Term mkValHelper(T t) const;
4465
  /** Helper for mkReal functions that take a string as argument. */
4466
  Term mkRealFromStrHelper(const std::string& s) const;
4467
  /** Helper for mkBitVector functions that take a string as argument. */
4468
  Term mkBVFromStrHelper(const std::string& s, uint32_t base) const;
4469
  /**
4470
   * Helper for mkBitVector functions that take a string and a size as
4471
   * arguments.
4472
   */
4473
  Term mkBVFromStrHelper(uint32_t size,
4474
                         const std::string& s,
4475
                         uint32_t base) const;
4476
  /** Helper for mkBitVector functions that take an integer as argument. */
4477
  Term mkBVFromIntHelper(uint32_t size, uint64_t val) const;
4478
  /** Helper for functions that create tuple sorts. */
4479
  Sort mkTupleSortHelper(const std::vector<Sort>& sorts) const;
4480
  /** Helper for mkTerm functions that create Term from a Kind */
4481
  Term mkTermFromKind(Kind kind) const;
4482
  /** Helper for mkChar functions that take a string as argument. */
4483
  Term mkCharFromStrHelper(const std::string& s) const;
4484
  /** Get value helper, which accounts for subtyping */
4485
  Term getValueHelper(const Term& term) const;
4486
4487
  /**
4488
   * Helper function that ensures that a given term is of sort real (as opposed
4489
   * to being of sort integer).
4490
   * @param t a term of sort integer or real
4491
   * @return a term of sort real
4492
   */
4493
  Term ensureRealSort(const Term& t) const;
4494
4495
  /**
4496
   * Create n-ary term of given kind. This handles the cases of left/right
4497
   * associative operators, chainable operators, and cases when the number of
4498
   * children exceeds the maximum arity for the kind.
4499
   * @param kind the kind of the term
4500
   * @param children the children of the term
4501
   * @return the Term
4502
   */
4503
  Term mkTermHelper(Kind kind, const std::vector<Term>& children) const;
4504
4505
  /**
4506
   * Create n-ary term of given kind from a given operator.
4507
   * @param op the operator
4508
   * @param children the children of the term
4509
   * @return the Term
4510
   */
4511
  Term mkTermHelper(const Op& op, const std::vector<Term>& children) const;
4512
4513
  /**
4514
   * Create a vector of datatype sorts, using unresolved sorts.
4515
   * @param dtypedecls the datatype declarations from which the sort is created
4516
   * @param unresolvedSorts the list of unresolved sorts
4517
   * @return the datatype sorts
4518
   */
4519
  std::vector<Sort> mkDatatypeSortsInternal(
4520
      const std::vector<DatatypeDecl>& dtypedecls,
4521
      const std::set<Sort>& unresolvedSorts) const;
4522
4523
  /**
4524
   * Synthesize n-ary function following specified syntactic constraints.
4525
   * SMT-LIB:
4526
   * \verbatim
4527
   *   ( synth-fun <symbol> ( <boundVars>* ) <sort> <g>? )
4528
   * \endverbatim
4529
   * @param symbol the name of the function
4530
   * @param boundVars the parameters to this function
4531
   * @param sort the sort of the return value of this function
4532
   * @param isInv determines whether this is synth-fun or synth-inv
4533
   * @param grammar the syntactic constraints
4534
   * @return the function
4535
   */
4536
  Term synthFunHelper(const std::string& symbol,
4537
                      const std::vector<Term>& boundVars,
4538
                      const Sort& sort,
4539
                      bool isInv = false,
4540
                      Grammar* grammar = nullptr) const;
4541
4542
  /** Check whether string s is a valid decimal integer. */
4543
  bool isValidInteger(const std::string& s) const;
4544
4545
  /** Increment the term stats counter. */
4546
  void increment_term_stats(Kind kind) const;
4547
  /** Increment the vars stats (if 'is_var') or consts stats counter. */
4548
  void increment_vars_consts_stats(const Sort& sort, bool is_var) const;
4549
4550
  /** Keep a copy of the original option settings (for resets). */
4551
  std::unique_ptr<Options> d_originalOptions;
4552
  /** The node manager of this solver. */
4553
  NodeManager* d_nodeMgr;
4554
  /** The statistics collected on the Api level. */
4555
  std::unique_ptr<APIStatistics> d_stats;
4556
  /** The SMT engine of this solver. */
4557
  std::unique_ptr<SolverEngine> d_slv;
4558
  /** The random number generator of this solver. */
4559
  std::unique_ptr<Random> d_rng;
4560
};
4561
4562
}  // namespace cvc5::api
4563
4564
#endif