{-# OPTIONS --without-K --safe #-} open import Relation.Binary module Cfe.Expression.Properties {c ℓ} (over : Setoid c ℓ) where open Setoid over using () renaming (Carrier to C; _≈_ to _∼_) open import Algebra open import Cfe.Expression.Base over open import Cfe.Function.Power open import Cfe.Language over hiding ( ≈-isPartialEquivalence; partialSetoid ; ∙-isMagma; ∙-isSemigroup; ∙-isMonoid; ∙-magma; ∙-semigroup; ∙-monoid ) renaming ( _≈_ to _≈ˡ_ ; ≈-refl to ≈ˡ-refl ; ≈-sym to ≈ˡ-sym ; ≈-trans to ≈ˡ-trans ; ≈-isEquivalence to ≈ˡ-isEquivalence ; setoid to setoidˡ ; _∙_ to _∙ˡ_ ; ∙-cong to ∙ˡ-cong ; ∙-assoc to ∙ˡ-assoc ; ∙-identityˡ to ∙ˡ-identityˡ ; ∙-identityʳ to ∙ˡ-identityʳ ; ∙-identity to ∙ˡ-identity ; ∙-zeroˡ to ∙ˡ-zeroˡ ; ∙-zeroʳ to ∙ˡ-zeroʳ ; ∙-zero to ∙ˡ-zero ) open import Data.Empty using (⊥-elim) open import Data.Fin hiding (_+_; _≤_; _<_) open import Data.List using (List; length; _++_) open import Data.List.Properties using (length-++) open import Data.List.Relation.Binary.Pointwise using (Pointwise-length) open import Data.Nat hiding (_≟_; _⊔_; _^_) open import Data.Nat.Properties hiding (_≟_) open import Data.Product open import Data.Sum using (_⊎_; inj₁; inj₂) open import Data.Vec hiding (length; _++_) open import Data.Vec.Properties open import Data.Vec.Relation.Binary.Pointwise.Inductive as PW hiding (refl; sym; trans; setoid; lookup) open import Level using (_⊔_) open import Relation.Binary.PropositionalEquality hiding (setoid) open import Relation.Nullary private variable k m n : ℕ ≈ˡ-reflexive = IsEquivalence.reflexive (≈ˡ-isEquivalence {c ⊔ ℓ}) ------------------------------------------------------------------------ -- Properties of ⟦_⟧ ------------------------------------------------------------------------ -- Algebraic properties of ⟦_⟧ ⟦⟧-mono-env : ∀ (e : Expression n) {γ γ′} → Pointwise _⊆_ γ γ′ → ⟦ e ⟧ γ ⊆ ⟦ e ⟧ γ′ ⟦⟧-mono-env ⊥ mono = ⊆-refl ⟦⟧-mono-env ε mono = ⊆-refl ⟦⟧-mono-env (Char _) mono = ⊆-refl ⟦⟧-mono-env (e₁ ∨ e₂) mono = ∪-mono (⟦⟧-mono-env e₁ mono) (⟦⟧-mono-env e₂ mono) ⟦⟧-mono-env (e₁ ∙ e₂) mono = ∙-mono (⟦⟧-mono-env e₁ mono) (⟦⟧-mono-env e₂ mono) ⟦⟧-mono-env (Var j) mono = PW.lookup mono j ⟦⟧-mono-env (μ e) mono = ⋃-mono λ A⊆B → ⟦⟧-mono-env e (A⊆B ∷ mono) ⟦⟧-cong-env : ∀ (e : Expression n) {γ γ′} → Pointwise _≈ˡ_ γ γ′ → ⟦ e ⟧ γ ≈ˡ ⟦ e ⟧ γ′ ⟦⟧-cong-env ⊥ cong = ≈ˡ-refl ⟦⟧-cong-env ε cong = ≈ˡ-refl ⟦⟧-cong-env (Char _) cong = ≈ˡ-refl ⟦⟧-cong-env (e₁ ∨ e₂) cong = ∪-cong (⟦⟧-cong-env e₁ cong) (⟦⟧-cong-env e₂ cong) ⟦⟧-cong-env (e₁ ∙ e₂) cong = ∙ˡ-cong (⟦⟧-cong-env e₁ cong) (⟦⟧-cong-env e₂ cong) ⟦⟧-cong-env (Var j) cong = PW.lookup cong j ⟦⟧-cong-env (μ e) cong = ⋃-cong λ A≈B → ⟦⟧-cong-env e (A≈B ∷ cong) ------------------------------------------------------------------------ -- Properties of _≈_ ------------------------------------------------------------------------ -- Relational properties ≈-refl : Reflexive (_≈_ {n}) ≈-refl _ = ≈ˡ-refl ≈-sym : Symmetric (_≈_ {n}) ≈-sym e≈e′ γ = ≈ˡ-sym (e≈e′ γ) ≈-trans : Transitive (_≈_ {n}) ≈-trans e≈e′ e′≈e′′ γ = ≈ˡ-trans (e≈e′ γ) (e′≈e′′ γ) ------------------------------------------------------------------------ -- Structures ≈-isPartialEquivalence : IsPartialEquivalence (_≈_ {n}) ≈-isPartialEquivalence {n} = record { sym = λ {e} {e′} → ≈-sym {n} {e} {e′} ; trans = λ {e} {e′} {e′′} → ≈-trans {n} {e} {e′} {e′′} } ≈-isEquivalence : IsEquivalence (_≈_ {n}) ≈-isEquivalence {n} = record { refl = λ {e} → ≈-refl {n} {e} ; sym = λ {e} {e′} → ≈-sym {n} {e} {e′} ; trans = λ {e} {e′} {e′′} → ≈-trans {n} {e} {e′} {e′′} } ------------------------------------------------------------------------ -- Bundles partialSetoid : ∀ {n} → PartialSetoid _ _ partialSetoid {n} = record { isPartialEquivalence = ≈-isPartialEquivalence {n} } setoid : ∀ {n} → Setoid _ _ setoid {n} = record { isEquivalence = ≈-isEquivalence {n} } ------------------------------------------------------------------------ -- Properties of _<ᵣₐₙₖ_ ------------------------------------------------------------------------ -- Definitions infix 4 _<ₗₑₓ_ _<ₗₑₓ_ : REL (List C × Expression m) (List C × Expression n) _ (w , e) <ₗₑₓ (w′ , e′) = length w < length w′ ⊎ length w ≡ length w′ × e <ᵣₐₙₖ e′ ------------------------------------------------------------------------ -- Relational properties <ᵣₐₙₖ-trans : Trans (_<ᵣₐₙₖ_ {k}) (_<ᵣₐₙₖ_ {m} {n}) _<ᵣₐₙₖ_ <ᵣₐₙₖ-trans = <-trans <ᵣₐₙₖ-asym : Asymmetric (_<ᵣₐₙₖ_ {n}) <ᵣₐₙₖ-asym = <-asym <ₗₑₓ-trans : Trans (_<ₗₑₓ_ {k}) (_<ₗₑₓ_ {m} {n}) _<ₗₑₓ_ <ₗₑₓ-trans (inj₁ ∣w₁∣<∣w₂∣) (inj₁ ∣w₂∣<∣w₃∣) = inj₁ (<-trans ∣w₁∣<∣w₂∣ ∣w₂∣<∣w₃∣) <ₗₑₓ-trans (inj₁ ∣w₁∣<∣w₂∣) (inj₂ (∣w₂∣≡∣w₃∣ , _)) = inj₁ (<-transˡ ∣w₁∣<∣w₂∣ (≤-reflexive ∣w₂∣≡∣w₃∣)) <ₗₑₓ-trans (inj₂ (∣w₁∣≡∣w₂∣ , _)) (inj₁ ∣w₂∣<∣w₃∣) = inj₁ (<-transʳ (≤-reflexive ∣w₁∣≡∣w₂∣) ∣w₂∣<∣w₃∣) <ₗₑₓ-trans (inj₂ (∣w₁∣≡∣w₂∣ , r₁