Skip to content
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

feat: linear order is isomorphic to lexicographic sum of two intervals #20409

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

vihdzp
Copy link
Collaborator

@vihdzp vihdzp commented Jan 3, 2025


The material in this PR was previously in #18893.

Open in Gitpod

@vihdzp vihdzp added the t-order Order theory label Jan 3, 2025
@vihdzp vihdzp requested a review from YaelDillies January 3, 2025 02:07
Copy link

github-actions bot commented Jan 3, 2025

PR summary 962da91995

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Order.Hom.Lex (new file) 349

Declarations diff

+ sumCongr
+ sumCongr_symm
+ sumLexComplLeft
+ sumLexComplLeft_apply
+ sumLexComplLeft_symm_apply
+ sumLexComplRight
+ sumLexComplRight_apply
+ sumLexComplRight_symm_apply
+ sumLexCongr
+ sumLexCongr_symm
+ sumLexIicIoi
+ sumLexIicIoi_apply_inl
+ sumLexIicIoi_apply_inr
+ sumLexIicIoi_symm_apply_Iic
+ sumLexIicIoi_symm_apply_Ioi
+ sumLexIicIoi_symm_apply_of_le
+ sumLexIicIoi_symm_apply_of_lt
+ sumLexIioIci
+ sumLexIioIci_apply_inl
+ sumLexIioIci_apply_inr
+ sumLexIioIci_symm_apply_Ici
+ sumLexIioIci_symm_apply_Iio
+ sumLexIioIci_symm_apply_of_le
+ sumLexIioIci_symm_apply_of_lt

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).

Copy link
Collaborator

@YaelDillies YaelDillies left a comment

Choose a reason for hiding this comment

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

Can we have the specialisation to preorders?

Mathlib/Order/RelIso/Set.lean Outdated Show resolved Hide resolved
@YaelDillies YaelDillies added the awaiting-author A reviewer has asked the author a question or requested changes label Jan 3, 2025
@vihdzp
Copy link
Collaborator Author

vihdzp commented Jan 4, 2025

Can we have the specialisation to preorders?

This adds a bunch of imports and makes the PR twice as big. But I think they're an useful addition, so I've done a few changes to accomodate it: mainly, I've moved all of this to its own file.

@vihdzp vihdzp removed the awaiting-author A reviewer has asked the author a question or requested changes label Jan 4, 2025
map_rel_iff' := by simp_rw [Lex.forall]; rintro (a | a) (b | b) <;> simp

@[simp]
theorem sumLexCongr_symm {α₁ α₂ β₁ β₂ : Type*} [LE α₁] [LE α₂] [LE β₁] [LE β₂]
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to have the trans and refl versions of this too.

variable (r x) in
/-- A relation is isomorphic to the lexicographic sum of elements less than `x` and elements not
less than `x`. -/
-- The explicit type signature stops `simp` from complaining.
Copy link
Member

Choose a reason for hiding this comment

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

Where does this complaining happen? If you're able to make a mwe, can you file an issue with it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This complaining is addressed in #20479, I can make this a dependent PR so that this doesn't come up

Copy link
Member

Choose a reason for hiding this comment

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

Do you mean #20475?

Mathlib/Order/Hom/Lex.lean Outdated Show resolved Hide resolved
greater or equal to `x`. -/
def sumLexIioIci : Iio x ⊕ₗ Ici x ≃o α :=
(sumLexCongr (refl _) (setCongr (Ici x) {y | ¬ y < x} (by ext; simp))).trans <|
ofRelIsoLT (RelIso.sumLexComplLeft (· < ·) x)
Copy link
Member

Choose a reason for hiding this comment

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

I think you should be composing with ofLex here somehow. Do we have ofLex as a RelIso for Sum?

Copy link
Collaborator Author

@vihdzp vihdzp Jan 5, 2025

Choose a reason for hiding this comment

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

There's some pretty subtle def-eq finagling going on here: the reason ofRelIsoLT works is because Sum.Lex (· < ·) (· < ·) (Iio x) (Ici x) is def-eq to the < relation on Iio x ⊕ₗ Ici x. I'm not sure this can be made less abusive by just inserting ofLex.

In any case things should probably be fine as long as we keep the actual API free of def-eq abuse.

Copy link
Member

@eric-wieser eric-wieser Jan 5, 2025

Choose a reason for hiding this comment

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

I think we should introduce a Sum.toLexRelIso : Sum.Lex (. < .) (. < .) ≃r (fun a b : Lex (Sum _ _) => a < b) or whatever the true version is, with simp lemmas reducing to toLex, and cast through that here

Comment on lines 87 to 92
theorem sumLexIioIci_apply_inl (a : Iio x) : sumLexIioIci x (Sum.inl a) = a :=
rfl

@[simp]
theorem sumLexIioIci_apply_inr (a : Ici x) : sumLexIioIci x (Sum.inr a) = a :=
rfl
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
theorem sumLexIioIci_apply_inl (a : Iio x) : sumLexIioIci x (Sum.inl a) = a :=
rfl
@[simp]
theorem sumLexIioIci_apply_inr (a : Ici x) : sumLexIioIci x (Sum.inr a) = a :=
rfl
theorem sumLexIioIci_apply_inl (a : Iio x) : sumLexIioIci x (ofLex <| Sum.inl a) = a :=
rfl
@[simp]
theorem sumLexIioIci_apply_inr (a : Ici x) : sumLexIioIci x (ofLex <| Sum.inr a) = a :=
rfl

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It'd be better for simp to instead put toLex on the RHS.

Copy link
Member

Choose a reason for hiding this comment

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

That suggestion doesn't make any sense to me, the type of this bundled map is Lex (Sum (Iio x) (Ici x)) ≃o α, so when applying the map to a Sum you have to call toLex first.

(I realize I made a type above too...)

Copy link
Collaborator Author

@vihdzp vihdzp Jan 5, 2025

Choose a reason for hiding this comment

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

Oh nevermind, I see why what I was saying is nonsense. And in fact I'm missing some other ofLex elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t-order Order theory
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants