-
Notifications
You must be signed in to change notification settings - Fork 534
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
chore: extend GetElem with getElem! and getElem? #3694
Conversation
Mathlib CI status (docs):
|
a7e1a76
to
21f2e42
Compare
71904a5
to
9f675a5
Compare
befe403
to
5a14080
Compare
!bench |
Here are the benchmark results for commit 5a14080. |
src/Init/GetElem.lean
Outdated
|
||
There are other variations on this syntax: | ||
* `arr[i]`: proves the proof side goal by `get_elem_tactic` | ||
* `arr[i]!`: panics if the side goal is false |
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.
* `arr[i]!`: panics if the side goal is false | |
* `arr[i]!`: panics if the side goal is false using `getElem!` in this class |
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.
But I think actually it just expands to getElem!
, which is intended to panic when the value isn't there, right? That is, the side goal is not checked anymore? In that case,
* `arr[i]!`: panics if the side goal is false | |
* `arr[i]!`: invokes `GetElem.getElem!`, which panics if the index is not found |
src/Init/GetElem.lean
Outdated
There are other variations on this syntax: | ||
* `arr[i]`: proves the proof side goal by `get_elem_tactic` | ||
* `arr[i]!`: panics if the side goal is false | ||
* `arr[i]?`: returns `none` if the side goal is false |
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.
* `arr[i]?`: returns `none` if the side goal is false | |
* `arr[i]?`: expands to `GetElem.getElem?`, which returns `none` if the index is not found |
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.
Thanks. I've tried to clarify
Co-authored-by: Mac Malone <[email protected]>
5b99fae
to
569e2ac
Compare
This makes changes to the
GetElem
class so that it does not lead to unnecessary overhead in container likeRBMap
.The changes are to:
getElem?
andgetElem!
part of theGetElem
class so they can be overridden in instances.LawfulGetElem
class that contains correctness theorems forgetElem?
andgetElem!
using the original definitions.GetElem
out ofInit.Prelude
) so that theGetElem
changes are feasible.LawfulGetElem
instances to complement all existingGetElem
instances in Lean core.To reduce the size of the PR, this doesn't do the work of providing new
GetElem
instances forRBMap
,HashMap
etc. That will be done in a separate PR (#3688) that depends on this.