-
Notifications
You must be signed in to change notification settings - Fork 632
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
More bitwise in Numbers.Natural.Abstract #18628
Conversation
Thank you for prototyping a Numbers-based proof for these lemmas! Overall looking nice; let's try to make it happen. I am not sure whether the supporting lemmas newly added in this PR are important to expose for use outside Numbers, but maybe they are, and regardless I think we want them non- I would be willing to assign (and merge after working out minor details) but I'll give other stdlib devs the opportunity since this design is substantially influenced by my own work and independent review is good or something. Naming brainstormingHmm, this is one of the cases where syntax-tree-based naming does not lead to unique naming choices. I will throw out some alternatives.
How about Can this definition be used with
I think the
MinorParenthesizing function applications that appear as arguments to infix operations shouldn't be necessary (function application binds tighter). Using The proofs look fine on their own. High-level approach@coq/stdlib-maintainers @proux01 the Numbers-based proofs here are 5x longer than the lia-based proofs versions here, and I'd guess they took more than 5x as long to create (thanks again @Villetaneuse!). I think this comparison is a clear indication that we would benefit from separate |
Regarding high-level approach: I think the ultimate goal here should maybe be to provide a bitblast tactic that can (a) turn bitwise goals and hypotheses into equivalent boolean ones and then (b) discharge with btauto or similar. And then have a library of "convenience lemmas" that are all proven with bitblast, and a core library of "specs of each operation in terms of testbit". I'm not sure what the appropriate way to handle addition and multiplication would be---maybe turn every concrete number into a sum of powers of two, distribute multiplication over addition, turn multiplication by a power of two into left shift, have a rule that turns x + y into x | y when x & y = 0? Or I guess we want (x + y) = x | y + x & y? Thoughts? (Apologies if this PR is the wrong place for this discussion and it belongs in a PR or CEP) |
@JasonGross I think your high-level idea is different from the one I raised, but dependent on it: a bitwise-reasoning tactic would almost surely depend on Z through lia for side condiitons. Zbitwise.v has a tactic that kinda matches what you have in mind, I try not to call it bitblasting to avoid confusion with the easier known-width case. And yes, any separate discussion space would probably be preferred. |
I am also a fan of a split level approach: files with really basic stuff on top of which come tools like lia, bit blasting, you name it, on top of which come the user facing lemma library. With the current structure a major problem ist that many useful lemmas, which could go into the library, are proven in a richer context, so that porting them to the standard library frequently requires a complete rewrite. This is bad. |
Mostly to @andres-erbsen:
@andres-erbsen @JasonGross @MSoegtropIMC
|
I agree the considerations you bring up are relevant and sometimes in tension with using automation for ease of maintenance as I was advocating; we'll have to see for each proposed addition. As for the user-visible dependency graph, my preference would be for NArith to be the path for all theory about N operations and that we should make a new path for only basic theory for (probably less common) use cases that require it. @coqbot run full ci |
CI looks good; windows failure looks unrelated. I believe the precedent is to have a changelog entry for this. I intend to look at this again in a couple of days and to merge if it has a changelog entry by then. |
Thank you!
I can spend a couple hour on this tomorrow If it's ok and people use these lemmas we can easily add more for |
8282175
to
8ed36f0
Compare
I only had a quick look and this mostly looks reasonable. You two are certainly more knowledgable than me about that part of the library, so please go ahead.
It seems we all agree. A PR clearly separating some NArithBase from some more general files that could use lia would certainly be welcome. It could for instance put the current content of |
Thank you @proux01 for your comments. I will take them carefully into account. @andres-erbsen I need to work a little bit more on it, sorry. I think I don't want to add anything more but maybe remove some of theses lemmas and there are two issues:
I made new additions and I'm scared so don't hesitate to criticize them:
So that's more than what you asked for... these seemed reasonable but maybe I got carried away! |
8d28f19
to
555530d
Compare
Sorry for the noise... I made many mistakes I will fix tomorrow. My poor brain still struggles with git. |
52822aa
to
22dab92
Compare
No real progress (except a crazy amount of git shenanigans to fix whitespace issues and errors on my part).
I need to work this out. The best solution would be to move these lemmas from PeanoNat to Numbers/Natural so that we get them at least in N and Nat (maybe also in Z, but I'm scared by division in Z) without any breakage. The naming of I still can't figure how I could remove the "Proper" condition in |
If you're talking about |
Thank you for your comment! I was not saying that the I certainly don't want to add another one of these suboptimal lemmas, hence my problem with my In the end (sorry for thinking oop too much), I really would like to specialize those inherited suboptimal lemmas. I don't know if it's possible. |
@andres-erbsen strange, the "Maintainers are allowed to edit this pull request." box is checked and I was able to push your commit. |
I think for Github (as opposed to Coqbot), maintainers means core devs. |
That sounds bound, it shouldn't IMO. |
At a glance, https://github.com/orgs/coq/teams/contributors?query=role%3Amaintainer+membership%3Achild-team and https://github.com/orgs/coq/teams/contributors?query=role%3Amaintainer indeed seem to contain only the core devs. |
But https://github.com/orgs/coq/teams/contributors?query=role%3Amember+membership%3Achild-team seems to contain everybody. I don't understand much to those github things, let's add it to the agenda of a forthcoming call: https://github.com/coq/coq/wiki/Coq-Call-2024-04-30 |
Yes, that is everybody with write access I believe. There's a table of permissions here. Given that it specifically says "maintainers" in "Maintainers are allowed to edit this pull request", it's not surprising that people with only write access but not maintain access can't push. |
@andres-erbsen Can you confirm that you do not see the sentence "Add more commits by pushing to..." at the bottom of the conversation, as in this screenshot? |
I do see that text 🤔. And apparently I can commit using the github web interface. |
Did you add git@github.com:Villetaneuse/coq.git as your remote or https://github.com/Villetaneuse/coq.git, or did you try to push to refs/pull/18628/head on coq/coq? I believe only the first option (git@github.com:Villetaneuse/coq.git) will work. |
This is to help write more lemmas about bitwise operations.
TODO: Not sure about the names for shift and le names.
Also removed some parentheses around function applications when it's clearer to read.
There is still an issue with `div2_double` and `div2_succ_double`. It's not possible to factor these because there are different such lemmas in `PeanoNat` and `BinNat`. So we settle for `div2_even` and `div2_odd'` in `NBits`. `div2_even` will appear twice (the other name is `div2_double`) in `PeanoNat`. Maybe this is not a big problem? The naming convention in Numbers is now (mostly) that - `even` after an operation name means (2 * n) - `odd` after an operation name means (2 * n + 1) - `even` as a prefix means it is about the boolean operation `even` - `same` for `odd` Unfortunately this clashes with `div2_odd`, hence the name `div2_odd'`. There are still some questions about the `div2` inequalities (some new in `NBits`, some imported from `PeanoNat`); some of which are very similar.
The lemmas `strong_induction_le` and `binary_induction` in `Numbers.Natural` are now marked as `Private_` and hidden from the documentation. Specialized versions (not hidden) are provided for `PeanoNat` and (only `strong_induction`) for `BinNat`. A new test file for these induction lemmas (and other additions in coq#18628) is provided.
035fd03
to
f2212cd
Compare
f2212cd
to
a393f28
Compare
@coqbot run full ci |
@coqbot merge now |
Added:
strong_induction_le
in NOrder (not sure about this one)Even_Odd_induction
in NBits (not sure about capitalization)land_(even|odd)_(even|odd)
,land_le_[lr]
ldiff_(even|odd)_(even|odd)
,ldiff_le_l
le_div2_diag_l
le_shiftl
andshiftr_le
(not sure about names here)ones_0
andones_succ
related to #17043: there, the lemmas are in a new file
NArith.Nbitwise
and proved withlia
@andres-erbsen
lnot_ones_same
is already there, namedlnot_ones
; I've not looked intoPositive
yet.Questions:
lxor
,lor
, ...)?Integer
? Should I try to give the most general statements in NatInt?I don't think it's a final product, but I feel that I need some feedback now.
Fixes / closes #????