Debian Codegraph @

src/Data/Tree/Rose/Properties.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties of rose trees
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --sized-types #-}
8
9 module Data.Tree.Rose.Properties where
10
11 open import Level using (Level)
12 open import Size
13 open import Data.List.Base as List using (List)
14 open import Data.List.Extrema.Nat using (max)
15 import Data.List.Properties as List
16 open import Data.Nat.Base using (ℕ; zero; suc)
17 open import Data.Tree.Rose using (Rose; node; map; depth; foldr)
18 open import Function.Base using (_∘′_; _$_; _∘_)
19 open import Relation.Binary.PropositionalEquality.Core
20 using (_≡_; _≗_; cong)
21 open import Relation.Binary.PropositionalEquality.Properties
22 using (module ≡-Reasoning)
23 open ≡-Reasoning
24
25 private
26 variable
27 a b c : Level
28 A : Set a
29 B : Set b
30 C : Set c
31 i : Size
32
33 ------------------------------------------------------------------------
34 -- map properties
35
36 map-∘ : (f : A → B) (g : B → C) →
37 map {i = i} (g ∘′ f) ≗ map {i = i} g ∘′ map {i = i} f
38 map-∘ f g (node a ts) = cong (node (g (f a))) $ begin
39 List.map (map (g ∘′ f)) ts ≡⟨ List.map-cong (map-∘ f g) ts ⟩
40 List.map (map g ∘ map f) ts ≡⟨ List.map-∘ ts ⟩
41 List.map (map g) (List.map (map f) ts) ∎
42
43 depth-map : (f : A → B) (t : Rose A i) → depth {i = i} (map {i = i} f t) ≡ depth {i = i} t
44 depth-map f (node a ts) = cong (suc ∘′ max 0) $ begin
45 List.map depth (List.map (map f) ts) ≡⟨ List.map-∘ ts ⟨
46 List.map (depth ∘′ map f) ts ≡⟨ List.map-cong (depth-map f) ts ⟩
47 List.map depth ts ∎
48
49 ------------------------------------------------------------------------
50 -- foldr properties
51
52 foldr-map : (f : A → B) (n : B → List C → C) (ts : Rose A i) →
53 foldr {i = i} n (map {i = i} f ts) ≡ foldr {i = i} (n ∘′ f) ts
54 foldr-map f n (node a ts) = cong (n (f a)) $ begin
55 List.map (foldr n) (List.map (map f) ts) ≡⟨ List.map-∘ ts ⟨
56 List.map (foldr n ∘′ map f) ts ≡⟨ List.map-cong (foldr-map f n) ts ⟩
57 List.map (foldr (n ∘′ f)) ts ∎
58
59 ------------------------------------------------------------------------
60 -- DEPRECATED
61 ------------------------------------------------------------------------
62 -- Please use the new names as continuing support for the old names is
63 -- not guaranteed.
64
65 -- Version 2.0
66
67 map-compose = map-∘
68 {-# WARNING_ON_USAGE map-compose
69 "Warning: map-compose was deprecated in v2.0.
70 Please use map-∘ instead."
71 #-}