Skip to content

feat: Kronecker delta api#979

Open
gloges wants to merge 5 commits intoleanprover-community:masterfrom
gloges:kronecker-delta
Open

feat: Kronecker delta api#979
gloges wants to merge 5 commits intoleanprover-community:masterfrom
gloges:kronecker-delta

Conversation

@gloges
Copy link
Contributor

@gloges gloges commented Mar 8, 2026

Introduces a basic api for the Kronecker delta function.

  • I've kept to lemmas which adhere to the Einstein summation rules that indices occur at most twice in each term and free indices match across = (unless one side is zero). Hence no δ[i,j] • f i j = δ[i,j] • f i i lemma.
  • Commutators.lean and LaplaceRungeLenzVector.lean required some fixes, which I have done crudely (w/ sorries for some of the more computation-heavy lemmas); I will revisit these soon.

@morrison-daniel morrison-daniel self-assigned this Mar 8, 2026
Copy link
Collaborator

@morrison-daniel morrison-daniel left a comment

Choose a reason for hiding this comment

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

Just a few style points for now, I'll take a deeper look soon.


lemma kroneckerDelta_self (i : α) : δ[i,i] = 1 := if_pos rfl

lemma kroneckerDelta_diff {i j : α} (h : i ≠ j) : δ[i,j] = 0 := if_neg h
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
lemma kroneckerDelta_diff {i j : α} (h : i ≠ j) : δ[i,j] = 0 := if_neg h
lemma eq_zero_of_ne {i j : α} (h : i ≠ j) : δ[i,j] = 0 := if_neg h

This a more conventional way of writing this

-/
TODO "YVABB" "Build functionality for working with sums involving Kronecker deltas."

namespace KroneckerDelta
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since you're in the KroneckerDelta namespace you don't need to put kroneckerDelta into lemma names, it's already (implicitly) there.

@[inherit_doc]
notation "δ[" i "," j "]" => kroneckerDelta i j

lemma kroneckerDelta_self (i : α) : δ[i,i] = 1 := if_pos rfl
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
lemma kroneckerDelta_self (i : α) : δ[i,i] = 1 := if_pos rfl
@[simp]
lemma eq_one_of_same (i : α) : δ[i,i] = 1 := if_pos rfl

### Conditions for nsmul to vanish
-/

lemma nsmul_of_eq_zero [AddMonoid M] (i j : α) {f : α → α → M} (hf : f i i = 0) :
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
lemma nsmul_of_eq_zero [AddMonoid M] (i j : α) {f : α → α → M} (hf : f i i = 0) :
lemma smul_of_eq_zero [AddMonoid M] (i j : α) {f : α → α → M} (hf : f i i = 0) :

I think using "nsmul" isn't necessary since the delta function is a natural number it's clear the scalar multiplication is over naturals.

Comment on lines +71 to +72
lemma symmetrize [AddMonoid M] (i j : α) (f : α → α → M) :
(2 * δ[i,j]) • f i j = δ[i,j] • (f i j + f j i) := by
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
lemma symmetrize [AddMonoid M] (i j : α) (f : α → α → M) :
(2 * δ[i,j]) • f i j = δ[i,j] • (f i j + f j i) := by
lemma symmetrize [AddMonoid M] (i j : α) (f : α → α → M) :
δ[i,j] • (f i j + f j i) = (2 * δ[i,j]) • f i j := by

I would say to swap the order here since you generally want the simplified version on the right.

Comment on lines +77 to +78
lemma symmetrize' [AddCommMonoid M] {K : Type*} [Semifield K] [CharZero K] [Module K M]
(i j : α) (f : α → α → M) : δ[i,j] • f i j = δ[i,j] • (2 : K)⁻¹ • (f i j + f j i) := by
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps reverse the equality on this too, but I'm not sure which way you'd want to be using this.

Comment on lines +99 to +105
@[simp]
lemma sum_self : ∑ i : α, δ[i,i] = card α := by
simp [kroneckerDelta_self]

@[simp]
lemma sum_self_nsmul (f : M) : ∑ i : α, δ[i,i] • f = card α • f := by
simp [kroneckerDelta_self, one_nsmul]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would remove these, they're really just using the fact that δ[i,i] = 1 and then applying a lemma about sums.

section Sums
open Finset Fintype

variable [Fintype α] [AddCommMonoid M]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Having versions for summing over a Fintype is good, but I would also include versions for summing over finite sums in (possibly) infinite types.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants