1-- Subrings of a bundled ring: Subring(R, S) under a ring hypothesis, the2-- bridges to the form over separate pieces, the closure instances, the3-- ring on a subring, and its inclusion homomorphism; everything here is ZF4-- Part of Cumulus, the Grace17 mathematics library.5-- Copyright (c) 2026 Grant Passmore.6-- Released under the Apache License 2.0. See LICENSE in the repository root.7-- Authors: Grant Passmore89module Grace.Cumulus.Algebra.Ring.Subring10import SubringCore11import Homomorphism1213-- Under a hypothesis Ring(R), a subring is a subset containing zero and14-- one and closed under negation, addition, and multiplication. IsSubring(A,15-- add, zero, neg, mul, one, S) remains the form over separate pieces,16-- bridged below.17section Definitions18variable (R : Set)19hypothesisring : Ring(R)2021predicate Subring (S : Set) :=22 S ⊆ R ∧ R[0] ∈ S ∧ R[1] ∈ S ∧ (∀ x ∈ S, -x ∈ S) ∧23 (∀ x y ∈ S, x + y ∈ S) ∧ (∀ x y ∈ S, x * y ∈ S)2425end Definitions2627notationinfixl60"+"=> call2(R.add, _, _) viahypothesis Subring(R, S) for S28notationinfixl70"*"=> call2(R.mul, _, _) viahypothesis Subring(R, S) for S29notationprefix75"-"=>apply(R.neg, _) viahypothesis Subring(R, S) for S30notationinfixl60"-"=> Ring.sub(R, _, _) viahypothesis Subring(R, S) for S3132instance Subring.parts (R S : Set)33requires subring : Subring(R, S)34shows IsSubring(R.carrier, R.add, R.zero, R.neg, R.mul, R.one, S)35proof36obtain⟨bounded, zeroIn, oneIn, negatives, sums, products⟩:= subring37unfold IsSubring38refine⟨bounded, zeroIn, oneIn, ?_, ?_, ?_⟩39 . unfold ClosedUnary40exact negatives41 . unfold ClosedBinary42exact sums43 . unfold ClosedBinary44exact products4546theorem Subring.of_projections (R S : Set)47requires subring : IsSubring(R.carrier, R.add, R.zero, R.neg, R.mul, R.one, S)48shows Subring(R, S)49proof50obtain⟨bounded, zeroIn, oneIn, negatives, sums, products⟩:= subring51unfold ClosedUnary at negatives52unfold ClosedBinary at sums53unfold ClosedBinary at products54unfold Subring.Subring55exact⟨bounded, zeroIn, oneIn, negatives, sums, products⟩5657theorem Subring.of_parts (A add zero neg mul one S : Set)58requires subring : IsSubring(A, add, zero, neg, mul, one, S)59shows Subring(Ring.mk(A, add, zero, neg, mul, one), S)60proof61have shifted : IsSubring(Ring.carrier(Ring.mk(A, add, zero, neg, mul, one)),62 Ring.add(Ring.mk(A, add, zero, neg, mul, one)),63 Ring.zero(Ring.mk(A, add, zero, neg, mul, one)),64 Ring.neg(Ring.mk(A, add, zero, neg, mul, one)),65 Ring.mul(Ring.mk(A, add, zero, neg, mul, one)),66 Ring.one(Ring.mk(A, add, zero, neg, mul, one)), S)67 ring_projections68exact Subring.of_projections with shifted6970section SubringLaws71variable (R S : Set)72hypothesis subring : Subring(R, S)7374theorem Subring.subset75shows S ⊆ R.carrier76proof77obtain⟨bounded, rest⟩:= subring78exact bounded7980-- Closure: the carrier membership of an element is a typing rule, and the81-- memberships of the constants and of compound terms are instances.82theorem Subring.mem_carrier (x : S)83shows x ∈ R.carrier84proof85have bounded := Subring.subset with subring86have xIn : x ∈ S byassumption87exact bounded with x, xIn8889instance Subring.zero_mem90shows R[0] ∈ S91proof92obtain⟨bounded, zeroIn, rest⟩:= subring93exact zeroIn9495instance Subring.one_mem96shows R[1] ∈ S97proof98obtain⟨bounded, zeroIn, oneIn, rest⟩:= subring99exact oneIn100101instance Subring.neg_mem (x : S)102shows -x ∈ S103proof104obtain⟨bounded, zeroIn, oneIn, negatives, sums, products⟩:= subring105have xIn : x ∈ S byassumption106exact negatives with x, xIn107108instance Subring.add_mem (x y : S)109shows x + y ∈ S110proof111obtain⟨bounded, zeroIn, oneIn, negatives, sums, products⟩:= subring112have xIn : x ∈ S byassumption113have yIn : y ∈ S byassumption114exact sums with x, xIn, y, yIn115116instance Subring.mul_mem (x y : S)117shows x * y ∈ S118proof119obtain⟨bounded, zeroIn, oneIn, negatives, sums, products⟩:= subring120have xIn : x ∈ S byassumption121have yIn : y ∈ S byassumption122exact products with x, xIn, y, yIn123124end SubringLaws125126section SubringSubtraction127variable (R S : Set)128hypothesisring : Ring(R)129hypothesis subring : Subring(R, S)130131instance Subring.sub_mem (x y : S)132shows x - y ∈ S133proof134have xIn : x ∈ R := Subring.mem_carrier with*135have yIn : y ∈ R := Subring.mem_carrier with*136have negIn : -y ∈ S := Subring.neg_mem with*137rw Ring.sub.value138exact Subring.add_mem with*139140end SubringSubtraction141142section SubringConstructions143variable (R : Set)144hypothesisring : Ring(R)145146-- The constructor, and the whole ring as a subring of itself.147theorem Subring.mk (S : Set)148requires bounded : S ⊆ R149requires zeroIn : R[0] ∈ S150requires oneIn : R[1] ∈ S151requires negatives : ∀ x ∈ S, -x ∈ S152requires sums : ∀ x y ∈ S, x + y ∈ S153requires products : ∀ x y ∈ S, x * y ∈ S154shows Subring(R, S)155proof156unfold Subring.Subring157exact⟨bounded, zeroIn, oneIn, negatives, sums, products⟩158159theorem Subring.whole160shows Subring(R, R.carrier)161proof162have reflexive := Subset.reflexive at R.carrier163have zeroIn : R[0] ∈ R := Ring.zero_mem with*164have oneIn : R[1] ∈ R := Ring.one_mem with*165apply Subring.mk withring, reflexive, zeroIn, oneIn166 . intros x hx167exact Ring.neg_mem with*168 . intros x hx y hy169exact Ring.add_mem with*170 . intros x hx y hy171exact Ring.mul_mem with*172173end SubringConstructions174175-- The ring on a subring: the operations of R restricted to S, with the176-- same zero and one.177def subringRing (R S : Set) : Set:=178 Ring.mk(S, restrict(R.add, S × S), R.zero, restrict(R.neg, S),179 restrict(R.mul, S × S), R.one)180181theorem subringRing.carrierOf (R S : Set)182shows Ring.carrier(subringRing(R, S)) = S183proof184simp [subringRing, Ring.mk.carrier]185186section SubringRings187variable (R S : Set)188hypothesis comm : CommRing(R)189hypothesis subring : Subring(R, S)190191theorem subringRing.comm_ring192shows CommRing(subringRing(R, S))193proof194have parts := CommRing.parts with comm195have subParts := Subring.parts with subring196have engine := IsSubring.comm_ring with parts, subParts197unfold subringRing198exact CommRing.of_parts with engine199200-- The inclusion is an injective homomorphism.201theorem Subring.inclusion202shows identity(S) : subringRing(R, S) →+* R203proof204have parts := CommRing.parts with comm205have subParts := Subring.parts with subring206have engine := IsSubring.inclusion_hom with parts, subParts207have smaller := subringRing.comm_ring with comm, subring208have shifted : IsRingHom(identity(S), Ring.carrier(subringRing(R, S)),209 Ring.add(subringRing(R, S)), Ring.zero(subringRing(R, S)),210 Ring.neg(subringRing(R, S)), Ring.mul(subringRing(R, S)),211 Ring.one(subringRing(R, S)), R.carrier, R.add, R.zero, R.neg, R.mul,212 R.one)213unfold subringRing214 ring_projections215exact RingHom.of_projections with (CommRing.to_ring with smaller),216 (CommRing.to_ring with comm), shifted217218end SubringRings219