Zulip Chat Archive

Stream: mathlib4

Topic: Integral notation


Yury G. Kudryashov (Jun 10 2023 at 16:53):

In Lean 4, ∫ x, f x ∂μ = 5 has to be written as (∫ x, f x ∂μ) = 5.

Yury G. Kudryashov (Jun 10 2023 at 16:53):

This was not the case in Lean 3.

Mario Carneiro (Jun 10 2023 at 16:54):

is this the same issue as the one about sum precedence?

Yury G. Kudryashov (Jun 10 2023 at 16:54):

This is about Lean 4 notation, not about mathport output.

Mario Carneiro (Jun 10 2023 at 16:54):

maybe it's just missing a precedence then

Yury G. Kudryashov (Jun 10 2023 at 16:55):

It's

@[inherit_doc MeasureTheory.integral]
notation3"∫ "(...)", "r:(scoped f => f)" ∂"μ => integral μ r

Mario Carneiro (Jun 10 2023 at 16:55):

there are no precedences there...

Mario Carneiro (Jun 10 2023 at 16:55):

this is probably a post-mathport issue

Yury G. Kudryashov (Jun 10 2023 at 16:55):

What is the right precedence for the measure?

Mario Carneiro (Jun 10 2023 at 16:56):

mathport is fixed but bugfixes in mathport don't propagate to all the files that are already ported

Mario Carneiro (Jun 10 2023 at 16:56):

so go find that line in current mathport output and apply it

Mario Carneiro (Jun 10 2023 at 16:57):

https://github.com/leanprover-community/mathlib3port/commit/3fdc57bc6b5ce9c256c25248e07a1971dafe7620

Mario Carneiro (Jun 10 2023 at 16:59):

-- mathport name: «expr∫ , ∂ »
notation3"∫ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => integral μ r

-- mathport name: «expr∫ , »
notation3"∫ "(...)", "r:60:(scoped f => integral volume f) => r

-- mathport name: «expr∫ in , ∂ »
notation3"∫ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => integral (Measure.restrict μ s) r

-- mathport name: «expr∫ in , »
notation3"∫ "(...)" in "s", "r:60:(scoped f => integral Measure.restrict volume s f) => r

Yury G. Kudryashov (Jun 10 2023 at 16:59):

Thank you!

Yury G. Kudryashov (Jun 10 2023 at 17:00):

I'll test it.

Eric Wieser (Jun 10 2023 at 17:42):

Mario Carneiro said:

mathport is fixed but bugfixes in mathport don't propagate to all the files that are already ported

Perhaps we should have been putting the mathport version in the header comment too so that it was easier to track these down

Eric Wieser (Jun 10 2023 at 17:43):

Another obvious one is open vs open scoped

Jireh Loreaux (Jun 10 2023 at 19:55):

It should be possible to get an estimated mathport version from the mathlib3 SHA in the header. This may not pick up on things that have had forward ports, but it could be helpful as a first approximation.

Eric Wieser (Jun 10 2023 at 23:14):

!4#4960 cleans up the majority of the open scoped/open mismatches

Eric Wieser (Jun 10 2023 at 23:51):

Annoyingly it's hard to fix this kind of thing because we did random cleanup when porting files (such as merging together open commands), and now it's hard to apply the diffs from mathport...

Yury G. Kudryashov (Jun 11 2023 at 00:19):

I have a branch with precedences for integral notation, I'll fix compile and open a PR tonight.

Yury G. Kudryashov (Jun 11 2023 at 03:01):

While copying integral notation from mathlib3port, I noticed that mathport often omits parentheses around restrict _ _.

Yury G. Kudryashov (Jun 11 2023 at 03:01):

See any of its "set integral" notation commands.

Yury G. Kudryashov (Jun 11 2023 at 03:01):

(e.g., in MeasureTheory.Integral.Bochner)

Mario Carneiro (Jun 11 2023 at 03:04):

Do you mean like here:

notation3"∫ "(...)" in "s", "r:60:(scoped f => integral Measure.restrict volume s f) => r

Mario Carneiro (Jun 11 2023 at 03:04):

which I guess should be

notation3"∫ "(...)" in "s", "r:60:(scoped f => integral (Measure.restrict volume s) f) => r

Mario Carneiro (Jun 11 2023 at 03:05):

I would guess that the parenthesizer doesn't work inside notations for some reason

Yury G. Kudryashov (Jun 11 2023 at 03:06):

Yes, here.

Yury G. Kudryashov (Jun 11 2023 at 03:06):

A more important question: ∫ x in 0..2 * π, f x doesn't work, ∫ x in (0)..2 * π, f x works

Mario Carneiro (Jun 11 2023 at 03:07):

presumably another precedence issue

Mario Carneiro (Jun 11 2023 at 03:07):

what's the notation?

Yury G. Kudryashov (Jun 11 2023 at 03:07):

It's in IntervalIntegral

Yury G. Kudryashov (Jun 11 2023 at 03:08):

The error message says "invalid projection, structure has only 1 field(s)"

Mario Carneiro (Jun 11 2023 at 03:08):

hm, maybe another parser is triggering on it

Yury G. Kudryashov (Jun 11 2023 at 03:08):

https://github.com/leanprover-community/mathlib4/pull/4963/files#diff-896f2f3c71fb2f7eaa4fcfab2a525c0d02b0879311e75727ef42dfea851f55bc

Yury G. Kudryashov (Jun 11 2023 at 03:09):

It tries to interpret 0. as a dot-notation on 0

Mario Carneiro (Jun 11 2023 at 03:09):

does it work if you replace ".." by "." "."?

Yury G. Kudryashov (Jun 11 2023 at 03:10):

I'll try.

Mario Carneiro (Jun 11 2023 at 03:10):

also try adding a space like 0 .. 2 pi

Yury G. Kudryashov (Jun 11 2023 at 03:11):

Adding a space breaks notation too, with 0 or without.

Mario Carneiro (Jun 11 2023 at 03:11):

Actually I think it's not a dot notation on 0, it's a float literal

Mario Carneiro (Jun 11 2023 at 03:12):

0. is a float literal apparently

Mario Carneiro (Jun 11 2023 at 03:14):

Right, .. is not a good token because it's legal after an expression

Mario Carneiro (Jun 11 2023 at 03:14):

f .. means f _ _ _ for however many _ are needed

Yury G. Kudryashov (Jun 11 2023 at 03:14):

We can change notation for interval integral.

Yury G. Kudryashov (Jun 11 2023 at 03:16):

(or we can postpone this decision)

Mario Carneiro (Jun 11 2023 at 03:16):

how about ∫ _ in [a, b], r ∂μ

Yury G. Kudryashov (Jun 11 2023 at 03:17):

Note that we have ∫ _ in s, r ∂μ, where s is a set.

Mario Carneiro (Jun 11 2023 at 03:17):

true, but sets starting with [ are rare, no?

Mario Carneiro (Jun 11 2023 at 03:18):

and you can use a ( to disambiguate

Yury G. Kudryashov (Jun 11 2023 at 03:18):

And here comes localized notation for docs4#Set.uIcc (was [a, b] in mathlib3).

Mario Carneiro (Jun 11 2023 at 03:19):

well, those should be equal so it's fine :grinning:

Yury G. Kudryashov (Jun 11 2023 at 03:19):

No, they are not equal because of the sign.

Yury G. Kudryashov (Jun 11 2023 at 03:20):

∫ _ in 1..0, 1 = -1

Yury G. Kudryashov (Jun 11 2023 at 03:20):

The sign is the only reason why intervalIntegral exists as a separate definition.

Mario Carneiro (Jun 11 2023 at 03:20):

∫ₐᵇ x, f x ∂μ :see_no_evil:

Yury G. Kudryashov (Jun 11 2023 at 03:21):

We don't have a superscript pi.

Mario Carneiro (Jun 11 2023 at 03:22):

I think in practice we will want to use a composite version of the superscript parser and one that takes an explicit ^(expr) for when you can't do it with unicode

Yury G. Kudryashov (Jun 11 2023 at 03:22):

I mean, ∫_{a}^{b} x, f x ∂μ is closest to LaTeX...

Yury G. Kudryashov (Jun 11 2023 at 03:23):

Is it a problem that _{}^ are used elsewhere too?

Mario Carneiro (Jun 11 2023 at 03:24):

no, although this is more than notation3 will handle

Mario Carneiro (Jun 11 2023 at 03:24):

the fact that there is an initial (relatively) unique token helps a lot here

Yury G. Kudryashov (Jun 11 2023 at 03:25):

Parses:

notation3"∫_{"a"}^{"b"}"(...)", "r:60:(scoped f => intervalIntegral f a b volume) => r

example : _{0}^{1} _, (0 : ) = 0 := sorry

Mario Carneiro (Jun 11 2023 at 03:26):

oh I meant if you have multiple options for how to write the bounds

Yury G. Kudryashov (Jun 11 2023 at 03:27):

What other options do you want to have?

Mario Carneiro (Jun 11 2023 at 03:27):

maybe leaving off the braces, or using the superscript parser

Mario Carneiro (Jun 11 2023 at 03:27):

also you probably want to split the initial token or else it will break the other integral parsers

Yury G. Kudryashov (Jun 11 2023 at 03:28):

As a person who often writes 2^{3} in LaTeX, I don't care.

Yury G. Kudryashov (Jun 11 2023 at 03:28):

It doesn't: I added it after

notation3"∫ "(...)" in "a".."b", "r:60:(scoped f => intervalIntegral f a b volume) => r

and the file compiles.

Yury G. Kudryashov (Jun 11 2023 at 03:29):

I'll make a PR after !4#4963 gets merged.

Yury G. Kudryashov (Jun 11 2023 at 03:30):

What else should I edit to tell mathport to change old notation to the new one?

Yury G. Kudryashov (Jun 11 2023 at 03:30):

Or should I leave both options for now?

Yury G. Kudryashov (Jun 11 2023 at 03:31):

BTW, should we add notation for integrals over Iio a and Ioi a? Something like

notation3"∫_-∞^{"b"}"(...)", "r:60:(scoped f => integral f (restrict volume (Iio b))) => r

Mario Carneiro (Jun 11 2023 at 03:31):

you can't, right now, unless mathport hardcodes the new notation or you backport it to lean 3

Mario Carneiro (Jun 11 2023 at 03:32):

and I guess backporting doesn't actually do the rewriting for you

Mario Carneiro (Jun 11 2023 at 03:32):

how about skipping the braces for those?

Mario Carneiro (Jun 11 2023 at 03:33):

I'm still worried about the long tokens though, I'm pretty sure lean uses a longest match parse for the tokens and this might make some cases not apply

Yury G. Kudryashov (Jun 11 2023 at 03:33):

It's hard for me to skip braces around -∞: then the infinity symbol won't be a subscript!

Mario Carneiro (Jun 11 2023 at 03:34):

is using too weird?

Yury G. Kudryashov (Jun 11 2023 at 03:34):

I tried adding new nothation both before and after the existing one, in each case file compiles.

Yury G. Kudryashov (Jun 11 2023 at 03:34):

Yes, it is too weird.

Yury G. Kudryashov (Jun 11 2023 at 03:35):

OK, I'm going to bed soon. I'll think about it again tomorrow.

Mario Carneiro (Jun 11 2023 at 03:35):

too bad there is no unicode subscript infinity

Yury G. Kudryashov (Jun 30 2023 at 15:42):

!3#19225 changes notation in Mathlib 3

Sebastien Gouezel (Jun 30 2023 at 16:03):

Are you sure it's more readable? Comparing in one of the first instances in the diff ∫ x in (-r:ℝ)..r to ∫_{(-r:ℝ)}^{r} x, I am not convinced (but maybe it's just because it takes some time to get used to it).

Yury G. Kudryashov (Jun 30 2023 at 16:05):

You can drop the type annotation.

Yury G. Kudryashov (Jun 30 2023 at 16:05):

I did a search&replace, so I didn't drop them.

Yury G. Kudryashov (Jun 30 2023 at 16:05):

The main issue with the current notation is that ∫ x in 0..r, x doesn't work in Lean 4 (see above).

Yury G. Kudryashov (Jun 30 2023 at 16:06):

We have a workaround ∫ x in (0)..r, x but it looks strange.

Kyle Miller (Jun 30 2023 at 16:10):

Would ∫ x in [0 : r], f x be too weird? Lean 4 already has [0:r] for a kind of interval notation (for natural number ranges), so it's at least parseable, and it even sort of looks like a closed interval.

Yury G. Kudryashov (Jun 30 2023 at 16:11):

For me, the main argument pro ∫_{a}^{b} is that it's what we write in LaTeX

Yury G. Kudryashov (Jun 30 2023 at 16:13):

In fact, I see no problem with ∫_{a}^{b} fun x => f x so that ∫_{a}^{b} (f - g) is a thing.

Yury G. Kudryashov (Jun 30 2023 at 16:14):

(but I'm ready to use any other notation that works)

Kyle Miller (Jun 30 2023 at 16:21):

Yeah, I figured it was LaTeX-inspired, though the way x works in ∫_{0}^{r} x, f x isn't very familiar

Kyle Miller (Jun 30 2023 at 16:23):

Here's another thought: if we defined I[a, b] to be I a b (this special notation is to help eliminate some parentheses and to look like a closed interval) then ∫ x in I[0, r], f x could rely on the ∫ x in s, f x notation

Yury G. Kudryashov (Jun 30 2023 at 16:25):

No, the main point of the interval integral notation is that it works for b < a: (∫ x in 1..0, 1) = -1

Kyle Miller (Jun 30 2023 at 16:26):

Oops, I was accidentally looking at the average integral in the PR

Kyle Miller (Jun 30 2023 at 16:31):

For the ∫ x in s, f x ambiguity, Mario and I discussed some ideas for extending the notation3 command to be able to give special interpretations of extended binders, so it's possible that we could have ∫ x ∈ s, f x with the same meaning (and similarly for Finset.prod/Finset.sum notation). That could open up in for interval integrals.

Kyle Miller (Jun 30 2023 at 16:35):

Yet another suggestion: ∫ x in 0 to r, x (viable if we're ok with to becoming a keyword, and it should be Lean 4 parseable)

Yury G. Kudryashov (Jun 30 2023 at 16:48):

I'm happy with any of these notations.

Yury G. Kudryashov (Jun 30 2023 at 16:48):

(and can write a regexp to migrate)

Yury G. Kudryashov (Jun 30 2023 at 16:48):

Should we start a poll?

Yury G. Kudryashov (Jun 30 2023 at 17:01):

Let me do it. tl;dr: ∫ x in 0..1, x doesn't work in Lean 4. Which notation should we use instead?

Sebastien Gouezel (Jun 30 2023 at 17:03):

Is there really no way to fix the notation ∫ x in 0..1, x?

Yury G. Kudryashov (Jun 30 2023 at 17:05):

/poll Notation for interval integral
∫_{a}^{b} x, f x ∂μ
∫ x in [a:b], f x ∂μ
∫_{a}^{b} fun x ↦ f x ∂μ
∫ x in a to b, f x ∂μ
∫ x from a to b, f x ∂μ (will it conflict with from?)

Yury G. Kudryashov (Jun 30 2023 at 17:06):

As far as I understand, Lean parses 0..1 as dot notation on 0. (decimal fraction) and fails.

Yury G. Kudryashov (Jun 30 2023 at 17:07):

We can use a different symbol instead of ... E.g., [a:b] is very close. I don't know if a::b will work.

Yury G. Kudryashov (Jun 30 2023 at 17:14):

I droped most of the explicit type annotations from the PR.

Yury G. Kudryashov (Jun 30 2023 at 17:46):

It looks like option 2 is winning. I'll change the PR.

Yury G. Kudryashov (Jun 30 2023 at 17:51):

Will it conflict with set integral notation + docs#Std.Range notation?

Yury G. Kudryashov (Jun 30 2023 at 17:52):

Let me try in Mathlib 4

Kyle Miller (Jun 30 2023 at 17:54):

There's a chance you might need to give (priority := high) in the notation3 command if it can't resolve the ambiguity itself

Yury G. Kudryashov (Jun 30 2023 at 18:55):

Even with (priority := high), it fails to parse ∫ _ in [j:N], (1 : ℝ) ∂ρ without a type annotation.

Yury G. Kudryashov (Jun 30 2023 at 18:56):

(here j and N are natural numbers)

Yury G. Kudryashov (Jun 30 2023 at 19:00):

I pushed to branch#YK-interval-integral. Have a look at Probability.StrongLaw

Yury G. Kudryashov (Jun 30 2023 at 19:01):

Note that I messed up with search&replace and added extra commas after some ]s

Yury G. Kudryashov (Jun 30 2023 at 19:01):

It looks like I fixed these in that file.

Yury G. Kudryashov (Jun 30 2023 at 19:10):

UPD: and now I actually pushed to github.

Patrick Massot (Sep 12 2023 at 21:48):

Any news here? @Yury G. Kudryashov

Yury G. Kudryashov (Sep 12 2023 at 23:47):

No news. I failed to implement ∫ x in [a:b], f x ∂μ.

Yury G. Kudryashov (Sep 12 2023 at 23:48):

It would be nice if someone who better understands how Lean notation work will do it.

Mario Carneiro (Sep 12 2023 at 23:48):

what is the desired behavior?

Yury G. Kudryashov (Sep 13 2023 at 04:14):

∫ x in [1:10], f x ∂μ should parse as an interval integral, not as set integral over a non-existent coercion of a range to set.


Last updated: Dec 20 2023 at 11:08 UTC