Debian Codegraph @

src/Data/List/Relation/Ternary/Interleaving/Propositional.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Interleavings of lists using propositional equality
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.List.Relation.Ternary.Interleaving.Propositional {a} {A : Set a} where
10
11 open import Data.List.Base as List using (List; []; _∷_; _++_)
12 open import Data.List.Relation.Binary.Permutation.Propositional as Perm using (_↭_)
13 open import Data.List.Relation.Binary.Permutation.Propositional.Properties using (shift)
14 import Data.List.Relation.Ternary.Interleaving.Setoid as General
15 open import Relation.Binary.PropositionalEquality.Core using (refl)
16 open import Relation.Binary.PropositionalEquality.Properties using (setoid)
17 open Perm.PermutationReasoning
18
19 ------------------------------------------------------------------------
20 -- Re-export the basic combinators
21
22 open General hiding (Interleaving) public
23
24 ------------------------------------------------------------------------
25 -- Definition
26
27 Interleaving : List A → List A → List A → Set a
28 Interleaving = General.Interleaving (setoid A)
29
30 pattern consˡ xs = refl ∷ˡ xs
31 pattern consʳ xs = refl ∷ʳ xs
32
33 ------------------------------------------------------------------------
34 -- New combinators
35
36 toPermutation : ∀ {l r as} → Interleaving l r as → as ↭ l ++ r
37 toPermutation [] = Perm.refl
38 toPermutation (consˡ sp) = Perm.prep _ (toPermutation sp)
39 toPermutation {l} {r ∷ rs} {a ∷ as} (consʳ sp) = begin
40 a ∷ as ↭⟨ Perm.prep a (toPermutation sp) ⟩
41 a ∷ l ++ rs ↭⟨ Perm.↭-sym (shift a l rs) ⟩
42 l ++ a ∷ rs ∎