3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-05-16 23:25:36 +00:00
Commit graph

234 commits

Author SHA1 Message Date
copilot-swe-agent[bot]
a26a0da1dc
Fix soundness bug in fpa2bv_converter::mk_to_real for negative exponents
The mk_to_real function in fpa2bv_converter.cpp incorrectly computed the
exponent scaling factor for floats with negative exponents. The code was
computing 2^(1/|exp|) instead of 1/(2^|exp|) = 2^(-|exp|).

Root cause: after the loop that computed exp2 = |unbiased_exp| as an integer,
the code did:
  one_div_exp2 = 1/exp2        (computed 1/|exp|, NOT 1/2^|exp|)
  exp2 = ite(exp_is_neg, one_div_exp2, exp2)
  two_exp2 = mk_power(two, exp2)  -> gives 2^(1/|exp|) for negative exp

For example, for exp=-3 (as in Float32(0xBE7BE653)):
  OLD (buggy): two_exp2 = 2^(1/3) ≈ 1.26 (wrong)
  NEW (fixed):  two_exp2 = 1/8 (correct: 2^(-3) = 1/8)

Fix: compute two_exp2 = 2^|exp| first, then use 1/two_exp2 for negative exponents:
  two_exp2 = mk_power(two, exp2)       (2^|exp|)
  one_div_two_exp2 = 1/two_exp2        (1/2^|exp| = 2^(-|exp|))
  two_exp2 = ite(exp_is_neg, one_div_two_exp2, two_exp2)

This bug affected:
1. QF_FPLRA: to_fp(RTZ, r) for symbolic real r in an interval containing
   the exact rational value of a float returned UNSAT instead of SAT
2. fp.to_real: incorrect results for floats with negative exponents,
   including denormals (which had the same issue via the lz subtraction)

Adds regression test in src/test/fpa.cpp for the to_fp (from real) case.

Agent-Logs-Url: https://github.com/Z3Prover/z3/sessions/56265d81-608a-4768-8c4d-30bd740d89fb

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-05-13 00:11:00 +00:00
Nikolaj Bjorner
070f760501
Merge pull request #8748 from Z3Prover/copilot/fix-floating-point-model-validation
Fix fp.to_real bitvector encoding for denormal floating-point values
2026-02-26 02:21:20 -08:00
copilot-swe-agent[bot]
de3cf18899 Fix fp.to_real encoding for denormal floating-point values
The mk_to_real function in fpa2bv_converter.cpp was missing the
normalization shift adjustment (lz) when computing the real-valued
exponent for denormal floating-point numbers.

When unpack(x, sgn, sig, exp, lz, normalize=true) normalizes a denormal
by shifting the significand left by lz positions, the returned exp does
not account for this shift. All other callers (mk_mul, mk_div, mk_fma)
correctly subtract lz from the exponent, but mk_to_real was missing this.

The fix subtracts zero-extended lz from the sign-extended exp to get the
true exponent, matching the convention used by other FP operations.

Fixes incorrect model with (_ FloatingPoint 2 24) and fp.to_real.

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-02-24 05:22:54 +00:00
copilot-swe-agent[bot]
c0fd3513a2 Fix RNE/RNA overflow-to-infinity in Real-to-FP conversion (soundness bug)
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-02-23 04:34:58 +00:00
Copilot
4b7e02ebdd
Refactor mk_concat call sites to use std::initializer_list (#8494)
* Initial plan

* Refactor mk_concat call sites to use std::initializer_list

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-02-04 13:45:20 -08:00
Copilot
50d04d32bf
Add std::initializer_list overloads for BV and arith operations (#8467)
* Initial plan

* Add std::initializer_list overloads for BV and arith functions

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Update call sites to use initializer_list format for BV and arith functions

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-02-02 10:00:13 -08:00
Copilot
2436943794
Standardize for-loop increments to prefix form (++i) (#8199)
* Initial plan

* Convert postfix to prefix increment in for loops

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Fix member variable increment conversion bug

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Update API generator to produce prefix increments

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-01-14 19:55:31 -08:00
Nikolaj Bjorner
ed5312fbe4 fix #8097 2025-12-21 10:02:47 -08:00
Nikolaj Bjorner
2714dc2623 fix #7661 2025-05-29 17:46:51 +01:00
LeeYoungJoon
0a93ff515d
Centralize and document TRACE tags using X-macros (#7657)
* Introduce X-macro-based trace tag definition
- Created trace_tags.def to centralize TRACE tag definitions
- Each tag includes a symbolic name and description
- Set up enum class TraceTag for type-safe usage in TRACE macros

* Add script to generate Markdown documentation from trace_tags.def
- Python script parses trace_tags.def and outputs trace_tags.md

* Refactor TRACE_NEW to prepend TraceTag and pass enum to is_trace_enabled

* trace: improve trace tag handling system with hierarchical tagging

- Introduce hierarchical tag-class structure: enabling a tag class activates all child tags
- Unify TRACE, STRACE, SCTRACE, and CTRACE under enum TraceTag
- Implement initial version of trace_tag.def using X(tag, tag_class, description)
  (class names and descriptions to be refined in a future update)

* trace: replace all string-based TRACE tags with enum TraceTag
- Migrated all TRACE, STRACE, SCTRACE, and CTRACE macros to use enum TraceTag values instead of raw string literals

* trace : add cstring header

* trace : Add Markdown documentation generation from trace_tags.def via mk_api_doc.py

* trace : rename macro parameter 'class' to 'tag_class' and remove Unicode comment in trace_tags.h.

* trace : Add TODO comment for future implementation of tag_class activation

* trace : Disable code related to tag_class until implementation is ready (#7663).
2025-05-28 14:31:25 +01:00
Nuno Lopes
322e4441b3 Fix conversion of signed 1-bit BV to FP
Fixes https://github.com/AliveToolkit/alive2/issues/1193
2025-04-25 12:38:00 +01:00
Nikolaj Bjorner
328616b8b2 fix build warnings 2024-09-30 17:25:19 -07:00
Christoph M. Wintersteiger
2e83352d42
Fix bug in fp.round_to_integral (#7060) 2023-12-15 08:34:27 -08:00
Christoph M. Wintersteiger
6910a4e18c
Fix to_fp_signed (#7034) 2023-12-03 16:38:06 -08:00
Christoph M. Wintersteiger
9d57bdd2ef
Assorted fixes for floats (#6968)
* Improve 4be26eb543

* Add-on to 0f4f32c5d0

* Fix mk_numeral

* Fix corner-case in fp.div

* Fixes for corner-cases in mk_to_fp_(un)signed

* Fix out-of-range results in mpf_manager::fma

* Further adjustments for fp.to_fp_(un)signed

* fp.to_fp from real can't be NaN

* fp.to_fp from reals: add bounds

* Fix NaN encodings in theory_fpa.

* Fix fp.fma rounding with tiny floats

* Fix literal creation order in theory_fpa
2023-10-29 17:29:42 -07:00
Nikolaj Bjorner
eac7d7576f force to_fp to disambiguate +zero and -zero, #6548, filter unsupported on relevancy
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2023-01-24 12:29:42 -08:00
Nuno Lopes
477b90228e fix #6460: crash in mk_to_ieee_bv_i 2022-11-20 19:19:12 +00:00
Nuno Lopes
0445d6f264 FPA->BV fix unused vars 2022-11-20 19:03:32 +00:00
Nikolaj Bjorner
3c8c80bbac fix #6336 2022-09-11 12:22:49 -07:00
Nikolaj Bjorner
4be26eb543 #6116
handle also nan/oo/0+ as numerals
2022-08-18 04:26:14 -07:00
Nuno Lopes
73a24ca0a9 remove '#include <iostream>' from headers and from unneeded places
It's harmful to have iostream everywhere as it injects functions in the compiled files
2022-06-17 14:10:19 +01:00
Christoph M. Wintersteiger
f77608ed88
Add interpreted versions of unspecified cases of fp.to_ieee_bv and fp.to_real (#6077) 2022-06-04 17:53:23 +01:00
Christoph M. Wintersteiger
6422a6b5a7
Fix rounding bug in to_fp (#6074) 2022-06-04 14:32:08 +01:00
Nikolaj Bjorner
459cfc8eb4 fix #5993
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2022-04-23 19:33:55 +01:00
Christoph M. Wintersteiger
b471ebdf1c
Revert "Fix off-by-one in fp.div bit-blasting. Inspired by #4841 but doesn't quite fix it."
This reverts commit f80fdb4ea3a762cfe95daa0321d9875cfa00c7ae.
2021-10-12 12:45:11 +00:00
Christoph M. Wintersteiger
738783a26c
Fix off-by-one in fp.div bit-blasting. Inspired by #4841 but doesn't quite fix it. 2021-10-12 12:45:11 +00:00
Christoph M. Wintersteiger
c24f438e51
Fix for mk_to_fp_float; pertains to #4841 2021-10-12 12:45:10 +00:00
Christoph M. Wintersteiger
f1acc4b78a
Make fpa2bv debug symbol names optional 2021-10-12 12:45:09 +00:00
Christoph M. Wintersteiger
12c32663c6
Fix error messsages 2021-10-12 12:45:08 +00:00
Nikolaj Bjorner
d36c3faf76 #4880 add interpreted versions of to_bv functions for MBQI quantifier models 2021-09-17 14:23:14 +01:00
Nikolaj Bjorner
c3c5c14ead prepare for min/max i
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2021-09-16 16:23:10 +01:00
Nikolaj Bjorner
6a3ba64afe #5454
@wintersteiger: added code review comment to theory_fpa. The bug seen in #5454 doesn't surface with theory_fpa, though.
2021-08-15 16:48:28 -07:00
Nikolaj Bjorner
5b32c3778f remove out
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2021-07-31 18:00:37 -07:00
Nikolaj Bjorner
f5a08cc54e add wip
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2021-07-31 17:57:36 -07:00
Nikolaj Bjorner
4a6083836a call it data instead of c_ptr for approaching C++11 std::vector convention. 2021-04-13 18:17:35 -07:00
Nikolaj Bjorner
937b61fc88 fix build, refactor 2021-02-02 05:26:57 -08:00
Nikolaj Bjorner
3ae4c6e9de refactor get_sort 2021-02-02 04:45:54 -08:00
Nuno Lopes
4db41c02cc remove some dead code from fpa2bv converter 2021-01-04 17:06:35 +00:00
Christoph M. Wintersteiger
eadf755628
Fix bonus subtraction in fp.rem. Fixes #4564. Fixes most of #2381. 2020-11-06 20:54:10 +00:00
Nikolaj Bjorner
fa58a36b9f
model refactor (#4723)
* refactor model fixing

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>

* missing cond macro

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>

* file

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>

* file

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>

* add macros dependency

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>

* deps and debug

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>

* add dependency to normal forms

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>

* na

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>

* build issues

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>

* compile

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>

* fix leal regression

* complete model fixer

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>

* fold back private functionality to model_finder

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>

* avoid duplicate fixed callbacks

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2020-10-05 14:13:05 -07:00
Nikolaj Bjorner
08a87b102c more fpa
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2020-10-01 17:47:50 -07:00
Nikolaj Bjorner
4cb07a539b more fpa 2020-09-30 19:06:07 -07:00
Nikolaj Bjorner
6708a764f5 move generic functionality for fpa
move generic functionality for fpa to converter/rewriter so it can be used outside of theory_fpa @wintersteiger
2020-09-30 18:50:07 -07:00
Nikolaj Bjorner
72d140334f fixes for #4634
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2020-08-13 08:45:22 -07:00
Christoph M. Wintersteiger
a298091322
Fix for fp.roundToIntegral of tiny, denormal floats. Fixes #4190. 2020-07-17 15:58:01 +00:00
Christoph M. Wintersteiger
2ef57d7f8d
Fix FP rounding of huge exponents. Fixes #3776. 2020-07-17 13:42:12 +00:00
Christoph M. Wintersteiger
ccdae7af24
Fix for corner-case in fp.roundToIntegral. Fixes #2894. 2020-07-16 11:58:18 +00:00
Christoph M. Wintersteiger
3776588375
Clarify bit-blasting of fp.neg. Fixes #4466. 2020-07-08 18:24:08 +00:00
Christoph M. Wintersteiger
c59519bf9c
Add missing FP conversion. Fixes #4470. 2020-07-08 17:56:25 +00:00
Nikolaj Bjorner
399cf75ad4 fpa warning
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2020-04-05 00:55:13 -07:00