Skip to content

feat(LinearAlgebra/AffineSpace/Simplex): CoeFun instance for Simplex - #30853

Open
JovanGerb wants to merge 9 commits into
leanprover-community:masterfrom
JovanGerb:Jovan-Simplex-FunLike
Open

JovanGerb wants to merge 9 commits into
leanprover-community:masterfrom
JovanGerb:Jovan-Simplex-FunLike

Conversation

@JovanGerb

Copy link
Copy Markdown
Contributor

This PR introduces the notation s i to refer to the ith vertex of simplex s, which replaces the current s.points i. It does this by adding a CoeFun instance.

I first tried using FunLike, but this came with some different problems related to discrimination tree indexing in simp.


Open in Gitpod

@github-actions

github-actions Bot commented Oct 24, 2025 •

Copy link
Copy Markdown

PR summary 25333c500c

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ instance {n : ℕ} : CoeFun (Simplex k P n) (fun _ => Fin (n + 1) → P)
+ mkOfPoint_apply
- mkOfPoint_points

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.


Decrease in tech debt: (relative, absolute) = (1.00, 0.00)
Current number Change Type
275 -1 documentation nolint entries

Current commit 3715253ae7
Reference commit 25333c500c

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

@JovanGerb JovanGerb changed the title feat(LinearAlgebra/AffineSpace/Simples): CoeFun instance for Simplex feat(LinearAlgebra/AffineSpace/Simplex): CoeFun instance for Simplex Oct 24, 2025
Comment on lines +57 to +59
run_cmd Lean.Elab.Command.liftTermElabM do
Lean.Meta.registerCoercion ``points
(some { numArgs := 9, coercee := 8, type := .coeFun })

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 is this code for? I wouldn't expect a straightforward coercion such as this one to need more than the CoeFun instance plus a coe attribute. If it needs extra meta code such as this, I think it should come with a comment referencing an open bug against either Lean itself, for needing such code at all, or the Lean reference manual, for failing to discuss anywhere in the coercions section when and why you might want to do things like this with Lean.Meta.registerCoercion.

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.

The reason for this code is that I want s i instead of ↑s i and ⇑s instead of ↑s. So we need a @[coe_fun] attribute, but this attribute doesn't exist. Do you think it should exist? And do you agree we want to have the ⇑ arrow?

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 agree that delaborating with ⇑ would be good. I don't think each individual instance of coercion to a function should be running special-case meta code to achieve that; it would be better to have an open issue against Lean to request an improvement (such as a @[coe_fun] attribute) to achieve better delaboration for coercion to functions, and then once fixed the attribute could be added to relevant coercions in mathlib without needing to remove lots of custom meta code as well.

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.

I think it's not such a big deal to have to run this meta code. The same is used for DFunLike.coe. Or do you think there are many places in Mathlib that would need a @[coeFun] attribute?

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.

There are lots of CoeFun instances in mathlib, and only two cases of this meta code (DFunLike.coe and Setoid.r). The first step before adding more should be to have an open Lean issue about the need for this meta code and then ensure that every instance of that meta code in mathlib has a comment referencing that Lean issue.

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.

I've commented on an old Zulip thread that was already proposing this: #lean4 > `coe` attribute for CoeFun/CoeSort @ 💬

@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 Nov 28, 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 Nov 29, 2025
@JovanGerb

Copy link
Copy Markdown
Contributor Author

What should we do about the lemmas that refer to points in the name? I think the lemmas of the form foo_points should be renamed to foo_apply.

@jsm28

jsm28 commented Nov 29, 2025

Copy link
Copy Markdown
Contributor

That would seem reasonable for references to points or point in lemma names (whether or not the actual structure field points ends up being renamed).

  • As usual, any renaming should come with deprecated aliases unless the lemmas were very recently added.
  • Such a renaming could reasonably go in a followup rather than making this PR larger.
  • In some cases, no name fragment such as apply or points is needed to indicate a reference to the vertices; for example, I think fragments such as affineSpan_face are sufficient in place of a longer affineSpan_range_points_face or affineSpan_range_apply_face or similar that literally repeats more of the elements actually present in the lemma type.

@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 4, 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 4, 2025
@jcommelin jcommelin assigned jsm28 and unassigned mattrobball Dec 5, 2025
@jcommelin jcommelin added t-euclidean-geometry Affine and axiomatic geometry awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. labels Dec 5, 2025
@jsm28

jsm28 commented Dec 5, 2025

Copy link
Copy Markdown
Contributor

My view is still that we should have an issue filed against Lean about the need for a coe_fun attribute (which can point to that Zulip thread and this PR where the issue template asks for links to prior discussion), with comments referencing it on the meta code here and the two other copies of that code in mathlib, and then I expect this PR will be essentially ready to go in (with any other renaming or changes to remaining existing uses of points being doable in followups).

@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 11, 2025
@eric-wieser

Copy link
Copy Markdown
Member

What should we do about the lemmas that refer to points in the name? I think the lemmas of the form foo_points should be renamed to foo_apply.

My take is that we should ignore coercions in theorem names, and name theorems after what you get when you hover over the arrow. If you don't do this, then it becomes very annoying to name things with multiple coercions.

Phrased another way, I'd suggest reserving apply for only the cases where DFunLike.coe is used.

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-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) t-euclidean-geometry Affine and axiomatic geometry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants