Skip to content

feat(LinearAlgebra/PiTensorProduct): API for PiTensorProducts indexed by sets - #32608

Draft
PrParadoxy wants to merge 22 commits into
leanprover-community:masterfrom
PrParadoxy:pi-set-3
Draft

PrParadoxy wants to merge 22 commits into
leanprover-community:masterfrom
PrParadoxy:pi-set-3

Conversation

@PrParadoxy

@PrParadoxy PrParadoxy commented Dec 8, 2025 •

Copy link
Copy Markdown
Contributor

This PR addresses a TODO item in LinearAlgebra/PiTensorProduct.lean:

  • API for the various ways ι can be split into subsets; connect this
    with the binary tensor product

-- specifically by describing tensors of type ⨂ (i : S), M i, for S : Set ι.

Our primary motivation is to formalise the notion of "restricted tensor
products". This will be the content of a follow-up PR.

Beyond that, the Set API is natural in contexts where the index type has
an independent interpretation. An example is quantum physics, where ι
ranges over distinguishable degrees of freedom, and where its is common
practice to annotate objects by the set of indices they are defined on.


Stub file with preliminary definition of the restricted tensor product as a direct limit of tensors indexed by finite subsets of an index type:
https://github.com/PrParadoxy/mathlib4/blob/restricted-stub/Mathlib/LinearAlgebra/PiTensorProduct/Restricted.lean


Open in Gitpod

…v` for dependent case

Dependent `PiTensorProduct`s over singleton types occur naturally when
using `tmulEquivDep` to split off one index from a dependent
`PiTensorProduct`. This PR creates `subsingletonEquivDep` to deal with
this situation.

The non-dependent `subsingletonEquiv` is re-defined as a specialization
of the general case. This breaks `toDirectSum_ι` in
TensorAlgebra/ToTensorPower, which relies on the precise definition of
`subsingletonEquiv`. Its proof is therefore changed to use `simp`
lemmas.
@github-actions github-actions Bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Dec 8, 2025
@github-actions

github-actions Bot commented Dec 8, 2025 •

Copy link
Copy Markdown

PR summary 758284ccda

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.LinearAlgebra.PiTensorProduct.Set (new file) 723

Declarations diff

+ extendEnd
+ extendEnd_tprod
+ extendFunctional
+ extendFunctional_tprod
+ extendLinear
+ extendLinear_tprod
+ extendTensor
+ extendTensor_self
+ extendTensor_tprod
+ extendTensor_trans
+ singletonEquiv_symm_tprod
+ singletonEquiv_tprod
+ singletonSetEquiv
+ tmulBipartitionEquiv
+ tmulBipartitionEquiv_tprod
+ tmulBipartition_symm_tprod
+ tmulDiffEquiv
+ tmulDiffEquiv_tprod
+ tmulDiffEquiv_tprod_symm
+ tmulInsertEquiv
+ tmulInsertEquiv_symm_tprod
+ tmulInsertEquiv_tprod
+ tmulUnionEquiv
+ tmulUnionEquiv_symm_tprod
+ tmulUnionEquiv_tprod
+ univEquiv
+ univEquiv_symm_tprod
+ univEquiv_tprod

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

@mathlib4-merge-conflict-bot

Copy link
Copy Markdown

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

@mathlib4-merge-conflict-bot mathlib4-merge-conflict-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 Dec 9, 2025
@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 Dec 9, 2025
… by sets

This PR addresses a TODO item in LinearAlgebra/PiTensorProduct.lean:

  * API for the various ways `ι` can be split into subsets; connect this
    with the binary tensor product

-- specifically by describing tensors of type `⨂ (i : S), s i`, for `S : Set ι`.

Our primary motivation is to formalize the notion of "tensors with
infinite index set, which are equal to a distinguished element on all
but finitely many indices". This is a standard construction e.g. in the
theory of "infinite tensor products" of unital algebras.

Beyond that, the `Set` API is natural in contexts where the index type has
an independent interpretation. An example is quantum physics, where `ι`
ranges over distinguishable degrees of freedom, and where its is common
practice to annotate objects by the set of indices they are defined on.

This PR creates a directory LinearAlgebra/PiTensorProduct and starts the
file Set.lean.

A separate PR adds results on finite families of disjoint subsets.

---

The material is enough to define the notion of "tensors of finite
support", see WIP here:

https://github.com/PrParadoxy/mathlib4/blob/test/Mathlib/LinearAlgebra/PiTensorProduct/Finsupp.lean
@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Dec 11, 2025
@mathlib4-dependent-issues-bot

Copy link
Copy Markdown

@mathlib4-merge-conflict-bot mathlib4-merge-conflict-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 Dec 11, 2025
@mathlib4-merge-conflict-bot

Copy link
Copy Markdown

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

@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 Dec 12, 2025
@PrParadoxy

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Dec 12, 2025 •

Copy link
Copy Markdown

Benchmark results for 7193e20 against d76e532 are in! @PrParadoxy

No significant changes detected.

@dagurtomas dagurtomas 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 haven't had time yet to review the proofs in detail, here are a few comments about documentation. Also, if this resolves a TODO somewhere, you should remove it. In the PR description, you mention applying this to formalize "tensors with infinite index set, which are equal to a distinguished element on all but finitely many indices". Do you have any concrete progress on this which uses the code in this PR? (It's ok if you don't, it's just nice to have evidence that the API is working well).

Comment on lines +20 to +24
* Equivalences for `PiTensorproduct`s over sets:

Definition... ...pertains to
`univEquiv` `univ : Set ι`
`singletonEquiv` `{i₀}`

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.

You should say what each definition is, not what it pertains to.

Comment on lines +46 to +49
## TODO

* Injectivity lemmas for the extensions. These are easy for vector spaces, but
can become quite subtle for `AddCommMonoid`s.

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.

What precise statements are you after here?

@goliath-klein goliath-klein Dec 30, 2025 •

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.

We've stated it more precisely.

Also, we've included a new TBD item, together with a reference to a PR that's already in the queue:


  • We currently treat only pairs of subsets of the index type. The generalization
    to finite collections is PR #32609.

OK?

Comment on lines +64 to +65
/-- Tensors indexed by `ι` are isomorphic to tensors indexed by `univ : Set ι`. -/
def univEquiv : (⨂[R] i, s i) ≃ₗ[R] ⨂[R] i : ↥univ, s i.val := reindex R s (Equiv.Set.univ ι).symm

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
/-- Tensors indexed by `ι` are isomorphic to tensors indexed by `univ : Set ι`. -/
def univEquiv : (⨂[R] i, s i) ≃ₗ[R] ⨂[R] i : ↥univ, s i.val := reindex R s (Equiv.Set.univ ι).symm
/-- The tensor product of a family of modules indexed by `ι` is isomorphic
to the tensor product of the corresponding family indexed by `univ : Set ι`. -/
def univEquiv : (⨂[R] i, s i) ≃ₗ[R] ⨂[R] i : ↥univ, s i.val := reindex R s (Equiv.Set.univ ι).symm

Similar for other docstrings that say that "tensors ... are isomorphic to ..."

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.

We've reworked all the docstrings.

The format you suggest works well for the short definitions, but becomes a bit too verbose for the more complex ones. Our new format borrows idioms from PiTensorProduct.tmulEquivDep. Should be more precise now.

(Lesson learned: Writing good docstrings is surprisingly hard!)

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

This looks mostly good to me, once my previous comments have been addressed. However, I wonder if we want specialized API for this, i.e. a definition Set.TensorProduct which is the restriction of a PiTensorProduct to a set of the indexing type.

I'll mark this PR as awaiting-zulip until we've had some input from regular users of tensor products on the [Zulip thread](#mathlib4 > Tensor products indexed by a set) I created.

@dagurtomas dagurtomas added awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. awaiting-zulip There is a Zulip discussion; the author should await and report/implement the decision reached there labels Dec 22, 2025
Comment on lines +28 to +32
Definition... ...pertains to
`tmulUnionEquiv` `S₁ ∪ S₂`
`tmulBipartitionEquiv` `S ∪ Sᶜ`
`tmulUnifyEquiv` `S ∪ (T \ S)`
`tmulInsertEquiv` `{i₀} ∪ S`

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.

This will render quite badly in docgen: I'd suggest just a bulleted list, or if you insist a markdown table.

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.

Changed to standard style.


/-- For sets `S ⊆ T`, tensors indexed by `S` times tensors indexed by `T \ S`
are isomorphic to tensors indexed by `T`. -/
def tmulUnifyEquiv :

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.

This name seems a little weird to me, especially as unify appears neither in the docstring nor the implementation.

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.

@eric-wieser As tmulUnionEquiv already exists, what naming convention would you suggest for this particular equivalence?

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.

tmulDiffEquiv maybe?

Comment on lines +205 to +208
/-- An equivalence `e : Equiv.Perm ι` maps tensors indexed by a set `S` to
tensors indexed by `e '' S`. -/
def permSetEquiv : (⨂[R] _ : S, M) ≃ₗ[R] ⨂[R] _ : (e '' S), M :=
reindex R (fun _ ↦ M) (Equiv.image e S)

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.

Arguably this one should have M be dependently-typed

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.

Right.

On consideration, we have removed the section containing this definition and the two simp lemmas.

Reasons:

  • The definition is too thin a wrapper around reindex to merit its own definition.
  • We've done some follow-up work and never felt the urge to use permSetEquiv so far.


/-- For sets `S ⊆ T`, tensors indexed by `S` times tensors indexed by `T \ S`
are isomorphic to tensors indexed by `T`. -/
def tmulUnifyEquiv :

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.

tmulDiffEquiv maybe?

@[simp]
theorem tmulInsertEquiv_tprod (x : s i₀) (f : (i : S) → s i) :
(tmulInsertEquiv h₀) (x ⊗ₜ[R] (⨂ₜ[R] i, f i)) = ⨂ₜ[R] i : ↥(insert i₀ S),
if h : i.val ∈ ({i₀} : Set ι) then cast (by grind) x else f ⟨i, by grind⟩ := 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.

Why not use an equality here, i.val = i₀?

@goliath-klein

goliath-klein commented Dec 30, 2025 •

Copy link
Copy Markdown
Contributor

Further changes since last review:

  • We've changed s to M for the family of modules. That's more consistent with the conventions in the rest of the library. (The notation 's' is used in PiTensorProduct.lean. Only after we had submitted the PR, the directory PiTensorProduct was added with new files that also use M (like Dual.lean). So now there's precedent).
  • Added the simp lemma extendTensor_tprod. This was missing before.
  • Made the ring R an explicit argument in the Extensions section. Saves a few (R:=R) here, and in follow-up work.

@goliath-klein

Copy link
Copy Markdown
Contributor

Also, if this resolves a TODO somewhere, you should remove it. In the PR description, you mention applying this to formalize "tensors with infinite index set, which are equal to a distinguished element on all but finitely many indices". Do you have any concrete progress on this which uses the code in this PR? (It's ok if you don't, it's just nice to have evidence that the API is working well).

  • "TODO" is now removed.
  • The link to the stub file on restricted tensor products came up in the Zulip discussion, but is now also included in the PR description "below the fold".

@PrParadoxy

Copy link
Copy Markdown
Contributor Author

-awaiting-author

@github-actions github-actions Bot removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Dec 30, 2025
`tmulBipartitionEquiv` is the equivalence between the binary tensor product of
`PiTensorProduct`s indexed by `S` and its complement `Sᶜ`, and the
`PiTensorProduct` indexed by `ι`. -/
def tmulBipartitionEquiv : (⨂[R] i₁ : S, M i₁) ⊗[R] (⨂[R] i₂ : ↥Sᶜ, M i₂) ≃ₗ[R] ⨂[R] i, M i :=

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.

This might be more useful as

Suggested change
def tmulBipartitionEquiv : (⨂[R] i₁ : S, M i₁) ⊗[R] (⨂[R] i₂ : ↥Sᶜ, M i₂) ≃ₗ[R] ⨂[R] i, M i :=
def tmulBipartitionEquiv (hST : IsCompl S T) : (⨂[R] i₁ : S, M i₁) ⊗[R] (⨂[R] i₂ : T, M i₂) ≃ₗ[R] ⨂[R] i, M i :=

since that naturally lets you swap S and Sᶜ, and matches the interface of subtypeEquivProp.

/-- Consider a family of modules indexed by `ι` and a set `S : Set ι`.
`tmulBipartitionEquiv` is the equivalence between the binary tensor product of
`PiTensorProduct`s indexed by `S` and its complement `Sᶜ`, and the
`PiTensorProduct`s indexed by `S` and its complement `T = Sᶜ`, and the

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.

Suggested change
`PiTensorProduct`s indexed by `S` and its complement `T = Sᶜ`, and the
`PiTensorProduct`s indexed by complemtary sets `S` and `T`, and the

@eric-wieser

eric-wieser commented Jan 3, 2026 •

Copy link
Copy Markdown
Member

Apologies for not raising it earlier; this API makes me a little uneasy, because I don't think we have anything analogous anywhere.

Concretely, this PR adds the following

def PiTensorProduct.univEquiv : (⨂[R] i, M i) ≃ₗ[R] ⨂[R] i : ↥univ, M i.val
def PiTensorProduct.singletonSetEquiv (i₀ : ι) : (⨂[R] i : ({i₀} : Set ι), M i) ≃ₗ[R] M i₀
def PiTensorProduct.tmulUnionEquiv :
    ((⨂[R] (i₁ : S₁), M i₁) ⊗[R] (⨂[R] (i₂ : S₂), M i₂)) ≃ₗ[R] ⨂[R] (i : ↥(S₁ ∪ S₂)), M i
def PiTensorProduct.tmulBipartitionEquiv :
    (⨂[R] i₁ : S, M i₁) ⊗[R] (⨂[R] i₂ : T, M i₂) ≃ₗ[R] ⨂[R] i, M i :=
def PiTensorProduct.tmulDiffEquiv :
    (⨂[R] i₁ : S, M i₁) ⊗[R] (⨂[R] i₂ : ↥(T \ S), M i₂) ≃ₗ[R] ⨂[R] i : T, M i 
def PiTensorProduct.tmulInsertEquiv :
    ((M i₀) ⊗[R] (⨂[R] i₁ : S, M i₁)) ≃ₗ[R] (⨂[R] i₁ : ↥(insert i₀ S), M i₁)

but there's nothing particularly special about PiTensorProduct here. If we're going to declare these worth of API, then we should probably first do so for more elementary types, like

def Pi.univEquiv : (Π i, M i) ≃ Π i : ↥univ, M i.val
def Pi.singletonSetEquiv (i₀ : ι) : (Π i : ({i₀} : Set ι), M i) ≃ M i₀
def Pi.prodUnionEquiv :
    ((Π (i₁ : S₁), M i₁) × (Π (i₂ : S₂), M i₂)) ≃ Π (i : ↥(S₁ ∪ S₂)), M i
def Pi.prodBipartitionEquiv :
    (Π i₁ : S, M i₁) × (Π i₂ : T, M i₂) ≃ Π i, M i :=
def Pi.prodDiffEquiv :
    (Π i₁ : S, M i₁) × (Π i₂ : ↥(T \ S), M i₂) ≃ Π i : T, M i 
def Pi.prodInsertEquiv :
    ((M i₀) × (Π i₁ : S, M i₁)) ≃ (Π i₁ : ↥(insert i₀ S), M i₁)
-- and `AddEquiv`, `MulEquiv`, `LinearEquiv`, `RingEquiv`, `AlgEquiv` versions of the above

or

def DirectSum.univEquiv : (⨁ i, M i) ≃ ⨁ i : ↥univ, M i.val
def DirectSum.singletonSetEquiv (i₀ : ι) : (⨁ i : ({i₀} : Set ι), M i) ≃ M i₀
def DirectSum.prodUnionEquiv :
    ((⨁ (i₁ : S₁), M i₁) × (⨁ (i₂ : S₂), M i₂)) ≃ ⨁ (i : ↥(S₁ ∪ S₂)), M i
def DirectSum.prodBipartitionEquiv :
    (⨁ i₁ : S, M i₁) × (⨁ i₂ : T, M i₂) ≃ ⨁ i, M i
def DirectSum.prodDiffEquiv :
    (⨁ i₁ : S, M i₁) × (⨁ i₂ : ↥(T \ S), M i₂) ≃ ⨁ i : T, M i 
def DirectSum.prodInsertEquiv :
    ((M i₀) × (⨁ i₁ : S, M i₁)) ≃ (⨁ i₁ : ↥(insert i₀ S), M i₁)

(and for DFinsupp, Finsupp, and probably some more I'm forgetting)

So either:

  • We already have these APIs somewhere else. We should find them, ensure the names are consistent, and add cross-references.
  • We do not have any of these APIs somewhere else. We should think carefully about whether they are actually worth the maintainance cost. In practice, it is often the case that we don't work with set indicies in the first place, and stick with Sum and Option types.

Did you have a use-case in mind for these, or was the primary motivation to fill out the TODO?

@eric-wieser

eric-wieser commented Jan 3, 2026 •

Copy link
Copy Markdown
Member

(Perhaps let's continue discussion in #mathlib4 > Tensor products indexed by a set @ 💬 for everything except your motivation)

@joneugster joneugster added the t-algebra Algebra (groups, rings, fields, etc) label Feb 1, 2026
@dagurtomas dagurtomas removed their assignment Mar 18, 2026
@dagurtomas

Copy link
Copy Markdown
Contributor

@PrParadoxy nothing has happened here or in the Zulip discussion for quite a while. What's the status here? Do you feel like you have gotten clear feedback on how to proceed if you want this merged? Or is this stuck on some disagreement?

@dagurtomas dagurtomas added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label May 7, 2026
@goliath-klein

goliath-klein commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

The Zulip discussion did not produce a consensus that such an API was needed in Mathlib.

@PrParadoxy and me wrote it in order to implement the restricted tensor product. After the Zulip discussion stalled, our plan changed to finishing that project first, and to re-open the discussion once this is done. The logic being that with a concrete project building on the Set API, it would be easier to see whether it is useful or whether there are better alternatives.

We have since gotten sidetracked with a different project, and there isn't currently a time-line for the restricted tensor product.

Should we mark this PR as WIP in the meantime, so as to remove it from the review queue?

Another motivation for the PR was a "TBD item" in PiTensorProduct.lean calling for a Set API. This should probably be removed given the lack of consensus at the moment. We can submit a mini PR to that effect.

@goliath-klein

Copy link
Copy Markdown
Contributor

-awaiting-author

@github-actions github-actions Bot removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label May 11, 2026
@dagurtomas dagurtomas added the WIP Work in progress label May 11, 2026
@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 Jun 19, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

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

@joneugster
joneugster marked this pull request as draft September 19, 2026 16:43
@mathlib-bors

mathlib-bors Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

This pull request is now in draft mode. No active bors state needed cleanup.

While this PR remains draft, bors will ignore commands on this PR. Mark it ready for review before using commands like bors r+ or bors try.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-zulip There is a Zulip discussion; the author should await and report/implement the decision reached there merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-algebra Algebra (groups, rings, fields, etc) WIP Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants