---
layout: default
title : "Legacy.Base.Structures.Graphs module"
date : "2021-06-22"
author: "agda-algebras development team"
---
### <a id="graph-structures">Graph Structures</a>
This is the [Legacy.Base.Structures.Graphs][] module of the [Agda Universal Algebra Library][].
N.B. This module differs from 0Graphs.lagda in that this module is universe polymorphic; i.e., we do not restrict universe levels (to, e.g., `ββ`). This complicates some things; e.g., we must use lift and lower in some places (cf. [Legacy/Base/Structures/Graphs0.lagda][]).
**Definition** (Graph of a structure). Let `π¨` be an `(π
, πΉ)`-structure (relations from `π
` and operations from `πΉ`). The *graph* of `π¨` is the structure `Gr π¨` with the same domain as `π¨` with relations from `π
` together with a (`k+1`)-ary relation symbol `G π` for each `π β πΉ` of arity `k`, which is interpreted in `Gr π¨` as all tuples `(t , y) β Aα΅βΊΒΉ` such that `π t β‘ y`. (See also Definition 2 of https://arxiv.org/pdf/2010.04958v2.pdf)
```agda
{-# OPTIONS --cubical-compatible --exact-split --safe #-}
module Legacy.Base.Structures.Graphs where
open import Agda.Primitive using () renaming ( Set to Type )
open import Data.Product using ( _,_ ; Ξ£-syntax ; _Γ_ )
open import Data.Sum.Base using ( _β_ ) renaming ( injβ to inl ; injβ to inr )
open import Data.Unit.Base using ( β€ ; tt )
open import Level using ( _β_ ; Level ; Lift ; lift ; lower ) renaming ( 0β to ββ )
open import Function.Base using ( _β_ )
open import Relation.Binary.PropositionalEquality as β‘
using ( _β‘_ ; module β‘-Reasoning )
open import Overture using ( β£_β£ ; β₯_β₯ )
open import Legacy.Base.Relations using ( Rel )
open import Legacy.Base.Structures.Basic using ( signature ; structure )
open import Legacy.Base.Structures.Homs using ( hom ; β-hom ; is-hom-rel ; is-hom-op)
open import Examples.Structures.Signatures using ( Sβ
)
open signature ; open structure ; open _β_
Gr-sig : signature ββ ββ β signature ββ ββ β signature ββ ββ
Gr-sig πΉ π
= record { symbol = symbol π
β symbol πΉ
; arity = ar
}
where
ar : symbol π
β symbol πΉ β Type _
ar (inl π) = (arity π
) π
ar (inr π) = (arity πΉ) π β β€
private variable
πΉ π
: signature ββ ββ
Ξ± Ο : Level
Gr : β{Ξ± Ο} β structure πΉ π
{Ξ±} {Ο} β structure Sβ
(Gr-sig πΉ π
) {Ξ±} {Ξ± β Ο}
Gr {πΉ}{π
}{Ξ±}{Ο} π¨ = record { carrier = carrier π¨ ; op = Ξ» () ; rel = split }
where
split : (s : symbol π
β symbol πΉ) β Rel (carrier π¨) (arity (Gr-sig πΉ π
) s) {Ξ± β Ο}
split (inl π) arg = Lift Ξ± (rel π¨ π arg)
split (inr π) args = Lift Ο (op π¨ π (args β inl) β‘ args (inr tt))
open β‘-Reasoning
private variable Οα΅ Ξ² Οα΅ : Level
module _ {π¨ : structure πΉ π
{Ξ±} {Οα΅}} {π© : structure πΉ π
{Ξ²} {Οα΅}} where
homβGrhom : hom π¨ π© β hom (Gr π¨) (Gr π©)
homβGrhom (h , hhom) = h , (i , ii)
where
i : is-hom-rel (Gr π¨) (Gr π©) h
i (inl π) a x = lift (β£ hhom β£ π a (lower x))
i (inr π) a x = lift goal
where
homop : h (op π¨ π (a β inl)) β‘ op π© π (h β (a β inl))
homop = β₯ hhom β₯ π (a β inl)
goal : op π© π (h β (a β inl)) β‘ h (a (inr tt))
goal = op π© π (h β (a β inl)) β‘β¨ β‘.sym homop β©
h (op π¨ π (a β inl)) β‘β¨ β‘.cong h (lower x) β©
h (a (inr tt)) β
ii : is-hom-op (Gr π¨) (Gr π©) h
ii = Ξ» ()
Grhomβhom : hom (Gr π¨) (Gr π©) β hom π¨ π©
Grhomβhom (h , hhom) = h , (i , ii)
where
i : is-hom-rel π¨ π© h
i R a x = lower (β£ hhom β£ (inl R) a (lift x))
ii : is-hom-op π¨ π© h
ii f a = goal
where
split : arity πΉ f β β€ β carrier π¨
split (inl x) = a x
split (inr y) = op π¨ f a
goal : h (op π¨ f a) β‘ op π© f (Ξ» x β h (a x))
goal = β‘.sym (lower (β£ hhom β£ (inr f) split (lift β‘.refl)))
```
**Lemma III.1**. Let `π` be a signature and `π¨` be an `π`-structure.
Let `β°` be a finite set of identities such that `π¨ β§ β°`. For every
instance `πΏ` of CSP(`π¨`), one can compute in polynomial time an
instance `π` of CSP(`π¨`) such that `π β§ β°` and `| hom πΏ π¨ | = | hom π π¨ |`.
**Proof**. `β s β t` in `β°` and each tuple `b` such that `π© β¦ s β§ b β’ π© β¦ t β§ b`, one can compute
the congruence `ΞΈ = Cg (π© β¦ s β§ b , π© β¦ t β§ b)` generated by `π© β¦ s β§ b` and `π© β¦ t β§ b`.
Let `π©β := π© / ΞΈ`, and note that `| π©β | < | π© |`.
We show there exists a bijection from `hom π© π¨` to `hom π©β π¨`.
Fix an `h : hom π© π¨`. For all `s β t` in `β°`, we have
`h (π© β¦ s β§ b) = π¨ β¦ s β§ (h b) = π¨ β¦ t β§ (h b) = h (π© β¦ t β§ b)`.
Therefore, `ΞΈ β ker h`, so `h` factors uniquely as `h = h' β Ο : π© β (π© / ΞΈ) β π¨`,
where `Ο` is the canonical projection onto `π© / ΞΈ`.
Thus the mapping `Ο : hom π© π¨ β hom π©β π¨` that takes each `h` to `h'` such that `h = h' β Ο`
is injective. It is also surjective since each `g' : π© / ΞΈ β π¨` is mapped back to
a `g : π© β π¨` such that `g = g' β Ο`. Iterating over all identities in `β°`, possibly
several times, at the final step we obtain a structure `π©β` that satisfies `β°`
and is such that `β£ hom π© π¨ β£ = β£ hom π©β π¨ β£`. Moreover, since the number of elements
in the intermediate structures decreases at each step, `| π©α΅’ββ | < | π©α΅’ |`, the process
finishes in time that is bounded by a polynomial in the size of `π©`.
```agda
record _β_β_ (π© π¨ πͺ : structure πΉ π
) : Type ββ where
field
to : hom π© π¨ β hom πͺ π¨
from : hom πͺ π¨ β hom π© π¨
toβΌfrom : β h β (to β from) h β‘ h
fromβΌto : β h β (from β to) h β‘ h
```