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: add BitVec.toFin_append #36

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft

feat: add BitVec.toFin_append #36

wants to merge 15 commits into from

Conversation

tobiasgrosser
Copy link

@tobiasgrosser tobiasgrosser commented Dec 5, 2024

This adds BitVec.[toInt|toFIn]_append.

An alternative way to state toFin_append is:

[simp] theorem toFin_append (x : BitVec m) (y : BitVec n)
    (h : x.toNat <<< n ||| y.toNat < 2 ^ (m + n) := toNat_append_lt x y) :
    (x ++ y).toFin = @Fin.mk (2^(m+n)) (x.toNat <<< n ||| y.toNat) h  := by

which avoids the toNat_append proof in the match. @bollu reported this is preferable for robustness, but we would appreciate feedback from lean experts.

Comment on lines +1774 to +1776
@[simp] theorem toFin_append {x : BitVec m} {y : BitVec n} :
(x ++ y).toFin = @Fin.mk (2^(m+n)) (x.toNat <<< n ||| y.toNat) (toNat_append_lt x y) := by
ext
Copy link

Choose a reason for hiding this comment

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

I think it's more general to have h be a proof, I have had situations where lean fails to unify correctly with the proposition when we fix the proof to be a a particular proof, even if we have proof irrelevance.

@tobiasgrosser
Copy link
Author

I added a proof template for:

@[simp] theorem toInt_append {x : BitVec n} {y : BitVec m} :
    (x ++ y).toInt = if n == 0 then y.toInt else x.toInt * (2 ^ m) + y.toNat := by

but got a bit stuck in the actual proof. On the other hand, I find the toInt statement actually pretty neat.

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