Skip to content

[Merged by Bors] - feat: injectivity of Function.extend for disjoint ranges - #43325

Closed
kim-em wants to merge 4 commits into
leanprover-community:masterfrom
kim-em:extend_sum_inl_inr
Closed

kim-em wants to merge 4 commits into
leanprover-community:masterfrom
kim-em:extend_sum_inl_inr

Conversation

@kim-em

@kim-em kim-em commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

This PR adds Function.Injective.extend_of_disjoint: if f : α → β, g : α → γ and j : β → γ are injective and g and j have disjoint ranges, then Function.extend f g j is injective. It is used in leanprover/cslib#401 to build families of total orders for a comparison-sorting lower bound, via Function.extend f Sum.inl Sum.inr : β → α ⊕ β.

🤖 Prepared with Claude Code

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

PR summary f8c3dba6af

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ _root_.Function.Injective.extend_of_disjoint

You can run this locally as follows
## 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>

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

Declarations diff (Lean)

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

  • +1 new declarations
  • −0 removed declarations
+Function.Injective.extend_of_disjoint

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

Current commit f8c3dba6af
Reference commit 1318ddb253

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

@github-actions github-actions Bot added the t-logic Logic (model theory, etc) label Sep 2, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pxy48TaP92UgEq28KGm8BG
kim-em added a commit to kim-em/cslib that referenced this pull request Sep 2, 2026
Function.Injective.extend_sum_inl_inr is proposed in
leanprover-community/mathlib4#43325 (with a golfed
LeftInverse proof, mirrored here) and the Std.Total (InvImage r f) instance
in leanprover-community/mathlib4#43326; keeping the
local copies private avoids conflicts when those land.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pxy48TaP92UgEq28KGm8BG
Comment thread Mathlib/Logic/Function/Basic.lean Outdated
Comment on lines +946 to +947
theorem Injective.extend_sum_inl_inr {α β : Type*} {f : α → β} (hf : Injective f) :
Injective (extend f (Sum.inl : α → α ⊕ β) (Sum.inr : β → α ⊕ β)) := by

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Gemini suggests the more general result

theorem Injective.extend_of_disjoint {α β γ : Type*} 
    {f : α → β} {g : α → γ} {h : β → γ}
    (hf : Injective f) (hg : Injective g) (hh : Injective h)
    (hd : Disjoint (range g) (range h)) :
    Injective (extend f g h) := by

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@grunweg grunweg added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Sep 2, 2026
Per Eric's review, state the general result: `extend f g j` is injective
when `f`, `g`, `j` are injective and `g`, `j` have disjoint ranges.
`Disjoint` and `Set.range` are not available in `Mathlib/Logic/Function/Basic.lean`
(they would be import cycles), so both lemmas live in `Mathlib/Data/Set/Restrict.lean`
alongside `Injective.extend_injOn`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AjjWKN4JxeBhmHnUVY3mC5
@kim-em kim-em changed the title feat: injectivity of Function.extend f Sum.inl Sum.inr feat: injectivity of Function.extend for disjoint ranges Sep 9, 2026
@kim-em kim-em removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Sep 9, 2026
Comment thread Mathlib/Data/Set/Restrict.lean Outdated
and everything else is sent to itself under `Sum.inr`. -/
lemma _root_.Function.Injective.extend_sum_inl_inr {f : α → β} (hf : f.Injective) :
Injective (extend f (Sum.inl : α → α ⊕ β) (Sum.inr : β → α ⊕ β)) :=
hf.extend_of_disjoint (fun _ _ ↦ Sum.inl.inj) (fun _ _ ↦ Sum.inr.inj)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I think we have a lemma that directly proves injectivity.

Given that, i'd suggest just dropping this specialization entirely.

bors d+

@mathlib-bors mathlib-bors Bot added the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Sep 9, 2026
@mathlib-bors

mathlib-bors Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

✌️ kim-em can now approve this pull request until 2026-09-23 05:34 UTC (in 2 weeks). To approve and merge, reply with bors r+. More detailed instructions are available here.

⚠️ This delegation only covers changes within Archive/**, Counterexamples/**, docs/**, DownstreamTest/**, Mathlib/**, MathlibTest/**, Wanted/**, widget/**, Archive.lean, Counterexamples.lean, docs.lean, Mathlib.lean, Wanted.lean; an author commit touching anything else will revoke it. Bors also revokes it if a later push changes too many files for it to check the full list — even if it stays within scope.

Per Eric's review: the general `extend_of_disjoint` plus the existing
injectivity lemmas for `Sum.inl`/`Sum.inr` prove the specialization directly,
so it does not earn its place.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWf1KKiXXZSa2qQuWresw7
@kim-em

kim-em commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

bors merge

@mathlib-bors mathlib-bors Bot added the ready-to-merge This PR has been sent to bors. label Sep 10, 2026
mathlib-bors Bot pushed a commit that referenced this pull request Sep 10, 2026
This PR adds `Function.Injective.extend_of_disjoint`: if `f : α → β`, `g : α → γ` and `j : β → γ` are injective and `g` and `j` have disjoint ranges, then `Function.extend f g j` is injective. It is used in leanprover/cslib#401 to build families of total orders for a comparison-sorting lower bound, via `Function.extend f Sum.inl Sum.inr : β → α ⊕ β`.

🤖 Prepared with Claude Code
@mathlib-bors mathlib-bors Bot added the bors-staging This PR is currently being built by bors on the staging branch. label Sep 10, 2026
@mathlib-bors

mathlib-bors Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

@mathlib-bors mathlib-bors Bot changed the title feat: injectivity of Function.extend for disjoint ranges [Merged by Bors] - feat: injectivity of Function.extend for disjoint ranges Sep 10, 2026
@mathlib-bors mathlib-bors Bot closed this Sep 10, 2026
@mathlib-bors mathlib-bors Bot removed the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bors-staging This PR is currently being built by bors on the staging branch. ready-to-merge This PR has been sent to bors. t-logic Logic (model theory, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants