GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/api/cpp/cvc5.h Lines: 25 28 89.3 %
Date: 2021-09-29 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 SmtEngine;
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
1374
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
1374
  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
1
  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
58
  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
68
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
68
  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
279463
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
6472449
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 a Boolean sort
358
   */
359
  bool isBoolean() const;
360
361
  /**
362
   * Is this a integer sort?
363
   * @return true if the sort is a integer sort
364
   */
365
  bool isInteger() const;
366
367
  /**
368
   * Is this a real sort?
369
   * @return true if the sort is a 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 a 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 a sort kind?
489
   * @return true if this is a sort kind
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 element 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 parameterezied
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 getBVSize() 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 getFPExponentSize() const;
711
712
  /**
713
   * @return the width of the significand of the floating-point sort
714
   */
715
  uint32_t getFPSignificandSize() 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 interal 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
196910
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 i).
939
   * @param i position of the index. Should be less than getNumIndicesHelper().
940
   * @return the index at position i
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
33731453
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 simulatenously 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
262
  class const_iterator : public std::iterator<std::input_iterator_tag, Term>
1171
  {
1172
    friend class Term;
1173
1174
   public:
1175
    /**
1176
     * Null Constructor.
1177
     */
1178
    const_iterator();
1179
1180
    /**
1181
     * Constructor
1182
     * @param slv the associated solver object
1183
     * @param e a shared pointer to the node that we're iterating over
1184
     * @param p the position of the iterator (e.g. which child it's on)
1185
     */
1186
    const_iterator(const Solver* slv,
1187
                   const std::shared_ptr<cvc5::Node>& e,
1188
                   uint32_t p);
1189
1190
    /**
1191
     * Copy constructor.
1192
     */
1193
    const_iterator(const const_iterator& it);
1194
1195
    /**
1196
     * Assignment operator.
1197
     * @param it the iterator to assign to
1198
     * @return the reference to the iterator after assignment
1199
     */
1200
    const_iterator& operator=(const const_iterator& it);
1201
1202
    /**
1203
     * Equality operator.
1204
     * @param it the iterator to compare to for equality
1205
     * @return true if the iterators are equal
1206
     */
1207
    bool operator==(const const_iterator& it) const;
1208
1209
    /**
1210
     * Disequality operator.
1211
     * @param it the iterator to compare to for disequality
1212
     * @return true if the iterators are disequal
1213
     */
1214
    bool operator!=(const const_iterator& it) const;
1215
1216
    /**
1217
     * Increment operator (prefix).
1218
     * @return a reference to the iterator after incrementing by one
1219
     */
1220
    const_iterator& operator++();
1221
1222
    /**
1223
     * Increment operator (postfix).
1224
     * @return a reference to the iterator after incrementing by one
1225
     */
1226
    const_iterator operator++(int);
1227
1228
    /**
1229
     * Dereference operator.
1230
     * @return the term this iterator points to
1231
     */
1232
    Term operator*() const;
1233
1234
   private:
1235
    /**
1236
     * The associated solver object.
1237
     */
1238
    const Solver* d_solver;
1239
    /** The original node to be iterated over. */
1240
    std::shared_ptr<cvc5::Node> d_origNode;
1241
    /** Keeps track of the iteration position. */
1242
    uint32_t d_pos;
1243
  };
1244
1245
  /**
1246
   * @return an iterator to the first child of this Term
1247
   */
1248
  const_iterator begin() const;
1249
1250
  /**
1251
   * @return an iterator to one-off-the-last child of this Term
1252
   */
1253
  const_iterator end() const;
1254
1255
  /**
1256
   * @return true if the term is an integer value that fits within int32_t.
1257
   */
1258
  bool isInt32Value() const;
1259
  /**
1260
   * Asserts isInt32Value().
1261
   * @return the integer term as a int32_t.
1262
   */
1263
  int32_t getInt32Value() const;
1264
  /**
1265
   * @return true if the term is an integer value that fits within uint32_t.
1266
   */
1267
  bool isUInt32Value() const;
1268
  /**
1269
   * Asserts isUInt32Value().
1270
   * @return the integer term as a uint32_t.
1271
   */
1272
  uint32_t getUInt32Value() const;
1273
  /**
1274
   * @return true if the term is an integer value that fits within int64_t.
1275
   */
1276
  bool isInt64Value() const;
1277
  /**
1278
   * Asserts isInt64Value().
1279
   * @return the integer term as a int64_t.
1280
   */
1281
  int64_t getInt64Value() const;
1282
  /**
1283
   * @return true if the term is an integer value that fits within uint64_t.
1284
   */
1285
  bool isUInt64Value() const;
1286
  /**
1287
   * Asserts isUInt64Value().
1288
   * @return the integer term as a uint64_t.
1289
   */
1290
  uint64_t getUInt64Value() const;
1291
  /**
1292
   * @return true if the term is an integer value.
1293
   */
1294
  bool isIntegerValue() const;
1295
  /**
1296
   * Asserts isIntegerValue().
1297
   * @return the integer term in (decimal) string representation.
1298
   */
1299
  std::string getIntegerValue() const;
1300
1301
  /**
1302
   * @return true if the term is a string value.
1303
   */
1304
  bool isStringValue() const;
1305
  /**
1306
   * Note: This method is not to be confused with toString() which returns
1307
   * the term in some string representation, whatever data it may hold. Asserts
1308
   * isStringValue().
1309
   * @return the string term as a native string value.
1310
   */
1311
  std::wstring getStringValue() const;
1312
1313
  /**
1314
   * @return true if the term is a rational value whose numerator and
1315
   * denominator fit within int32_t and uint32_t, respectively.
1316
   */
1317
  bool isReal32Value() const;
1318
  /**
1319
   * Asserts isReal32Value().
1320
   * @return the representation of a rational value as a pair of its numerator
1321
   * and denominator.
1322
   */
1323
  std::pair<int32_t, uint32_t> getReal32Value() const;
1324
  /**
1325
   * @return true if the term is a rational value whose numerator and
1326
   * denominator fit within int64_t and uint64_t, respectively.
1327
   */
1328
  bool isReal64Value() const;
1329
  /**
1330
   * Asserts isReal64Value().
1331
   * @return the representation of a rational value as a pair of its numerator
1332
   * and denominator.
1333
   */
1334
  std::pair<int64_t, uint64_t> getReal64Value() const;
1335
  /**
1336
   * @return true if the term is a rational value.
1337
   */
1338
  bool isRealValue() const;
1339
  /**
1340
   * Asserts isRealValue().
1341
   * @return the representation of a rational value as a (decimal) string.
1342
   */
1343
  std::string getRealValue() const;
1344
1345
  /**
1346
   * @return true if the term is a constant array.
1347
   */
1348
  bool isConstArray() const;
1349
  /**
1350
   * Asserts isConstArray().
1351
   * @return the base (element stored at all indices) of a constant array
1352
   */
1353
  Term getConstArrayBase() const;
1354
1355
  /**
1356
   * @return true if the term is a Boolean value.
1357
   */
1358
  bool isBooleanValue() const;
1359
  /**
1360
   * Asserts isBooleanValue().
1361
   * @return the representation of a Boolean value as a native Boolean value.
1362
   */
1363
  bool getBooleanValue() const;
1364
1365
  /**
1366
   * @return true if the term is a bit-vector value.
1367
   */
1368
  bool isBitVectorValue() const;
1369
  /**
1370
   * Asserts isBitVectorValue().
1371
   * @return the representation of a bit-vector value in string representation.
1372
   * Supported bases are 2 (bit string), 10 (decimal string) or 16 (hexadecimal
1373
   * string).
1374
   */
1375
  std::string getBitVectorValue(uint32_t base = 2) const;
1376
1377
  /**
1378
   * @return true if the term is an abstract value.
1379
   */
1380
  bool isAbstractValue() const;
1381
  /**
1382
   * Asserts isAbstractValue().
1383
   * @return the representation of an abstract value as a string.
1384
   */
1385
  std::string getAbstractValue() const;
1386
1387
  /**
1388
   * @return true if the term is a tuple value.
1389
   */
1390
  bool isTupleValue() const;
1391
  /**
1392
   * Asserts isTupleValue().
1393
   * @return the representation of a tuple value as a vector of terms.
1394
   */
1395
  std::vector<Term> getTupleValue() const;
1396
1397
  /**
1398
   * @return true if the term is the floating-point value for positive zero.
1399
   */
1400
  bool isFloatingPointPosZero() const;
1401
  /**
1402
   * @return true if the term is the floating-point value for negative zero.
1403
   */
1404
  bool isFloatingPointNegZero() const;
1405
  /**
1406
   * @return true if the term is the floating-point value for positive
1407
   * infinity.
1408
   */
1409
  bool isFloatingPointPosInf() const;
1410
  /**
1411
   * @return true if the term is the floating-point value for negative
1412
   * infinity.
1413
   */
1414
  bool isFloatingPointNegInf() const;
1415
  /**
1416
   * @return true if the term is the floating-point value for not a number.
1417
   */
1418
  bool isFloatingPointNaN() const;
1419
  /**
1420
   * @return true if the term is a floating-point value.
1421
   */
1422
  bool isFloatingPointValue() const;
1423
  /**
1424
   * Asserts isFloatingPointValue().
1425
   * @return the representation of a floating-point value as a tuple of the
1426
   * exponent width, the significand width and a bit-vector value.
1427
   */
1428
  std::tuple<uint32_t, uint32_t, Term> getFloatingPointValue() const;
1429
1430
  /**
1431
   * @return true if the term is a set value.
1432
   */
1433
  bool isSetValue() const;
1434
  /**
1435
   * Asserts isSetValue().
1436
   * @return the representation of a set value as a set of terms.
1437
   */
1438
  std::set<Term> getSetValue() const;
1439
1440
  /**
1441
   * @return true if the term is a sequence value.
1442
   */
1443
  bool isSequenceValue() const;
1444
  /**
1445
   * Asserts isSequenceValue().
1446
   * Note that it is usually necessary for sequences to call
1447
   * `Solver::simplify()` to turn a sequence that is constructed by, e.g.,
1448
   * concatenation of unit sequences, into a sequence value.
1449
   * @return the representation of a sequence value as a vector of terms.
1450
   */
1451
  std::vector<Term> getSequenceValue() const;
1452
1453
  /**
1454
   * @return true if the term is a value from an uninterpreted sort.
1455
   */
1456
  bool isUninterpretedValue() const;
1457
  /**
1458
  bool @return() const;
1459
   * Asserts isUninterpretedValue().
1460
   * @return the representation of an uninterpreted value as a pair of its
1461
  sort and its
1462
   * index.
1463
   */
1464
  std::pair<Sort, int32_t> getUninterpretedValue() const;
1465
1466
 protected:
1467
  /**
1468
   * The associated solver object.
1469
   */
1470
  const Solver* d_solver;
1471
1472
 private:
1473
  /** Helper to convert a vector of Terms to internal Nodes. */
1474
  std::vector<Node> static termVectorToNodes(const std::vector<Term>& terms);
1475
1476
  /** Helper method to collect all elements of a set. */
1477
  static void collectSet(std::set<Term>& set,
1478
                         const cvc5::Node& node,
1479
                         const Solver* slv);
1480
  /** Helper method to collect all elements of a sequence. */
1481
  static void collectSequence(std::vector<Term>& seq,
1482
                              const cvc5::Node& node,
1483
                              const Solver* slv);
1484
1485
  /**
1486
   * Constructor.
1487
   * @param slv the associated solver object
1488
   * @param n the internal node that is to be wrapped by this term
1489
   * @return the Term
1490
   */
1491
  Term(const Solver* slv, const cvc5::Node& n);
1492
1493
  /** @return the internal wrapped Node of this term. */
1494
  const cvc5::Node& getNode(void) const;
1495
1496
  /**
1497
   * Helper for isNull checks. This prevents calling an API function with
1498
   * CVC5_API_CHECK_NOT_NULL
1499
   */
1500
  bool isNullHelper() const;
1501
1502
  /**
1503
   * Helper function that returns the kind of the term, which takes into
1504
   * account special cases of the conversion for internal to external kinds.
1505
   * @return the kind of this term
1506
   */
1507
  Kind getKindHelper() const;
1508
1509
  /**
1510
   * @return true if the current term is a constant integer that is casted into
1511
   * real using the operator CAST_TO_REAL, and returns false otherwise
1512
   */
1513
  bool isCastedReal() const;
1514
  /**
1515
   * The internal node wrapped by this term.
1516
   * Note: This is a shared_ptr rather than a unique_ptr to avoid overhead due
1517
   *       to memory allocation (cvc5::Node is already ref counted, so this
1518
   *       could be a unique_ptr instead).
1519
   */
1520
  std::shared_ptr<cvc5::Node> d_node;
1521
};
1522
1523
/**
1524
 * Serialize a term to given stream.
1525
 * @param out the output stream
1526
 * @param t the term to be serialized to the given output stream
1527
 * @return the output stream
1528
 */
1529
std::ostream& operator<<(std::ostream& out, const Term& t) CVC5_EXPORT;
1530
1531
/**
1532
 * Serialize a vector of terms to given stream.
1533
 * @param out the output stream
1534
 * @param vector the vector of terms to be serialized to the given stream
1535
 * @return the output stream
1536
 */
1537
std::ostream& operator<<(std::ostream& out,
1538
                         const std::vector<Term>& vector) CVC5_EXPORT;
1539
1540
/**
1541
 * Serialize a set of terms to the given stream.
1542
 * @param out the output stream
1543
 * @param set the set of terms to be serialized to the given stream
1544
 * @return the output stream
1545
 */
1546
std::ostream& operator<<(std::ostream& out,
1547
                         const std::set<Term>& set) CVC5_EXPORT;
1548
1549
/**
1550
 * Serialize an unordered_set of terms to the given stream.
1551
 *
1552
 * @param out the output stream
1553
 * @param unordered_set the set of terms to be serialized to the given stream
1554
 * @return the output stream
1555
 */
1556
std::ostream& operator<<(std::ostream& out,
1557
                         const std::unordered_set<Term>& unordered_set)
1558
    CVC5_EXPORT;
1559
1560
/**
1561
 * Serialize a map of terms to the given stream.
1562
 *
1563
 * @param out the output stream
1564
 * @param map the map of terms to be serialized to the given stream
1565
 * @return the output stream
1566
 */
1567
template <typename V>
1568
std::ostream& operator<<(std::ostream& out,
1569
                         const std::map<Term, V>& map) CVC5_EXPORT;
1570
1571
/**
1572
 * Serialize an unordered_map of terms to the given stream.
1573
 *
1574
 * @param out the output stream
1575
 * @param unordered_map the map of terms to be serialized to the given stream
1576
 * @return the output stream
1577
 */
1578
template <typename V>
1579
std::ostream& operator<<(std::ostream& out,
1580
                         const std::unordered_map<Term, V>& unordered_map)
1581
    CVC5_EXPORT;
1582
1583
}  // namespace cvc5::api
1584
1585
namespace std {
1586
/**
1587
 * Hash function for Terms.
1588
 */
1589
template <>
1590
struct CVC5_EXPORT hash<cvc5::api::Term>
1591
{
1592
  size_t operator()(const cvc5::api::Term& t) const;
1593
};
1594
}  // namespace std
1595
1596
namespace cvc5::api {
1597
1598
/* -------------------------------------------------------------------------- */
1599
/* Datatypes                                                                  */
1600
/* -------------------------------------------------------------------------- */
1601
1602
class DatatypeConstructorIterator;
1603
class DatatypeIterator;
1604
1605
/**
1606
 * A cvc5 datatype constructor declaration.
1607
 */
1608
22
class CVC5_EXPORT DatatypeConstructorDecl
1609
{
1610
  friend class DatatypeDecl;
1611
  friend class Solver;
1612
1613
 public:
1614
  /** Constructor.  */
1615
  DatatypeConstructorDecl();
1616
1617
  /**
1618
   * Destructor.
1619
   */
1620
  ~DatatypeConstructorDecl();
1621
1622
  /**
1623
   * Add datatype selector declaration.
1624
   * @param name the name of the datatype selector declaration to add
1625
   * @param sort the range sort of the datatype selector declaration to add
1626
   */
1627
  void addSelector(const std::string& name, const Sort& sort);
1628
  /**
1629
   * Add datatype selector declaration whose range type is the datatype itself.
1630
   * @param name the name of the datatype selector declaration to add
1631
   */
1632
  void addSelectorSelf(const std::string& name);
1633
1634
  /**
1635
   * @return true if this DatatypeConstructorDecl is a null declaration.
1636
   */
1637
  bool isNull() const;
1638
1639
  /**
1640
   * @return a string representation of this datatype constructor declaration
1641
   */
1642
  std::string toString() const;
1643
1644
 private:
1645
  /**
1646
   * Constructor.
1647
   * @param slv the associated solver object
1648
   * @param name the name of the datatype constructor
1649
   * @return the DatatypeConstructorDecl
1650
   */
1651
  DatatypeConstructorDecl(const Solver* slv, const std::string& name);
1652
1653
  /**
1654
   * Helper for isNull checks. This prevents calling an API function with
1655
   * CVC5_API_CHECK_NOT_NULL
1656
   */
1657
  bool isNullHelper() const;
1658
1659
  /**
1660
   * The associated solver object.
1661
   */
1662
  const Solver* d_solver;
1663
1664
  /**
1665
   * The internal (intermediate) datatype constructor wrapped by this
1666
   * datatype constructor declaration.
1667
   * Note: This is a shared_ptr rather than a unique_ptr since
1668
   *       cvc5::DTypeConstructor is not ref counted.
1669
   */
1670
  std::shared_ptr<cvc5::DTypeConstructor> d_ctor;
1671
};
1672
1673
class Solver;
1674
1675
/**
1676
 * A cvc5 datatype declaration.
1677
 */
1678
1177
class CVC5_EXPORT DatatypeDecl
1679
{
1680
  friend class DatatypeConstructorArg;
1681
  friend class Solver;
1682
  friend class Grammar;
1683
1684
 public:
1685
  /** Constructor.  */
1686
  DatatypeDecl();
1687
1688
  /**
1689
   * Destructor.
1690
   */
1691
  ~DatatypeDecl();
1692
1693
  /**
1694
   * Add datatype constructor declaration.
1695
   * @param ctor the datatype constructor declaration to add
1696
   */
1697
  void addConstructor(const DatatypeConstructorDecl& ctor);
1698
1699
  /** Get the number of constructors (so far) for this Datatype declaration. */
1700
  size_t getNumConstructors() const;
1701
1702
  /** Is this Datatype declaration parametric? */
1703
  bool isParametric() const;
1704
1705
  /**
1706
   * @return true if this DatatypeDecl is a null object
1707
   */
1708
  bool isNull() const;
1709
1710
  /**
1711
   * @return a string representation of this datatype declaration
1712
   */
1713
  std::string toString() const;
1714
1715
  /** @return the name of this datatype declaration. */
1716
  std::string getName() const;
1717
1718
 private:
1719
  /**
1720
   * Constructor.
1721
   * @param slv the associated solver object
1722
   * @param name the name of the datatype
1723
   * @param isCoDatatype true if a codatatype is to be constructed
1724
   * @return the DatatypeDecl
1725
   */
1726
  DatatypeDecl(const Solver* slv,
1727
               const std::string& name,
1728
               bool isCoDatatype = false);
1729
1730
  /**
1731
   * Constructor for parameterized datatype declaration.
1732
   * Create sorts parameter with Solver::mkParamSort().
1733
   * @param slv the associated solver object
1734
   * @param name the name of the datatype
1735
   * @param param the sort parameter
1736
   * @param isCoDatatype true if a codatatype is to be constructed
1737
   */
1738
  DatatypeDecl(const Solver* slv,
1739
               const std::string& name,
1740
               const Sort& param,
1741
               bool isCoDatatype = false);
1742
1743
  /**
1744
   * Constructor for parameterized datatype declaration.
1745
   * Create sorts parameter with Solver::mkParamSort().
1746
   * @param slv the associated solver object
1747
   * @param name the name of the datatype
1748
   * @param params a list of sort parameters
1749
   * @param isCoDatatype true if a codatatype is to be constructed
1750
   */
1751
  DatatypeDecl(const Solver* slv,
1752
               const std::string& name,
1753
               const std::vector<Sort>& params,
1754
               bool isCoDatatype = false);
1755
1756
  /** @return the internal wrapped Dtype of this datatype declaration. */
1757
  cvc5::DType& getDatatype(void) const;
1758
1759
  /**
1760
   * Helper for isNull checks. This prevents calling an API function with
1761
   * CVC5_API_CHECK_NOT_NULL
1762
   */
1763
  bool isNullHelper() const;
1764
1765
  /**
1766
   * The associated solver object.
1767
   */
1768
  const Solver* d_solver;
1769
1770
  /**
1771
   * The internal (intermediate) datatype wrapped by this datatype
1772
   * declaration.
1773
   * Note: This is a shared_ptr rather than a unique_ptr since cvc5::DType is
1774
   *       not ref counted.
1775
   */
1776
  std::shared_ptr<cvc5::DType> d_dtype;
1777
};
1778
1779
/**
1780
 * A cvc5 datatype selector.
1781
 */
1782
2
class CVC5_EXPORT DatatypeSelector
1783
{
1784
  friend class Datatype;
1785
  friend class DatatypeConstructor;
1786
  friend class Solver;
1787
1788
 public:
1789
  /**
1790
   * Constructor.
1791
   */
1792
  DatatypeSelector();
1793
1794
  /**
1795
   * Destructor.
1796
   */
1797
  ~DatatypeSelector();
1798
1799
  /** @return the name of this Datatype selector. */
1800
  std::string getName() const;
1801
1802
  /**
1803
   * Get the selector operator of this datatype selector.
1804
   * @return the selector term
1805
   */
1806
  Term getSelectorTerm() const;
1807
1808
  /**
1809
   * Get the upater operator of this datatype selector.
1810
   * @return the updater term
1811
   */
1812
  Term getUpdaterTerm() const;
1813
1814
  /** @return the range sort of this selector. */
1815
  Sort getRangeSort() const;
1816
1817
  /**
1818
   * @return true if this DatatypeSelector is a null object
1819
   */
1820
  bool isNull() const;
1821
1822
  /**
1823
   * @return a string representation of this datatype selector
1824
   */
1825
  std::string toString() const;
1826
1827
 private:
1828
  /**
1829
   * Constructor.
1830
   * @param slv the associated solver object
1831
   * @param stor the internal datatype selector to be wrapped
1832
   * @return the DatatypeSelector
1833
   */
1834
  DatatypeSelector(const Solver* slv, const cvc5::DTypeSelector& stor);
1835
1836
  /**
1837
   * Helper for isNull checks. This prevents calling an API function with
1838
   * CVC5_API_CHECK_NOT_NULL
1839
   */
1840
  bool isNullHelper() const;
1841
1842
  /**
1843
   * The associated solver object.
1844
   */
1845
  const Solver* d_solver;
1846
1847
  /**
1848
   * The internal datatype selector wrapped by this datatype selector.
1849
   * Note: This is a shared_ptr rather than a unique_ptr since cvc5::DType is
1850
   *       not ref counted.
1851
   */
1852
  std::shared_ptr<cvc5::DTypeSelector> d_stor;
1853
};
1854
1855
/**
1856
 * A cvc5 datatype constructor.
1857
 */
1858
2
class CVC5_EXPORT DatatypeConstructor
1859
{
1860
  friend class Datatype;
1861
  friend class Solver;
1862
1863
 public:
1864
  /**
1865
   * Constructor.
1866
   */
1867
  DatatypeConstructor();
1868
1869
  /**
1870
   * Destructor.
1871
   */
1872
  ~DatatypeConstructor();
1873
1874
  /** @return the name of this Datatype constructor. */
1875
  std::string getName() const;
1876
1877
  /**
1878
   * Get the constructor operator of this datatype constructor.
1879
   * @return the constructor term
1880
   */
1881
  Term getConstructorTerm() const;
1882
1883
  /**
1884
   * Get the constructor operator of this datatype constructor whose return
1885
   * type is retSort. This method is intended to be used on constructors of
1886
   * parametric datatypes and can be seen as returning the constructor
1887
   * term that has been explicitly cast to the given sort.
1888
   *
1889
   * This method is required for constructors of parametric datatypes whose
1890
   * return type cannot be determined by type inference. For example, given:
1891
   *   (declare-datatype List (par (T) ((nil) (cons (head T) (tail (List T))))))
1892
   * The type of nil terms need to be provided by the user. In SMT version 2.6,
1893
   * this is done via the syntax for qualified identifiers:
1894
   *   (as nil (List Int))
1895
   * This method is equivalent of applying the above, where this
1896
   * DatatypeConstructor is the one corresponding to nil, and retSort is
1897
   * (List Int).
1898
   *
1899
   * Furthermore note that the returned constructor term t is an operator,
1900
   * while Solver::mkTerm(APPLY_CONSTRUCTOR, t) is used to construct the above
1901
   * (nullary) application of nil.
1902
   *
1903
   * @param retSort the desired return sort of the constructor
1904
   * @return the constructor term
1905
   */
1906
  Term getSpecializedConstructorTerm(const Sort& retSort) const;
1907
1908
  /**
1909
   * Get the tester operator of this datatype constructor.
1910
   * @return the tester operator
1911
   */
1912
  Term getTesterTerm() const;
1913
1914
  /**
1915
   * @return the number of selectors (so far) of this Datatype constructor.
1916
   */
1917
  size_t getNumSelectors() const;
1918
1919
  /** @return the i^th DatatypeSelector. */
1920
  DatatypeSelector operator[](size_t index) const;
1921
  /**
1922
   * Get the datatype selector with the given name.
1923
   * This is a linear search through the selectors, so in case of
1924
   * multiple, similarly-named selectors, the first is returned.
1925
   * @param name the name of the datatype selector
1926
   * @return the first datatype selector with the given name
1927
   */
1928
  DatatypeSelector operator[](const std::string& name) const;
1929
  DatatypeSelector getSelector(const std::string& name) const;
1930
1931
  /**
1932
   * Get the term representation of the datatype selector with the given name.
1933
   * This is a linear search through the arguments, so in case of multiple,
1934
   * similarly-named arguments, the selector for the first is returned.
1935
   * @param name the name of the datatype selector
1936
   * @return a term representing the datatype selector with the given name
1937
   */
1938
  Term getSelectorTerm(const std::string& name) const;
1939
1940
  /**
1941
   * @return true if this DatatypeConstructor is a null object
1942
   */
1943
  bool isNull() const;
1944
1945
  /**
1946
   * @return a string representation of this datatype constructor
1947
   */
1948
  std::string toString() const;
1949
1950
  /**
1951
   * Iterator for the selectors of a datatype constructor.
1952
   */
1953
  class const_iterator
1954
      : public std::iterator<std::input_iterator_tag, DatatypeConstructor>
1955
  {
1956
    friend class DatatypeConstructor;  // to access constructor
1957
1958
   public:
1959
    /** Nullary constructor (required for Cython). */
1960
    const_iterator();
1961
1962
    /**
1963
     * Assignment operator.
1964
     * @param it the iterator to assign to
1965
     * @return the reference to the iterator after assignment
1966
     */
1967
    const_iterator& operator=(const const_iterator& it);
1968
1969
    /**
1970
     * Equality operator.
1971
     * @param it the iterator to compare to for equality
1972
     * @return true if the iterators are equal
1973
     */
1974
    bool operator==(const const_iterator& it) const;
1975
1976
    /**
1977
     * Disequality operator.
1978
     * @param it the iterator to compare to for disequality
1979
     * @return true if the iterators are disequal
1980
     */
1981
    bool operator!=(const const_iterator& it) const;
1982
1983
    /**
1984
     * Increment operator (prefix).
1985
     * @return a reference to the iterator after incrementing by one
1986
     */
1987
    const_iterator& operator++();
1988
1989
    /**
1990
     * Increment operator (postfix).
1991
     * @return a reference to the iterator after incrementing by one
1992
     */
1993
    const_iterator operator++(int);
1994
1995
    /**
1996
     * Dereference operator.
1997
     * @return a reference to the selector this iterator points to
1998
     */
1999
    const DatatypeSelector& operator*() const;
2000
2001
    /**
2002
     * Dereference operator.
2003
     * @return a pointer to the selector this iterator points to
2004
     */
2005
    const DatatypeSelector* operator->() const;
2006
2007
   private:
2008
    /**
2009
     * Constructor.
2010
     * @param slv the associated Solver object
2011
     * @param ctor the internal datatype constructor to iterate over
2012
     * @param begin true if this is a begin() iterator
2013
     */
2014
    const_iterator(const Solver* slv,
2015
                   const cvc5::DTypeConstructor& ctor,
2016
                   bool begin);
2017
2018
    /**
2019
     * The associated solver object.
2020
     */
2021
    const Solver* d_solver;
2022
2023
    /**
2024
     * A pointer to the list of selectors of the internal datatype
2025
     * constructor to iterate over.
2026
     * This pointer is maintained for operators == and != only.
2027
     */
2028
    const void* d_int_stors;
2029
2030
    /** The list of datatype selector (wrappers) to iterate over. */
2031
    std::vector<DatatypeSelector> d_stors;
2032
2033
    /** The current index of the iterator. */
2034
    size_t d_idx;
2035
  };
2036
2037
  /**
2038
   * @return an iterator to the first selector of this constructor
2039
   */
2040
  const_iterator begin() const;
2041
2042
  /**
2043
   * @return an iterator to one-off-the-last selector of this constructor
2044
   */
2045
  const_iterator end() const;
2046
2047
 private:
2048
  /**
2049
   * Constructor.
2050
   * @param slv the associated solver instance
2051
   * @param ctor the internal datatype constructor to be wrapped
2052
   * @return the DatatypeConstructor
2053
   */
2054
  DatatypeConstructor(const Solver* slv, const cvc5::DTypeConstructor& ctor);
2055
2056
  /**
2057
   * Return selector for name.
2058
   * @param name The name of selector to find
2059
   * @return the selector object for the name
2060
   */
2061
  DatatypeSelector getSelectorForName(const std::string& name) const;
2062
2063
  /**
2064
   * Helper for isNull checks. This prevents calling an API function with
2065
   * CVC5_API_CHECK_NOT_NULL
2066
   */
2067
  bool isNullHelper() const;
2068
2069
  /**
2070
   * The associated solver object.
2071
   */
2072
  const Solver* d_solver;
2073
2074
  /**
2075
   * The internal datatype constructor wrapped by this datatype constructor.
2076
   * Note: This is a shared_ptr rather than a unique_ptr since cvc5::DType is
2077
   *       not ref counted.
2078
   */
2079
  std::shared_ptr<cvc5::DTypeConstructor> d_ctor;
2080
};
2081
2082
/**
2083
 * A cvc5 datatype.
2084
 */
2085
2
class CVC5_EXPORT Datatype
2086
{
2087
  friend class Solver;
2088
  friend class Sort;
2089
2090
 public:
2091
  /** Constructor. */
2092
  Datatype();
2093
2094
  /**
2095
   * Destructor.
2096
   */
2097
  ~Datatype();
2098
2099
  /**
2100
   * Get the datatype constructor at a given index.
2101
   * @param idx the index of the datatype constructor to return
2102
   * @return the datatype constructor with the given index
2103
   */
2104
  DatatypeConstructor operator[](size_t idx) const;
2105
2106
  /**
2107
   * Get the datatype constructor with the given name.
2108
   * This is a linear search through the constructors, so in case of multiple,
2109
   * similarly-named constructors, the first is returned.
2110
   * @param name the name of the datatype constructor
2111
   * @return the datatype constructor with the given name
2112
   */
2113
  DatatypeConstructor operator[](const std::string& name) const;
2114
  DatatypeConstructor getConstructor(const std::string& name) const;
2115
2116
  /**
2117
   * Get a term representing the datatype constructor with the given name.
2118
   * This is a linear search through the constructors, so in case of multiple,
2119
   * similarly-named constructors, the
2120
   * first is returned.
2121
   */
2122
  Term getConstructorTerm(const std::string& name) const;
2123
2124
  /**
2125
   * Get the datatype constructor with the given name.
2126
   * This is a linear search through the constructors and their selectors, so
2127
   * in case of multiple, similarly-named selectors, the first is returned.
2128
   * @param name the name of the datatype selector
2129
   * @return the datatype selector with the given name
2130
   */
2131
  DatatypeSelector getSelector(const std::string& name) const;
2132
2133
  /** @return the name of this Datatype. */
2134
  std::string getName() const;
2135
2136
  /** @return the number of constructors for this Datatype. */
2137
  size_t getNumConstructors() const;
2138
2139
  /** @return true if this datatype is parametric */
2140
  bool isParametric() const;
2141
2142
  /** @return true if this datatype corresponds to a co-datatype */
2143
  bool isCodatatype() const;
2144
2145
  /** @return true if this datatype corresponds to a tuple */
2146
  bool isTuple() const;
2147
2148
  /** @return true if this datatype corresponds to a record */
2149
  bool isRecord() const;
2150
2151
  /** @return true if this datatype is finite */
2152
  bool isFinite() const;
2153
2154
  /**
2155
   * Is this datatype well-founded? If this datatype is not a codatatype,
2156
   * this returns false if there are no values of this datatype that are of
2157
   * finite size.
2158
   *
2159
   * @return true if this datatype is well-founded
2160
   */
2161
  bool isWellFounded() const;
2162
2163
  /**
2164
   * Does this datatype have nested recursion? This method returns false if a
2165
   * value of this datatype includes a subterm of its type that is nested
2166
   * beneath a non-datatype type constructor. For example, a datatype
2167
   * T containing a constructor having a selector with range type (Set T) has
2168
   * nested recursion.
2169
   *
2170
   * @return true if this datatype has nested recursion
2171
   */
2172
  bool hasNestedRecursion() const;
2173
2174
  /**
2175
   * @return true if this Datatype is a null object
2176
   */
2177
  bool isNull() const;
2178
2179
  /**
2180
   * @return a string representation of this datatype
2181
   */
2182
  std::string toString() const;
2183
2184
  /**
2185
   * Iterator for the constructors of a datatype.
2186
   */
2187
  class const_iterator : public std::iterator<std::input_iterator_tag, Datatype>
2188
  {
2189
    friend class Datatype;  // to access constructor
2190
2191
   public:
2192
    /** Nullary constructor (required for Cython). */
2193
    const_iterator();
2194
2195
    /**
2196
     * Assignment operator.
2197
     * @param it the iterator to assign to
2198
     * @return the reference to the iterator after assignment
2199
     */
2200
    const_iterator& operator=(const const_iterator& it);
2201
2202
    /**
2203
     * Equality operator.
2204
     * @param it the iterator to compare to for equality
2205
     * @return true if the iterators are equal
2206
     */
2207
    bool operator==(const const_iterator& it) const;
2208
2209
    /**
2210
     * Disequality operator.
2211
     * @param it the iterator to compare to for disequality
2212
     * @return true if the iterators are disequal
2213
     */
2214
    bool operator!=(const const_iterator& it) const;
2215
2216
    /**
2217
     * Increment operator (prefix).
2218
     * @return a reference to the iterator after incrementing by one
2219
     */
2220
    const_iterator& operator++();
2221
2222
    /**
2223
     * Increment operator (postfix).
2224
     * @return a reference to the iterator after incrementing by one
2225
     */
2226
    const_iterator operator++(int);
2227
2228
    /**
2229
     * Dereference operator.
2230
     * @return a reference to the constructor this iterator points to
2231
     */
2232
    const DatatypeConstructor& operator*() const;
2233
2234
    /**
2235
     * Dereference operator.
2236
     * @return a pointer to the constructor this iterator points to
2237
     */
2238
    const DatatypeConstructor* operator->() const;
2239
2240
   private:
2241
    /**
2242
     * Constructor.
2243
     * @param slv the associated Solver object
2244
     * @param dtype the internal datatype to iterate over
2245
     * @param begin true if this is a begin() iterator
2246
     */
2247
    const_iterator(const Solver* slv, const cvc5::DType& dtype, bool begin);
2248
2249
    /**
2250
     * The associated solver object.
2251
     */
2252
    const Solver* d_solver;
2253
2254
    /**
2255
     * A pointer to the list of constructors of the internal datatype
2256
     * to iterate over.
2257
     * This pointer is maintained for operators == and != only.
2258
     */
2259
    const void* d_int_ctors;
2260
2261
    /** The list of datatype constructor (wrappers) to iterate over. */
2262
    std::vector<DatatypeConstructor> d_ctors;
2263
2264
    /** The current index of the iterator. */
2265
    size_t d_idx;
2266
  };
2267
2268
  /**
2269
   * @return an iterator to the first constructor of this datatype
2270
   */
2271
  const_iterator begin() const;
2272
2273
  /**
2274
   * @return an iterator to one-off-the-last constructor of this datatype
2275
   */
2276
  const_iterator end() const;
2277
2278
 private:
2279
  /**
2280
   * Constructor.
2281
   * @param slv the associated solver instance
2282
   * @param dtype the internal datatype to be wrapped
2283
   * @return the Datatype
2284
   */
2285
  Datatype(const Solver* slv, const cvc5::DType& dtype);
2286
2287
  /**
2288
   * Return constructor for name.
2289
   * @param name The name of constructor to find
2290
   * @return the constructor object for the name
2291
   */
2292
  DatatypeConstructor getConstructorForName(const std::string& name) const;
2293
2294
  /**
2295
   * Return selector for name.
2296
   * @param name The name of selector to find
2297
   * @return the selector object for the name
2298
   */
2299
  DatatypeSelector getSelectorForName(const std::string& name) const;
2300
2301
  /**
2302
   * Helper for isNull checks. This prevents calling an API function with
2303
   * CVC5_API_CHECK_NOT_NULL
2304
   */
2305
  bool isNullHelper() const;
2306
2307
  /**
2308
   * The associated solver object.
2309
   */
2310
  const Solver* d_solver;
2311
2312
  /**
2313
   * The internal datatype wrapped by this datatype.
2314
   * Note: This is a shared_ptr rather than a unique_ptr since cvc5::DType is
2315
   *       not ref counted.
2316
   */
2317
  std::shared_ptr<cvc5::DType> d_dtype;
2318
};
2319
2320
/**
2321
 * Serialize a datatype declaration to given stream.
2322
 * @param out the output stream
2323
 * @param dtdecl the datatype declaration to be serialized to the given stream
2324
 * @return the output stream
2325
 */
2326
std::ostream& operator<<(std::ostream& out,
2327
                         const DatatypeDecl& dtdecl) CVC5_EXPORT;
2328
2329
/**
2330
 * Serialize a datatype constructor declaration to given stream.
2331
 * @param out the output stream
2332
 * @param ctordecl the datatype constructor declaration to be serialized
2333
 * @return the output stream
2334
 */
2335
std::ostream& operator<<(std::ostream& out,
2336
                         const DatatypeConstructorDecl& ctordecl) CVC5_EXPORT;
2337
2338
/**
2339
 * Serialize a vector of datatype constructor declarations to given stream.
2340
 * @param out the output stream
2341
 * @param vector the vector of datatype constructor declarations to be
2342
 * serialized to the given stream
2343
 * @return the output stream
2344
 */
2345
std::ostream& operator<<(std::ostream& out,
2346
                         const std::vector<DatatypeConstructorDecl>& vector)
2347
    CVC5_EXPORT;
2348
2349
/**
2350
 * Serialize a datatype to given stream.
2351
 * @param out the output stream
2352
 * @param dtype the datatype to be serialized to given stream
2353
 * @return the output stream
2354
 */
2355
std::ostream& operator<<(std::ostream& out, const Datatype& dtype) CVC5_EXPORT;
2356
2357
/**
2358
 * Serialize a datatype constructor to given stream.
2359
 * @param out the output stream
2360
 * @param ctor the datatype constructor to be serialized to given stream
2361
 * @return the output stream
2362
 */
2363
std::ostream& operator<<(std::ostream& out,
2364
                         const DatatypeConstructor& ctor) CVC5_EXPORT;
2365
2366
/**
2367
 * Serialize a datatype selector to given stream.
2368
 * @param out the output stream
2369
 * @param stor the datatype selector to be serialized to given stream
2370
 * @return the output stream
2371
 */
2372
std::ostream& operator<<(std::ostream& out,
2373
                         const DatatypeSelector& stor) CVC5_EXPORT;
2374
2375
/* -------------------------------------------------------------------------- */
2376
/* Grammar                                                                    */
2377
/* -------------------------------------------------------------------------- */
2378
2379
/**
2380
 * A Sygus Grammar.
2381
 */
2382
178
class CVC5_EXPORT Grammar
2383
{
2384
  friend class cvc5::Command;
2385
  friend class Solver;
2386
2387
 public:
2388
  /**
2389
   * Add \p rule to the set of rules corresponding to \p ntSymbol.
2390
   * @param ntSymbol the non-terminal to which the rule is added
2391
   * @param rule the rule to add
2392
   */
2393
  void addRule(const Term& ntSymbol, const Term& rule);
2394
2395
  /**
2396
   * Add \p rules to the set of rules corresponding to \p ntSymbol.
2397
   * @param ntSymbol the non-terminal to which the rules are added
2398
   * @param rules the rules to add
2399
   */
2400
  void addRules(const Term& ntSymbol, const std::vector<Term>& rules);
2401
2402
  /**
2403
   * Allow \p ntSymbol to be an arbitrary constant.
2404
   * @param ntSymbol the non-terminal allowed to be any constant
2405
   */
2406
  void addAnyConstant(const Term& ntSymbol);
2407
2408
  /**
2409
   * Allow \p ntSymbol to be any input variable to corresponding
2410
   * synth-fun/synth-inv with the same sort as \p ntSymbol.
2411
   * @param ntSymbol the non-terminal allowed to be any input constant
2412
   */
2413
  void addAnyVariable(const Term& ntSymbol);
2414
2415
  /**
2416
   * @return a string representation of this grammar.
2417
   */
2418
  std::string toString() const;
2419
2420
  /**
2421
   * Nullary constructor. Needed for the Cython API.
2422
   */
2423
  Grammar();
2424
2425
 private:
2426
  /**
2427
   * Constructor.
2428
   * @param slv the solver that created this grammar
2429
   * @param sygusVars the input variables to synth-fun/synth-var
2430
   * @param ntSymbols the non-terminals of this grammar
2431
   */
2432
  Grammar(const Solver* slv,
2433
          const std::vector<Term>& sygusVars,
2434
          const std::vector<Term>& ntSymbols);
2435
2436
  /**
2437
   * @return the resolved datatype of the Start symbol of the grammar
2438
   */
2439
  Sort resolve();
2440
2441
  /**
2442
   * Adds a constructor to sygus datatype <dt> whose sygus operator is <term>.
2443
   *
2444
   * \p ntsToUnres contains a mapping from non-terminal symbols to the
2445
   * unresolved sorts they correspond to. This map indicates how the argument
2446
   * <term> should be interpreted (instances of symbols from the domain of
2447
   * \p ntsToUnres correspond to constructor arguments).
2448
   *
2449
   * The sygus operator that is actually added to <dt> corresponds to replacing
2450
   * each occurrence of non-terminal symbols from the domain of \p ntsToUnres
2451
   * with bound variables via purifySygusGTerm, and binding these variables
2452
   * via a lambda.
2453
   *
2454
   * @param dt the non-terminal's datatype to which a constructor is added
2455
   * @param term the sygus operator of the constructor
2456
   * @param ntsToUnres mapping from non-terminals to their unresolved sorts
2457
   */
2458
  void addSygusConstructorTerm(
2459
      DatatypeDecl& dt,
2460
      const Term& term,
2461
      const std::unordered_map<Term, Sort>& ntsToUnres) const;
2462
2463
  /**
2464
   * Purify SyGuS grammar term.
2465
   *
2466
   * This returns a term where all occurrences of non-terminal symbols (those
2467
   * in the domain of \p ntsToUnres) are replaced by fresh variables. For
2468
   * each variable replaced in this way, we add the fresh variable it is
2469
   * replaced with to \p args, and the unresolved sorts corresponding to the
2470
   * non-terminal symbol to \p cargs (constructor args). In other words,
2471
   * \p args contains the free variables in the term returned by this method
2472
   * (which should be bound by a lambda), and \p cargs contains the sorts of
2473
   * the arguments of the sygus constructor.
2474
   *
2475
   * @param term the term to purify
2476
   * @param args the free variables in the term returned by this method
2477
   * @param cargs the sorts of the arguments of the sygus constructor
2478
   * @param ntsToUnres mapping from non-terminals to their unresolved sorts
2479
   * @return the purfied term
2480
   */
2481
  Term purifySygusGTerm(const Term& term,
2482
                        std::vector<Term>& args,
2483
                        std::vector<Sort>& cargs,
2484
                        const std::unordered_map<Term, Sort>& ntsToUnres) const;
2485
2486
  /**
2487
   * This adds constructors to \p dt for sygus variables in \p d_sygusVars
2488
   * whose sort is argument \p sort. This method should be called when the
2489
   * sygus grammar term (Variable sort) is encountered.
2490
   *
2491
   * @param dt the non-terminal's datatype to which the constructors are added
2492
   * @param sort the sort of the sygus variables to add
2493
   */
2494
  void addSygusConstructorVariables(DatatypeDecl& dt, const Sort& sort) const;
2495
2496
  /**
2497
   * Check if \p rule contains variables that are neither parameters of
2498
   * the corresponding synthFun/synthInv nor non-terminals.
2499
   * @param rule the non-terminal allowed to be any constant
2500
   * @return true if \p rule contains free variables and false otherwise
2501
   */
2502
  bool containsFreeVariables(const Term& rule) const;
2503
2504
  /** The solver that created this grammar. */
2505
  const Solver* d_solver;
2506
  /** Input variables to the corresponding function/invariant to synthesize.*/
2507
  std::vector<Term> d_sygusVars;
2508
  /** The non-terminal symbols of this grammar. */
2509
  std::vector<Term> d_ntSyms;
2510
  /** The mapping from non-terminal symbols to their production terms. */
2511
  std::unordered_map<Term, std::vector<Term>> d_ntsToTerms;
2512
  /** The set of non-terminals that can be arbitrary constants. */
2513
  std::unordered_set<Term> d_allowConst;
2514
  /** The set of non-terminals that can be sygus variables. */
2515
  std::unordered_set<Term> d_allowVars;
2516
  /** Did we call resolve() before? */
2517
  bool d_isResolved;
2518
};
2519
2520
/**
2521
 * Serialize a grammar to given stream.
2522
 * @param out the output stream
2523
 * @param g the grammar to be serialized to the given output stream
2524
 * @return the output stream
2525
 */
2526
std::ostream& operator<<(std::ostream& out, const Grammar& g) CVC5_EXPORT;
2527
2528
/* -------------------------------------------------------------------------- */
2529
/* Rounding Mode for Floating-Points                                          */
2530
/* -------------------------------------------------------------------------- */
2531
2532
/**
2533
 * Rounding modes for floating-point numbers.
2534
 *
2535
 * For many floating-point operations, infinitely precise results may not be
2536
 * representable with the number of available bits. Thus, the results are
2537
 * rounded in a certain way to one of the representable floating-point numbers.
2538
 *
2539
 * \verbatim embed:rst:leading-asterisk
2540
 * These rounding modes directly follow the SMT-LIB theory for floating-point
2541
 * arithmetic, which in turn is based on IEEE Standard 754 :cite:`IEEE754`.
2542
 * The rounding modes are specified in Sections 4.3.1 and 4.3.2 of the IEEE
2543
 * Standard 754.
2544
 * \endverbatim
2545
 */
2546
enum CVC5_EXPORT RoundingMode
2547
{
2548
  /**
2549
   * Round to the nearest even number.
2550
   * If the two nearest floating-point numbers bracketing an unrepresentable
2551
   * infinitely precise result are equally near, the one with an even least
2552
   * significant digit will be delivered.
2553
   */
2554
  ROUND_NEAREST_TIES_TO_EVEN,
2555
  /**
2556
   * Round towards positive infinity (+oo).
2557
   * The result shall be the format’s floating-point number (possibly +oo)
2558
   * closest to and no less than the infinitely precise result.
2559
   */
2560
  ROUND_TOWARD_POSITIVE,
2561
  /**
2562
   * Round towards negative infinity (-oo).
2563
   * The result shall be the format’s floating-point number (possibly -oo)
2564
   * closest to and no less than the infinitely precise result.
2565
   */
2566
  ROUND_TOWARD_NEGATIVE,
2567
  /**
2568
   * Round towards zero.
2569
   * The result shall be the format’s floating-point number closest to and no
2570
   * greater in magnitude than the infinitely precise result.
2571
   */
2572
  ROUND_TOWARD_ZERO,
2573
  /**
2574
   * Round to the nearest number away from zero.
2575
   * If the two nearest floating-point numbers bracketing an unrepresentable
2576
   * infinitely precise result are equally near, the one with larger magnitude
2577
   * will be selected.
2578
   */
2579
  ROUND_NEAREST_TIES_TO_AWAY,
2580
};
2581
2582
}  // namespace cvc5::api
2583
2584
namespace std {
2585
2586
/**
2587
 * Hash function for RoundingModes.
2588
 */
2589
template <>
2590
struct CVC5_EXPORT hash<cvc5::api::RoundingMode>
2591
{
2592
  size_t operator()(cvc5::api::RoundingMode rm) const;
2593
};
2594
}  // namespace std
2595
namespace cvc5::api {
2596
2597
/* -------------------------------------------------------------------------- */
2598
/* Options                                                                    */
2599
/* -------------------------------------------------------------------------- */
2600
2601
/**
2602
 * Provides access to options that can not be communicated via the regular
2603
 * getOption() or getOptionInfo() methods. This class does not store the options
2604
 * itself, but only acts as a wrapper to the solver object. It can thus no
2605
 * longer be used after the solver object has been destroyed.
2606
 */
2607
class CVC5_EXPORT DriverOptions
2608
{
2609
  friend class Solver;
2610
2611
 public:
2612
  /** Access the solvers input stream */
2613
  std::istream& in() const;
2614
  /** Access the solvers error output stream */
2615
  std::ostream& err() const;
2616
  /** Access the solvers output stream */
2617
  std::ostream& out() const;
2618
2619
 private:
2620
  DriverOptions(const Solver& solver);
2621
  const Solver& d_solver;
2622
};
2623
2624
/**
2625
 * Holds some description about a particular option, including its name, its
2626
 * aliases, whether the option was explcitly set by the user, and information
2627
 * concerning its value. The `valueInfo` member holds any of the following
2628
 * alternatives:
2629
 * - VoidInfo if the option holds no value (or the value has no native type)
2630
 * - ValueInfo<T> if the option is of type bool or std::string, holds the
2631
 *   current value and the default value.
2632
 * - NumberInfo<T> if the option is of type int64_t, uint64_t or double, holds
2633
 *   the current and default value, as well as the minimum and maximum.
2634
 * - ModeInfo if the option is a mode option, holds the current and default
2635
 *   values, as well as a list of valid modes.
2636
 * Additionally, this class provides convenience functions to obtain the
2637
 * current value of an option in a type-safe manner using boolValue(),
2638
 * stringValue(), intValue(), uintValue() and doubleValue(). They assert that
2639
 * the option has the respective type and return the current value.
2640
 */
2641
1977035
struct CVC5_EXPORT OptionInfo
2642
{
2643
  /** Has no value information */
2644
  struct VoidInfo {};
2645
  /** Has the current and the default value */
2646
  template <typename T>
2647
12124
  struct ValueInfo
2648
  {
2649
    T defaultValue;
2650
    T currentValue;
2651
  };
2652
  /** Default value, current value, minimum and maximum of a numeric value */
2653
  template <typename T>
2654
216574
  struct NumberInfo
2655
  {
2656
    T defaultValue;
2657
    T currentValue;
2658
    std::optional<T> minimum;
2659
    std::optional<T> maximum;
2660
  };
2661
  /** Default value, current value and choices of a mode option */
2662
10
  struct ModeInfo
2663
  {
2664
    std::string defaultValue;
2665
    std::string currentValue;
2666
    std::vector<std::string> modes;
2667
  };
2668
2669
  /** The option name */
2670
  std::string name;
2671
  /** The option name aliases */
2672
  std::vector<std::string> aliases;
2673
  /** Whether the option was explicitly set by the user */
2674
  bool setByUser;
2675
  /** The option value information */
2676
  std::variant<VoidInfo,
2677
               ValueInfo<bool>,
2678
               ValueInfo<std::string>,
2679
               NumberInfo<int64_t>,
2680
               NumberInfo<uint64_t>,
2681
               NumberInfo<double>,
2682
               ModeInfo>
2683
      valueInfo;
2684
  /** Obtain the current value as a bool. Asserts that valueInfo holds a bool.
2685
   */
2686
  bool boolValue() const;
2687
  /** Obtain the current value as a string. Asserts that valueInfo holds a
2688
   * string. */
2689
  std::string stringValue() const;
2690
  /** Obtain the current value as as int. Asserts that valueInfo holds an int.
2691
   */
2692
  int64_t intValue() const;
2693
  /** Obtain the current value as a uint. Asserts that valueInfo holds a uint.
2694
   */
2695
  uint64_t uintValue() const;
2696
  /** Obtain the current value as a double. Asserts that valueInfo holds a
2697
   * double. */
2698
  double doubleValue() const;
2699
};
2700
2701
/**
2702
 * Print a `OptionInfo` object to an ``std::ostream``.
2703
 */
2704
std::ostream& operator<<(std::ostream& os, const OptionInfo& oi) CVC5_EXPORT;
2705
2706
/* -------------------------------------------------------------------------- */
2707
/* Statistics                                                                 */
2708
/* -------------------------------------------------------------------------- */
2709
2710
/**
2711
 * Represents a snapshot of a single statistic value.
2712
 * A value can be of type `int64_t`, `double`, `std::string` or a histogram
2713
 * (`std::map<std::string, uint64_t>`).
2714
 * The value type can be queried (using `isInt()`, `isDouble()`, etc.) and
2715
 * the stored value can be accessed (using `getInt()`, `getDouble()`, etc.).
2716
 * It is possible to query whether this statistic is an expert statistic by
2717
 * `isExpert()` and whether its value is the default value by `isDefault()`.
2718
 */
2719
class CVC5_EXPORT Stat
2720
{
2721
  struct StatData;
2722
2723
 public:
2724
  friend class Statistics;
2725
  friend std::ostream& operator<<(std::ostream& os, const Stat& sv);
2726
  /** Representation of a histogram: maps names to frequencies. */
2727
  using HistogramData = std::map<std::string, uint64_t>;
2728
  /** Can only be obtained from a `Statistics` object. */
2729
  Stat() = delete;
2730
  /** Copy constructor */
2731
  Stat(const Stat& s);
2732
  /** Destructor */
2733
  ~Stat();
2734
  /** Copy assignment */
2735
  Stat& operator=(const Stat& s);
2736
2737
  /**
2738
   * Is this value intended for experts only?
2739
   * @return Whether this is an expert statistic.
2740
   */
2741
  bool isExpert() const;
2742
  /**
2743
   * Does this value hold the default value?
2744
   * @return Whether this is a defaulted statistic.
2745
   */
2746
  bool isDefault() const;
2747
2748
  /**
2749
   * Is this value an integer?
2750
   * @return Whether the value is an integer.
2751
   */
2752
  bool isInt() const;
2753
  /**
2754
   * Return the integer value.
2755
   * @return The integer value.
2756
   */
2757
  int64_t getInt() const;
2758
  /**
2759
   * Is this value a double?
2760
   * @return Whether the value is a double.
2761
   */
2762
  bool isDouble() const;
2763
  /**
2764
   * Return the double value.
2765
   * @return The double value.
2766
   */
2767
  double getDouble() const;
2768
  /**
2769
   * Is this value a string?
2770
   * @return Whether the value is a string.
2771
   */
2772
  bool isString() const;
2773
  /**
2774
   * Return the string value.
2775
   * @return The string value.
2776
   */
2777
  const std::string& getString() const;
2778
  /**
2779
   * Is this value a histogram?
2780
   * @return Whether the value is a histogram.
2781
   */
2782
  bool isHistogram() const;
2783
  /**
2784
   * Return the histogram value.
2785
   * @return The histogram value.
2786
   */
2787
  const HistogramData& getHistogram() const;
2788
2789
 private:
2790
  Stat(bool expert, bool def, StatData&& sd);
2791
  /** Whether this statistic is only meant for experts */
2792
  bool d_expert;
2793
  /** Whether this statistic has the default value */
2794
  bool d_default;
2795
  std::unique_ptr<StatData> d_data;
2796
};
2797
2798
/**
2799
 * Print a `Stat` object to an ``std::ostream``.
2800
 */
2801
std::ostream& operator<<(std::ostream& os, const Stat& sv) CVC5_EXPORT;
2802
2803
/**
2804
 * Represents a snapshot of the solver statistics.
2805
 * Once obtained, an instance of this class is independent of the `Solver`
2806
 * object: it will not change when the solvers internal statistics do, it
2807
 * will not be invalidated if the solver is destroyed.
2808
 * Iterating on this class (via `begin()` and `end()`) shows only public
2809
 * statistics that have been changed. By passing appropriate flags to
2810
 * `begin()`, statistics that are expert, defaulted, or both, can be
2811
 * included as well. A single statistic value is represented as `Stat`.
2812
 */
2813
class CVC5_EXPORT Statistics
2814
{
2815
 public:
2816
  friend class Solver;
2817
  /** How the statistics are stored internally. */
2818
  using BaseType = std::map<std::string, Stat>;
2819
2820
  /** Custom iterator to hide certain statistics from regular iteration */
2821
  class iterator
2822
  {
2823
   public:
2824
    friend class Statistics;
2825
    BaseType::const_reference operator*() const;
2826
    BaseType::const_pointer operator->() const;
2827
    iterator& operator++();
2828
    iterator operator++(int);
2829
    iterator& operator--();
2830
    iterator operator--(int);
2831
    bool operator==(const iterator& rhs) const;
2832
    bool operator!=(const iterator& rhs) const;
2833
2834
   private:
2835
    iterator(BaseType::const_iterator it,
2836
             const BaseType& base,
2837
             bool expert,
2838
             bool defaulted);
2839
    bool isVisible() const;
2840
    BaseType::const_iterator d_it;
2841
    const BaseType* d_base;
2842
    bool d_showExpert = false;
2843
    bool d_showDefault = false;
2844
  };
2845
2846
  /**
2847
   * Retrieve the statistic with the given name.
2848
   * Asserts that a statistic with the given name actually exists and throws
2849
   * a `CVC5ApiRecoverableException` if it does not.
2850
   * @param name Name of the statistic.
2851
   * @return The statistic with the given name.
2852
   */
2853
  const Stat& get(const std::string& name);
2854
  /**
2855
   * Begin iteration over the statistics values.
2856
   * By default, only entries that are public (non-expert) and have been set
2857
   * are visible while the others are skipped.
2858
   * @param expert If set to true, expert statistics are shown as well.
2859
   * @param defaulted If set to true, defaulted statistics are shown as well.
2860
   */
2861
  iterator begin(bool expert = false, bool defaulted = false) const;
2862
  /** End iteration */
2863
  iterator end() const;
2864
2865
 private:
2866
  Statistics() = default;
2867
  Statistics(const StatisticsRegistry& reg);
2868
  /** Internal data */
2869
  BaseType d_stats;
2870
};
2871
std::ostream& operator<<(std::ostream& out,
2872
                         const Statistics& stats) CVC5_EXPORT;
2873
2874
/* -------------------------------------------------------------------------- */
2875
/* Solver                                                                     */
2876
/* -------------------------------------------------------------------------- */
2877
2878
/**
2879
 * A cvc5 solver.
2880
 */
2881
class CVC5_EXPORT Solver
2882
{
2883
  friend class Datatype;
2884
  friend class DatatypeDecl;
2885
  friend class DatatypeConstructor;
2886
  friend class DatatypeConstructorDecl;
2887
  friend class DatatypeSelector;
2888
  friend class DriverOptions;
2889
  friend class Grammar;
2890
  friend class Op;
2891
  friend class cvc5::Command;
2892
  friend class cvc5::main::CommandExecutor;
2893
  friend class Sort;
2894
  friend class Term;
2895
2896
 private:
2897
  /*
2898
   * Constructs a solver with the given original options. This should only be
2899
   * used internally when the Solver is reset.
2900
   */
2901
  Solver(std::unique_ptr<Options>&& original);
2902
2903
 public:
2904
  /* .................................................................... */
2905
  /* Constructors/Destructors                                             */
2906
  /* .................................................................... */
2907
2908
  /**
2909
   * Constructor.
2910
   * @return the Solver
2911
   */
2912
  Solver();
2913
2914
  /**
2915
   * Destructor.
2916
   */
2917
  ~Solver();
2918
2919
  /**
2920
   * Disallow copy/assignment.
2921
   */
2922
  Solver(const Solver&) = delete;
2923
  Solver& operator=(const Solver&) = delete;
2924
2925
  /* .................................................................... */
2926
  /* Sorts Handling                                                       */
2927
  /* .................................................................... */
2928
2929
  /**
2930
   * @return sort null
2931
   */
2932
  Sort getNullSort() const;
2933
2934
  /**
2935
   * @return sort Boolean
2936
   */
2937
  Sort getBooleanSort() const;
2938
2939
  /**
2940
   * @return sort Integer (in cvc5, Integer is a subtype of Real)
2941
   */
2942
  Sort getIntegerSort() const;
2943
2944
  /**
2945
   * @return sort Real
2946
   */
2947
  Sort getRealSort() const;
2948
2949
  /**
2950
   * @return sort RegExp
2951
   */
2952
  Sort getRegExpSort() const;
2953
2954
  /**
2955
   * @return sort RoundingMode
2956
   */
2957
  Sort getRoundingModeSort() const;
2958
2959
  /**
2960
   * @return sort String
2961
   */
2962
  Sort getStringSort() const;
2963
2964
  /**
2965
   * Create an array sort.
2966
   * @param indexSort the array index sort
2967
   * @param elemSort the array element sort
2968
   * @return the array sort
2969
   */
2970
  Sort mkArraySort(const Sort& indexSort, const Sort& elemSort) const;
2971
2972
  /**
2973
   * Create a bit-vector sort.
2974
   * @param size the bit-width of the bit-vector sort
2975
   * @return the bit-vector sort
2976
   */
2977
  Sort mkBitVectorSort(uint32_t size) const;
2978
2979
  /**
2980
   * Create a floating-point sort.
2981
   * @param exp the bit-width of the exponent of the floating-point sort.
2982
   * @param sig the bit-width of the significand of the floating-point sort.
2983
   */
2984
  Sort mkFloatingPointSort(uint32_t exp, uint32_t sig) const;
2985
2986
  /**
2987
   * Create a datatype sort.
2988
   * @param dtypedecl the datatype declaration from which the sort is created
2989
   * @return the datatype sort
2990
   */
2991
  Sort mkDatatypeSort(const DatatypeDecl& dtypedecl) const;
2992
2993
  /**
2994
   * Create a vector of datatype sorts. The names of the datatype declarations
2995
   * must be distinct.
2996
   *
2997
   * @param dtypedecls the datatype declarations from which the sort is created
2998
   * @return the datatype sorts
2999
   */
3000
  std::vector<Sort> mkDatatypeSorts(
3001
      const std::vector<DatatypeDecl>& dtypedecls) const;
3002
3003
  /**
3004
   * Create a vector of datatype sorts using unresolved sorts. The names of
3005
   * the datatype declarations in dtypedecls must be distinct.
3006
   *
3007
   * This method is called when the DatatypeDecl objects dtypedecls have been
3008
   * built using "unresolved" sorts.
3009
   *
3010
   * We associate each sort in unresolvedSorts with exacly one datatype from
3011
   * dtypedecls. In particular, it must have the same name as exactly one
3012
   * datatype declaration in dtypedecls.
3013
   *
3014
   * When constructing datatypes, unresolved sorts are replaced by the datatype
3015
   * sort constructed for the datatype declaration it is associated with.
3016
   *
3017
   * @param dtypedecls the datatype declarations from which the sort is created
3018
   * @param unresolvedSorts the list of unresolved sorts
3019
   * @return the datatype sorts
3020
   */
3021
  std::vector<Sort> mkDatatypeSorts(
3022
      const std::vector<DatatypeDecl>& dtypedecls,
3023
      const std::set<Sort>& unresolvedSorts) const;
3024
3025
  /**
3026
   * Create function sort.
3027
   * @param domain the sort of the fuction argument
3028
   * @param codomain the sort of the function return value
3029
   * @return the function sort
3030
   */
3031
  Sort mkFunctionSort(const Sort& domain, const Sort& codomain) const;
3032
3033
  /**
3034
   * Create function sort.
3035
   * @param sorts the sort of the function arguments
3036
   * @param codomain the sort of the function return value
3037
   * @return the function sort
3038
   */
3039
  Sort mkFunctionSort(const std::vector<Sort>& sorts,
3040
                      const Sort& codomain) const;
3041
3042
  /**
3043
   * Create a sort parameter.
3044
   * @param symbol the name of the sort
3045
   * @return the sort parameter
3046
   */
3047
  Sort mkParamSort(const std::string& symbol) const;
3048
3049
  /**
3050
   * Create a predicate sort.
3051
   * @param sorts the list of sorts of the predicate
3052
   * @return the predicate sort
3053
   */
3054
  Sort mkPredicateSort(const std::vector<Sort>& sorts) const;
3055
3056
  /**
3057
   * Create a record sort
3058
   * @param fields the list of fields of the record
3059
   * @return the record sort
3060
   */
3061
  Sort mkRecordSort(
3062
      const std::vector<std::pair<std::string, Sort>>& fields) const;
3063
3064
  /**
3065
   * Create a set sort.
3066
   * @param elemSort the sort of the set elements
3067
   * @return the set sort
3068
   */
3069
  Sort mkSetSort(const Sort& elemSort) const;
3070
3071
  /**
3072
   * Create a bag sort.
3073
   * @param elemSort the sort of the bag elements
3074
   * @return the bag sort
3075
   */
3076
  Sort mkBagSort(const Sort& elemSort) const;
3077
3078
  /**
3079
   * Create a sequence sort.
3080
   * @param elemSort the sort of the sequence elements
3081
   * @return the sequence sort
3082
   */
3083
  Sort mkSequenceSort(const Sort& elemSort) const;
3084
3085
  /**
3086
   * Create an uninterpreted sort.
3087
   * @param symbol the name of the sort
3088
   * @return the uninterpreted sort
3089
   */
3090
  Sort mkUninterpretedSort(const std::string& symbol) const;
3091
3092
  /**
3093
   * Create a sort constructor sort.
3094
   * @param symbol the symbol of the sort
3095
   * @param arity the arity of the sort
3096
   * @return the sort constructor sort
3097
   */
3098
  Sort mkSortConstructorSort(const std::string& symbol, size_t arity) const;
3099
3100
  /**
3101
   * Create a tuple sort.
3102
   * @param sorts of the elements of the tuple
3103
   * @return the tuple sort
3104
   */
3105
  Sort mkTupleSort(const std::vector<Sort>& sorts) const;
3106
3107
  /* .................................................................... */
3108
  /* Create Terms                                                         */
3109
  /* .................................................................... */
3110
3111
  /**
3112
   * Create 0-ary term of given kind.
3113
   * @param kind the kind of the term
3114
   * @return the Term
3115
   */
3116
  Term mkTerm(Kind kind) const;
3117
3118
  /**
3119
   * Create a unary term of given kind.
3120
   * @param kind the kind of the term
3121
   * @param child the child of the term
3122
   * @return the Term
3123
   */
3124
  Term mkTerm(Kind kind, const Term& child) const;
3125
3126
  /**
3127
   * Create binary term of given kind.
3128
   * @param kind the kind of the term
3129
   * @param child1 the first child of the term
3130
   * @param child2 the second child of the term
3131
   * @return the Term
3132
   */
3133
  Term mkTerm(Kind kind, const Term& child1, const Term& child2) const;
3134
3135
  /**
3136
   * Create ternary term of given kind.
3137
   * @param kind the kind of the term
3138
   * @param child1 the first child of the term
3139
   * @param child2 the second child of the term
3140
   * @param child3 the third child of the term
3141
   * @return the Term
3142
   */
3143
  Term mkTerm(Kind kind,
3144
              const Term& child1,
3145
              const Term& child2,
3146
              const Term& child3) const;
3147
3148
  /**
3149
   * Create n-ary term of given kind.
3150
   * @param kind the kind of the term
3151
   * @param children the children of the term
3152
   * @return the Term
3153
   */
3154
  Term mkTerm(Kind kind, const std::vector<Term>& children) const;
3155
3156
  /**
3157
   * Create nullary term of given kind from a given operator.
3158
   * Create operators with mkOp().
3159
   * @param op the operator
3160
   * @return the Term
3161
   */
3162
  Term mkTerm(const Op& op) const;
3163
3164
  /**
3165
   * Create unary term of given kind from a given operator.
3166
   * Create operators with mkOp().
3167
   * @param op the operator
3168
   * @param child the child of the term
3169
   * @return the Term
3170
   */
3171
  Term mkTerm(const Op& op, const Term& child) const;
3172
3173
  /**
3174
   * Create binary term of given kind from a given operator.
3175
   * Create operators with mkOp().
3176
   * @param op the operator
3177
   * @param child1 the first child of the term
3178
   * @param child2 the second child of the term
3179
   * @return the Term
3180
   */
3181
  Term mkTerm(const Op& op, const Term& child1, const Term& child2) const;
3182
3183
  /**
3184
   * Create ternary term of given kind from a given operator.
3185
   * Create operators with mkOp().
3186
   * @param op the operator
3187
   * @param child1 the first child of the term
3188
   * @param child2 the second child of the term
3189
   * @param child3 the third child of the term
3190
   * @return the Term
3191
   */
3192
  Term mkTerm(const Op& op,
3193
              const Term& child1,
3194
              const Term& child2,
3195
              const Term& child3) const;
3196
3197
  /**
3198
   * Create n-ary term of given kind from a given operator.
3199
   * Create operators with mkOp().
3200
   * @param op the operator
3201
   * @param children the children of the term
3202
   * @return the Term
3203
   */
3204
  Term mkTerm(const Op& op, const std::vector<Term>& children) const;
3205
3206
  /**
3207
   * Create a tuple term. Terms are automatically converted if sorts are
3208
   * compatible.
3209
   * @param sorts The sorts of the elements in the tuple
3210
   * @param terms The elements in the tuple
3211
   * @return the tuple Term
3212
   */
3213
  Term mkTuple(const std::vector<Sort>& sorts,
3214
               const std::vector<Term>& terms) const;
3215
3216
  /* .................................................................... */
3217
  /* Create Operators                                                     */
3218
  /* .................................................................... */
3219
3220
  /**
3221
   * Create an operator for a builtin Kind
3222
   * The Kind may not be the Kind for an indexed operator
3223
   *   (e.g. BITVECTOR_EXTRACT)
3224
   * Note: in this case, the Op simply wraps the Kind.
3225
   * The Kind can be used in mkTerm directly without
3226
   *   creating an op first.
3227
   * @param kind the kind to wrap
3228
   */
3229
  Op mkOp(Kind kind) const;
3230
3231
  /**
3232
   * Create operator of kind:
3233
   *   - DIVISIBLE (to support arbitrary precision integers)
3234
   * See enum Kind for a description of the parameters.
3235
   * @param kind the kind of the operator
3236
   * @param arg the string argument to this operator
3237
   */
3238
  Op mkOp(Kind kind, const std::string& arg) const;
3239
3240
  /**
3241
   * Create operator of kind:
3242
   *   - DIVISIBLE
3243
   *   - BITVECTOR_REPEAT
3244
   *   - BITVECTOR_ZERO_EXTEND
3245
   *   - BITVECTOR_SIGN_EXTEND
3246
   *   - BITVECTOR_ROTATE_LEFT
3247
   *   - BITVECTOR_ROTATE_RIGHT
3248
   *   - INT_TO_BITVECTOR
3249
   *   - FLOATINGPOINT_TO_UBV
3250
   *   - FLOATINGPOINT_TO_UBV_TOTAL
3251
   *   - FLOATINGPOINT_TO_SBV
3252
   *   - FLOATINGPOINT_TO_SBV_TOTAL
3253
   *   - TUPLE_UPDATE
3254
   * See enum Kind for a description of the parameters.
3255
   * @param kind the kind of the operator
3256
   * @param arg the uint32_t argument to this operator
3257
   */
3258
  Op mkOp(Kind kind, uint32_t arg) const;
3259
3260
  /**
3261
   * Create operator of Kind:
3262
   *   - BITVECTOR_EXTRACT
3263
   *   - FLOATINGPOINT_TO_FP_IEEE_BITVECTOR
3264
   *   - FLOATINGPOINT_TO_FP_FLOATINGPOINT
3265
   *   - FLOATINGPOINT_TO_FP_REAL
3266
   *   - FLOATINGPOINT_TO_FP_SIGNED_BITVECTOR
3267
   *   - FLOATINGPOINT_TO_FP_UNSIGNED_BITVECTOR
3268
   *   - FLOATINGPOINT_TO_FP_GENERIC
3269
   * See enum Kind for a description of the parameters.
3270
   * @param kind the kind of the operator
3271
   * @param arg1 the first uint32_t argument to this operator
3272
   * @param arg2 the second uint32_t argument to this operator
3273
   */
3274
  Op mkOp(Kind kind, uint32_t arg1, uint32_t arg2) const;
3275
3276
  /**
3277
   * Create operator of Kind:
3278
   *   - TUPLE_PROJECT
3279
   * See enum Kind for a description of the parameters.
3280
   * @param kind the kind of the operator
3281
   * @param args the arguments (indices) of the operator
3282
   */
3283
  Op mkOp(Kind kind, const std::vector<uint32_t>& args) const;
3284
3285
  /* .................................................................... */
3286
  /* Create Constants                                                     */
3287
  /* .................................................................... */
3288
3289
  /**
3290
   * Create a Boolean true constant.
3291
   * @return the true constant
3292
   */
3293
  Term mkTrue() const;
3294
3295
  /**
3296
   * Create a Boolean false constant.
3297
   * @return the false constant
3298
   */
3299
  Term mkFalse() const;
3300
3301
  /**
3302
   * Create a Boolean constant.
3303
   * @return the Boolean constant
3304
   * @param val the value of the constant
3305
   */
3306
  Term mkBoolean(bool val) const;
3307
3308
  /**
3309
   * Create a constant representing the number Pi.
3310
   * @return a constant representing Pi
3311
   */
3312
  Term mkPi() const;
3313
  /**
3314
   * Create an integer constant from a string.
3315
   * @param s the string representation of the constant, may represent an
3316
   *          integer (e.g., "123").
3317
   * @return a constant of sort Integer assuming 's' represents an integer)
3318
   */
3319
  Term mkInteger(const std::string& s) const;
3320
3321
  /**
3322
   * Create an integer constant from a c++ int.
3323
   * @param val the value of the constant
3324
   * @return a constant of sort Integer
3325
   */
3326
  Term mkInteger(int64_t val) const;
3327
3328
  /**
3329
   * Create a real constant from a string.
3330
   * @param s the string representation of the constant, may represent an
3331
   *          integer (e.g., "123") or real constant (e.g., "12.34" or "12/34").
3332
   * @return a constant of sort Real
3333
   */
3334
  Term mkReal(const std::string& s) const;
3335
3336
  /**
3337
   * Create a real constant from an integer.
3338
   * @param val the value of the constant
3339
   * @return a constant of sort Integer
3340
   */
3341
  Term mkReal(int64_t val) const;
3342
3343
  /**
3344
   * Create a real constant from a rational.
3345
   * @param num the value of the numerator
3346
   * @param den the value of the denominator
3347
   * @return a constant of sort Real
3348
   */
3349
  Term mkReal(int64_t num, int64_t den) const;
3350
3351
  /**
3352
   * Create a regular expression empty term.
3353
   * @return the empty term
3354
   */
3355
  Term mkRegexpEmpty() const;
3356
3357
  /**
3358
   * Create a regular expression sigma term.
3359
   * @return the sigma term
3360
   */
3361
  Term mkRegexpSigma() const;
3362
3363
  /**
3364
   * Create a constant representing an empty set of the given sort.
3365
   * @param sort the sort of the set elements.
3366
   * @return the empty set constant
3367
   */
3368
  Term mkEmptySet(const Sort& sort) const;
3369
3370
  /**
3371
   * Create a constant representing an empty bag of the given sort.
3372
   * @param sort the sort of the bag elements.
3373
   * @return the empty bag constant
3374
   */
3375
  Term mkEmptyBag(const Sort& sort) const;
3376
3377
  /**
3378
   * Create a separation logic nil term.
3379
   * @param sort the sort of the nil term
3380
   * @return the separation logic nil term
3381
   */
3382
  Term mkSepNil(const Sort& sort) const;
3383
3384
  /**
3385
   * Create a String constant from a `std::string` which may contain SMT-LIB
3386
   * compatible escape sequences like `\u1234` to encode unicode characters.
3387
   * @param s the string this constant represents
3388
   * @param useEscSequences determines whether escape sequences in `s` should
3389
   * be converted to the corresponding unicode character
3390
   * @return the String constant
3391
   */
3392
  Term mkString(const std::string& s, bool useEscSequences = false) const;
3393
3394
  /**
3395
   * Create a String constant from a `std::wstring`.
3396
   * This method does not support escape sequences as `std::wstring` already
3397
   * supports unicode characters.
3398
   * @param s the string this constant represents
3399
   * @return the String constant
3400
   */
3401
  Term mkString(const std::wstring& s) const;
3402
3403
  /**
3404
   * Create an empty sequence of the given element sort.
3405
   * @param sort The element sort of the sequence.
3406
   * @return the empty sequence with given element sort.
3407
   */
3408
  Term mkEmptySequence(const Sort& sort) const;
3409
3410
  /**
3411
   * Create a universe set of the given sort.
3412
   * @param sort the sort of the set elements
3413
   * @return the universe set constant
3414
   */
3415
  Term mkUniverseSet(const Sort& sort) const;
3416
3417
  /**
3418
   * Create a bit-vector constant of given size and value.
3419
   *
3420
   * Note: The given value must fit into a bit-vector of the given size.
3421
   *
3422
   * @param size the bit-width of the bit-vector sort
3423
   * @param val the value of the constant
3424
   * @return the bit-vector constant
3425
   */
3426
  Term mkBitVector(uint32_t size, uint64_t val = 0) const;
3427
3428
  /**
3429
   * Create a bit-vector constant of a given bit-width from a given string of
3430
   * base 2, 10 or 16.
3431
   *
3432
   * Note: The given value must fit into a bit-vector of the given size.
3433
   *
3434
   * @param size the bit-width of the constant
3435
   * @param s the string representation of the constant
3436
   * @param base the base of the string representation (2, 10, or 16)
3437
   * @return the bit-vector constant
3438
   */
3439
  Term mkBitVector(uint32_t size, const std::string& s, uint32_t base) const;
3440
3441
  /**
3442
   * Create a constant array with the provided constant value stored at every
3443
   * index
3444
   * @param sort the sort of the constant array (must be an array sort)
3445
   * @param val the constant value to store (must match the sort's element sort)
3446
   * @return the constant array term
3447
   */
3448
  Term mkConstArray(const Sort& sort, const Term& val) const;
3449
3450
  /**
3451
   * Create a positive infinity floating-point constant. Requires cvc5 to be
3452
   * compiled with SymFPU support.
3453
   * @param exp Number of bits in the exponent
3454
   * @param sig Number of bits in the significand
3455
   * @return the floating-point constant
3456
   */
3457
  Term mkPosInf(uint32_t exp, uint32_t sig) const;
3458
3459
  /**
3460
   * Create a negative infinity floating-point constant. Requires cvc5 to be
3461
   * compiled with SymFPU support.
3462
   * @param exp Number of bits in the exponent
3463
   * @param sig Number of bits in the significand
3464
   * @return the floating-point constant
3465
   */
3466
  Term mkNegInf(uint32_t exp, uint32_t sig) const;
3467
3468
  /**
3469
   * Create a not-a-number (NaN) floating-point constant. Requires cvc5 to be
3470
   * compiled with SymFPU support.
3471
   * @param exp Number of bits in the exponent
3472
   * @param sig Number of bits in the significand
3473
   * @return the floating-point constant
3474
   */
3475
  Term mkNaN(uint32_t exp, uint32_t sig) const;
3476
3477
  /**
3478
   * Create a positive zero (+0.0) floating-point constant. Requires cvc5 to be
3479
   * compiled with SymFPU support.
3480
   * @param exp Number of bits in the exponent
3481
   * @param sig Number of bits in the significand
3482
   * @return the floating-point constant
3483
   */
3484
  Term mkPosZero(uint32_t exp, uint32_t sig) const;
3485
3486
  /**
3487
   * Create a negative zero (-0.0) floating-point constant. Requires cvc5 to be
3488
   * compiled with SymFPU support.
3489
   * @param exp Number of bits in the exponent
3490
   * @param sig Number of bits in the significand
3491
   * @return the floating-point constant
3492
   */
3493
  Term mkNegZero(uint32_t exp, uint32_t sig) const;
3494
3495
  /**
3496
   * Create a roundingmode constant.
3497
   * @param rm the floating point rounding mode this constant represents
3498
   */
3499
  Term mkRoundingMode(RoundingMode rm) const;
3500
3501
  /**
3502
   * Create uninterpreted constant.
3503
   * @param sort Sort of the constant
3504
   * @param index Index of the constant
3505
   */
3506
  Term mkUninterpretedConst(const Sort& sort, int32_t index) const;
3507
3508
  /**
3509
   * Create an abstract value constant.
3510
   * The given index needs to be a positive integer in base 10.
3511
   * @param index Index of the abstract value
3512
   */
3513
  Term mkAbstractValue(const std::string& index) const;
3514
3515
  /**
3516
   * Create an abstract value constant.
3517
   * The given index needs to be positive.
3518
   * @param index Index of the abstract value
3519
   */
3520
  Term mkAbstractValue(uint64_t index) const;
3521
3522
  /**
3523
   * Create a floating-point constant (requires cvc5 to be compiled with symFPU
3524
   * support).
3525
   * @param exp Size of the exponent
3526
   * @param sig Size of the significand
3527
   * @param val Value of the floating-point constant as a bit-vector term
3528
   */
3529
  Term mkFloatingPoint(uint32_t exp, uint32_t sig, Term val) const;
3530
3531
  /* .................................................................... */
3532
  /* Create Variables                                                     */
3533
  /* .................................................................... */
3534
3535
  /**
3536
   * Create (first-order) constant (0-arity function symbol).
3537
   * SMT-LIB:
3538
   * \verbatim
3539
   *   ( declare-const <symbol> <sort> )
3540
   *   ( declare-fun <symbol> ( ) <sort> )
3541
   * \endverbatim
3542
   *
3543
   * @param sort the sort of the constant
3544
   * @param symbol the name of the constant
3545
   * @return the first-order constant
3546
   */
3547
  Term mkConst(const Sort& sort, const std::string& symbol) const;
3548
  /**
3549
   * Create (first-order) constant (0-arity function symbol), with a default
3550
   * symbol name.
3551
   *
3552
   * @param sort the sort of the constant
3553
   * @return the first-order constant
3554
   */
3555
  Term mkConst(const Sort& sort) const;
3556
3557
  /**
3558
   * Create a bound variable to be used in a binder (i.e. a quantifier, a
3559
   * lambda, or a witness binder).
3560
   * @param sort the sort of the variable
3561
   * @param symbol the name of the variable
3562
   * @return the variable
3563
   */
3564
  Term mkVar(const Sort& sort, const std::string& symbol = std::string()) const;
3565
3566
  /* .................................................................... */
3567
  /* Create datatype constructor declarations                             */
3568
  /* .................................................................... */
3569
3570
  DatatypeConstructorDecl mkDatatypeConstructorDecl(const std::string& name);
3571
3572
  /* .................................................................... */
3573
  /* Create datatype declarations                                         */
3574
  /* .................................................................... */
3575
3576
  /**
3577
   * Create a datatype declaration.
3578
   * @param name the name of the datatype
3579
   * @param isCoDatatype true if a codatatype is to be constructed
3580
   * @return the DatatypeDecl
3581
   */
3582
  DatatypeDecl mkDatatypeDecl(const std::string& name,
3583
                              bool isCoDatatype = false);
3584
3585
  /**
3586
   * Create a datatype declaration.
3587
   * Create sorts parameter with Solver::mkParamSort().
3588
   * @param name the name of the datatype
3589
   * @param param the sort parameter
3590
   * @param isCoDatatype true if a codatatype is to be constructed
3591
   * @return the DatatypeDecl
3592
   */
3593
  DatatypeDecl mkDatatypeDecl(const std::string& name,
3594
                              Sort param,
3595
                              bool isCoDatatype = false);
3596
3597
  /**
3598
   * Create a datatype declaration.
3599
   * Create sorts parameter with Solver::mkParamSort().
3600
   * @param name the name of the datatype
3601
   * @param params a list of sort parameters
3602
   * @param isCoDatatype true if a codatatype is to be constructed
3603
   * @return the DatatypeDecl
3604
   */
3605
  DatatypeDecl mkDatatypeDecl(const std::string& name,
3606
                              const std::vector<Sort>& params,
3607
                              bool isCoDatatype = false);
3608
3609
  /* .................................................................... */
3610
  /* Formula Handling                                                     */
3611
  /* .................................................................... */
3612
3613
  /**
3614
   * Simplify a formula without doing "much" work.  Does not involve
3615
   * the SAT Engine in the simplification, but uses the current
3616
   * definitions, assertions, and the current partial model, if one
3617
   * has been constructed.  It also involves theory normalization.
3618
   * @param t the formula to simplify
3619
   * @return the simplified formula
3620
   */
3621
  Term simplify(const Term& t);
3622
3623
  /**
3624
   * Assert a formula.
3625
   * SMT-LIB:
3626
   * \verbatim
3627
   *   ( assert <term> )
3628
   * \endverbatim
3629
   * @param term the formula to assert
3630
   */
3631
  void assertFormula(const Term& term) const;
3632
3633
  /**
3634
   * Check satisfiability.
3635
   * SMT-LIB:
3636
   * \verbatim
3637
   *   ( check-sat )
3638
   * \endverbatim
3639
   * @return the result of the satisfiability check.
3640
   */
3641
  Result checkSat() const;
3642
3643
  /**
3644
   * Check satisfiability assuming the given formula.
3645
   * SMT-LIB:
3646
   * \verbatim
3647
   *   ( check-sat-assuming ( <prop_literal> ) )
3648
   * \endverbatim
3649
   * @param assumption the formula to assume
3650
   * @return the result of the satisfiability check.
3651
   */
3652
  Result checkSatAssuming(const Term& assumption) const;
3653
3654
  /**
3655
   * Check satisfiability assuming the given formulas.
3656
   * SMT-LIB:
3657
   * \verbatim
3658
   *   ( check-sat-assuming ( <prop_literal>+ ) )
3659
   * \endverbatim
3660
   * @param assumptions the formulas to assume
3661
   * @return the result of the satisfiability check.
3662
   */
3663
  Result checkSatAssuming(const std::vector<Term>& assumptions) const;
3664
3665
  /**
3666
   * Check entailment of the given formula w.r.t. the current set of assertions.
3667
   * @param term the formula to check entailment for
3668
   * @return the result of the entailment check.
3669
   */
3670
  Result checkEntailed(const Term& term) const;
3671
3672
  /**
3673
   * Check entailment of the given set of given formulas w.r.t. the current
3674
   * set of assertions.
3675
   * @param terms the terms to check entailment for
3676
   * @return the result of the entailmentcheck.
3677
   */
3678
  Result checkEntailed(const std::vector<Term>& terms) const;
3679
3680
  /**
3681
   * Create datatype sort.
3682
   * SMT-LIB:
3683
   * \verbatim
3684
   *   ( declare-datatype <symbol> <datatype_decl> )
3685
   * \endverbatim
3686
   * @param symbol the name of the datatype sort
3687
   * @param ctors the constructor declarations of the datatype sort
3688
   * @return the datatype sort
3689
   */
3690
  Sort declareDatatype(const std::string& symbol,
3691
                       const std::vector<DatatypeConstructorDecl>& ctors) const;
3692
3693
  /**
3694
   * Declare n-ary function symbol.
3695
   * SMT-LIB:
3696
   * \verbatim
3697
   *   ( declare-fun <symbol> ( <sort>* ) <sort> )
3698
   * \endverbatim
3699
   * @param symbol the name of the function
3700
   * @param sorts the sorts of the parameters to this function
3701
   * @param sort the sort of the return value of this function
3702
   * @return the function
3703
   */
3704
  Term declareFun(const std::string& symbol,
3705
                  const std::vector<Sort>& sorts,
3706
                  const Sort& sort) const;
3707
3708
  /**
3709
   * Declare uninterpreted sort.
3710
   * SMT-LIB:
3711
   * \verbatim
3712
   *   ( declare-sort <symbol> <numeral> )
3713
   * \endverbatim
3714
   * @param symbol the name of the sort
3715
   * @param arity the arity of the sort
3716
   * @return the sort
3717
   */
3718
  Sort declareSort(const std::string& symbol, uint32_t arity) const;
3719
3720
  /**
3721
   * Define n-ary function.
3722
   * SMT-LIB:
3723
   * \verbatim
3724
   *   ( define-fun <function_def> )
3725
   * \endverbatim
3726
   * @param symbol the name of the function
3727
   * @param bound_vars the parameters to this function
3728
   * @param sort the sort of the return value of this function
3729
   * @param term the function body
3730
   * @param global determines whether this definition is global (i.e. persists
3731
   *               when popping the context)
3732
   * @return the function
3733
   */
3734
  Term defineFun(const std::string& symbol,
3735
                 const std::vector<Term>& bound_vars,
3736
                 const Sort& sort,
3737
                 const Term& term,
3738
                 bool global = false) const;
3739
  /**
3740
   * Define n-ary function.
3741
   * SMT-LIB:
3742
   * \verbatim
3743
   * ( define-fun <function_def> )
3744
   * \endverbatim
3745
   * Create parameter 'fun' with mkConst().
3746
   * @param fun the sorted function
3747
   * @param bound_vars the parameters to this function
3748
   * @param term the function body
3749
   * @param global determines whether this definition is global (i.e. persists
3750
   *               when popping the context)
3751
   * @return the function
3752
   */
3753
  Term defineFun(const Term& fun,
3754
                 const std::vector<Term>& bound_vars,
3755
                 const Term& term,
3756
                 bool global = false) const;
3757
3758
  /**
3759
   * Define recursive function.
3760
   * SMT-LIB:
3761
   * \verbatim
3762
   * ( define-fun-rec <function_def> )
3763
   * \endverbatim
3764
   * @param symbol the name of the function
3765
   * @param bound_vars the parameters to this function
3766
   * @param sort the sort of the return value of this function
3767
   * @param term the function body
3768
   * @param global determines whether this definition is global (i.e. persists
3769
   *               when popping the context)
3770
   * @return the function
3771
   */
3772
  Term defineFunRec(const std::string& symbol,
3773
                    const std::vector<Term>& bound_vars,
3774
                    const Sort& sort,
3775
                    const Term& term,
3776
                    bool global = false) const;
3777
3778
  /**
3779
   * Define recursive function.
3780
   * SMT-LIB:
3781
   * \verbatim
3782
   * ( define-fun-rec <function_def> )
3783
   * \endverbatim
3784
   * Create parameter 'fun' with mkConst().
3785
   * @param fun the sorted function
3786
   * @param bound_vars the parameters to this function
3787
   * @param term the function body
3788
   * @param global determines whether this definition is global (i.e. persists
3789
   *               when popping the context)
3790
   * @return the function
3791
   */
3792
  Term defineFunRec(const Term& fun,
3793
                    const std::vector<Term>& bound_vars,
3794
                    const Term& term,
3795
                    bool global = false) const;
3796
3797
  /**
3798
   * Define recursive functions.
3799
   * SMT-LIB:
3800
   * \verbatim
3801
   *   ( define-funs-rec ( <function_decl>^{n+1} ) ( <term>^{n+1} ) )
3802
   * \endverbatim
3803
   * Create elements of parameter 'funs' with mkConst().
3804
   * @param funs the sorted functions
3805
   * @param bound_vars the list of parameters to the functions
3806
   * @param terms the list of function bodies of the functions
3807
   * @param global determines whether this definition is global (i.e. persists
3808
   *               when popping the context)
3809
   * @return the function
3810
   */
3811
  void defineFunsRec(const std::vector<Term>& funs,
3812
                     const std::vector<std::vector<Term>>& bound_vars,
3813
                     const std::vector<Term>& terms,
3814
                     bool global = false) const;
3815
3816
  /**
3817
   * Echo a given string to the given output stream.
3818
   * SMT-LIB:
3819
   * \verbatim
3820
   * ( echo <std::string> )
3821
   * \endverbatim
3822
   * @param out the output stream
3823
   * @param str the string to echo
3824
   */
3825
  void echo(std::ostream& out, const std::string& str) const;
3826
3827
  /**
3828
   * Get the list of asserted formulas.
3829
   * SMT-LIB:
3830
   * \verbatim
3831
   * ( get-assertions )
3832
   * \endverbatim
3833
   * @return the list of asserted formulas
3834
   */
3835
  std::vector<Term> getAssertions() const;
3836
3837
  /**
3838
   * Get info from the solver.
3839
   * SMT-LIB: \verbatim( get-info <info_flag> )\verbatim
3840
   * @return the info
3841
   */
3842
  std::string getInfo(const std::string& flag) const;
3843
3844
  /**
3845
   * Get the value of a given option.
3846
   * SMT-LIB:
3847
   * \verbatim
3848
   * ( get-option <keyword> )
3849
   * \endverbatim
3850
   * @param option the option for which the value is queried
3851
   * @return a string representation of the option value
3852
   */
3853
  std::string getOption(const std::string& option) const;
3854
3855
  /**
3856
   * Get all option names that can be used with `setOption`, `getOption` and
3857
   * `getOptionInfo`.
3858
   * @return all option names
3859
   */
3860
  std::vector<std::string> getOptionNames() const;
3861
3862
  /**
3863
   * Get some information about the given option. Check the `OptionInfo` class
3864
   * for more details on which information is available.
3865
   * @return information about the given option
3866
   */
3867
  OptionInfo getOptionInfo(const std::string& option) const;
3868
3869
  /**
3870
   * Get the driver options, which provide access to options that can not be
3871
   * communicated properly via getOption() and getOptionInfo().
3872
   * @return a DriverOptions object.
3873
   */
3874
  DriverOptions getDriverOptions() const;
3875
3876
  /**
3877
   * Get the set of unsat ("failed") assumptions.
3878
   * SMT-LIB:
3879
   * \verbatim
3880
   * ( get-unsat-assumptions )
3881
   * \endverbatim
3882
   * Requires to enable option 'produce-unsat-assumptions'.
3883
   * @return the set of unsat assumptions.
3884
   */
3885
  std::vector<Term> getUnsatAssumptions() const;
3886
3887
  /**
3888
   * Get the unsatisfiable core.
3889
   * SMT-LIB:
3890
   * \verbatim
3891
   * ( get-unsat-core )
3892
   * \endverbatim
3893
   * Requires to enable option 'produce-unsat-cores'.
3894
   * @return a set of terms representing the unsatisfiable core
3895
   */
3896
  std::vector<Term> getUnsatCore() const;
3897
3898
  /**
3899
   * Get a difficulty estimate for an asserted formula. This method is
3900
   * intended to be called immediately after any response to a checkSat.
3901
   *
3902
   * @return a map from (a subset of) the input assertions to a real value that
3903
   * is an estimate of how difficult each assertion was to solve. Unmentioned
3904
   * assertions can be assumed to have zero difficulty.
3905
   */
3906
  std::map<Term, Term> getDifficulty() const;
3907
3908
  /**
3909
   * Get the refutation proof
3910
   * SMT-LIB:
3911
   * \verbatim
3912
   * ( get-proof )
3913
   * \endverbatim
3914
   * Requires to enable option 'produce-proofs'.
3915
   * @return a string representing the proof, according to the the value of
3916
   * proof-format-mode.
3917
   */
3918
  std::string getProof() const;
3919
3920
  /**
3921
   * Get the value of the given term in the current model.
3922
   * SMT-LIB:
3923
   * \verbatim
3924
   * ( get-value ( <term> ) )
3925
   * \endverbatim
3926
   * @param term the term for which the value is queried
3927
   * @return the value of the given term
3928
   */
3929
  Term getValue(const Term& term) const;
3930
3931
  /**
3932
   * Get the values of the given terms in the current model.
3933
   * SMT-LIB:
3934
   * \verbatim
3935
   * ( get-value ( <term>+ ) )
3936
   * \endverbatim
3937
   * @param terms the terms for which the value is queried
3938
   * @return the values of the given terms
3939
   */
3940
  std::vector<Term> getValue(const std::vector<Term>& terms) const;
3941
3942
  /**
3943
   * Get the domain elements of uninterpreted sort s in the current model. The
3944
   * current model interprets s as the finite sort whose domain elements are
3945
   * given in the return value of this method.
3946
   *
3947
   * @param s The uninterpreted sort in question
3948
   * @return the domain elements of s in the current model
3949
   */
3950
  std::vector<Term> getModelDomainElements(const Sort& s) const;
3951
3952
  /**
3953
   * This returns false if the model value of free constant v was not essential
3954
   * for showing the satisfiability of the last call to checkSat using the
3955
   * current model. This method will only return false (for any v) if
3956
   * the model-cores option has been set.
3957
   *
3958
   * @param v The term in question
3959
   * @return true if v is a model core symbol
3960
   */
3961
  bool isModelCoreSymbol(const Term& v) const;
3962
3963
  /**
3964
   * Get the model
3965
   * SMT-LIB:
3966
   * \verbatim
3967
   * ( get-model )
3968
   * \endverbatim
3969
   * Requires to enable option 'produce-models'.
3970
   * @param sorts The list of uninterpreted sorts that should be printed in the
3971
   * model.
3972
   * @param vars The list of free constants that should be printed in the
3973
   * model. A subset of these may be printed based on isModelCoreSymbol.
3974
   * @return a string representing the model.
3975
   */
3976
  std::string getModel(const std::vector<Sort>& sorts,
3977
                       const std::vector<Term>& vars) const;
3978
3979
  /**
3980
   * Do quantifier elimination.
3981
   * SMT-LIB:
3982
   * \verbatim
3983
   * ( get-qe <q> )
3984
   * \endverbatim
3985
   * Requires a logic that supports quantifier elimination. Currently, the only
3986
   * logics supported by quantifier elimination is LRA and LIA.
3987
   * @param q a quantified formula of the form:
3988
   *   Q x1...xn. P( x1...xn, y1...yn )
3989
   * where P( x1...xn, y1...yn ) is a quantifier-free formula
3990
   * @return a formula ret such that, given the current set of formulas A
3991
   * asserted to this solver:
3992
   *   - ( A ^ q ) and ( A ^ ret ) are equivalent
3993
   *   - ret is quantifier-free formula containing only free variables in
3994
   *     y1...yn.
3995
   */
3996
  Term getQuantifierElimination(const Term& q) const;
3997
3998
  /**
3999
   * Do partial quantifier elimination, which can be used for incrementally
4000
   * computing the result of a quantifier elimination.
4001
   * SMT-LIB:
4002
   * \verbatim
4003
   * ( get-qe-disjunct <q> )
4004
   * \endverbatim
4005
   * Requires a logic that supports quantifier elimination. Currently, the only
4006
   * logics supported by quantifier elimination is LRA and LIA.
4007
   * @param q a quantified formula of the form:
4008
   *   Q x1...xn. P( x1...xn, y1...yn )
4009
   * where P( x1...xn, y1...yn ) is a quantifier-free formula
4010
   * @return a formula ret such that, given the current set of formulas A
4011
   * asserted to this solver:
4012
   *   - (A ^ q) => (A ^ ret) if Q is forall or (A ^ ret) => (A ^ q) if Q is
4013
   *     exists,
4014
   *   - ret is quantifier-free formula containing only free variables in
4015
   *     y1...yn,
4016
   *   - If Q is exists, let A^Q_n be the formula
4017
   *       A ^ ~ret^Q_1 ^ ... ^ ~ret^Q_n
4018
   *     where for each i=1,...n, formula ret^Q_i is the result of calling
4019
   *     getQuantifierEliminationDisjunct for q with the set of assertions
4020
   *     A^Q_{i-1}. Similarly, if Q is forall, then let A^Q_n be
4021
   *       A ^ ret^Q_1 ^ ... ^ ret^Q_n
4022
   *     where ret^Q_i is the same as above. In either case, we have
4023
   *     that ret^Q_j will eventually be true or false, for some finite j.
4024
   */
4025
  Term getQuantifierEliminationDisjunct(const Term& q) const;
4026
4027
  /**
4028
   * When using separation logic, this sets the location sort and the
4029
   * datatype sort to the given ones. This method should be invoked exactly
4030
   * once, before any separation logic constraints are provided.
4031
   * @param locSort The location sort of the heap
4032
   * @param dataSort The data sort of the heap
4033
   */
4034
  void declareSeparationHeap(const Sort& locSort, const Sort& dataSort) const;
4035
4036
  /**
4037
   * When using separation logic, obtain the term for the heap.
4038
   * @return The term for the heap
4039
   */
4040
  Term getSeparationHeap() const;
4041
4042
  /**
4043
   * When using separation logic, obtain the term for nil.
4044
   * @return The term for nil
4045
   */
4046
  Term getSeparationNilTerm() const;
4047
4048
  /**
4049
   * Declare a symbolic pool of terms with the given initial value.
4050
   * SMT-LIB:
4051
   * \verbatim
4052
   * ( declare-pool <symbol> <sort> ( <term>* ) )
4053
   * \endverbatim
4054
   * @param symbol The name of the pool
4055
   * @param sort The sort of the elements of the pool.
4056
   * @param initValue The initial value of the pool
4057
   */
4058
  Term declarePool(const std::string& symbol,
4059
                   const Sort& sort,
4060
                   const std::vector<Term>& initValue) const;
4061
  /**
4062
   * Pop (a) level(s) from the assertion stack.
4063
   * SMT-LIB:
4064
   * \verbatim
4065
   * ( pop <numeral> )
4066
   * \endverbatim
4067
   * @param nscopes the number of levels to pop
4068
   */
4069
  void pop(uint32_t nscopes = 1) const;
4070
4071
  /**
4072
   * Get an interpolant
4073
   * SMT-LIB:
4074
   * \verbatim
4075
   * ( get-interpol <conj> )
4076
   * \endverbatim
4077
   * Requires to enable option 'produce-interpols'.
4078
   * @param conj the conjecture term
4079
   * @param output a Term I such that A->I and I->B are valid, where A is the
4080
   *        current set of assertions and B is given in the input by conj.
4081
   * @return true if it gets I successfully, false otherwise.
4082
   */
4083
  bool getInterpolant(const Term& conj, Term& output) const;
4084
4085
  /**
4086
   * Get an interpolant
4087
   * SMT-LIB:
4088
   * \verbatim
4089
   * ( get-interpol <conj> <g> )
4090
   * \endverbatim
4091
   * Requires to enable option 'produce-interpols'.
4092
   * @param conj the conjecture term
4093
   * @param grammar the grammar for the interpolant I
4094
   * @param output a Term I such that A->I and I->B are valid, where A is the
4095
   *        current set of assertions and B is given in the input by conj.
4096
   * @return true if it gets I successfully, false otherwise.
4097
   */
4098
  bool getInterpolant(const Term& conj, Grammar& grammar, Term& output) const;
4099
4100
  /**
4101
   * Get an abduct.
4102
   * SMT-LIB:
4103
   * \verbatim
4104
   * ( get-abduct <conj> )
4105
   * \endverbatim
4106
   * Requires enabling option 'produce-abducts'
4107
   * @param conj the conjecture term
4108
   * @param output a term C such that A^C is satisfiable, and A^~B^C is
4109
   *        unsatisfiable, where A is the current set of assertions and B is
4110
   *        given in the input by conj
4111
   * @return true if it gets C successfully, false otherwise
4112
   */
4113
  bool getAbduct(const Term& conj, Term& output) const;
4114
4115
  /**
4116
   * Get an abduct.
4117
   * SMT-LIB:
4118
   * \verbatim
4119
   * ( get-abduct <conj> <g> )
4120
   * \endverbatim
4121
   * Requires enabling option 'produce-abducts'
4122
   * @param conj the conjecture term
4123
   * @param grammar the grammar for the abduct C
4124
   * @param output a term C such that A^C is satisfiable, and A^~B^C is
4125
   *        unsatisfiable, where A is the current set of assertions and B is
4126
   *        given in the input by conj
4127
   * @return true if it gets C successfully, false otherwise
4128
   */
4129
  bool getAbduct(const Term& conj, Grammar& grammar, Term& output) const;
4130
4131
  /**
4132
   * Block the current model. Can be called only if immediately preceded by a
4133
   * SAT or INVALID query.
4134
   * SMT-LIB:
4135
   * \verbatim
4136
   * ( block-model )
4137
   * \endverbatim
4138
   * Requires enabling 'produce-models' option and setting 'block-models' option
4139
   * to a mode other than "none".
4140
   */
4141
  void blockModel() const;
4142
4143
  /**
4144
   * Block the current model values of (at least) the values in terms. Can be
4145
   * called only if immediately preceded by a SAT or NOT_ENTAILED query.
4146
   * SMT-LIB:
4147
   * \verbatim
4148
   * ( block-model-values ( <terms>+ ) )
4149
   * \endverbatim
4150
   * Requires enabling 'produce-models' option and setting 'block-models' option
4151
   * to a mode other than "none".
4152
   */
4153
  void blockModelValues(const std::vector<Term>& terms) const;
4154
4155
  /**
4156
   * Print all instantiations made by the quantifiers module.
4157
   * @param out the output stream
4158
   */
4159
  void printInstantiations(std::ostream& out) const;
4160
4161
  /**
4162
   * Push (a) level(s) to the assertion stack.
4163
   * SMT-LIB:
4164
   * \verbatim
4165
   * ( push <numeral> )
4166
   * \endverbatim
4167
   * @param nscopes the number of levels to push
4168
   */
4169
  void push(uint32_t nscopes = 1) const;
4170
4171
  /**
4172
   * Remove all assertions.
4173
   * SMT-LIB:
4174
   * \verbatim
4175
   * ( reset-assertions )
4176
   * \endverbatim
4177
   */
4178
  void resetAssertions() const;
4179
4180
  /**
4181
   * Set info.
4182
   * SMT-LIB:
4183
   * \verbatim
4184
   * ( set-info <attribute> )
4185
   * \endverbatim
4186
   * @param keyword the info flag
4187
   * @param value the value of the info flag
4188
   */
4189
  void setInfo(const std::string& keyword, const std::string& value) const;
4190
4191
  /**
4192
   * Set logic.
4193
   * SMT-LIB:
4194
   * \verbatim
4195
   * ( set-logic <symbol> )
4196
   * \endverbatim
4197
   * @param logic the logic to set
4198
   */
4199
  void setLogic(const std::string& logic) const;
4200
4201
  /**
4202
   * Set option.
4203
   * SMT-LIB:
4204
   * \verbatim
4205
   *   ( set-option <option> )
4206
   * \endverbatim
4207
   * @param option the option name
4208
   * @param value the option value
4209
   */
4210
  void setOption(const std::string& option, const std::string& value) const;
4211
4212
  /**
4213
   * If needed, convert this term to a given sort. Note that the sort of the
4214
   * term must be convertible into the target sort. Currently only Int to Real
4215
   * conversions are supported.
4216
   * @param t the term
4217
   * @param s the target sort
4218
   * @return the term wrapped into a sort conversion if needed
4219
   */
4220
  Term ensureTermSort(const Term& t, const Sort& s) const;
4221
4222
  /**
4223
   * Append \p symbol to the current list of universal variables.
4224
   * SyGuS v2:
4225
   * \verbatim
4226
   *   ( declare-var <symbol> <sort> )
4227
   * \endverbatim
4228
   * @param sort the sort of the universal variable
4229
   * @param symbol the name of the universal variable
4230
   * @return the universal variable
4231
   */
4232
  Term mkSygusVar(const Sort& sort,
4233
                  const std::string& symbol = std::string()) const;
4234
4235
  /**
4236
   * Create a Sygus grammar. The first non-terminal is treated as the starting
4237
   * non-terminal, so the order of non-terminals matters.
4238
   *
4239
   * @param boundVars the parameters to corresponding synth-fun/synth-inv
4240
   * @param ntSymbols the pre-declaration of the non-terminal symbols
4241
   * @return the grammar
4242
   */
4243
  Grammar mkSygusGrammar(const std::vector<Term>& boundVars,
4244
                         const std::vector<Term>& ntSymbols) const;
4245
4246
  /**
4247
   * Synthesize n-ary function.
4248
   * SyGuS v2:
4249
   * \verbatim
4250
   *   ( synth-fun <symbol> ( <boundVars>* ) <sort> )
4251
   * \endverbatim
4252
   * @param symbol the name of the function
4253
   * @param boundVars the parameters to this function
4254
   * @param sort the sort of the return value of this function
4255
   * @return the function
4256
   */
4257
  Term synthFun(const std::string& symbol,
4258
                const std::vector<Term>& boundVars,
4259
                const Sort& sort) const;
4260
4261
  /**
4262
   * Synthesize n-ary function following specified syntactic constraints.
4263
   * SyGuS v2:
4264
   * \verbatim
4265
   *   ( synth-fun <symbol> ( <boundVars>* ) <sort> <g> )
4266
   * \endverbatim
4267
   * @param symbol the name of the function
4268
   * @param boundVars the parameters to this function
4269
   * @param sort the sort of the return value of this function
4270
   * @param grammar the syntactic constraints
4271
   * @return the function
4272
   */
4273
  Term synthFun(const std::string& symbol,
4274
                const std::vector<Term>& boundVars,
4275
                Sort sort,
4276
                Grammar& grammar) const;
4277
4278
  /**
4279
   * Synthesize invariant.
4280
   * SyGuS v2:
4281
   * \verbatim
4282
   *   ( synth-inv <symbol> ( <boundVars>* ) )
4283
   * \endverbatim
4284
   * @param symbol the name of the invariant
4285
   * @param boundVars the parameters to this invariant
4286
   * @return the invariant
4287
   */
4288
  Term synthInv(const std::string& symbol,
4289
                const std::vector<Term>& boundVars) const;
4290
4291
  /**
4292
   * Synthesize invariant following specified syntactic constraints.
4293
   * SyGuS v2:
4294
   * \verbatim
4295
   *   ( synth-inv <symbol> ( <boundVars>* ) <g> )
4296
   * \endverbatim
4297
   * @param symbol the name of the invariant
4298
   * @param boundVars the parameters to this invariant
4299
   * @param grammar the syntactic constraints
4300
   * @return the invariant
4301
   */
4302
  Term synthInv(const std::string& symbol,
4303
                const std::vector<Term>& boundVars,
4304
                Grammar& grammar) const;
4305
4306
  /**
4307
   * Add a forumla to the set of Sygus constraints.
4308
   * SyGuS v2:
4309
   * \verbatim
4310
   *   ( constraint <term> )
4311
   * \endverbatim
4312
   * @param term the formula to add as a constraint
4313
   */
4314
  void addSygusConstraint(const Term& term) const;
4315
4316
  /**
4317
   * Add a forumla to the set of Sygus assumptions.
4318
   * SyGuS v2:
4319
   * \verbatim
4320
   *   ( assume <term> )
4321
   * \endverbatim
4322
   * @param term the formula to add as an assumption
4323
   */
4324
  void addSygusAssume(const Term& term) const;
4325
4326
  /**
4327
   * Add a set of Sygus constraints to the current state that correspond to an
4328
   * invariant synthesis problem.
4329
   * SyGuS v2:
4330
   * \verbatim
4331
   *   ( inv-constraint <inv> <pre> <trans> <post> )
4332
   * \endverbatim
4333
   * @param inv the function-to-synthesize
4334
   * @param pre the pre-condition
4335
   * @param trans the transition relation
4336
   * @param post the post-condition
4337
   */
4338
  void addSygusInvConstraint(Term inv, Term pre, Term trans, Term post) const;
4339
4340
  /**
4341
   * Try to find a solution for the synthesis conjecture corresponding to the
4342
   * current list of functions-to-synthesize, universal variables and
4343
   * constraints.
4344
   * SyGuS v2:
4345
   * \verbatim
4346
   *   ( check-synth )
4347
   * \endverbatim
4348
   * @return the result of the synthesis conjecture.
4349
   */
4350
  Result checkSynth() const;
4351
4352
  /**
4353
   * Get the synthesis solution of the given term. This method should be called
4354
   * immediately after the solver answers unsat for sygus input.
4355
   * @param term the term for which the synthesis solution is queried
4356
   * @return the synthesis solution of the given term
4357
   */
4358
  Term getSynthSolution(Term term) const;
4359
4360
  /**
4361
   * Get the synthesis solutions of the given terms. This method should be
4362
   * called immediately after the solver answers unsat for sygus input.
4363
   * @param terms the terms for which the synthesis solutions is queried
4364
   * @return the synthesis solutions of the given terms
4365
   */
4366
  std::vector<Term> getSynthSolutions(const std::vector<Term>& terms) const;
4367
4368
  /**
4369
   * Returns a snapshot of the current state of the statistic values of this
4370
   * solver. The returned object is completely decoupled from the solver and
4371
   * will not change when the solver is used again.
4372
   */
4373
  Statistics getStatistics() const;
4374
4375
  /**
4376
   * Whether the output stream for the given tag is enabled. Tags can be enabled
4377
   * with the `output` option (and `-o <tag>` on the command line). Raises an
4378
   * exception when an invalid tag is given.
4379
   */
4380
  bool isOutputOn(const std::string& tag) const;
4381
4382
  /**
4383
   * Returns an output stream for the given tag. Tags can be enabled with the
4384
   * `output` option (and `-o <tag>` on the command line). Raises an exception
4385
   * when an invalid tag is given.
4386
   */
4387
  std::ostream& getOutput(const std::string& tag) const;
4388
4389
 private:
4390
  /** @return the node manager of this solver */
4391
  NodeManager* getNodeManager(void) const;
4392
  /** Reset the API statistics */
4393
  void resetStatistics();
4394
4395
  /**
4396
   * Print the statistics to the given file descriptor, suitable for usage in
4397
   * signal handlers.
4398
   */
4399
  void printStatisticsSafe(int fd) const;
4400
4401
  /** Helper to check for API misuse in mkOp functions. */
4402
  void checkMkTerm(Kind kind, uint32_t nchildren) const;
4403
  /** Helper for mk-functions that call d_nodeMgr->mkConst(). */
4404
  template <typename T>
4405
  Term mkValHelper(T t) const;
4406
  /** Helper for mkReal functions that take a string as argument. */
4407
  Term mkRealFromStrHelper(const std::string& s) const;
4408
  /** Helper for mkBitVector functions that take a string as argument. */
4409
  Term mkBVFromStrHelper(const std::string& s, uint32_t base) const;
4410
  /**
4411
   * Helper for mkBitVector functions that take a string and a size as
4412
   * arguments.
4413
   */
4414
  Term mkBVFromStrHelper(uint32_t size,
4415
                         const std::string& s,
4416
                         uint32_t base) const;
4417
  /** Helper for mkBitVector functions that take an integer as argument. */
4418
  Term mkBVFromIntHelper(uint32_t size, uint64_t val) const;
4419
  /** Helper for functions that create tuple sorts. */
4420
  Sort mkTupleSortHelper(const std::vector<Sort>& sorts) const;
4421
  /** Helper for mkTerm functions that create Term from a Kind */
4422
  Term mkTermFromKind(Kind kind) const;
4423
  /** Helper for mkChar functions that take a string as argument. */
4424
  Term mkCharFromStrHelper(const std::string& s) const;
4425
  /** Get value helper, which accounts for subtyping */
4426
  Term getValueHelper(const Term& term) const;
4427
4428
  /**
4429
   * Helper function that ensures that a given term is of sort real (as opposed
4430
   * to being of sort integer).
4431
   * @param t a term of sort integer or real
4432
   * @return a term of sort real
4433
   */
4434
  Term ensureRealSort(const Term& t) const;
4435
4436
  /**
4437
   * Create n-ary term of given kind. This handles the cases of left/right
4438
   * associative operators, chainable operators, and cases when the number of
4439
   * children exceeds the maximum arity for the kind.
4440
   * @param kind the kind of the term
4441
   * @param children the children of the term
4442
   * @return the Term
4443
   */
4444
  Term mkTermHelper(Kind kind, const std::vector<Term>& children) const;
4445
4446
  /**
4447
   * Create n-ary term of given kind from a given operator.
4448
   * @param op the operator
4449
   * @param children the children of the term
4450
   * @return the Term
4451
   */
4452
  Term mkTermHelper(const Op& op, const std::vector<Term>& children) const;
4453
4454
  /**
4455
   * Create a vector of datatype sorts, using unresolved sorts.
4456
   * @param dtypedecls the datatype declarations from which the sort is created
4457
   * @param unresolvedSorts the list of unresolved sorts
4458
   * @return the datatype sorts
4459
   */
4460
  std::vector<Sort> mkDatatypeSortsInternal(
4461
      const std::vector<DatatypeDecl>& dtypedecls,
4462
      const std::set<Sort>& unresolvedSorts) const;
4463
4464
  /**
4465
   * Synthesize n-ary function following specified syntactic constraints.
4466
   * SMT-LIB:
4467
   * \verbatim
4468
   *   ( synth-fun <symbol> ( <boundVars>* ) <sort> <g>? )
4469
   * \endverbatim
4470
   * @param symbol the name of the function
4471
   * @param boundVars the parameters to this function
4472
   * @param sort the sort of the return value of this function
4473
   * @param isInv determines whether this is synth-fun or synth-inv
4474
   * @param grammar the syntactic constraints
4475
   * @return the function
4476
   */
4477
  Term synthFunHelper(const std::string& symbol,
4478
                      const std::vector<Term>& boundVars,
4479
                      const Sort& sort,
4480
                      bool isInv = false,
4481
                      Grammar* grammar = nullptr) const;
4482
4483
  /** Check whether string s is a valid decimal integer. */
4484
  bool isValidInteger(const std::string& s) const;
4485
4486
  /** Increment the term stats counter. */
4487
  void increment_term_stats(Kind kind) const;
4488
  /** Increment the vars stats (if 'is_var') or consts stats counter. */
4489
  void increment_vars_consts_stats(const Sort& sort, bool is_var) const;
4490
4491
  /** Keep a copy of the original option settings (for resets). */
4492
  std::unique_ptr<Options> d_originalOptions;
4493
  /** The node manager of this solver. */
4494
  NodeManager* d_nodeMgr;
4495
  /** The statistics collected on the Api level. */
4496
  std::unique_ptr<APIStatistics> d_stats;
4497
  /** The SMT engine of this solver. */
4498
  std::unique_ptr<SmtEngine> d_smtEngine;
4499
  /** The random number generator of this solver. */
4500
  std::unique_ptr<Random> d_rng;
4501
};
4502
4503
}  // namespace cvc5::api
4504
4505
#endif