Ian Ray. 28th August 2025.

Minor changes and merged into TypeToplogy in April 2026.

We define the notion of univalent family in terms of a reflexive graph image.
The terminology here is borrowed from "Reflexive graph lenses in univalent
foundations" by Jon Sterling (see ReflexiveGraphs.index for link).

\begin{code}

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

module ReflexiveGraphs.UnivalentFamilies where

open import MLTT.Spartan
open import UF.Equiv
open import UF.EquivalenceExamples
open import UF.Subsingletons
open import UF.Univalence
open import ReflexiveGraphs.Type
open import ReflexiveGraphs.Univalent

\end{code}

The reflexive graph image with carrier A, on a family B : A โ†’ Type, has edges
x โ‰ˆ y given by an equivalence between the fibers, that is B(x) โ‰ƒ B(y).

\begin{code}

refl-graph-image : (A : ๐“ค ฬ‡) โ†’ (A โ†’ ๐“ฃ ฬ‡) โ†’ Refl-Graph ๐“ค ๐“ฃ
refl-graph-image {๐“ค} {๐“ฃ} A B = (A , I , II)
 where
  I : A โ†’ A โ†’ ๐“ฃ ฬ‡
  I x y = B x โ‰ƒ B y
  II : (x : A) โ†’ I x x
  II x = โ‰ƒ-refl (B x)

is-univalent-family : ฮฃ A ๊ž‰ ๐“ค ฬ‡ , (A โ†’ ๐“ฃ ฬ‡)
                    โ†’ ๐“ค โŠ” ๐“ฃ ฬ‡
is-univalent-family (A , B) = is-univalent-refl-graph (refl-graph-image A B)

\end{code}

This definition is intentionally general and offers a robust theoretical
framework for working with universes. Concretely, if one were working directly
with the codes of a Tarski style universe presentation then a univalent family
could be a pair (๐“ค , El) consisting of the universe type and the decoding map
El : ๐“ค โ†’ Type. In Agda the user may operate as if universes where presented ร 
la Russel and thus the pair of interest is simply (๐“ค , id). But there are other
examples of univalent families of interest such as any h-level sub-universe
(e.g. (Prop, prโ‚), (Set, prโ‚)). Perhaps (โ„• , finset) offers a more non-standard
and interesting example for your consideration. 

We can give some equivalent characterizations of univalent family of types.

\begin{code}

id-to-equiv-family : {A : ๐“ค ฬ‡} {B : A โ†’ ๐“ฃ ฬ‡}
                   โ†’ (x y : A)
                   โ†’ x ๏ผ y
                   โ†’ B x โ‰ƒ B y
id-to-equiv-family {_} {_} {A} {B} x y = id-to-edge (refl-graph-image A B) 

is-univalent-family-implies-id-to-equiv
 : {A : ๐“ค ฬ‡} {B : A โ†’ ๐“ฃ ฬ‡}
 โ†’ is-univalent-family (A , B)
 โ†’ (x y : A)
 โ†’ is-equiv (id-to-equiv-family x y)
is-univalent-family-implies-id-to-equiv {๐“ค} {๐“ฃ} {A} {B} is-ua-fam
 = prop-fans-implies-id-to-edge-equiv (refl-graph-image A B) is-ua-fam

id-to-equiv-family-implies-univalent-family
 : {A : ๐“ค ฬ‡} {B : A โ†’ ๐“ฃ ฬ‡}
 โ†’ ((x y : A) โ†’ is-equiv (id-to-equiv-family x y))
 โ†’ is-univalent-family (A , B)
id-to-equiv-family-implies-univalent-family {๐“ค} {๐“ฃ} {A} {B} is-equiv
 = id-to-edge-equiv-implies-prop-fans (refl-graph-image A B) is-equiv

\end{code}

We conclude by defining a univalent family of univalent reflexive graphs.

\begin{code}

univalent-family-of-univalent-refl-graphs
 : {๐“ฆ ๐“ฃ : Universe}
 โ†’ ((U , ๐“”) : ฮฃ U ๊ž‰ ๐“ค ฬ‡ , (U โ†’ Univalent-Refl-Graph ๐“ฆ ๐“ฃ))
 โ†’ ๐“ค โŠ” ๐“ฆ ฬ‡
univalent-family-of-univalent-refl-graphs (U , ๐“”)
 = is-univalent-refl-graph (refl-graph-image U (ฮป A โ†’ โŸจ (๐“” A) โŸฉแตค))

\end{code}

We observe that a univalent universe is a univalent family and thus a univalent
reflexive graph. 

\begin{code}

universe-refl-graph : (๐“ค : Universe)
                    โ†’ Refl-Graph (๐“ค โบ) ๐“ค
universe-refl-graph ๐“ค = refl-graph-image (๐“ค  ฬ‡) id

module _ (๐“ค : Universe) (ua : is-univalent ๐“ค) where

 univalent-universe-is-univalent-family : is-univalent-family ((๐“ค  ฬ‡) , id)
 univalent-universe-is-univalent-family X
  = singletons-are-props (equiv-to-singleton (I X)
     (singleton-types-are-singletons X))
  where
   I : (X : ๐“ค ฬ‡) โ†’ (ฮฃ Y ๊ž‰ ๐“ค ฬ‡ , X โ‰ƒ Y) โ‰ƒ (ฮฃ Y ๊ž‰ ๐“ค ฬ‡ , X ๏ผ Y)
   I X = ฮฃ-cong (ฮป - โ†’ โ‰ƒ-sym (univalence-โ‰ƒ ua X -))

 universe-univalent-refl-graph : Univalent-Refl-Graph (๐“ค โบ) ๐“ค
 universe-univalent-refl-graph
  = (universe-refl-graph ๐“ค , univalent-universe-is-univalent-family)

\end{code}