UnbiasedLenses
Ian Ray. 4th November 2025. Minor changes and merged into TypeToplogy in June 2026.{-# OPTIONS --safe --without-K #-} module ReflexiveGraphs.UnbiasedLenses where open import MLTT.Spartan open import UF.Equiv open import UF.EquivalenceExamples open import ReflexiveGraphs.Displayed open import ReflexiveGraphs.DisplayedUnivalent open import ReflexiveGraphs.Lenses open import ReflexiveGraphs.Type open import ReflexiveGraphs.UnivalentIn this file we generalize the two previous notion of lenses, but before diving into the technical details we attempt to motivate the notion of an unbiased lens (see index for link to Jon Sterling's "Reflexive graph lenses in univalent foundations"). We first note that, not surprisingly, some univalent reflexive graphs of interest do not arise naturally from the existing notion of lenses. For example consider an isomorphism of magmas (M , β) β (N , β') which consist of an equivalence of the underlying types e : M β N that preserves the binary operation, that is: e (x β y) οΌ (e x) β' (e y) for all x, y : M. One could produce the reflexive graph for the type of magmas from the following displayed reflexive graph BinOp(M) :β‘ M Γ M β M β ββ¨ BinOp , e β© β' :β‘ (x y : M) β e (x β y) οΌ (e x) β' (e y) β-disp-refl BinOp β :β‘ Ξ» x y : M . refl {x β y} but notice that this displayed reflexive graph DOES NOT arise from either of the existing notions of lens. We could consider a similar, albeit asymmetric (or biased!), displayed reflexive graph BinOp(M) :β‘ M Γ M β M β ββ¨ BinOp , e β© β' :β‘ (x y : N) β e (eβ»ΒΉ x β eβ»ΒΉ y) οΌ x β' y β-disp-refl BinOp β :β‘ Ξ» x y : M . refl {x β y} which does arise from an oplax contravariant lens. Aesthetically, the latter is lacking but more importantly it is awkward to use. What we need is a notion of lens that allows us to mediate between either side of the edge we are displaying over. Without further delay we now introduce the notion of an unbiased lens. (TODO when the examples file is added we should note that the above magma example is actually formalized.) We define the structure of an unbiased lens using a record and then collect the type of unbiased lenses as a sigma type.record unbiased-lens-structure (π€' π₯' : Universe) (π : Refl-Graph π€ π₯) (π : {x y : β¨ π β©} β (x ββ¨ π β© y) β Refl-Graph π€' π₯') : π€ β π₯ β π€' β π₯' Μ where field lext : {x y : β¨ π β©} (p : x ββ¨ π β© y) β β¨ π (β-refl π x) β© β β¨ π p β© rext : {x y : β¨ π β©} (p : x ββ¨ π β© y) β β¨ π (β-refl π y) β© β β¨ π p β© ext-refl : {x : β¨ π β©} (u : β¨ π (β-refl π x) β©) β lext (β-refl π x) u ββ¨ π (β-refl π x) β© rext (β-refl π x) u rext-refl : {x : β¨ π β©} (u : β¨ π (β-refl π x) β©) β u ββ¨ π (β-refl π x) β© rext (β-refl π x) uAlthough the previous discussion motivating the notion of an unbiased lens may offer the reader with insight into the first three fields one may have a moment's pause at the final field rext-refl. You will see below that it is not necessary for defining a displayed reflexive graph associated to an unbiased lens, but it will be relevant when showing univalence is inherited. The reader may wonder why we only include a reflexivity datum for the rext field. The situation here is similar to that of half-adjoint equivalences where we must exclude one of the coherences in the interest of ensuring that being an equivalence is a property (although it is worth noting that the situation does differ in that the analogous lext-refl is not derivable from rext-refl in general).Unbiased-Lens : (π€' π₯' : Universe) (π : Refl-Graph π€ π₯) β π€ β π₯ β (π€' β π₯')βΊ Μ Unbiased-Lens π€' π₯' π = Ξ£ π κ ({x y : β¨ π β©} β (x ββ¨ π β© y) β Refl-Graph π€' π₯') , unbiased-lens-structure π€' π₯' π π module _ {π€' π₯' : Universe} {π : Refl-Graph π€ π₯} (π@(π , s) : Unbiased-Lens π€' π₯' π) where open unbiased-lens-structure s unbiased-graph : {x y : β¨ π β©} β (x ββ¨ π β© y) β Refl-Graph π€' π₯' unbiased-graph = π unbiased-fam : {x y : β¨ π β©} β (x ββ¨ π β© y) β π€' Μ unbiased-fam p = β¨ unbiased-graph p β© unbiased-lext : {x y : β¨ π β©} (p : x ββ¨ π β© y) β β¨ π (β-refl π x) β© β β¨ π p β© unbiased-lext = lext unbiased-rext : {x y : β¨ π β©} (p : x ββ¨ π β© y) β β¨ π (β-refl π y) β© β β¨ π p β© unbiased-rext = rext unbiased-ext-refl : {x : β¨ π β©} (u : β¨ π (β-refl π x) β©) β lext (β-refl π x) u ββ¨ π (β-refl π x) β© rext (β-refl π x) u unbiased-ext-refl = ext-refl unbiased-rext-refl : {x : β¨ π β©} (u : β¨ π (β-refl π x) β©) β u ββ¨ π (β-refl π x) β© rext (β-refl π x) u unbiased-rext-refl = rext-reflNow we define when a unbiased lens is univalent.module _ {π€' π₯' : Universe} (π : Refl-Graph π€ π₯) where unbiased-lens-is-univalent : Unbiased-Lens π€' π₯' π β π€ β π₯ β π€' β π₯' Μ unbiased-lens-is-univalent π = {x y : β¨ π β©} (p : (x ββ¨ π β© y)) β is-univalent-refl-graph (unbiased-graph π p)Now we define a display of unbiased lenses.display-unbiased-lens : Unbiased-Lens π€' π₯' π β Displayed-Refl-Graph π€' π₯' π display-unbiased-lens π = (I , II , III) where I : β¨ π β© β π€' Μ I x = β¨ unbiased-graph π (β-refl π x) β© II : {x y : β¨ π β©} β (x ββ¨ π β© y) β β¨ unbiased-graph π (β-refl π x) β© β β¨ unbiased-graph π (β-refl π y) β© β π₯' Μ II p u v = unbiased-lext π p u ββ¨ unbiased-graph π p β© unbiased-rext π p v III : {x : β¨ π β©} (u : β¨ unbiased-graph π (β-refl π x) β©) β II (β-refl π x) u u III {x} u = unbiased-ext-refl π u dispΒ± : Unbiased-Lens π€' π₯' π β Displayed-Refl-Graph π€' π₯' π dispΒ± π = display-unbiased-lens π private observationβ : (π : Unbiased-Lens π€' π₯' π) β (x : β¨ π β©) β [ dispΒ± π ] x οΌ (βͺ dispΒ± π β« x , displayed-edge-rel (dispΒ± π) (β-refl π x) , β-disp-refl (dispΒ± π)) observationβ π x = reflWe now look at fans of unbiased lenses.compute-fan-of-unbiased-lens : (π : Unbiased-Lens π€' π₯' π) β ((x : β¨ π β©) β is-univalent-refl-graph (unbiased-graph π (β-refl π x))) β (x : β¨ π β©) β (u : βͺ dispΒ± π β« x) β fan ([ dispΒ± π ] x) u β fan (unbiased-graph π (β-refl π x)) (unbiased-lext π (β-refl π x) u) compute-fan-of-unbiased-lens π@(π , s) fibers-ua x u = III where open unbiased-lens-structure s I : (v : βͺ dispΒ± π β« x) β (rext (β-refl π x) v , rext-refl v) οΌ (v , β-refl (π (β-refl π x)) v) I v = fibers-ua x v (rext (β-refl π x) v , rext-refl v) (v , β-refl (π (β-refl π x)) v) II : (v : βͺ dispΒ± π β« x) β rext (β-refl π x) v οΌ v II v = ap prβ (I v) III : (Ξ£ v κ (βͺ dispΒ± π β« x) , lext (β-refl π x) u ββ¨ π (β-refl π x) β© rext (β-refl π x) v) β (Ξ£ v κ (β¨ π (β-refl π x) β©) , lext (β-refl π x) u ββ¨ π (β-refl π x) β© v) III = Ξ£-cong (Ξ» v β transport-β (Ξ» - β lext (β-refl π x) u ββ¨ π (β-refl π x) β© -) (II v))We now show that if each fiber of a unbiased lens is univalent then the displayed reflexive graph over it is univalent.disp-unbiased-lens-univalent : (π : Unbiased-Lens π€' π₯' π) β ((x : β¨ π β©) β is-univalent-refl-graph (unbiased-graph π (β-refl π x))) β is-displayed-univalent-refl-graph π (dispΒ± π) disp-unbiased-lens-univalent π fibers-ua x u = equiv-to-prop (compute-fan-of-unbiased-lens π fibers-ua x u) (fibers-ua x (unbiased-lext π (β-refl π x) u))We construct an unbiased lens from an oplax covariant lens.oplax-covariant-to-unbiased-lens : Oplax-Covariant-Lens π€' π₯' π β Unbiased-Lens π€' π₯' π oplax-covariant-to-unbiased-lens π@(π , s) = (π' , s') where open oplax-covariant-lens-structure s π' : {x y : β¨ π β©} β (x ββ¨ π β© y) β Refl-Graph π€' π₯' π' {x} {y} p = π y s' : unbiased-lens-structure π€' π₯' π (Ξ» {x} {y} p β π y) s' = record { lext = Ξ» {x} {y} p u β push p u ; rext = Ξ» {x} {y} p u β u ; ext-refl = Ξ» {x} u β push-refl u ; rext-refl = Ξ» {x} u β β-refl (π x) u } unbiasβΊ : Oplax-Covariant-Lens π€' π₯' π β Unbiased-Lens π€' π₯' π unbiasβΊ π = oplax-covariant-to-unbiased-lens πWe open a new module so we can make the carriers in the arguments of the induced displayed reflexive graphs explicit in the following observation.module _ {π€' π₯' : Universe} (π : Refl-Graph π€ π₯) where private observationβ : (π : Oplax-Covariant-Lens π€' π₯' π) β dispβΊ π π οΌ dispΒ± π (unbiasβΊ π π) observationβ π = reflWe now construct an unbiased lens from a lax contravariant lens.lax-contravariant-to-unbiased-lens : Lax-Contravariant-Lens π€' π₯' π β Unbiased-Lens π€' π₯' π lax-contravariant-to-unbiased-lens π@(π , s) = (π' , s') where open lax-contravariant-lens-structure s π' : {x y : β¨ π β©} β (x ββ¨ π β© y) β Refl-Graph π€' π₯' π' {x} {y} p = π x s' : unbiased-lens-structure π€' π₯' π (Ξ» {x} {y} p β π x) s' = record { lext = Ξ» {x} {y} p u β u ; rext = Ξ» {x} {y} p u β pull p u ; ext-refl = Ξ» {x} u β pull-refl u ; rext-refl = Ξ» {x} u β pull-refl u } unbiasβ» : Lax-Contravariant-Lens π€' π₯' π β Unbiased-Lens π€' π₯' π unbiasβ» π = lax-contravariant-to-unbiased-lens π module _ {π€' π₯' : Universe} (π : Refl-Graph π€ π₯) where private observationβ : (π : Lax-Contravariant-Lens π€' π₯' π) β dispβ» π π οΌ dispΒ± π (unbiasβ» π π) observationβ π = refl