{-# OPTIONS --without-K --safe #-} open import Relation.Binary module Cfe.Language.Base {c β„“} (setoid : Setoid c β„“) where open Setoid setoid renaming (Carrier to A) open import Data.Empty open import Data.List open import Data.List.Relation.Binary.Equality.Setoid setoid open import Data.Product as Product open import Function open import Level import Relation.Binary.PropositionalEquality as ≑ import Relation.Binary.Indexed.Heterogeneous as I record IsLanguage {a aβ„“} (𝕃 : List A β†’ Set a) (_β‰ˆα΄Έ_ : βˆ€ {l} β†’ Rel (𝕃 l) aβ„“) (β€– : βˆ€ {l₁ lβ‚‚} β†’ l₁ ≋ lβ‚‚ β†’ 𝕃 l₁ β†’ 𝕃 lβ‚‚) : Set (c βŠ” β„“ βŠ” a βŠ” aβ„“) where field β‰ˆα΄Έ-isEquivalence : βˆ€ {l} β†’ IsEquivalence (_β‰ˆα΄Έ_ {l}) β€–-cong : βˆ€ {l₁ lβ‚‚ l₁≋lβ‚‚} β†’ (β€– l₁≋lβ‚‚) Preserves _β‰ˆα΄Έ_ {l₁} ⟢ _β‰ˆα΄Έ_ {lβ‚‚} β€–-bijective : βˆ€ {l₁ lβ‚‚ l₁≋lβ‚‚} β†’ Bijective (_β‰ˆα΄Έ_ {l₁}) (_β‰ˆα΄Έ_ {lβ‚‚}) (β€– l₁≋lβ‚‚) β€–-refl : βˆ€ {l lβˆˆπ•ƒ} β†’ (β€– {l} ≋-refl lβˆˆπ•ƒ) β‰ˆα΄Έ lβˆˆπ•ƒ β€–-sym : βˆ€ {l₁ lβ‚‚ lβ‚βˆˆπ•ƒ lβ‚‚βˆˆπ•ƒ l₁≋lβ‚‚} β†’ (β€– {l₁} l₁≋lβ‚‚ lβ‚βˆˆπ•ƒ) β‰ˆα΄Έ lβ‚‚βˆˆπ•ƒ β†’ (β€– {lβ‚‚} (≋-sym l₁≋lβ‚‚) lβ‚‚βˆˆπ•ƒ) β‰ˆα΄Έ lβ‚βˆˆπ•ƒ β€–-trans : βˆ€ {l₁ lβ‚‚ l₃ lβ‚βˆˆπ•ƒ lβ‚‚βˆˆπ•ƒ lβ‚ƒβˆˆπ•ƒ l₁≋lβ‚‚ l₂≋l₃} β†’ (β€– {l₁} l₁≋lβ‚‚ lβ‚βˆˆπ•ƒ) β‰ˆα΄Έ lβ‚‚βˆˆπ•ƒ β†’ (β€– {lβ‚‚} l₂≋l₃ lβ‚‚βˆˆπ•ƒ) β‰ˆα΄Έ lβ‚ƒβˆˆπ•ƒ β†’ (β€– {_} {l₃} (≋-trans l₁≋lβ‚‚ l₂≋l₃) lβ‚βˆˆπ•ƒ) β‰ˆα΄Έ lβ‚ƒβˆˆπ•ƒ β‰ˆα΄Έ-refl : βˆ€ {l} β†’ Reflexive (_β‰ˆα΄Έ_ {l}) β‰ˆα΄Έ-refl = IsEquivalence.refl β‰ˆα΄Έ-isEquivalence β‰ˆα΄Έ-sym : βˆ€ {l} β†’ Symmetric (_β‰ˆα΄Έ_ {l}) β‰ˆα΄Έ-sym = IsEquivalence.sym β‰ˆα΄Έ-isEquivalence β‰ˆα΄Έ-trans : βˆ€ {l} β†’ Transitive (_β‰ˆα΄Έ_ {l}) β‰ˆα΄Έ-trans = IsEquivalence.trans β‰ˆα΄Έ-isEquivalence β‰ˆα΄Έ-reflexive : βˆ€ {l} β†’ ≑._≑_ β‡’ (_β‰ˆα΄Έ_ {l}) β‰ˆα΄Έ-reflexive = IsEquivalence.reflexive β‰ˆα΄Έ-isEquivalence β€–-injective : βˆ€ {l₁ lβ‚‚ l₁≋lβ‚‚} β†’ Injective (_β‰ˆα΄Έ_ {l₁}) (_β‰ˆα΄Έ_ {lβ‚‚}) (β€– l₁≋lβ‚‚) β€–-injective = proj₁ β€–-bijective β€–-surjective : βˆ€ {l₁ lβ‚‚ l₁≋lβ‚‚} β†’ Surjective (_β‰ˆα΄Έ_ {l₁}) (_β‰ˆα΄Έ_ {lβ‚‚}) (β€– {l₁} l₁≋lβ‚‚) β€–-surjective = projβ‚‚ β€–-bijective β€–-isIndexedEquivalence : I.IsIndexedEquivalence 𝕃 (Ξ» lβ‚βˆˆπ•ƒ lβ‚‚βˆˆπ•ƒ β†’ βˆƒ[ l₁≋lβ‚‚ ] ((β€– l₁≋lβ‚‚ lβ‚βˆˆπ•ƒ) β‰ˆα΄Έ lβ‚‚βˆˆπ•ƒ)) β€–-isIndexedEquivalence = record { refl = ≋-refl , β€–-refl ; sym = Product.map ≋-sym β€–-sym ; trans = Product.zip ≋-trans β€–-trans } β€–-reflexive : βˆ€ {l lβˆˆπ•ƒ lβˆˆπ•ƒβ€²} β†’ lβˆˆπ•ƒ ≑.≑ lβˆˆπ•ƒβ€² β†’ βˆƒ[ l≋l ]((β€– {l} l≋l lβˆˆπ•ƒ) β‰ˆα΄Έ lβˆˆπ•ƒβ€²) β€–-reflexive = I.IsIndexedEquivalence.reflexive β€–-isIndexedEquivalence record Language a aβ„“ : Set (c βŠ” β„“ βŠ” suc (a βŠ” aβ„“)) where infix 4 _β‰ˆα΄Έ_ field 𝕃 : List A β†’ Set a _β‰ˆα΄Έ_ : βˆ€ {l} β†’ Rel (𝕃 l) aβ„“ β€– : βˆ€ {l₁ lβ‚‚} β†’ l₁ ≋ lβ‚‚ β†’ 𝕃 l₁ β†’ 𝕃 lβ‚‚ isLanguage : IsLanguage 𝕃 _β‰ˆα΄Έ_ β€– open IsLanguage isLanguage public open Language infix 4 _∈_ _∈_ : βˆ€ {a aβ„“} β†’ List A β†’ Language a aβ„“ β†’ Set a l ∈ A = 𝕃 A l βˆ… : Language 0β„“ 0β„“ βˆ… = record { 𝕃 = const βŠ₯ ; _β‰ˆα΄Έ_ = ≑._≑_ ; β€– = const id ; isLanguage = record { β‰ˆα΄Έ-isEquivalence = ≑.isEquivalence ; β€–-cong = ≑.cong id ; β€–-bijective = (Ξ» {x} β†’ βŠ₯-elim x) , (Ξ» ()) ; β€–-refl = Ξ» {_} {lβˆˆπ•ƒ} β†’ βŠ₯-elim lβˆˆπ•ƒ ; β€–-sym = Ξ» {_} {_} {lβ‚βˆˆπ•ƒ} β†’ βŠ₯-elim lβ‚βˆˆπ•ƒ ; β€–-trans = Ξ» {_} {_} {_} {lβ‚βˆˆπ•ƒ} β†’ βŠ₯-elim lβ‚βˆˆπ•ƒ } } ⦃Ρ⦄ : Language (c βŠ” β„“) (c βŠ” β„“) ⦃Ρ⦄ = record { 𝕃 = [] ≋_ ; _β‰ˆα΄Έ_ = ≑._≑_ ; β€– = flip ≋-trans ; isLanguage = record { β‰ˆα΄Έ-isEquivalence = ≑.isEquivalence ; β€–-cong = Ξ» {_} {_} {l₁≋lβ‚‚} β†’ ≑.cong (flip ≋-trans l₁≋lβ‚‚) ; β€–-bijective = Ξ» {_} {_} {l₁≋lβ‚‚} β†’ ( (Ξ» {x} {y} x≑y β†’ case x , y return (Ξ» (x , y) β†’ x ≑.≑ y) of Ξ» { ([] , []) β†’ ≑.refl }) , (Ξ» { [] β†’ (case l₁≋lβ‚‚ return (Ξ» x β†’ βˆƒ[ y ](≋-trans y x ≑.≑ [])) of Ξ» { [] β†’ [] , ≑.refl})})) ; β€–-refl = Ξ» {_} {[]≋l} β†’ case []≋l return (Ξ» []≋l β†’ ≋-trans []≋l ≋-refl ≑.≑ []≋l) of Ξ» {[] β†’ ≑.refl} ; β€–-sym = Ξ» {_} {_} {[]≋l₁} {[]≋lβ‚‚} {l₁≋lβ‚‚} _ β†’ case []≋l₁ , []≋lβ‚‚ , l₁≋lβ‚‚ return (Ξ» ([]≋l₁ , []≋lβ‚‚ , l₁≋lβ‚‚) β†’ ≋-trans []≋lβ‚‚ (≋-sym l₁≋lβ‚‚) ≑.≑ []≋l₁) of Ξ» { ([] , [] , []) β†’ ≑.refl } ; β€–-trans = Ξ» {_} {_} {_} {[]≋l₁} {[]≋lβ‚‚} {[]≋l₃} {l₁≋lβ‚‚} {l₂≋l₃} _ _ β†’ case []≋l₁ , []≋lβ‚‚ , []≋l₃ , l₁≋lβ‚‚ , l₂≋l₃ return (Ξ» ([]≋l₁ , []≋lβ‚‚ , []≋l₃ , l₁≋lβ‚‚ , l₂≋l₃) β†’ ≋-trans []≋l₁ (≋-trans l₁≋lβ‚‚ l₂≋l₃) ≑.≑ []≋l₃) of Ξ» { ([] , [] , [] , [] , []) β†’ ≑.refl } } } _≀_ : {a aβ„“ b bβ„“ : Level} β†’ REL (Language a aβ„“) (Language b bβ„“) (c βŠ” a βŠ” b) A ≀ B = βˆ€ {l} β†’ l ∈ A β†’ l ∈ B