Datasets:

Modalities:
Text
Languages:
English
Libraries:
Datasets
License:
File size: 24,635 Bytes
4365a98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc5e983
4365a98
 
 
 
 
 
 
 
 
 
 
 
 
fc5e983
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4365a98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc5e983
4365a98
fc5e983
 
 
 
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes HΓΆlzl, Mario Carneiro, Anne Baanen,
  FrΓ©dΓ©ric Dupuis, Heather Macbeth
-/
import algebra.module.linear_map

/-!
# (Semi)linear equivalences

In this file we define

* `linear_equiv Οƒ M Mβ‚‚`, `M ≃ₛₗ[Οƒ] Mβ‚‚`: an invertible semilinear map. Here, `Οƒ` is a `ring_hom`
  from `R` to `Rβ‚‚` and an `e : M ≃ₛₗ[Οƒ] Mβ‚‚` satisfies `e (c β€’ x) = (Οƒ c) β€’ (e x)`. The plain
  linear version, with `Οƒ` being `ring_hom.id R`, is denoted by `M ≃ₗ[R] Mβ‚‚`, and the
  star-linear version (with `Οƒ` being `star_ring_end`) is denoted by `M ≃ₗ⋆[R] Mβ‚‚`.

## Implementation notes

To ensure that composition works smoothly for semilinear equivalences, we use the typeclasses
`ring_hom_comp_triple`, `ring_hom_inv_pair` and `ring_hom_surjective` from
`algebra/ring/comp_typeclasses`.

The group structure on automorphisms, `linear_equiv.automorphism_group`, is provided elsewhere.

## TODO

* Parts of this file have not yet been generalized to semilinear maps

## Tags

linear equiv, linear equivalences, linear isomorphism, linear isomorphic
-/

open function
open_locale big_operators

universes u u' v w x y z
variables {R : Type*} {R₁ : Type*} {Rβ‚‚ : Type*} {R₃ : Type*}
variables {k : Type*} {S : Type*} {M : Type*} {M₁ : Type*} {Mβ‚‚ : Type*} {M₃ : Type*}
variables {N₁ : Type*} {Nβ‚‚ : Type*} {N₃ : Type*} {Nβ‚„ : Type*} {ΞΉ : Type*}

section
set_option old_structure_cmd true

/-- A linear equivalence is an invertible linear map. -/
@[nolint has_nonempty_instance]
structure linear_equiv {R : Type*} {S : Type*} [semiring R] [semiring S] (Οƒ : R β†’+* S)
  {Οƒ' : S β†’+* R} [ring_hom_inv_pair Οƒ Οƒ'] [ring_hom_inv_pair Οƒ' Οƒ]
  (M : Type*) (Mβ‚‚ : Type*)
  [add_comm_monoid M] [add_comm_monoid Mβ‚‚] [module R M] [module S Mβ‚‚]
  extends linear_map Οƒ M Mβ‚‚, M ≃+ Mβ‚‚

attribute [nolint doc_blame] linear_equiv.to_linear_map
attribute [nolint doc_blame] linear_equiv.to_add_equiv

notation M ` ≃ₛₗ[`:50 Οƒ `] ` Mβ‚‚ := linear_equiv Οƒ M Mβ‚‚
notation M ` ≃ₗ[`:50 R `] ` Mβ‚‚ := linear_equiv (ring_hom.id R) M Mβ‚‚
notation M ` ≃ₗ⋆[`:50 R `] ` Mβ‚‚ := linear_equiv (star_ring_end R) M Mβ‚‚

/-- `semilinear_equiv_class F Οƒ M Mβ‚‚` asserts `F` is a type of bundled `Οƒ`-semilinear equivs
`M β†’ Mβ‚‚`.

See also `linear_equiv_class F R M Mβ‚‚` for the case where `Οƒ` is the identity map on `R`.

A map `f` between an `R`-module and an `S`-module over a ring homomorphism `Οƒ : R β†’+* S`
is semilinear if it satisfies the two properties `f (x + y) = f x + f y` and
`f (c β€’ x) = (Οƒ c) β€’ f x`. -/
class semilinear_equiv_class (F : Type*) {R S : out_param Type*} [semiring R] [semiring S]
  (Οƒ : out_param $ R β†’+* S) {Οƒ' : out_param $ S β†’+* R}
  [ring_hom_inv_pair Οƒ Οƒ'] [ring_hom_inv_pair Οƒ' Οƒ] (M Mβ‚‚ : out_param Type*)
  [add_comm_monoid M] [add_comm_monoid Mβ‚‚] [module R M] [module S Mβ‚‚]
  extends add_equiv_class F M Mβ‚‚ :=
(map_smulβ‚›β‚— : βˆ€ (f : F) (r : R) (x : M), f (r β€’ x) = (Οƒ r) β€’ f x)

-- `R, S, Οƒ, Οƒ'` become metavars, but it's OK since they are outparams.
attribute [nolint dangerous_instance] semilinear_equiv_class.to_add_equiv_class

/-- `linear_equiv_class F R M Mβ‚‚` asserts `F` is a type of bundled `R`-linear equivs `M β†’ Mβ‚‚`.
This is an abbreviation for `semilinear_equiv_class F (ring_hom.id R) M Mβ‚‚`.
-/
abbreviation linear_equiv_class (F : Type*) (R M Mβ‚‚ : out_param Type*)
  [semiring R] [add_comm_monoid M] [add_comm_monoid Mβ‚‚] [module R M] [module R Mβ‚‚] :=
semilinear_equiv_class F (ring_hom.id R) M Mβ‚‚

end

namespace semilinear_equiv_class

variables (F : Type*) [semiring R] [semiring S]
variables [add_comm_monoid M] [add_comm_monoid M₁] [add_comm_monoid Mβ‚‚]
variables [module R M] [module S Mβ‚‚] {Οƒ : R β†’+* S} {Οƒ' : S β†’+* R}

-- `Οƒ'` becomes a metavariable, but it's OK since it's an outparam
@[priority 100, nolint dangerous_instance]
instance [ring_hom_inv_pair Οƒ Οƒ'] [ring_hom_inv_pair Οƒ' Οƒ] [s : semilinear_equiv_class F Οƒ M Mβ‚‚] :
  semilinear_map_class F Οƒ M Mβ‚‚ :=
{ coe := (coe : F β†’ M β†’ Mβ‚‚),
  coe_injective' := @fun_like.coe_injective F _ _ _,
  ..s }

end semilinear_equiv_class

namespace linear_equiv

section add_comm_monoid

variables {Mβ‚„ : Type*}
variables [semiring R] [semiring S]

section
variables [add_comm_monoid M] [add_comm_monoid M₁] [add_comm_monoid Mβ‚‚]
variables [module R M] [module S Mβ‚‚] {Οƒ : R β†’+* S} {Οƒ' : S β†’+* R}
variables [ring_hom_inv_pair Οƒ Οƒ'] [ring_hom_inv_pair Οƒ' Οƒ]

include R

include Οƒ'
instance : has_coe (M ≃ₛₗ[Οƒ] Mβ‚‚) (M β†’β‚›β‚—[Οƒ] Mβ‚‚) := ⟨to_linear_map⟩
-- see Note [function coercion]
instance : has_coe_to_fun (M ≃ₛₗ[Οƒ] Mβ‚‚) (Ξ» _, M β†’ Mβ‚‚) := ⟨to_fun⟩

@[simp] lemma coe_mk {to_fun inv_fun map_add map_smul left_inv right_inv } :
  ⇑(⟨to_fun, map_add, map_smul, inv_fun, left_inv, right_inv⟩ : M ≃ₛₗ[Οƒ] Mβ‚‚) = to_fun :=
rfl

-- This exists for compatibility, previously `≃ₗ[R]` extended `≃` instead of `≃+`.
@[nolint doc_blame]
def to_equiv : (M ≃ₛₗ[Οƒ] Mβ‚‚) β†’ M ≃ Mβ‚‚ := Ξ» f, f.to_add_equiv.to_equiv

lemma to_equiv_injective : function.injective (to_equiv : (M ≃ₛₗ[Οƒ] Mβ‚‚) β†’ M ≃ Mβ‚‚) :=
λ ⟨_, _, _, _, _, _⟩ ⟨_, _, _, _, _, _⟩ h, linear_equiv.mk.inj_eq.mpr (equiv.mk.inj h)

@[simp] lemma to_equiv_inj {e₁ eβ‚‚ : M ≃ₛₗ[Οƒ] Mβ‚‚} : e₁.to_equiv = eβ‚‚.to_equiv ↔ e₁ = eβ‚‚ :=
to_equiv_injective.eq_iff

lemma to_linear_map_injective :
  injective (coe : (M ≃ₛₗ[Οƒ] Mβ‚‚) β†’ (M β†’β‚›β‚—[Οƒ] Mβ‚‚)) :=
Ξ» e₁ eβ‚‚ H, to_equiv_injective $ equiv.ext $ linear_map.congr_fun H

@[simp, norm_cast] lemma to_linear_map_inj {e₁ eβ‚‚ : M ≃ₛₗ[Οƒ] Mβ‚‚} :
  (e₁ : M β†’β‚›β‚—[Οƒ] Mβ‚‚) = eβ‚‚ ↔ e₁ = eβ‚‚ :=
to_linear_map_injective.eq_iff

instance : semilinear_equiv_class (M ≃ₛₗ[Οƒ] Mβ‚‚) Οƒ M Mβ‚‚ :=
{ coe := linear_equiv.to_fun,
  inv := linear_equiv.inv_fun,
  coe_injective' := Ξ» f g h₁ hβ‚‚, by { cases f, cases g, congr' },
  left_inv := linear_equiv.left_inv,
  right_inv := linear_equiv.right_inv,
  map_add := map_add',
  map_smulβ‚›β‚— := map_smul' }

lemma coe_injective :
  @injective (M ≃ₛₗ[Οƒ] Mβ‚‚) (M β†’ Mβ‚‚) coe_fn :=
fun_like.coe_injective

end

section
variables [semiring R₁] [semiring Rβ‚‚] [semiring R₃]
variables [add_comm_monoid M] [add_comm_monoid M₁] [add_comm_monoid Mβ‚‚]
variables [add_comm_monoid M₃] [add_comm_monoid Mβ‚„]
variables [add_comm_monoid N₁] [add_comm_monoid Nβ‚‚]
variables {module_M : module R M} {module_S_Mβ‚‚ : module S Mβ‚‚} {Οƒ : R β†’+* S} {Οƒ' : S β†’+* R}
variables {re₁ : ring_hom_inv_pair Οƒ Οƒ'} {reβ‚‚ : ring_hom_inv_pair Οƒ' Οƒ}
variables (e e' : M ≃ₛₗ[Οƒ] Mβ‚‚)

lemma to_linear_map_eq_coe : e.to_linear_map = (e : M β†’β‚›β‚—[Οƒ] Mβ‚‚) := rfl

@[simp, norm_cast] theorem coe_coe : ⇑(e : M β†’β‚›β‚—[Οƒ] Mβ‚‚) = e := rfl

@[simp] lemma coe_to_equiv : ⇑e.to_equiv = e := rfl

@[simp] lemma coe_to_linear_map : ⇑e.to_linear_map = e := rfl

@[simp] lemma to_fun_eq_coe : e.to_fun = e := rfl

section
variables {e e'}
@[ext] lemma ext (h : βˆ€ x, e x = e' x) : e = e' := fun_like.ext _ _ h

lemma ext_iff : e = e' ↔ βˆ€ x, e x = e' x := fun_like.ext_iff

protected lemma congr_arg {x x'} : x = x' β†’ e x = e x' := fun_like.congr_arg e

protected lemma congr_fun (h : e = e') (x : M) : e x = e' x := fun_like.congr_fun h x

end

section
variables (M R)

/-- The identity map is a linear equivalence. -/
@[refl]
def refl [module R M] : M ≃ₗ[R] M := { .. linear_map.id, .. equiv.refl M }

end

@[simp] lemma refl_apply [module R M] (x : M) : refl R M x = x := rfl

include module_M module_S_Mβ‚‚ re₁ reβ‚‚
/-- Linear equivalences are symmetric. -/
@[symm]
def symm (e : M ≃ₛₗ[Οƒ] Mβ‚‚) : Mβ‚‚ ≃ₛₗ[Οƒ'] M :=
{ to_fun := e.to_linear_map.inverse e.inv_fun e.left_inv e.right_inv,
  inv_fun := e.to_equiv.symm.inv_fun,
  map_smul' := Ξ» r x, by rw map_smulβ‚›β‚—,
  .. e.to_linear_map.inverse e.inv_fun e.left_inv e.right_inv,
  .. e.to_equiv.symm }
omit module_M module_S_Mβ‚‚ re₁ reβ‚‚

/-- See Note [custom simps projection] -/
def simps.symm_apply {R : Type*} {S : Type*} [semiring R] [semiring S] {Οƒ : R β†’+* S}
  {Οƒ' : S β†’+* R} [ring_hom_inv_pair Οƒ Οƒ'] [ring_hom_inv_pair Οƒ' Οƒ]
  {M : Type*} {Mβ‚‚ : Type*} [add_comm_monoid M] [add_comm_monoid Mβ‚‚] [module R M] [module S Mβ‚‚]
  (e : M ≃ₛₗ[Οƒ] Mβ‚‚) : Mβ‚‚ β†’ M := e.symm

initialize_simps_projections linear_equiv (to_fun β†’ apply, inv_fun β†’ symm_apply)

include Οƒ'
@[simp] lemma inv_fun_eq_symm : e.inv_fun = e.symm := rfl
omit Οƒ'

@[simp] lemma coe_to_equiv_symm : ⇑e.to_equiv.symm = e.symm := rfl

variables {module_M₁ : module R₁ M₁} {module_Mβ‚‚ : module Rβ‚‚ Mβ‚‚} {module_M₃ : module R₃ M₃}
variables {module_N₁ : module R₁ N₁} {module_Nβ‚‚ : module R₁ Nβ‚‚}
variables {σ₁₂ : R₁ β†’+* Rβ‚‚} {σ₂₃ : Rβ‚‚ β†’+* R₃} {σ₁₃ : R₁ β†’+* R₃}
variables {σ₂₁ : Rβ‚‚ β†’+* R₁} {σ₃₂ : R₃ β†’+* Rβ‚‚} {σ₃₁ : R₃ β†’+* R₁}
variables [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃]
variables [ring_hom_comp_triple σ₃₂ σ₂₁ σ₃₁]
variables {re₁₂ : ring_hom_inv_pair σ₁₂ σ₂₁} {re₂₃ : ring_hom_inv_pair σ₂₃ σ₃₂}
variables [ring_hom_inv_pair σ₁₃ σ₃₁] {re₂₁ : ring_hom_inv_pair σ₂₁ σ₁₂}
variables {re₃₂ : ring_hom_inv_pair σ₃₂ σ₂₃} [ring_hom_inv_pair σ₃₁ σ₁₃]
variables (e₁₂ : M₁ ≃ₛₗ[σ₁₂] Mβ‚‚) (e₂₃ : Mβ‚‚ ≃ₛₗ[σ₂₃] M₃)

include σ₃₁
/-- Linear equivalences are transitive. -/
-- Note: The linter thinks the `ring_hom_comp_triple` argument is doubled -- it is not.
@[trans, nolint unused_arguments]
def trans : M₁ ≃ₛₗ[σ₁₃] M₃ :=
{ .. e₂₃.to_linear_map.comp e₁₂.to_linear_map,
  .. e₁₂.to_equiv.trans e₂₃.to_equiv }
omit σ₃₁

infixl ` β‰ͺ≫ₗ `:80 := @linear_equiv.trans _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  (ring_hom.id _) (ring_hom.id _) (ring_hom.id _)
  (ring_hom.id _) (ring_hom.id _) (ring_hom.id _)
  ring_hom_comp_triple.ids ring_hom_comp_triple.ids
  ring_hom_inv_pair.ids ring_hom_inv_pair.ids ring_hom_inv_pair.ids
  ring_hom_inv_pair.ids ring_hom_inv_pair.ids ring_hom_inv_pair.ids

variables {e₁₂} {e₂₃}

@[simp] lemma coe_to_add_equiv : ⇑(e.to_add_equiv) = e := rfl

/-- The two paths coercion can take to an `add_monoid_hom` are equivalent -/
lemma to_add_monoid_hom_commutes :
  e.to_linear_map.to_add_monoid_hom = e.to_add_equiv.to_add_monoid_hom :=
rfl

include σ₃₁
@[simp] theorem trans_apply (c : M₁) :
  (e₁₂.trans e₂₃ : M₁ ≃ₛₗ[σ₁₃] M₃) c = e₂₃ (e₁₂ c) := rfl
omit σ₃₁

include Οƒ'
@[simp] theorem apply_symm_apply (c : Mβ‚‚) : e (e.symm c) = c := e.right_inv c
@[simp] theorem symm_apply_apply (b : M) : e.symm (e b) = b := e.left_inv b
omit Οƒ'

include σ₃₁ σ₂₁ σ₃₂
@[simp] lemma trans_symm : (e₁₂.trans e₂₃ : M₁ ≃ₛₗ[σ₁₃] M₃).symm = e₂₃.symm.trans e₁₂.symm :=
rfl

lemma symm_trans_apply
  (c : M₃) : (e₁₂.trans e₂₃ : M₁ ≃ₛₗ[σ₁₃] M₃).symm c = e₁₂.symm (e₂₃.symm c) := rfl
omit σ₃₁ σ₂₁ σ₃₂

@[simp] lemma trans_refl : e.trans (refl S Mβ‚‚) = e := to_equiv_injective e.to_equiv.trans_refl
@[simp] lemma refl_trans : (refl R M).trans e = e := to_equiv_injective e.to_equiv.refl_trans

include Οƒ'
lemma symm_apply_eq {x y} : e.symm x = y ↔ x = e y := e.to_equiv.symm_apply_eq

lemma eq_symm_apply {x y} : y = e.symm x ↔ e y = x := e.to_equiv.eq_symm_apply
omit Οƒ'

lemma eq_comp_symm {Ξ± : Type*} (f : Mβ‚‚ β†’ Ξ±) (g : M₁ β†’ Ξ±) :
  f = g ∘ e₁₂.symm ↔ f ∘ e₁₂ = g := e₁₂.to_equiv.eq_comp_symm f g

lemma comp_symm_eq {Ξ± : Type*} (f : Mβ‚‚ β†’ Ξ±) (g : M₁ β†’ Ξ±) :
  g ∘ e₁₂.symm = f ↔ g = f ∘ e₁₂ := e₁₂.to_equiv.comp_symm_eq f g

lemma eq_symm_comp {Ξ± : Type*} (f : Ξ± β†’ M₁) (g : Ξ± β†’ Mβ‚‚) :
  f = e₁₂.symm ∘ g ↔ e₁₂ ∘ f = g := e₁₂.to_equiv.eq_symm_comp f g

lemma symm_comp_eq {Ξ± : Type*} (f : Ξ± β†’ M₁) (g : Ξ± β†’ Mβ‚‚) :
  e₁₂.symm ∘ g = f ↔ g = e₁₂ ∘ f := e₁₂.to_equiv.symm_comp_eq f g

variables [ring_hom_comp_triple σ₂₁ σ₁₃ σ₂₃] [ring_hom_comp_triple σ₃₁ σ₁₂ σ₃₂]

include module_M₃

lemma eq_comp_to_linear_map_symm (f : Mβ‚‚ β†’β‚›β‚—[σ₂₃] M₃) (g : M₁ β†’β‚›β‚—[σ₁₃] M₃) :
  f = g.comp e₁₂.symm.to_linear_map ↔ f.comp e₁₂.to_linear_map = g :=
begin
  split; intro H; ext,
  { simp [H, e₁₂.to_equiv.eq_comp_symm f g] },
  { simp [←H, ←e₁₂.to_equiv.eq_comp_symm f g] }
end

lemma comp_to_linear_map_symm_eq (f : Mβ‚‚ β†’β‚›β‚—[σ₂₃] M₃) (g : M₁ β†’β‚›β‚—[σ₁₃] M₃) :
  g.comp e₁₂.symm.to_linear_map = f ↔ g = f.comp e₁₂.to_linear_map :=
begin
  split; intro H; ext,
  { simp [←H, ←e₁₂.to_equiv.comp_symm_eq f g] },
  { simp [H, e₁₂.to_equiv.comp_symm_eq f g] }
end

lemma eq_to_linear_map_symm_comp (f : M₃ β†’β‚›β‚—[σ₃₁] M₁) (g : M₃ β†’β‚›β‚—[σ₃₂] Mβ‚‚) :
  f = e₁₂.symm.to_linear_map.comp g ↔ e₁₂.to_linear_map.comp f = g :=
begin
  split; intro H; ext,
  { simp [H, e₁₂.to_equiv.eq_symm_comp f g] },
  { simp [←H, ←e₁₂.to_equiv.eq_symm_comp f g] }
end

lemma to_linear_map_symm_comp_eq (f : M₃ β†’β‚›β‚—[σ₃₁] M₁) (g : M₃ β†’β‚›β‚—[σ₃₂] Mβ‚‚) :
  e₁₂.symm.to_linear_map.comp g = f ↔ g = e₁₂.to_linear_map.comp f :=
begin
  split; intro H; ext,
  { simp [←H, ←e₁₂.to_equiv.symm_comp_eq f g] },
  { simp [H, e₁₂.to_equiv.symm_comp_eq f g] }
end

omit module_M₃

@[simp] lemma refl_symm [module R M] : (refl R M).symm = linear_equiv.refl R M := rfl

@[simp] lemma self_trans_symm [module R M] [module R Mβ‚‚] (f : M ≃ₗ[R] Mβ‚‚) :
  f.trans f.symm = linear_equiv.refl R M :=
by { ext x, simp }

@[simp] lemma symm_trans_self [module R M] [module R Mβ‚‚] (f : M ≃ₗ[R] Mβ‚‚) :
  f.symm.trans f = linear_equiv.refl R Mβ‚‚ :=
by { ext x, simp }

@[simp, norm_cast] lemma refl_to_linear_map [module R M] :
  (linear_equiv.refl R M : M β†’β‚—[R] M) = linear_map.id :=
rfl

@[simp, norm_cast]
lemma comp_coe [module R M] [module R Mβ‚‚] [module R M₃] (f :  M ≃ₗ[R] Mβ‚‚)
  (f' :  Mβ‚‚ ≃ₗ[R] M₃) : (f' : Mβ‚‚ β†’β‚—[R] M₃).comp (f : M β†’β‚—[R] Mβ‚‚) = (f.trans f' : M ≃ₗ[R] M₃) :=
rfl

@[simp] lemma mk_coe (h₁ hβ‚‚ f h₃ hβ‚„) :
  (linear_equiv.mk e h₁ hβ‚‚ f h₃ hβ‚„ : M ≃ₛₗ[Οƒ] Mβ‚‚) = e := ext $ Ξ» _, rfl

protected theorem map_add (a b : M) : e (a + b) = e a + e b := map_add e a b
protected theorem map_zero : e 0 = 0 := map_zero e
-- TODO: `simp` isn't picking up `map_smulβ‚›β‚—` for `linear_equiv`s without specifying `map_smulβ‚›β‚— f`
@[simp] protected theorem map_smulβ‚›β‚— (c : R) (x : M) : e (c β€’ x) = (Οƒ c) β€’ e x := e.map_smul' c x

include module_N₁ module_Nβ‚‚
theorem map_smul (e : N₁ ≃ₗ[R₁] Nβ‚‚) (c : R₁) (x : N₁) :
  e (c β€’ x) = c β€’ e x := map_smulβ‚›β‚— e c x
omit module_N₁ module_Nβ‚‚

@[simp] lemma map_sum {s : finset ΞΉ} (u : ΞΉ β†’ M) : e (βˆ‘ i in s, u i) = βˆ‘ i in s, e (u i) :=
e.to_linear_map.map_sum

@[simp] theorem map_eq_zero_iff {x : M} : e x = 0 ↔ x = 0 :=
e.to_add_equiv.map_eq_zero_iff
theorem map_ne_zero_iff {x : M} : e x β‰  0 ↔ x β‰  0 :=
e.to_add_equiv.map_ne_zero_iff

include module_M module_S_Mβ‚‚ re₁ reβ‚‚
@[simp] theorem symm_symm (e : M ≃ₛₗ[Οƒ] Mβ‚‚): e.symm.symm = e :=
by { cases e, refl }
omit module_M module_S_Mβ‚‚ re₁ reβ‚‚

lemma symm_bijective [module R M] [module S Mβ‚‚] [ring_hom_inv_pair Οƒ' Οƒ]
  [ring_hom_inv_pair Οƒ Οƒ'] : function.bijective (symm : (M ≃ₛₗ[Οƒ] Mβ‚‚) β†’ (Mβ‚‚ ≃ₛₗ[Οƒ'] M)) :=
equiv.bijective ⟨(symm : (M ≃ₛₗ[Οƒ] Mβ‚‚) β†’
  (Mβ‚‚ ≃ₛₗ[Οƒ'] M)), (symm : (Mβ‚‚ ≃ₛₗ[Οƒ'] M) β†’ (M ≃ₛₗ[Οƒ] Mβ‚‚)), symm_symm, symm_symm⟩

@[simp] lemma mk_coe' (f h₁ hβ‚‚ h₃ hβ‚„) : (linear_equiv.mk f h₁ hβ‚‚ ⇑e h₃ hβ‚„ :
  Mβ‚‚ ≃ₛₗ[Οƒ'] M) = e.symm :=
symm_bijective.injective $ ext $ Ξ» x, rfl

@[simp] theorem symm_mk (f h₁ hβ‚‚ h₃ hβ‚„) :
  (⟨e, h₁, hβ‚‚, f, h₃, hβ‚„βŸ© : M ≃ₛₗ[Οƒ] Mβ‚‚).symm =
  { to_fun := f, inv_fun := e,
    ..(⟨e, h₁, hβ‚‚, f, h₃, hβ‚„βŸ© : M ≃ₛₗ[Οƒ] Mβ‚‚).symm } := rfl

@[simp] lemma coe_symm_mk [module R M] [module R Mβ‚‚]
  {to_fun inv_fun map_add map_smul left_inv right_inv} :
  ⇑((⟨to_fun, map_add, map_smul, inv_fun, left_inv, right_inv⟩ : M ≃ₗ[R] Mβ‚‚).symm) = inv_fun :=
rfl

protected lemma bijective : function.bijective e := e.to_equiv.bijective
protected lemma injective : function.injective e := e.to_equiv.injective
protected lemma surjective : function.surjective e := e.to_equiv.surjective

protected lemma image_eq_preimage (s : set M) : e '' s = e.symm ⁻¹' s :=
e.to_equiv.image_eq_preimage s

protected lemma image_symm_eq_preimage (s : set Mβ‚‚) : e.symm '' s = e ⁻¹' s :=
e.to_equiv.symm.image_eq_preimage s

end

/-- Interpret a `ring_equiv` `f` as an `f`-semilinear equiv. -/
@[simps]
def _root_.ring_equiv.to_semilinear_equiv (f : R ≃+* S) :
  by haveI := ring_hom_inv_pair.of_ring_equiv f;
     haveI := ring_hom_inv_pair.symm (↑f : R β†’+* S) (f.symm : S β†’+* R);
     exact (R ≃ₛₗ[(↑f : R β†’+* S)] S) :=
by exact
{ to_fun := f,
  map_smul' := f.map_mul,
  .. f}

variables [semiring R₁] [semiring Rβ‚‚] [semiring R₃]
variables [add_comm_monoid M] [add_comm_monoid M₁] [add_comm_monoid Mβ‚‚]

/-- An involutive linear map is a linear equivalence. -/
def of_involutive {Οƒ Οƒ' : R β†’+* R} [ring_hom_inv_pair Οƒ Οƒ'] [ring_hom_inv_pair Οƒ' Οƒ]
  {module_M : module R M} (f : M β†’β‚›β‚—[Οƒ] M) (hf : involutive f) :
  M ≃ₛₗ[Οƒ] M :=
{ .. f, .. hf.to_perm f }

@[simp] lemma coe_of_involutive {Οƒ Οƒ' : R β†’+* R} [ring_hom_inv_pair Οƒ Οƒ']
  [ring_hom_inv_pair Οƒ' Οƒ] {module_M : module R M} (f : M β†’β‚›β‚—[Οƒ] M) (hf : involutive f) :
  ⇑(of_involutive f hf) = f :=
rfl

section restrict_scalars

variables (R) [module R M] [module R Mβ‚‚] [module S M] [module S Mβ‚‚]
  [linear_map.compatible_smul M Mβ‚‚ R S]

/-- If `M` and `Mβ‚‚` are both `R`-semimodules and `S`-semimodules and `R`-semimodule structures
are defined by an action of `R` on `S` (formally, we have two scalar towers), then any `S`-linear
equivalence from `M` to `Mβ‚‚` is also an `R`-linear equivalence.

See also `linear_map.restrict_scalars`. -/
@[simps]
def restrict_scalars (f : M ≃ₗ[S] Mβ‚‚) : M ≃ₗ[R] Mβ‚‚ :=
{ to_fun := f,
  inv_fun := f.symm,
  left_inv := f.left_inv,
  right_inv := f.right_inv,
  .. f.to_linear_map.restrict_scalars R }

lemma restrict_scalars_injective :
  function.injective (restrict_scalars R : (M ≃ₗ[S] Mβ‚‚) β†’ (M ≃ₗ[R] Mβ‚‚)) :=
Ξ» f g h, ext (linear_equiv.congr_fun h : _)

@[simp]
lemma restrict_scalars_inj (f g : M ≃ₗ[S] Mβ‚‚) :
  f.restrict_scalars R = g.restrict_scalars R ↔ f = g :=
(restrict_scalars_injective R).eq_iff

end restrict_scalars

section automorphisms
variables [module R M]

instance automorphism_group : group (M ≃ₗ[R] M) :=
{ mul := Ξ» f g, g.trans f,
  one := linear_equiv.refl R M,
  inv := Ξ» f, f.symm,
  mul_assoc := Ξ» f g h, rfl,
  mul_one := Ξ» f, ext $ Ξ» x, rfl,
  one_mul := Ξ» f, ext $ Ξ» x, rfl,
  mul_left_inv := Ξ» f, ext $ f.left_inv }

/-- Restriction from `R`-linear automorphisms of `M` to `R`-linear endomorphisms of `M`,
promoted to a monoid hom. -/
@[simps]
def automorphism_group.to_linear_map_monoid_hom : (M ≃ₗ[R] M) β†’* (M β†’β‚—[R] M) :=
{ to_fun := coe,
  map_one' := rfl,
  map_mul' := Ξ» _ _, rfl }

/-- The tautological action by `M ≃ₗ[R] M` on `M`.

This generalizes `function.End.apply_mul_action`. -/
instance apply_distrib_mul_action : distrib_mul_action (M ≃ₗ[R] M) M :=
{ smul := ($),
  smul_zero := linear_equiv.map_zero,
  smul_add := linear_equiv.map_add,
  one_smul := Ξ» _, rfl,
  mul_smul := Ξ» _ _ _, rfl }

@[simp] protected lemma smul_def (f : M ≃ₗ[R] M) (a : M) :
  f β€’ a = f a := rfl

/-- `linear_equiv.apply_distrib_mul_action` is faithful. -/
instance apply_has_faithful_smul : has_faithful_smul (M ≃ₗ[R] M) M :=
⟨λ _ _, linear_equiv.ext⟩

instance apply_smul_comm_class : smul_comm_class R (M ≃ₗ[R] M) M :=
{ smul_comm := Ξ» r e m, (e.map_smul r m).symm }

instance apply_smul_comm_class' : smul_comm_class (M ≃ₗ[R] M) R M :=
{ smul_comm := linear_equiv.map_smul }

end automorphisms

end add_comm_monoid

end linear_equiv

namespace module

/-- `g : R ≃+* S` is `R`-linear when the module structure on `S` is `module.comp_hom S g` . -/
@[simps]
def comp_hom.to_linear_equiv {R S : Type*} [semiring R] [semiring S] (g : R ≃+* S) :
  (by haveI := comp_hom S (↑g : R β†’+* S); exact (R ≃ₗ[R] S)) :=
by exact
{ to_fun := (g : R β†’ S),
  inv_fun := (g.symm : S β†’ R),
  map_smul' := g.map_mul,
  ..g }

end module

namespace distrib_mul_action

variables (R M) [semiring R] [add_comm_monoid M] [module R M]
variables [group S] [distrib_mul_action S M] [smul_comm_class S R M]

/-- Each element of the group defines a linear equivalence.

This is a stronger version of `distrib_mul_action.to_add_equiv`. -/
@[simps]
def to_linear_equiv (s : S) : M ≃ₗ[R] M :=
{ ..to_add_equiv M s,
  ..to_linear_map R M s }

/-- Each element of the group defines a module automorphism.

This is a stronger version of `distrib_mul_action.to_add_aut`. -/
@[simps]
def to_module_aut : S β†’* M ≃ₗ[R] M :=
{ to_fun := to_linear_equiv R M,
  map_one' := linear_equiv.ext $ one_smul _,
  map_mul' := Ξ» a b, linear_equiv.ext $ mul_smul _ _ }

end distrib_mul_action

namespace add_equiv

section add_comm_monoid

variables [semiring R] [add_comm_monoid M] [add_comm_monoid Mβ‚‚] [add_comm_monoid M₃]
variables [module R M] [module R Mβ‚‚]

variable (e : M ≃+ Mβ‚‚)

/-- An additive equivalence whose underlying function preserves `smul` is a linear equivalence. -/
def to_linear_equiv (h : βˆ€ (c : R) x, e (c β€’ x) = c β€’ e x) : M ≃ₗ[R] Mβ‚‚ :=
{ map_smul' := h, .. e, }

@[simp] lemma coe_to_linear_equiv (h : βˆ€ (c : R) x, e (c β€’ x) = c β€’ e x) :
  ⇑(e.to_linear_equiv h) = e :=
rfl

@[simp] lemma coe_to_linear_equiv_symm (h : βˆ€ (c : R) x, e (c β€’ x) = c β€’ e x) :
  ⇑(e.to_linear_equiv h).symm = e.symm :=
rfl

/-- An additive equivalence between commutative additive monoids is a linear equivalence between
β„•-modules -/
def to_nat_linear_equiv  : M ≃ₗ[β„•] Mβ‚‚ :=
e.to_linear_equiv $ Ξ» c a, by { erw e.to_add_monoid_hom.map_nsmul, refl }

@[simp] lemma coe_to_nat_linear_equiv :
  ⇑(e.to_nat_linear_equiv) = e := rfl

@[simp] lemma to_nat_linear_equiv_to_add_equiv :
  e.to_nat_linear_equiv.to_add_equiv = e := by { ext, refl }

@[simp] lemma _root_.linear_equiv.to_add_equiv_to_nat_linear_equiv
  (e : M ≃ₗ[β„•] Mβ‚‚) : e.to_add_equiv.to_nat_linear_equiv = e := fun_like.coe_injective rfl

@[simp] lemma to_nat_linear_equiv_symm :
  (e.to_nat_linear_equiv).symm = e.symm.to_nat_linear_equiv := rfl

@[simp] lemma to_nat_linear_equiv_refl :
  ((add_equiv.refl M).to_nat_linear_equiv) = linear_equiv.refl β„• M := rfl

@[simp] lemma to_nat_linear_equiv_trans (eβ‚‚ : Mβ‚‚ ≃+ M₃) :
  (e.to_nat_linear_equiv).trans (eβ‚‚.to_nat_linear_equiv) = (e.trans eβ‚‚).to_nat_linear_equiv := rfl

end add_comm_monoid

section add_comm_group

variables [add_comm_group M] [add_comm_group Mβ‚‚] [add_comm_group M₃]

variable (e : M ≃+ Mβ‚‚)

/-- An additive equivalence between commutative additive groups is a linear
equivalence between β„€-modules -/
def to_int_linear_equiv : M ≃ₗ[β„€] Mβ‚‚ :=
e.to_linear_equiv $ Ξ» c a, e.to_add_monoid_hom.map_zsmul a c

@[simp] lemma coe_to_int_linear_equiv :
  ⇑(e.to_int_linear_equiv) = e := rfl

@[simp] lemma to_int_linear_equiv_to_add_equiv :
  e.to_int_linear_equiv.to_add_equiv = e := by { ext, refl }

@[simp] lemma _root_.linear_equiv.to_add_equiv_to_int_linear_equiv
  (e : M ≃ₗ[β„€] Mβ‚‚) : e.to_add_equiv.to_int_linear_equiv = e := fun_like.coe_injective rfl

@[simp] lemma to_int_linear_equiv_symm :
  (e.to_int_linear_equiv).symm = e.symm.to_int_linear_equiv := rfl

@[simp] lemma to_int_linear_equiv_refl :
  ((add_equiv.refl M).to_int_linear_equiv) = linear_equiv.refl β„€ M := rfl

@[simp] lemma to_int_linear_equiv_trans (eβ‚‚ : Mβ‚‚ ≃+ M₃)  :
  (e.to_int_linear_equiv).trans (eβ‚‚.to_int_linear_equiv) = (e.trans eβ‚‚).to_int_linear_equiv :=
rfl

end add_comm_group

end add_equiv