Datasets:
Tasks:
Text Generation
Modalities:
Text
Sub-tasks:
language-modeling
Languages:
English
Size:
100K - 1M
License:
/- | |
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 | |