Skip to content

feat(LinearAlgebra): add a variable_alias for VectorSpace - #19212

Closed
Julian wants to merge 1 commit into
masterfrom
vector-space
Closed

Julian wants to merge 1 commit into
masterfrom
vector-space

Conversation

@Julian

@Julian Julian commented Nov 18, 2024 •

Copy link
Copy Markdown
Member

Taken directly from the variable_alias docs.

Zulip: https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/why.20.5Bvariable_alias.5D.20attribute.20is.20not.20used.20in.20Mathlib.3F


This is the first actual variable alias added to mathlib. I haven't reviewed variable_alias fully, but it seems like there's at least 3 ways they could be distributed in Mathlib:

  • alongside whatever subfolder they "belong to" (which is what I've tentatively done here)
  • In a file called Aliases somewhere near the thing they alias (which seems less discoverable to me)
  • In a single file, a la Mathlib.TrainingWheels (with some less playful name) which is meant to define a bunch of more "friendly" aliases all in one place.

I kind of like the idea of the third thing as a future module but perhaps it can be synthesized if/when there are more aliases? For now as I say I've done the first one, but please let me know if someone prefers something else.

Open in Gitpod

@github-actions

github-actions Bot commented Nov 18, 2024 •

Copy link
Copy Markdown

PR summary dd812d8c50

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.LinearAlgebra.VectorSpace 425

Declarations diff

+ VectorSpace

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

@github-actions github-actions Bot added the t-algebra Algebra (groups, rings, fields, etc) label Nov 18, 2024
Taken directly from the variable_alias docs.
Comment thread scripts/noshake.json
"Mathlib.Logic.Function.Defs": ["Mathlib.Tactic.AdaptationNote"],
"Mathlib.Logic.Function.Basic": ["Batteries.Tactic.Init"],
"Mathlib.Logic.Equiv.Defs": ["Mathlib.Data.Bool.Basic"],
"Mathlib.LinearAlgebra.VectorSpace": ["Mathlib.Algebra.Module.Pi"],

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'm aware this is needed because I used Mathlib.Algebra.Module.Pi -- my rationale was that someone looking for the alias was likely to be newer, and that this other import seems reasonably cheap anyways. Let me know if that doesn't seem like a good enough reason to ignore this.)

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.

Please add a test file with variable? [VectorSpace K V] and guard_msgs instead.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(newbie:) Is there a standard format for adding a test file? What to name it, where to place it? Just asking so I can mimick the moves in my own PR.

@PieterCuijpers

Copy link
Copy Markdown
Collaborator

I just started to use an alias in my own PR on Quantales as well (branch#PieterCuijpers_Quantales / #17289) and basically follow the same route. I just defined the alias in the 'main file' where, I think, it belongs. The planned use, after all to me, is writing [VectorSpace a] is more natural (in a file that proofs something about vector spaces) than writing the unfolding of it.

In my case, my reviewers asked me to define a mixin IsQuantale instead of having a proper class Quantale.
The latter seems more natural to me from a 'software structure' point of view, but I understand that having the mixin leads to (much?) less overhead in re-proving theorems. The alias 'saves' me, so I can define at least the structure Quantale after all - which was the point of the whole file. Hence, I feel the alias belongs there.

But then again... this is my first PR ever... so I don't really now anything ;-)
Curious to learn what happens to your PR.

@Julian

Julian commented Nov 18, 2024

Copy link
Copy Markdown
Member Author

Aha! Thanks for the cross-link and info, I'll have a look at yours as well!

/-- A vector space is a module over a field. -/
@[variable_alias]
structure VectorSpace (k V : Type*)
[Field k] [AddCommGroup V] [Module k V]

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.

The docstring should underline the fact that this is not a class and it's here to be used with a variable? command, not as a [VectorSpace K V] assumption in a theorem.

@Julian Julian Nov 18, 2024 •

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 agree with this) but it will apply to every use of variable_alias, correct? In which case it seems like perhaps variable_alias should automatically append that sort of message to the docstring of the declaration you use it on, presuming that should be possible, no?

@PieterCuijpers

Copy link
Copy Markdown
Collaborator

Aha! Thanks for the cross-link and info, I'll have a look at yours as well!

@Julian That would be great. However, I'm a bit weighing off two choices. I'd like the quantale PR to go through quickly, and having the variable_alias in there may slow down the reviewing process. It may be better to make it a separate PR after the first one got through. So I'll probably remove it for now and get back to you a.s.a.p. keeping an eye on this discussion for inspiration.

@PieterCuijpers

Copy link
Copy Markdown
Collaborator

The original PR for Quantale has been merged, now it's time to add the variable_alias. I've added a dependency to this PR, so that we can focus the discussion.

@leanprover-community-bot-assistant leanprover-community-bot-assistant added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 26, 2024
@joneugster

Copy link
Copy Markdown
Member

Mathlib has moved to PRs from forks. This PR is still from a branch of the main repository and will soon be closed! Please migrate the content to a fork and reopen a PR from there if you wish to do so. See Zulip topic for more instructions. Thank you for contributing to mathlib!

@joneugster joneugster added the will-close-soon Unless something changes, we will close this PR soon label Sep 19, 2026
@Julian Julian closed this Sep 19, 2026
@YaelDillies
YaelDillies deleted the vector-space branch October 24, 2026 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) t-algebra Algebra (groups, rings, fields, etc) will-close-soon Unless something changes, we will close this PR soon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants