Ian Ray. 4th November 2025.

Minor changes and merged into TypeToplogy in July 2026.

We provide some examples of using (displayed) univalent reflexive graphs and
reflexive graph lenses to characterize certain identity types, characterize
transport, and observe the relationship between the reflexive graph approach
to the structured identity principled (SIP) and the existing approaches
available in the TypeTopology library.

\begin{code}

{-# OPTIONS --safe --without-K #-}

module ReflexiveGraphs.Examples where

open import MLTT.Spartan
open import UF.Base
open import UF.Equiv
open import UF.EquivalenceExamples
open import UF.FunExt
open import UF.FundamentalLemmaOfTransportAlongEquivalences
open import UF.Pullback
open import UF.Sets
open import UF.Sets-Properties
open import UF.SIP
open import UF.Subsingletons
open import UF.Subsingletons-FunExt
open import UF.Subsingletons-Properties
open import UF.Univalence
open import ReflexiveGraphs.Constructions
open import ReflexiveGraphs.Displayed
open import ReflexiveGraphs.DisplayedUnivalent
open import ReflexiveGraphs.Lenses
open import ReflexiveGraphs.Properties
open import ReflexiveGraphs.Type
open import ReflexiveGraphs.UnbiasedLenses
open import ReflexiveGraphs.Univalent
open import ReflexiveGraphs.UnivalentClosureProperties
open import ReflexiveGraphs.UnivalentFamilies

\end{code}

We can recover the standard characterization of the identity type of products
using the discrete reflexive graph construction.

\begin{code}

product-characterization-from-univalent-refl-graphs
 : (A : 𝓀 Μ‡) (B : π“₯ Μ‡) (a a' : A) (b b' : B)
 β†’ ((a , b) = (a' , b')) ≃ (a = a') Γ— (b = b')
product-characterization-from-univalent-refl-graphs A B a a' b b'
 = id-equiv-edge ((Ξ” A) βŠ— (Ξ” B) , I) (a , b) (a' , b')
 where
  I : is-univalent-refl-graph ((Ξ” A) βŠ— (Ξ” B))
  I = univalence-closed-under-Γ— (Ξ” A) (Ξ” B)
       (discrete-refl-graph-is-univalent A) (discrete-refl-graph-is-univalent B)

\end{code}

Similarly for Sigma types.

\begin{code}

sigma-characterization-from-univalent-refl-graphs
 : (A : 𝓀 Μ‡) (B : A β†’ π“₯ Μ‡) (a a' : A) (b : B a) (b' : B a')
 β†’ ((a , b) = (a' , b')) ≃ (Ξ£ p κž‰ (a = a') , transport B p b = b')
sigma-characterization-from-univalent-refl-graphs A B a a' b b'
 = id-equiv-edge ((∐ a ΛΈ A , (Ξ” (B a))) , I) (a , b) (a' , b')
 where
  I : is-univalent-refl-graph (∐ a ΛΈ A , (Ξ” (B a)))
  I = univalence-closed-under-Ξ£ A (Ξ» a β†’ Ξ” (B a))
       (Ξ» a β†’ discrete-refl-graph-is-univalent (B a))

\end{code}

This is simply a sanity check for the theory we have developed. We now move
towards a more unified approach to the SIP, by working through some
illustrative examples.

Example 1:

We give a detailed characterization of the identity type of cones over a
cospan using reflexive graphs. This illustration is not intended to be brief.

Two cones with commutative graphs witnessed by 

               q                                  q'
        A ─────────→ X                      A ─────────→ X       
        β”‚            β”‚                      β”‚            β”‚
  H : p β”‚            β”‚ g            H' : p' β”‚            β”‚ g
        β”‚            β”‚                      β”‚            β”‚
        ↓            ↓                      ↓            ↓
        Y ─────────→ Z                      Y ─────────→ Z
                f                                 f

are the same when we have homotopies α : p ∼ p' and β : q ∼ q' and a natural
coherence

                           H
                 f ∘ p  ───────→ g ∘ q
                   |               |
               Ξ±*  |               |  Ξ²*
                   |               |
                   ↓               ↓
                 f ∘ p' ───────→ g ∘ q'
                           H'
between the homotopies.

\begin{code}

module _ (fe : Fun-Ext) {X : 𝓀 Μ‡ } {Y : π“₯ Μ‡ } {Z : 𝓦 Μ‡ }
         (f : X β†’ Z) (g : Y β†’ Z) (A : 𝓣 Μ‡)
       where

 open pullback f g

\end{code}

We define reflexive graph structure on the base of a cone whose underlying type
must be (A β†’ X) Γ— (A β†’ Y) with edges corresponding to the pair of homotopies
p ∼ p' and q ∼ q'.

\begin{code}

 cone-base-refl-graph : Refl-Graph (𝓀 βŠ” π“₯ βŠ” 𝓣) (𝓀 βŠ” π“₯ βŠ” 𝓣)
 cone-base-refl-graph 
  = (((A β†’ X) Γ— (A β†’ Y)) , I , II)
  where
   I : ((A β†’ X) Γ— (A β†’ Y))
     β†’ ((A β†’ X) Γ— (A β†’ Y))
     β†’ 𝓀 βŠ” π“₯ βŠ” 𝓣 Μ‡
   I (p , q) (p' , q') = (p ∼ p') Γ— (q ∼ q')
   II : ((p , q) : (A β†’ X) Γ— (A β†’ Y)) β†’ (p ∼ p) Γ— (q ∼ q) 
   II (p , q) = (∼-refl , ∼-refl)

\end{code}

That this reflexive graph is univalent is automatic as univalence is closed
under products, functions and the discrete reflexive graph.

\begin{code}
     
 cone-base-is-univalent : is-univalent-refl-graph cone-base-refl-graph
 cone-base-is-univalent = univalence-closed-under-Γ—
                           (A βž™ (Ξ” X)) (A βž™ (Ξ” Y))
                           (univalence-closed-under-cotensor fe A (Ξ” X)
                            (discrete-refl-graph-is-univalent X))
                           (univalence-closed-under-cotensor fe A (Ξ” Y)
                            (discrete-refl-graph-is-univalent Y))

\end{code}

We now give the structure of a displayed reflexive graph over the base
whose type family takes pairs of maps and returns commutative squares. The
edges correspond to the natural coherence condition mentioned above.

\begin{code}
                              
 cone-displayed-refl-graph
  : Displayed-Refl-Graph (𝓦 βŠ” 𝓣) (𝓦 βŠ” 𝓣) cone-base-refl-graph
 cone-displayed-refl-graph
  = (commutative-square , I , II)
  where
   I : {(p , q) (p' , q') : (A β†’ X) Γ— (A β†’ Y)}
       ((Ξ± , Ξ²) : (p ∼ p') Γ— (q ∼ q'))
     β†’ commutative-square (p , q)
     β†’ commutative-square (p' , q')
     β†’ 𝓦 βŠ” 𝓣 Μ‡
   I (α , β) H H' = ∼-trans H (∼-ap-∘ g β) ∼ ∼-trans (∼-ap-∘ f α) H'
   II : {(p , q) : (A β†’ X) Γ— (A β†’ Y)}
        (H : commutative-square (p , q))
      β†’ ∼-trans H ∼-refl ∼ ∼-trans ∼-refl H
   II H x = refl-left-neutral ⁻¹

\end{code}

To see that the displayed reflexive graph is univalent we only have to look
at the fibers. The luxury here is that the base edges are taken to be the
reflexive data. The fan of interest is equivalent to a fan over what is
essentially the discrete reflexive graph of f ∘ p ∼ g ∘ q (which is manifestly
univalent).

\begin{code}

 cone-display-is-univalent
  : is-displayed-univalent-refl-graph
     cone-base-refl-graph cone-displayed-refl-graph 
 cone-display-is-univalent (p , q) H
  = equiv-to-prop I
     (univalence-closed-under-Ξ  fe A (Ξ» - β†’ Ξ” (f (p -) = g (q -)))
      (Ξ» - β†’ discrete-refl-graph-is-univalent (f (p -) = g (q -))) H)
  where
   I : fan ([ cone-displayed-refl-graph ] (p , q)) H
     ≃ fan (∏ x ΛΈ A , (Ξ” (f (p x) = g (q x)))) H
   I = (Ξ£ H' κž‰ commutative-square (p , q) ,
        ∼-trans H ∼-refl ∼ ∼-trans ∼-refl H')              β‰ƒβŸ¨ II ⟩
       (Ξ£ H' κž‰ commutative-square (p , q) , H ∼ H')        β– 
    where
     II = Ξ£-cong (Ξ» - β†’ transport-≃ (Ξ» - β†’ H ∼ -)
           (dfunext fe (Ξ» x β†’ refl-left-neutral)))

\end{code}

The hard work is done. Since we have a displayed univalent reflexive graph
over a univalent reflexive graph the total reflexive graph is also univalent.
The carrier of this total reflexive graph corresponds to the type of cones.

\begin{code}

 cone-total-refl-graph : Refl-Graph (𝓀 βŠ” π“₯ βŠ” 𝓦 βŠ” 𝓣) (𝓀 βŠ” π“₯ βŠ” 𝓦 βŠ” 𝓣)
 cone-total-refl-graph = (cone-base-refl-graph ﹐ cone-displayed-refl-graph)

 private
  observation₁ : ⟨ cone-total-refl-graph ⟩ = cone A
  observation₁ = refl

 cone-total-is-univalent : is-univalent-refl-graph cone-total-refl-graph 
 cone-total-is-univalent
  = univalence-closed-under-total cone-base-refl-graph cone-displayed-refl-graph
     cone-base-is-univalent cone-display-is-univalent 

 cone-=-characterization
  : (p p' : A β†’ X) (q q' : A β†’ Y)
    (H : f ∘ p ∼ g ∘ q) (H' : f ∘ p' ∼ g ∘ q')
  β†’ (((p , q) , H) = ((p' , q') , H'))
  ≃ (Ξ£ (Ξ± , Ξ²) κž‰ (p ∼ p') Γ— (q ∼ q') ,
     ∼-trans H (∼-ap-∘ g β) ∼ ∼-trans (∼-ap-∘ f α) H')
 cone-=-characterization p p' q q' H H'
  = id-equiv-edge (cone-total-refl-graph , cone-total-is-univalent)
     ((p , q) , H) ((p' , q') , H')

\end{code}

Example 2:

We now use lenses to generalize an existing characterization of transport (see
file UF.FundamentalLemmaOfTransportAlongEquivalences). We start by defining
transport along an edge.

\begin{code}

module _ (𝓐 : Refl-Graph 𝓀 π“₯)
         (ua-𝓐 : is-univalent-refl-graph 𝓐)
         (P : ⟨ 𝓐 ⟩ β†’ 𝓣 Μ‡)
       where

 transport-along-β‰ˆ : {x y : ⟨ 𝓐 ⟩}
                   β†’ x β‰ˆβŸ¨ 𝓐 ⟩ y
                   β†’ P x β†’ P y
 transport-along-β‰ˆ e = transport P (edge-to-id (𝓐 , ua-𝓐) e)

 transport-along-β‰ˆ-comp : {x : ⟨ 𝓐 ⟩}
                        β†’ (u : P x)
                        β†’ transport-along-β‰ˆ (β‰ˆ-refl 𝓐 x) u = u
 transport-along-β‰ˆ-comp u
  = transport (Ξ» - β†’ transport P - u = u)
     (edge-to-id-preserves-refl (𝓐 , ua-𝓐) ⁻¹) refl

\end{code}

We now show that if a univalent reflexive graph has an oplax covariant lens
structure on it then push and transport share an edge.

\begin{code}

module _ {𝓀' π“₯' : Universe}
         (𝓐 : Refl-Graph 𝓀 π“₯) (ua-𝓐 : is-univalent-refl-graph 𝓐)
         (𝓛@(𝓑 , s) : Oplax-Covariant-Lens 𝓀' π“₯' 𝓐)
       where

 open oplax-covariant-lens-structure s

 fundamental-theorem-of-transport-for-edges
  : {x y : ⟨ 𝓐 ⟩}
  β†’ (e : x β‰ˆβŸ¨ 𝓐 ⟩ y)
  β†’ (u : ⟨ 𝓑 x ⟩)
  β†’ push e u β‰ˆβŸ¨ 𝓑 y ⟩ transport-along-β‰ˆ 𝓐 ua-𝓐 (lens-push-fam 𝓛) e u
 fundamental-theorem-of-transport-for-edges {x} {y} = I II IV x y
  where
   I : edge-induction 𝓐
   I = univalence-implies-edge-induction 𝓐 ua-𝓐
   II : (x y : ⟨ 𝓐 ⟩) β†’ x β‰ˆβŸ¨ 𝓐 ⟩ y β†’ 𝓀' βŠ” π“₯' Μ‡
   II x y e = (u : ⟨ 𝓑 x ⟩)
            β†’ push e u β‰ˆβŸ¨ 𝓑 y ⟩ transport-along-β‰ˆ 𝓐 ua-𝓐 (lens-push-fam 𝓛) e u
   III : (x : ⟨ 𝓐 ⟩) (u : ⟨ 𝓑 x ⟩)
       β†’ u = transport-along-β‰ˆ 𝓐 ua-𝓐 (lens-push-fam 𝓛) (β‰ˆ-refl 𝓐 x) u
   III x u = transport-along-β‰ˆ-comp 𝓐 ua-𝓐 (lens-push-fam 𝓛) u ⁻¹
   IV : (x : ⟨ 𝓐 ⟩) (u : ⟨ 𝓑 x ⟩)
      β†’ push (β‰ˆ-refl 𝓐 x) u
      β‰ˆβŸ¨ 𝓑 x ⟩ transport-along-β‰ˆ 𝓐 ua-𝓐 (lens-push-fam 𝓛) (β‰ˆ-refl 𝓐 x) u
   IV x u = transport (Ξ» - β†’ push (β‰ˆ-refl 𝓐 x) u β‰ˆβŸ¨ 𝓑 x ⟩ -) (III x u)
             (push-refl u)

\end{code}

If the oplax lens is itself univalent then we can upgrade the edge to an
identity.

\begin{code}

module _ {𝓀' π“₯' : Universe}
         (𝓐 : Refl-Graph 𝓀 π“₯) (ua-𝓐 : is-univalent-refl-graph 𝓐)
         (𝓛@(𝓑 , s) : Oplax-Covariant-Lens 𝓀' π“₯' 𝓐)
         (ua-𝓛 : oplax-covariant-lens-is-univalent 𝓐 𝓛)
       where

 open oplax-covariant-lens-structure s

 fundamental-theorem-of-transport
  : {x y : ⟨ 𝓐 ⟩}
  β†’ (e : x β‰ˆβŸ¨ 𝓐 ⟩ y)
  β†’ push e ∼ transport-along-β‰ˆ 𝓐 ua-𝓐 (lens-push-fam 𝓛) e
 fundamental-theorem-of-transport {x} {y} e u
  = edge-to-id (𝓑 y , ua-𝓛 y)
     (fundamental-theorem-of-transport-for-edges 𝓐 ua-𝓐 𝓛 e u)

\end{code}

It is worth noting that this result follows immediately from the fact that
oplax structure is in fact a property, but this avenue requires function
extensionality.

\begin{code}

 private
  transport-along-β‰ˆ-is-oplax-structure
   : oplax-covariant-lens-structure 𝓀' π“₯' 𝓐 𝓑
  transport-along-β‰ˆ-is-oplax-structure
   = record {push = I ; push-refl = II}
   where
    I : {x y : ⟨ 𝓐 ⟩} β†’ (x β‰ˆβŸ¨ 𝓐 ⟩ y) β†’ ⟨ 𝓑 x ⟩ β†’ ⟨ 𝓑 y ⟩
    I {x} {y} = transport-along-β‰ˆ 𝓐 ua-𝓐 (lens-push-fam 𝓛)
    II : {x : ⟨ 𝓐 ⟩} (u : ⟨ 𝓑 x ⟩)
       β†’ (I (β‰ˆ-refl 𝓐 x) u) β‰ˆβŸ¨ 𝓑 x ⟩ u
    II {x} u = id-to-edge (𝓑 x)
                (transport-along-β‰ˆ-comp 𝓐 ua-𝓐 (lens-push-fam 𝓛) u)

  oplax-=-transport-structure
   : Fun-Ext
   β†’ s = transport-along-β‰ˆ-is-oplax-structure
  oplax-=-transport-structure fe
   = oplax-lens-structure-is-a-property fe 𝓀' π“₯' 𝓐 𝓑 ua-𝓐 ua-𝓛
      s transport-along-β‰ˆ-is-oplax-structure

  unique-transport-observation
   : Fun-Ext
   β†’ {x y : ⟨ 𝓐 ⟩}
   β†’ (e : x β‰ˆβŸ¨ 𝓐 ⟩ y)
   β†’ push e ∼ transport-along-β‰ˆ 𝓐 ua-𝓐 (lens-push-fam 𝓛) e
  unique-transport-observation fe e u
   = ap (Ξ» - β†’ lens-push (𝓑 , -) e u) (oplax-=-transport-structure fe)

\end{code}

Using the fundamental theorem derived above on the reflexive graph associated
to a univalent universe we can recover the lemma that is stated in the file
UF.FundamentalLemmaOfTransportAlongEquivalences. 

\begin{code}

transport-along-≃-fundamental-lemma'
 : {𝓀 π“₯ : Universe}
   (S : 𝓀 Μ‡ β†’ π“₯ Μ‡ )
   (T : {X Y : 𝓀 Μ‡ } β†’ X ≃ Y β†’ S X β†’ S Y)
   (T-refl : {X : 𝓀 Μ‡ } β†’ T (≃-refl X) ∼ id)
   {X Y : 𝓀 Μ‡ }
   (𝕗 : X ≃ Y)
   (ua : is-univalent 𝓀)
 β†’ T 𝕗 ∼ transport-along-≃ ua S 𝕗
transport-along-≃-fundamental-lemma' {𝓀} {π“₯} S T T-refl {X} {Y} 𝕗 ua s
 = III s βˆ™ IV s ⁻¹
 where
  I = universe-refl-graph 𝓀
  II = univalent-universe-is-univalent-family 𝓀 ua
  III : T 𝕗 ∼ transport-along-β‰ˆ I II S 𝕗
  III = fundamental-theorem-of-transport I II
         ((Ξ» - β†’ Ξ” (S -)) , record {push = T ; push-refl = T-refl})
         (Ξ» - β†’ discrete-refl-graph-is-univalent (S -)) 𝕗
  IV : transport-along-≃ ua S 𝕗 ∼ transport-along-β‰ˆ I II S 𝕗
  IV = fundamental-theorem-of-transport I II
        ((Ξ» - β†’ Ξ” (S -)) , record {push = transport-along-≃ ua S
                                  ; push-refl = Ξ» {x} u
                                              β†’ ap (Ξ» r β†’ transport S r u)
                                                   (eqtoid-refl ua x)})
        (Ξ» - β†’ discrete-refl-graph-is-univalent (S -)) 𝕗

\end{code}

Example 3:

We record the logical equivalence between displayed univalent reflexive graphs
over the reflexive graph on a univalent universe and the standard notion of
structure (SNS) (see UF.SIP) already present in the TypeTopology library.

\begin{code}

module _ {𝓀 𝓣 𝓦 : Universe} (fe : Fun-Ext) where

 open sip hiding (⟨_⟩)

 displayed-univalent-refl-graph-to-SNS
  : (((B , _ , _) , _) : Displayed-Univalent-Refl-Graph 𝓣 𝓦
                          (universe-refl-graph 𝓀))
  β†’ SNS B 𝓦
 displayed-univalent-refl-graph-to-SNS (𝓑@(B , R , r) , ua)
  = (I , II , III)
  where
   I : ((X , _) (Y , _) : Ξ£ B) β†’ X ≃ Y β†’ 𝓦 Μ‡
   I X Y e = structure X β‰ˆβŸ¨ 𝓑 βΈ΄ e ⟩ structure Y
   II : ((X , _) : Ξ£ B) β†’ I (X , _) (X , _) (≃-refl X)
   II X = r (structure X)
   obs : {X : 𝓀 Μ‡} (s t : B X)
       β†’ id-to-edge ([ 𝓑 ] X) {s} {t} = canonical-map I II s t
   obs {X} s t = dfunext fe obs'
    where
     obs' : id-to-edge ([ (B , R , r) ] X) ∼ canonical-map I II s t
     obs' refl = refl
   III : {X : 𝓀 Μ‡} (s t : B X)
       β†’ is-equiv (canonical-map I II s t)
   III {X} s t = transport is-equiv (obs s t)
                  (prop-fans-implies-id-to-edge-equiv ([ 𝓑 ] X) (ua X) s t)

 SNS-to-displayed-univalent-refl-graph
  : (B : 𝓀 Μ‡ β†’ 𝓣 Μ‡)
  β†’ SNS B 𝓦 
  β†’ Displayed-Univalent-Refl-Graph 𝓣 𝓦 (universe-refl-graph 𝓀)
 SNS-to-displayed-univalent-refl-graph B (ι , ρ , θ)
  = ((B , I , II) , III)
  where
   I : {X Y : ⟨ universe-refl-graph 𝓀 ⟩} β†’ X ≃ Y β†’ B X β†’ B Y β†’ 𝓦 Μ‡
   I {X} {Y} e s t = ΞΉ (X , s) (Y , t) e
   II : {X : ⟨ universe-refl-graph 𝓀 ⟩} (u : B X)
      β†’ ΞΉ (X , u) (X , u) (β‰ˆ-refl (universe-refl-graph 𝓀) X)
   II {X} u = ρ (X , u)
   obs : {X : 𝓀 Μ‡} (s t : B X)
       β†’ canonical-map ΞΉ ρ s t = id-to-edge ([ (B , I , II) ] X)
   obs {X} s t = dfunext fe obs'
    where
     obs' : canonical-map ι ρ s t ∼ id-to-edge ([ (B , I , II) ] X)
     obs' refl = refl
   III : is-displayed-univalent-refl-graph (universe-refl-graph 𝓀) (B , I , II)
   III X u = id-to-edge-equiv-implies-prop-fans ([ (B , I , II) ] X)
              (Ξ» s t β†’ transport is-equiv (obs s t) (ΞΈ s t)) u

\end{code}

TODO: Characterize the identity type of displayed refl graphs and finish the
proof of equivalence stated below.

 displayed-univalent-refl-graph-≃-SNS
  : (displayed-univalent-refl-graph 𝓣 𝓦 (universe-refl-graph 𝓀))
  ≃ (Ξ£ B κž‰ (𝓀 Μ‡ β†’ 𝓣 Μ‡) , SNS B 𝓦)
 displayed-univalent-refl-graph-≃-SNS fe
  = (I , qinvs-are-equivs I (II , III , IV))
  where
   I : (displayed-univalent-refl-graph 𝓣 𝓦 (universe-refl-graph 𝓀))
     β†’ (Ξ£ B κž‰ (𝓀 Μ‡ β†’ 𝓣 Μ‡) , SNS B 𝓦)
   I (𝓑@((B , _ , _) , _)) = (B , displayed-univalent-refl-graph-to-SNS fe 𝓑)
   II : (Ξ£ B κž‰ (𝓀 Μ‡ β†’ 𝓣 Μ‡) , SNS B 𝓦)
      β†’ (displayed-univalent-refl-graph 𝓣 𝓦 (universe-refl-graph 𝓀))
   II (B , sns) = SNS-to-displayed-univalent-refl-graph fe B sns
   III : II ∘ I ∼ id
   III ((B , R , r) , ua) = ?
   IV : I ∘ II ∼ id
   IV (B , (ι , ρ , θ)) = ?

Example 4:

We now compare two characterizations of the identity type of ∞-magmas. The
former characterization directly via displayed reflexive graphs and the latter
via unbiased lenses. 

\begin{code}

∞-Magma : (𝓀 : Universe) β†’ (𝓀 ⁺) Μ‡
∞-Magma 𝓀 = Ξ£ X κž‰ 𝓀 Μ‡ , (X β†’ X β†’ X)

\end{code}

We now define a displayed reflexive graph over 𝓀 of binary operations.

\begin{code}

module _ (𝓀 : Universe) (ua : is-univalent 𝓀) (fe : Fun-Ext) where

 bin-op-displayed-refl-graph : Displayed-Refl-Graph 𝓀 𝓀 (universe-refl-graph 𝓀)
 bin-op-displayed-refl-graph
  = ((Ξ» X β†’ (X β†’ X β†’ X)) , I , II)
  where
   I : {X Y : 𝓀 Μ‡}
     β†’ (X ≃ Y)
     β†’ (X β†’ X β†’ X)
     β†’ (Y β†’ Y β†’ Y)
     β†’ 𝓀 Μ‡
   I {X} {_} e _Β·X_ _Β·Y_ = (x y : X) β†’ ⌜ e ⌝ (x Β·X y) = (⌜ e ⌝ x Β·Y ⌜ e ⌝ y)
   II : {X : 𝓀 Μ‡}
      β†’ (_Β·X_ : X β†’ X β†’ X)
      β†’ (x y : X)
      β†’ (x Β·X y) = (x Β·X y)
   II _Β·X_ x y = refl

 bin-op-disp-is-univalent
  : is-displayed-univalent-refl-graph (universe-refl-graph 𝓀)
     (bin-op-displayed-refl-graph)
 bin-op-disp-is-univalent X _Β·X_
  = equiv-to-prop I
     (Ξ -is-prop fe (Ξ» x β†’ Ξ -is-prop fe Ξ» y
       β†’ singletons-are-props (singleton-types-are-singletons (x Β·X y))))
  where
   I : fan ([ bin-op-displayed-refl-graph ] X) _Β·X_
     ≃ ((x y : X) β†’ Ξ£ z κž‰ X , x Β·X y = z)
   I = (Ξ£ _Β·X'_ κž‰ (X β†’ X β†’ X) , ((x y : X) β†’ x Β·X y = x Β·X' y)) β‰ƒβŸ¨ II ⟩
       ((x y : X) β†’ Ξ£ z κž‰ X , x Β·X y = z)                       β– 
    where
     II = ≃-sym (≃-comp (Ξ -cong fe fe (Ξ» x β†’ Ξ Ξ£-distr-≃)) Ξ Ξ£-distr-≃)

\end{code}

Now we can give the total univalent reflexive graph whose carrier is the type
of ∞-magmas and then characterize the type of identifications of them.

\begin{code}

 ∞-Magma-total-refl-graph : Refl-Graph (𝓀 ⁺) 𝓀
 ∞-Magma-total-refl-graph
  = (universe-refl-graph 𝓀 ﹐ bin-op-displayed-refl-graph)

 private
  observationβ‚‚ : ⟨ ∞-Magma-total-refl-graph ⟩ = ∞-Magma 𝓀
  observationβ‚‚ = refl

 ∞-Magma-total-univalent-refl-graph
  : is-univalent-refl-graph (∞-Magma-total-refl-graph)
 ∞-Magma-total-univalent-refl-graph 
  = univalence-closed-under-total
     (universe-refl-graph 𝓀)
     (bin-op-displayed-refl-graph)
     (univalent-universe-is-univalent-family 𝓀 ua)
     (bin-op-disp-is-univalent)

 ∞-Magma-=-char
  : ((X , _Β·X_) (Y , _Β·Y_) : ∞-Magma 𝓀) 
  β†’ ((X , _Β·X_) = (Y , _Β·Y_))
   ≃ (Ξ£ e κž‰ X ≃ Y , ((x y : X) β†’ ⌜ e ⌝ (x Β·X y) = (⌜ e ⌝ x Β·Y ⌜ e ⌝ y)))
 ∞-Magma-=-char (X , _·X_) (Y , _·Y_)
  = id-equiv-edge
     (∞-Magma-total-refl-graph , ∞-Magma-total-univalent-refl-graph)
      (X , _Β·X_) (Y , _Β·Y_)

\end{code}

We may instead utilize the unbiased lense machinery, which allows us to
characterize structures that have 'mixed variance'.

\begin{code}

module _ (𝓀 : Universe) (ua : is-univalent 𝓀) (fe : Fun-Ext) where

 ∞-Magma-unbiased-lens : Unbiased-Lens 𝓀 𝓀 (universe-refl-graph 𝓀)
 ∞-Magma-unbiased-lens =
  (I , record
        { lext = Ξ» e u β†’ Ξ» x x' β†’ ⌜ e ⌝ (u x x')
        ; rext = Ξ» e u β†’ Ξ» x x' β†’ u (⌜ e ⌝ x) (⌜ e ⌝ x')
        ; ext-refl = Ξ» u x x' β†’ refl
        ; rext-refl = Ξ» u x x' β†’ refl })
  where
   I : {x y : ⟨ universe-refl-graph 𝓀 ⟩}
     β†’ x β‰ˆβŸ¨ universe-refl-graph 𝓀 ⟩ y
     β†’ Refl-Graph 𝓀 𝓀
   I {X} {Y} e = X βž™ (X βž™ (Ξ” Y))

 ∞-Magma-unbiased-lens-is-univalent
  : unbiased-lens-is-univalent (universe-refl-graph 𝓀) ∞-Magma-unbiased-lens
 ∞-Magma-unbiased-lens-is-univalent {X} {Y} p
  = univalence-closed-under-cotensor fe X (X βž™ (Ξ” Y))
     (univalence-closed-under-cotensor fe X (Ξ” Y)
      (discrete-refl-graph-is-univalent Y))

 ∞-Magma-unbiased-lens-display
  : Displayed-Refl-Graph 𝓀 𝓀 (universe-refl-graph 𝓀)
 ∞-Magma-unbiased-lens-display
  = dispΒ± (universe-refl-graph 𝓀) ∞-Magma-unbiased-lens

 ∞-Magma-unbiased-lens-display-univalent
  : is-displayed-univalent-refl-graph (universe-refl-graph 𝓀)
     ∞-Magma-unbiased-lens-display 
 ∞-Magma-unbiased-lens-display-univalent
  = disp-unbiased-lens-univalent (universe-refl-graph 𝓀) ∞-Magma-unbiased-lens
      (Ξ» x β†’ ∞-Magma-unbiased-lens-is-univalent (≃-refl x))

 ∞-Magma-unbiased-lens-total
  : Refl-Graph (𝓀 ⁺) 𝓀
 ∞-Magma-unbiased-lens-total
  = universe-refl-graph 𝓀 ﹐ ∞-Magma-unbiased-lens-display

 private
  observation₃ : ⟨ ∞-Magma-unbiased-lens-total ⟩ = ∞-Magma 𝓀
  observation₃ = refl

 ∞-Magma-unbiased-lens-total-univalent
  : is-univalent-refl-graph ∞-Magma-unbiased-lens-total 
 ∞-Magma-unbiased-lens-total-univalent
  = univalence-closed-under-total
     (universe-refl-graph 𝓀) ∞-Magma-unbiased-lens-display
     (univalent-universe-is-univalent-family 𝓀 ua)
     ∞-Magma-unbiased-lens-display-univalent

 ∞-Magma-unbiased-lens-=-char
  : ((X , _Β·X_) (Y , _Β·Y_) : ∞-Magma 𝓀) 
  β†’ ((X , _Β·X_) = (Y , _Β·Y_))
   ≃ (Ξ£ e κž‰ X ≃ Y , ((x y : X) β†’ ⌜ e ⌝ (x Β·X y) = (⌜ e ⌝ x Β·Y ⌜ e ⌝ y)))
 ∞-Magma-unbiased-lens-=-char (X , _·X_) (Y , _·Y_)
  = id-equiv-edge
     (∞-Magma-unbiased-lens-total , ∞-Magma-unbiased-lens-total-univalent)
     (X , _Β·X_) (Y , _Β·Y_)

\end{code}

Appealing simply to line counting one could not justify the latter approach to
characterizing the identity type of ∞-Magma. But we would like to point out a
few advantages. We get the displayed reflexive graph (and its univalence) for
free just by identifying what we want the left and right hand side of the
equation relating the mixed variance data to be. This offers a blueprint for
characterizing mixed variance structures of increasingly complicated nature
where "guessing" (or maybe it is more apt to say "being clever") is not
feasible.

TODO: Currently we are exploring a number of results of similar flavor to the
one below. When such a file is added we will move the following result and
import that file here.

If we have a univalent lens with underlying propositionally valued family then
the total reflexive graph induced by the lens carries no new edge information.

\begin{code}

univalent-prop-lens-edge-char
 : (𝓐 : Refl-Graph 𝓀 π“₯)
 β†’ (𝓛 : Oplax-Covariant-Lens 𝓣 𝓣' 𝓐)
 β†’ oplax-covariant-lens-is-univalent 𝓐 𝓛
 β†’ ((x : ⟨ 𝓐 ⟩) β†’ is-prop (lens-push-fam 𝓛 x))
 β†’ (x y : ⟨ 𝓐 ⟩) (u : lens-push-fam 𝓛 x) (v : lens-push-fam 𝓛 y)
 β†’ (x , u) β‰ˆβŸ¨ 𝓐 ﹐ disp⁺ 𝓐 𝓛 ⟩ (y , v) ≃ x β‰ˆβŸ¨ 𝓐 ⟩ y
univalent-prop-lens-edge-char 𝓐 𝓛 ua-𝓛 prop-lens x y u v
 = (x , u) β‰ˆβŸ¨ 𝓐 ﹐ disp⁺ 𝓐 𝓛 ⟩ (y , v)                              β‰ƒβŸ¨refl⟩
   (Ξ£ p κž‰ x β‰ˆβŸ¨ 𝓐 ⟩ y , lens-push 𝓛 p u β‰ˆβŸ¨ lens-push-graph 𝓛 y ⟩ v) β‰ƒβŸ¨ I ⟩
   (Ξ£ p κž‰ x β‰ˆβŸ¨ 𝓐 ⟩ y , lens-push 𝓛 p u = v)                       β‰ƒβŸ¨ II ⟩
   x β‰ˆβŸ¨ 𝓐 ⟩ y                                                      β– 
    where
     I = Ξ£-cong (Ξ» - β†’ ≃-sym (id-equiv-edge (lens-push-graph 𝓛 y , ua-𝓛 y)
                               (lens-push 𝓛 - u) v))
     II = pr₁-≃ (x β‰ˆβŸ¨ 𝓐 ⟩ y) (Ξ» - β†’ lens-push 𝓛 - u = v)
           (Ξ» - β†’ pointed-props-are-singletons (prop-lens y (lens-push 𝓛 - u) v)
            (props-are-sets (prop-lens y)))

\end{code}

Example 5:

We use the previous fact to give a characterization of the identity type of
hSets. Although we make no claims that this characterization of hSet identity
is superior, it suggests a methodology for characterizing the identity type of
more complicated structures with propositional lenses.

\begin{code}

module _ (𝓀 : Universe) (ua : is-univalent 𝓀) (fe : Fun-Ext) where

 hSet-lens : Oplax-Covariant-Lens 𝓀 𝓀 (universe-refl-graph 𝓀)
 hSet-lens = (I , II)
  where
   I : 𝓀 Μ‡ β†’ Refl-Graph 𝓀 𝓀
   I X = Ξ” (is-set X)
   II : oplax-covariant-lens-structure 𝓀 𝓀 (universe-refl-graph 𝓀) I
   II = record
        {push = equiv-to-set ∘ ≃-sym
        ; push-refl = Ξ» {X} is-set β†’ being-set-is-prop fe
                       ((equiv-to-set ∘ ≃-sym) (≃-refl X) is-set) is-set}

 hSet-refl-graph : Refl-Graph (𝓀 ⁺) 𝓀
 hSet-refl-graph
  = universe-refl-graph 𝓀 ﹐ disp⁺ (universe-refl-graph 𝓀) hSet-lens

 private
  observationβ‚„ : ⟨ hSet-refl-graph ⟩ = hSet 𝓀
  observationβ‚„ = refl

 hSet-refl-graph-is-univalent : is-univalent-refl-graph hSet-refl-graph
 hSet-refl-graph-is-univalent 
  = univalence-closed-under-total (universe-refl-graph 𝓀)
     (disp⁺ (universe-refl-graph 𝓀) hSet-lens)
     (univalent-universe-is-univalent-family 𝓀 ua)
     (Ξ» X β†’ disp-oplax-covariant-lens-univalent (universe-refl-graph 𝓀)
             hSet-lens (Ξ» - β†’ discrete-refl-graph-is-univalent (is-set -)) X)

 hSet-univalent-refl-graph : Univalent-Refl-Graph (𝓀 ⁺) 𝓀
 hSet-univalent-refl-graph 
  = (hSet-refl-graph , hSet-refl-graph-is-univalent)

 hSet-=-char : (X Y : hSet 𝓀)
              β†’ (X = Y) ≃ (underlying-set X ≃ underlying-set Y)
 hSet-=-char 𝓧@(X , X-is-set) 𝓨@(Y , Y-is-set)
  = (𝓧 = 𝓨)                         β‰ƒβŸ¨ I ⟩
    (𝓧 β‰ˆβŸ¨ hSet-refl-graph ⟩ 𝓨)       β‰ƒβŸ¨ II ⟩
    (X ≃ Y)                          β– 
  where
   I = id-equiv-edge hSet-univalent-refl-graph 𝓧 𝓨
   II = univalent-prop-lens-edge-char (universe-refl-graph 𝓀)
         hSet-lens (Ξ» - β†’ discrete-refl-graph-is-univalent (is-set -))
          (Ξ» _ β†’ being-set-is-prop fe) X Y X-is-set Y-is-set

\end{code}