{-# OPTIONS --safe --cubical #-}
open import Agda.Primitive
open import Cubical.Foundations.Prelude
open import Cubical.Data.Sigma
import Cubical.Data.Empty
open import Cubical.Data.Sum
open import Cubical.Data.Nat
open import Cubical.Induction.WellFounded
renaming (WellFounded to isWellFounded;
Acc to isAcc;
Rel to BinRel)
open import Cubical.Data.List.Base hiding (rev)
open import Cubical.Data.List.Properties
open import Cubical.Relation.Nullary.Base
module squier.polygraphs where
open import squier.graphclosures
private variable
ℓ₀ ℓ₁ ℓ₂ ℓ₃ : Level
record 2-polygraph : Type (ℓ-suc (ℓ₀ ⊔ ℓ₁ ⊔ ℓ₂)) where
field
Σ₀ : Type ℓ₀
_↝_ : BinRel Σ₀ ℓ₁
_⇒_ : {y z : Σ₀} → BinRel (TransReflClosure (SymClosure _↝_) y z) ℓ₂
module polygraph-properties (p : 2-polygraph {ℓ₀} {ℓ₁} {ℓ₂}) where
Σ₀ = 2-polygraph.Σ₀ p
_↝_ = 2-polygraph._↝_ p
_⇒_ = 2-polygraph._⇒_ p
_↝*_ = TransReflClosure _↝_
_↭_ = SymClosure _↝_
_↭*_ = TransReflClosure _↭_
mkLocalPeak : ∀ {y x z} → (x ↝ y) → (x ↝ z) → y ↭* z
mkLocalPeak s t = (rev s) ∷ᵗ (inj t) ∷ᵗ []ᵗ
mkPeak : ∀ {y x z} → (x ↝* y) → (x ↝* z) → y ↭* z
mkPeak x↝y x↝z = embed⁻ x↝y ++ᵗ embed⁺ x↝z
mkValley : ∀ {y x' z} → (y ↝* x') → (z ↝* x') → y ↭* z
mkValley y↝x z↝x = embed⁺ y↝x ++ᵗ (embed⁻ z↝x)
data isIncreasing : ∀ {x y} → (x ↭* y) → Type (ℓ₀ ⊔ ℓ₁) where
isIncreasing[]ᵗ : ∀ {x} → isIncreasing ([]ᵗ {a = x})
isIncreasing∷ᵗ : ∀ {x y z}(s : x ↝ y){u : y ↭* z}
→ isIncreasing u → isIncreasing (inj s ∷ᵗ u)
data isDecreasing : ∀ {x y} → (x ↭* y) → Type (ℓ₀ ⊔ ℓ₁) where
isDecreasing[]ᵗ : ∀ {x} → isDecreasing ([]ᵗ {a = x})
isDecreasing∷ᵗ : ∀ {x y z}(s : y ↝ x){u : y ↭* z}
→ isDecreasing u → isDecreasing (rev s ∷ᵗ u)
_⇒*_ : {y z : Σ₀} → BinRel (y ↭* z) _
_⇒*_ = TransReflClosure _⇒_
_⇔_ : {y z : Σ₀} → BinRel (y ↭* z) _
_⇔_ = SymClosure _⇒_
_⇔*_ : {y z : Σ₀} → BinRel (y ↭* z) _
_⇔*_ = TransReflClosure _⇔_
_⇒*⟨_⟩_ : {y z : Σ₀} {v w : y ↭* z}
→ (u : y ↭* z) → (u ⇒* v) → (v ⇒* w) → (u ⇒* w)
u ⇒*⟨ uv ⟩ vw = uv ++ᵗ vw
_⇒*∎ : {y z : Σ₀} (u : y ↭* z) → u ⇒* u
u ⇒*∎ = []ᵗ
infixr 0 _⇒*⟨_⟩_
infix 1 _⇒*∎
_⇔*⟨_⟩_ : {y z : Σ₀} {v w : y ↭* z}
→ (u : y ↭* z) → (u ⇔* v) → (v ⇔* w) → (u ⇔* w)
u ⇔*⟨ uv ⟩ vw = uv ++ᵗ vw
_⇔*∎ : {y z : Σ₀} (u : y ↭* z) → u ⇔* u
u ⇔*∎ = []ᵗ
infixr 0 _⇔*⟨_⟩_
infix 1 _⇔*∎
≡2⇔* : ∀ {x y} {u v : x ↭* y} → (u ≡ v) → (u ⇔* v)
≡2⇔* {u = u} p = subst (λ w → u ⇔* w) p []ᵗ
hasOrder : ∀ {ℓ₃} → Type _
hasOrder {ℓ₃} =
Σ[ _>_ ∈ BinRel Σ₀ ℓ₃ ]
(isTransitive _>_)
×
∀ {y z} → y ↝ z → y > z
module order (ord : hasOrder {ℓ₃}) where
_>_ = fst ord
trans = fst (snd ord)
↝2> = snd (snd ord)
↝*2≥ : {x z : Σ₀} (x↝*z : x ↝* z) → (lengthᵗ x↝*z ≡ 0) ⊎ (x > z)
↝*2≥ []ᵗ = inl refl
↝*2≥ (x↝y ∷ᵗ y↝*z) with ↝*2≥ y↝*z
↝*2≥ {x} {z} (x↝y ∷ᵗ y↝*z) | inl y≡z =
inr (subst (λ y → x > y) (length≡0 y≡z) (↝2> x↝y))
↝*2≥ {x} {z} (x↝y ∷ᵗ y↝*z) | inr y>z =
inr (trans (↝2> x↝y) y>z)
isNoetherian : ∀ {ℓ₃} → hasOrder {ℓ₃} → Type _
isNoetherian (_>_ , _) = isWellFounded λ x y → y > x
⇔*isCongrClosed = ∀ {x₀ x y y₀} (w₀ : x₀ ↭* x) (u v : x ↭* y) (w₁ : y ↭* y₀)
→ (u ⇔* v) → (w₀ ++ᵗ u ++ᵗ w₁) ⇔* (w₀ ++ᵗ v ++ᵗ w₁)
⇔*isCongrClosedR = ∀ {x₀ x y} (w₀ : x₀ ↭* x) (u v : x ↭* y)
→ (u ⇔* v) → (w₀ ++ᵗ u) ⇔* (w₀ ++ᵗ v)
⇔*isCongrClosedL = ∀ {x y y₀} (u v : x ↭* y) (w₁ : y ↭* y₀)
→ (u ⇔* v) → (u ++ᵗ w₁) ⇔* (v ++ᵗ w₁)
⇔*cc2ccr : ⇔*isCongrClosed → ⇔*isCongrClosedR
⇔*cc2ccr cc w₀ u v α =
(w₀ ++ᵗ u)
⇔*⟨ ≡2⇔* (sym (cong (λ u' → w₀ ++ᵗ u') ++ᵗ[]ᵗ)) ⟩
(w₀ ++ᵗ u ++ᵗ []ᵗ)
⇔*⟨ cc w₀ u v []ᵗ α ⟩
(w₀ ++ᵗ v ++ᵗ []ᵗ)
⇔*⟨ ≡2⇔* (cong (λ v' → w₀ ++ᵗ v') ++ᵗ[]ᵗ) ⟩
(w₀ ++ᵗ v)
⇔*∎
⇔*cc2ccl : ⇔*isCongrClosed → ⇔*isCongrClosedL
⇔*cc2ccl cc = cc []ᵗ