Setoid
Martin Escardo, July 2026. Setoids, for the development of free groups in a Spartan MLTT. A setoid is a type equipped with an equivalence relation with values given as data. We collect here the notion of setoid, together with the generic setoid infrastructure that is not specific to groups.{-# OPTIONS --safe --without-K #-} module EGroups.Setoid where open import MLTT.Spartan is-equivalence-relation : {X : ๐ค ฬ } โ (X โ X โ ๐ฅ ฬ ) โ ๐ค โ ๐ฅ ฬ is-equivalence-relation _โ_ = reflexive _โ_ ร symmetric _โ_ ร transitive _โ_ Setoid : (๐ค ๐ฅ : Universe) โ (๐ค โ ๐ฅ)โบ ฬ Setoid ๐ค ๐ฅ = ฮฃ X ๊ ๐ค ฬ , ฮฃ R ๊ (X โ X โ ๐ฅ ฬ ) , is-equivalence-relation RWe write โฃ S โฃ for the underlying type of a setoid S and x โโฃ S โฃ y for its equivalence relation.โฃ_โฃ : Setoid ๐ค ๐ฅ โ ๐ค ฬ โฃ (X , _โ_ , r , s , t) โฃ = X setoid-relation : (S : Setoid ๐ค ๐ฅ) โ โฃ S โฃ โ โฃ S โฃ โ ๐ฅ ฬ setoid-relation (X , _โ_ , r , s , t) = _โ_ syntax setoid-relation S x y = x โโฃ S โฃ y setoid-refl : (S : Setoid ๐ค ๐ฅ) โ reflexive (setoid-relation S) setoid-refl (X , _โ_ , r , s , t) = r setoid-sym : (S : Setoid ๐ค ๐ฅ) โ symmetric (setoid-relation S) setoid-sym (X , _โ_ , r , s , t) = s setoid-trans : (S : Setoid ๐ค ๐ฅ) โ transitive (setoid-relation S) setoid-trans (X , _โ_ , r , s , t) = tSome general notions here stated with respect to an equivalence relation, rather than the identity type. We use the prefix `is-` for them, unlike their counterparts in Notation.General. In the HoTT/UF setting that prefix indicates property in the sense of being subsingleton-valued. Here property is in the sense of MLTT with setoids, which is just propositions as types, rather than propositions as types with at most one element, and it is in this sense that we use the prefix.is-econgruence : {X : ๐ค ฬ } โ (X โ X โ ๐ฅ ฬ ) โ (X โ X โ X) โ ๐ค โ ๐ฅ ฬ is-econgruence _โ_ _ยท_ = {x x' y y' : _} โ x โ x' โ y โ y' โ (x ยท y) โ (x' ยท y') is-eleft-neutral : {X : ๐ค ฬ } โ (X โ X โ ๐ฅ ฬ ) โ X โ (X โ X โ X) โ ๐ค โ ๐ฅ ฬ is-eleft-neutral _โ_ e _ยท_ = โ x โ (e ยท x) โ x is-eright-neutral : {X : ๐ค ฬ } โ (X โ X โ ๐ฅ ฬ ) โ X โ (X โ X โ X) โ ๐ค โ ๐ฅ ฬ is-eright-neutral _โ_ e _ยท_ = โ x โ (x ยท e) โ x is-eassociative : {X : ๐ค ฬ } โ (X โ X โ ๐ฅ ฬ ) โ (X โ X โ X) โ ๐ค โ ๐ฅ ฬ is-eassociative _โ_ _ยท_ = โ x y z โ ((x ยท y) ยท z) โ (x ยท (y ยท z))We develop equational reasoning up to an equivalence relation, parameterized by reflexivity and transitivity.module โ-reasoning {X : ๐ค ฬ } (_โ_ : X โ X โ ๐ฅ ฬ ) (โr : reflexive _โ_) (โt : transitive _โ_) where infixr 0 _โ[_]_ infix 1 _โโ _โ[_]_ : (x : X) {y z : X} โ x โ y โ y โ z โ x โ z x โ[ p ] q = โt x _ _ p q _โโ : (x : X) โ x โ x x โโ = โr x to-โ : {x y : X} โ x ๏ผ y โ x โ y to-โ {x} refl = โr xA setoid map is a function that respects the equivalence relations.is-setoid-map : (S : Setoid ๐ค ๐ฅ) (T : Setoid ๐ค' ๐ฅ') โ (โฃ S โฃ โ โฃ T โฃ) โ ๐ค โ ๐ฅ โ ๐ฅ' ฬ is-setoid-map S T f = {x y : โฃ S โฃ} โ x โโฃ S โฃ y โ f x โโฃ T โฃ f yA setoid isomorphism is a pair of setoid maps that are mutually inverse up to the equivalence relations.record _โ หข_ (S : Setoid ๐ค ๐ฅ) (T : Setoid ๐ค' ๐ฅ') : ๐ค โ ๐ฅ โ ๐ค' โ ๐ฅ' ฬ where field to : โฃ S โฃ โ โฃ T โฃ from : โฃ T โฃ โ โฃ S โฃ to-resp : is-setoid-map S T to from-resp : is-setoid-map T S from to-from : (y : โฃ T โฃ) โ to (from y) โโฃ T โฃ y from-to : (x : โฃ S โฃ) โ from (to x) โโฃ S โฃ xWe form the function setoid from a type A into a setoid T, whose elements are the functions A โ โฃ T โฃ with the pointwise equivalence relation.function-setoid : (A : ๐ค ฬ ) (T : Setoid ๐ฅ ๐ฆ) โ Setoid (๐ค โ ๐ฅ) (๐ค โ ๐ฆ) function-setoid A T = (A โ โฃ T โฃ) , (ฮป f g โ (a : A) โ f a โโฃ T โฃ g a) , (ฮป f a โ setoid-refl T (f a)) , (ฮป f g p a โ setoid-sym T (f a) (g a) (p a)) , (ฮป f g h p q a โ setoid-trans T (f a) (g a) (h a) (p a) (q a))We form the setoid of setoid maps from S to T, again with the pointwise equivalence relation.setoid-map-setoid : (S : Setoid ๐ค ๐ฅ) (T : Setoid ๐ค' ๐ฅ') โ Setoid (๐ค โ ๐ฅ โ ๐ค' โ ๐ฅ') (๐ค โ ๐ฅ') setoid-map-setoid S T = (ฮฃ f ๊ (โฃ S โฃ โ โฃ T โฃ) , is-setoid-map S T f) , (ฮป u v โ (x : โฃ S โฃ) โ prโ u x โโฃ T โฃ prโ v x) , (ฮป u x โ setoid-refl T (prโ u x)) , (ฮป u v p x โ setoid-sym T (prโ u x) (prโ v x) (p x)) , (ฮป u v w p q x โ setoid-trans T (prโ u x) (prโ v x) (prโ w x) (p x) (q x))