Skip to content

refactor(bv): Simplify bv2nat mapping using right shifts#1320

Open
bclement-ocp wants to merge 3 commits into
OCamlPro:nextfrom
bclement-ocp:bclement/bv2nat-asr
Open

refactor(bv): Simplify bv2nat mapping using right shifts#1320
bclement-ocp wants to merge 3 commits into
OCamlPro:nextfrom
bclement-ocp:bclement/bv2nat-asr

Conversation

@bclement-ocp

Copy link
Copy Markdown
Collaborator

The bv2nat mapping is able to record an integer expression for each bit-vector extraction, but we only need to record arithmetic right shifts since we encode an extraction bv<i, j> as (bv asr j) - (bv asr i) * 2^(j - i + 1).

This ensures we can't accidentally leave bogus extractions in the map.

@bclement-ocp bclement-ocp force-pushed the bclement/bv2nat-asr branch 9 times, most recently from 9bc2300 to eb35a3a Compare September 9, 2025 14:27

(* Add the equality [nat_r = bv2nat(bv_r)]. *)
let add_bv2nat ~ex nat_r bv_r t =
match BitvNormalForm.normal_form bv_r with

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What is the motivation of this change? If I understand well, you replace the normal form of Bitv_rel by the normal form of Bitv?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

(Sorry, realized I have left this comment as "pending" — hopefully it still makes some sense…)

It's not really useful to compute the BitvNormalForm here, the loop in add_bv2nat_abstract already processes this and it's simpler.

The BitvNormalForm distinguishes between constants / variables (concatenation of constants and exactly one variable) / composites (arbitrary concatenations), which is useful when doing reductions. But here we don't really care about this distinction, we just need to be able to iterate on the components of the concatenation to decompose the bv2nat expression — I think I failed to recognise this when writing the code initially and it ended up more convoluted than necessary.

@bclement-ocp bclement-ocp force-pushed the bclement/bv2nat-asr branch from eb35a3a to 7bf6e2a Compare May 22, 2026 14:06
And add it to the lockfile, so that the workflows that use a lock file
can build (:
To simplify review of the next commit.
The bv2nat mapping is able to record an integer expression for each
bit-vector extraction, but we only need to record arithmetic right
shifts since we encode an extraction `bv<i, j>` as `(bv asr j) - (bv asr
i) * 2^(j - i + 1)`.

This ensures we can't accidentally leave bogus extractions in the map.
@bclement-ocp bclement-ocp force-pushed the bclement/bv2nat-asr branch from 7bf6e2a to 4fd9d98 Compare June 8, 2026 11:58
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.

2 participants