Data.List.Relation.Unary.Linked.Properties
{-# OPTIONS --cubical-compatible --safe #-}
module Data.List.Relation.Unary.Linked.Properties where
open import Data.Bool.Base using (true; false)
open import Data.List.Base hiding (any)
open import Data.List.Relation.Unary.AllPairs as AllPairs
using (AllPairs; []; _â·_)
import Data.List.Relation.Unary.AllPairs.Properties as AllPairs
open import Data.List.Relation.Unary.All using (All; []; _â·_)
open import Data.List.Relation.Unary.Linked as Linked
using (Linked; []; [-]; _â·_)
open import Data.Nat.Base using (zero; suc; _<_; z<s; s<s)
open import Data.Nat.Properties using (â€-refl; mâ€nâmâ€1+n)
open import Data.Maybe.Relation.Binary.Connected
using (Connected; just; nothing; just-nothing; nothing-just)
open import Level using (Level)
open import Function.Base using (_â_; flip; _on_)
open import Relation.Binary.Core using (Rel)
open import Relation.Binary.Bundles using (DecSetoid)
open import Relation.Binary.Definitions using (Transitive)
open import Relation.Binary.PropositionalEquality.Core using (_âą_)
open import Relation.Unary using (Pred; Decidable)
open import Relation.Nullary.Decidable using (yes; no; does)
private
variable
a b p â : Level
A : Set a
B : Set b
module _ {R : Rel A â} where
AllPairsâLinked : â {xs} â AllPairs R xs â Linked R xs
AllPairsâLinked [] = []
AllPairsâLinked (px â· []) = [-]
AllPairsâLinked ((px â· _) â· py â· pxs) =
px â· (AllPairsâLinked (py â· pxs))
module _ {R : Rel A â} (trans : Transitive R) where
LinkedâAll : â {v x xs} â R v x â
Linked R (x â· xs) â All (R v) (x â· xs)
LinkedâAll Rvx [-] = Rvx â· []
LinkedâAll Rvx (Rxy â· Rxs) = Rvx â· LinkedâAll (trans Rvx Rxy) Rxs
LinkedâAllPairs : â {xs} â Linked R xs â AllPairs R xs
LinkedâAllPairs [] = []
LinkedâAllPairs [-] = [] â· []
LinkedâAllPairs (Rxy â· Rxs) = LinkedâAll Rxy Rxs â· LinkedâAllPairs Rxs
module _ {R : Rel A â} {f : B â A} where
mapâș : â {xs} â Linked (R on f) xs â Linked R (map f xs)
mapâș [] = []
mapâș [-] = [-]
mapâș (Rxy â· Rxs) = Rxy â· mapâș Rxs
mapâ» : â {xs} â Linked R (map f xs) â Linked (R on f) xs
mapâ» {[]} [] = []
mapâ» {x â· []} [-] = [-]
mapâ» {x â· y â· xs} (Rxy â· Rxs) = Rxy â· mapâ» Rxs
module _ {R : Rel A â} where
++âș : â {xs ys} â
Linked R xs â
Connected R (last xs) (head ys) â
Linked R ys â
Linked R (xs ++ ys)
++âș [] _ Rys = Rys
++âș [-] _ [] = [-]
++âș [-] (just Rxy) [-] = Rxy â· [-]
++âș [-] (just Rxy) (Ryz â· Rys) = Rxy â· Ryz â· Rys
++âș (Rxy â· Rxs) Rxsys Rys = Rxy â· ++âș Rxs Rxsys Rys
module _ {R : Rel A â} where
applyUpToâșâ : â f n â (â {i} â suc i < n â R (f i) (f (suc i))) â
Linked R (applyUpTo f n)
applyUpToâșâ f 0 Rf = []
applyUpToâșâ f 1 Rf = [-]
applyUpToâșâ f (suc n@(suc _)) Rf =
Rf (s<s z<s) â· (applyUpToâșâ (f â suc) n (Rf â s<s))
applyUpToâșâ : â f n â (â i â R (f i) (f (suc i))) â
Linked R (applyUpTo f n)
applyUpToâșâ f n Rf = applyUpToâșâ f n (λ _ â Rf _)
module _ {R : Rel A â} where
applyDownFromâșâ : â f n â (â {i} â suc i < n â R (f (suc i)) (f i)) â
Linked R (applyDownFrom f n)
applyDownFromâșâ f 0 Rf = []
applyDownFromâșâ f 1 Rf = [-]
applyDownFromâșâ f (suc n@(suc _)) Rf =
Rf â€-refl â· applyDownFromâșâ f n (Rf â mâ€nâmâ€1+n)
applyDownFromâșâ : â f n â (â i â R (f (suc i)) (f i)) â
Linked R (applyDownFrom f n)
applyDownFromâșâ f n Rf = applyDownFromâșâ f n (λ _ â Rf _)
module _ {P : Pred A p} (P? : Decidable P)
{R : Rel A â} (trans : Transitive R)
where
â·-filterâș : â {x xs} â Linked R (x â· xs) â Linked R (x â· filter P? xs)
â·-filterâș [-] = [-]
â·-filterâș {xs = y â· _} (r â· [-]) with does (P? y)
... | false = [-]
... | true = r â· [-]
â·-filterâș {x = x} {xs = y â· ys} (r â· râČ â· rs)
with does (P? y) | â·-filterâș {xs = ys} | â·-filterâș (râČ â· rs)
... | false | ihf | _ = ihf (trans r râČ â· rs)
... | true | _ | iht = r â· iht
filterâș : â {xs} â Linked R xs â Linked R (filter P? xs)
filterâș [] = []
filterâș {xs = x â· []} [-] with does (P? x)
... | false = []
... | true = [-]
filterâș {xs = x â· _} (r â· rs) with does (P? x)
... | false = filterâș rs
... | true = â·-filterâș (r â· rs)