This repository was archived by the owner on Jul 24, 2024. It is now read-only.
refactor(order/well_founded): typeclasses for well-founded < and >#15023
Closed
refactor(order/well_founded): typeclasses for well-founded < and >#15023
< and >#15023Conversation
vihdzp
commented
Jun 28, 2022
| dec_tac := tactic.assumption } | ||
|
|
||
| @[priority 100] -- see Note [lower instance priority] | ||
| instance is_well_order.is_strict_total_order {α} (r : α → α → Prop) [is_well_order α r] : |
Collaborator
Author
There was a problem hiding this comment.
I don't know why these redundant typeclasses were here. I presume it's to short-circuit the search, but is this standard practice? If so, I'll add these again.
src/order/well_founded.lean
Outdated
| classical.some (H.has_min p h) | ||
| /-- A minimal element of a nonempty set with respect to a well-founded relation. See also | ||
| `well_founded_lt.min` and `well_founded_gt.max`. -/ | ||
| noncomputable def min [is_well_founded α r] (s : set α) (hs : s.nonempty) : α := |
Collaborator
Author
There was a problem hiding this comment.
I've decided to make s explicit in all of these theorems, since you can't really infer s from a proof of s.nonempty a lot of the time.
Collaborator
Author
|
The PR builds now! Right now the diff is huge, but |
This was referenced Jul 8, 2022
Collaborator
Author
|
On second thought, I definitely scope crept here. I'll introduce the typeclasses in a separate PR and slowly implement them throughout the library. |
bors bot
pushed a commit
that referenced
this pull request
Jul 27, 2022
…15399) # Well-founded typeclasses We introduce a new unbundled typeclass `is_well_founded` for a general well-founded relation, and reducible defs `well_founded_lt` and `well_founded_gt` for well-founded `<` and `>` specifically, to be used as mixins. For now, all we do is specialize only the most basic API on well-founded relations to these new typeclasses. This is just an initial development. If this is merged, a subsequent PR will redefine `is_well_order` in terms of `is_well_founded` (and remove the redundant `irrefl` field). Further PRs will focus on providing all the possible instances for this new typeclass, and actually using it throughout mathlib. Moved from #15023. ## Why do we want this? Here's the part where I justify why this is a good thing we want in mathlib. ### Well-ordered `<` There is a need to talk about well-ordered `<` relations, as a quick search for `is_well_order α (<)` or `is_well_order ι (<)` reveals. The most obvious way to spell this condition out, namely `[has_lt α] [is_well_order α (<)]` is actually the most inconvenient, since none of the results for linear orders are available. You actually need to write `[linear_order α] [is_well_order α (<)]` instead. With this new typeclass, the obvious spelling is now the good one: `[linear_order α] [well_founded_lt α]` ### Redundant typeclasses We actually already at least four typeclasses for the well-foundedness of a concrete relation: `category.noetherian_object`, `category.artinian_object`, `topological_space.noetherian_space`, and `wf_dvd_monoid`. One currently needs to specialize the characterizing properties of a well-founded relation to these separate typeclasses in order to use them. Redefining these typeclasses in terms of these new ones, and making them `reducible def`s, would alleviate this problem. ### Typeclass inference Well-founded relations are actually a nice candidate for typeclass inference, since there's many common constructions that automatically preserve well-foundedness. These include taking inverse images (including `measure` and `order.preimage`), maps through relation embeddings (including subtypes), lexicographic sums or products, and adding a top or bottom element. Many of these are currently provided as instances, but only for well-orders. ### Misleading theorem names Perhaps the most useful result on well-founded relations is that every nonempty set has a minimum - when you view the relation as `<`, that is. This leads to misleading theorem names when you're using them on a well-founded `>` relation. With this refactor, we could simply specialize `well_founded.min` into `well_founded_gt.max` and end up with clearer theorem statements. On a related note, given a linear order and a well-founded `<` relation, we can rephrase `well_founded.not_lt_min` into the much more convenient `well_founded_lt.min_le`.
bottine
pushed a commit
to bottine/mathlib
that referenced
this pull request
Jul 30, 2022
…eanprover-community#15399) # Well-founded typeclasses We introduce a new unbundled typeclass `is_well_founded` for a general well-founded relation, and reducible defs `well_founded_lt` and `well_founded_gt` for well-founded `<` and `>` specifically, to be used as mixins. For now, all we do is specialize only the most basic API on well-founded relations to these new typeclasses. This is just an initial development. If this is merged, a subsequent PR will redefine `is_well_order` in terms of `is_well_founded` (and remove the redundant `irrefl` field). Further PRs will focus on providing all the possible instances for this new typeclass, and actually using it throughout mathlib. Moved from leanprover-community#15023. ## Why do we want this? Here's the part where I justify why this is a good thing we want in mathlib. ### Well-ordered `<` There is a need to talk about well-ordered `<` relations, as a quick search for `is_well_order α (<)` or `is_well_order ι (<)` reveals. The most obvious way to spell this condition out, namely `[has_lt α] [is_well_order α (<)]` is actually the most inconvenient, since none of the results for linear orders are available. You actually need to write `[linear_order α] [is_well_order α (<)]` instead. With this new typeclass, the obvious spelling is now the good one: `[linear_order α] [well_founded_lt α]` ### Redundant typeclasses We actually already at least four typeclasses for the well-foundedness of a concrete relation: `category.noetherian_object`, `category.artinian_object`, `topological_space.noetherian_space`, and `wf_dvd_monoid`. One currently needs to specialize the characterizing properties of a well-founded relation to these separate typeclasses in order to use them. Redefining these typeclasses in terms of these new ones, and making them `reducible def`s, would alleviate this problem. ### Typeclass inference Well-founded relations are actually a nice candidate for typeclass inference, since there's many common constructions that automatically preserve well-foundedness. These include taking inverse images (including `measure` and `order.preimage`), maps through relation embeddings (including subtypes), lexicographic sums or products, and adding a top or bottom element. Many of these are currently provided as instances, but only for well-orders. ### Misleading theorem names Perhaps the most useful result on well-founded relations is that every nonempty set has a minimum - when you view the relation as `<`, that is. This leads to misleading theorem names when you're using them on a well-founded `>` relation. With this refactor, we could simply specialize `well_founded.min` into `well_founded_gt.max` and end up with clearer theorem statements. On a related note, given a linear order and a well-founded `<` relation, we can rephrase `well_founded.not_lt_min` into the much more convenient `well_founded_lt.min_le`.
robertylewis
pushed a commit
that referenced
this pull request
Aug 2, 2022
…15399) # Well-founded typeclasses We introduce a new unbundled typeclass `is_well_founded` for a general well-founded relation, and reducible defs `well_founded_lt` and `well_founded_gt` for well-founded `<` and `>` specifically, to be used as mixins. For now, all we do is specialize only the most basic API on well-founded relations to these new typeclasses. This is just an initial development. If this is merged, a subsequent PR will redefine `is_well_order` in terms of `is_well_founded` (and remove the redundant `irrefl` field). Further PRs will focus on providing all the possible instances for this new typeclass, and actually using it throughout mathlib. Moved from #15023. ## Why do we want this? Here's the part where I justify why this is a good thing we want in mathlib. ### Well-ordered `<` There is a need to talk about well-ordered `<` relations, as a quick search for `is_well_order α (<)` or `is_well_order ι (<)` reveals. The most obvious way to spell this condition out, namely `[has_lt α] [is_well_order α (<)]` is actually the most inconvenient, since none of the results for linear orders are available. You actually need to write `[linear_order α] [is_well_order α (<)]` instead. With this new typeclass, the obvious spelling is now the good one: `[linear_order α] [well_founded_lt α]` ### Redundant typeclasses We actually already at least four typeclasses for the well-foundedness of a concrete relation: `category.noetherian_object`, `category.artinian_object`, `topological_space.noetherian_space`, and `wf_dvd_monoid`. One currently needs to specialize the characterizing properties of a well-founded relation to these separate typeclasses in order to use them. Redefining these typeclasses in terms of these new ones, and making them `reducible def`s, would alleviate this problem. ### Typeclass inference Well-founded relations are actually a nice candidate for typeclass inference, since there's many common constructions that automatically preserve well-foundedness. These include taking inverse images (including `measure` and `order.preimage`), maps through relation embeddings (including subtypes), lexicographic sums or products, and adding a top or bottom element. Many of these are currently provided as instances, but only for well-orders. ### Misleading theorem names Perhaps the most useful result on well-founded relations is that every nonempty set has a minimum - when you view the relation as `<`, that is. This leads to misleading theorem names when you're using them on a well-founded `>` relation. With this refactor, we could simply specialize `well_founded.min` into `well_founded_gt.max` and end up with clearer theorem statements. On a related note, given a linear order and a well-founded `<` relation, we can rephrase `well_founded.not_lt_min` into the much more convenient `well_founded_lt.min_le`.
khwilson
pushed a commit
that referenced
this pull request
Aug 2, 2022
…15399) # Well-founded typeclasses We introduce a new unbundled typeclass `is_well_founded` for a general well-founded relation, and reducible defs `well_founded_lt` and `well_founded_gt` for well-founded `<` and `>` specifically, to be used as mixins. For now, all we do is specialize only the most basic API on well-founded relations to these new typeclasses. This is just an initial development. If this is merged, a subsequent PR will redefine `is_well_order` in terms of `is_well_founded` (and remove the redundant `irrefl` field). Further PRs will focus on providing all the possible instances for this new typeclass, and actually using it throughout mathlib. Moved from #15023. ## Why do we want this? Here's the part where I justify why this is a good thing we want in mathlib. ### Well-ordered `<` There is a need to talk about well-ordered `<` relations, as a quick search for `is_well_order α (<)` or `is_well_order ι (<)` reveals. The most obvious way to spell this condition out, namely `[has_lt α] [is_well_order α (<)]` is actually the most inconvenient, since none of the results for linear orders are available. You actually need to write `[linear_order α] [is_well_order α (<)]` instead. With this new typeclass, the obvious spelling is now the good one: `[linear_order α] [well_founded_lt α]` ### Redundant typeclasses We actually already at least four typeclasses for the well-foundedness of a concrete relation: `category.noetherian_object`, `category.artinian_object`, `topological_space.noetherian_space`, and `wf_dvd_monoid`. One currently needs to specialize the characterizing properties of a well-founded relation to these separate typeclasses in order to use them. Redefining these typeclasses in terms of these new ones, and making them `reducible def`s, would alleviate this problem. ### Typeclass inference Well-founded relations are actually a nice candidate for typeclass inference, since there's many common constructions that automatically preserve well-foundedness. These include taking inverse images (including `measure` and `order.preimage`), maps through relation embeddings (including subtypes), lexicographic sums or products, and adding a top or bottom element. Many of these are currently provided as instances, but only for well-orders. ### Misleading theorem names Perhaps the most useful result on well-founded relations is that every nonempty set has a minimum - when you view the relation as `<`, that is. This leads to misleading theorem names when you're using them on a well-founded `>` relation. With this refactor, we could simply specialize `well_founded.min` into `well_founded_gt.max` and end up with clearer theorem statements. On a related note, given a linear order and a well-founded `<` relation, we can rephrase `well_founded.not_lt_min` into the much more convenient `well_founded_lt.min_le`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Well-founded refactor
We create a new unbundled typeclass
is_well_founded α rand the correspondingwell_founded_ltandwell_founded_gttypeclasses. We rephrase the existing results on generic well-founded relations in terms of these new typeclasses.This is a very large refactor, so we thoroughly describe its main effects on the library:
order/rel_classes.leanHere's where the new typeclasses are defined. We provide basic instances, and transfer preexisting API on
well_foundedfor convenience.A minor change: we remove the redundant
irreflhypothesis fromis_well_order.order/well_founded.leanWe pretty much re-do this whole file. The basic theorems are stated in terms of all three new typeclasses for convenience.
order/well_founded_set.leanWe redefine
set.well_founded_onandset.is_wfin terms of our new predicates. These definitions are equivalent to the previous. We renameset.well_founded_ontoset.is_well_founded_onfor consistency. We also add API to get the corresponding instances when needed.(on second thought, this is definitely scope creep. I'll move this to a new refactor at a later point.)
Miscellaneous
Many theorems that previously had
well_foundedin the name are renamed usingis_well_foundedand stated in terms of this new typeclass. (Todo: evaluate potential scope creep here)Various structures, such as
category.noetherian_object,category.artinian_object, andwf_dvd_monoid, whose sole field was the well-foundedness of some relation, have been turned intoreducibledefs.A few definitions for well-founded relations have been rewritten in terms of
inv_imageandmeasure. These are def-eq but their well-foundedness can now be inferred automatically.Many theorems are turned into instances. Some former theorems that can now be inferred as instances are removed, such as
polynomial.degree_lt_wf.We golf a few theorems by using the new API, particularly the
function.arg_maxAPI, though we don't change their proofs considerably. Some proofs show up with a large diff, but this is only due to the indenting changing.is_irrefl#15039ordinal.min→infi#14707well_founded_iff_has_min'andwell_founded_iff_has_max'#15071well_founded.monotone_chain_conditionto preorders #15073This will probably be a huge refactor once it's done. Be patient!