-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcvc5.lean
More file actions
3039 lines (2059 loc) · 96.1 KB
/
cvc5.lean
File metadata and controls
3039 lines (2059 loc) · 96.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
995
996
997
998
999
1000
/-
Copyright (c) 2023-2024 by the authors listed in the file AUTHORS and their
institutional affiliations. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Abdalrhman Mohamed, Adrien Champion
-/
import cvc5.Init
import cvc5.Kind
import cvc5.ProofRule
import cvc5.SkolemId
import cvc5.Types
@[export prod_mk_generic]
private def mkProd := @Prod.mk
namespace cvc5
namespace Kind
/-- Produces a string representation. -/
@[extern "kind_toString"]
protected opaque toString : Kind → String
instance : ToString Kind := ⟨Kind.toString⟩
/-- Produces a hash. -/
@[extern "kind_hash"]
protected opaque hash : Kind → UInt64
instance : Hashable Kind := ⟨Kind.hash⟩
end Kind
namespace SortKind
/-- Produces a string representation. -/
@[extern "sortKind_toString"]
protected opaque toString : SortKind → String
instance : ToString SortKind := ⟨SortKind.toString⟩
/-- Produces a hash. -/
@[extern "sortKind_hash"]
protected opaque hash : SortKind → UInt64
instance : Hashable SortKind := ⟨SortKind.hash⟩
end SortKind
namespace ProofRule
/-- Produces a string representation. -/
@[extern "proofRule_toString"]
protected opaque toString : ProofRule → String
instance : ToString ProofRule := ⟨ProofRule.toString⟩
/-- Produces a hash. -/
@[extern "proofRule_hash"]
protected opaque hash : ProofRule → UInt64
instance : Hashable ProofRule := ⟨ProofRule.hash⟩
end ProofRule
namespace SkolemId
/-- Produces a string representation. -/
@[extern "skolemId_toString"]
protected opaque toString : SkolemId → String
instance : ToString SkolemId := ⟨SkolemId.toString⟩
/-- Produces a hash. -/
@[extern "skolemId_hash"]
protected opaque hash : SkolemId → UInt64
instance : Hashable SkolemId := ⟨SkolemId.hash⟩
end SkolemId
namespace ProofRewriteRule
/-- Produces a string representation. -/
@[extern "proofRewriteRule_toString"]
protected opaque toString : ProofRewriteRule → String
instance : ToString ProofRewriteRule := ⟨ProofRewriteRule.toString⟩
/-- Produces a hash. -/
@[extern "proofRewriteRule_hash"]
protected opaque hash : ProofRewriteRule → UInt64
instance : Hashable ProofRewriteRule := ⟨ProofRewriteRule.hash⟩
end ProofRewriteRule
namespace UnknownExplanation
/-- Produces a string representation. -/
@[extern "unknownExplanation_toString"]
protected opaque toString : UnknownExplanation → String
instance : ToString UnknownExplanation := ⟨UnknownExplanation.toString⟩
/-- Produces a hash. -/
@[extern "unknownExplanation_hash"]
protected opaque hash : UnknownExplanation → UInt64
instance : Hashable UnknownExplanation := ⟨UnknownExplanation.hash⟩
end UnknownExplanation
namespace RoundingMode
/-- Produces a string representation. -/
@[extern "roundingMode_toString"]
protected opaque toString : RoundingMode → String
instance : ToString RoundingMode := ⟨RoundingMode.toString⟩
/-- Produces a hash. -/
@[extern "roundingMode_hash"]
protected opaque hash : RoundingMode → UInt64
instance : Hashable RoundingMode := ⟨RoundingMode.hash⟩
end RoundingMode
namespace BlockModelsMode
/-- Produces a string representation. -/
@[extern "blockModelsMode_toString"]
protected opaque toString : BlockModelsMode → String
instance : ToString BlockModelsMode := ⟨BlockModelsMode.toString⟩
/-- Produces a hash. -/
@[extern "blockModelsMode_hash"]
protected opaque hash : BlockModelsMode → UInt64
instance : Hashable BlockModelsMode := ⟨BlockModelsMode.hash⟩
end BlockModelsMode
namespace LearnedLitType
/-- Produces a string representation. -/
@[extern "learnedLitType_toString"]
protected opaque toString : LearnedLitType → String
instance : ToString LearnedLitType := ⟨LearnedLitType.toString⟩
/-- Produces a hash. -/
@[extern "learnedLitType_hash"]
protected opaque hash : LearnedLitType → UInt64
instance : Hashable LearnedLitType := ⟨LearnedLitType.hash⟩
end LearnedLitType
namespace ProofComponent
/-- Produces a string representation. -/
@[extern "proofComponent_toString"]
protected opaque toString : ProofComponent → String
instance : ToString ProofComponent := ⟨ProofComponent.toString⟩
/-- Produces a hash. -/
@[extern "proofComponent_hash"]
protected opaque hash : ProofComponent → UInt64
instance : Hashable ProofComponent := ⟨ProofComponent.hash⟩
end ProofComponent
namespace ProofFormat
/-- Produces a string representation. -/
@[extern "proofFormat_toString"]
protected opaque toString : ProofFormat → String
instance : ToString ProofFormat := ⟨ProofFormat.toString⟩
/-- Produces a hash. -/
@[extern "proofFormat_hash"]
protected opaque hash : ProofFormat → UInt64
instance : Hashable ProofFormat := ⟨ProofFormat.hash⟩
end ProofFormat
namespace FindSynthTarget
/-- Produces a string representation. -/
@[extern "findSynthTarget_toString"]
protected opaque toString : FindSynthTarget → String
instance : ToString FindSynthTarget := ⟨FindSynthTarget.toString⟩
/-- Produces a hash. -/
@[extern "findSynthTarget_hash"]
protected opaque hash : FindSynthTarget → UInt64
instance : Hashable FindSynthTarget := ⟨FindSynthTarget.hash⟩
end FindSynthTarget
namespace InputLanguage
/-- Produces a string representation. -/
@[extern "inputLanguage_toString"]
protected opaque toString : InputLanguage → String
instance : ToString InputLanguage := ⟨InputLanguage.toString⟩
/-- Produces a hash. -/
@[extern "inputLanguage_hash"]
protected opaque hash : InputLanguage → UInt64
instance : Hashable InputLanguage := ⟨InputLanguage.hash⟩
end InputLanguage
private opaque ResultImpl : NonemptyType.{0}
/-- Encapsulation of a three-valued solver result, with explanations. -/
def Result : Type := ResultImpl.type
instance Result.instNonemptyResult : Nonempty Result := ResultImpl.property
private opaque SynthResultImpl : NonemptyType.{0}
/-- Encapsulation of a three-valued solver result, with explanations. -/
def SynthResult : Type := SynthResultImpl.type
instance SynthResult.instNonemptySynthResult : Nonempty SynthResult := SynthResultImpl.property
private opaque SortImpl : NonemptyType.{0}
end cvc5
/-- The sort of a cvc5 term. -/
def cvc5.Sort : Type := cvc5.SortImpl.type
namespace cvc5
instance Sort.instNonemptySort : Nonempty cvc5.Sort := SortImpl.property
private opaque OpImpl : NonemptyType.{0}
/-- A cvc5 operator.
An operator is a term that represents certain operators, instantiated with its required parameters,
*e.g.*, a `Term` of kind `Kind.BITVECTOR_EXTRACT`.
-/
def Op : Type := OpImpl.type
instance Op.instNonemptyOp : Nonempty Op := OpImpl.property
private opaque TermImpl : NonemptyType.{0}
/-- A cvc5 term. -/
def Term : Type := TermImpl.type
instance Term.instNonemptyTerm : Nonempty Term := TermImpl.property
private opaque ProofImpl : NonemptyType.{0}
/-- A cvc5 proof.
Proofs are trees and every proof object corresponds to the root step of a proof. The branches of the
root step are the premises of the step.
-/
def Proof : Type := ProofImpl.type
instance Proof.instNonemptyProof : Nonempty Proof := ProofImpl.property
/-- Error type. -/
inductive Error where
| missingValue
| error (msg : String)
| recoverable (msg : String)
| unsupported (msg : String)
| option (msg : String)
deriving Repr
/-- Cvc5 environment monad transformer.
Most monadic functions in this API use the non-transformer monad `cvc5.Env`, where `m := BaseIO`.
When using an `EnvT m α`, do make sure `m` is such that `MonadLiftT BaseIO m` which gives
`MonadLiftT Env (EnvT m)`.
-/
abbrev EnvT (m : Type → Type) (α : Type) : Type :=
ExceptT Error m α
/-- Cvc5 environment monad in `BaseIO`. -/
abbrev Env (α : Type) := EnvT BaseIO α
namespace EnvT
-- functions used by the underlying C++ layer
section ffi variable [Monad m]
@[export env_pure]
private def env_pure (a : α) : Env α := return a
@[export env_bool]
private def env_bool (b : Bool) : Env Bool := return b
@[export env_uint64]
private def env_uint64 (u : UInt64) : Env UInt64 := return u
@[export env_throw]
private def env_throw (e : Error) : Env α := throw e
@[export env_throw_string]
private def env_throw_string (e : String) : Env α := throw <| (.error e)
end ffi
end EnvT
namespace Error
/-- String representation of an error. -/
protected def toString : Error → String :=
toString ∘ repr
/-- Panics on errors, otherwise yields the `ok` result. -/
def unwrap! [Inhabited α] : Except Error α → α
| .ok a => a
| .error e => panic! e.toString
instance : ToString Error :=
⟨Error.toString⟩
end Error
private opaque TermManagerImpl : NonemptyType.{0}
/-- Manager for cvc5 terms. -/
def TermManager : Type := TermManagerImpl.type
namespace TermManager
instance : Nonempty TermManager := TermManagerImpl.property
/-- Constructor. -/
extern_def new : Env TermManager
end TermManager
private opaque SolverImpl : NonemptyType.{0}
/-- A cvc5 solver. -/
def Solver : Type := SolverImpl.type
namespace Solver
instance : Nonempty Solver := SolverImpl.property
/-- Constructor.
- `tm` The associated term manager instance.
-/
extern_def new : (tm : TermManager) → Env Solver
end Solver
private opaque DatatypeConstructorDeclImpl : NonemptyType.{0}
/-- A cvc5 datatype constructor declaration.
A datatype constructor declaration is a specification used for creating a datatype constructor.
-/
def DatatypeConstructorDecl : Type := DatatypeConstructorDeclImpl.type
namespace DatatypeConstructorDecl
instance : Nonempty DatatypeConstructorDecl := DatatypeConstructorDeclImpl.property
/-- A string representation of this datatype constructor declaration. -/
protected extern_def toString : DatatypeConstructorDecl → String
instance : ToString DatatypeConstructorDecl := ⟨DatatypeConstructorDecl.toString⟩
end DatatypeConstructorDecl
private opaque DatatypeDeclImpl : NonemptyType.{0}
/-- A cvc5 datatype declaration.
A datatype declaration is not itself a datatype (see `Datatype`), but a specification for creating a
datatype sort.
The interface for a datatype declaration coincides with the syntax for the SMT-LIB 2.6 command
`declare-datatype`, or a single datatype within the `declare-datatypes` command.
`Datatype` sorts can be constructed from a `DatatypeDecl` using:
- `Solver.mkDatatypeSort`
- `Solver.mkDatatypeSorts`
-/
def DatatypeDecl : Type := DatatypeDeclImpl.type
namespace DatatypeDecl
instance : Nonempty DatatypeDecl := DatatypeDeclImpl.property
/-- Get a string representation of this datatype declaration. -/
protected extern_def toString : DatatypeDecl → String
instance : ToString DatatypeDecl := ⟨DatatypeDecl.toString⟩
end DatatypeDecl
private opaque DatatypeSelectorImpl : NonemptyType.{0}
/-- A cvc5 datatype selector. -/
def DatatypeSelector : Type := DatatypeSelectorImpl.type
namespace DatatypeSelector
instance : Nonempty DatatypeSelector := DatatypeSelectorImpl.property
/-- Gte the string representation of this datatype selector. -/
protected extern_def toString : DatatypeSelector → String
instance : ToString DatatypeSelector := ⟨DatatypeSelector.toString⟩
end DatatypeSelector
private opaque DatatypeConstructorImpl : NonemptyType.{0}
/-- A cvc5 datatype constructor. -/
def DatatypeConstructor : Type := DatatypeConstructorImpl.type
namespace DatatypeConstructor
instance : Nonempty DatatypeConstructor := DatatypeConstructorImpl.property
/-- A string representation of this datatype. -/
protected extern_def toString : DatatypeConstructor → String
instance : ToString DatatypeConstructor := ⟨DatatypeConstructor.toString⟩
end DatatypeConstructor
private opaque DatatypeImpl : NonemptyType.{0}
/-- A cvc5 datatype. -/
def Datatype : Type := DatatypeImpl.type
namespace Datatype
instance : Nonempty Datatype := DatatypeImpl.property
/-- A string representation of this datatype. -/
protected extern_def toString : Datatype → String
instance : ToString Datatype := ⟨Datatype.toString⟩
end Datatype
private opaque GrammarImpl : NonemptyType.{0}
/-- A Sygus Grammar.
This class can be used to define a context-free grammar of terms. Its interface coincides with the
definition of grammars in the SyGuS IF 2.1 standard.
-/
def Grammar : Type := GrammarImpl.type
namespace Grammar
instance : Nonempty Grammar := GrammarImpl.property
/-- A string representation of this grammar. -/
protected extern_def toString : Grammar → String
instance : ToString Grammar := ⟨Grammar.toString⟩
end Grammar
private opaque CommandImpl : NonemptyType.{0}
/-- Encapsulation of a command.
Commands are constructed by the `InputParser` and can be invoked on the `Solver` and
`Command`.
-/
def Command : Type := CommandImpl.type
namespace Command
instance : Nonempty Command := CommandImpl.property
/-- Get a string representation of this command. -/
protected extern_def toString : Command → String
instance : ToString Command := ⟨Command.toString⟩
end Command
private opaque SymbolManagerImpl : NonemptyType.{0}
/-- Symbol manager.
Internally, this class manages a symbol table and other meta-information pertaining to SMT2 file
inputs (*e.g.* named assertions, declared functions, *etc.*).
A symbol manager can be modified by invoking commands, see `Command.invoke`.
A symbol manager can be provided when constructing an `InputParser`, in which case that
`InputParser` has symbols of this symbol manager preloaded.
The symbol manager's interface is otherwise not publicly available.
-/
def SymbolManager : Type := SymbolManagerImpl.type
namespace SymbolManager
instance SymbolManager.instNonempty : Nonempty SymbolManager := SymbolManagerImpl.property
/-- Constructor.
- `tm` The associated term manager instance.
-/
extern_def new : (tm : TermManager) → Env SymbolManager
end SymbolManager
private opaque InputParserImpl : NonemptyType.{0}
/-- This type is the main interface for retrieving commands and expressions from an input using a
parser.
After construction, it is expected that an input is first configured via, e.g.,
`InputParser.setFileInput`, `InputParser.setStreamInput`, `InputParser.setStringInput` or
`InputParser.setIncrementalStringInput` and `InputParser.appendIncrementalStringInput`. Then,
functions `InputParser.nextCommand` and `InputParser.nextExpression` can be invoked to parse the
input.
The input parser interacts with a symbol manager, which determines which symbols are defined in the
current context, based on the background logic and user-defined symbols. If no symbol manager is
provided, then the input parser will construct (an initially empty) one.
If provided, the symbol manager must have a logic that is compatible with the provided solver. That
is, if both the solver and symbol manager have their logics set (`SymbolManager.isLogicSet` and
`Solver.isLogicSet`), then their logics must be the same.
Upon setting an input source, if either the solver (resp. symbol manager) has its logic set, then
the symbol manager (resp. solver) is set to use that logic, if its logic is not already set.
-/
def InputParser : Type := InputParserImpl.type
namespace InputParser
instance : Nonempty InputParser := InputParserImpl.property
/-- Construct an input parser with an initially empty symbol manager.
- `solver`: The solver (e.g. for constructing terms and sorts).
-/
private extern_def ofSolver : (solver : Solver) → Env InputParser
/-- Construct an input parser.
- `solver` The solver (e.g. for constructing terms and sorts).
- `sm` The symbol manager, which contains a symbol table that maps symbols to terms and sorts. Must
have a logic that is compatible with the solver.
-/
private extern_def ofSolverAndSM : (solver : Solver) → (sm : SymbolManager) → Env InputParser
@[inherit_doc ofSolverAndSM]
def new (solver : Solver) : (sm : Option SymbolManager := none) → Env InputParser
| none => ofSolver solver
| some sm => ofSolverAndSM solver sm
end InputParser
namespace Result
/-- Comparison for structural equality. -/
protected extern_def beq : Result → Result → Bool
instance : BEq Result := ⟨Result.beq⟩
/-- Hash function for cvc5 sorts. -/
protected extern_def hash : Result → UInt64
instance : Hashable Result := ⟨Result.hash⟩
/-- True if this result is from a satisfiable `checkSat` or `checkSatAssuming` query. -/
extern_def isSat : Result → Bool
/-- True if this result is from a unsatisfiable `checkSat` or `checkSatAssuming` query. -/
extern_def isUnsat : Result → Bool
/-- True if this result is from a `checkSat` or `checkSatAssuming` query and cvc5 was not able to
determine (un)satisfiability.
-/
extern_def isUnknown : Result → Bool
/-- An explanation for an unknown query result.
Note that if the result is (un)sat, this function returns `UnknownExplanation.UNKNOWN_REASON`.
-/
extern_def getUnknownExplanation : Result → UnknownExplanation
with
/-- An explanation for an unknown query result, `none` if the result in not unknown. -/
getUnknownExplanation? (res : Result) : Option UnknownExplanation :=
if ¬ res.isUnknown then none else res.getUnknownExplanation
/-- A string representation of this result. -/
protected extern_def toString : Result → String
instance : ToString Result := ⟨Result.toString⟩
end Result
namespace SynthResult
/-- A string representation of this synthesis result. -/
protected extern_def toString : SynthResult → String
instance : ToString SynthResult := ⟨SynthResult.toString⟩
/-- Hash function for synthesis results. -/
protected extern_def hash : SynthResult → UInt64
instance : Hashable SynthResult := ⟨SynthResult.hash⟩
/-- Equality of two synthesis results. -/
protected extern_def beq : SynthResult → SynthResult → Bool
instance : BEq SynthResult := ⟨SynthResult.beq⟩
/-- Determine if a given synthesis result is empty (a nullary result) and not an actual result
returned from a synthesis query.
-/
extern_def isNull : SynthResult → Bool
/-- True if the synthesis query has a solution. -/
extern_def hasSolution : SynthResult → Bool
/-- True if the synthesis query has no solution. In this case, it was determined that there was no
solution.
-/
extern_def hasNoSolution : SynthResult → Bool
/-- True if the result of the synthesis query could not be determined. -/
extern_def isUnknown : SynthResult → Bool
end SynthResult
section ffi_except_constructors
/--
992E
Only used by FFI to inject values. -/
@[export generic_except_ok]
private def mkExceptOk {α : Type} : α → Except Error α := .ok
/-- Only used by FFI to inject values. -/
@[export except_ok_bool]
private def mkExceptOkBool : Bool → Except Error Bool := .ok
/-- Only used by FFI to inject values. -/
@[export except_ok_i64]
private def mkExceptOkI64 : Int64 → Except Error Int64 := .ok
/-- Only used by FFI to inject values. -/
@[export except_ok_u64]
private def mkExceptOkU64 : Int64 → Except Error Int64 := .ok
/-- Only used by FFI to inject values. -/
@[export except_ok_u32]
private def mkExceptOkU32 : UInt32 → Except Error UInt32 := .ok
/-- Only used by FFI to inject values. -/
@[export except_ok_i32]
private def mkExceptOkI32 : Int32 → Except Error Int32 := .ok
/-- Only used by FFI to inject values. -/
@[export except_ok_u16]
private def mkExceptOkU16 : UInt16 → Except Error UInt16 := .ok
/-- Only used by FFI to inject values. -/
@[export except_ok_u8]
private def mkExceptOkU8 : UInt8 → Except Error UInt8 := .ok
/-- Only used by FFI to inject errors. -/
@[export generic_except_err]
private def mkExceptErr {α : Type} : Error → Except Error α := .error
/-- Only used by FFI to inject errors. -/
@[export generic_except_err_of_string]
private def mkExceptErrOfString {α : Type} : String → Except Error α := .error ∘ Error.error
end ffi_except_constructors
namespace DatatypeConstructorDecl
/-- The null datatype constructor declaration. -/
extern_def null : Unit → DatatypeConstructorDecl
/-- True if this `DatatypeConstructorDecl` is a null declaration. -/
extern_def isNull : DatatypeConstructorDecl → Bool
/-- Equality operator. -/
protected extern_def beq : DatatypeConstructorDecl → DatatypeConstructorDecl → Bool
instance : BEq DatatypeConstructorDecl := ⟨DatatypeConstructorDecl.beq⟩
/-- Hash function for datatype declarations. -/
protected extern_def hash : DatatypeConstructorDecl → UInt64
instance : Hashable DatatypeConstructorDecl := ⟨DatatypeConstructorDecl.hash⟩
/-- Add datatype selector declaration.
- `name` The name of the datatype selector declaration to add.
- `sort` The codomain sort of the datatype selector declaration to add.
-/
extern_def addSelector :
(dtCons : DatatypeConstructorDecl) → (name : String) → (sort : cvc5.Sort) →
Env DatatypeConstructorDecl
/-- Add datatype selector declaration whose codomain type is the datatype itself.
- `name` The name of the datatype selector declaration to add.
-/
extern_def addSelectorSelf :
(dtCons : DatatypeConstructorDecl) → (name : String) → Env DatatypeConstructorDecl
/-- Add datatype selector declaration whose codomain sort is an unresolved datatype with the given
name.
- `name` The name of the datatype selector declaration to add.
- `unresDatatypeName` The name of the unresolved datatype. The codomain of the selector will be the
resolved datatype with the given name
-/
extern_def addSelectorUnresolved :
(dtCons : DatatypeConstructorDecl) → (name : String) → (unresDatatypeName : String) →
Env DatatypeConstructorDecl
end DatatypeConstructorDecl
namespace DatatypeDecl
/-- The null datatype declaration. -/
extern_def null : Unit → DatatypeDecl
instance : Inhabited DatatypeDecl := ⟨null ()⟩
/-- Determine if this datatype declaration is nullary. -/
extern_def isNull : DatatypeDecl → Bool
/-- Equality operator. -/
protected extern_def beq : DatatypeDecl → DatatypeDecl → Bool
instance : BEq DatatypeDecl := ⟨DatatypeDecl.beq⟩
/-- Hash function for datatype declarations. -/
protected extern_def hash : DatatypeDecl → UInt64
instance : Hashable DatatypeDecl := ⟨DatatypeDecl.hash⟩
/-- Add datatype constructor declaration.
- `ctor` The datatype constructor declaration to add.
-/
extern_def addConstructor :
DatatypeDecl → (ctor : DatatypeConstructorDecl) → Env DatatypeDecl
/-- Get the number of constructors for this datatype declaration. -/
extern_def getNumConstructors : DatatypeDecl → Nat
/-- Determine if this datatype declaration is parametric.
**Warning**: this function is experimental and may change in future versions.
-/
extern_def isParametric : DatatypeDecl → Bool
/-- Get the name of this datatype declaration. -/
extern_def!? getName : DatatypeDecl → Except Error String
/-- Determine if this datatype declaration is resolved (has already been used to declare a
datatype).
-/
extern_def isResolved : DatatypeDecl → Env Bool
end DatatypeDecl
namespace DatatypeSelector
/-- The null datatype constructor. -/
extern_def null : Unit → DatatypeSelector
instance : Inhabited DatatypeSelector := ⟨null ()⟩
/-- True if this datatype is a null object. -/
extern_def isNull : DatatypeSelector → Bool
/-- Equality operator. -/
protected extern_def beq : DatatypeSelector → DatatypeSelector → Bool
instance : BEq DatatypeSelector := ⟨DatatypeSelector.beq⟩
/-- Hash function for datatype selectors. -/
protected extern_def hash : DatatypeSelector → UInt64
instance : Hashable DatatypeSelector := ⟨DatatypeSelector.hash⟩
7292
/-- Get the name of this datatype selector. -/
extern_def!? getName : DatatypeSelector → Except Error String
/-- Get the selector term of this datatype selector.
Selector terms are a class of function-like terms of selector sort (`Sort.isDatatypeSelector`), and
should be used as the first argument of terms of kind `Kind.APPLY_SELECTOR`.
-/
extern_def getTerm : DatatypeSelector → Env Term
/-- Get the updater term of this datatype selector.
Similar to selectors, updater terms are a class of function-like terms of updater sort
(`Sort.isDatatypeUpdater`), and should be used as the first argument of terms of kind
`Kind.APPLY_UPDATER`.
-/
extern_def getUpdaterTerm : DatatypeSelector → Env Term
/-- Get the codomain sort of this selector. -/
extern_def getCodomainSort : DatatypeSelector → Env cvc5.Sort
end DatatypeSelector
namespace DatatypeConstructor
/-- The null datatype constructor. -/
extern_def null : Unit → DatatypeConstructor
instance : Inhabited DatatypeConstructor := ⟨null ()⟩
/-- True if this datatype is a null object. -/
extern_def isNull : DatatypeConstructor → Bool
/-- Equality operator. -/
protected extern_def beq : DatatypeConstructor → DatatypeConstructor → Bool
instance : BEq DatatypeConstructor := ⟨DatatypeConstructor.beq⟩
/-- Hash function for datatype constructors. -/
protected extern_def hash : DatatypeConstructor → UInt64
instance : Hashable DatatypeConstructor := ⟨DatatypeConstructor.hash⟩
/-- Get the name of this datatype constructor. -/
extern_def!? getName : DatatypeConstructor → Except Error String
/-- Get the constructor term of this datatype constructor.
Datatype constructors are a special class of function-like terms whose sort is datatype constructor
(`Sort.isDatatypeConstructor`). All datatype constructors, including nullary ones, should be used as
the first argument to terms whose kind is `Kind.APPLY_CONSTRUCTOR`. For example, the nil list can
be constructor by `tm.mkTerm Kind.APPLY_CONSTRUCTOR #[t]`, where `tm` is a `TermManager` and `t` is
the term returned by this function.
This function should not be used for parametric datatypes. Instead, use the function
`DatatypeConstructor.getInstantiatedTerm`.
-/
extern_def getTerm : DatatypeConstructor → Env Term
/-- Get the constructor term of this datatype constructor whose return type is `retSort`.
This function is intended to be used on constructors of parametric datatypes and can be seen as
returning the constructor term that has been explicitly cast to the given sort.
This function is required for constructors of parametric datatypes whose return type cannot be
determined by type inference. For example, given:
```smtlib
(declare-datatype List (par (T) ((nil) (cons (head T) (tail (List T))))))
```
The type of nil terms must be provided by the user. In SMT version 2.6, this is done via the syntax
for qualified identifiers:
```smtlib
(as nil (List Int))
```
This function is equivalent of applying the above, where this DatatypeConstructor is the one
corresponding to `nil`, and `retSort` is `(List Int)`.
The returned constructor term `t` is used to construct the above (nullary) application of `nil` with
`TermManager::mkTerm(Kind::APPLY_CONSTRUCTOR, {t})`.
**Warning**: this function is experimental and may change in future versions.
- `retSort` The desired return sort of the constructor.
-/
extern_def getInstantiatedTerm : DatatypeConstructor → (retSort : cvc5.Sort) → Env Term
/-- Get the tester term of this datatype constructor.
Similar to constructors, testers are a class of function-like terms of tester sort
(`Sort.isDatatypeTester`) which should be used as the first argument of terms of kind
`Kind.APPLY_TESTER`.
-/
extern_def getTesterTerm : DatatypeConstructor → Env Term
/-- The number of selectors of this datatype constructor. -/
extern_def getNumSelectors : DatatypeConstructor → Nat
/-- Get the datatype selector with the given name.
This is a linear search through the selectors, so in case of multiple, similarly-named selectors,
the first is returned.
- `name` The name of the datatype selector.
-/
extern_def getSelector : DatatypeConstructor → (name : String) → Env DatatypeSelector
/-- The datatype selector at index `idx`. -/
extern_def getSelectorAt :
(dtCons : DatatypeConstructor) → (idx : Fin dtCons.getNumSelectors) → DatatypeSelector
instance : GetElem DatatypeConstructor Nat DatatypeSelector
fun dt idx => idx < dt.getNumSelectors
where
getElem dt idx h := dt.getSelectorAt ⟨idx, h⟩
instance [Monad m] : ForIn m DatatypeConstructor DatatypeSelector where
forIn dtCons init fold := forIn' [:dtCons.getNumSelectors] init fun idx h_member acc =>
let selector := dtCons.getSelectorAt ⟨idx, h_member.upper⟩
fold selector acc
end DatatypeConstructor
namespace Datatype
/-- The null datatype. -/
extern_def null : Unit → Datatype
instance : Inhabited Datatype := ⟨null ()⟩
/-- True if this datatype is a null object. -/
extern_def isNull : Datatype → Bool
/-- Equality operator. -/
protected extern_def beq : Datatype → Datatype → Bool
instance : BEq Datatype := ⟨Datatype.beq⟩
/-- Hash function for datatypes. -/
protected extern_def hash : Datatype → UInt64
instance : Hashable Datatype := ⟨Datatype.hash⟩
/-- Get the datatype constructor with the given name.
This is a linear search through the constructors, so in case of multiple, similarly-named
constructors, the first is returned.
- `name` The name of the datatype constructor.
-/
extern_def getConstructor : Datatype → (name : String) → Env DatatypeConstructor
/-- Get the number of constructors of this datatype. -/
extern_def getNumConstructors : Datatype → Nat
/-- Get the datatype constructor at a given index.
- `idx` The index of the datatype constructor to return.
-/
extern_def getConstructorAt :
(dt : Datatype) → (idx : Fin dt.getNumConstructors) → DatatypeConstructor
instance : GetElem Datatype Nat DatatypeConstructor
fun dt idx => idx < dt.getNumConstructors
where
getElem dt idx h := dt.getConstructorAt ⟨idx, h⟩
instance [Monad m] : ForIn m Datatype DatatypeConstructor where
forIn dt init fold := forIn' [:dt.getNumConstructors] init fun idx h_member acc =>
let constructor := dt.getConstructorAt ⟨idx, h_member.upper⟩
fold constructor acc
/-- Get the datatype selector with the given name.
This is a linear search through the constructors and their selectors, so in case of multiple,
similarly-named selectors, the first is returned.
- `name` The name of the datatype selector.
-/
extern_def getSelector : Datatype → (name : String) → Env DatatypeSelector