Skip to content

feat(Util): support noWS in notation3 - #45029

Open
YaelDillies wants to merge 1 commit into
leanprover-community:masterfrom
YaelDillies:notation3_nows
Open

YaelDillies wants to merge 1 commit into
leanprover-community:masterfrom
YaelDillies:notation3_nows

Conversation

@YaelDillies

@YaelDillies YaelDillies commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

... and use it to define the conditional probability notation μ[|s].

Generated by Claude Opus, reviewed line-by-line by myself.

Zulip discussion: #mathlib reviewers > status of `notation3` @ 💬

Assisted-by: Claude Opus 5.5


... and use it to define the conditional probability notation `μ[|s]`.

Generated by Claude Opus, reviewed line-by-line by myself.

Assisted-by: Claude Opus 5.5
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

PR summary 0ebe647d41

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ noWsTest

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit 0ebe647).

  • +1 new declarations
  • −2 removed declarations
+Mathlib.Notation3.noWsItem
-ProbabilityTheory.condUnexpander
-ProbabilityTheory.delabCondApplied

No changes to strong technical debt.
No changes to weak technical debt.

Current commit 0ebe647d41
Reference commit 83c11fb8f9

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py 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).

@grunweg grunweg added the LLM-generated PRs with substantial input from LLMs - review accordingly label Oct 19, 2026
@grunweg

grunweg commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Thanks. This looks good to me, but I'd like a second pair of eyes as I'm not deeply familiar with this.
maintainer merge?

@grunweg grunweg added the t-meta Tactics, attributes or user commands label Oct 19, 2026
@github-actions

Copy link
Copy Markdown

🚀 Pull request has been placed on the maintainer queue by grunweg.

@mathlib-triage mathlib-triage Bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Oct 19, 2026
meta def condUnexpander : Lean.PrettyPrinter.Unexpander
| `($_ $μ $s) => `($μ[|$s])
| _ => throw ()
scoped notation3:max μ noWs "[" t " | " s "]" => ProbabilityTheory.cond μ s t

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 syntax is a little wird to me, in that μ and noWs look syntactically similar, but one is a special token and one is a placeholder.

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.

But this is taken from notation and macro, etc... Surely consistency is best here?

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.

In what way is it taken from notation? notation:max μ noWs "[" t " | " s "]" => (μ, t, s) means "create a variable called noWs".

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.

Sorry I guess just macro

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.

Macro doesn't support someVar noWs either, you have to write someVar:term noWs

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 the syntax of noWs looks a bit strange here.

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.

Maybe it could be mu:noWs? I think this makes sense since you having no whitespace is a sort of precedence.

@[inherit_doc ProbabilityTheory.cond]
scoped macro:max μ:term noWs "[|" s:term "]" : term =>
`(ProbabilityTheory.cond $μ $s)
scoped notation3:max μ noWs "[|" s "]" => ProbabilityTheory.cond μ 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.

Shouldn't this be notation instead of notation3? The old code uses an app_unexpander and not a delaborator.

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 point of this PR is to write it using notation3. Is an app_unexpander better than a delaborator? If so, we could try changing the logic of notation3 to produce an app_unexpander whenever possible.

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.

@JovanGerb, notation does not support noWs

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.

@YaelDillies, the whole point of notation3 is that it produces a delaborator (which from #45028 it seems you know). There are situations where a delaborator works and an app_unexpander doesn't, which is why we need notation3 is essential. But for situations where an app_unexpander works, it is preferred because it is simpler as it is purely syntax based.

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.

Okay, so your PoV is that notation3 should be used over notation iff a delaborator is required over an app_unexpander. What about Eric's comment above that notation doesn't support noWs?

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.

Well, I think that notation and notation3/notation +delab should support the same things for consistency. So I guess you could talk to core and see if they want to add this feature to notation.

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 don't think that approach makes sense given that notation3 is already different from core because of differing priorities. We should just do our own thing for now, and eventually hopefully core will adapt.

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 worry that the lack of an obvious syntax choice noWs is going to make core developers choose a different syntax, so we end up with two incompatible versions. I don't think we need to wait for the implementation in core to be finished to merge this PR. We only need for core to say "we want to implement this exact syntax too" or "we don't want this at all".

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.

@grunweg grunweg added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Oct 19, 2026
@YaelDillies YaelDillies removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Oct 20, 2026
@Vierkantor Vierkantor self-assigned this Oct 24, 2026

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

The implementation looks fine to me. But I think we should communicate with core before continuing with this.

@Vierkantor Vierkantor added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Oct 24, 2026
@YaelDillies YaelDillies added awaiting-zulip There is a Zulip discussion; the author should await and report/implement the decision reached there and removed awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. labels Oct 24, 2026

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 LLM-generated PRs with substantial input from LLMs - review accordingly maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. t-meta Tactics, attributes or user commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants