Debian Codegraph @

src/Text/Regex/Properties/Core.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Regular expressions: core properties (only require a Preorder)
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 open import Relation.Binary.Bundles using (Preorder)
10
11 module Text.Regex.Properties.Core {a e r} (P : Preorder a e r) where
12
13 open import Level using (_⊔_)
14
15 open import Data.Bool.Base using (Bool)
16 open import Data.List.Base as List using (List; []; _∷_; _++_)
17
18 open import Data.List.Relation.Unary.Any using (Any; here; there)
19 open import Data.List.Relation.Unary.All using (All; []; _∷_)
20 open import Data.Product.Base using (_×_; _,_)
21 open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
22
23 open import Relation.Nullary using (¬_; Dec; yes; no)
24 open import Relation.Nullary.Negation using (contradiction)
25 open import Relation.Unary using (Pred)
26 open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl)
27
28 open Preorder P using (_≈_) renaming (Carrier to A; _∼_ to _≤_)
29 open import Text.Regex.Base P
30
31 open import Data.List.Relation.Ternary.Appending.Propositional.Properties {A = A}
32 using (++[]⁻¹; []++⁻¹; conicalˡ; conicalʳ)
33
34 ------------------------------------------------------------------------
35 -- Views
36
37 is-∅ : ∀ (e : Exp) → Dec (e ≡ ∅)
38 is-∅ ε = no (λ ())
39 is-∅ [ [] ] = yes refl
40 is-∅ [ r ∷ rs ] = no (λ ())
41 is-∅ [^ rs ] = no (λ ())
42 is-∅ (e ∣ f) = no (λ ())
43 is-∅ (e ∙ f) = no (λ ())
44 is-∅ (e ⋆) = no (λ ())
45
46 is-ε : ∀ (e : Exp) → Dec (e ≡ ε)
47 is-ε ε = yes refl
48 is-ε [ rs ] = no (λ ())
49 is-ε [^ rs ] = no (λ ())
50 is-ε (e ∣ f) = no (λ ())
51 is-ε (e ∙ f) = no (λ ())
52 is-ε (e ⋆) = no (λ ())
53
54 ------------------------------------------------------------------------
55 -- Inversion lemmas
56
57 ∉∅ : ∀ {xs} → xs ∉ ∅
58 ∉∅ [ () ]
59
60 ∈ε⋆-inv : ∀ {w} → w ∈ (ε ⋆) → w ∈ ε
61 ∈ε⋆-inv (star (sum (inj₁ ε))) = ε
62 ∈ε⋆-inv (star (sum (inj₂ (prod eq ε p)))) rewrite []++⁻¹ eq = ∈ε⋆-inv p
63
64 ∈∅⋆-inv : ∀ {w} → w ∈ (∅ ⋆) → w ∈ ε
65 ∈∅⋆-inv (star (sum (inj₁ ε))) = ε
66 ∈∅⋆-inv (star (sum (inj₂ (prod eq p q)))) = contradiction p ∉∅
67
68 ∈ε∙e-inv : ∀ {w e} → w ∈ (ε ∙ e) → w ∈ e
69 ∈ε∙e-inv (prod eq ε p) rewrite []++⁻¹ eq = p
70
71 ∈e∙ε-inv : ∀ {w e} → w ∈ (e ∙ ε) → w ∈ e
72 ∈e∙ε-inv (prod eq p ε) rewrite ++[]⁻¹ eq = p
73
74 []∈e∙f-inv : ∀ {e f} → [] ∈ (e ∙ f) → [] ∈ e × [] ∈ f
75 []∈e∙f-inv (prod eq p q) rewrite conicalˡ eq | conicalʳ eq = p , q