Skip to content

feat: add DFinsupp.mapDomain to match Finsupp.mapDomain#38977

Open
eric-wieser wants to merge 12 commits into
leanprover-community:masterfrom
eric-wieser:dfinsupp-mapDomain
Open

feat: add DFinsupp.mapDomain to match Finsupp.mapDomain#38977
eric-wieser wants to merge 12 commits into
leanprover-community:masterfrom
eric-wieser:dfinsupp-mapDomain

Conversation

@eric-wieser

@eric-wieser eric-wieser commented May 6, 2026

Copy link
Copy Markdown
Member

The API for DFinsupp.mapDomain is copied from Finsupp.mapDomain.

One motivation here is to make it easier to swap out either Basis or AddMonoidAlgebra to use DFinsupp and thus become computable.


Open in Gitpod

@github-actions github-actions Bot added the t-data Data (lists, quotients, numbers, etc) label May 6, 2026
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

PR summary a60ac7cccf

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Data.DFinsupp.Basic (new file) 781

Declarations diff (regex)

+ _root_.Function.Injective.subsingleton_fiber
+ embDomain
+ embDomain_apply_self
+ embDomain_eq_mapDomain
+ embDomain_notin_range
+ equivCongrLeft_symm_eq_mapDomain
+ mapDomain
+ mapDomain.addMonoidHom
+ mapDomain.addMonoidHom_apply
+ mapDomain.addMonoidHom_comp
+ mapDomain.addMonoidHom_comp_mapRange
+ mapDomain.addMonoidHom_id
+ mapDomainEmbedding
+ mapDomain_add
+ mapDomain_apply
+ mapDomain_apply'
+ mapDomain_comp
+ mapDomain_congr
+ mapDomain_dcongr
+ mapDomain_eq_sum
+ mapDomain_equiv_apply
+ mapDomain_finsetSum
+ mapDomain_fun_id
+ mapDomain_id
+ mapDomain_injOn
+ mapDomain_injective
+ mapDomain_mapRange
+ mapDomain_notin_range
+ mapDomain_rightInverse
+ mapDomain_single
+ mapDomain_sub
+ mapDomain_sum
+ mapDomain_support
+ mapDomain_support_of_injOn
+ mapDomain_support_of_injective
+ mapDomain_surjective
+ mapDomain_zero
+ mapRange_fun_comp
+ mapRange_fun_id
+ prod_congr
+ prod_embDomain
+ prod_mapDomain_index
+ prod_mapDomain_index_inj
+ sum_mapDomain_index_addMonoidHom
+ support_embDomain

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

  • +57 new declarations
  • −0 removed declarations
+AddCommMonoid.toAddMonoid.hcongr_2
+AddMonoid.toAddZeroClass.hcongr_2
+AddZero.toZero.hcongr_2
+AddZeroClass.toAddZero.hcongr_2
+DFinsupp.embDomain
+DFinsupp.embDomain.match_1.congr_eq_1
+DFinsupp.embDomain.match_1.congr_eq_2
+DFinsupp.embDomain_apply_self
+DFinsupp.embDomain_eq_mapDomain
+DFinsupp.embDomain_notin_range
+DFinsupp.equivCongrLeft_symm_eq_mapDomain
+DFinsupp.mapDomain
+DFinsupp.mapDomain.addMonoidHom
+DFinsupp.mapDomain.addMonoidHom_apply
+DFinsupp.mapDomain.addMonoidHom_comp
+DFinsupp.mapDomain.addMonoidHom_comp_mapRange
+DFinsupp.mapDomain.addMonoidHom_id
+DFinsupp.mapDomain.congr_simp
+DFinsupp.mapDomainEmbedding
+DFinsupp.mapDomainEmbedding_apply
+DFinsupp.mapDomain_add
+DFinsupp.mapDomain_apply
+DFinsupp.mapDomain_apply'
+DFinsupp.mapDomain_comp
+DFinsupp.mapDomain_congr
+DFinsupp.mapDomain_dcongr
+DFinsupp.mapDomain_eq_sum
+DFinsupp.mapDomain_equiv_apply
+DFinsupp.mapDomain_finsetSum
+DFinsupp.mapDomain_fun_id
+DFinsupp.mapDomain_id
+DFinsupp.mapDomain_injOn
+DFinsupp.mapDomain_injective
+DFinsupp.mapDomain_mapRange
+DFinsupp.mapDomain_notin_range
+DFinsupp.mapDomain_rightInverse
+DFinsupp.mapDomain_single
+DFinsupp.mapDomain_sub
+DFinsupp.mapDomain_sum
+DFinsupp.mapDomain_support
+DFinsupp.mapDomain_support_of_injOn
+DFinsupp.mapDomain_support_of_injective
+DFinsupp.mapDomain_surjective
+DFinsupp.mapDomain_zero
+DFinsupp.mapRange_fun_comp
+DFinsupp.mapRange_fun_id
+DFinsupp.prod_congr
+DFinsupp.prod_embDomain
+DFinsupp.prod_mapDomain_index
+DFinsupp.prod_mapDomain_index_inj
+DFinsupp.sum_congr
+DFinsupp.sum_embDomain
+DFinsupp.sum_mapDomain_index
+DFinsupp.sum_mapDomain_index_addMonoidHom
+DFinsupp.sum_mapDomain_index_inj
+DFinsupp.support_embDomain
+Function.Injective.subsingleton_fiber

Increase in strong tech debt: (relative, absolute) = (1.00, 0.00)
Current number Change Type (strong)
499 1 erw
Increase in weak tech debt: (relative, absolute) = (1.00, 0.00)
Current number Change Type (weak)
5011 1 exposed public sections

Current commit a60ac7cccf
Reference commit 1f165a51de

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

@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label May 23, 2026
@eric-wieser
eric-wieser temporarily deployed to cache-upload-forks June 5, 2026 22:49 — with GitHub Actions Inactive
@eric-wieser
eric-wieser temporarily deployed to cache-upload-forks June 6, 2026 01:46 — with GitHub Actions Inactive
@eric-wieser
eric-wieser temporarily deployed to cache-upload-forks June 6, 2026 02:21 — with GitHub Actions Inactive
@eric-wieser
eric-wieser temporarily deployed to cache-upload-forks June 7, 2026 06:18 — with GitHub Actions Inactive
@eric-wieser
eric-wieser temporarily deployed to cache-upload-forks June 7, 2026 07:34 — with GitHub Actions Inactive
@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 Jun 7, 2026
@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 Jul 13, 2026
@mathlib-dependent-issues

Copy link
Copy Markdown

This PR/issue depends on:

@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jul 13, 2026
@eric-wieser eric-wieser changed the title feat: DFinsupp.mapDomain feat: add DFinsupp.mapDomain to match Finsupp.mapDomain Jul 13, 2026
@eric-wieser
eric-wieser requested a review from YaelDillies July 13, 2026 22:06
@eric-wieser
eric-wieser marked this pull request as ready for review July 13, 2026 22:06

@YaelDillies YaelDillies 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.

I am worried that striving for local consistency here means you are spreading some bad design choices about Finsupp.

Comment on lines +128 to +135
theorem mapRange_fun_id (g : Π₀ i : ι, β₁ i) :
mapRange (fun _ x => x) (fun _ => rfl) g = g := by
ext
rfl

@[simp]
theorem mapRange_id (g : Π₀ i : ι, β₁ i) :
mapRange (fun i => (id : β₁ i → β₁ i)) (fun _ => rfl) g = g :=

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
theorem mapRange_fun_id (g : Π₀ i : ι, β₁ i) :
mapRange (fun _ x => x) (fun _ => rfl) g = g := by
ext
rfl
@[simp]
theorem mapRange_id (g : Π₀ i : ι, β₁ i) :
mapRange (fun i => (id : β₁ i → β₁ i)) (fun _ => rfl) g = g :=
@[to_fun (attr := simp) mapRange_fun_id]
theorem mapRange_id (g : Π₀ i : ι, β₁ i) :
mapRange (fun i => (id : β₁ i → β₁ i)) (fun _ => rfl) g = g :=

ext
simp only [mapRange_apply]

theorem mapRange_comp (f : ∀ i, β₁ i → β₂ i) (f₂ : ∀ i, β i → β₁ i) (hf : ∀ i, f i 0 = 0)

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.

Same here

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.

Should it not be Map?

theorem mapDomain_fun_id (x : Π₀ b, M b) : mapDomain (·) x = x :=
congr($(sumAddHom_singleAddHom) x)

/-- Note that `x` the RHS is mildly type-incorrect. -/

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
/-- Note that `x` the RHS is mildly type-incorrect. -/
/-- Note that `x` in the RHS is mildly type-incorrect. -/

Comment on lines +156 to +159
/-- Note that `x` the RHS is mildly type-incorrect. -/
@[simp]
theorem mapDomain_id (x : Π₀ b, M (id b)) :
mapDomain id x = x :=

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.

Doesn't that mean we shouldn't have this lemma?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I tried adding the correct version with suitable casting, but simp simplifies the id in the type anyway and changes it to this form.

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.

Surely this is a bug?

· grind
· exact (hs a).resolve_left ha |>.symm

lemma embDomain_notin_range (f : α ↪ β) (v : Π₀ a, M (f a)) {b : β} (hb : b ∉ Set.range f) :

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.

Let's not spread poor naming

Suggested change
lemma embDomain_notin_range (f : α ↪ β) (v : Π₀ a, M (f a)) {b : β} (hb : b ∉ Set.range f) :
lemma embDomain_of_notMem_range (f : α ↪ β) (v : Π₀ a, M (f a)) {b : β} (hb : b ∉ Set.range f) :

See #41766 for the Finsupp rename

Comment on lines +120 to +121
is the finitely supported function whose value at `a : β` is the sum
of `v x` over all `x` such that `f x = a`. -/

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
is the finitely supported function whose value at `a : β` is the sum
of `v x` over all `x` such that `f x = a`. -/
is the finitely supported function whose value at `a : β` is the sum
of `v x` over all `x` such that `f x = a`. -/

Comment on lines +183 to +185
theorem mapDomain_congr {f g : α → β} [(x : N) → Decidable (x ≠ 0)]
(v : Π₀ _ : α, N) (h : ∀ x ∈ v.support, f x = g x) :
v.mapDomain f = (mapDomain g v : Π₀ _ : β, N) := by

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.

I suggest

Suggested change
theorem mapDomain_congr {f g : α → β} [(x : N) → Decidable (x ≠ 0)]
(v : Π₀ _ : α, N) (h : ∀ x ∈ v.support, f x = g x) :
v.mapDomain f = (mapDomain g v : Π₀ _ : β, N) := by
@[congr]
theorem mapDomain_congr {f g : α → β} [(x : N) → Decidable (x ≠ 0)]
(v : Π₀ _ : α, N) (h : ∀ x ∈ v.support, f x = g x) :
v.mapDomain f = (mapDomain g v : Π₀ _ : β, N) := by

to match #39575

Comment on lines +196 to +203
theorem mapDomain_add {f : α → β} (v₁ v₂ : Π₀ a, M (f a)) :
mapDomain f (v₁ + v₂) = mapDomain f v₁ + mapDomain f v₂ :=
map_add _ _ _

lemma mapDomain_sub {M : β → Type*} [∀ b, AddCommGroup (M b)]
{f : α → β} (v₁ v₂ : Π₀ a, M (f a)) :
mapDomain f (v₁ - v₂) = mapDomain f v₁ - mapDomain f v₂ :=
map_sub _ _ _

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.

Any reason not to make this simp?

@YaelDillies YaelDillies added the awaiting-author A reviewer has asked the author a question or requested changes. label Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author A reviewer has asked the author a question or requested changes. t-data Data (lists, quotients, numbers, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants