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

[Bitv] Add support for the SMT-LIB2's BV primitives #669

Closed
wants to merge 37 commits into from
Closed

[Bitv] Add support for the SMT-LIB2's BV primitives #669

wants to merge 37 commits into from

Conversation

hra687261
Copy link
Contributor

@hra687261 hra687261 commented Jun 20, 2023

See #625

@bclement-ocp bclement-ocp changed the title [WIP] Add support to the SMT-LIB2's BV primitives [WIP] Add support for the SMT-LIB2's BV primitives Jun 20, 2023
@bclement-ocp bclement-ocp mentioned this pull request Jun 26, 2023
5 tasks
@hra687261 hra687261 marked this pull request as ready for review June 26, 2023 15:15
@hra687261 hra687261 modified the milestone: 2.5.0 Jun 26, 2023
@hra687261 hra687261 changed the title [WIP] Add support for the SMT-LIB2's BV primitives [Bitv] Add support for the SMT-LIB2's BV primitives Jun 26, 2023
Copy link
Collaborator

@bclement-ocp bclement-ocp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I made a first pass with a few comments/questions. There are still things I don't understand, I will do a second pass tomorrow.

src/lib/structures/symbols.mli Outdated Show resolved Hide resolved
src/lib/structures/symbols.ml Outdated Show resolved Hide resolved
src/lib/structures/symbols.mli Outdated Show resolved Hide resolved
src/lib/structures/expr.ml Outdated Show resolved Hide resolved
src/lib/structures/expr.ml Outdated Show resolved Hide resolved
src/lib/reasoners/bitv.ml Outdated Show resolved Hide resolved
src/lib/reasoners/bitv.ml Outdated Show resolved Hide resolved
src/lib/reasoners/bitv.ml Outdated Show resolved Hide resolved
src/lib/reasoners/bitv.ml Show resolved Hide resolved
src/lib/reasoners/bitv.ml Outdated Show resolved Hide resolved
@bclement-ocp
Copy link
Collaborator

@hra687261 you mentioned crashes, can you add the crashing test cases here?

@hra687261
Copy link
Contributor Author

Done the crashing tests are under tests/dolmen/bitv/errors and goals that should be proven but aren't are under tests/dolmen/bitv/todo
(Although there might be more since I haven't ran the benches in a while)

bclement-ocp added a commit to bclement-ocp/alt-ergo that referenced this pull request Jul 7, 2023
This patch adds support for the negation (bvnot) operator in the
bitvector solver.

There are two components to this support:

 - First, the union-find data structure used by the solver is replaced
   with an actual union-find data structure implemented using Tarjan's
   efficient algorithm, rather than using an implementation with sets
   and maps.

 - Second, the new union-find data structure is augmented with a link
   between a class representative and the representative of its negated
   class. When merging two classes, their negated classes are merged as
   well (and, in particular, if a class gets forced to all ones or all
   zeroes, its negated classes gets forced to the other bit value). If a
   class is ever merged with its negated class, the problem is
   unsolvable.

The implementation is not necessarily the most efficient (e.g. we
iterate over lists to negate them rather than directly creating the
negated variables at several points), but it should be fairly simple and
requires few changes to the existing solver infrastructure. The
performance can be improved later if necessary.

This extracted and simplified from part OCamlPro#669 and works towards better
support for OCamlPro#625.
bclement-ocp pushed a commit to bclement-ocp/alt-ergo that referenced this pull request Jul 10, 2023
This is the first part in a reloaded version of OCamlPro#669.  It only includes
parsing and typechecking support for the bit-vector primitives: bvnot,
bvand, bvor, bv2nat and nat2bv (called int2bv because it also accepts
negative inputs) are treated as uninterpreted functions; the other
operators defined in the SMT-LIB are defined in terms of these
primitives and of the existing `concat` and `extract` operators.

The support for the bit-vector functions will be improved in separate
PRs focusing on the bv2nat/nat2bv interaction, so that we are at least
able to solve simple arithmetic goals. In the future, we might want to
consider additional strategies (e.g. bitblasting), but that is out of
scope for now.

Following the discussion in OCamlPro#669, including the apparent restrictions
around the building of "ite" in the theory and the lack of
infrastructure for actually doing simplifications there (at least for
now), the definition of most functions are moved back to `Expr.ml`. The
PR also includes a few helper functions to help write the definition of
the bitvector operators more concisely, which should help ensuring that
they are correct.
bclement-ocp added a commit to bclement-ocp/alt-ergo that referenced this pull request Jul 10, 2023
This is the first part in a reloaded version of OCamlPro#669.  It only includes
parsing and typechecking support for the bit-vector primitives: bvnot,
bvand, bvor, bv2nat and nat2bv (called int2bv because it also accepts
negative inputs) are treated as uninterpreted functions; the other
operators defined in the SMT-LIB are defined in terms of these
primitives and of the existing `concat` and `extract` operators.

The support for the bit-vector functions will be improved in separate
PRs focusing on the bv2nat/nat2bv interaction, so that we are at least
able to solve simple arithmetic goals. In the future, we might want to
consider additional strategies (e.g. bitblasting), but that is out of
scope for now.

Following the discussion in OCamlPro#669, including the apparent restrictions
around the building of "ite" in the theory and the lack of
infrastructure for actually doing simplifications there (at least for
now), the definition of most functions are moved back to `Expr.ml`. The
PR also includes a few helper functions to help write the definition of
the bitvector operators more concisely, which should help ensuring that
they are correct.
bclement-ocp added a commit to bclement-ocp/alt-ergo that referenced this pull request Jul 11, 2023
This is the first part in a reloaded version of OCamlPro#669.  It only includes
parsing and typechecking support for the bit-vector primitives: bvnot,
bvand, bvor, bv2nat and nat2bv (called int2bv because it also accepts
negative inputs) are treated as uninterpreted functions; the other
operators defined in the SMT-LIB are defined in terms of these
primitives and of the existing `concat` and `extract` operators.

The support for the bit-vector functions will be improved in separate
PRs focusing on the bv2nat/nat2bv interaction, so that we are at least
able to solve simple arithmetic goals. In the future, we might want to
consider additional strategies (e.g. bitblasting), but that is out of
scope for now.

Following the discussion in OCamlPro#669, including the apparent restrictions
around the building of "ite" in the theory and the lack of
infrastructure for actually doing simplifications there (at least for
now), the definition of most functions are moved back to `Expr.ml`. The
PR also includes a few helper functions to help write the definition of
the bitvector operators more concisely, which should help ensuring that
they are correct.
bclement-ocp added a commit to bclement-ocp/alt-ergo that referenced this pull request Jul 11, 2023
This is a full rewrite of the Canonizer module in the bitvector solver.
The new Canonizer (now called Canon) performs the same work as the
old one, but does so slightly differently -- in particular, we now build
terms lazily, which allows us to ignore parts of the tree for
performance.

The main motivation is actually not performance, but the ability to
integrate bitwise operators (bvnot, bvand, bvor) into the canonizer in a
more natural way. This is essentially the same architecture as that of
`make_aux` from OCamlPro#669, but lifted to use a simple custom type (`view`) to
avoid building new terms during canonization and benefit from match
exhaustiveness checks.
bclement-ocp added a commit to bclement-ocp/alt-ergo that referenced this pull request Jul 11, 2023
This is a full rewrite of the Canonizer module in the bitvector solver.
The new Canonizer (now called Canon) performs the same work as the
old one, but does so slightly differently -- in particular, we now build
terms lazily, which allows us to ignore parts of the tree for
performance.

The main motivation is actually not performance, but the ability to
integrate bitwise operators (bvnot, bvand, bvor) into the canonizer in a
more natural way. This is essentially the same architecture as that of
`make_aux` from OCamlPro#669, but lifted to use a simple custom type (`view`) to
avoid building new terms during canonization and benefit from match
exhaustiveness checks.
bclement-ocp added a commit that referenced this pull request Jul 12, 2023
This is the first part in a reloaded version of #669.  It only includes
parsing and typechecking support for the bit-vector primitives: bvnot,
bvand, bvor, bv2nat and nat2bv (called int2bv because it also accepts
negative inputs) are treated as uninterpreted functions; the other
operators defined in the SMT-LIB are defined in terms of these
primitives and of the existing `concat` and `extract` operators.

The support for the bit-vector functions will be improved in separate
PRs focusing on the bv2nat/nat2bv interaction, so that we are at least
able to solve simple arithmetic goals. In the future, we might want to
consider additional strategies (e.g. bitblasting), but that is out of
scope for now.

Following the discussion in #669, including the apparent restrictions
around the building of "ite" in the theory and the lack of
infrastructure for actually doing simplifications there (at least for
now), the definition of most functions are moved back to `Expr.ml`. The
PR also includes a few helper functions to help write the definition of
the bitvector operators more concisely, which should help ensuring that
they are correct.
bclement-ocp added a commit that referenced this pull request Jul 12, 2023
This is a full rewrite of the Canonizer module in the bitvector solver.
The new Canonizer (now called Canon) performs the same work as the
old one, but does so slightly differently -- in particular, we now build
terms lazily, which allows us to ignore parts of the tree for
performance.

The main motivation is actually not performance, but the ability to
integrate bitwise operators (bvnot, bvand, bvor) into the canonizer in a
more natural way. This is essentially the same architecture as that of
`make_aux` from #669, but lifted to use a simple custom type (`view`) to
avoid building new terms during canonization and benefit from match
exhaustiveness checks.
@Halbaroth
Copy link
Collaborator

Is it ready for review?

@bclement-ocp
Copy link
Collaborator

Sorry, this one should be closed, it has been split off into #733 and #730

@hra687261 hra687261 deleted the bv-primitives branch May 12, 2024 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants