← Back to Pull requests

feat: more precise characterizations of `IsLUB s (sSup s)` for `s : Set (WithTop α)` #46150

Open
vihdzp opened this pull request with 55 lines diff across 1 files
View on GitHub
vihdzp vihdzp commented on Nov 18, 2026 11:00 UTC
Author

Used in the CGT repo.

---
<!-- Your PR title will become the first line of the commit message.

In this box, the text above the --- (if not empty) will be appended
to the commit message, and can be used to give additional context or
details. Please leave a blank newline before the ---, otherwise GitHub
will format the text above it as a title.

For details on the "pull request lifecycle" in mathlib, please see:
https://leanprover-community.github.io/contribute/index.html

In particular, note that most reviewers will only notice your PR
if it passes the continuous integration checks.
Please ask for help on https://leanprover.zulipchat.com if needed.

When merging, all the commits will be squashed into a single commit
listing all co-authors.

Co-authors in the squash commit are gathered from two sources:

First, all authors of commits to this PR branch are included. Thus,
one way to add co-authors is to include at least one commit authored by
each co-author among the commits in the pull request. If necessary, you
may create empty commits to indicate co-authorship, using commands like so:

git commit --author="Author Name <author@email.com>" --allow-empty -m "add Author Name as coauthor"

Second, co-authors can also be listed in lines at the very bottom of
the commit message (that is, directly before the ---) using the following format:

Co-authored-by: Author Name <author@email.com>

If you are moving or deleting declarations, please include these lines
at the bottom of the commit message (before the ---, and also before
any "Co-authored-by" lines) using the following format:

Moves:

  • Vector. -> List.Vector.

  • ...
  • Deletions:

  • Nat.bit1_add_bit1

  • ...
  • Any other comments you want to keep out of the PR commit should go
    below the ---, and placed outside this HTML comment, or else they
    will be invisible to reviewers.

    If this PR depends on other PRs, please list them below this comment,
    using the following format:

  • depends on: #abc [optional extra text]

  • depends on: #xyz [optional extra text]
  • -->

    Diff: 55 lines (+41 / -14) across 1 files Reviewer: YaelDillies Review duration: 20777m
    All Vouch review confidence checks passed
    Residual risk 0.02 = Change Risk (0.27) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.27 · 55 lines diff across 1 files
    0.27
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.91 · 5 substantive comment(s)
    0.91
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    91%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.241
    Real PR Conversation Timeline
    12 items
    github-actions[bot] github-actions[bot] commented on Nov 18, 2026 11:01 UTC
    Bot

    PR summary ce0422e367

    Import changes for modified files

    No significant changes to the import graph

    <details><summary>Import changes for all files</summary>

    |Files|Import difference|
    |-|-|

    </details>

    ---

    <details><summary>

    Declarations diff (regex)

    </summary>

    + isGLB_sInf_of_preimage
    + isLUB_sSup_of_preimage
    + nonempty_preimage_some_iff
    + preimage_some_eq_empty_iff
    + subset_range_some_iff
    <details>
    <summary>You can run this locally as follows</summary>

    ## from your `mathlib4` directory:
    git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
    
    ## summary with just the declaration names:
    ../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>
    
    ## more verbose report:
    ../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>
    

    </details>

    The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

    </details>

    <!-- DECLS_DIFF_LEAN_BEGIN -->
    <details><summary>

    Declarations diff (Lean)

    </summary>

    ✅ Lean-aware diff — post-build, computed from the Lean environment (commit ce0422e).

    +10 new declarations
    −0 removed declarations

    +WithBot.isGLB_sInf_of_preimage
    +WithBot.isLUB_sSup_of_preimage
    +WithBot.nonempty_preimage_some_iff
    +WithBot.preimage_some_eq_empty_iff
    +WithBot.subset_range_some_iff
    +WithTop.isGLB_sInf_of_preimage
    +WithTop.isLUB_sSup_of_preimage
    +WithTop.nonempty_preimage_some_iff
    +WithTop.preimage_some_eq_empty_iff
    +WithTop.subset_range_some_iff
    

    </details>
    <!-- DECLS_DIFF_LEAN_END -->

    ---

    No changes to strong technical debt.
    No changes to weak technical debt.

    Current commit ce0422e367
    Reference commit 12f966a2d9

    This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

    git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
    ../mathlib-ci/scripts/reporting/technical-debt-metrics.py 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).

    astrainfinita astrainfinita commented on code on Nov 18, 2026 12:52 UTC
    Code Review
    Mathlib/Order/ConditionallyCompleteLattice/WithTop.lean:1
    @@ -158,6 +168,42 @@ theorem isLUB_top_iff {s : Set (WithTop α)} :
       simp [isLUB_iff_le_iff, WithTop.forall, mem_upperBounds, BddAbove, Set.Nonempty,
         ← or_iff_not_imp_left, forall_or_left]
     
    +@[to_dual]
    +theorem isGLB_sInf_of_preimage' [InfSet α] {s : Set (WithTop α)}
    +    (hs : ¬ s ⊆ {⊤} → IsGLB ((↑) ⁻¹' s : Set α) (sInf ((↑) ⁻¹' s))) (hs' : BddBelow s) :
    +    IsGLB s (sInf s) := by
    +  by_cases h : s ⊆ {⊤}
    +  · rw [sInf_eq_top_iff.2 (.inl h)]
    +    exact isGLB_top_iff.2 h
    +  rw [sInf_eq h hs', isGLB_coe_iff]
    +  exact ⟨h, hs h⟩
    +
    +/-- See `isGLB_sInf_of_preimage'` for a stronger version. -/
    +@[to_dual
    +/-- See `isGLB_sInf_of_preimage` for a stronger version. -/]

    /-- See `isLUB_sSup_of_preimage'` for a stronger version. -/]
    

    YaelDillies YaelDillies commented on Nov 24, 2026 20:23 UTC
    Reviewer

    Have you seen #40620 ? Could you coordinate with @SnirBroshi ?

    vihdzp vihdzp commented on Nov 25, 2026 14:12 UTC
    Author

    I don't think there's any overlap between PRs.

    SnirBroshi SnirBroshi commented on Nov 25, 2026 15:05 UTC
    Contributor

    Hi! I haven't thought this through about this specific PR, but as I wrote here there are many predicates (like IsLUB here) which need these lemmas that cast from α to WithTop α, and I have been thinking for a while about whether we can generalize from WithTop.some to any RelEmbedding or InitialSeg or PrincipalSeg.

    #44199 also has some translation lemmas btw, slightly similar to this PR.

    Lots of things could use such translation lemmas, e.g. IsLUB / IsCofinal / BddAbove / IsLowerSet / IsCompactElement / IsAtom / IsCompl / Set.OrdConnected / Disjoint / IsSuccLimit, and if possible we shouldn't specialize to WithTop.coe as it'll mean lots more specific lemmas for all the other embeddings, e.g. ℕ → Ordinal / ℕ → Cardinal / ℕ → ENNReal / α → α ⊕ₗ β (Sum.inlₗ), etc.

    Also sometimes we have lemmas for Set.image and for Set.preimage (and even Set.range), so perhaps we should prove them once for Set.MapsTo.

    btw I think this isn't trivial, so it shouldn't block this upstreaming effort, just something to think about as we make all these translation lemma PRs

    vihdzp vihdzp commented on Nov 25, 2026 15:57 UTC
    Author

    I think the first step in your hypothetical refactor would be to move the definitions of InitialSeg/PrincipalSeg earlier in the import chain. Right now that entire file is specialized to results which are later useful for ordinals.

    YaelDillies YaelDillies commented on code on Nov 27, 2026 09:16 UTC
    Code Review
    Mathlib/Order/ConditionallyCompleteLattice/WithTop.lean:1
    @@ -26,11 +26,21 @@ variable {α β γ : Type*} {ι : Sort*}
     
     namespace WithTop
     
    --- TODO: find a better home for this lemma.
    +-- TODO: find a better home for these lemmas.
    +
     @[to_dual]
     theorem isCompl_range_coe : IsCompl (range ((↑) : α → WithTop α)) {⊤} :=
       eq_compl_iff_isCompl.1 <| Set.ext fun _ ↦ ne_top_iff_exists.symm
     
    +@[to_dual]
    +theorem nonempty_preimage_some_iff {s : Set (WithTop α)} :
    +    (((↑) ⁻¹' s : Set α)).Nonempty ↔ ¬ s ⊆ {⊤} := by
    +  rw [nonempty_preimage_iff, isCompl_range_coe.eq_compl, inter_compl_nonempty_iff]

    What about the _eq_empty version?

    YaelDillies YaelDillies commented on code on Nov 27, 2026 09:18 UTC
    Code Review
    Mathlib/Order/ConditionallyCompleteLattice/WithTop.lean:1
    @@ -158,6 +168,42 @@ theorem isLUB_top_iff {s : Set (WithTop α)} :
       simp [isLUB_iff_le_iff, WithTop.forall, mem_upperBounds, BddAbove, Set.Nonempty,
         ← or_iff_not_imp_left, forall_or_left]
     
    +@[to_dual]
    +theorem isGLB_sInf_of_preimage' [InfSet α] {s : Set (WithTop α)}
    +    (hs : ¬ s ⊆ {⊤} → IsGLB ((↑) ⁻¹' s : Set α) (sInf ((↑) ⁻¹' s))) (hs' : BddBelow s) :
    +    IsGLB s (sInf s) := by
    +  by_cases h : s ⊆ {⊤}
    +  · rw [sInf_eq_top_iff.2 (.inl h)]
    +    exact isGLB_top_iff.2 h
    +  rw [sInf_eq h hs', isGLB_coe_iff]
    +  exact ⟨h, hs h⟩
    +
    +/-- See `isGLB_sInf_of_preimage'` for a stronger version. -/
    +@[to_dual
    +/-- See `isLUB_sSup_of_preimage'` for a stronger version. -/]
    +theorem isGLB_sInf_of_preimage [InfSet α] {s : Set (WithTop α)}
    +    (hs : IsGLB ((↑) ⁻¹' s : Set α) (sInf ((↑) ⁻¹' s))) (hs' : BddBelow s) : IsGLB s (sInf s) :=
    +  isGLB_sInf_of_preimage' (fun _ ↦ hs) hs'

    Is it really worth having both lemmas? The specialisation of the primed lemma to the unprimed one is trivial

    vihdzp vihdzp commented on code on Nov 27, 2026 14:45 UTC
    Code Review
    Mathlib/Order/ConditionallyCompleteLattice/WithTop.lean:1
    @@ -158,6 +168,42 @@ theorem isLUB_top_iff {s : Set (WithTop α)} :
       simp [isLUB_iff_le_iff, WithTop.forall, mem_upperBounds, BddAbove, Set.Nonempty,
         ← or_iff_not_imp_left, forall_or_left]
     
    +@[to_dual]
    +theorem isGLB_sInf_of_preimage' [InfSet α] {s : Set (WithTop α)}
    +    (hs : ¬ s ⊆ {⊤} → IsGLB ((↑) ⁻¹' s : Set α) (sInf ((↑) ⁻¹' s))) (hs' : BddBelow s) :
    +    IsGLB s (sInf s) := by
    +  by_cases h : s ⊆ {⊤}
    +  · rw [sInf_eq_top_iff.2 (.inl h)]
    +    exact isGLB_top_iff.2 h
    +  rw [sInf_eq h hs', isGLB_coe_iff]
    +  exact ⟨h, hs h⟩
    +
    +/-- See `isGLB_sInf_of_preimage'` for a stronger version. -/
    +@[to_dual
    +/-- See `isLUB_sSup_of_preimage'` for a stronger version. -/]
    +theorem isGLB_sInf_of_preimage [InfSet α] {s : Set (WithTop α)}
    +    (hs : IsGLB ((↑) ⁻¹' s : Set α) (sInf ((↑) ⁻¹' s))) (hs' : BddBelow s) : IsGLB s (sInf s) :=
    +  isGLB_sInf_of_preimage' (fun _ ↦ hs) hs'

    It felt a bit weird having a theorem with an implication as a hypothesis. But you're right, I'll deduplicate.

    YaelDillies YaelDillies approved these changes on Nov 28, 2026 15:16 UTC
    Approved Reviewer

    Thanks! 🚀

    maintainer merge

    github-actions[bot] github-actions[bot] commented on Nov 28, 2026 15:17 UTC
    Bot

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

    Reviewers
    Assignees
    vihdzp vihdzp
    Labels
    risk: low confidence: 91.3% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 27.1% (LOW) · Higher = larger blast radius
    27.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 91.3% · Lower = rushed or shallow review
    91.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 2.4% · Safe to merge
    2.4%