module Algebra.Ring.Localisation where
Localisations of commutative ringsπ
The localisation of a commutative ring at a set of elements is the universal solution to forcing the elements of to become invertible, analogously to how localisations of a category universally invert a class of maps in Explicitly, it is a commutative ring equipped with a homomorphism which sends elements to invertible elements and which is initial among these.
The elements of are given by formal fractions, which we will write with and Type-theoretically, such a fraction is really a triple, since we must also consider the witness that the denominator belongs to but, since these proofs do not matter for identity of fractions, we will generally omit them in the prose.
record Fraction {β β'} {R : Type β} (S : R β Type β') : Type (β β β') where
no-eta-equality ; pattern
constructor _/_[_]
field
: R
num : R
denom : denom β S has-denom
open Fraction renaming (num to β ; denom to β)
pattern _/_ x y = x / y [ _ ]
instance
H-Level-Fraction: β {n β β'} {R : Type β} {S : R β Type β'} β¦ _ : H-Level R n β¦ β¦ _ : β {x} β H-Level (S x) n β¦
β H-Level (Fraction S) n
{n = n} {k} {R = R} {S} = hlevel-instance
H-Level-Fraction (retractβis-hlevel {A = R Γ β«β S} n
(Ξ» (x , y , p) β x / y [ p ])
(Ξ» (x / y [ p ]) β x , y , p)
(Ξ» { (x / y [ p ]) i β x / y [ p ] })
(hlevel n))
Inductive-Fraction: β {β β' β'' βm} {R : Type β} {S : R β Type β'} {P : Fraction S β Type β''}
β β¦ _ : Inductive ((num : β R β) (denom : β R β) (has : denom β S) β P (num / denom [ has ])) βm β¦
β Inductive ((x : Fraction S) β P x) βm
.Inductive.methods = r .Inductive.methods
Inductive-Fraction β¦ r β¦ .Inductive.from f (x / s [ p ]) = r .Inductive.from f x s p
Inductive-Fraction β¦ r β¦
Fraction-path: β {β β'} {R : Type β} {S : β R β β Type β'}
β β¦ _ : β {x} β H-Level (S x) 1 β¦ {x y : Fraction S}
β β x β‘ β y β β x β‘ β y β x β‘ y
{S = S} {x = x / s [ p ]} {y / t [ q ] } Ξ± Ξ² i = record
Fraction-path { num = Ξ± i
; denom = Ξ² i
; has-denom = is-propβpathp (Ξ» i β hlevel {T = S (Ξ² i)} 1) p q i
}
module Frac {β} (R : CRing β) where
open Explicit R
open CRing R
To ensure that we have a well-behaved theory of fractions, we will require that is a multiplicatively closed subset of In particular, the presence of allows us to form the fractions for any thus ensuring we have a map We also require that, if and then also This will be important to define both multiplication and identity of fractions.
record is-multiplicative {β'} (S : β R β β Type β') : Type (β β β') where
field
: 1r β S
has-1 : β {x y} β x β S β y β S β (x * y) β S has-*
Under the assumption that is multiplicatively closed, we could attempt to mimic the usual operations on integer-valued fractions on our fractions, for example, defining the sum to be This turns out not to work too well: for example, if we then also define we would have equal to
which is not literally the zero fraction However, we still have so these fractions βrepresent the same quantityβ β they both stand for zero times the formal inverse of something. We could then try to identify fractions and whenever but, in a general ring this relation fails to be transitive, so it can not be equality in a set. Therefore, we allow an βadjustmentβ by one of our formal denominators: the equivalence relation we will impose on fractions identifies whenever there exists with
data _β_ {β'} {S : β R β β Type β'} (x y : Fraction S) : Type (β β β') where
: (u : β R β) (uβS : u β S) β u * β x * β y β‘ u * β y * β x β x β y
inc : is-prop (x β y) squash
{-
We define _β_ as a data type so it's injective. It could also be a
record, but then we'd have to truncate the record in a separate step.
-}
instance
Inductive-β: β {β' β'' βm} {S : β R β β Type β'} {x y : Fraction S} {P : x β y β Type β''}
β β¦ h : β {x} β H-Level (P x) 1 β¦
β β¦ r : Inductive ((u : β R β) (uβS : u β S) (p : u * β x * β y β‘ u * β y * β x) β P (inc u uβS p)) βm β¦
β Inductive ((p : x β y) β P p) βm
.Inductive.methods = r .Inductive.methods
Inductive-β β¦ h β¦ β¦ r β¦ {S = S} {x} {y} {P} β¦ h β¦ β¦ r β¦ .Inductive.from f = go (r .Inductive.from f) where
Inductive-β
go: ((u : β R β) (uβS : u β S) (p : u * β x * β y β‘ u * β y * β x) β P (inc u uβS p))
β β x β P x
(inc u uβS x) = m u uβS x
go m (squash x y i) = is-propβpathp (Ξ» i β hlevel {T = P (squash x y i)} 1) (go m x) (go m y) i
go m
: β {β'} {S : β R β β Type β'} {x y : Fraction S} {n} β H-Level (x β y) (suc n)
H-Level-β = prop-instance squash H-Level-β
In the literature, this is more commonly phrased as but the equivalence between that and our definition is routine.
_β'_ : β {β'} {S : β R β β Type β'} β Fraction S β Fraction S β Type _
_β'_ {S = S} (x / s) (y / t) = β[ u β R ] (u β S Γ u * (x * t - y * s) β‘ 0r)
The calculation can be found in this <details>
block.
: β {β'} {S : β R β β Type β'} {x y : Fraction S} β x β y β x β' y
βββ' {x = x / s} {y = y / t} = elim! Ξ» u uβS p β
βββ' let
=
prf (x * t - y * s) β‘β¨ solve 5 (Ξ» u x t y s β u :* (x :* t :- y :* s) β u :* x :* t :- u :* y :* s) u x t y s refl β©
u * _-_ refl (sym p) β©
u * x * t - u * y * s β‘β¨ apβ 1 (Ξ» x β x :- x β 0) (u * x * t) refl β©
u * x * t - u * x * t β‘β¨ solve
0r βin inc (u , uβS , prf)
: β {β'} {S : β R β β Type β'} {x y : Fraction S} β x β' y β x β y
β'ββ {x = x / s} {y = y / t} = elim! Ξ» u uβS p β
β'ββ let
=
prf 5 (Ξ» u x t y s β u :* x :* t :- u :* y :* s β u :* (x :* t :- y :* s)) u x t y s refl β©
u * x * t - u * y * s β‘β¨ solve (x * t - y * s) β‘β¨ p β©
u *
0r βin inc u uβS (zero-diff prf)
module Loc {β} (R : CRing β) (S : β R β β Ξ©) (mult : Frac.is-multiplicative R (_β S)) where
open Frac.is-multiplicative mult
open Explicit R
open CRing R
open Frac R public
open Congruence using (_βΌ_ ; has-is-prop ; reflαΆ ; _βαΆ_ ; symαΆ)
Our next step is showing that this relation is actually an equivalence relation. The proof of transitivity is the most interesting step: we assume that and with βadjustmentsβ by respectively, but we produce the equation β we must consider the denominator of the middle fraction to relate the two endpoints and
: Congruence (Fraction (_β S)) _
Fraction-congruence ._βΌ_ = _β_
Fraction-congruence .has-is-prop (_ / _) (_ / _) = hlevel 1
Fraction-congruence .reflαΆ {x / s} = inc 1r has-1 refl
Fraction-congruence .symαΆ {x / s} {y / t} = rec! Ξ» u uβS p β inc u uβS (sym p)
Fraction-congruence ._βαΆ_ {x / s} {y / t [ r ]} {z / u} = elim!
Fraction-congruence Ξ» v vβS p w wβS q β
let
=
prf
w * v * t * x * u β‘β¨ cring! R β©(v * x * t) β‘β¨ ap (w * u *_) p β©
w * u * (v * y * s) β‘β¨ cring! R β©
w * u * (w * y * u) * (v * s) β‘β¨ apβ _*_ q refl β©
(w * z * t) * (v * s) β‘β¨ cring! R β©
w * v * t * z * s βin
(w * v * t) (has-* (has-* wβS vβS) r) prf inc
module Fr = Congruence Fraction-congruence
open Fraction
private
: β {x y : Fraction (_β S)} β x .num β‘ y .num β x .denom β‘ y .denom β Path Fr.quotient (inc x) (inc y)
/-ap = ap Coeq.inc (Fraction-path p q) /-ap p q
We then define to be the set of fractions identified according to this relation. Since we can immediately cough up the function mapping
_/1 : β R β β Fr.quotient
= inc (x / 1r [ has-1 ]) x /1
To define the operations of a ring on we first define them at the level of fractions:
As mentioned above, these operations do not satisfy the laws of a ring on the set of fractions. We must therefore prove that they respect the quotient weβve taken, and then prove that they satisfy the ring laws on the quotient.
: Fraction (_β S) β Fraction (_β S) β Fraction (_β S)
+f (x / s [ p ]) (y / t [ q ]) = (x * t + y * s) / (s * t) [ has-* p q ]
+f
: Fraction (_β S) β Fraction (_β S)
-f (x / s [ p ]) = (- x) / s [ p ]
-f
: Fraction (_β S) β Fraction (_β S) β Fraction (_β S)
*f (x / s [ p ]) (y / t [ q ]) = (x * y) / (s * t) [ has-* p q ] *f
Showing that these operations descend to the quotient is entirely
routine algebra; However, the calculations do get pretty long,
so weβll leave them in this <details>
block.
_ : Fr.quotient β Fr.quotient
-β_ = Quot-elim (Ξ» _ β hlevel 2) (Ξ» x β inc (-f x)) -f-resp where abstract
-β: β x y β x β y β Path Fr.quotient (inc (-f x)) (inc (-f y))
-f-resp (x / s) (y / t) = elim! Ξ» u uβS p β
-f-resp let
=
prf (- x) * t β‘β¨ ap (_* t) *-negater β *-negatel β©
u * (u * x * t) β‘β¨ ap -_ p β©
- (u * y * s) β‘β¨ sym *-negatel β ap (_* s) (sym *-negater) β©
- (- y) * s β
u * in quot (inc u uβS prf)
_+β_ : Fr.quotient β Fr.quotient β Fr.quotient
_+β_ = Fr.opβ-comm +f (Ξ» a b β Fr.reflαΆ' (+f-comm a b)) +f-resp where abstract
: β u v β +f u v β‘ +f v u
+f-comm (x / s) (y / t) = Fraction-path +-commutes *-commutes
+f-comm
: β x u v β u β v β +f x u β +f x v
+f-resp (x / s) (u / y) (v / z) = rec! Ξ» w wβS p β
+f-resp let
=
prf (x * y + u * s) * (s * z) β‘β¨ cring! R β©
w *
w * x * y * s * z + s * s * β w * u * z β β‘β¨ ap! p β©
w * x * y * s * z + s * s * β w * v * y β β‘β¨ cring! R β©(x * z + v * s) * (s * y) β
w * in inc w wβS prf
_*β_ : Fr.quotient β Fr.quotient β Fr.quotient
_*β_ = Fr.opβ-comm *f *f-comm *f-resp where abstract
: β u v β *f u v β *f v u
*f-comm (x / s) (y / t) = inc 1r has-1 (solve 4 (Ξ» x y t s β 1 :* (x :* y) :* (t :* s) β 1 :* (y :* x) :* (s :* t)) x y t s refl)
*f-comm
: β x u v β u β v β *f x u β *f x v
*f-resp (x / s) (u / y) (v / z) = rec! Ξ» w wβS p β
*f-resp let
=
prf (x * u) * (s * z) β‘β¨ cring! R β©
w * (w * u * z) β‘β¨ ap (s * x *_) p β©
s * x * (w * v * y) β‘β¨ cring! R β©
s * x * (x * v) * (s * y) β
w * in inc w wβS prf
infixl 8 _+β_
infixl 9 _*β_
infix 10 -β_ _/1
: Fr.quotient
0β 1β = 0r /1
0β = 1r /1 1β
We choose the zero and identity elements for so that the localising map preserves them definitionally. Weβre almost done with the construction; while thereβs quite a bit of algebra left to do to show that we have a ring, this is almost entirely automatic. As a warm-up, we can prove that is inverted by whenever
: β x (p : x β S) β inc (1r / x [ p ]) *β (x /1) β‘ 1β
/1-inverts = quot (inc 1r has-1
/1-inverts x p (solve 1 (Ξ» x β 1 :* (1 :* x) :* 1 β 1 :* 1 :* (x :* 1)) x refl))
The actual proof obligation is shown above: we have to establish that which can be shown by a naΓ―ve solver. The equations for each of the ring laws are similarly boring:
abstract
: β x β 0β +β x β‘ x
+β-idl = elim! Ξ» x s _ β /-ap
+β-idl (solve 2 (Ξ» s x β 0 :* s :+ x :* 1 β x) s x refl)
*-idl
: β x β x +β (-β x) β‘ 0β
+β-invr = elim! Ξ» x s _ β quot (inc 1r has-1 (solve 2
+β-invr (Ξ» x s β 1 :* (x :* s :+ (:- x) :* s) :* 1 β 1 :* 0 :* (s :* s)) x s refl))
: β x y z β x +β (y +β z) β‘ (x +β y) +β z
+β-assoc = elim! Ξ» x s _ y t _ z u _ β /-ap
+β-assoc (solve 6 (Ξ» x y z s t u β
(t :* u) :+ (y :* u :+ z :* t) :* s
x :* (x :* t :+ y :* s) :* u :+ z :* (s :* t)) x y z s t u refl)
β
*-associative
: β x y β x +β y β‘ y +β x
+β-comm = elim! Ξ» x s _ y t _ β /-ap +-commutes *-commutes
+β-comm
: β x β 1β *β x β‘ x
*β-idl = elim! Ξ» x s sβS β quot (inc s sβS (solve 2
*β-idl (Ξ» x s β s :* (1 :* x) :* s β s :* x :* (1 :* s)) x s refl))
: β x y β x *β y β‘ y *β x
*β-comm = elim! Ξ» x s _ y t _ β /-ap *-commutes *-commutes
*β-comm
: β x y z β x *β (y *β z) β‘ (x *β y) *β z
*β-assoc = elim! Ξ» x s _ y t _ z u _ β /-ap *-associative *-associative
*β-assoc
: β x y z β x *β (y +β z) β‘ (x *β y) +β (x *β z)
*β-distribl = elim! Ξ» x s _ y t _ z u _ β
*β-distribl let
: 1r * (x * (y * u + z * t)) * (s * t * (s * u))
prf (x * y * (s * u) + x * z * (s * t)) * (s * (t * u))
β‘ 1r * = cring! R
prf in quot (inc 1r has-1 prf)
Finally, these fit together to make a commutative ring.
private
module mr = make-ring
open make-ring
: make-ring Fr.quotient
mk-loc .ring-is-set = hlevel 2
mk-loc .0R = 0β
mk-loc ._+_ = _+β_
mk-loc .-_ = -β_
mk-loc .1R = 1β
mk-loc ._*_ = _*β_
mk-loc .+-idl = +β-idl
mk-loc .+-invr = +β-invr
mk-loc .+-assoc = +β-assoc
mk-loc .+-comm = +β-comm
mk-loc .*-idl = *β-idl
mk-loc .*-idr x = *β-comm x 1β β *β-idl x
mk-loc .*-assoc = *β-assoc
mk-loc .*-distribl = *β-distribl
mk-loc .*-distribr x y z =
mk-loc (y +β z) x β *β-distribl x y z β apβ _+β_ (*β-comm x y) (*β-comm x z)
*β-comm
: CRing β
Sβ»ΒΉR .fst = el! Fr.quotient
Sβ»ΒΉR .snd .CRing-on.has-ring-on = to-ring-on mk-loc
Sβ»ΒΉR .snd .CRing-on.*-commutes {x} {y} = *β-comm x y Sβ»ΒΉR