Debian Codegraph @

src/Data/List/Scans/Properties.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- List scans: properties
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.List.Scans.Properties where
10
11 open import Data.List.Base as List using (List; []; _∷_)
12 open import Data.List.NonEmpty.Base as List⁺ using (List⁺; _∷_; toList)
13 import Data.List.Properties as List using (map-∘)
14 open import Data.List.Scans.Base using (scanr⁺; scanr; scanl⁺; scanl)
15 open import Function.Base using (_∘_; _$_)
16 open import Level using (Level)
17 open import Relation.Binary.PropositionalEquality.Core
18 using (_≡_; _≗_; refl; trans; cong; cong₂)
19
20 private
21 variable
22 a b : Level
23 A : Set a
24 B : Set b
25
26
27 ------------------------------------------------------------------------
28 -- Properties
29
30 -- scanr⁺ and scanr
31
32 module _ (f : A → B → B) (e : B) where
33
34 private
35 h = List.foldr f e
36
37 scanr⁺-defn : scanr⁺ f e ≗ List⁺.map h ∘ List⁺.tails
38 scanr⁺-defn [] = refl
39 scanr⁺-defn (x ∷ xs) = let eq = scanr⁺-defn xs
40 in cong₂ (λ z → f x z ∷_) (cong List⁺.head eq) (cong toList eq)
41
42 scanr-defn : scanr f e ≗ List.map h ∘ List.tails
43 scanr-defn xs = cong toList (scanr⁺-defn xs)
44
45 -- scanl⁺ and scanl
46
47 module _ (f : A → B → A) where
48
49 private
50 h = List.foldl f
51
52 scanl⁺-defn : ∀ e → scanl⁺ f e ≗ List⁺.map (h e) ∘ List⁺.inits
53 scanl⁺-defn e [] = refl
54 scanl⁺-defn e (x ∷ xs) = let eq = scanl⁺-defn (f e x) xs in
55 cong (e ∷_) $ cong (f e x ∷_) $ trans (cong List⁺.tail eq) (List.map-∘ _)
56
57 scanl-defn : ∀ e → scanl f e ≗ List.map (h e) ∘ List.inits
58 scanl-defn e xs = cong toList (scanl⁺-defn e xs)