Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 9a37e3f

Browse files
jcommelinmergify[bot]
authored andcommitted
refactor(*): make vector_space an abbreviation for module (#1793)
* refactor(*): make vector_space an abbreviation for module * Remove superfluous instances * Fix build * Add Note[vector space definition] * Update src/algebra/module.lean * Fix build (hopefully) * Update src/measure_theory/bochner_integration.lean
1 parent a3844c8 commit 9a37e3f

File tree

8 files changed

+24
-20
lines changed

8 files changed

+24
-20
lines changed

src/algebra/module.lean

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,27 @@ end ideal
358358

359359
section prio
360360
set_option default_priority 100 -- see Note [default priority]
361+
362+
/- Note[vector space definition]:
363+
Vector spaces are defined as an `abbreviation` for modules,
364+
if the base ring is a field.
365+
(A previous definition made `vector_space` a structure
366+
defined to be `module`.)
367+
This has as advantage that vector spaces are completely transparant
368+
for type class inference, which means that all instances for modules
369+
are immediately picked up for vector spaces as well.
370+
A cosmetic disadvantage is that one can not extend vector spaces an sich,
371+
in definitions such as `normed_space`.
372+
The solution is to extend `module` instead.
373+
-/
374+
361375
/-- A vector space is the same as a module, except the scalar ring is actually
362376
a field. (This adds commutativity of the multiplication and existence of inverses.)
363377
This is the traditional generalization of spaces like `ℝ^n`, which have a natural
364378
addition operation and a way to multiply them by real numbers, but no multiplication
365379
operation between vectors. -/
366-
class vector_space (α : Type u) (β : Type v) [discrete_field α] [add_comm_group β] extends module α β
380+
abbreviation vector_space (α : Type u) (β : Type v) [discrete_field α] [add_comm_group β] :=
381+
module α β
367382
end prio
368383

369384
instance discrete_field.to_vector_space {α : Type*} [discrete_field α] : vector_space α α :=

src/algebra/pi_instances.lean

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ variables {I f}
8383

8484
instance module (α) {r : ring α} [∀ i, add_comm_group $ f i] [∀ i, module α $ f i] : module α (Π i : I, f i) := {..pi.semimodule I f α}
8585

86-
instance vector_space (α) {r : discrete_field α} [∀ i, add_comm_group $ f i] [∀ i, vector_space α $ f i] : vector_space α (Π i : I, f i) := {..pi.module α}
87-
8886
instance left_cancel_semigroup [∀ i, left_cancel_semigroup $ f i] : left_cancel_semigroup (Π i : I, f i) :=
8987
by pi_instance
9088

@@ -354,9 +352,6 @@ instance {r : semiring α} [add_comm_monoid β] [add_comm_monoid γ]
354352
instance {r : ring α} [add_comm_group β] [add_comm_group γ]
355353
[module α β] [module α γ] : module α (β × γ) := {}
356354

357-
instance {r : discrete_field α} [add_comm_group β] [add_comm_group γ]
358-
[vector_space α β] [vector_space α γ] : vector_space α (β × γ) := {}
359-
360355
section substructures
361356
variables (s : set α) (t : set β)
362357

src/analysis/normed_space/basic.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,11 @@ section normed_space
555555

556556
section prio
557557
set_option default_priority 100 -- see Note [default priority]
558+
-- see Note[vector space definition] for why we extend `module`.
558559
/-- A normed space over a normed field is a vector space endowed with a norm which satisfies the
559560
equality `∥c • x∥ = ∥c∥ ∥x∥`. -/
560561
class normed_space (α : Type*) (β : Type*) [normed_field α] [normed_group β]
561-
extends vector_space α β :=
562+
extends module α β :=
562563
(norm_smul : ∀ (a:α) (b:β), norm (a • b) = has_norm.norm a * norm b)
563564
end prio
564565

@@ -661,7 +662,7 @@ instance : normed_space α (E × F) :=
661662
add_smul := λ r x y, prod.ext (add_smul _ _ _) (add_smul _ _ _),
662663
smul_add := λ r x y, prod.ext (smul_add _ _ _) (smul_add _ _ _),
663664
..prod.normed_group,
664-
..prod.vector_space }
665+
..prod.module }
665666

666667
/-- The product of finitely many normed spaces is a normed space, with the sup norm. -/
667668
instance pi.normed_space {E : ι → Type*} [fintype ι] [∀i, normed_group (E i)]

src/analysis/normed_space/finite_dimension.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ open_locale classical
4343

4444
-- To get a reasonable compile time for `continuous_equiv_fun_basis`, typeclass inference needs
4545
-- to be guided.
46-
local attribute [instance, priority 10000] pi.module normed_space.to_vector_space
47-
vector_space.to_module submodule.add_comm_group submodule.module
46+
local attribute [instance, priority 10000] pi.module normed_space.to_module
47+
submodule.add_comm_group submodule.module
4848
linear_map.finite_dimensional_range Pi.complete nondiscrete_normed_field.to_normed_field
4949

5050
set_option class.instance_max_depth 100

src/analysis/normed_space/real_inner_product.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ export has_inner (inner)
5858

5959
section prio
6060
set_option default_priority 100 -- see Note [default priority]
61+
-- see Note[vector space definition] for why we extend `module`.
6162
/--
6263
An inner product space is a real vector space with an additional operation called inner product.
6364
Inner product spaces over complex vector space will be defined in another file.
6465
-/
65-
class inner_product_space (α : Type*) extends add_comm_group α, vector_space ℝ α, has_inner α :=
66+
class inner_product_space (α : Type*) extends add_comm_group α, module ℝ α, has_inner α :=
6667
(comm : ∀ x y, inner x y = inner y x)
6768
(nonneg : ∀ x, 0 ≤ inner x x)
6869
(definite : ∀ x, inner x x = 0 → x = 0)

src/linear_algebra/basic.lean

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,9 +834,6 @@ module.of_core $ by refine {smul := (•), ..};
834834
repeat {rintro ⟨⟩ <|> intro}; simp [smul_add, add_smul, smul_smul,
835835
-mk_add, (mk_add p).symm, -mk_smul, (mk_smul p).symm]
836836

837-
instance {K M} {R:discrete_field K} [add_comm_group M] [vector_space K M]
838-
(p : submodule K M) : vector_space K (quotient p) := {}
839-
840837
end quotient
841838

842839
end submodule

src/measure_theory/bochner_integration.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ set_option class.instance_max_depth 100
122122
-- Typeclass inference has difficulty finding `has_scalar ℝ β` where `β` is a `normed_space` on `ℝ`
123123
local attribute [instance, priority 10000]
124124
mul_action.to_has_scalar distrib_mul_action.to_mul_action add_comm_group.to_add_comm_monoid
125-
normed_group.to_add_comm_group normed_space.to_vector_space vector_space.to_module
125+
normed_group.to_add_comm_group normed_space.to_module
126126
module.to_semimodule
127127

128128
namespace measure_theory

src/ring_theory/algebra.lean

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,6 @@ by rw [smul_def, smul_def, left_comm]
103103
(r • x) * y = r • (x * y) :=
104104
by rw [smul_def, smul_def, mul_assoc]
105105

106-
@[priority 100] -- see Note [lower instance priority]
107-
instance {F : Type u} {K : Type v} [discrete_field F] [ring K] [algebra F K] :
108-
vector_space F K :=
109-
@vector_space.mk F _ _ _ algebra.to_module
110-
111106
/-- R[X] is the generator of the category R-Alg. -/
112107
instance polynomial (R : Type u) [comm_ring R] : algebra R (polynomial R) :=
113108
{ to_fun := polynomial.C,

0 commit comments

Comments
 (0)