Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly print negative real literals #1272

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/lib/structures/expr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,22 @@ module SmtPrinter = struct
| Sy.Real q when Q.(equal q zero) -> true
| _ -> false

let pp_integer ppf i =
if Z.sign i = -1 then
Fmt.pf ppf "(- %a)" Z.pp_print (Z.abs i)
else
Z.pp_print ppf i

let pp_rational ppf q =
if Z.equal (Q.den q) Z.one then
Fmt.pf ppf "%a.0" Z.pp_print (Q.num q)
else if Q.sign q = -1 then
Fmt.pf ppf "(/ (- %a) %a)"
Z.pp_print (Z.abs (Q.num q))
Z.pp_print (Q.den q)
if Z.sign (Q.num q) = -1 then
Fmt.pf ppf "(- %a.0)" Z.pp_print (Z.abs (Q.num q))
else
Fmt.pf ppf "%a.0" Z.pp_print (Q.num q)
else
Fmt.pf ppf "(/ %a %a)" Z.pp_print (Q.num q) Z.pp_print (Q.den q)
Fmt.pf ppf "(/ %a %a)"
pp_integer (Q.num q)
Z.pp_print (Q.den q)

let pp_binder ppf (var, ty) =
Fmt.pf ppf "(%a %a)" Var.print var Ty.pp_smtlib ty
Expand Down Expand Up @@ -484,14 +491,9 @@ module SmtPrinter = struct

| Sy.Var v, [] -> Var.print ppf v

| Sy.Int i, [] ->
if Z.sign i = -1 then
Fmt.pf ppf "(- %a)" Z.pp_print (Z.abs i)
else
Fmt.pf ppf "%a" Z.pp_print i
| Sy.Int i, [] -> pp_integer ppf i

| Sy.Real q, [] ->
pp_rational ppf q
| Sy.Real q, [] -> pp_rational ppf q

| Sy.Bitv (n, s), [] ->
if n mod 4 = 0 then
Expand Down
5 changes: 5 additions & 0 deletions tests/issues/1271.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

unknown
(
(define-fun x () Real (- 42.0))
)
7 changes: 7 additions & 0 deletions tests/issues/1271.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; Test printing of negative real values
(set-logic ALL)
(set-option :produce-models true)
(declare-fun x () Real)
(assert (= x (- 42.0)))
(check-sat)
(get-model)
Loading