Skip to content

[Merged by Bors] - fix(Order): fix simp lemma for with{Top/Bot}{Map/Congr}#26787

Closed
wwylele wants to merge 4 commits intoleanprover-community:masterfrom
wwylele:wwylele-hahn-withtopbot
Closed

[Merged by Bors] - fix(Order): fix simp lemma for with{Top/Bot}{Map/Congr}#26787
wwylele wants to merge 4 commits intoleanprover-community:masterfrom
wwylele:wwylele-hahn-withtopbot

Conversation

@wwylele
Copy link
Copy Markdown
Collaborator

@wwylele wwylele commented Jul 5, 2025

This change includes the following in generated simp lemmas:

-@[simp] theorem OrderEmbedding.withBotMap_apply {α : Type u_1} {β : Type u_2} [Preorder α] [Preorder β] (f : α ↪o β) : 
-  ⇑f.withBotMap = Option.map ⇑f
+@[simp] theorem OrderEmbedding.withBotMap_apply {α : Type u_1} {β : Type u_2} [Preorder α] [Preorder β] (f : α ↪o β) :
+  ⇑f.withBotMap = WithBot.map ⇑f

@[simp] theorem OrderEmbedding.withTopMap_apply {α : Type u_1} {β : Type u_2} [Preorder α] [Preorder β] (f : α ↪o β) :
  ⇑f.withTopMap = WithTop.map ⇑f -- unchanged

-@[simp] theorem OrderIso.withBotCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) (a✝ : Option α) : 
-  e.withBotCongr a✝ = Option.map (⇑e) a✝
+@[simp] theorem OrderIso.withBotCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) :
+  ⇑e.withBotCongr = WithBot.map ⇑e

-@[simp] theorem OrderIso.withTopCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) (a✝ : Option α) : 
-  e.withTopCongr a✝ = Option.map (⇑e) a✝
+@[simp] theorem OrderIso.withTopCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) :
+  ⇑e.withTopCongr = WithTop.map ⇑e

The existing @[simps!] lemma on withTopCongr sends the expression to Equiv.optionCongr, which is hard to work with because it losts WithTop/WithBot tags and Option has fewer lemmas. Add these to preserve WithTop/WithBot tags.

I didn't tag these as @[simp] because it would conflict with existing @[simps!]. But to be honest I don't like the existing simps. Can I remove @[simps! apply] from withTopCongr and promote the new lemma as simp normal form?

Open in Gitpod

The existing @[simps!] lemma on withTopCongr sends expression to
Equiv.optionCongr, which is hard to work with because it losts
WithTop/WithBot tags and Option has fewer lemmas. Add these to preserve
WithTop/WithBot tags.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 5, 2025

PR summary 063d2e5dac

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

No declarations were harmed in the making of this PR! 🐙

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@Ruben-VandeVelde
Copy link
Copy Markdown
Contributor

Please do try to replace the existing lemmas, I can't imagine them being used often. Thanks!

@wwylele
Copy link
Copy Markdown
Collaborator Author

wwylele commented Jul 5, 2025

After playing around a bit, I decided to instead change the existing withTopCongr_apply lemma (generated from simps) to sending the expression to WithTop.map. A withTopCongr (some ...)) expression will then be further handled by WithTop.map_coe to reach the simplest form.

I don't know about the deprecation policy for this kind of issue. The new good one will take the the name withTopCongr_apply so it isn't compatible with the old one. Is this ok? At least within mathlib this doesn't have much use yet.

Copy link
Copy Markdown
Contributor

@Ruben-VandeVelde Ruben-VandeVelde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

maintainer merge

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 7, 2025

🚀 Pull request has been placed on the maintainer queue by Ruben-VandeVelde.

@ghost ghost added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Jul 7, 2025
Comment on lines 164 to 166
def withTopCongr (e : α ≃o β) : WithTop α ≃o WithTop β :=
{ e.toOrderEmbedding.withTopMap with
toEquiv := e.toEquiv.optionCongr }
Copy link
Copy Markdown
Member

@eric-wieser eric-wieser Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue we should redefine this so that simps does do the right thing; I think in practice that would look like

Suggested change
def withTopCongr (e : α ≃o β) : WithTop α ≃o WithTop β :=
{ e.toOrderEmbedding.withTopMap with
toEquiv := e.toEquiv.optionCongr }
def withTopCongr (e : α ≃o β) : WithTop α ≃o WithTop β where
toFun := WithTop.map e
invFun := WithTop.map e.symm
__ := e.toOrderEmbedding.withTopMap
__ := e.toEquiv.optionCongr

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! Just did a quick test that the new simp from this can still correctly simplify e.withTopCongr (WithTop.some ...), so I am using the code as-is

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I said it too fast... this leaded to a rabbit hole in OrderEmbedding.withTop/BotCongr's bad def. Currently their generated apply simp don't even have the same signature:

Guess there is more to fix

@wwylele wwylele changed the title feat(Order): Add apply lemma for withTopCongr/withBotCongr refactor(Order): fix simp lemma for with{Top/Bot}{Map/Congr} Jul 7, 2025
@wwylele wwylele changed the title refactor(Order): fix simp lemma for with{Top/Bot}{Map/Congr} fix(Order): fix simp lemma for with{Top/Bot}{Map/Congr} Jul 7, 2025
@wwylele
Copy link
Copy Markdown
Collaborator Author

wwylele commented Jul 7, 2025

I pushed a change to unify the four simp lemmas across OrderEmbedding and OrderIso (see PR description)

@wwylele wwylele requested a review from eric-wieser July 7, 2025 21:13
Copy link
Copy Markdown
Contributor

@Ruben-VandeVelde Ruben-VandeVelde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

maintainer merge

@github-actions
Copy link
Copy Markdown

🚀 Pull request has been placed on the maintainer queue by Ruben-VandeVelde.

@bryangingechen
Copy link
Copy Markdown
Contributor

Thanks!
bors r+

@ghost ghost added ready-to-merge This PR has been sent to bors. and removed maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. labels Jul 11, 2025
mathlib-bors bot pushed a commit that referenced this pull request Jul 11, 2025
This change includes the following in generated simp lemmas:
```diff
-@[simp] theorem OrderEmbedding.withBotMap_apply {α : Type u_1} {β : Type u_2} [Preorder α] [Preorder β] (f : α ↪o β) : 
-  ⇑f.withBotMap = Option.map ⇑f
+@[simp] theorem OrderEmbedding.withBotMap_apply {α : Type u_1} {β : Type u_2} [Preorder α] [Preorder β] (f : α ↪o β) :
+  ⇑f.withBotMap = WithBot.map ⇑f

@[simp] theorem OrderEmbedding.withTopMap_apply {α : Type u_1} {β : Type u_2} [Preorder α] [Preorder β] (f : α ↪o β) :
  ⇑f.withTopMap = WithTop.map ⇑f -- unchanged

-@[simp] theorem OrderIso.withBotCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) (a✝ : Option α) : 
-  e.withBotCongr a✝ = Option.map (⇑e) a✝
+@[simp] theorem OrderIso.withBotCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) :
+  ⇑e.withBotCongr = WithBot.map ⇑e

-@[simp] theorem OrderIso.withTopCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) (a✝ : Option α) : 
-  e.withTopCongr a✝ = Option.map (⇑e) a✝
+@[simp] theorem OrderIso.withTopCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) :
+  ⇑e.withTopCongr = WithTop.map ⇑e
```
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Jul 11, 2025

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title fix(Order): fix simp lemma for with{Top/Bot}{Map/Congr} [Merged by Bors] - fix(Order): fix simp lemma for with{Top/Bot}{Map/Congr} Jul 11, 2025
@mathlib-bors mathlib-bors bot closed this Jul 11, 2025
BeibeiX0 pushed a commit to BeibeiX0/mathlib4 that referenced this pull request Jul 16, 2025
…ommunity#26787)

This change includes the following in generated simp lemmas:
```diff
-@[simp] theorem OrderEmbedding.withBotMap_apply {α : Type u_1} {β : Type u_2} [Preorder α] [Preorder β] (f : α ↪o β) : 
-  ⇑f.withBotMap = Option.map ⇑f
+@[simp] theorem OrderEmbedding.withBotMap_apply {α : Type u_1} {β : Type u_2} [Preorder α] [Preorder β] (f : α ↪o β) :
+  ⇑f.withBotMap = WithBot.map ⇑f

@[simp] theorem OrderEmbedding.withTopMap_apply {α : Type u_1} {β : Type u_2} [Preorder α] [Preorder β] (f : α ↪o β) :
  ⇑f.withTopMap = WithTop.map ⇑f -- unchanged

-@[simp] theorem OrderIso.withBotCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) (a✝ : Option α) : 
-  e.withBotCongr a✝ = Option.map (⇑e) a✝
+@[simp] theorem OrderIso.withBotCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) :
+  ⇑e.withBotCongr = WithBot.map ⇑e

-@[simp] theorem OrderIso.withTopCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) (a✝ : Option α) : 
-  e.withTopCongr a✝ = Option.map (⇑e) a✝
+@[simp] theorem OrderIso.withTopCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) :
+  ⇑e.withTopCongr = WithTop.map ⇑e
```
callesonne pushed a commit to callesonne/mathlib4 that referenced this pull request Jul 24, 2025
…ommunity#26787)

This change includes the following in generated simp lemmas:
```diff
-@[simp] theorem OrderEmbedding.withBotMap_apply {α : Type u_1} {β : Type u_2} [Preorder α] [Preorder β] (f : α ↪o β) : 
-  ⇑f.withBotMap = Option.map ⇑f
+@[simp] theorem OrderEmbedding.withBotMap_apply {α : Type u_1} {β : Type u_2} [Preorder α] [Preorder β] (f : α ↪o β) :
+  ⇑f.withBotMap = WithBot.map ⇑f

@[simp] theorem OrderEmbedding.withTopMap_apply {α : Type u_1} {β : Type u_2} [Preorder α] [Preorder β] (f : α ↪o β) :
  ⇑f.withTopMap = WithTop.map ⇑f -- unchanged

-@[simp] theorem OrderIso.withBotCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) (a✝ : Option α) : 
-  e.withBotCongr a✝ = Option.map (⇑e) a✝
+@[simp] theorem OrderIso.withBotCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) :
+  ⇑e.withBotCongr = WithBot.map ⇑e

-@[simp] theorem OrderIso.withTopCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) (a✝ : Option α) : 
-  e.withTopCongr a✝ = Option.map (⇑e) a✝
+@[simp] theorem OrderIso.withTopCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) :
+  ⇑e.withTopCongr = WithTop.map ⇑e
```
hrmacbeth pushed a commit to szqzs/mathlib4 that referenced this pull request Jul 28, 2025
…ommunity#26787)

This change includes the following in generated simp lemmas:
```diff
-@[simp] theorem OrderEmbedding.withBotMap_apply {α : Type u_1} {β : Type u_2} [Preorder α] [Preorder β] (f : α ↪o β) : 
-  ⇑f.withBotMap = Option.map ⇑f
+@[simp] theorem OrderEmbedding.withBotMap_apply {α : Type u_1} {β : Type u_2} [Preorder α] [Preorder β] (f : α ↪o β) :
+  ⇑f.withBotMap = WithBot.map ⇑f

@[simp] theorem OrderEmbedding.withTopMap_apply {α : Type u_1} {β : Type u_2} [Preorder α] [Preorder β] (f : α ↪o β) :
  ⇑f.withTopMap = WithTop.map ⇑f -- unchanged

-@[simp] theorem OrderIso.withBotCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) (a✝ : Option α) : 
-  e.withBotCongr a✝ = Option.map (⇑e) a✝
+@[simp] theorem OrderIso.withBotCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) :
+  ⇑e.withBotCongr = WithBot.map ⇑e

-@[simp] theorem OrderIso.withTopCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) (a✝ : Option α) : 
-  e.withTopCongr a✝ = Option.map (⇑e) a✝
+@[simp] theorem OrderIso.withTopCongr_apply {α : Type u_1} {β : Type u_2} [PartialOrder α] [PartialOrder β] (e : α ≃o β) :
+  ⇑e.withTopCongr = WithTop.map ⇑e
```
@wwylele wwylele deleted the wwylele-hahn-withtopbot branch September 2, 2025 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge This PR has been sent to bors. t-order Order theory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants