-
Notifications
You must be signed in to change notification settings - Fork 97
feat: Kronecker delta sums #975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
59192cd
delta sum lemmas
gloges bfbae49
todo ideas
gloges 1149033
commutator fixes (sorryful)
gloges 310710a
LRL fixes (sorryful)
gloges aa71dad
Merge branch 'main' into kronecker-delta-sums
gloges 398631c
lint fix
gloges ccc9afa
general ring + coercion
gloges File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is a good idea, if anything we'd want to generalize this definition further and not narrow the uses. Can you explain why you want to revise the definition in this way?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No good reason - I've reverted to a general ring. Are the newly added simp lemmas the best way to handle coercion? (I have
ℝ → ℂseparate because for some reasonℝis not a subring ofℂ...!)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so this probably going to be a long comment but I think this is a great lesson worth learning about formalization and designing definitions.
Generally the goal with definitions is to define them so they are usable in as many scenarios as possible. The Kronecker delta function is useful any time you take a sum, and there are lots of types that aren't compatible with
ℝand are not rings where we may want to take a sum. Probably the easiest example isℕ: you can't multiplyℕbyℝand it is not a ring, but rather a semiring since it doesn't have a negation.So you may say, okay let's change the definition to
Semiring R. But this is also a trap! You see, 1 means a lot of things in Lean and not just numbers, any type with an instance of theOneclass will let you use 1. In a semiring or ring, 1 is the multiplicative identity. So 1 doesn't always mean the number one (natural, integer, real, or otherwise) but is something of the given type. An easy example isMatrix, where 1 refers to the identity matrix.With what you have now, the Kronecker delta function on a
Matrixtype will map to either the zero matrix or the identity matrix, and Lean would allow you to then multiply the Kronecker delta function and a vector, which isn't really what we want. We genuinely want the numbers 0 and 1.Then how do we define and use this function? Your inclination to map into the ring
Rmakes sense since that would allow you to multiply the Kronecker delta with an element of the ring. However, this is not the multiplication - we also have access to scalar multiplication. If a typeαhas an instance ofSMul ℕ αthis lets us writen • awherenis of typeℕandais of typeα, and the result is typeαas well. So what we want is to define this as a map intoℕand then use it with scalar multiplication on other types.The other thing we can generalize in the definition is the type of
iandjbeing inFin d. Again it makes sense that you did that as this is a common use but really we can do this in any type where we can compareiandj. This is encoded in an instance of the type[DecidableEq α], which essentially means that Lean knows how to tell ifiandjare equal.Putting it all together, we can define
When you want to prove lemmas about sums, you are using notation for
Finset.sumwhich is done on a typeMwith an instance[AddCommMonoid M], so you will needfor those lemmas. Remember we should also need an instance
[SMul ℕ M]to apply the Kronecker delta function, but Lean is able to figure out this on its own fromAddCommMonoid M. Basically the scalar multiplication is defined by repeated addition, as you would expect.Hopefully this makes sense, writing the right definition is a skill you have to learn with formalization because Lean will be picky about things you take for granted. If you like, I'm also happy to help set up the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS: Would you mind if I used snippets of your code here to write up a general explanation on how to make effective definitions? It's a common confusion for new contributors and I think this is a great example.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the comment about subrings, there is a good reason that we don't have a statement that
ℝis a subring ofℂ- it is not true (from a Lean perspective). If you look at the definition of Subring, you see that the typeSubring Rconsists of an elementSet Rplus some properties.Set Ris a set of elements of typeR. So something of typeSubring ℂis a set of elements of typeℂ- butℝis it's own independent type. The precise statement that is true in Lean is that the embedding ofℝinℂinduces subring ofℂ. RingHom.range is the more general statement of this idea. Again, this is an instance of Lean being picky about things you would normally totally ignore - to Lean real numbers and complex numbers are completely different objects and you need a map to move between them. As you found, this makes it really easy to get into trouble when you aren't careful about writing exactly what you mean!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is a lot to take in, but please don't be discouraged! It is a rite of passage for all Lean contributors to fall victim to this trap - usually many times - before getting the hang of things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking the time to write up this clear explanation and exemplifying the mindset that goes into proper formalization. The 'traps' would not have (and did not!) occur to me but are obvious with hindsight. I think this also sheds some light why in some calculation-heavy proofs I kept running into something like
2 : 𝓢(Space d, ℂ) →L[ℂ] 𝓢(Space d, ℂ).Please feel free to use this as an example - it has been a good learning experience for me and now hopefully for others!
I think I will close this PR and attack it again from scratch.