Skip to content

Feature esum psum esum only#1978

Merged
affeldt-aist merged 27 commits into
math-comp:masterfrom
affeldt-aist:feature-esum-psum-esum-only
Jun 28, 2026
Merged

Feature esum psum esum only#1978
affeldt-aist merged 27 commits into
math-comp:masterfrom
affeldt-aist:feature-esum-psum-esum-only

Conversation

@affeldt-aist

@affeldt-aist affeldt-aist commented May 20, 2026

Copy link
Copy Markdown
Member
Motivation for this change

closes #1954

This PR intends to extract the reusable part of PR #1954

  • new lemmas about esum
  • removal of fpos and fneg (superseded by funrpos and funrneg)

TODO: completed (?)

  • some scripts still need to be linted
  • some lemmas are wrongly named
  • ome lemmas are not in the right files

fyi: @lyonel2017 @strub

Checklist
  • added corresponding entries in CHANGELOG_UNRELEASED.md
  • added corresponding documentation in the headers

Reference: How to document

Merge policy

As a rule of thumb:

  • PRs with several commits that make sense individually and that
    all compile are preferentially merged into master.
  • PRs with disorganized commits are very likely to be squash-rebased.
Reminder to reviewers

Comment thread theories/esum.v Outdated
Comment thread theories/esum.v Outdated
Comment thread theories/esum.v Outdated
@affeldt-aist affeldt-aist force-pushed the feature-esum-psum-esum-only branch from d5fc795 to bc6feda Compare June 10, 2026 01:34
Comment thread theories/esum.v Outdated
@affeldt-aist affeldt-aist force-pushed the feature-esum-psum-esum-only branch 3 times, most recently from 8e0aacb to 3aec29b Compare June 12, 2026 01:01
@affeldt-aist

Copy link
Copy Markdown
Member Author

@t6s I am pinging you because this PR changes the definition of esum, I thought you may want to know

@affeldt-aist affeldt-aist requested a review from strub June 13, 2026 03:25
@affeldt-aist affeldt-aist force-pushed the feature-esum-psum-esum-only branch from 4d86e16 to ba957d0 Compare June 16, 2026 13:18
@affeldt-aist affeldt-aist added this to the 1.17.0 milestone Jun 16, 2026
@affeldt-aist

Copy link
Copy Markdown
Member Author

@lyonel2017 @strub rebased

@affeldt-aist affeldt-aist requested a review from t6s June 16, 2026 13:21
@t6s

t6s commented Jun 22, 2026

Copy link
Copy Markdown
Member

It looks like there are several chunks of changes contained in this PR, making it difficult to review it at once. Can you provide a bit more detailed description of intention for each of them? For example, which lemmas do you consider are important?

@affeldt-aist

Copy link
Copy Markdown
Member Author

It looks like there are several chunks of changes contained in this PR, making it difficult to review it at once.
Can you provide a bit more detailed description of intention for each of them?
For example, which lemmas do you consider are important?

This is maybe for @lyonel2017 and @strub to say because this PR is used to develop another one.

From my viewpoint, the main change is the definition of esum which has become:

Definition esum S f := pos_esum S f^\+ - pos_esum S f^\-.

Before that, it was only the positive part.

@lyonel2017

Copy link
Copy Markdown
Contributor

This is maybe for @lyonel2017 and @strub to say because this PR is used to develop another one.

I started porting the distr.v file from experimental_real to use esum. The idea is to better integrate the result present in experimental_reals into mathcomp-analysis. The current status is available here counting_distr.v (the branch is not up to date with this PR). For me all the changes present in this PR are required for the porting.

Comment thread experimental_reals/realsum.v
Qed.
End SumTh.

Lemma esum_psum {R : realType} {T : choiceType} (f : T -> R) :

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.

Noting that esum has a very similar definition to sum, the following proof strategy is also possible:
discard the negative part of esum, and show PosEsum.pos_esum and psum are equal.

An attempt is as follows, but resulted in a longer proof:

Lemma ge0_funenegET :
  forall [T : Type] [R : realDomainType] [f : T -> \bar R],
  (forall x : T, (0%R <= f x)%E) -> f^\-%E = cst 0.
Proof.
move=> ? ? ? H; apply/funext => ?.
have ->// := @ge0_funenegE _ _ setT.
by rewrite mem_set.
Qed.

Lemma ge0_funrposET :
  forall [T : Type] [R : realDomainType] [f : T -> R],
    (forall x : T, 0 <= f x) -> f^\+ = f.
Proof.
move=> ? ? ? H; apply/funext => ?.
have ->// := @ge0_funrposE _ _ setT.
by rewrite mem_set.
Qed.

Lemma fsetsTE (T : choiceType) : fsets [set: T] = finite_set.
Proof. by apply/funext=> ?; apply/propext; split => // -[]. Qed.

Lemma exists_fsetE (T : choiceType) (P : {fset T} -> Prop) :
  (exists J : {fset T}, P J) = (exists2 J : set T, finite_set J & P (fset_set J)).
Proof.
apply/propext; split.
  by case=> J ?; exists [set` J]%classic => //; rewrite set_fsetK.
by case=> J ? ?; exists (fset_set J).
Qed.

Lemma exists_finite_setE (T : choiceType) (P : set T -> Prop) :
  (exists2 J : set T, finite_set J & P J) = (exists J : {fset T}, P [set` J]%classic).
Proof.
rewrite exists_fsetE; apply/propext; split => -[] J ?.
  by move=> ?; exists J => //; rewrite fset_setK.
by rewrite fset_setK// => ?; exists J.
Qed.

Lemma esymE (T : Type) (x y : T) : (x = y) = (y = x).
Proof. by apply/propext; split => /esym. Qed.

Lemma esum_psum {R : realType} {T : choiceType} (f : T -> R) :
    (forall i, 0 <= f i) -> summable f ->
  \esum_(x in [set: T]) (f x)%:E = (psum f)%:E.
Proof.
move=> f0 h.
rewrite /esum ge0_funenegET// [X in (_ - X)%E]PosEsum.pos_esum1// sube0.
rewrite /PosEsum.pos_esum fsetsTE.
rewrite /psum/=; case:asboolP => // _.
set S := (S in sup S).
have S_has_ubound : has_ubound S.
  by case: h => M HM; exists M => ?/= [] J ->; exact: HM.
  (* summable f -> has_ubound S; (S in the definition of psum) *)
have S_nonempty : (S !=set0)%classic.
  by exists 0, fset0; rewrite big1// => i; have := fsvalP i.
  (* S always has the sum over the emptyset as its elements *)
rewrite -ereal_sup_EFin; [exact: S_has_ubound | exact: S_nonempty |].
congr ereal_sup.
under eq_imagel do rewrite fsbig_finite//= funerpos/= sumEFin.
rewrite -[LHS]image_comp; congr image.
rewrite /S; apply: funext=> x/=.
rewrite exists_finite_setE; congr ex; apply/funext => J.
rewrite [LHS]esymE; congr eq.
rewrite -(big_seq_fsetE _ _ xpredT (Num.norm \o f))/= set_fsetK.
apply: eq_bigr => ? _.
by rewrite ger0_norm// ge0_funrposET.
Qed.

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.

Further refactored; this ge0_psumEpos_esum can also be used to shorten esumEsum.

Lemma ge0_psumEpos_esum {R : realType} {T : choiceType} (f : T -> R) :
  (forall i, 0 <= f i) -> summable f ->
  (psum f)%:E = PosEsum.pos_esum [set: T] (EFin \o f).
Proof.
move=> f0 h.
rewrite /psum/=; case: asboolP => // _.
rewrite /PosEsum.pos_esum fsetsTE.
set S := (S in sup S).
have S_has_ubound : has_ubound S.
  by case: h => M HM; exists M => ?/= [] J ->; exact: HM.
  (* summable f -> has_ubound S; (S in the definition of psum) *)
have S_nonempty : (S !=set0)%classic.
  by exists 0, fset0; rewrite big1// => i; have := fsvalP i.
  (* S always has the sum over the emptyset as its elements *)
rewrite -ereal_sup_EFin; [exact: S_has_ubound | exact: S_nonempty |].
congr ereal_sup.
under [RHS]eq_imagel do rewrite fsbig_finite//= sumEFin.
rewrite -[RHS]image_comp; congr image.
rewrite /S; apply: funext=> x/=.
rewrite exists_finite_setE; congr ex; apply/funext => J.
rewrite [LHS]esymE; congr eq.
rewrite -(big_seq_fsetE _ _ xpredT (Num.norm \o f))/= set_fsetK.
apply: eq_bigr => ? _.
by rewrite ger0_norm.
Qed.

Lemma esum_psum {R : realType} {T : choiceType} (f : T -> R) :
    (forall i, 0 <= f i) -> summable f ->
  \esum_(x in [set: T]) (f x)%:E = (psum f)%:E.
Proof.
move=> f0 h.
rewrite /esum ge0_funenegET// [X in (_ - X)%E]PosEsum.pos_esum1// sube0.
by rewrite psumEpos_esum// funerpos ge0_funrposET.
Qed.

@affeldt-aist affeldt-aist Jun 28, 2026

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 am not sure we need to revise the proof scripts,
even though I am still unsure about the quality of the API:
this PR is certainly an improvement but work remains.
For example, what about renaming psum to pos_sum (to match pos_esum and also because it looks like "partial sum" to me, since we use gt0 to say "positive" in MathComp---of course in lemmas).

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.

This is a right observation to say that some lemma should bridge pos_esum and psum,
but while pos_esum is "hidden" in a Module, psum isn't yet.

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.

But, if we were to really "hide" psum in a Module, it is maybe reasonable to postpone because the API of psum contains infamous admitted lemmas (__admitted__psumB and __admitted__interchange_psum).
Fixing the latter is a goal of @lyonel2017, so we shall come back to it anyway.

@affeldt-aist affeldt-aist Jun 28, 2026

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.

The last commit (86ec8af) proves __admitted_psumB (it was about time...).

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.

Noting that esum has a very similar definition to sum, the following proof strategy is also possible: discard the negative part of esum, and show PosEsum.pos_esum and psum are equal.

An attempt is as follows, but resulted in a longer proof:

[crunch]
Lemma fsetsTE (T : choiceType) : fsets [set: T] = finite_set.
Proof. by apply/funext=> ?; apply/propext; split => // -[]. Qed.
[crunch]

I kept this lemma but didn't integrate the other ones.
In particular, I didn't keep ge0_funenegET and its pos variant because iirc they were introduced at some point but turned out to be less useful than their extensional variants (forall x, ... x = ... x).

@affeldt-aist affeldt-aist force-pushed the feature-esum-psum-esum-only branch from ba957d0 to ae2b17b Compare June 28, 2026 09:54
affeldt-aist and others added 4 commits June 28, 2026 20:12
Co-authored-by: Takafumi Saikawa <tscompor@gmail.com>

@t6s t6s left a comment

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.

After playing for a while with this code, I have a feeling that the code is in a consistent state.
I am inspired to do some additions (other than I suggested in the previous review comments) to fsbig, which could possibly simplify PosEsum, psum, and esum, but I will let them go into a separate PR rather than requesting changes here.

@t6s

t6s commented Jun 28, 2026

Copy link
Copy Markdown
Member

ah, but one thing: naming conventions seem to be incoherent between esum_psum and esumEsum

@affeldt-aist

Copy link
Copy Markdown
Member Author

ah, but one thing: naming conventions seem to be incoherent between esum_psum and esumEsum

Yes indeed, esum_sum seems better than esumEsum.
Thank you for you time trying to optimize this PR, I understand it is difficult to context switch.

@affeldt-aist affeldt-aist merged commit e656ced into math-comp:master Jun 28, 2026
45 checks passed
@affeldt-aist affeldt-aist deleted the feature-esum-psum-esum-only branch June 28, 2026 15:02
Brixfoly pushed a commit to Brixfoly/analysis that referenced this pull request Jun 30, 2026
* Add missing lemmas for distr

* use fun{r,e}{pos,neg} instead of f{pos,neg}

* esum lemmas from PR math-comp#1954

* new definition of esum

* prove __admitted__psumB

---------

Co-authored-by: Lionel Blatter <lionel.blatter@wanadoo.fr>
Co-authored-by: Takafumi Saikawa <tscompor@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants