-
Notifications
You must be signed in to change notification settings - Fork 49
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
rewriting posnum #511
rewriting posnum #511
Conversation
I had a quick look, this looks great. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, here are some comments after a careful reading
of the code. I still need to
- do the doc
- do the extended reals
so more comments will come later.
Main comment: in abstract interpretation, we would say that the abstract domain (>=0, <=0) doesn't have the property of the best abstraction, which causes a bunch of issues (should 0 be considered >=0 or <=0 ? both abstractions are not comparable), the usual fix is to add a 0 in the lattice (as (meet <=0 >=0) so that 0 now has a best abstraction). I could offer a commit with that change if you want.
Comments on entire files
- measure.v and normedtype.v: replace all
%:nngnum
by%:num
? - nngnum.v and posnum.v: shouldn't we just remove these files?
Previously, a posnum was also a nonneg thanks to that Canonical instance in posnum.v Canonical posnum_nngnum x := Nonneg.NngNum x%:num (posnum_ge0 x). it seems we have a regression here (c.f. comments above on one and inv). |
Thank you for your thorough review @proux01, this is much appreciated. I will try to address all your comments.
Yes, I noticed this very late and this additional would make sense.
Yes, I kept these two files as a stub in order to transition smoothly between the new and old code, especially to anticipate a compat with unmerged PRs. But they should disappear in the long run.
I'm not completely sure, this will show up more precisely later in my answer to detailed comments, but the rough reason is that we may not want to rely on an arbitrary signed number, as we may want to guide the resolution a little bit. |
I'm not worried about
Here it is: https://github.com/proux01/analysis/commits/posnum_wip (this branch also adresses all my comments above we agreed upon) |
I added the doc I promised, so AFAICT, the remaining TODOs are:
Extended reals are handled separately in #375 |
@CohenCyril I generalized (c.f. last commit) what was already done for nat to infer some sign information based on the type when no canonical instance matches the head symbol. In particular, I added a "top" catch-all that states that everything is in The main drawback is that canonical structure inference no longer unfolds anything (since the catch-all triggers before). Apart from the few points above (and adding still more canonical instances, but that's endless), I consider this and #375 ready. |
Yes indeed, I think that's a good trade-off. |
Thanks @affeldt-aist or the review. @CohenCyril do you agree if I rebase (and squash a bit/tidy the history) this in order to move towards merging? |
It was requiring an exact abstract value, now any more-precise abstract value also works. For instance `unify AnySign NonNeg` was failing because NonNeg was too precise, whereas `unify_r AnySign NonNeg` now works. This is currently useless because one was only asking for most-precise abstract values, but should become useful in the future.
`expr%:nng` was failing when `expr%:pos` was working because the more precise type `{posnum _}` was infered instead of `{nonneg _}`.
Otherwise, we didn't know wether 0 should be abstracted as >=0 or <=0. The former made max(0, _) fail to be recognized as <=0 while the latter would break min(0, _) similarly.
Previously e%:sgn was failing when an unknown (or no, i.e., for which no canonical instance is registered) operation was encountered in the expression e, now some sign information can be inferred from the type of the unknown sub expression. This is generalizing the canonical instance already existing for the type nat. This is needed in #375 to be able to infer that `|x|%E is non negative when nothing is known on x.
Generalize min and max signed instances from numDomainType to porderType. This way, they can be used for extended reals.
This way, they can also be used for extended reals for instance.
Since there was no opposition, I rebased (thanks @affeldt-aist for the initial rebase!). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I committed a few simplifications that I observed when doing the rebase for PR #559 .
"Pull request authors cannot approve their own pull request", still I'm in favor. |
Looks everyone agrees, let's merge then. |
Generalizing posnum and nonneg and linking the two
TODO:
`|x| > 0
whenx != 0