-
Notifications
You must be signed in to change notification settings - Fork 28
Added new lemma: mod_false_spec #202
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
Added new lemma: mod_false_spec #202
Conversation
|
Let me know if there is any issue with how I formatted the PR! I'd like to get this lemma added to the standard lib soon. |
|
Our apologies for the slow reply. Could you motivate the usefulness and naming of this lemma a bit? If I saw the LHS in a goal, i'd rewrite with the generic lemma for testbit of mod-2^_, and then with the hypothesis. |
|
Can you clarify what you mean by LHS? Also, which lemma are you referring to when you say "the generic lemma for testbit of mod-2^_"? |
|
Chiming in. At the bottom are the results for N.mod_pow2_bits_low:
forall a n m : N, m < n -> testbit (a mod 2 ^ n) m = testbit a m
N.mod_pow2_bits_high:
forall a n m : N, n <= m -> testbit (a mod 2 ^ n) m = falseBoth of these require proving a relationship about the index tested and the modulo taken, which is fundamentally different than throwing the modulo away and reasoning exclusively about testing the unmodulo'd value a. Perhaps an isolated goal where I think LHS refers to the left-hand-side of the consequent equation, i.e., the An alternative name might be (* results of `Search N.testbit N.modulo 2.`*)
N.bit0_mod: forall a : N, N.b2n (N.testbit a 0) = a mod 2
N.bit0_eqb: forall a : N, N.testbit a 0 = (a mod 2 =? 1)
N.testbit_spec': forall a n : N, N.b2n (N.testbit a n) = (a / 2 ^ n) mod 2
N.mod_pow2_bits_low:
forall a n m : N, m < n -> N.testbit (a mod 2 ^ n) m = N.testbit a m
N.mod_pow2_bits_high:
forall a n m : N, n <= m -> N.testbit (a mod 2 ^ n) m = false
N.testbit_eqb: forall a n : N, N.testbit a n = ((a / 2 ^ n) mod 2 =? 1)
N.testbit_true:
forall a n : N, N.testbit a n = true <-> (a / 2 ^ n) mod 2 = 1
N.testbit_false:
forall a n : N, N.testbit a n = false <-> (a / 2 ^ n) mod 2 = 0 |
|
The lemma I had in mind was Z.testbit_mod_pow2, but indeed, looks like there is no N version of it. If there was, would that solve your use case? (If we want to go ahead with adding this lemma, maybe |
|
I agree with the name |
:/ |
|
Thank you for the contribution! |
|
@ErrWare Thanks for chiming in! |
I added and proved this lemma to the
NBits.vfile: