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: BitVec.eq_of_getElem_eq #5213

Closed
wants to merge 5 commits into from

Conversation

tobiasgrosser
Copy link
Contributor

No description provided.

@tobiasgrosser tobiasgrosser requested a review from kim-em as a code owner August 30, 2024 05:52
@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 Aug 30, 2024
@leanprover-community-mathlib4-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 a47c590a914e5ed564d07e8ec303c77b81f51c5c --onto 9ce15fb0c61e3a1bee17fd81647ed4d02b4f6c6d. (2024-08-30 06:10:07)

@@ -168,6 +168,17 @@ theorem getMsbD_eq_getMsb?_getD (x : BitVec w) (i : Nat) :
intros
omega

theorem eq_of_getElem_eq {x y : BitVec w}
(pred : ∀ (i : Fin w), x[i] = y[i]) : x = y := by
Copy link
Member

Choose a reason for hiding this comment

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

I think the preferred spelling of this would be to use Nat instead of Fin to be consistent with the bits of the API added in #5200.

Suggested change
(pred : ∀ (i : Fin w), x[i] = y[i]) : x = y := by
(pred : ∀ (i : Nat) (_ : i < w), x[i] = y[i]) : x = y := by

See also the analogous lemma List.ext_getElem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems for BitVec we used historically:

theorem eq_of_getLsbD_eq {x y : BitVec w}
    (pred : ∀(i : Fin w), x.getLsbD i.val = y.getLsbD i.val) : x = y := by

theorem eq_of_getMsbD_eq {x y : BitVec w}
    (pred : ∀(i : Fin w), x.getMsbD i.val = y.getMsbD i.val) : x = y := by

I guess we should at the very least remain consistent within BitVec.

I now added both variants to this PR and ported one theorem to show the code impact. Happy to flip to Nat, but would appreciate a comment why this is preferable over Fin.

@tobiasgrosser tobiasgrosser marked this pull request as draft August 31, 2024 13:39
@kim-em
Copy link
Collaborator

kim-em commented Sep 4, 2024

I don't think it's a good idea to prove theorems about zeroExtend without having proved the corresponding theorems about zeroExtend' first.

Comment on lines +173 to +174
theorem getElem_eq_toNat_testBit (x : BitVec w) (i : Fin w) :
x[i] = x.toNat.testBit i := rfl
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should use separate i : Nat and h : i < w arguments, otherwise it's only applicable for getElem of the coercion of a Fin.

@kim-em
Copy link
Collaborator

kim-em commented Sep 4, 2024

@tobiasgrosser, e.g. my first steps here would be #5247.

@tobiasgrosser
Copy link
Contributor Author

This was resolved in #5247.

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