-
Notifications
You must be signed in to change notification settings - Fork 299
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] - fix(algebra/ordered*): add norm_cast attribute #3132
Conversation
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.
These all look reasonable! Just suspicious of the two I've tagged, and any others that norm_cast
can already prove. It's not necessarily a problem to tag them anyway, just not needed.
src/algebra/ordered_group.lean
Outdated
@[simp, norm_cast] lemma coe_zero {α : Type*} | ||
[add_monoid α] : ((0 : α) : with_top α) = 0 := rfl | ||
|
||
@[simp, norm_cast] lemma coe_eq_zero {α : Type*} |
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.
If this lemma is proved by norm_cast
it probably shouldn't need to be tagged norm_cast
itself. Does something fail without this? what norm_cast
lemmas does it use? Are other lemmas in the file provable with norm_cast
already?
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.
Answers: 1) Nothing seems to fail if I untag it 2) The only way I know how to answer this is with set_option trace.simplify.rewrite true
, which tells me coe_eq_zero is proved using coe_zero. There must be more to it than this though; norm_cast is doing something simp isn't doing. 3) with_bot.coe_zero can be proved by norm_cast, using with_top.coe_zero (see below)
src/algebra/ordered_group.lean
Outdated
@[simp] lemma coe_zero [add_monoid α] : ((0 : α) : with_bot α) = 0 := rfl | ||
@[norm_cast] lemma coe_zero [add_monoid α] : ((0 : α) : with_bot α) = 0 := rfl | ||
|
||
@[norm_cast] lemma coe_eq_zero {α : Type*} |
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.
As above, the proof is already norm_cast
.
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.
In fact norm_cast
can even prove coe_zero
-- it uses with_top
proofs to prove with_bot
theorems, presumably because the with_bot
instances are defined using with_top
instances rather than being redefined. I don't know if this is good or bad.
You probably want |
I added |
I'm afraid I was wrong when I wrote
because of There shouldn't be an issue importing |
bors merge |
Co-authored-by: Rob Lewis <rob.y.lewis@gmail.com>
Pull request successfully merged into master. Build succeeded: |
…3132) Co-authored-by: Rob Lewis <rob.y.lewis@gmail.com>
A few
with_top
andwith_bot
coercion lemmas didn't have thenorm_cast
attribute. I added them.Comments:
I went to the docs to read about which lemmas should be tagged, but the recent refactor which meant that everything should be tagged
norm_cast
also entailed a cleanup of the docs, so I was a bit in the dark as to exactly what I should be tagging. I went for an "if it moves, norm_cast it" approach on the basis that it would be easier for a reviewer to say "no, you don't tag that kind of lemma" than for a reviewer to say "you missed this one, 100 lines up".The
norm_cast
attribute was not available inorder.bounded_lattice
so I just add the attribute to the coe lemmas from that file in the ordered_group file, where the attribute was available. This can't be the right answer. But again I took the approach that it was better to do the wrong thing than just ignore the problem completely and then forget about it.coe_zero and coe_eq_zero were only written for canonically ordered rings or something -- I've changed it so that they apply to additive monoids. Why can't they just apply to
with_zero
? Is there a problem with defining a zero on with_top X to be the zero of X, whenever X has a zero?