Skip to content

Commit

Permalink
Add Expr constructors for the Reals SMT-LIB theory (#878)
Browse files Browse the repository at this point in the history
This patch follows `Expr.Int` and adds constructors from the `Reals`
SMT-LIB theory to the `Expr` module.
  • Loading branch information
bclement-ocp authored Oct 13, 2023
1 parent 24cd9cd commit b553807
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/lib/structures/expr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2886,6 +2886,43 @@ module Ints = struct
let ( > ) x y = y < x
end


(** Constructors from the smtlib theory of real numbers.
https://smtlib.cs.uiowa.edu/theories-Reals.shtml *)
module Reals = struct
let of_int n = real (string_of_int n)

let ( ~$ ) = of_int

let of_Z n = real (Z.to_string n)

let ( ~$$ ) = of_Z

let of_Q q = real (Q.to_string q)

let ( ~$$$ ) = of_Q

let ( - ) x y = mk_term (Op Minus) [ x; y ] Treal

let ( ~- ) x = ~$0 - x

let ( + ) x y = mk_term (Op Plus) [ x; y ] Treal

let ( * ) x y = mk_term (Op Mult) [ x; y ] Treal

let ( / ) x y = mk_term (Op Div) [ x; y ] Treal

let ( ** ) x y = mk_term (Op Pow) [ x; y ] Treal

let ( <= ) x y = mk_builtin ~is_pos:true LE [ x; y ]

let ( >= ) x y = y <= x

let ( < ) x y = mk_builtin ~is_pos:true LT [x; y ]

let ( > ) x y = y < x
end

(** Constructors from the smtlib theory of fixed-size bit-vectors and the QF_BV
logic.
Expand Down
31 changes: 31 additions & 0 deletions src/lib/structures/expr.mli
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,37 @@ module Ints : sig
val ( > ) : t -> t -> t
end

(** Constructors from the smtlib theory of reals.
https://smtlib.cs.uiowa.edu/theories-Reals.shtml *)
module Reals : sig
(* Conversion from int *)
val of_int : int -> t
val ( ~$ ) : int -> t

(* Conversion from ZArith *)
val of_Z : Z.t -> t
val ( ~$$ ) : Z.t -> t

val of_Q : Q.t -> t
val ( ~$$$ ) : Q.t -> t

(* Arithmetic operations *)
val ( + ) : t -> t -> t
val ( - ) : t -> t -> t
val ( ~- ) : t -> t
val ( * ) : t -> t -> t
val ( / ) : t -> t -> t

(* Exponentiation *)
val ( ** ) : t -> t -> t

(* Comparisons *)
val ( <= ) : t -> t -> t
val ( >= ) : t -> t -> t
val ( < ) : t -> t -> t
val ( > ) : t -> t -> t
end

(** Constructors from the smtlib theory of fixed-size bit-vectors and the QF_BV
logic.
Expand Down

0 comments on commit b553807

Please sign in to comment.