Ian Ray. 28th August 2025.

Minor changes and merged into TypeToplogy in March 2026.

We observe some closure properties of univalent reflexive graphs
(see index for references to Sterling, Buchholtz, etc.)

\begin{code}

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

module ReflexiveGraphs.UnivalentClosureProperties where

open import MLTT.Spartan
open import UF.Equiv
open import UF.EquivalenceExamples
open import UF.FunExt
open import UF.PropIndexedPiSigma
open import UF.Powerset-MultiUniverse
open import UF.Subsingletons
open import UF.Subsingletons-FunExt
open import ReflexiveGraphs.Constructions
open import ReflexiveGraphs.Displayed
open import ReflexiveGraphs.DisplayedUnivalent
open import ReflexiveGraphs.Type
open import ReflexiveGraphs.Univalent

\end{code}

Conceptually, showing that a total reflexive graph is univalent when the base
reflexive graph and the displayed reflexive graph over it are both univalent
is easy enough.

Let (x,y) be a term of ⟨ 𝓐 ﹐ 𝓑 ⟩, that is x : ⟨ 𝓐 ⟩ and y : βŸͺ 𝓑 ⟫ x. By the
definition of univalence it suffices to show that any two fans of (x,y) are
equal. If we unpack the definition of a fan of the total reflexive graph 𝓐 ﹐ 𝓑
we get the following data:
terms xβ‚€, x₁ : ⟨ 𝓐 ⟩ with edges pβ‚€ : x β‰ˆβŸ¨ 𝓐 ⟩ xβ‚€ and p₁ : x β‰ˆβŸ¨ 𝓐 ⟩ x₁ and terms
yβ‚€ : βŸͺ 𝓑 ⟫ xβ‚€ and y₁ : βŸͺ 𝓑 ⟫ x₁ with displayed edges qβ‚€ : y β‰ˆβŸ¨ 𝓑 βΈ΄ pβ‚€ ⟩ yβ‚€ and
q₁ : y β‰ˆβŸ¨ 𝓑 βΈ΄ p₁ ⟩ y₁.
So we must show
 ((xβ‚€ , yβ‚€) , (pβ‚€ , qβ‚€)) = ((x₁ , y₁) , (p₁ , q₁)).
As 𝓐 is univalent the edges pβ‚€ and p₁ are contractible and it suffices to show
 ((x , yβ‚€) , (β‰ˆ-refl , qβ‚€)) = ((x , y₁) , (β‰ˆ-refl , q₁)).
Now yβ‚€ and y₁ are in the same fiber βŸͺ 𝓑 ⟫ x so by univalence of 𝓑 the displayed
edges qβ‚€ and q₁ are contractible and it suffices to show
 ((x , y) , (β‰ˆ-refl , β‰ˆ-disp-refl)) = ((x , y) , (β‰ˆ-refl , β‰ˆ-disp-refl))
which holds by refl.

There are two important steps in this proof where we 'contract away' edges
using the univalence assumption, and the latter step depends on the former.
So we will record these steps in two lemmas. Note the essential use of the
file PropIndexedPiSigma.lagda.

\begin{code}

total-component-fans-prop-lemma
 : (𝓐 : Refl-Graph 𝓀 π“₯) (𝓑 : Displayed-Refl-Graph 𝓣 𝓦 𝓐)
 β†’ is-displayed-univalent-refl-graph 𝓐 𝓑
 β†’ (x : ⟨ 𝓐 ⟩) (y : βŸͺ 𝓑 ⟫ x)
 β†’ ((yβ‚€ , qβ‚€) (y₁ , q₁) : fan ([ 𝓑 ] x) y)
 β†’ ((x , yβ‚€) , (β‰ˆ-refl 𝓐 x , qβ‚€)) =[ fan (𝓐 ﹐ 𝓑) (x , y) ]
   ((x , y₁) , (β‰ˆ-refl 𝓐 x , q₁))
total-component-fans-prop-lemma 𝓐 𝓑 ua-𝓑 x y
 = Ξ -proj⁻¹ (y , β‰ˆ-refl ([ 𝓑 ] x) y) (ua-𝓑 x y)
    (Ξ -proj⁻¹ (y , β‰ˆ-refl ([ 𝓑 ] x) y) (ua-𝓑 x y) refl)

total-fans-prop-lemma
 : (𝓐 : Refl-Graph 𝓀 π“₯) (𝓑 : Displayed-Refl-Graph 𝓣 𝓦 𝓐)
 β†’ is-univalent-refl-graph 𝓐
 β†’ is-displayed-univalent-refl-graph 𝓐 𝓑
 β†’ (x : ⟨ 𝓐 ⟩) (y : βŸͺ 𝓑 ⟫ x)
 β†’ ((xβ‚€ , pβ‚€) (x₁ , p₁) : fan 𝓐 x)
 β†’ (yβ‚€ : βŸͺ 𝓑 ⟫ xβ‚€) (qβ‚€ : y β‰ˆβŸ¨ 𝓑 βΈ΄ pβ‚€ ⟩ yβ‚€)
 β†’ (y₁ : βŸͺ 𝓑 ⟫ x₁) (q₁ : y β‰ˆβŸ¨ 𝓑 βΈ΄ p₁ ⟩ y₁)
 β†’ ((xβ‚€ , yβ‚€) , (pβ‚€ , qβ‚€)) =[ fan (𝓐 ﹐ 𝓑) (x , y) ] ((x₁ , y₁) , (p₁ , q₁))
total-fans-prop-lemma 𝓐 𝓑 ua-𝓐 ua-𝓑 x y
 = Ξ -proj⁻¹ (x , β‰ˆ-refl 𝓐 x) (ua-𝓐 x)
    (Ξ -proj⁻¹ (x , β‰ˆ-refl 𝓐 x) (ua-𝓐 x)
     (Ξ» yβ‚€ qβ‚€ y₁ q₁
       β†’ total-component-fans-prop-lemma 𝓐 𝓑 ua-𝓑 x y (yβ‚€ , qβ‚€) (y₁ , q₁)))

univalence-closed-under-total
 : (𝓐 : Refl-Graph 𝓀 π“₯) (𝓑 : Displayed-Refl-Graph 𝓣 𝓦 𝓐)
 β†’ is-univalent-refl-graph 𝓐
 β†’ is-displayed-univalent-refl-graph 𝓐 𝓑
 β†’ is-univalent-refl-graph (𝓐 ﹐ 𝓑)
univalence-closed-under-total 𝓐 𝓑 ua-𝓐 ua-𝓑
 (x , y) ((xβ‚€ , yβ‚€) , (pβ‚€ , qβ‚€)) ((x₁ , y₁) , (p₁ , q₁))
 = total-fans-prop-lemma 𝓐 𝓑 ua-𝓐 ua-𝓑 x y (xβ‚€ , pβ‚€) (x₁ , p₁) yβ‚€ qβ‚€ y₁ q₁

\end{code}

The remaining closure conditions are relatively straightforward.

\begin{code}

univalence-closed-under-op : (𝓐 : Refl-Graph 𝓀 π“₯)
                           β†’ is-univalent-refl-graph 𝓐
                           β†’ is-univalent-refl-graph (𝓐 α΅’α΅–)
univalence-closed-under-op 𝓐 𝓐-ua = prop-fan-to-cofan 𝓐 𝓐-ua

univalence-closed-under-op-op : (𝓐 : Refl-Graph 𝓀 π“₯)
                              β†’ is-univalent-refl-graph (𝓐 α΅’α΅–)
                              β†’ is-univalent-refl-graph 𝓐
univalence-closed-under-op-op 𝓐 = univalence-closed-under-op (𝓐 α΅’α΅–)

univalence-closed-under-constant
 : (𝓐 : Refl-Graph 𝓀 π“₯)
 β†’ (𝓑 : Refl-Graph 𝓀' π“₯')
 β†’ is-univalent-refl-graph 𝓑 
 β†’ is-displayed-univalent-refl-graph 𝓐 (𝓐 * 𝓑)
univalence-closed-under-constant 𝓐 𝓑 ua-𝓑 x = ua-𝓑
    
univalence-closed-under-Γ—
 : (𝓐 : Refl-Graph 𝓀 π“₯) (𝓐' : Refl-Graph 𝓀' π“₯')
 β†’ is-univalent-refl-graph 𝓐
 β†’ is-univalent-refl-graph 𝓐'
 β†’ is-univalent-refl-graph (𝓐 βŠ— 𝓐')
univalence-closed-under-Γ— 𝓐 𝓐' ua-𝓐 ua-𝓐'
 = univalence-closed-under-total 𝓐 (𝓐 * 𝓐') ua-𝓐
    (univalence-closed-under-constant 𝓐 𝓐' ua-𝓐')

univalence-closed-under-Ξ  : Fun-Ext
                          β†’ (A : 𝓀' Μ‡) (𝓑 : A β†’ Refl-Graph 𝓀 π“₯)
                          β†’ ((x : A) β†’ is-univalent-refl-graph (𝓑 x))
                          β†’ is-univalent-refl-graph (∏ x ΛΈ A , (𝓑 x))
univalence-closed-under-Ξ  fe A 𝓑 ua-𝓑 = III
 where
  I : (f : ⟨ ∏ x ΛΈ A , (𝓑 x) ⟩)
    β†’ fan (∏ x ΛΈ A , (𝓑 x)) f ≃ ((x : A) β†’ fan (𝓑 x) (f x))
  I f = fan (∏ x ΛΈ A , (𝓑 x)) f                                     β‰ƒβŸ¨refl⟩
        (Ξ£ g κž‰ ⟨ ∏ x ΛΈ A , (𝓑 x) ⟩ , f β‰ˆβŸ¨ ∏ x ΛΈ A , (𝓑 x) ⟩ g)      β‰ƒβŸ¨refl⟩
        (Ξ£ g κž‰ ⟨ ∏ x ΛΈ A , (𝓑 x) ⟩ , ((x : A) β†’ f x β‰ˆβŸ¨ 𝓑 x ⟩ g x))  β‰ƒβŸ¨ II ⟩
        ((x : A) β†’ Ξ£ v κž‰ ⟨ 𝓑 x ⟩ , f x β‰ˆβŸ¨ 𝓑 x ⟩ v)                  β‰ƒβŸ¨refl⟩
        ((x : A) β†’ fan (𝓑 x) (f x))                                 β– 
   where
    II = ≃-sym Ξ Ξ£-distr-≃
  III : (f : ⟨ ∏ x ΛΈ A , (𝓑 x) ⟩) β†’ is-prop (fan (∏ x ΛΈ A , (𝓑 x)) f)
  III f = equiv-to-prop (I f) (Ξ -is-prop fe (Ξ» x β†’ ua-𝓑 x (f x)))

univalence-closed-under-cotensor : Fun-Ext
                          β†’ (A : 𝓀' Μ‡) (𝓑 : Refl-Graph 𝓀 π“₯)
                          β†’ is-univalent-refl-graph 𝓑
                          β†’ is-univalent-refl-graph (A βž™ 𝓑)
univalence-closed-under-cotensor fe A 𝓑 ua-𝓑
 = univalence-closed-under-Ξ  fe A (Ξ» - β†’ 𝓑) (Ξ» - β†’ ua-𝓑)

univalence-closed-under-Ξ£ : (A : 𝓀' Μ‡) (𝓑 : A β†’ Refl-Graph 𝓀 π“₯)
                          β†’ ((x : A) β†’ is-univalent-refl-graph (𝓑 x))
                          β†’ is-univalent-refl-graph (∐ x ΛΈ A , (𝓑 x))
univalence-closed-under-Ξ£ A 𝓑 ua-𝓑 (x , y)
 ((.x , yβ‚€) , refl , qβ‚€) ((.x , y₁) , refl , q₁)
 = II (yβ‚€ , qβ‚€) (y₁ , q₁)
 where
  I = fan (∐ x ΛΈ A , (𝓑 x)) (x , y)
  II : ((y' , q') (y'' , q'') : fan (𝓑 x) y)
     β†’ ((x , y') , (refl , q')) =[ I ] ((x , y'') , (refl , q''))
  II = Ξ -proj⁻¹ (y , β‰ˆ-refl (𝓑 x) y) (ua-𝓑 x y)
        (Ξ -proj⁻¹ (y , β‰ˆ-refl (𝓑 x) y) (ua-𝓑 x y) refl)

univalence-closed-under-tensor : (A : 𝓀' Μ‡) (𝓑 : Refl-Graph 𝓀 π“₯)
                               β†’ is-univalent-refl-graph 𝓑
                               β†’ is-univalent-refl-graph (∐ _ ΛΈ A , 𝓑)
univalence-closed-under-tensor A 𝓑 ua-𝓑
 = univalence-closed-under-Ξ£ A (Ξ» - β†’ 𝓑) (Ξ» - β†’ ua-𝓑)

discrete-refl-graph-is-univalent : (A : 𝓀' Μ‡) β†’ is-univalent-refl-graph (Ξ” A)
discrete-refl-graph-is-univalent A x
 = singletons-are-props (singleton-types-are-singletons x)

codiscrete-refl-graph-is-univalent-when-prop
 : (A : 𝓀' Μ‡)
 β†’ is-prop A
 β†’ is-univalent-refl-graph (codiscrete-reflexive-graph A)
codiscrete-refl-graph-is-univalent-when-prop A A-prop x (x' , ⋆) (y' , ⋆)
 = ap (Ξ» - β†’ (- , ⋆)) (A-prop x' y')

codiscrete-refl-graph-is-univalent-implies-prop
 : (A : 𝓀' Μ‡)
 β†’ is-univalent-refl-graph (codiscrete-reflexive-graph A)
 β†’ is-prop A
codiscrete-refl-graph-is-univalent-implies-prop A ua-codis-A x y
 = ap pr₁ (ua-codis-A x (x , ⋆) (y , ⋆))

univalence-closed-under-subgraph : (𝓐 : Refl-Graph 𝓀 π“₯) 
                                 β†’ (S : π“Ÿ {𝓣} ⟨ 𝓐 ⟩)
                                 β†’ is-univalent-refl-graph 𝓐
                                 β†’ is-univalent-refl-graph (x ∢ 𝓐 ∣ S x)
univalence-closed-under-subgraph 𝓐 S ua-𝓐 (x , s) ((x' , r) , p) ((y' , t) , q)
 = I (ua-𝓐 x (x , β‰ˆ-refl 𝓐 x) (x' , p)) (ua-𝓐 x (x , β‰ˆ-refl 𝓐 x) (y' , q))
 where
  I : ((x , β‰ˆ-refl 𝓐 x) = (x' , p))
    β†’ ((x , β‰ˆ-refl 𝓐 x) = (y' , q))
    β†’ ((x' , r) , p) = ((y' , t) , q)
  I refl refl = ap (Ξ» - β†’ ((x , -) , β‰ˆ-refl 𝓐 x)) (∈-is-prop S x r t)

\end{code}