Skip to content

[Merged by Bors] - chore: use @[to_dual] in Bounds/Image - #35211

Closed
kim-em wants to merge 18 commits into
leanprover-community:masterfrom
kim-em:kim/to-dual-bounds-image
Closed

kim-em wants to merge 18 commits into
leanprover-community:masterfrom
kim-em:kim/to-dual-bounds-image

Conversation

@kim-em

@kim-em kim-em commented Feb 12, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds @[to_dual] annotations to primal theorems in Mathlib.Order.Bounds.Image, auto-generating their dual counterparts and deleting the hand-written versions. Covers MonotoneOn, AntitoneOn, Monotone, Antitone, image2, IsCofinalFor, Prod, and Pi sections.

Diff relative to #35208

🤖 Prepared with Claude Code

kim-em and others added 2 commits February 12, 2026 21:53
This enables @[to_dual] to automatically translate between
atom/coatom and lfp/gfp theorem names, preparing for expanded
@[to_dual] coverage in subsequent commits.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add @[to_dual] to IsLUB.insert, isLUB_pair, IsLeast.unique,
IsLeast.isLeast_iff_eq, and IsLUB.unique, auto-generating
their duals instead of maintaining hand-written copies.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@github-actions

github-actions Bot commented Feb 12, 2026 •

Copy link
Copy Markdown

PR summary 14d98a46b3

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

- BddAbove.bddBelow_image2_of_bddAbove
- BddAbove.image2_bddBelow
- BddBelow.bddBelow_image2_of_bddAbove
- BddBelow.image2
- BddBelow.range_comp
- BddBelow.range_mono
- IsCoinitialFor.image_of_antitone
- IsCoinitialFor.image_of_monotone
- IsGreatest.isLeast_image2
- IsGreatest.isLeast_image2_of_isLeast
- IsLUB.of_image
- IsLeast.image2
- IsLeast.isLeast_image2_of_isGreatest
- bddBelow_pi
- bddBelow_prod
- bddBelow_range_pi
- bddBelow_range_prod
- image2_lowerBounds_lowerBounds_subset
- image2_lowerBounds_lowerBounds_subset_lowerBounds_image2
- image2_lowerBounds_upperBounds_subset_lowerBounds_image2
- image2_upperBounds_lowerBounds_subset_lowerBounds_image2
- isGLB_pi
- isGLB_prod
- mem_lowerBounds_image2
- mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds
- mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds
- mem_lowerBounds_image2_of_mem_upperBounds
-- image_lowerBounds_subset_lowerBounds_image
-- image_upperBounds_subset_lowerBounds_image
-- map_isGreatest
-- map_isLeast
-- mem_lowerBounds_image_self
---- map_bddBelow
---- mem_lowerBounds_image

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

Add @[to_dual] to 15 more theorems in Order.Bounds.Basic,
auto-generating their duals instead of maintaining hand-written copies.

Covers univ, empty set, bounds, and lt_iff sections.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@mathlib-dependent-issues mathlib-dependent-issues Bot added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Feb 12, 2026
@kim-em
kim-em marked this pull request as draft February 12, 2026 22:58
kim-em and others added 4 commits February 12, 2026 23:00
Add @[to_dual] to 7 more theorems: bddBelow_iff_subset_Ici,
IsGreatest.insert, upperBounds_insert, OrderTop.bddAbove,
isGreatest_pair, upperBounds_prod, and IsLUB.prod.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
These don't enable any new @[to_dual] annotations in Bounds.Basic
(the Heyting pairs have type class issues), but prepare the dictionary
for use elsewhere.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@kim-em
kim-em force-pushed the kim/to-dual-bounds-image branch from f897e4b to 9e94c56 Compare February 12, 2026 23:15
@kim-em
kim-em force-pushed the kim/to-dual-bounds-image branch 2 times, most recently from e6e8a7d to 452085b Compare February 12, 2026 23:58
@kim-em
kim-em marked this pull request as ready for review February 13, 2026 00:02
@kim-em
kim-em force-pushed the kim/to-dual-bounds-image branch from dca52eb to 6a9bfbb Compare February 13, 2026 00:32
@kim-em
kim-em force-pushed the kim/to-dual-bounds-image branch from 6a9bfbb to cc6a238 Compare February 13, 2026 03:52
@kim-em
kim-em force-pushed the kim/to-dual-bounds-image branch from cc6a238 to 7290fbd Compare February 13, 2026 04:19
@mathlib-dependent-issues mathlib-dependent-issues Bot removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Feb 13, 2026
@mathlib-dependent-issues

Copy link
Copy Markdown

This PR/issue depends on:

Comment thread Mathlib/Order/Bounds/Image.lean Resolved
Comment thread Mathlib/Order/Bounds/Image.lean Resolved
Comment thread Mathlib/Order/Bounds/Image.lean Resolved
Comment thread Mathlib/Order/Bounds/Image.lean Resolved
Comment thread Mathlib/Order/Bounds/Image.lean Resolved
Comment thread Mathlib/Order/Bounds/Image.lean Resolved
Comment thread Mathlib/Order/Bounds/Image.lean Resolved
Comment thread Mathlib/Order/Bounds/Image.lean Resolved
Comment thread Mathlib/Order/Bounds/Image.lean Resolved
Comment thread Mathlib/Order/Bounds/Image.lean Resolved
@kim-em
kim-em force-pushed the kim/to-dual-bounds-image branch from 804106d to da1a268 Compare February 13, 2026 22:44
@[to_dual] generates a version with {f} (g) implicitness, but the
existing BddBelow.range_mono uses (f) {g} to match the convention
that the explicit argument is the "smaller" function.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@kim-em
kim-em force-pushed the kim/to-dual-bounds-image branch from da1a268 to f301c77 Compare February 13, 2026 22:45
kim-em and others added 3 commits February 14, 2026 10:07
When a dual lemma is deleted because it is now auto-generated by
@[to_dual], its original docstring is preserved via the
@[to_dual /-- ... -/] syntax.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
When a dual lemma is deleted because it is now auto-generated by
@[to_dual], its original docstring is preserved via the
@[to_dual /-- ... -/] syntax.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

@vihdzp vihdzp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@JovanGerb JovanGerb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A number of statements have had their proof modified for no reason.

Presumably the bot saw the word "dual" in the proof and felt the need to change the proof. Could you revert this, and tell your bot to never change any statements or proofs if the original statement and proof still work?

Comment thread Mathlib/Order/Bounds/Image.lean Outdated
Comment on lines +83 to +71
theorem mem_upperBounds_image (Hf : AntitoneOn f t) (Hst : s ⊆ t) (Has : a ∈ lowerBounds s) :
a ∈ t → f a ∈ upperBounds (f '' s) :=
Hf.dual_right.mem_lowerBounds_image Hst Has
@[to_dual]
theorem mem_upperBounds_image (Hf : AntitoneOn f t) (Hst : s ⊆ t) (Has : a ∈ lowerBounds s)
(Hat : a ∈ t) : f a ∈ upperBounds (f '' s) :=
forall_mem_image.2 fun _ H => Hf Hat (Hst H) (Has H)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

e.g. this one had its statement and proof modified

Revert unnecessary proof changes in the AntitoneOn and Antitone
sections, restoring the original .dual_right delegation proofs
while keeping the @[to_dual] annotations and docstrings.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@kim-em

kim-em commented Feb 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I've restored the original .dual_right proofs in both the AntitoneOn and Antitone sections, keeping only the @[to_dual] annotations and docstrings (which are the actual content of this PR).

@JovanGerb JovanGerb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

The one use of to_dual existing is not needed.

Some declarations in the file were skipped in this PR because they depend on missing to_dual tags in Mathlib.Order.Monotone.Basic

maintainer merge

Comment thread Mathlib/Order/Bounds/Image.lean Outdated
Comment on lines 424 to 437
lemma BddAbove.range_mono [Preorder β] {f : α → β} (g : α → β) (h : ∀ a, f a ≤ g a)
(hbdd : BddAbove (range g)) : BddAbove (range f) := by
obtain ⟨C, hC⟩ := hbdd
use C
rintro - ⟨x, rfl⟩
exact (h x).trans (hC <| mem_range_self x)

-- The implicit/explicit parameter structure differs from `BddAbove.range_mono`.
-- The `to_dual` proof translation strategy doesn't care that the implicitness differs,
-- and `@[to_dual existing]` doesn't care about the discrepancy since `isDefEq` ignores binder info.
@[to_dual existing]
lemma BddBelow.range_mono [Preorder β] (f : α → β) {g : α → β} (h : ∀ a, f a ≤ g a)
(hbdd : BddBelow (range f)) : BddBelow (range g) :=
BddAbove.range_mono (β := βᵒᵈ) f h hbdd

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
lemma BddAbove.range_mono [Preorder β] {f : α → β} (g : α → β) (h : ∀ a, f a ≤ g a)
(hbdd : BddAbove (range g)) : BddAbove (range f) := by
obtain ⟨C, hC⟩ := hbdd
use C
rintro - ⟨x, rfl⟩
exact (h x).trans (hC <| mem_range_self x)
-- The implicit/explicit parameter structure differs from `BddAbove.range_mono`.
-- The `to_dual` proof translation strategy doesn't care that the implicitness differs,
-- and `@[to_dual existing]` doesn't care about the discrepancy since `isDefEq` ignores binder info.
@[to_dual existing]
lemma BddBelow.range_mono [Preorder β] (f : α → β) {g : α → β} (h : ∀ a, f a ≤ g a)
(hbdd : BddBelow (range f)) : BddBelow (range g) :=
BddAbove.range_mono (β := βᵒᵈ) f h hbdd
@[to_dual (reorder := f g)]
lemma BddAbove.range_mono [Preorder β] {f : α → β} (g : α → β) (h : ∀ a, f a ≤ g a)
(hbdd : BddAbove (range g)) : BddAbove (range f) := by
obtain ⟨C, hC⟩ := hbdd
use C
rintro - ⟨x, rfl⟩
exact (h x).trans (hC <| mem_range_self x)

@github-actions

Copy link
Copy Markdown

🚀 Pull request has been placed on the maintainer queue by JovanGerb.

@mathlib-triage mathlib-triage Bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Feb 21, 2026
@bryangingechen

Copy link
Copy Markdown
Contributor

Thanks!
bors d+

@mathlib-bors

mathlib-bors Bot commented Feb 21, 2026

Copy link
Copy Markdown
Contributor

✌️ kim-em can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@mathlib-triage mathlib-triage Bot added delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). and removed maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. labels Feb 21, 2026
Per review feedback, use `reorder` on `BddAbove.range_mono` to auto-generate
`BddBelow.range_mono` instead of manually writing it with `@[to_dual existing]`.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@kim-em

kim-em commented Feb 22, 2026

Copy link
Copy Markdown
Contributor Author

bors merge

@mathlib-triage mathlib-triage Bot added the ready-to-merge This PR has been sent to bors. label Feb 22, 2026
mathlib-bors Bot pushed a commit that referenced this pull request Feb 22, 2026
This PR adds `@[to_dual]` annotations to primal theorems in `Mathlib.Order.Bounds.Image`, auto-generating their dual counterparts and deleting the hand-written versions. Covers `MonotoneOn`, `AntitoneOn`, `Monotone`, `Antitone`, `image2`, `IsCofinalFor`, `Prod`, and `Pi` sections.

[Diff relative to #35208](kim-em/mathlib4@kim/to-dual-bounds-basic...kim/to-dual-bounds-image)

- [x] depends on: #35208

🤖 Prepared with Claude Code
@mathlib-bors

mathlib-bors Bot commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors Bot changed the title chore: use @[to_dual] in Bounds/Image [Merged by Bors] - chore: use @[to_dual] in Bounds/Image Feb 23, 2026
@mathlib-bors mathlib-bors Bot closed this Feb 23, 2026
pfaffelh pushed a commit to pfaffelh/mathlib4 that referenced this pull request Mar 2, 2026
This PR adds `@[to_dual]` annotations to primal theorems in `Mathlib.Order.Bounds.Image`, auto-generating their dual counterparts and deleting the hand-written versions. Covers `MonotoneOn`, `AntitoneOn`, `Monotone`, `Antitone`, `image2`, `IsCofinalFor`, `Prod`, and `Pi` sections.

[Diff relative to leanprover-community#35208](kim-em/mathlib4@kim/to-dual-bounds-basic...kim/to-dual-bounds-image)

- [x] depends on: leanprover-community#35208

🤖 Prepared with Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). ready-to-merge This PR has been sent to bors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants