|
| 1 | +/- |
| 2 | +Copyright (c) 2026 Yaël Dillies. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Yaël Dillies |
| 5 | +-/ |
| 6 | +module |
| 7 | + |
| 8 | +public import Mathlib.Geometry.Convex.ConvexSpace.Prod |
| 9 | +public import Mathlib.LinearAlgebra.AffineSpace.Combination |
| 10 | +public import Mathlib.LinearAlgebra.AffineSpace.AffineMap |
| 11 | + |
| 12 | +/-! |
| 13 | +# Modules are convex spaces |
| 14 | +
|
| 15 | +This file shows that every semimodule over an ordered semiring is a convex space. |
| 16 | +
|
| 17 | +## Main declarations |
| 18 | +
|
| 19 | +* `ConvexSpace.ofModule`: A semimodule space over a semiring is a convex space. |
| 20 | +* `convexSpaceSelf`: A semiring is a convex space over itself. |
| 21 | +* `IsModuleConvexSpace`: Predicate for a convex space and module structures to be compatible. |
| 22 | +
|
| 23 | +## Implementation notes |
| 24 | +
|
| 25 | +It is sadly impossible to make `ConvexSpace.ofModule` a global instance since it creates diamonds |
| 26 | +with structural instances such as `ConvexSpace R X → ConvexSpace R Y → ConvexSpace R (X × Y)` |
| 27 | +because `(∑ i, f i).fst = ∑ i, (f i).fst` isn't defeq, ultimately because `Finset.sum` isn't a field |
| 28 | +of `AddCommMonoid`. |
| 29 | +-/ |
| 30 | + |
| 31 | +public section |
| 32 | + |
| 33 | +namespace Convexity |
| 34 | +variable {R M N I : Type*} [Semiring R] [PartialOrder R] [IsStrictOrderedRing R] |
| 35 | + [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] |
| 36 | + |
| 37 | +/-- Any semimodule over an ordered semiring is a convex space. |
| 38 | +
|
| 39 | +This is not an instance because it creates a diamond. -/ |
| 40 | +@[expose, implicit_reducible] |
| 41 | +def ConvexSpace.ofModule : ConvexSpace R M where |
| 42 | + sConvexComb w := w.weights.sum fun m r ↦ r • m |
| 43 | + sConvexComb_single := by simp |
| 44 | + assoc := by |
| 45 | + simp [Finsupp.sum_mapDomain_index, add_smul, Finsupp.sum_sum_index, Finsupp.sum_smul_index, |
| 46 | + mul_smul, Finsupp.smul_sum] |
| 47 | + |
| 48 | +instance convexSpaceSelf : ConvexSpace R R := .ofModule |
| 49 | + |
| 50 | +variable (R M) [ConvexSpace R M] in |
| 51 | +class IsModuleConvexSpace : Prop where |
| 52 | + sConvexComb_eq_sum (w : StdSimplex R M) : w.sConvexComb = w.weights.sum fun m r ↦ r • m |
| 53 | + |
| 54 | +export IsModuleConvexSpace (sConvexComb_eq_sum) |
| 55 | +attribute [simp] sConvexComb_eq_sum |
| 56 | + |
| 57 | +@[deprecated (since := "2026-04-03")] |
| 58 | +alias _root_.convexCombination_eq_sum := sConvexComb_eq_sum |
| 59 | + |
| 60 | +attribute [local instance] ConvexSpace.ofModule in |
| 61 | +protected lemma IsModuleConvexSpace.ofModule : IsModuleConvexSpace R M where |
| 62 | + sConvexComb_eq_sum _ := rfl |
| 63 | + |
| 64 | +instance isModuleConvexSpace_self : IsModuleConvexSpace R R := .ofModule |
| 65 | + |
| 66 | +section IsModuleConvexSpace |
| 67 | +variable [ConvexSpace R M] [IsModuleConvexSpace R M] |
| 68 | + |
| 69 | +/-- `iConvexComb` in a module can be expressed as a sum. -/ |
| 70 | +@[simp] |
| 71 | +lemma iConvexComb_eq_sum (w : StdSimplex R I) (f : I → M) : |
| 72 | + w.iConvexComb f = w.weights.sum fun i r ↦ r • f i := by |
| 73 | + simp [iConvexComb, sConvexComb_eq_sum, Finsupp.sum_mapDomain_index, add_smul] |
| 74 | + |
| 75 | +/-- `convexCombPair` in a module can be expressed as a sum. -/ |
| 76 | +@[simp] |
| 77 | +lemma convexCombPair_eq_sum (a b : R) (ha hb hab) (x y : M) : |
| 78 | + convexCombPair a b ha hb hab x y = a • x + b • y := by |
| 79 | + classical simp [convexCombPair, sConvexComb_eq_sum, Finsupp.sum_add_index, add_smul] |
| 80 | + |
| 81 | +instance [ConvexSpace R N] [IsModuleConvexSpace R N] : IsModuleConvexSpace R (M × N) where |
| 82 | + sConvexComb_eq_sum w := by ext <;> simp [Finsupp.sum, Prod.fst_sum, Prod.snd_sum] |
| 83 | + |
| 84 | +instance {ι : Type*} {M : ι → Type*} [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] |
| 85 | + [∀ i, ConvexSpace R (M i)] [∀ i, IsModuleConvexSpace R (M i)] : |
| 86 | + IsModuleConvexSpace R (∀ i, M i) where |
| 87 | + sConvexComb_eq_sum w := by ext; simp [Finsupp.sum] |
| 88 | + |
| 89 | +instance {ι : Type*} : IsModuleConvexSpace R (ι →₀ M) where |
| 90 | + sConvexComb_eq_sum w := by ext; simp [Finsupp.sum] |
| 91 | + |
| 92 | +end IsModuleConvexSpace |
| 93 | + |
| 94 | +variable (R I) in |
| 95 | +lemma StdSimplex.isAffineMap_weights : IsAffineMap R (weights (R := R) (M := I)) where |
| 96 | + map_sConvexComb s := by simp [sConvexComb_eq_sum, Finsupp.sum_mapDomain_index, add_smul] |
| 97 | + |
| 98 | +end Convexity |
0 commit comments