| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Property related to Grouped |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.List.Relation.Unary.Grouped.Properties where |
| 10 |
|
| 11 |
open import Data.Bool.Base using (true; false) |
| 12 |
open import Data.List.Base using ([]; [_]; _∷_; map; derun) |
| 13 |
open import Data.List.Relation.Unary.All as All using (All; []; _∷_) |
| 14 |
import Data.List.Relation.Unary.All.Properties as All |
| 15 |
open import Data.List.Relation.Unary.AllPairs as AllPairs using (AllPairs; []; _∷_) |
| 16 |
open import Data.List.Relation.Unary.Grouped |
| 17 |
open import Data.Product.Base using (_,_) |
| 18 |
open import Function.Base using (_∘_; _on_) |
| 19 |
open import Level using (Level) |
| 20 |
open import Relation.Binary.Definitions as B |
| 21 |
open import Relation.Binary.Core using (_⇔_; REL; Rel) |
| 22 |
open import Relation.Unary as U using (Pred) |
| 23 |
open import Relation.Nullary.Decidable.Core using (does; yes; no) |
| 24 |
open import Relation.Nullary.Negation.Core using (¬_; contradiction) |
| 25 |
|
| 26 |
private |
| 27 |
variable |
| 28 |
a b c p q : Level |
| 29 |
A B C : Set a |
| 30 |
|
| 31 |
------------------------------------------------------------------------ |
| 32 |
-- map |
| 33 |
|
| 34 |
module _ (P : Rel A p) (Q : Rel B q) where |
| 35 |
|
| 36 |
map⁺ : ∀ {f xs} → P ⇔ (Q on f) → Grouped P xs → Grouped Q (map f xs) |
| 37 |
map⁺ P⇔Q [] = [] |
| 38 |
map⁺ P⇔Q@(_ , Q⇒P) (all[¬Px,xs] ∷≉ g[xs]) = All.gmap⁺ (_∘ Q⇒P) all[¬Px,xs] ∷≉ map⁺ P⇔Q g[xs] |
| 39 |
map⁺ P⇔Q@(P⇒Q , _) (Px₁x₂ ∷≈ g[xs]) = P⇒Q Px₁x₂ ∷≈ map⁺ P⇔Q g[xs] |
| 40 |
|
| 41 |
map⁻ : ∀ {f xs} → P ⇔ (Q on f) → Grouped Q (map f xs) → Grouped P xs |
| 42 |
map⁻ {xs = []} P⇔Q [] = [] |
| 43 |
map⁻ {xs = _ ∷ []} P⇔Q ([] ∷≉ []) = [] ∷≉ [] |
| 44 |
map⁻ {xs = _ ∷ _ ∷ _} P⇔Q@(P⇒Q , _) (all[¬Qx,xs] ∷≉ g) = All.gmap⁻ (_∘ P⇒Q) all[¬Qx,xs] ∷≉ map⁻ P⇔Q g |
| 45 |
map⁻ {xs = _ ∷ _ ∷ _} P⇔Q@(_ , Q⇒P) (Qx₁x₂ ∷≈ g) = Q⇒P Qx₁x₂ ∷≈ map⁻ P⇔Q g |
| 46 |
|
| 47 |
------------------------------------------------------------------------ |
| 48 |
-- [_] |
| 49 |
|
| 50 |
module _ (P : Rel A p) where |
| 51 |
|
| 52 |
[_]⁺ : ∀ x → Grouped P [ x ] |
| 53 |
[_]⁺ x = [] ∷≉ [] |
| 54 |
|
| 55 |
------------------------------------------------------------------------ |
| 56 |
-- derun |
| 57 |
|
| 58 |
module _ {P : Rel A p} (P? : B.Decidable P) where |
| 59 |
|
| 60 |
grouped[xs]⇒unique[derun[xs]] : ∀ xs → Grouped P xs → AllPairs (λ x y → ¬ P x y) (derun P? xs) |
| 61 |
grouped[xs]⇒unique[derun[xs]] [] [] = [] |
| 62 |
grouped[xs]⇒unique[derun[xs]] (x ∷ []) ([] ∷≉ []) = [] ∷ [] |
| 63 |
grouped[xs]⇒unique[derun[xs]] (x ∷ y ∷ xs) (all[¬Px,y∷xs]@(¬Pxy ∷ _) ∷≉ grouped[y∷xs]) with P? x y |
| 64 |
... | yes Pxy = contradiction Pxy ¬Pxy |
| 65 |
... | no _ = All.derun⁺ P? all[¬Px,y∷xs] ∷ grouped[xs]⇒unique[derun[xs]] (y ∷ xs) grouped[y∷xs] |
| 66 |
grouped[xs]⇒unique[derun[xs]] (x ∷ y ∷ xs) (Pxy ∷≈ grouped[xs]) with P? x y |
| 67 |
... | yes _ = grouped[xs]⇒unique[derun[xs]] (y ∷ xs) grouped[xs] |
| 68 |
... | no ¬Pxy = contradiction Pxy ¬Pxy |