Skip to content

Commit 92bdcbf

Browse files
t6saffeldt-aist
andauthored
Conv convention (#1630)
* change the convention for the convex combination operation --------- Co-authored-by: Reynald Affeldt <reynald.affeldt@aist.go.jp>
1 parent 69ac3ce commit 92bdcbf

6 files changed

Lines changed: 182 additions & 80 deletions

File tree

CHANGELOG_UNRELEASED.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,21 @@
44

55
### Added
66

7+
- in `unstable.v`:
8+
+ lemma `subrKC`
9+
10+
- in `convex.v`:
11+
+ definition `convex_quasi_associative`
12+
* implemented through a module `ConvexQuasiAssoc` containing
13+
`law` and helper lemmas
14+
+ lemmas `convR_itv`, `convR_line_path`
15+
716
### Changed
817

18+
- in `convex.v`:
19+
+ convex combination operator `a <| t |> b` changed from
20+
`(1-t)a + tb` to `ta + (1-t)b`
21+
922
- in `sequences.v`:
1023
+ lemma `subset_seqDU`
1124

@@ -43,15 +56,24 @@
4356
+ definition `ae_eq`
4457
+ `ae_eq` lemmas now for `ringType`-valued functions (instead of `\bar R`)
4558

59+
- in `convex.v`:
60+
+ definition `convex_realDomainType` generalized and
61+
renamed accordingly `convex_numDomainType`
62+
4663
### Renamed
4764

4865
- in `measure.v`
4966
+ definition `ess_sup` moved to `ess_sup_inf.v`
5067

68+
- in `convex.v`
69+
+ lemma `conv_gt0` to `convR_gt0`
70+
5171
### Generalized
5272

5373
- in `derive.v`:
5474
+ `derive_cst`, `derive1_cst`
75+
- in `convex.v`
76+
+ parameter `R` of `convType` from `realDomainType` to `numDomainType`
5577

5678
### Deprecated
5779

classical/unstable.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ Unset Printing Implicit Defensive.
3535
Import Order.TTheory GRing.Theory Num.Theory.
3636
Local Open Scope ring_scope.
3737

38+
Section ssralg.
39+
Lemma subrKC {V : zmodType} (x y : V) : x + (y - x) = y.
40+
Proof. by rewrite addrC subrK. Qed.
41+
End ssralg.
42+
3843
(* NB: Coq 8.17.0 generalizes dependent_choice from Set to Type
3944
making the following lemma redundant *)
4045
Section dependent_choice_Type.

theories/convex.v

Lines changed: 134 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(* mathcomp analysis (c) 2022 Inria and AIST. License: CeCILL-C. *)
1+
(* mathcomp analysis (c) 2025 Inria and AIST. License: CeCILL-C. *)
22
From mathcomp Require Import all_ssreflect ssralg ssrint ssrnum finmap.
33
From mathcomp Require Import matrix interval zmodp vector fieldext falgebra.
44
From mathcomp Require Import mathcomp_extra unstable boolp classical_sets.
@@ -11,18 +11,23 @@ From HB Require Import structures.
1111
(* # Convexity *)
1212
(* *)
1313
(* This file provides a small account of convexity using convex spaces, to be *)
14-
(* completed with material from infotheo. *)
14+
(* completed with material from InfoTheo. *)
1515
(* *)
1616
(* ``` *)
17-
(* isConvexSpace R T == interface for convex spaces *)
18-
(* ConvexSpace R == structure of convex space *)
19-
(* a <| t |> b == convexity operator *)
17+
(* convex_quasi_associative == quasi-associativity of the operator of *)
18+
(* convex spaces *)
19+
(* isConvexSpace R T == interface for convex spaces with *)
20+
(* R : numDomainType *)
21+
(* The HB class is ConvexSpace. *)
22+
(* a <| t |> b == convexity operator *)
2023
(* ``` *)
2124
(* *)
22-
(* E : lmodType R with R : realDomainType and R : realDomainType are shown to *)
23-
(* be convex spaces with the following aliases: *)
24-
(* convex_lmodType E == E : lmodType T as a convex spaces *)
25-
(* convex_realDomainType R == R : realDomainType as a convex space *)
25+
(* For `R : numDomainType`, `E : lmodType R` and `R` itself are shown to be *)
26+
(* convex spaces with the following aliases: *)
27+
(* ``` *)
28+
(* convex_lmodType E == E : lmodType R as a convex space *)
29+
(* convex_numDomainType R == R : numDomainType as a convex space *)
30+
(* ``` *)
2631
(* *)
2732
(******************************************************************************)
2833

@@ -42,18 +47,70 @@ Import numFieldNormedType.Exports.
4247
Declare Scope convex_scope.
4348
Local Open Scope convex_scope.
4449

45-
HB.mixin Record isConvexSpace (R : realDomainType) T := {
50+
Module ConvexQuasiAssoc.
51+
Section def.
52+
Variables (R : numDomainType) (T : Type) (conv : {i01 R} -> T -> T -> T).
53+
54+
Local Notation "x <| p |> y" := (conv p x y).
55+
56+
Definition law := forall (p q r s : {i01 R}) (a b c : T),
57+
p%:num = r%:num * s%:num ->
58+
`1- (s%:num) = `1- (p%:num) * `1- (q%:num) ->
59+
a <| p |> (b <| q |> c) = (a <| r |> b) <| s |> c.
60+
End def.
61+
62+
(** technical relations between the parameters of the quasi-associativity law *)
63+
Section lemmas.
64+
65+
Lemma pq_sr (R : comRingType) (p q r s : R) :
66+
p = r * s ->
67+
1 - s = (1 - p) * (1 - q) ->
68+
(1 - p) * q = s * (1 - r).
69+
Proof.
70+
move=> prs spq.
71+
rewrite -[LHS]opprK -mulrN -[X in - X = _](addrK ((1 - p) * 1)).
72+
rewrite -mulrDr (addrC _ 1) -spq mulr1 prs.
73+
by rewrite !opprB addrC subrKA mulrDr mulr1 mulrN mulrC.
74+
Qed.
75+
76+
Lemma sE (R : ringType) (p q s : R) :
77+
1 - s = (1 - p) * (1 - q) ->
78+
s = 1 - (1 - p) * (1 - q).
79+
Proof. by move/eqP; rewrite subr_eq addrC -subr_eq => /eqP ->. Qed.
80+
81+
Lemma qE (R : comUnitRingType) (p q r s : R) :
82+
1 - p \is a GRing.unit ->
83+
p = r * s ->
84+
1 - s = (1 - p) * (1 - q) ->
85+
q = (s * (1 - r)) / (1 - p).
86+
Proof.
87+
move=> p1unit /pq_sr /[apply] /(congr1 ( *%R (1 - p)^-1)).
88+
by rewrite mulrA mulVr// mul1r mulrC.
89+
Qed.
90+
91+
Lemma rE (R : unitRingType) (p r s : R) :
92+
s \is a GRing.unit -> p = r * s -> r = p / s.
93+
Proof.
94+
move=> sunit /(congr1 ( *%R^~ s^-1)) ->.
95+
by rewrite -mulrA divrr// mulr1.
96+
Qed.
97+
98+
End lemmas.
99+
100+
End ConvexQuasiAssoc.
101+
102+
Definition convex_quasi_associative := ConvexQuasiAssoc.law.
103+
104+
HB.mixin Record isConvexSpace (R : numDomainType) T := {
46105
conv : {i01 R} -> T -> T -> T ;
47-
conv0 : forall a b, conv 0%:i01 a b = a ;
106+
conv1 : forall a b, conv 1%:i01 a b = a ;
48107
convmm : forall (p : {i01 R}) a, conv p a a = a ;
49108
convC : forall (p : {i01 R}) a b, conv p a b = conv (1 - p%:inum)%:i01 b a;
50-
convA : forall (p q r : {i01 R}) (a b c : T),
51-
p%:inum * (`1-(q%:inum)) = (`1-(p%:inum * q%:inum)) * r%:inum ->
52-
conv p a (conv q b c) = conv (p%:inum * q%:inum)%:i01 (conv r a b) c
109+
convA : convex_quasi_associative conv
53110
}.
54111

55112
#[short(type=convType)]
56-
HB.structure Definition ConvexSpace (R : realDomainType) :=
113+
HB.structure Definition ConvexSpace (R : numDomainType) :=
57114
{T of isConvexSpace R T & Choice T}.
58115

59116
Notation "a <| p |> b" := (conv p a b) : convex_scope.
@@ -62,102 +119,116 @@ Section convex_space_lemmas.
62119
Context R (A : convType R).
63120
Implicit Types a b : A.
64121

65-
Lemma conv1 a b : a <| 1%:i01 |> b = b.
122+
Lemma conv0 a b : a <| 0%:i01 |> b = b.
66123
Proof.
67-
rewrite convC/= [X in _ <| X |> _](_ : _ = 0%:i01) ?conv0//.
68-
by apply/val_inj => /=; rewrite subrr.
124+
rewrite convC/= [X in _ <| X |> _](_ : _ = 1%:i01) ?conv1//.
125+
by apply/val_inj => /=; rewrite subr0.
69126
Qed.
70127

71128
End convex_space_lemmas.
72129

73130
Local Open Scope convex_scope.
74131

75-
Definition convex_lmodType {R : realDomainType} (E : lmodType R) : Type := E.
132+
Definition convex_lmodType {R : numDomainType} (E : lmodType R) : Type := E.
76133

77134
Section lmodType_convex_space.
78-
Context {R : realDomainType} {E' : lmodType R}.
135+
Context {R : numDomainType} {E' : lmodType R}.
79136
Implicit Type p q r : {i01 R}.
80137

81138
Let E := convex_lmodType E'.
82139

83-
Let avg p (a b : E) := `1-(p%:inum) *: a + p%:inum *: b.
140+
Let avg p (a b : E) := p%:inum *: a + `1-(p%:inum) *: b.
84141

85-
Let avg0 a b : avg 0%:i01 a b = a.
86-
Proof. by rewrite /avg/= onem0 scale0r scale1r addr0. Qed.
142+
Let avg1 a b : avg 1%:i01 a b = a.
143+
Proof. by rewrite /avg/= onem1 scale0r scale1r addr0. Qed.
87144

88145
Let avgI p x : avg p x x = x.
89-
Proof. by rewrite /avg -scalerDl/= addrC add_onemK scale1r. Qed.
146+
Proof. by rewrite /avg -scalerDl/= add_onemK scale1r. Qed.
90147

91148
Let avgC p x y : avg p x y = avg (1 - (p%:inum))%:i01 y x.
92149
Proof. by rewrite /avg onemK addrC. Qed.
93150

94-
Let avgA p q r (a b c : E) :
95-
p%:inum * (`1-(q%:inum)) = (`1-(p%:inum * q%:inum)) * r%:inum ->
96-
avg p a (avg q b c) = avg (p%:inum * q%:inum)%:i01 (avg r a b) c.
151+
Let avgA : convex_quasi_associative avg.
97152
Proof.
98-
move=> pq; rewrite /avg.
153+
move=> p q r s a b c prs spq; rewrite /avg.
99154
rewrite [in LHS]scalerDr [in LHS]addrA [in RHS]scalerDr; congr (_ + _ + _).
100-
- rewrite scalerA; congr (_ *: _) => /=.
101-
by rewrite mulrDr mulr1 mulrN -pq mulrBr mulr1 opprB addrA subrK.
102-
- by rewrite 2!scalerA; congr (_ *: _).
103-
- by rewrite scalerA.
155+
- by rewrite scalerA mulrC prs.
156+
- by rewrite !scalerA; congr *:%R; rewrite (ConvexQuasiAssoc.pq_sr prs).
157+
- by rewrite scalerA spq.
104158
Qed.
105159

106160
HB.instance Definition _ := Choice.on E.
107161

108162
HB.instance Definition _ :=
109-
isConvexSpace.Build R E avg0 avgI avgC avgA.
163+
isConvexSpace.Build R E avg1 avgI avgC avgA.
110164

111165
End lmodType_convex_space.
112166

113-
Definition convex_realDomainType (R : realDomainType) : Type := R^o.
167+
Definition convex_numDomainType (R : numDomainType) : Type := R^o.
114168

115-
Section realDomainType_convex_space.
116-
Context {R : realDomainType}.
169+
Section numDomainType_convex_space.
170+
Context {R : numDomainType}.
117171
Implicit Types p q : {i01 R}.
118172

119-
Let E := @convex_realDomainType R.
120-
121173
Let avg p (a b : convex_lmodType R^o) := a <| p |> b.
122174

123-
Let avg0 a b : avg 0%:i01 a b = a.
124-
Proof. by rewrite /avg conv0. Qed.
175+
Let avg1 a b : avg 1%:i01 a b = a.
176+
Proof. exact: conv1. Qed.
125177

126178
Let avgI p x : avg p x x = x.
127-
Proof. by rewrite /avg convmm. Qed.
179+
Proof. exact: convmm. Qed.
128180

129181
Let avgC p x y : avg p x y = avg (1 - (p%:inum))%:i01 y x.
130-
Proof. by rewrite /avg convC. Qed.
182+
Proof. exact: convC. Qed.
131183

132-
Let avgA p q r (a b c : R) :
133-
p%:inum * (`1-(q%:inum)) = (`1-(p%:inum * q%:inum)) * r%:inum ->
134-
avg p a (avg q b c) = avg (p%:inum * q%:inum)%:i01 (avg r a b) c.
135-
Proof. by move=> h; rewrite /avg (convA _ _ r). Qed.
184+
Let avgA : convex_quasi_associative avg.
185+
Proof. exact: convA. Qed.
136186

137187
HB.instance Definition _ := @isConvexSpace.Build R R^o
138-
_ avg0 avgI avgC avgA.
188+
_ avg1 avgI avgC avgA.
139189

140-
End realDomainType_convex_space.
190+
End numDomainType_convex_space.
141191

142-
Section conv_realDomainType.
143-
Context {R : realDomainType}.
192+
Section conv_numDomainType.
193+
Context {R : numDomainType}.
144194

145-
Lemma conv_gt0 (a b : R^o) (t : {i01 R}) : 0 < a -> 0 < b -> 0 < a <| t |> b.
195+
Lemma convR_gt0 (a b : R^o) (t : {i01 R}) : 0 < a -> 0 < b -> 0 < a <| t |> b.
146196
Proof.
147197
move=> a0 b0.
148198
have [->|t0] := eqVneq t 0%:i01; first by rewrite conv0.
149199
have [->|t1] := eqVneq t 1%:i01; first by rewrite conv1.
150-
rewrite addr_gt0// mulr_gt0//; last by rewrite lt_neqAle eq_sym t0/=.
151-
by rewrite onem_gt0// lt_neqAle t1/=.
200+
rewrite addr_gt0// mulr_gt0//; first by rewrite lt_neqAle eq_sym t0 ge0.
201+
by rewrite subr_gt0 lt_neqAle t1 le1.
152202
Qed.
153203

154-
Lemma convRE (a b : R^o) (t : {i01 R}) : a <| t |> b = `1-(t%:inum) * a + t%:inum * b.
204+
Lemma convRE (a b : R^o) (t : {i01 R}) :
205+
a <| t |> b = t%:inum * a + `1-(t%:inum) * b.
155206
Proof. by []. Qed.
156207

157-
End conv_realDomainType.
208+
Lemma convR_itv (a b : R^o) (t : {i01 R}) : a <= b -> a <| t |> b \in `[a, b].
209+
Proof.
210+
move=> ab; rewrite convRE in_itv /=.
211+
rewrite -{1}(subrKC a b).
212+
rewrite mulrDr addrA -mulrDl.
213+
rewrite subrKC mul1r.
214+
rewrite lerDl mulr_ge0/=; [|by rewrite subr_ge0 le1|by rewrite subr_ge0].
215+
rewrite -[leRHS](convmm t b) convRE lerD//.
216+
by rewrite ler_wpM2l.
217+
Qed.
218+
219+
Let convRCE (a b : R^o) (t : {i01 R}) :
220+
a <| t |> b = `1-(t%:inum) * b + t%:inum * a.
221+
Proof. by rewrite addrC convRE. Qed.
222+
223+
Lemma convR_line_path (a b : R^o) (t : {i01 R}) :
224+
a <| t |> b = line_path b a t%:num.
225+
Proof. by rewrite convRCE. Qed.
226+
227+
End conv_numDomainType.
158228

159229
Definition convex_function (R : realType) (D : set R) (f : R -> R^o) :=
160-
forall (t : {i01 R}), {in D &, forall (x y : R^o), (f (x <| t |> y) <= f x <| t |> f y)%R}.
230+
forall (t : {i01 R}),
231+
{in D &, forall (x y : R^o), (f (x <| t |> y) <= f x <| t |> f y)%R}.
161232
(* TODO: generalize to convTypes once we have ordered convTypes (mathcomp 2) *)
162233

163234
(* ref: http://www.math.wisc.edu/~nagel/convexity.pdf *)
@@ -183,10 +254,10 @@ Qed.
183254
Let convexf_ptP : a < b -> (forall x, a <= x <= b -> 0 <= L x - f x) ->
184255
forall t, f (a <| t |> b) <= f a <| t |> f b.
185256
Proof.
186-
move=> ab h t; set x := a <| t |> b; have /h : a <= x <= b.
187-
by rewrite -(conv1 a b) -{1}(conv0 a b) /x !le_line_path//= ge0/=.
257+
move=> ba h t; set x := a <| t |> b; have /h : a <= x <= b.
258+
by have:= convR_itv t (ltW ba); rewrite in_itv/=.
188259
rewrite subr_ge0 => /le_trans; apply.
189-
by rewrite LE// /x line_pathK ?lt_eqF// convC line_pathK ?gt_eqF.
260+
by rewrite LE// /x {2}convC 2!convR_line_path !line_pathK//= ?(eq_sym b) lt_eqF.
190261
Qed.
191262

192263
Hypothesis HDf : {in `]a, b[, forall x, derivable f x 1}.
@@ -210,7 +281,8 @@ have [c2 Ic2 Hc2] : exists2 c2, x < c2 < b & (f b - f x) / (b - x) = 'D_1 f c2.
210281
have derivef z : z \in `]x, b[ -> is_derive z 1 f ('D_1 f z).
211282
by move=> zxb; apply/derivableP/xbf; exact: zxb.
212283
have [|z zxb fbfx] := MVT xb derivef.
213-
apply/(derivable_oo_continuous_bnd_within (And3 xbf _ cvg_left))/cvg_at_right_filter.
284+
apply/(derivable_oo_continuous_bnd_within (And3 xbf _ cvg_left)).
285+
apply/cvg_at_right_filter.
214286
have := derivable_within_continuous HDf.
215287
rewrite continuous_open_subspace//.
216288
by apply; rewrite inE/= in_itv/= ax.
@@ -221,7 +293,8 @@ have [c1 Ic1 Hc1] : exists2 c1, a < c1 < x & (f x - f a) / (x - a) = 'D_1 f c1.
221293
have derivef z : z \in `]a, x[ -> is_derive z 1 f ('D_1 f z).
222294
by move=> zax; apply /derivableP/axf.
223295
have [|z zax fxfa] := MVT ax derivef.
224-
apply/(derivable_oo_continuous_bnd_within (And3 axf cvg_right _))/cvg_at_left_filter.
296+
apply/(derivable_oo_continuous_bnd_within (And3 axf cvg_right _)).
297+
apply/cvg_at_left_filter.
225298
have := derivable_within_continuous HDf.
226299
rewrite continuous_open_subspace//.
227300
by apply; rewrite inE/= in_itv/= ax.

theories/exp.v

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ Lemma concave_ln (t : {i01 R}) (a b : R^o) : 0 < a -> 0 < b ->
786786
(ln a : R^o) <| t |> (ln b : R^o) <= ln (a <| t |> b).
787787
Proof.
788788
move=> a0 b0; have := convex_expR t (ln a) (ln b).
789-
by rewrite !lnK// -(@ler_ln) ?posrE ?expR_gt0 ?conv_gt0// expRK.
789+
by rewrite !lnK// -(@ler_ln) ?posrE ?expR_gt0 ?convR_gt0// expRK.
790790
Qed.
791791
Local Close Scope convex_scope.
792792

@@ -1026,11 +1026,13 @@ rewrite le_eqVlt => /predU1P[<-|b0] p0 q0 pq.
10261026
have iq1 : q^-1 <= 1 by rewrite -pq ler_wpDl// invr_ge0 ltW.
10271027
have ap0 : (0 < a `^ p)%R by rewrite powR_gt0.
10281028
have bq0 : (0 < b `^ q)%R by rewrite powR_gt0.
1029-
have := @concave_ln _ (Itv01 (eqbRL (invr_ge0 _) (ltW q0)) iq1) _ _ ap0 bq0.
1029+
have := @concave_ln _ (Itv01 (eqbRL (invr_ge0 _) (ltW q0)) iq1) _ _ bq0 ap0.
1030+
rewrite 2!(convC (Itv01 _ _)).
10301031
have pq' : (p^-1 = 1 - q^-1)%R by rewrite -pq addrK.
1032+
have qp' : (q^-1 = 1 - p^-1)%R by rewrite -pq addrAC subrr add0r.
10311033
rewrite !convRE/= /onem -pq' -[_ <= ln _]ler_expR expRD (mulrC p^-1).
1032-
rewrite ln_powR mulrAC divff ?mul1r ?gt_eqF// (mulrC q^-1).
10331034
rewrite ln_powR mulrAC divff ?mul1r ?gt_eqF//.
1035+
rewrite ln_powR -qp' mulrA mulVf ?gt_eqF// ?mul1r.
10341036
rewrite lnK ?posrE// lnK ?posrE// => /le_trans; apply.
10351037
rewrite lnK//; last by rewrite posrE addr_gt0// mulr_gt0// ?invr_gt0.
10361038
by rewrite (mulrC _ p^-1) (mulrC _ q^-1).

0 commit comments

Comments
 (0)