Feature esum psum esum only#1978
Conversation
d5fc795 to
bc6feda
Compare
8e0aacb to
3aec29b
Compare
|
@t6s I am pinging you because this PR changes the definition of |
4d86e16 to
ba957d0
Compare
|
@lyonel2017 @strub rebased |
|
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 Definition esum S f := pos_esum S f^\+ - pos_esum S f^\-.Before that, it was only the positive part. |
I started porting the distr.v file from |
|
|
||
| Definition psum f : R := | ||
| Definition psum {R : realType} {T : choiceType} (f : T -> R) : R := | ||
| (* We need some ticked `image` operator *) |
There was a problem hiding this comment.
Local Notation fsum f :=
(fun (J : {fset T}) => \sum_(x : J) `|f (val x)|).
Definition psum (f : T -> R) : R :=
let S := range (fsum f) in
if `[<summable f>] then sup S else 0.
I am afraid I did not understand what "ticked" means here, but the above code using image works.
(range f is a notation for (f @` [set: _])%classic)
There was a problem hiding this comment.
(oops, this line does not belong to this PR)
| Qed. | ||
| End SumTh. | ||
|
|
||
| Lemma esum_psum {R : realType} {T : choiceType} (f : T -> R) : |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Motivation for this change
closes #1954
This PR intends to extract the reusable part of PR #1954
esumfposandfneg(superseded byfunrposandfunrneg)TODO: completed (?)
some scripts still need to be lintedsome lemmas are wrongly namedome lemmas are not in the right filesfyi: @lyonel2017 @strub
Checklist
CHANGELOG_UNRELEASED.mdReference: How to document
Merge policy
As a rule of thumb:
all compile are preferentially merged into master.
Reminder to reviewers