Datasets:

Modalities:
Text
Languages:
English
Libraries:
Datasets
License:
File size: 15,361 Bytes
4365a98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro
-/

import linear_algebra.basic
import linear_algebra.basis

/-!
# Basics on bilinear maps

This file provides basics on bilinear maps. The most general form considered are maps that are
semilinear in both arguments. They are of type `M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P`, where `M` and `N`
are modules over `R` and `S` respectively, `P` is a module over both `Rβ‚‚` and `Sβ‚‚` with
commuting actions, and `ρ₁₂ : R β†’+* Rβ‚‚` and `σ₁₂ : S β†’+* Sβ‚‚`.

## Main declarations

* `linear_map.mkβ‚‚`: a constructor for bilinear maps,
  taking an unbundled function together with proof witnesses of bilinearity
* `linear_map.flip`: turns a bilinear map `M Γ— N β†’ P` into `N Γ— M β†’ P`
* `linear_map.lcomp` and `linear_map.llcomp`: composition of linear maps as a bilinear map
* `linear_map.complβ‚‚`: composition of a bilinear map `M Γ— N β†’ P` with a linear map `Q β†’ M`
* `linear_map.comprβ‚‚`: composition of a bilinear map `M Γ— N β†’ P` with a linear map `Q β†’ N`
* `linear_map.lsmul`: scalar multiplication as a bilinear map `R Γ— M β†’ M`

## Tags

bilinear
-/

variables {ι₁ ΞΉβ‚‚ : Type*}

namespace linear_map

section semiring

-- the `β‚—` subscript variables are for special cases about linear (as opposed to semilinear) maps
variables {R : Type*} [semiring R] {S : Type*} [semiring S]
variables {Rβ‚‚ : Type*} [semiring Rβ‚‚] {Sβ‚‚ : Type*} [semiring Sβ‚‚]
variables {M : Type*} {N : Type*} {P : Type*}
variables {Mβ‚‚ : Type*} {Nβ‚‚ : Type*} {Pβ‚‚ : Type*}
variables {Nβ‚— : Type*} {Pβ‚— : Type*}
variables {M' : Type*} {N' : Type*} {P' : Type*}

variables [add_comm_monoid M] [add_comm_monoid N] [add_comm_monoid P]
variables [add_comm_monoid Mβ‚‚] [add_comm_monoid Nβ‚‚] [add_comm_monoid Pβ‚‚]
variables [add_comm_monoid Nβ‚—] [add_comm_monoid Pβ‚—]
variables [add_comm_group M'] [add_comm_group N'] [add_comm_group P']
variables [module R M] [module S N] [module Rβ‚‚ P] [module Sβ‚‚ P]
variables [module R Mβ‚‚] [module S Nβ‚‚] [module R Pβ‚‚] [module Sβ‚‚ Pβ‚‚]
variables [module R Pβ‚—] [module S Pβ‚—]
variables [module R M'] [module S N'] [module Rβ‚‚ P'] [module Sβ‚‚ P']
variables [smul_comm_class Sβ‚‚ Rβ‚‚ P] [smul_comm_class S R Pβ‚—] [smul_comm_class Sβ‚‚ Rβ‚‚ P']
variables [smul_comm_class Sβ‚‚ R Pβ‚‚]
variables {ρ₁₂ : R β†’+* Rβ‚‚} {σ₁₂ : S β†’+* Sβ‚‚}

variables (ρ₁₂ σ₁₂)
/-- Create a bilinear map from a function that is semilinear in each component.
See `mkβ‚‚'` and `mkβ‚‚` for the linear case. -/
def mkβ‚‚'β‚›β‚— (f : M β†’ N β†’ P)
  (H1 : βˆ€ m₁ mβ‚‚ n, f (m₁ + mβ‚‚) n = f m₁ n + f mβ‚‚ n)
  (H2 : βˆ€ (c:R) m n, f (c β€’ m) n = (ρ₁₂ c) β€’ f m n)
  (H3 : βˆ€ m n₁ nβ‚‚, f m (n₁ + nβ‚‚) = f m n₁ + f m nβ‚‚)
  (H4 : βˆ€ (c:S) m n, f m (c β€’ n) = (σ₁₂ c) β€’ f m n) : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P :=
{ to_fun := Ξ» m, { to_fun := f m, map_add' := H3 m, map_smul' := Ξ» c, H4 c m},
  map_add' := Ξ» m₁ mβ‚‚, linear_map.ext $ H1 m₁ mβ‚‚,
  map_smul' := Ξ» c m, linear_map.ext $ H2 c m }
variables {ρ₁₂ σ₁₂}

@[simp] theorem mkβ‚‚'β‚›β‚—_apply
  (f : M β†’ N β†’ P) {H1 H2 H3 H4} (m : M) (n : N) :
  (mkβ‚‚'β‚›β‚— ρ₁₂ σ₁₂ f H1 H2 H3 H4 : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P) m n = f m n := rfl

variables (R S)
/-- Create a bilinear map from a function that is linear in each component.
See `mkβ‚‚` for the special case where both arguments come from modules over the same ring. -/
def mkβ‚‚' (f : M β†’ N β†’ Pβ‚—)
  (H1 : βˆ€ m₁ mβ‚‚ n, f (m₁ + mβ‚‚) n = f m₁ n + f mβ‚‚ n)
  (H2 : βˆ€ (c:R) m n, f (c β€’ m) n = c β€’ f m n)
  (H3 : βˆ€ m n₁ nβ‚‚, f m (n₁ + nβ‚‚) = f m n₁ + f m nβ‚‚)
  (H4 : βˆ€ (c:S) m n, f m (c β€’ n) = c β€’ f m n) : M β†’β‚—[R] N β†’β‚—[S] Pβ‚— :=
mkβ‚‚'β‚›β‚— (ring_hom.id R) (ring_hom.id S) f H1 H2 H3 H4
variables {R S}

@[simp] theorem mkβ‚‚'_apply
  (f : M β†’ N β†’ Pβ‚—) {H1 H2 H3 H4} (m : M) (n : N) :
  (mkβ‚‚' R S f H1 H2 H3 H4 : M β†’β‚—[R] N β†’β‚—[S] Pβ‚—) m n = f m n := rfl

theorem extβ‚‚ {f g : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P}
  (H : βˆ€ m n, f m n = g m n) : f = g :=
linear_map.ext (Ξ» m, linear_map.ext $ Ξ» n, H m n)

lemma congr_funβ‚‚ {f g : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P} (h : f = g) (x y) : f x y = g x y :=
linear_map.congr_fun (linear_map.congr_fun h x) y

section

local attribute [instance] smul_comm_class.symm

/-- Given a linear map from `M` to linear maps from `N` to `P`, i.e., a bilinear map from `M Γ— N` to
`P`, change the order of variables and get a linear map from `N` to linear maps from `M` to `P`. -/
def flip (f : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P) : N β†’β‚›β‚—[σ₁₂] M β†’β‚›β‚—[ρ₁₂] P :=
mkβ‚‚'β‚›β‚— σ₁₂ ρ₁₂ (Ξ» n m, f m n)
  (Ξ» n₁ nβ‚‚ m, (f m).map_add _ _)
  (Ξ» c n m, (f m).map_smulβ‚›β‚— _ _)
  (Ξ» n m₁ mβ‚‚, by rw f.map_add; refl)
  (Ξ» c n m, by rw f.map_smulβ‚›β‚—; refl)

end

@[simp] theorem flip_apply (f : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P) (m : M) (n : N) : flip f n m = f m n := rfl

@[simp] lemma flip_flip [smul_comm_class Rβ‚‚ Sβ‚‚ P] (f : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P) :
  f.flip.flip = f := linear_map.extβ‚‚ (Ξ» x y, ((f.flip).flip_apply _ _).trans (f.flip_apply _ _))

open_locale big_operators

variables {R}
theorem flip_inj {f g : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P} (H : flip f = flip g) : f = g :=
extβ‚‚ $ Ξ» m n, show flip f n m = flip g n m, by rw H

theorem map_zeroβ‚‚ (f : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P) (y) : f 0 y = 0 :=
(flip f y).map_zero

theorem map_negβ‚‚ (f : M' β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P') (x y) : f (-x) y = -f x y :=
(flip f y).map_neg _

theorem map_subβ‚‚ (f : M' β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P') (x y z) : f (x - y) z = f x z - f y z :=
(flip f z).map_sub _ _

theorem map_addβ‚‚ (f : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P) (x₁ xβ‚‚ y) : f (x₁ + xβ‚‚) y = f x₁ y + f xβ‚‚ y :=
(flip f y).map_add _ _

theorem map_smulβ‚‚ (f : Mβ‚‚ β†’β‚—[R] Nβ‚‚ β†’β‚›β‚—[σ₁₂] Pβ‚‚) (r : R) (x y) : f (r β€’ x) y = r β€’ f x y :=
(flip f y).map_smul _ _

theorem map_smulβ‚›β‚—β‚‚ (f : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P) (r : R) (x y) : f (r β€’ x) y = (ρ₁₂ r) β€’ f x y :=
(flip f y).map_smulβ‚›β‚— _ _

theorem map_sumβ‚‚ {ΞΉ : Type*} (f : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P) (t : finset ΞΉ) (x : ΞΉ β†’ M) (y) :
  f (βˆ‘ i in t, x i) y = βˆ‘ i in t, f (x i) y :=
(flip f y).map_sum

/-- Restricting a bilinear map in the second entry -/
def dom_restrictβ‚‚ (f : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P) (q : submodule S N) :
  M β†’β‚›β‚—[ρ₁₂] q β†’β‚›β‚—[σ₁₂] P :=
{ to_fun := Ξ» m, (f m).dom_restrict q,
  map_add' := Ξ» m₁ mβ‚‚, linear_map.ext $ Ξ» _, by simp only [map_add, dom_restrict_apply, add_apply],
  map_smul' := Ξ» c m, linear_map.ext $ Ξ» _, by simp only [f.map_smulβ‚›β‚—, dom_restrict_apply,
    smul_apply]}

lemma dom_restrictβ‚‚_apply (f : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P) (q : submodule S N) (x : M) (y : q) :
  f.dom_restrictβ‚‚ q x y = f x y := rfl

/-- Restricting a bilinear map in both components -/
def dom_restrict₁₂ (f : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P) (p : submodule R M) (q : submodule S N) :
  p β†’β‚›β‚—[ρ₁₂] q β†’β‚›β‚—[σ₁₂] P := (f.dom_restrict p).dom_restrictβ‚‚ q

lemma dom_restrict₁₂_apply (f : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P) (p : submodule R M) (q : submodule S N)
  (x : p) (y : q) : f.dom_restrict₁₂ p q x y = f x y := rfl

end semiring

section comm_semiring

variables {R : Type*} [comm_semiring R] {Rβ‚‚ : Type*} [comm_semiring Rβ‚‚]
variables {R₃ : Type*} [comm_semiring R₃] {Rβ‚„ : Type*} [comm_semiring Rβ‚„]
variables {M : Type*} {N : Type*} {P : Type*} {Q : Type*}
variables {Mβ‚— : Type*} {Nβ‚— : Type*} {Pβ‚— : Type*} {Qβ‚— Qβ‚—': Type*}

variables [add_comm_monoid M] [add_comm_monoid N] [add_comm_monoid P] [add_comm_monoid Q]
variables [add_comm_monoid Mβ‚—] [add_comm_monoid Nβ‚—] [add_comm_monoid Pβ‚—]
variables [add_comm_monoid Qβ‚—] [add_comm_monoid Qβ‚—']
variables [module R M] [module Rβ‚‚ N] [module R₃ P] [module Rβ‚„ Q]
variables [module R Mβ‚—] [module R Nβ‚—] [module R Pβ‚—] [module R Qβ‚—] [module R Qβ‚—']
variables {σ₁₂ : R β†’+* Rβ‚‚} {σ₂₃ : Rβ‚‚ β†’+* R₃} {σ₁₃ : R β†’+* R₃}
variables {Οƒβ‚„β‚‚ : Rβ‚„ β†’+* Rβ‚‚} {σ₄₃ : Rβ‚„ β†’+* R₃}
variables [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃] [ring_hom_comp_triple Οƒβ‚„β‚‚ σ₂₃ σ₄₃]

variables (R)

/-- Create a bilinear map from a function that is linear in each component.

This is a shorthand for `mkβ‚‚'` for the common case when `R = S`. -/
def mkβ‚‚ (f : M β†’ Nβ‚— β†’ Pβ‚—)
  (H1 : βˆ€ m₁ mβ‚‚ n, f (m₁ + mβ‚‚) n = f m₁ n + f mβ‚‚ n)
  (H2 : βˆ€ (c:R) m n, f (c β€’ m) n = c β€’ f m n)
  (H3 : βˆ€ m n₁ nβ‚‚, f m (n₁ + nβ‚‚) = f m n₁ + f m nβ‚‚)
  (H4 : βˆ€ (c:R) m n, f m (c β€’ n) = c β€’ f m n) : M β†’β‚—[R] Nβ‚— β†’β‚—[R] Pβ‚— :=
mkβ‚‚' R R f H1 H2 H3 H4

@[simp] theorem mkβ‚‚_apply
  (f : M β†’ Nβ‚— β†’ Pβ‚—) {H1 H2 H3 H4} (m : M) (n : Nβ‚—) :
  (mkβ‚‚ R f H1 H2 H3 H4 : M β†’β‚—[R] Nβ‚— β†’β‚—[R] Pβ‚—) m n = f m n := rfl

variables (R M N P)
/-- Given a linear map from `M` to linear maps from `N` to `P`, i.e., a bilinear map `M β†’ N β†’ P`,
change the order of variables and get a linear map from `N` to linear maps from `M` to `P`. -/
def lflip : (M β†’β‚›β‚—[σ₁₃] N β†’β‚›β‚—[σ₂₃] P) β†’β‚—[R₃] N β†’β‚›β‚—[σ₂₃] M β†’β‚›β‚—[σ₁₃] P :=
{ to_fun := flip, map_add' := Ξ» _ _, rfl, map_smul' := Ξ» _ _, rfl }
variables {R M N P}

variables (f : M β†’β‚›β‚—[σ₁₃] N β†’β‚›β‚—[σ₂₃] P)

@[simp] theorem lflip_apply (m : M) (n : N) : lflip R M N P f n m = f m n := rfl

variables (R Pβ‚—)
/-- Composing a linear map `M β†’ N` and a linear map `N β†’ P` to form a linear map `M β†’ P`. -/
def lcomp (f : M β†’β‚—[R] Nβ‚—) : (Nβ‚— β†’β‚—[R] Pβ‚—) β†’β‚—[R] M β†’β‚—[R] Pβ‚— :=
flip $ linear_map.comp (flip id) f

variables {R Pβ‚—}

@[simp] theorem lcomp_apply (f : M β†’β‚—[R] Nβ‚—) (g : Nβ‚— β†’β‚—[R] Pβ‚—) (x : M) :
  lcomp R Pβ‚— f g x = g (f x) := rfl

theorem lcomp_apply' (f : M β†’β‚—[R] Nβ‚—) (g : Nβ‚— β†’β‚—[R] Pβ‚—) :
  lcomp R Pβ‚— f g = g βˆ˜β‚— f := rfl

variables (P σ₂₃)
/-- Composing a semilinear map `M β†’ N` and a semilinear map `N β†’ P` to form a semilinear map
`M β†’ P` is itself a linear map. -/
def lcompβ‚›β‚— (f : M β†’β‚›β‚—[σ₁₂] N) : (N β†’β‚›β‚—[σ₂₃] P) β†’β‚—[R₃] M β†’β‚›β‚—[σ₁₃] P :=
flip $ linear_map.comp (flip id) f
variables {P σ₂₃}

include σ₁₃
@[simp] theorem lcompβ‚›β‚—_apply (f : M β†’β‚›β‚—[σ₁₂] N) (g : N β†’β‚›β‚—[σ₂₃] P) (x : M) :
  lcompβ‚›β‚— P σ₂₃ f g x = g (f x) := rfl
omit σ₁₃

variables (R M Nβ‚— Pβ‚—)
/-- Composing a linear map `M β†’ N` and a linear map `N β†’ P` to form a linear map `M β†’ P`. -/
def llcomp : (Nβ‚— β†’β‚—[R] Pβ‚—) β†’β‚—[R] (M β†’β‚—[R] Nβ‚—) β†’β‚—[R] M β†’β‚—[R] Pβ‚— :=
flip { to_fun := lcomp R Pβ‚—,
       map_add' := Ξ» f f', extβ‚‚ $ Ξ» g x, g.map_add _ _,
       map_smul' := Ξ» (c : R) f, extβ‚‚ $ Ξ» g x, g.map_smul _ _ }
variables {R M Nβ‚— Pβ‚—}

section
@[simp] theorem llcomp_apply (f : Nβ‚— β†’β‚—[R] Pβ‚—) (g : M β†’β‚—[R] Nβ‚—) (x : M) :
  llcomp R M Nβ‚— Pβ‚— f g x = f (g x) := rfl

theorem llcomp_apply' (f : Nβ‚— β†’β‚—[R] Pβ‚—) (g : M β†’β‚—[R] Nβ‚—) :
  llcomp R M Nβ‚— Pβ‚— f g = f βˆ˜β‚— g := rfl
end

/-- Composing a linear map `Q β†’ N` and a bilinear map `M β†’ N β†’ P` to
form a bilinear map `M β†’ Q β†’ P`. -/
def complβ‚‚ (g : Q β†’β‚›β‚—[Οƒβ‚„β‚‚] N) : M β†’β‚›β‚—[σ₁₃] Q β†’β‚›β‚—[σ₄₃] P := (lcompβ‚›β‚— _ _ g).comp f

include σ₄₃
@[simp] theorem complβ‚‚_apply (g : Q β†’β‚›β‚—[Οƒβ‚„β‚‚] N) (m : M) (q : Q) :
  f.complβ‚‚ g m q = f m (g q) := rfl
omit σ₄₃

/-- Composing linear maps `Q β†’ M` and `Q' β†’ N` with a bilinear map `M β†’ N β†’ P` to
form a bilinear map `Q β†’ Q' β†’ P`. -/
def compl₁₂ (f : Mβ‚— β†’β‚—[R] Nβ‚— β†’β‚—[R] Pβ‚—) (g : Qβ‚— β†’β‚—[R] Mβ‚—) (g' : Qβ‚—' β†’β‚—[R] Nβ‚—) :
  Qβ‚— β†’β‚—[R] Qβ‚—' β†’β‚—[R] Pβ‚— :=
(f.comp g).complβ‚‚ g'

@[simp] theorem compl₁₂_apply (f : Mβ‚— β†’β‚—[R] Nβ‚— β†’β‚—[R] Pβ‚—) (g : Qβ‚— β†’β‚—[R] Mβ‚—) (g' : Qβ‚—' β†’β‚—[R] Nβ‚—)
  (x : Qβ‚—) (y : Qβ‚—') : f.compl₁₂ g g' x y = f (g x) (g' y) := rfl

lemma compl₁₂_inj {f₁ fβ‚‚ : Mβ‚— β†’β‚—[R] Nβ‚— β†’β‚—[R] Pβ‚—} {g : Qβ‚— β†’β‚—[R] Mβ‚—} {g' : Qβ‚—' β†’β‚—[R] Nβ‚—}
  (hβ‚— : function.surjective g) (hα΅£ : function.surjective g') :
  f₁.compl₁₂ g g' = fβ‚‚.compl₁₂ g g' ↔ f₁ = fβ‚‚ :=
begin
  split; intros h,
  { -- B₁.comp l r = Bβ‚‚.comp l r β†’ B₁ = Bβ‚‚
    ext x y,
    cases hβ‚— x with x' hx, subst hx,
    cases hα΅£ y with y' hy, subst hy,
    convert linear_map.congr_funβ‚‚ h x' y' },
  { -- B₁ = Bβ‚‚ β†’ B₁.comp l r = Bβ‚‚.comp l r
    subst h },
end

/-- Composing a linear map `P β†’ Q` and a bilinear map `M β†’ N β†’ P` to
form a bilinear map `M β†’ N β†’ Q`. -/
def comprβ‚‚ (f : M β†’β‚—[R] Nβ‚— β†’β‚—[R] Pβ‚—) (g : Pβ‚— β†’β‚—[R] Qβ‚—) : M β†’β‚—[R] Nβ‚— β†’β‚—[R] Qβ‚— :=
(llcomp R Nβ‚— Pβ‚— Qβ‚— g) βˆ˜β‚— f

@[simp] theorem comprβ‚‚_apply (f : M β†’β‚—[R] Nβ‚— β†’β‚—[R] Pβ‚—) (g : Pβ‚— β†’β‚—[R] Qβ‚—) (m : M) (n : Nβ‚—) :
  f.comprβ‚‚ g m n = g (f m n) := rfl

variables (R M)
/-- Scalar multiplication as a bilinear map `R β†’ M β†’ M`. -/
def lsmul : R β†’β‚—[R] M β†’β‚—[R] M :=
mkβ‚‚ R (β€’) add_smul (Ξ» _ _ _, mul_smul _ _ _) smul_add
(Ξ» r s m, by simp only [smul_smul, smul_eq_mul, mul_comm])
variables {R M}

@[simp] theorem lsmul_apply (r : R) (m : M) : lsmul R M r m = r β€’ m := rfl

end comm_semiring

section comm_ring

variables {R Rβ‚‚ S Sβ‚‚ M N P : Type*}
variables [comm_ring R] [comm_ring S] [comm_ring Rβ‚‚] [comm_ring Sβ‚‚]
variables [add_comm_group M] [add_comm_group N] [add_comm_group P]
variables [module R M] [module S N] [module Rβ‚‚ P] [module Sβ‚‚ P]
variables [smul_comm_class Sβ‚‚ Rβ‚‚ P]
variables {ρ₁₂ : R β†’+* Rβ‚‚} {σ₁₂ : S β†’+* Sβ‚‚}
variables (b₁ : basis ι₁ R M) (bβ‚‚ : basis ΞΉβ‚‚ S N)

lemma lsmul_injective [no_zero_smul_divisors R M] {x : R} (hx : x β‰  0) :
  function.injective (lsmul R M x) :=
smul_right_injective _ hx

lemma ker_lsmul [no_zero_smul_divisors R M] {a : R} (ha : a β‰  0) :
  (linear_map.lsmul R M a).ker = βŠ₯ :=
linear_map.ker_eq_bot_of_injective (linear_map.lsmul_injective ha)


/-- Two bilinear maps are equal when they are equal on all basis vectors. -/
lemma ext_basis {B B' : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P}
  (h : βˆ€ i j, B (b₁ i) (bβ‚‚ j) = B' (b₁ i) (bβ‚‚ j)) : B = B' :=
b₁.ext $ Ξ» i, bβ‚‚.ext $ Ξ» j, h i j

/-- Write out `B x y` as a sum over `B (b i) (b j)` if `b` is a basis. -/
lemma sum_repr_mul_repr_mul {B : M β†’β‚›β‚—[ρ₁₂] N β†’β‚›β‚—[σ₁₂] P} (x y) :
  (b₁.repr x).sum (Ξ» i xi, (bβ‚‚.repr y).sum (Ξ» j yj, (ρ₁₂ xi) β€’ (σ₁₂ yj) β€’ B (b₁ i) (bβ‚‚ j))) =
  B x y :=
begin
  conv_rhs { rw [← b₁.total_repr x, ← bβ‚‚.total_repr y] },
  simp_rw [finsupp.total_apply, finsupp.sum, map_sumβ‚‚, map_sum,
    linear_map.map_smulβ‚›β‚—β‚‚, linear_map.map_smulβ‚›β‚—],
end


end comm_ring

end linear_map