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

Operations for bit representation of Nat and BitVec. #366

Merged
merged 31 commits into from
Nov 28, 2023
Merged

Conversation

joehendrix
Copy link
Contributor

@joehendrix joehendrix commented Nov 15, 2023

This is a large PR that has operations for working with Nat and BitVec as functions from indices to Bool. In particular it builds upon work in #314 and #358

Std/Data/BitVec/Basic.lean Outdated Show resolved Hide resolved
Std/Data/BitVec/Basic.lean Outdated Show resolved Hide resolved
@joehendrix joehendrix force-pushed the bitvec_scan branch 4 times, most recently from 8b340c3 to 2fd27f9 Compare November 16, 2023 18:37
@joehendrix joehendrix changed the title WIP: Bitvector scan for circuits. Bitvector scan for circuits. Nov 23, 2023
@joehendrix joehendrix changed the title Bitvector scan for circuits. Operations for testing bit values at indices and working with a bit representation of Nat and BitVec. Nov 23, 2023
@joehendrix joehendrix changed the title Operations for testing bit values at indices and working with a bit representation of Nat and BitVec. Operations for bit representation of Nat and BitVec. Nov 23, 2023
Std/Data/BitVec/Basic.lean Outdated Show resolved Hide resolved
Std/Data/BitVec/Folds.lean Outdated Show resolved Hide resolved
Std/Data/BitVec/Folds.lean Outdated Show resolved Hide resolved
Std/Data/BitVec/Folds.lean Outdated Show resolved Hide resolved
Std/Data/BitVec/Folds.lean Outdated Show resolved Hide resolved
Std/Data/BitVec/Folds.lean Outdated Show resolved Hide resolved
Std/Data/BitVec/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/BitVec/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/BitVec/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/BitVec/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/BitVec/Lemmas.lean Outdated Show resolved Hide resolved
@joehendrix
Copy link
Contributor Author

@semorrison I think I've done all the changes you suggested.

@joehendrix joehendrix added will-merge-soon PR will be merged soon. Any concerns should be raised quickly. and removed awaiting-review This PR is ready for review; the author thinks it is ready to be merged. labels Nov 28, 2023
@joehendrix joehendrix merged commit a93d4aa into main Nov 28, 2023
2 checks passed
@joehendrix joehendrix deleted the bitvec_scan branch November 28, 2023 16:53
kim-em added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 29, 2023
Comment on lines +288 to +291
theorem testBit_bitwise
(false_false_axiom : f false false = false) (x y i : Nat)
: (bitwise f x y).testBit i = f (x.testBit i) (y.testBit i) := by
induction i using Nat.strongInductionOn generalizing x y with
Copy link
Member

Choose a reason for hiding this comment

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

This formatting looks pretty weird to me

@eric-wieser eric-wieser mentioned this pull request Nov 29, 2023
2 tasks
Comment on lines +13 to +14
theorem toNat_eq (x y : BitVec n) : x = y ↔ x.toNat = y.toNat :=
Iff.intro (congrArg BitVec.toNat) eq_of_toNat_eq
Copy link
Member

Choose a reason for hiding this comment

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

Mathlib has this lemma, but calls it toNat_inj and states it in reverse.

@joehendrix joehendrix removed the will-merge-soon PR will be merged soon. Any concerns should be raised quickly. label Nov 29, 2023
alexkeizer pushed a commit to leanprover-community/mathlib4 that referenced this pull request Nov 30, 2023
revert

.

fix a bit

blech

one more

comment out broken and unused results

chore: bump Std

remove redundant simp lemmas

cleanup

fix: make `Nat.testBit_bitwise` a simp-lemma again.

This fixes the Int.testbit_bitwise proofs

fix `castNum_testBit`

fix `testBit_eq_inth`

fixes

golf

golf

Apply suggestions from code review

Co-authored-by: Eric Wieser <[email protected]>

fix whitespace

fix name conflict

more efficient

restore lemma

feat: Mapping extreme points under continuous maps (#8574)

Prove that extreme points are preserved under affine equivalences, and the less trivial statement that a continuous affine map sends extreme points of a compact set to a superset of the extreme
points of the image of that set.

Also fix a few name and tweak the API a bit.

Co-authored-by: Yury G. Kudryashov <[email protected]>

chore(Profinite): allow more universe flexibility in Profinite/CofilteredLimit (#8613)

We allow the indexing category for the cofiltered limit in the result `Profinite.exists_locallyConstant` to live in a smaller universe than our profinite sets.

feat(CategoryTheory): `Preregular` and `FinitaryPreExtensive` implies `Precoherent` (#8643)

We prove some results about effective epimorphisms which allow us to deduce that a category which is `FinitaryPreExtensive` and `Preregular` is also `Precoherent`.

feat(Analysis/Seminorm): add more `*ball_smul_*ball` (#8724)

We had `ball_smul_ball` and `closedBall_smul_closedBall`.
Add versions with mixed `ball` and `closedBall`.
Also move this lemmas below and golf the proofs.

feat: the annihilator of the kernel of the trace form of a Lie module is contained in the span of its weights (#8739)

fix breakage in BitVec lemmas
alexkeizer pushed a commit to leanprover-community/mathlib4 that referenced this pull request Nov 30, 2023
revert

.

fix a bit

blech

one more

comment out broken and unused results

chore: bump Std

remove redundant simp lemmas

cleanup

fix: make `Nat.testBit_bitwise` a simp-lemma again.

This fixes the Int.testbit_bitwise proofs

fix `castNum_testBit`

fix `testBit_eq_inth`

fixes

golf

golf

Apply suggestions from code review

Co-authored-by: Eric Wieser <[email protected]>

fix whitespace

fix name conflict

more efficient

restore lemma

feat: Mapping extreme points under continuous maps (#8574)

Prove that extreme points are preserved under affine equivalences, and the less trivial statement that a continuous affine map sends extreme points of a compact set to a superset of the extreme
points of the image of that set.

Also fix a few name and tweak the API a bit.

Co-authored-by: Yury G. Kudryashov <[email protected]>

chore(Profinite): allow more universe flexibility in Profinite/CofilteredLimit (#8613)

We allow the indexing category for the cofiltered limit in the result `Profinite.exists_locallyConstant` to live in a smaller universe than our profinite sets.

feat(CategoryTheory): `Preregular` and `FinitaryPreExtensive` implies `Precoherent` (#8643)

We prove some results about effective epimorphisms which allow us to deduce that a category which is `FinitaryPreExtensive` and `Preregular` is also `Precoherent`.

feat(Analysis/Seminorm): add more `*ball_smul_*ball` (#8724)

We had `ball_smul_ball` and `closedBall_smul_closedBall`.
Add versions with mixed `ball` and `closedBall`.
Also move this lemmas below and golf the proofs.

feat: the annihilator of the kernel of the trace form of a Lie module is contained in the span of its weights (#8739)

fix breakage in BitVec lemmas
else
simp [h]

theorem toNat_append (x : BitVec m) (y : BitVec n) : (x ++ y).toNat = x.toNat <<< n ||| y.toNat :=
Copy link
Member

Choose a reason for hiding this comment

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

In mathlib this had arguments msbs and lsbs for clarity; it feels like a regression to rename them back to x and y.

mathlib-bors bot pushed a commit to leanprover-community/mathlib4 that referenced this pull request Nov 30, 2023
Notably leanprover-community/batteries#366 changed the definition of `testBit` (to something equivalent) when upstreaming it, which broke a handful of proofs.

Other conflicting changes in Std, resolved for now by priming the mathlib name:

* `Std.BitVec.adc`: the type was changed from `BitVec (n + 1)` to `Bool × BitVec w`
* `Nat.mul_add_mod`: the type was changed from `(a * b + c) % b = c % b` to `(b * a + c) % b = c % b`

[Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/348111-std4/topic/Mathlib.20bump.20for.20.22Operations.20for.20bit.20representation.20of.20.2E.2E.2E.22/near/404801443)



Co-authored-by: Scott Morrison <[email protected]>
Co-authored-by: Alex Keizer <[email protected]>
Co-authored-by: Eric Wieser <[email protected]>
awueth pushed a commit to leanprover-community/mathlib4 that referenced this pull request Dec 19, 2023
Notably leanprover-community/batteries#366 changed the definition of `testBit` (to something equivalent) when upstreaming it, which broke a handful of proofs.

Other conflicting changes in Std, resolved for now by priming the mathlib name:

* `Std.BitVec.adc`: the type was changed from `BitVec (n + 1)` to `Bool × BitVec w`
* `Nat.mul_add_mod`: the type was changed from `(a * b + c) % b = c % b` to `(b * a + c) % b = c % b`

[Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/348111-std4/topic/Mathlib.20bump.20for.20.22Operations.20for.20bit.20representation.20of.20.2E.2E.2E.22/near/404801443)



Co-authored-by: Scott Morrison <[email protected]>
Co-authored-by: Alex Keizer <[email protected]>
Co-authored-by: Eric Wieser <[email protected]>
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.

5 participants