Zulip Chat Archive
Stream: lean4
Topic: Using a field of a structure in another field ?
Sophie Morel (Mar 22 2024 at 13:24):
The question is in the title: when defining a structure, can I use one of its fields to define another field, and if so how? I thought I saw some things like that in mathlib, but I can't find them anymore. More precisely, I am trying to define a LinearIsometryEquiv
between two normed spaces E
and F
. So I write:
def MyBeautifulIsometry : E ≃ₗᵢ[𝕜] F where
toFun := SomeExpression
map_add' := proof
map_smul' := proof
invFun := SomeComplicatedExpression
left_inv := proof
right_inv := proof
norm_map' := proof that uses the proof of left_inv
Is there a way to make the proof of norm_map'
use the fact that I have already proved left_inv
, or do I need to make a separate lemma ? The expression for invFun
is a bit complicated, so I'd rather not repeat it unless necessary.
Johan Commelin (Mar 22 2024 at 13:29):
The easiest solution is probably to first define MyBeautifulEquiv
.
Sophie Morel (Mar 22 2024 at 13:33):
Johan Commelin said:
The easiest solution is probably to first define
MyBeautifulEquiv
.
That's what I am currently doing, but then I ran into another problem. Now the definition of MyBeautifulIsometry
looks like this:
def MyBeautifulIsometry : E ≃ₗᵢ[𝕜] F :=
{MyBeautifulEquiv with
norm_map' := proof that uses the proof of left_inv}
Then I wanted to put a @[simps!]
before the definition of MyBeautifulIsometry
to generate a bunch of useful lemmas, but the linter complains that some (not all) of them can be proved by simp
. But if I remove the @[simps!]
, then simp
is unable to prove some results later, and I have to manually unfold the definition of MyBeautifulIsometry
. I am not sure what I should do, write out the lemmas myself? I don't know which lemmas @[simps!]
creates, but there seems to be a lot of them.
Ruben Van de Velde (Mar 22 2024 at 13:37):
@[simps!?]
prints the theorems it creates
Ruben Van de Velde (Mar 22 2024 at 13:37):
Did you also put @[simps]
on MyBeautifulEquiv
?
Sophie Morel (Mar 22 2024 at 13:37):
Ruben Van de Velde said:
@[simps!?]
prints the theorems it creates
Ah, thanks !
Sophie Morel (Mar 22 2024 at 13:38):
Ruben Van de Velde said:
Did you also put
@[simps]
onMyBeautifulEquiv
?
I did, was that the fatal mistake?
Sophie Morel (Mar 22 2024 at 14:04):
No it wasn't, I removed the @[simps]
on MyBeautifulEquiv
and the linter still complains for the same reason. It looks like I will have to generate those lemmas by hand. :-(
Yaël Dillies (Mar 22 2024 at 14:40):
Nono, you shouldn't have to. But you need to understand how initialize_simp_projections
works and fiddle with it.
Sophie Morel (Mar 22 2024 at 21:49):
What I ended up doing was see the auto-generated lemmas thanks to @[simps!?]
, see that there were a bunch of them but they all said one of only two things (and not in the way I would like them to say it), extract the two statements, put them in a form I thought was better, make two lemmas out of them and @[simp]
these lemmas. Now simp
can still prove the later statements, and in one case it actually works better. Whew. Let's hope that CI is happy now.
Sophie Morel (Mar 22 2024 at 21:50):
I have no idea how to even start understanding how initialize_simp_projections
works. Is there some doc about it that i should read?
Filippo A. E. Nuccio (Mar 22 2024 at 21:52):
A doc?! You dream... :night_sky: :rofl: My strategy is normally to find a maintainer to stalk until I undersand a bit more...
Sophie Morel (Mar 22 2024 at 21:58):
I like reading stuff by myself and taking time to understand...
I guess I'll just keep pestering people on Zulip instead.
Matthew Ballard (Mar 22 2024 at 21:59):
There is a fairly long doc string in Simps.Basic
Filippo A. E. Nuccio (Mar 22 2024 at 21:59):
Sophie Morel said:
I like reading stuff by myself and taking time to understand...
I guess I'll just keep pestering people on Zulip instead.
I also like this, that's why I called it a "dream"...
Sophie Morel (Mar 22 2024 at 22:01):
Matthew Ballard said:
There is a fairly long doc string in
Simps.Basic
Thanks ! See, Filippo, sometimes it is useful to dream.
Sophie Morel (Mar 22 2024 at 22:02):
Matthew Ballard said:
There is a fairly long doc string in
Simps.Basic
Thanks ! See, Filippo, sometimes it is useful to dream.
Filippo A. E. Nuccio (Mar 22 2024 at 22:07):
OK, then since we're here I have a question: the sentence "generate simplification lemmas for each projection of the instance" does it mean that if my class looks like
myclass (R :Type) [NiceClass R] where
blabla
a [@simps]
creates a sort of myclass.toNiceClass
simp lemma? Because I understand the doc insofar "projections" are concerned, but less so when it speaks about simp lemma for instances.
Adam Topaz (Mar 22 2024 at 22:08):
You could also git grep initialize_simps_projections
in your local mathlib4 folder to see examples of its usage
Sophie Morel (Mar 22 2024 at 22:26):
So something really weird happened with the new version of my PR: I got rid of most of the @[simps!]
-generated lemmas, but I still still had two, say one of them is lemma_1
. Then a bit later I had a lemma_2
, whose proof used lemma_1
(inside a simp
). Once lemma_2
was known, then lemma_1
became provable by simp
, but that would have been a circular proof as I was using lemma_1
to prove lemma_2
. Well, the linter still complained that lemma_1
could be proved by a simp
, and gave a suggested proof that used lemma_2
. :exploding_head:
I solved it by erasing lemma_1
and writing a different proof of lemma_2
, but still, I'm not sure why the linter would do that.
Sophie Morel (Mar 22 2024 at 22:35):
My latest lemma sacrifice has appeased the Mighty Linter! I have a sudden urge to find a church and go light a votive candle in it. :candle: :tada:
Yaël Dillies (Mar 22 2024 at 22:37):
I'm really sorry Lean is costing you so much in candles
Sophie Morel (Mar 22 2024 at 22:39):
It's nothing compared to the time I almost threw my computer out a window while trying to update mathlib; that would have been really expensive. Updating works so much better now.
Last updated: May 02 2025 at 03:31 UTC