open import Cat.Instances.Graphs
open import Cat.Prelude

open import Data.Sum
module Cat.Instances.Graphs.Box where

The box product of graphsπŸ”—

The box product of two graphs and is the graph with node set and, provided that there are edges (resp. edges of the form and

open Graph
private variable
  o β„“ o' β„“' : Level
  G : Graph o β„“


module _ {o β„“ o' β„“'} (G : Graph o β„“) (H : Graph o' β„“') where
  private variable
    gβ‚€ g₁ : ⌞ G ⌟
    hβ‚€ h₁ : ⌞ H ⌟

We define the edges as an indexed inductive type. Note that the indices corresponding to the graph we’re including an edge from vary, but the indices corresponding to the other graph remain fixed.

  data Box-edge : (gβ‚€ g₁ : ⌞ G ⌟) (hβ‚€ h₁ : ⌞ H ⌟) β†’ Type (o βŠ” o' βŠ” β„“ βŠ” β„“') where
    inl : G .Edge gβ‚€ g₁ β†’ Box-edge gβ‚€ g₁ hβ‚€ hβ‚€
    inr : H .Edge hβ‚€ h₁ β†’ Box-edge gβ‚€ gβ‚€ hβ‚€ h₁
We can prove that this type is a set by showing that it is equivalent to a sum, with a summand for each constructor, replacing the usage of indexing by an inductive identity.
instance
  H-Level-Box-edge
    : βˆ€ {G : Graph o β„“} {H : Graph o' β„“'} {gβ‚€ g₁ hβ‚€ h₁ n}
    β†’ H-Level (Box-edge G H gβ‚€ g₁ hβ‚€ h₁) (2 + n)
  H-Level-Box-edge {G = G} {H} {gβ‚€ = gβ‚€} {g₁} {hβ‚€} {h₁} =
    basic-instance 2 $ retract→is-hlevel 2 from to coh (hlevel 2)
    where
    T : Type _
    T = (hβ‚€ ≑ᡒ h₁ Γ— G .Edge gβ‚€ g₁) ⊎ (gβ‚€ ≑ᡒ g₁ Γ— H .Edge hβ‚€ h₁)

    from : T β†’ Box-edge G H gβ‚€ g₁ hβ‚€ h₁
    from (inl (reflα΅’ , x)) = inl x
    from (inr (reflα΅’ , x)) = inr x

    to : Box-edge G H gβ‚€ g₁ hβ‚€ h₁ β†’ T
    to (inl x) = inl (reflα΅’ , x)
    to (inr x) = inr (reflα΅’ , x)

    coh : is-left-inverse from to
    coh (inl x) = refl
    coh (inr x) = refl

We note that because the Box-edge type has to β€œstore” the endpoint nodes of the paths being included, the edges of a box product live in the least universe that contains both the edges and nodes of the operand graphs.

Box-product
  : Graph o β„“ β†’ Graph o' β„“' β†’ Graph (o βŠ” o') (o βŠ” β„“ βŠ” o' βŠ” β„“')
Box-product G H .Node = ⌞ G ⌟ Γ— ⌞ H ⌟
Box-product G H .Edge (gβ‚€ , hβ‚€) (g₁ , h₁) = Box-edge G H gβ‚€ g₁ hβ‚€ h₁
Box-product G H .Node-set = hlevel 2
Box-product G H .Edge-set = hlevel 2