| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- The non-commutative analogue of Nagata's construction of |
| 5 |
-- the "idealization of a module", (Local Rings, 1962; Wiley) |
| 6 |
-- defined here on R-R-*bi*modules M over a ring R, as used in |
| 7 |
-- "Forward- or reverse-mode automatic differentiation: What's the difference?" |
| 8 |
-- (Van den Berg, Schrijvers, McKinna, Vandenbroucke; |
| 9 |
-- Science of Computer Programming, Vol. 234, January 2024 |
| 10 |
-- https://doi.org/10.1016/j.scico.2023.103010) |
| 11 |
-- |
| 12 |
-- The construction N =def R ⋉ M , for which there is unfortunately |
| 13 |
-- no consistent notation in the literature, consists of: |
| 14 |
-- * carrier: pairs |R| × |M| |
| 15 |
-- * with additive structure that of the direct sum R ⊕ M _of modules_ |
| 16 |
-- * but with multiplication _*_ such that M forms an _ideal_ of N |
| 17 |
-- * moreover satisfying 'm * m ≈ 0' for every m ∈ M ⊆ N |
| 18 |
-- |
| 19 |
-- The fundamental lemma (proved here) is that N, in fact, defines a Ring: |
| 20 |
-- this ring is essentially the 'ring of dual numbers' construction R[M] |
| 21 |
-- (Clifford, 1874; generalised!) for an ideal M, and thus the synthetic/algebraic |
| 22 |
-- analogue of the tangent space of M (considered as a 'vector space' over R) |
| 23 |
-- in differential geometry, hence its application to Automatic Differentiation. |
| 24 |
-- |
| 25 |
-- Nagata's more fundamental insight (not yet shown here) is that |
| 26 |
-- the lattice of R-submodules of M is in order-isomorphism with |
| 27 |
-- the lattice of _ideals_ of R ⋉ M , and hence that the study of |
| 28 |
-- modules can be reduced to that of ideals of a ring, and vice versa. |
| 29 |
-- |
| 30 |
------------------------------------------------------------------------ |
| 31 |
|
| 32 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 33 |
|
| 34 |
open import Algebra.Bundles using (AbelianGroup; Ring) |
| 35 |
open import Algebra.Module.Bundles using (Bimodule) |
| 36 |
|
| 37 |
module Algebra.Module.Construct.Idealization |
| 38 |
{r ℓr m ℓm} (ring : Ring r ℓr) (bimodule : Bimodule ring ring m ℓm) where |
| 39 |
|
| 40 |
open import Algebra.Core using (Op₂) |
| 41 |
import Algebra.Consequences.Setoid as Consequences using (comm∧assoc⇒middleFour) |
| 42 |
import Algebra.Definitions as Definitions |
| 43 |
using (Congruent₂; _DistributesOverˡ_; _DistributesOverʳ_; _DistributesOver_ |
| 44 |
; LeftIdentity; RightIdentity; Identity; Associative) |
| 45 |
import Algebra.Module.Construct.DirectProduct as DirectProduct using (bimodule) |
| 46 |
import Algebra.Module.Construct.TensorUnit as TensorUnit using (bimodule) |
| 47 |
open import Algebra.Structures using (IsAbelianGroup; IsRing) |
| 48 |
open import Data.Product.Base using (_,_; ∃-syntax) |
| 49 |
open import Level using (Level; _⊔_) |
| 50 |
open import Relation.Binary.Bundles using (Setoid) |
| 51 |
open import Relation.Binary.Core using (Rel) |
| 52 |
open import Relation.Binary.Structures using (IsEquivalence) |
| 53 |
import Relation.Binary.Reasoning.Setoid as ≈-Reasoning |
| 54 |
|
| 55 |
------------------------------------------------------------------------ |
| 56 |
-- Definitions |
| 57 |
|
| 58 |
private |
| 59 |
open module R = Ring ring |
| 60 |
using () |
| 61 |
renaming (Carrier to R) |
| 62 |
|
| 63 |
open module M = Bimodule bimodule |
| 64 |
renaming (Carrierᴹ to M) |
| 65 |
|
| 66 |
+ᴹ-middleFour = Consequences.comm∧assoc⇒middleFour ≈ᴹ-setoid +ᴹ-cong +ᴹ-comm +ᴹ-assoc |
| 67 |
|
| 68 |
open module N = Bimodule (DirectProduct.bimodule TensorUnit.bimodule bimodule) |
| 69 |
using () |
| 70 |
renaming ( Carrierᴹ to N |
| 71 |
; _≈ᴹ_ to _≈_ |
| 72 |
; _+ᴹ_ to _+_ |
| 73 |
; 0ᴹ to 0# |
| 74 |
; -ᴹ_ to -_ |
| 75 |
; +ᴹ-isAbelianGroup to +-isAbelianGroup |
| 76 |
) |
| 77 |
|
| 78 |
open AbelianGroup M.+ᴹ-abelianGroup hiding (_≈_) |
| 79 |
open ≈-Reasoning ≈ᴹ-setoid |
| 80 |
open Definitions _≈_ |
| 81 |
|
| 82 |
-- Injections ι from the components of the direct sum |
| 83 |
-- ιᴹ in fact exhibits M as an _ideal_ of R ⋉ M (see below) |
| 84 |
ιᴿ : R → N |
| 85 |
ιᴿ r = r , 0ᴹ |
| 86 |
|
| 87 |
ιᴹ : M → N |
| 88 |
ιᴹ m = R.0# , m |
| 89 |
|
| 90 |
-- Multiplicative unit |
| 91 |
|
| 92 |
1# : N |
| 93 |
1# = ιᴿ R.1# |
| 94 |
|
| 95 |
-- Multiplication |
| 96 |
|
| 97 |
infixl 7 _*_ |
| 98 |
|
| 99 |
_*_ : Op₂ N |
| 100 |
(r₁ , m₁) * (r₂ , m₂) = r₁ R.* r₂ , r₁ *ₗ m₂ +ᴹ m₁ *ᵣ r₂ |
| 101 |
|
| 102 |
-- Properties: because we work in the direct sum, every proof has |
| 103 |
-- * an 'R'-component, which inherits directly from R, and |
| 104 |
-- * an 'M'-component, where the work happens |
| 105 |
|
| 106 |
*-cong : Congruent₂ _*_ |
| 107 |
*-cong (r₁ , m₁) (r₂ , m₂) = R.*-cong r₁ r₂ , +ᴹ-cong (*ₗ-cong r₁ m₂) (*ᵣ-cong m₁ r₂) |
| 108 |
|
| 109 |
*-identityˡ : LeftIdentity 1# _*_ |
| 110 |
*-identityˡ (r , m) = R.*-identityˡ r , (begin |
| 111 |
R.1# *ₗ m +ᴹ 0ᴹ *ᵣ r ≈⟨ +ᴹ-cong (*ₗ-identityˡ m) (*ᵣ-zeroˡ r) ⟩ |
| 112 |
m +ᴹ 0ᴹ ≈⟨ +ᴹ-identityʳ m ⟩ |
| 113 |
m ∎) |
| 114 |
|
| 115 |
*-identityʳ : RightIdentity 1# _*_ |
| 116 |
*-identityʳ (r , m) = R.*-identityʳ r , (begin |
| 117 |
r *ₗ 0ᴹ +ᴹ m *ᵣ R.1# ≈⟨ +ᴹ-cong (*ₗ-zeroʳ r) (*ᵣ-identityʳ m) ⟩ |
| 118 |
0ᴹ +ᴹ m ≈⟨ +ᴹ-identityˡ m ⟩ |
| 119 |
m ∎) |
| 120 |
|
| 121 |
*-identity : Identity 1# _*_ |
| 122 |
*-identity = *-identityˡ , *-identityʳ |
| 123 |
|
| 124 |
*-assoc : Associative _*_ |
| 125 |
*-assoc (r₁ , m₁) (r₂ , m₂) (r₃ , m₃) = R.*-assoc r₁ r₂ r₃ , (begin |
| 126 |
(r₁ R.* r₂) *ₗ m₃ +ᴹ (r₁ *ₗ m₂ +ᴹ m₁ *ᵣ r₂) *ᵣ r₃ |
| 127 |
≈⟨ +ᴹ-cong (*ₗ-assoc r₁ r₂ m₃) (*ᵣ-distribʳ r₃ (r₁ *ₗ m₂) (m₁ *ᵣ r₂)) ⟩ |
| 128 |
r₁ *ₗ (r₂ *ₗ m₃) +ᴹ ((r₁ *ₗ m₂) *ᵣ r₃ +ᴹ (m₁ *ᵣ r₂) *ᵣ r₃) |
| 129 |
≈⟨ +ᴹ-congˡ (+ᴹ-congʳ (*ₗ-*ᵣ-assoc r₁ m₂ r₃)) ⟩ |
| 130 |
r₁ *ₗ (r₂ *ₗ m₃) +ᴹ (r₁ *ₗ (m₂ *ᵣ r₃) +ᴹ (m₁ *ᵣ r₂) *ᵣ r₃) |
| 131 |
≈⟨ +ᴹ-assoc (r₁ *ₗ (r₂ *ₗ m₃)) (r₁ *ₗ (m₂ *ᵣ r₃)) ((m₁ *ᵣ r₂) *ᵣ r₃) ⟨ |
| 132 |
(r₁ *ₗ (r₂ *ₗ m₃) +ᴹ r₁ *ₗ (m₂ *ᵣ r₃)) +ᴹ (m₁ *ᵣ r₂) *ᵣ r₃ |
| 133 |
≈⟨ +ᴹ-cong (≈ᴹ-sym (*ₗ-distribˡ r₁ (r₂ *ₗ m₃) (m₂ *ᵣ r₃))) (*ᵣ-assoc m₁ r₂ r₃) ⟩ |
| 134 |
r₁ *ₗ (r₂ *ₗ m₃ +ᴹ m₂ *ᵣ r₃) +ᴹ m₁ *ᵣ (r₂ R.* r₃) ∎) |
| 135 |
|
| 136 |
distribˡ : _*_ DistributesOverˡ _+_ |
| 137 |
distribˡ (r₁ , m₁) (r₂ , m₂) (r₃ , m₃) = R.distribˡ r₁ r₂ r₃ , (begin |
| 138 |
r₁ *ₗ (m₂ +ᴹ m₃) +ᴹ m₁ *ᵣ (r₂ R.+ r₃) |
| 139 |
≈⟨ +ᴹ-cong (*ₗ-distribˡ r₁ m₂ m₃) (*ᵣ-distribˡ m₁ r₂ r₃) ⟩ |
| 140 |
(r₁ *ₗ m₂ +ᴹ r₁ *ₗ m₃) +ᴹ (m₁ *ᵣ r₂ +ᴹ m₁ *ᵣ r₃) |
| 141 |
≈⟨ +ᴹ-middleFour (r₁ *ₗ m₂) (r₁ *ₗ m₃) (m₁ *ᵣ r₂) (m₁ *ᵣ r₃) ⟩ |
| 142 |
(r₁ *ₗ m₂ +ᴹ m₁ *ᵣ r₂) +ᴹ (r₁ *ₗ m₃ +ᴹ m₁ *ᵣ r₃) ∎) |
| 143 |
|
| 144 |
|
| 145 |
distribʳ : _*_ DistributesOverʳ _+_ |
| 146 |
distribʳ (r₁ , m₁) (r₂ , m₂) (r₃ , m₃) = R.distribʳ r₁ r₂ r₃ , (begin |
| 147 |
(r₂ R.+ r₃) *ₗ m₁ +ᴹ (m₂ +ᴹ m₃) *ᵣ r₁ |
| 148 |
≈⟨ +ᴹ-cong (*ₗ-distribʳ m₁ r₂ r₃) (*ᵣ-distribʳ r₁ m₂ m₃) ⟩ |
| 149 |
(r₂ *ₗ m₁ +ᴹ r₃ *ₗ m₁) +ᴹ (m₂ *ᵣ r₁ +ᴹ m₃ *ᵣ r₁) |
| 150 |
≈⟨ +ᴹ-middleFour (r₂ *ₗ m₁) (r₃ *ₗ m₁) (m₂ *ᵣ r₁) (m₃ *ᵣ r₁) ⟩ |
| 151 |
(r₂ *ₗ m₁ +ᴹ m₂ *ᵣ r₁) +ᴹ (r₃ *ₗ m₁ +ᴹ m₃ *ᵣ r₁) ∎) |
| 152 |
|
| 153 |
distrib : _*_ DistributesOver _+_ |
| 154 |
distrib = distribˡ , distribʳ |
| 155 |
|
| 156 |
|
| 157 |
------------------------------------------------------------------------ |
| 158 |
-- The Fundamental Lemma |
| 159 |
|
| 160 |
-- Structure |
| 161 |
|
| 162 |
isRingᴺ : IsRing _≈_ _+_ _*_ -_ 0# 1# |
| 163 |
isRingᴺ = record |
| 164 |
{ +-isAbelianGroup = +-isAbelianGroup |
| 165 |
; *-cong = *-cong |
| 166 |
; *-assoc = *-assoc |
| 167 |
; *-identity = *-identity |
| 168 |
; distrib = distrib |
| 169 |
} |
| 170 |
|
| 171 |
-- Bundle |
| 172 |
|
| 173 |
ringᴺ : Ring (r ⊔ m) (ℓr ⊔ ℓm) |
| 174 |
ringᴺ = record { isRing = isRingᴺ } |
| 175 |
|
| 176 |
------------------------------------------------------------------------ |
| 177 |
-- M is an ideal of R ⋉ M satisfying m₁ * m₂ ≈ 0# |
| 178 |
|
| 179 |
ιᴹ-idealˡ : (n : N) (m : M) → ∃[ n*m ] n * ιᴹ m ≈ ιᴹ n*m |
| 180 |
ιᴹ-idealˡ n@(r , _) m = _ , R.zeroʳ r , ≈ᴹ-refl |
| 181 |
|
| 182 |
ιᴹ-idealʳ : (m : M) (n : N) → ∃[ m*n ] ιᴹ m * n ≈ ιᴹ m*n |
| 183 |
ιᴹ-idealʳ m n@(r , _) = _ , R.zeroˡ r , ≈ᴹ-refl |
| 184 |
|
| 185 |
*-annihilates-ιᴹ : (m₁ m₂ : M) → ιᴹ m₁ * ιᴹ m₂ ≈ 0# |
| 186 |
*-annihilates-ιᴹ m₁ m₂ = R.zeroˡ R.0# , (begin |
| 187 |
R.0# *ₗ m₂ +ᴹ m₁ *ᵣ R.0# ≈⟨ +ᴹ-cong (*ₗ-zeroˡ m₂) (*ᵣ-zeroʳ m₁) ⟩ |
| 188 |
0ᴹ +ᴹ 0ᴹ ≈⟨ +ᴹ-identityˡ 0ᴹ ⟩ |
| 189 |
0ᴹ ∎) |
| 190 |
|
| 191 |
m*m≈0 : (m : M) → ιᴹ m * ιᴹ m ≈ 0# |
| 192 |
m*m≈0 m = *-annihilates-ιᴹ m m |
| 193 |
|
| 194 |
------------------------------------------------------------------------ |
| 195 |
-- Infix notation for when opening the module unparameterised |
| 196 |
|
| 197 |
infixl 4 _⋉_ |
| 198 |
_⋉_ = ringᴺ |