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

feat: lemmas for Bitvector division when denominator is zero #5609

Merged
merged 6 commits into from
Oct 7, 2024

Conversation

bollu
Copy link
Contributor

@bollu bollu commented Oct 3, 2024

These lemmas explain what happens when the denominator is zero with udiv, umod, sdiv, smod. A follow-up PR will show what happens with smtUDiv and smtSMod, since these need some more bitvector theory.
These lemmas will be used by bv_decide for bitblasting.

The theorems {sdiv, smod}_zero are located after neg theory has been built for the purpose of writing terse proofs.

bollu added 2 commits October 3, 2024 12:09
These lemmas explain what happens when the denominator is zero.
This is used by bv_decide for bitblasting.
@bollu bollu changed the title Udiv denom zero lemmas feat: lemmas for division when denominator is zero Oct 3, 2024
@bollu bollu changed the title feat: lemmas for division when denominator is zero feat: lemmas for Bitvector division when denominator is zero Oct 3, 2024
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Oct 3, 2024
@leanprover-community-bot
Copy link
Collaborator

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 53c5470200eef7c6a185577c4d18106e4cf105aa --onto a4fda010f3d44c02393d5afd5cf05509989daf63. (2024-10-03 17:32:28)

@tobiasgrosser
Copy link
Contributor

I think you can also drop the _eq from the PR description.

@bollu
Copy link
Contributor Author

bollu commented Oct 3, 2024

@tobiasgrosser done, the names are terser now.

@tobiasgrosser
Copy link
Contributor

This LGTM now. Thank you, @bollu.

@tobiasgrosser
Copy link
Contributor

The theorems {sdiv, smod}_zero are located after neg theory has been built for the purpose of writing terse proofs.

Given that neg proofs are unlikely to refer to sdiv/smod proofs, we could consider moving sdiv/smod after neg/sub. I guess @kim-em may have an opinion here.

tobiasgrosser added a commit to opencompl/lean4 that referenced this pull request Oct 6, 2024
Divison proofs are more likely to depend on add/sub/mul proofs than the other
way around. This prepares for leanprover#5609,
which adds division proofs that depend on negation to already be defined.

This PR only moves proofs, but does not change the proofs with the exception
of the last `simp` on toNat_smod being turned into a `simp only` to ensure
the proof stability there.
@tobiasgrosser
Copy link
Contributor

The theorems {sdiv, smod}_zero are located after neg theory has been built for the purpose of writing terse proofs.

Given that neg proofs are unlikely to refer to sdiv/smod proofs, we could consider moving sdiv/smod after neg/sub. I guess @kim-em may have an opinion here.

I implemented this in #5623.

Copy link
Contributor

@hargoniX hargoniX left a comment

Choose a reason for hiding this comment

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

Is udiv the decided simp nf of division on BitVec? For < we have < and slt while udiv seems to be udiv and sdiv instead of / and sdiv?

src/Init/Data/BitVec/Lemmas.lean Outdated Show resolved Hide resolved
tobiasgrosser added a commit to opencompl/lean4 that referenced this pull request Oct 7, 2024
Divison proofs are more likely to depend on add/sub/mul proofs than the other
way around. This prepares for leanprover#5609,
which adds division proofs that depend on negation to already be defined.

This PR only moves proofs, but does not change the proofs with the exception
of the last `simp` on toNat_smod being turned into a `simp only` to ensure
the proof stability there.
@hargoniX hargoniX added this pull request to the merge queue Oct 7, 2024
Merged via the queue into leanprover:master with commit 6312787 Oct 7, 2024
13 checks passed
@bollu
Copy link
Contributor Author

bollu commented Oct 8, 2024

@hargoniX I sent a PR that establishes / and % as normal forms for udiv and umod: #5645

tobiasgrosser added a commit to opencompl/lean4 that referenced this pull request Oct 13, 2024
Divison proofs are more likely to depend on add/sub/mul proofs than the other
way around. This prepares for leanprover#5609, which adds division proofs that depend on
negation to already be defined.

This PR only moves proofs, but does not change the proofs with the exception of
the last simp on toNat_smod being turned into a simp only which was needed for
proof stability.
tobiasgrosser added a commit to opencompl/lean4 that referenced this pull request Oct 13, 2024
Divison proofs are more likely to depend on add/sub/mul proofs than the other
way around. This cleans up leanprover#5609, which added division proofs that rely on
negation to already be defined.
tobiasgrosser added a commit to opencompl/lean4 that referenced this pull request Oct 13, 2024
Divison proofs are more likely to depend on add/sub/mul proofs than the other
way around. This cleans up leanprover#5609, which added division proofs that rely on
negation to already be defined.
github-merge-queue bot pushed a commit that referenced this pull request Oct 13, 2024
Divison proofs are more likely to depend on add/sub/mul proofs than the
other way around. This cleans up
#5609, which added division
proofs that rely on negation to already be defined.
github-merge-queue bot pushed a commit that referenced this pull request Nov 10, 2024
)

This PR is a follow-up to #5609,
where we add lemmas characterizing `smtUDiv` and `smtSDiv`'s behavior
when the denominator is zero.

We build some `slt` theory, connecting it to `msb` for a clean proof. I
chose not to characterize `slt` in terms of `msb` a `simp` lemma, since
I anticipate use cases where we want to keep the arithmetic
interpretation of `slt`.
JovanGerb pushed a commit to JovanGerb/lean4 that referenced this pull request Jan 21, 2025
…anprover#5616)

This PR is a follow-up to leanprover#5609,
where we add lemmas characterizing `smtUDiv` and `smtSDiv`'s behavior
when the denominator is zero.

We build some `slt` theory, connecting it to `msb` for a clean proof. I
chose not to characterize `slt` in terms of `msb` a `simp` lemma, since
I anticipate use cases where we want to keep the arithmetic
interpretation of `slt`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants