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
[Merged by Bors] - feat: make norm_num
erasable (and scoped)
#1364
Conversation
Q's:
|
test/norm_num.lean
Outdated
/- should error: | ||
type mismatch | ||
HEq.rfl | ||
has type | ||
HEq ?m.38198 ?m.38198 : Prop | ||
but is expected to have type | ||
3 ^ 3 + 4 = 31 : Prop |
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.
@thorimur Can you please use successIfFail
here, even though there's no good way to make the with_msg
part work?
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.
Hmm, I'm having a bit of trouble translating the monad operation successIfFail
into this context. Would a syntactic guard_target
be alright? Or is admit frowned upon?
attribute [-norm_num] Mathlib.Meta.NormNum.evalPow
example : 3 ^ 3 + 4 = 31 := by
norm_num1
guard_target =ₛ 3 ^ 3 + 4 = 31
admit
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 think that's a good approach! (Also you can probably change the admit
to rfl
, if you want to get rid of the warning.)
I've never personally tried this, but can you update your |
I'll try! I am a little wary of making all of mathlib4 depend on a non-master branch of std4, though...is that what would be happening? (Also I should link this conversation with @digama0, just so it's visible to everyone) EDIT: I tried, but it doesn't seem to like it enough to build. Maybe someone more familiar with EDIT 2: I removed the commits to make the rebase to master work well...but that seems to have changed the timestamps of all the commits. oh well. |
test/norm_num.lean
Outdated
/- should error: 'Mathlib.Meta.NormNum.evalPow' does not have [norm_num] attribute -/ | ||
/- | ||
attribute [-norm_num] Mathlib.Meta.NormNum.evalPow | ||
attribute [-norm_num] Mathlib.Meta.NormNum.evalPow in |
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.
Could you clarify what these comments refer to? Are they tests which you hoped would work but don't?
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.
Writing attribute [-norm_num] ...
a second time should give the error that the identifier does not have the norm_num
attribute, as it has already been erased. This comment tries to say that if you uncomment those lines of code, it should (and does) give that error—I'll clarify it so that it actually says that :)
Or maybe there's a way to use successIfFail
here?
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.
Clarified! I couldn't find a way to make successIfFail
work, though.
@thorimur Another possible approach to the dependency on leanprover/std4#56: If I understand correctly, @JLimperg made this PR in order to move some |
Ah, great find! Importing |
norm_num
erasablenorm_num
erasable, scoped, and localizable
norm_num
erasable, scoped, and localizablenorm_num
erasable (and scoped)
With #1447, the |
8c1de2f
to
3be6101
Compare
3be6101
to
94bfd5f
Compare
Thanks for the heads up (and the functionality)! :) I've rebased and the import has been updated. Note: I needed to delete some experimental |
bors r+ |
As per #1308, we give `norm_num`s the capability to be erased. E.g. ```lean attribute [-norm_num] Mathlib.Meta.NormNum.evalPow ``` This required us to switch the implementation from a `PersistentEnvExtenstion` to a `ScopedEnvExtension` so that the attribute could be erased in a section (or via `attribute [-norm_num] ... in`) in a way the user would expect. This also easily lets us now make `norm_num` a `local`izable attribute. (I imagine that's a rare occurrence, but may as well—the functionality comes for free with `ScopedEnvExtension`, and all we have to do is *not* prevent it.) The following explains in detail what changes I make, but the actual changes to the code are small. If you're reviewing this, it might make more sense just to read the code.
Pull request successfully merged into master. Build succeeded:
|
norm_num
erasable (and scoped)norm_num
erasable (and scoped)
As per #1308, we give `norm_num`s the capability to be erased. E.g. ```lean attribute [-norm_num] Mathlib.Meta.NormNum.evalPow ``` This required us to switch the implementation from a `PersistentEnvExtenstion` to a `ScopedEnvExtension` so that the attribute could be erased in a section (or via `attribute [-norm_num] ... in`) in a way the user would expect. This also easily lets us now make `norm_num` a `local`izable attribute. (I imagine that's a rare occurrence, but may as well—the functionality comes for free with `ScopedEnvExtension`, and all we have to do is *not* prevent it.) The following explains in detail what changes I make, but the actual changes to the code are small. If you're reviewing this, it might make more sense just to read the code.
As per #1308, we give
norm_num
s the capability to be erased. E.g.attribute [-norm_num] Mathlib.Meta.NormNum.evalPow
This required us to switch the implementation from a
PersistentEnvExtenstion
to aScopedEnvExtension
so that the attribute could be erased in a section (or viaattribute [-norm_num] ... in
) in a way the user would expect.This also easily lets us now make
norm_num
alocal
izable attribute. (I imagine that's a rare occurrence, but may as well—the functionality comes for free withScopedEnvExtension
, and all we have to do is not prevent it.)The following explains in detail what changes I make, but the actual changes to the code are small. If you're reviewing this, it might make more sense just to read the code.
To handle erasure:
erased
fieldname
field to the extension structure and give it an autoparam to capture the name of the norm_num extension at handEntry
s if present, and when adding the attribute, we remove it fromerased
if present—the latter shouldn't ever need to happen, butsimp
apparently does it sometimes (but I don't know why), so I left it in there just to avoid unanticipated edge cases.DiscrTree
and that it's not already erased. If it can't be erased, we throw an error saying that the identifier does not have the norm_num attribute, likesimp
does.To switch to
ScopedEnvExtension
, we:exportEntriesFn
, sinceScopedEnvExtension
performs an equivalent.toArray.reverse
operation automatically.addImportedFn
toofOLeanEntry
plusaddEntry
, with the rest being taken care of byScopedEnvExtension
's built-inaddImportedFn
)entries
field from the state, since that's now taken care of throughScopedEnvExtension
directlyTo make it localizable, we adjust the
add
field when registering the attribute to:kind
setEnv
andaddEntry
toScopedEnvExtension
'sadd
(which callsmodifyEnv
andaddEntry
behind the scenes on appropriately-scoped values)Misc:
norm_num
traces now print the name of the extension used for the rewrite, since it's now available (whereas it wasn't before).