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
(* SPDX-License-Identifier: MIT *)
(* Copyright (C) 2023-2024 formalsec *)
(* Written by the Smtml programmers *)

type satisfiability =
  [ `Sat
  | `Unsat
  | `Unknown
  ]

module type M = sig
  type ty

  type term

  type interp

  type model

  type solver

  type handle

  type optimizer

  type func_decl

  val caches_consts : bool

  val true_ : term

  val false_ : term

  val int : int -> term

  val real : float -> term

  val const : string -> ty -> term

  val not_ : term -> term

  val and_ : term -> term -> term

  val or_ : term -> term -> term

  val logand : term list -> term

  val logor : term list -> term

  val xor : term -> term -> term

  val eq : term -> term -> term

  val distinct : term list -> term

  val ite : term -> term -> term -> term

  module Types : sig
    val int : ty

    val real : ty

    val bool : ty

    val string : ty

    val bitv : int -> ty

    val float : int -> int -> ty

    val ty : term -> ty

    val to_ety : ty -> Ty.t
  end

  module Interp : sig
    val to_int : interp -> int

    val to_real : interp -> float

    val to_bool : interp -> bool

    val to_string : interp -> string

    val to_bitv : interp -> int -> int64

    val to_float : interp -> int -> int -> float
  end

  module Int : sig
    val neg : term -> term

    val to_real : term -> term

    val add : term -> term -> term

    val sub : term -> term -> term

    val mul : term -> term -> term

    val div : term -> term -> term

    val rem : term -> term -> term

    val pow : term -> term -> term

    val lt : term -> term -> term

    val le : term -> term -> term

    val gt : term -> term -> term

    val ge : term -> term -> term
  end

  module Real : sig
    val neg : term -> term

    val to_int : term -> term

    val add : term -> term -> term

    val sub : term -> term -> term

    val mul : term -> term -> term

    val div : term -> term -> term

    val pow : term -> term -> term

    val lt : term -> term -> term

    val le : term -> term -> term

    val gt : term -> term -> term

    val ge : term -> term -> term
  end

  module String : sig
    val v : string -> term

    val length : term -> term

    val to_code : term -> term

    val of_code : term -> term

    val to_int : term -> term

    val of_int : term -> term

    val to_re : term -> term

    val at : term -> pos:term -> term

    val concat : term list -> term

    val contains : term -> sub:term -> term

    val is_prefix : term -> prefix:term -> term

    val is_suffix : term -> suffix:term -> term

    val in_re : term -> term -> term

    val lt : term -> term -> term

    val le : term -> term -> term

    val sub : term -> pos:term -> len:term -> term

    val index_of : term -> sub:term -> pos:term -> term

    val replace : term -> pattern:term -> with_:term -> term
  end

  module Re : sig
    val star : term -> term

    val plus : term -> term

    val opt : term -> term

    val comp : term -> term

    val range : term -> term -> term

    val loop : term -> int -> int -> term

    val union : term list -> term

    val concat : term list -> term
  end

  module Bitv : sig
    val v : string -> int -> term

    val neg : term -> term

    val lognot : term -> term

    val add : term -> term -> term

    val sub : term -> term -> term

    val mul : term -> term -> term

    val div : term -> term -> term

    val div_u : term -> term -> term

    val logor : term -> term -> term

    val logand : term -> term -> term

    val logxor : term -> term -> term

    val shl : term -> term -> term

    val ashr : term -> term -> term

    val lshr : term -> term -> term

    val rem : term -> term -> term

    val rem_u : term -> term -> term

    val rotate_left : term -> term -> term

    val rotate_right : term -> term -> term

    val lt : term -> term -> term

    val lt_u : term -> term -> term

    val le : term -> term -> term

    val le_u : term -> term -> term

    val gt : term -> term -> term

    val gt_u : term -> term -> term

    val ge : term -> term -> term

    val ge_u : term -> term -> term

    val concat : term -> term -> term

    val extract : term -> high:int -> low:int -> term

    val zero_extend : int -> term -> term

    val sign_extend : int -> term -> term
  end

  module Float : sig
    (* Rounding modes *)
    module Rounding_mode : sig
      (* Round nearest ties to even *)
      val rne : term

      (* Round nearest ties to away *)
      val rna : term

      (* Round toward positive *)
      val rtp : term

      (* Round toward negative *)
      val rtn : term

      (* Round toward zero *)
      val rtz : term
    end

    val v : float -> int -> int -> term

    val neg : term -> term

    val abs : term -> term

    (* [sqrt ~rm t] where [rm] is the rounding mode *)
    val sqrt : rm:term -> term -> term

    val is_nan : term -> term

    (* [round_to_integral ~rm t] where [rm] is the rounding mode *)
    val round_to_integral : rm:term -> term -> term

    (* [add ~rm t1 t2] where [rm] is the rounding mode *)
    val add : rm:term -> term -> term -> term

    (* [sub ~rm t1 t2] where [rm] is the rounding mode *)
    val sub : rm:term -> term -> term -> term

    (* [mul ~rm t1 t2] where [rm] is the rounding mode *)
    val mul : rm:term -> term -> term -> term

    (* [div ~rm t1 t2] where [rm] is the rounding mode *)
    val div : rm:term -> term -> term -> term

    val min : term -> term -> term

    val max : term -> term -> term

    val rem : term -> term -> term

    val eq : term -> term -> term

    val lt : term -> term -> term

    val le : term -> term -> term

    val gt : term -> term -> term

    val ge : term -> term -> term

    val to_fp : int -> int -> rm:term -> term -> term

    val sbv_to_fp : int -> int -> rm:term -> term -> term

    val ubv_to_fp : int -> int -> rm:term -> term -> term

    val to_ubv : int -> rm:term -> term -> term

    val to_sbv : int -> rm:term -> term -> term

    val of_ieee_bv : int -> int -> term -> term

    val to_ieee_bv : term -> term
  end

  module Func : sig
    val make : string -> ty list -> ty -> func_decl

    val apply : func_decl -> term list -> term
  end

  module Model : sig
    val get_symbols : model -> Symbol.t list

    val eval : ?completion:bool -> model -> term -> interp option
  end

  module Solver : sig
    val make : ?params:Params.t -> ?logic:Ty.logic -> unit -> solver

    val clone : solver -> solver

    val push : solver -> unit

    val pop : solver -> int -> unit

    val reset : solver -> unit

    val add : solver -> term list -> unit

    val check : solver -> assumptions:term list -> satisfiability

    val model : solver -> model option

    val add_simplifier : solver -> solver

    val interrupt : unit -> unit

    val get_statistics : solver -> Statistics.t

    val pp_statistics : solver Fmt.t
  end

  module Optimizer : sig
    val make : unit -> optimizer

    val push : optimizer -> unit

    val pop : optimizer -> unit

    val add : optimizer -> term list -> unit

    val check : optimizer -> satisfiability

    val model : optimizer -> model option

    val maximize : optimizer -> term -> handle

    val minimize : optimizer -> term -> handle

    val interrupt : unit -> unit

    val get_statistics : optimizer -> Statistics.t

    val pp_statistics : optimizer Fmt.t
  end

  module Smtlib : sig
    val pp :
         ?name:string
      -> ?logic:Ty.logic
      -> ?status:satisfiability
      -> term list Fmt.t
  end
end

module type M_with_make = sig
  module Make () : M

  val is_available : bool

  include M
end

module type S = sig
  type model

  type solver

  type optimize

  type handle

  val value : model -> Expr.t -> Value.t

  val values_of_model : ?symbols:Symbol.t list -> model -> Model.t

  val set_debug : bool -> unit

  module Smtlib : sig
    val pp :
         ?name:string
      -> ?logic:Ty.logic
      -> ?status:satisfiability
      -> Expr.t list Fmt.t
  end

  module Solver : sig
    val make : ?params:Params.t -> ?logic:Ty.logic -> unit -> solver

    val add_simplifier : solver -> solver

    val clone : solver -> solver

    val push : solver -> unit

    val pop : solver -> int -> unit

    val reset : solver -> unit

    val add : solver -> Expr.t list -> unit

    val check : solver -> assumptions:Expr.t list -> satisfiability

    val model : solver -> model option

    val interrupt : solver -> unit

    val get_statistics : solver -> Statistics.t
  end

  module Optimizer : sig
    val make : unit -> optimize

    val push : optimize -> unit

    val pop : optimize -> unit

    val add : optimize -> Expr.t list -> unit

    val check : optimize -> satisfiability

    val model : optimize -> model option

    val maximize : optimize -> Expr.t -> handle

    val minimize : optimize -> Expr.t -> handle

    val interrupt : optimize -> unit

    val get_statistics : optimize -> Statistics.t
  end
end

module type S_with_fresh = sig
  module Fresh : sig
    module Make () : S
  end

  val is_available : bool

  include S
end